Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = ["Ash Manning <ash@layertwolabs.com>",
edition = "2024"
license-file = "LICENSE.txt"
publish = false
version = "0.17.0"
version = "0.18.0"

[workspace.dependencies]
anyhow = "1.0.72"
Expand Down
37 changes: 35 additions & 2 deletions lib/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,7 @@ pub trait Verify {

#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
pub struct Block {
#[serde(flatten)]
pub header: Header,
#[serde(flatten)]
pub body: Body,
pub height: u32,
}
Expand Down Expand Up @@ -842,3 +840,38 @@ mod withdrawal_bundle_order_regression {
}
}
}

#[cfg(test)]
mod block_json_tests {
use bitcoin::hashes::Hash as _;

use super::{Block, Body, Header, MerkleRoot};

#[test]
fn block_json_nests_the_header_and_the_body() {
let block = Block {
header: Header {
merkle_root: MerkleRoot::from([1; 32]),
prev_side_hash: None,
prev_main_hash: bitcoin::BlockHash::from_byte_array([2; 32]),
},
body: Body {
coinbase: Vec::new(),
transactions: Vec::new(),
authorizations: Vec::new(),
actor_proofs: Vec::new(),
},
height: 7,
};
let json = serde_json::to_value(&block).unwrap();
assert_eq!(
json["header"]["prev_main_hash"],
serde_json::to_value(block.header.prev_main_hash).unwrap()
);
assert!(json["body"]["transactions"].is_array());
assert_eq!(json["height"], 7);
assert!(json.get("prev_main_hash").is_none());
let decoded: Block = serde_json::from_value(json.clone()).unwrap();
assert_eq!(serde_json::to_value(&decoded).unwrap(), json);
}
}
Loading