Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 09b5afd

Browse files
committedMar 5, 2025··
Set json schema uri.
1 parent b72ad8c commit 09b5afd

File tree

1 file changed

+16
-2
lines changed
  • cmd/soroban-cli/src/commands/tx

1 file changed

+16
-2
lines changed
 

‎cmd/soroban-cli/src/commands/tx/edit.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66
process::{self},
77
};
88

9+
use serde_json::json;
910
use stellar_xdr::curr;
1011

1112
use crate::{commands::global, print::Print};
@@ -152,8 +153,13 @@ fn xdr_to_json<T>(xdr_string: &str) -> Result<String, Error>
152153
where
153154
T: curr::ReadXdr + serde::Serialize,
154155
{
156+
let version = env!("CARGO_PKG_VERSION");
155157
let tx = T::from_xdr_base64(xdr_string, curr::Limits::none())?;
156-
let json = serde_json::to_string_pretty(&tx)?;
158+
let mut schema: serde_json::Value = serde_json::to_value(tx).unwrap();
159+
schema["$schema"] = json!(format!(
160+
"https://github.com/stellar/stellar-cli/releases/download/v{version}/stellar-xdr-{version}.json"
161+
));
162+
let json = serde_json::to_string_pretty(&schema)?;
157163

158164
Ok(json)
159165
}
@@ -162,7 +168,15 @@ fn json_to_xdr<T>(json_string: &str) -> Result<String, Error>
162168
where
163169
T: serde::de::DeserializeOwned + curr::WriteXdr,
164170
{
165-
let value: T = serde_json::from_str(json_string)?;
171+
let mut schema: serde_json::Value = serde_json::from_str(json_string).unwrap();
172+
173+
if let Some(obj) = schema.as_object_mut() {
174+
obj.remove("$schema");
175+
}
176+
177+
let json_string = serde_json::to_string(&schema)?;
178+
179+
let value: T = serde_json::from_str(json_string.as_str())?;
166180
let mut data = Vec::new();
167181
let cursor = Cursor::new(&mut data);
168182
let mut limit = curr::Limited::new(cursor, curr::Limits::none());

0 commit comments

Comments
 (0)
Please sign in to comment.