@@ -6,6 +6,7 @@ use std::{
6
6
process:: { self } ,
7
7
} ;
8
8
9
+ use serde_json:: json;
9
10
use stellar_xdr:: curr;
10
11
11
12
use crate :: { commands:: global, print:: Print } ;
@@ -152,8 +153,13 @@ fn xdr_to_json<T>(xdr_string: &str) -> Result<String, Error>
152
153
where
153
154
T : curr:: ReadXdr + serde:: Serialize ,
154
155
{
156
+ let version = env ! ( "CARGO_PKG_VERSION" ) ;
155
157
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) ?;
157
163
158
164
Ok ( json)
159
165
}
@@ -162,7 +168,15 @@ fn json_to_xdr<T>(json_string: &str) -> Result<String, Error>
162
168
where
163
169
T : serde:: de:: DeserializeOwned + curr:: WriteXdr ,
164
170
{
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 ( ) ) ?;
166
180
let mut data = Vec :: new ( ) ;
167
181
let cursor = Cursor :: new ( & mut data) ;
168
182
let mut limit = curr:: Limited :: new ( cursor, curr:: Limits :: none ( ) ) ;
0 commit comments