Skip to content

Commit

Permalink
draft of validate_merkle_root
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejka committed Aug 2, 2024
1 parent c972cf7 commit 8c44c90
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
pub struct ChainState {
/// Height of the current block.
pub block_height: u32, // not u256?

/// Total work done.
pub total_work: u256,

/// Best block.
pub best_block_hash: u256,

/// Current block.
pub current_target: u32,

/// Start of the current epoch.
pub epoch_start_time: u32,

/// Previous timestamps.
pub prev_timestamps: Span<u32>,

// TODO: utreexo_roots?
}

Expand All @@ -34,14 +40,19 @@ pub struct Block {
struct Header {
/// The version of the block.
pub version: u32,

/// The hash of the previous block in the blockchain.
pub prev_block_hash: u256,

/// The Merkle root hash of the transactions in the block.
pub merkle_root_hash: u256,

/// The timestamp of the block.
pub time: u32,

/// The difficulty target for mining the block.
pub bits: u32,

/// The nonce used in mining the block.
pub nonce: u32,
}
Expand All @@ -52,10 +63,13 @@ struct Header {
pub struct Transaction {
/// The version of the transaction.
pub version: i32,

/// The inputs of the transaction.
pub inputs: Span<TxIn>,

/// The outputs of the transaction.
pub outputs: Span<TxOut>,

/// The lock time of the transaction.
pub lock_time: u32,
}
Expand All @@ -66,6 +80,7 @@ pub struct Transaction {
pub struct TxOut {
/// The value of the output.
value: i64,

/// The public key script of the output.
pk_script: @ByteArray,
}
Expand All @@ -76,10 +91,13 @@ pub struct TxOut {
pub struct TxIn {
/// The transaction ID of the input.
txid: u256,

/// The index of the input.
index: u32,

/// The script of the input.
script: @ByteArray,

/// The sequence of the input.
sequence: u32,
}
Expand Down
7 changes: 6 additions & 1 deletion src/validation.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl BlockValidatorImpl of BlockValidator {
validate_target(@self, @block)?;
validate_timestamp(@self, @block)?;

// validate_merkle_root
validate_merkle_root(@self, @block)?;
// validate_and_apply_transactions

let prev_timestamps = next_prev_timestamps(@self, @block);
Expand Down Expand Up @@ -58,3 +58,8 @@ fn adjust_difficulty(self: @ChainState, block: @Block) -> (u32, u32) {
// TODO: implement
(*self.current_target, *self.epoch_start_time)
}

fn validate_merkle_root(self: @ChainState, block: @Block) -> Result<(), ByteArray> {
// TODO: implement
Result::Ok(())
}

0 comments on commit 8c44c90

Please sign in to comment.