mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-12 14:09:25 +00:00
Write a new impl of the merkle algorithm
This one tries to be understandable.
This commit is contained in:
@@ -5,12 +5,11 @@ use std_shims::{
|
||||
|
||||
use crate::{
|
||||
hash,
|
||||
merkle::merkle_root,
|
||||
serialize::*,
|
||||
transaction::{Input, Transaction},
|
||||
};
|
||||
|
||||
mod merkle_root;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct BlockHeader {
|
||||
pub major_version: u64,
|
||||
@@ -71,11 +70,11 @@ impl Block {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn tx_merkle_root(&self) -> [u8; 32] {
|
||||
merkle_root::tree_hash(self.miner_tx.hash(), &self.txs)
|
||||
fn tx_merkle_root(&self) -> [u8; 32] {
|
||||
merkle_root(self.miner_tx.hash(), &self.txs)
|
||||
}
|
||||
|
||||
pub fn serialize_hashable(&self) -> Vec<u8> {
|
||||
fn serialize_hashable(&self) -> Vec<u8> {
|
||||
let mut blob = self.header.serialize();
|
||||
blob.extend_from_slice(&self.tx_merkle_root());
|
||||
write_varint(&(1 + u64::try_from(self.txs.len()).unwrap()), &mut blob).unwrap();
|
||||
@@ -87,7 +86,7 @@ impl Block {
|
||||
out
|
||||
}
|
||||
|
||||
pub fn id(&self) -> [u8; 32] {
|
||||
pub fn hash(&self) -> [u8; 32] {
|
||||
// TODO: Handle block 202612
|
||||
// https://monero.stackexchange.com/questions/421/what-happened-at-block-202612
|
||||
// If this block's header is fully-equivalent to 202612, return the malformed hash instead
|
||||
|
||||
Reference in New Issue
Block a user