diff --git a/CHANGELOG.md b/CHANGELOG.md index 8517c2401b..fd6f7d2d1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Graceful shutdown upon SIGINT and SIGTERM with a default grace period of 10 seconds, configurable via `--shutdown.grace-period`. +- `storage_root` along `nonce` and `class_hash` in `contracts_proof/contract_leaves_data` for `starknet_getStorageProof`. ### Removed diff --git a/crates/rpc/src/method/get_storage_proof.rs b/crates/rpc/src/method/get_storage_proof.rs index 8a8bafdaca..aea48dd90a 100644 --- a/crates/rpc/src/method/get_storage_proof.rs +++ b/crates/rpc/src/method/get_storage_proof.rs @@ -9,6 +9,7 @@ use pathfinder_common::{ ClassHash, ContractAddress, ContractNonce, + ContractRoot, StorageAddress, }; use pathfinder_crypto::Felt; @@ -172,6 +173,7 @@ impl SerializeForVersion for &NodeHashToNodeMappings { struct ContractLeafData { nonce: ContractNonce, class_hash: ClassHash, + storage_root: ContractRoot, } impl SerializeForVersion for &ContractLeafData { @@ -182,6 +184,7 @@ impl SerializeForVersion for &ContractLeafData { let mut s = serializer.serialize_struct()?; s.serialize_field("nonce", &self.nonce)?; s.serialize_field("class_hash", &self.class_hash)?; + s.serialize_field("storage_root", &self.storage_root)?; s.end() } } @@ -439,7 +442,16 @@ fn get_contract_proofs( .context("Querying contract's nonce")? .unwrap_or_default(); - Ok(ContractLeafData { nonce, class_hash }) + let storage_root = tx + .contract_root(block_number, address) + .context("Querying contract's storage root")? + .unwrap_or_default(); + + Ok(ContractLeafData { + nonce, + class_hash, + storage_root, + }) }) .collect::, Error>>()?; Ok(( @@ -670,6 +682,7 @@ mod tests { contract_leaves_data: vec![ContractLeafData { nonce: ContractNonce::ZERO, class_hash: ClassHash(Felt::from_hex_str("0x123").unwrap()), + storage_root: ContractRoot(Felt::from_hex_str("0x234").unwrap()), }], }, contracts_storage_proofs: vec![NodeHashToNodeMappings(vec![NodeHashToNodeMapping { @@ -702,14 +715,15 @@ mod tests { "node": { "child": "0x123", "length": 8, - "path": "0x0", + "path": "0x0" } } ], "contract_leaves_data": [ { "nonce": "0x0", - "class_hash": "0x123" + "class_hash": "0x123", + "storage_root": "0x234" } ] }, @@ -734,7 +748,7 @@ mod tests { fn serialization_output(#[case] output: Output, #[case] expected: serde_json::Value) { let output = output.serialize(crate::dto::Serializer::default()).unwrap(); - assert_eq!(output, expected); + pretty_assertions_sorted::assert_eq!(output, expected); } } diff --git a/doc/rpc/v08/starknet_api_openrpc.json b/doc/rpc/v08/starknet_api_openrpc.json index 4c46d7ba5b..fd6ef0c3c4 100644 --- a/doc/rpc/v08/starknet_api_openrpc.json +++ b/doc/rpc/v08/starknet_api_openrpc.json @@ -994,6 +994,9 @@ }, "class_hash": { "$ref": "#/components/schemas/FELT" + }, + "storage_root": { + "$ref": "#/components/schemas/FELT" } }, "required": ["nonce", "class_hash"] @@ -3877,4 +3880,4 @@ } } } -} \ No newline at end of file +}