@@ -31,6 +31,11 @@ use tokio::time::sleep;
3131
3232const VERSION : Option < & str > = option_env ! ( "CARGO_PKG_VERSION" ) ;
3333
34+ /// Depth limit when encoding and decoding XDR.
35+ ///
36+ /// 500 matches `soroban-env-host`'s `DEFAULT_XDR_RW_LIMITS`.
37+ const XDR_DEPTH_LIMIT : u32 = 500 ;
38+
3439pub type LogEvents = fn (
3540 footprint : & LedgerFootprint ,
3641 auth : & [ VecM < SorobanAuthorizationEntry > ] ,
@@ -222,7 +227,7 @@ impl TryInto<GetTransactionResponse> for GetTransactionResponseRaw {
222227 let events = self . events . unwrap_or_default ( ) ;
223228 let result_meta: Option < xdr:: TransactionMeta > = self
224229 . result_meta_xdr
225- . map ( |v| ReadXdr :: from_xdr_base64 ( v, Limits :: none ( ) ) )
230+ . map ( |v| ReadXdr :: from_xdr_base64 ( v, Limits :: depth ( XDR_DEPTH_LIMIT ) ) )
226231 . transpose ( ) ?;
227232
228233 let events = match result_meta {
@@ -233,7 +238,10 @@ impl TryInto<GetTransactionResponse> for GetTransactionResponseRaw {
233238 . into_iter ( )
234239 . map ( |es| {
235240 es. into_iter ( )
236- . filter_map ( |e| ContractEvent :: from_xdr_base64 ( e, Limits :: none ( ) ) . ok ( ) )
241+ . filter_map ( |e| {
242+ ContractEvent :: from_xdr_base64 ( e, Limits :: depth ( XDR_DEPTH_LIMIT ) )
243+ . ok ( )
244+ } )
237245 . collect :: < Vec < _ > > ( )
238246 } )
239247 . collect :: < Vec < Vec < ContractEvent > > > ( ) ,
@@ -242,14 +250,18 @@ impl TryInto<GetTransactionResponse> for GetTransactionResponseRaw {
242250 . diagnostic_events_xdr
243251 . unwrap_or_default ( )
244252 . iter ( )
245- . filter_map ( |e| DiagnosticEvent :: from_xdr_base64 ( e, Limits :: none ( ) ) . ok ( ) )
253+ . filter_map ( |e| {
254+ DiagnosticEvent :: from_xdr_base64 ( e, Limits :: depth ( XDR_DEPTH_LIMIT ) ) . ok ( )
255+ } )
246256 . collect ( ) ,
247257
248258 transaction_events : events
249259 . transaction_events_xdr
250260 . unwrap_or_default ( )
251261 . iter ( )
252- . filter_map ( |e| TransactionEvent :: from_xdr_base64 ( e, Limits :: none ( ) ) . ok ( ) )
262+ . filter_map ( |e| {
263+ TransactionEvent :: from_xdr_base64 ( e, Limits :: depth ( XDR_DEPTH_LIMIT ) ) . ok ( )
264+ } )
253265 . collect ( ) ,
254266 } ,
255267
@@ -278,11 +290,11 @@ impl TryInto<GetTransactionResponse> for GetTransactionResponseRaw {
278290 created_at : self . created_at ,
279291 envelope : self
280292 . envelope_xdr
281- . map ( |v| ReadXdr :: from_xdr_base64 ( v, Limits :: none ( ) ) )
293+ . map ( |v| ReadXdr :: from_xdr_base64 ( v, Limits :: depth ( XDR_DEPTH_LIMIT ) ) )
282294 . transpose ( ) ?,
283295 result : self
284296 . result_xdr
285- . map ( |v| ReadXdr :: from_xdr_base64 ( v, Limits :: none ( ) ) )
297+ . map ( |v| ReadXdr :: from_xdr_base64 ( v, Limits :: depth ( XDR_DEPTH_LIMIT ) ) )
286298 . transpose ( ) ?,
287299 result_meta,
288300 events,
@@ -596,11 +608,11 @@ impl SimulateTransactionResponse {
596608 . map ( |a| {
597609 Ok ( SorobanAuthorizationEntry :: from_xdr_base64 (
598610 a,
599- Limits :: none ( ) ,
611+ Limits :: depth ( XDR_DEPTH_LIMIT ) ,
600612 ) ?)
601613 } )
602614 . collect :: < Result < _ , Error > > ( ) ?,
603- xdr : xdr:: ScVal :: from_xdr_base64 ( & r. xdr , Limits :: none ( ) ) ?,
615+ xdr : xdr:: ScVal :: from_xdr_base64 ( & r. xdr , Limits :: depth ( XDR_DEPTH_LIMIT ) ) ?,
604616 } )
605617 } )
606618 . collect ( )
@@ -611,7 +623,12 @@ impl SimulateTransactionResponse {
611623 pub fn events ( & self ) -> Result < Vec < DiagnosticEvent > , Error > {
612624 self . events
613625 . iter ( )
614- . map ( |e| Ok ( DiagnosticEvent :: from_xdr_base64 ( e, Limits :: none ( ) ) ?) )
626+ . map ( |e| {
627+ Ok ( DiagnosticEvent :: from_xdr_base64 (
628+ e,
629+ Limits :: depth ( XDR_DEPTH_LIMIT ) ,
630+ ) ?)
631+ } )
615632 . collect ( )
616633 }
617634
@@ -620,7 +637,7 @@ impl SimulateTransactionResponse {
620637 pub fn transaction_data ( & self ) -> Result < SorobanTransactionData , Error > {
621638 Ok ( SorobanTransactionData :: from_xdr_base64 (
622639 & self . transaction_data ,
623- Limits :: none ( ) ,
640+ Limits :: depth ( XDR_DEPTH_LIMIT ) ,
624641 ) ?)
625642 }
626643}
@@ -742,12 +759,12 @@ impl Display for Event {
742759 writeln ! ( f, " Topics:" ) ?;
743760
744761 for topic in & self . topic {
745- let scval =
746- xdr :: ScVal :: from_xdr_base64 ( topic , Limits :: none ( ) ) . map_err ( |_| std:: fmt:: Error ) ?;
762+ let scval = xdr :: ScVal :: from_xdr_base64 ( topic , Limits :: depth ( XDR_DEPTH_LIMIT ) )
763+ . map_err ( |_| std:: fmt:: Error ) ?;
747764 writeln ! ( f, " {scval:?}" ) ?;
748765 }
749766
750- let scval = xdr:: ScVal :: from_xdr_base64 ( & self . value , Limits :: none ( ) )
767+ let scval = xdr:: ScVal :: from_xdr_base64 ( & self . value , Limits :: depth ( XDR_DEPTH_LIMIT ) )
751768 . map_err ( |_| std:: fmt:: Error ) ?;
752769
753770 writeln ! ( f, " Value: {scval:?}" )
@@ -813,7 +830,7 @@ impl Event {
813830
814831 colored ! ( stdout, " Topics:\n " ) ?;
815832 for topic in & self . topic {
816- let scval = xdr:: ScVal :: from_xdr_base64 ( topic, Limits :: none ( ) ) ?;
833+ let scval = xdr:: ScVal :: from_xdr_base64 ( topic, Limits :: depth ( XDR_DEPTH_LIMIT ) ) ?;
817834 colored ! (
818835 stdout,
819836 " {}{:?}{}\n " ,
@@ -823,7 +840,7 @@ impl Event {
823840 ) ?;
824841 }
825842
826- let scval = xdr:: ScVal :: from_xdr_base64 ( & self . value , Limits :: none ( ) ) ?;
843+ let scval = xdr:: ScVal :: from_xdr_base64 ( & self . value , Limits :: depth ( XDR_DEPTH_LIMIT ) ) ?;
827844 colored ! (
828845 stdout,
829846 " Value: {}{:?}{}\n \n " ,
@@ -1135,7 +1152,7 @@ impl Client {
11351152 }
11361153
11371154 let ledger_entry = & entries[ 0 ] ;
1138- let mut read = Limited :: new ( ledger_entry. xdr . as_bytes ( ) , Limits :: none ( ) ) ;
1155+ let mut read = Limited :: new ( ledger_entry. xdr . as_bytes ( ) , Limits :: depth ( XDR_DEPTH_LIMIT ) ) ;
11391156
11401157 if let LedgerEntryData :: Account ( entry) = LedgerEntryData :: read_xdr_base64 ( & mut read) ? {
11411158 Ok ( entry)
@@ -1166,7 +1183,10 @@ impl Client {
11661183 /// # Errors
11671184 pub async fn send_transaction ( & self , tx : & TransactionEnvelope ) -> Result < Hash , Error > {
11681185 let mut oparams = ObjectParams :: new ( ) ;
1169- oparams. insert ( "transaction" , tx. to_xdr_base64 ( Limits :: none ( ) ) ?) ?;
1186+ oparams. insert (
1187+ "transaction" ,
1188+ tx. to_xdr_base64 ( Limits :: depth ( XDR_DEPTH_LIMIT ) ) ?,
1189+ ) ?;
11701190 let SendTransactionResponse {
11711191 hash,
11721192 error_result_xdr,
@@ -1186,7 +1206,7 @@ impl Client {
11861206 . and_then ( |x| {
11871207 TransactionResult :: read_xdr_base64 ( & mut Limited :: new (
11881208 x. as_bytes ( ) ,
1189- Limits :: none ( ) ,
1209+ Limits :: depth ( XDR_DEPTH_LIMIT ) ,
11901210 ) )
11911211 . map_err ( |_| Error :: InvalidResponse )
11921212 } )
@@ -1215,7 +1235,7 @@ impl Client {
12151235 tx : & TransactionEnvelope ,
12161236 auth_mode : Option < AuthMode > ,
12171237 ) -> Result < SimulateTransactionResponse , Error > {
1218- let base64_tx = tx. to_xdr_base64 ( Limits :: none ( ) ) ?;
1238+ let base64_tx = tx. to_xdr_base64 ( Limits :: depth ( XDR_DEPTH_LIMIT ) ) ?;
12191239 let mut params = ObjectParams :: new ( ) ;
12201240
12211241 params. insert ( "transaction" , base64_tx) ?;
@@ -1246,7 +1266,7 @@ impl Client {
12461266 auth_mode : Option < AuthMode > ,
12471267 resource_config : Option < ResourceConfig > ,
12481268 ) -> Result < SimulateTransactionResponse , Error > {
1249- let base64_tx = tx. to_xdr_base64 ( Limits :: none ( ) ) ?;
1269+ let base64_tx = tx. to_xdr_base64 ( Limits :: depth ( XDR_DEPTH_LIMIT ) ) ?;
12501270 let mut params = ObjectParams :: new ( ) ;
12511271
12521272 params. insert ( "transaction" , base64_tx) ?;
@@ -1366,11 +1386,11 @@ impl Client {
13661386 let mut base64_keys: Vec < String > = vec ! [ ] ;
13671387
13681388 for k in keys {
1369- let base64_result = k. to_xdr_base64 ( Limits :: none ( ) ) ;
1389+ let base64_result = k. to_xdr_base64 ( Limits :: depth ( XDR_DEPTH_LIMIT ) ) ;
13701390 if base64_result. is_err ( ) {
13711391 return Err ( Error :: Xdr ( XdrError :: Invalid ) ) ;
13721392 }
1373- base64_keys. push ( k. to_xdr_base64 ( Limits :: none ( ) ) ?) ;
1393+ base64_keys. push ( k. to_xdr_base64 ( Limits :: depth ( XDR_DEPTH_LIMIT ) ) ?) ;
13741394 }
13751395
13761396 let mut oparams = ObjectParams :: new ( ) ;
@@ -1405,8 +1425,8 @@ impl Client {
14051425 live_until_ledger_seq_ledger_seq,
14061426 } | {
14071427 Ok ( FullLedgerEntry {
1408- key : LedgerKey :: from_xdr_base64 ( key, Limits :: none ( ) ) ?,
1409- val : LedgerEntryData :: from_xdr_base64 ( xdr, Limits :: none ( ) ) ?,
1428+ key : LedgerKey :: from_xdr_base64 ( key, Limits :: depth ( XDR_DEPTH_LIMIT ) ) ?,
1429+ val : LedgerEntryData :: from_xdr_base64 ( xdr, Limits :: depth ( XDR_DEPTH_LIMIT ) ) ?,
14101430 live_until_ledger_seq : * live_until_ledger_seq_ledger_seq,
14111431 last_modified_ledger : * last_modified_ledger,
14121432 } )
@@ -1486,7 +1506,10 @@ impl Client {
14861506 ) ) ;
14871507 }
14881508 let contract_ref_entry = & entries[ 0 ] ;
1489- match LedgerEntryData :: from_xdr_base64 ( & contract_ref_entry. xdr , Limits :: none ( ) ) ? {
1509+ match LedgerEntryData :: from_xdr_base64 (
1510+ & contract_ref_entry. xdr ,
1511+ Limits :: depth ( XDR_DEPTH_LIMIT ) ,
1512+ ) ? {
14901513 LedgerEntryData :: ContractData ( contract_data) => Ok ( contract_data) ,
14911514 scval => Err ( Error :: UnexpectedContractCodeDataType ( scval) ) ,
14921515 }
@@ -1523,7 +1546,10 @@ impl Client {
15231546 ) ) ;
15241547 }
15251548 let contract_data_entry = & entries[ 0 ] ;
1526- match LedgerEntryData :: from_xdr_base64 ( & contract_data_entry. xdr , Limits :: none ( ) ) ? {
1549+ match LedgerEntryData :: from_xdr_base64 (
1550+ & contract_data_entry. xdr ,
1551+ Limits :: depth ( XDR_DEPTH_LIMIT ) ,
1552+ ) ? {
15271553 LedgerEntryData :: ContractCode ( xdr:: ContractCodeEntry { code, .. } ) => Ok ( code. into ( ) ) ,
15281554 scval => Err ( Error :: UnexpectedContractCodeDataType ( scval) ) ,
15291555 }
0 commit comments