From e887b940c3a8b1ba8f489c0e4cced0c16f82e86b Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Fri, 5 Apr 2024 13:11:24 +0200 Subject: [PATCH] =?UTF-8?q?stellar-rpc-client:=20Add=20support=20for=20new?= =?UTF-8?q?=20simulateTransaction=20stateChan=E2=80=A6=20(#123)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/crates/stellar-rpc-client/src/lib.rs | 35 ++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/cmd/crates/stellar-rpc-client/src/lib.rs b/cmd/crates/stellar-rpc-client/src/lib.rs index ee1d93d0..ca861e1b 100644 --- a/cmd/crates/stellar-rpc-client/src/lib.rs +++ b/cmd/crates/stellar-rpc-client/src/lib.rs @@ -279,6 +279,21 @@ pub struct SimulateHostFunctionResult { pub xdr: xdr::ScVal, } +#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, PartialEq)] +#[serde(tag = "type")] +pub enum LedgerEntryChange { + #[serde(rename = "created")] + Created { key: String, after: String }, + #[serde(rename = "deleted")] + Deleted { key: String, before: String }, + #[serde(rename = "updated")] + Updated { + key: String, + before: String, + after: String, + }, +} + #[derive(serde::Deserialize, serde::Serialize, Debug, Default, Clone)] pub struct SimulateTransactionResponse { #[serde( @@ -305,6 +320,12 @@ pub struct SimulateTransactionResponse { default )] pub restore_preamble: Option, + #[serde( + rename = "stateChanges", + skip_serializing_if = "Option::is_none", + default + )] + pub state_changes: Option>, #[serde(rename = "latestLedger")] pub latest_ledger: u32, #[serde(skip_serializing_if = "Option::is_none", default)] @@ -1070,10 +1091,20 @@ mod tests { "minResourceFee": "100000000", "cost": { "cpuInsns": "1000", "memBytes": "1000" }, "transactionData": "", - "latestLedger": 1234 - }"#; + "latestLedger": 1234, + "stateChanges": [{ + "type": "created", + "key": "AAAAAAAAAABuaCbVXZ2DlXWarV6UxwbW3GNJgpn3ASChIFp5bxSIWg==", + "before": null, + "after": "AAAAZAAAAAAAAAAAbmgm1V2dg5V1mq1elMcG1txjSYKZ9wEgoSBaeW8UiFoAAAAAAAAAZAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" + }] + }"#; let resp: SimulateTransactionResponse = serde_json::from_str(s).unwrap(); + assert_eq!( + resp.state_changes.unwrap()[0], + LedgerEntryChange::Created { key: "AAAAAAAAAABuaCbVXZ2DlXWarV6UxwbW3GNJgpn3ASChIFp5bxSIWg==".to_string(), after: "AAAAZAAAAAAAAAAAbmgm1V2dg5V1mq1elMcG1txjSYKZ9wEgoSBaeW8UiFoAAAAAAAAAZAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=".to_string() }, + ); assert_eq!(resp.min_resource_fee, 100_000_000); }