Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stellar-rpc-client: Add support for new simulateTransaction stateChan… #123

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Changes from 1 commit
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
38 changes: 36 additions & 2 deletions cmd/crates/stellar-rpc-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,24 @@ pub struct SimulateHostFunctionResult {
pub xdr: xdr::ScVal,
}

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, PartialEq)]
pub enum LedgerEntryChangeType {
#[serde(rename = "created")]
Created,
#[serde(rename = "deleted")]
Deleted,
#[serde(rename = "updated")]
Updated,
}
#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
pub struct LedgerEntryChange {
#[serde(rename = "type")]
pub type_: LedgerEntryChangeType,
2opremio marked this conversation as resolved.
Show resolved Hide resolved
pub key: String,
pub before: Option<String>,
pub after: Option<String>,
}
2opremio marked this conversation as resolved.
Show resolved Hide resolved

#[derive(serde::Deserialize, serde::Serialize, Debug, Default, Clone)]
pub struct SimulateTransactionResponse {
#[serde(
Expand All @@ -305,6 +323,12 @@ pub struct SimulateTransactionResponse {
default
)]
pub restore_preamble: Option<RestorePreamble>,
#[serde(
rename = "stateChanges",
skip_serializing_if = "Option::is_none",
2opremio marked this conversation as resolved.
Show resolved Hide resolved
default
)]
pub state_changes: Option<Vec<LedgerEntryChange>>,
#[serde(rename = "latestLedger")]
pub latest_ledger: u32,
#[serde(skip_serializing_if = "Option::is_none", default)]
Expand Down Expand Up @@ -1070,10 +1094,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].type_,
LedgerEntryChangeType::Created
);
assert_eq!(resp.min_resource_fee, 100_000_000);
}

Expand Down
Loading