From 476409d61a29f11bee4a7809dcf05402741554e6 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Mon, 11 Sep 2023 23:28:48 +0200 Subject: [PATCH 1/2] cli: Remove explicit decoding depths --- cmd/soroban-cli/src/rpc/mod.rs | 11 +++------ cmd/soroban-cli/src/utils/contract_spec.rs | 26 ++++++---------------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/cmd/soroban-cli/src/rpc/mod.rs b/cmd/soroban-cli/src/rpc/mod.rs index 0e9796482..d9063b2a1 100644 --- a/cmd/soroban-cli/src/rpc/mod.rs +++ b/cmd/soroban-cli/src/rpc/mod.rs @@ -4,7 +4,6 @@ use jsonrpsee_core::params::ObjectParams; use jsonrpsee_core::{self, client::ClientT, rpc_params}; use jsonrpsee_http_client::{HeaderMap, HttpClient, HttpClientBuilder}; use serde_aux::prelude::{deserialize_default_from_null, deserialize_number_from_string}; -use soroban_env_host::xdr::DepthLimitedRead; use soroban_env_host::xdr::{ self, AccountEntry, AccountId, ContractDataEntry, DiagnosticEvent, Error as XdrError, LedgerEntryData, LedgerFootprint, LedgerKey, LedgerKeyAccount, PublicKey, ReadXdr, @@ -519,9 +518,8 @@ soroban config identity fund {address} --helper-url "# )); } let ledger_entry = &entries[0]; - let mut depth_limit_read = DepthLimitedRead::new(ledger_entry.xdr.as_bytes(), 100); if let LedgerEntryData::Account(entry) = - LedgerEntryData::read_xdr_base64(&mut depth_limit_read)? + LedgerEntryData::from_xdr_base64(ledger_entry.xdr.as_bytes())? { tracing::trace!(account=?entry); Ok(entry) @@ -550,11 +548,8 @@ soroban config identity fund {address} --helper-url "# let error = error_result_xdr .ok_or(Error::MissingError) .and_then(|x| { - TransactionResult::read_xdr_base64(&mut DepthLimitedRead::new( - x.as_bytes(), - 100, - )) - .map_err(|_| Error::InvalidResponse) + TransactionResult::from_xdr_base64(x.as_bytes()) + .map_err(|_| Error::InvalidResponse) }) .map(|r| r.result); tracing::error!(?error); diff --git a/cmd/soroban-cli/src/utils/contract_spec.rs b/cmd/soroban-cli/src/utils/contract_spec.rs index da67bedc4..de7272995 100644 --- a/cmd/soroban-cli/src/utils/contract_spec.rs +++ b/cmd/soroban-cli/src/utils/contract_spec.rs @@ -1,14 +1,11 @@ use base64::{engine::general_purpose::STANDARD as base64, Engine as _}; -use std::{ - fmt::Display, - io::{self, Cursor}, -}; +use std::{fmt::Display, io}; use soroban_env_host::xdr::{ - self, DepthLimitedRead, ReadXdr, ScEnvMetaEntry, ScMetaEntry, ScMetaV0, ScSpecEntry, - ScSpecFunctionV0, ScSpecUdtEnumV0, ScSpecUdtErrorEnumV0, ScSpecUdtStructV0, ScSpecUdtUnionV0, - StringM, WriteXdr, + self, ReadXdr, ScEnvMetaEntry, ScMetaEntry, ScMetaV0, ScSpecEntry, ScSpecFunctionV0, + ScSpecUdtEnumV0, ScSpecUdtErrorEnumV0, ScSpecUdtStructV0, ScSpecUdtUnionV0, StringM, WriteXdr, }; +use soroban_sdk::xdr::VecM; pub struct ContractSpec { pub env_meta_base64: Option, @@ -59,10 +56,7 @@ impl ContractSpec { let mut env_meta_base64 = None; let env_meta = if let Some(env_meta) = env_meta { env_meta_base64 = Some(base64.encode(env_meta)); - let cursor = Cursor::new(env_meta); - let mut depth_limit_read = DepthLimitedRead::new(cursor, 100); - ScEnvMetaEntry::read_xdr_iter(&mut depth_limit_read) - .collect::, xdr::Error>>()? + VecM::::from_xdr(env_meta)?.into() } else { vec![] }; @@ -70,10 +64,7 @@ impl ContractSpec { let mut meta_base64 = None; let meta = if let Some(meta) = meta { meta_base64 = Some(base64.encode(meta)); - let cursor = Cursor::new(meta); - let mut depth_limit_read = DepthLimitedRead::new(cursor, 100); - ScMetaEntry::read_xdr_iter(&mut depth_limit_read) - .collect::, xdr::Error>>()? + VecM::::from_xdr(meta)?.into() } else { vec![] }; @@ -81,10 +72,7 @@ impl ContractSpec { let mut spec_base64 = None; let spec = if let Some(spec) = spec { spec_base64 = Some(base64.encode(spec)); - let cursor = Cursor::new(spec); - let mut depth_limit_read = DepthLimitedRead::new(cursor, 100); - ScSpecEntry::read_xdr_iter(&mut depth_limit_read) - .collect::, xdr::Error>>()? + VecM::::from_xdr(spec)?.into() } else { vec![] }; From 8315a226ef552c7342d761515e9b8d7497b34d54 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Wed, 13 Sep 2023 13:29:07 +0200 Subject: [PATCH 2/2] Remove unused import --- cmd/soroban-cli/src/rpc/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/soroban-cli/src/rpc/mod.rs b/cmd/soroban-cli/src/rpc/mod.rs index f5779e27c..85954369f 100644 --- a/cmd/soroban-cli/src/rpc/mod.rs +++ b/cmd/soroban-cli/src/rpc/mod.rs @@ -4,13 +4,13 @@ use jsonrpsee_core::params::ObjectParams; use jsonrpsee_core::{self, client::ClientT, rpc_params}; use jsonrpsee_http_client::{HeaderMap, HttpClient, HttpClientBuilder}; use serde_aux::prelude::{deserialize_default_from_null, deserialize_number_from_string}; +use soroban_env_host::xdr::SorobanAuthorizedFunction; use soroban_env_host::xdr::{ self, AccountEntry, AccountId, ContractDataEntry, DiagnosticEvent, Error as XdrError, LedgerEntryData, LedgerFootprint, LedgerKey, LedgerKeyAccount, PublicKey, ReadXdr, SorobanAuthorizationEntry, SorobanResources, Transaction, TransactionEnvelope, TransactionMeta, TransactionMetaV3, TransactionResult, TransactionV1Envelope, Uint256, VecM, WriteXdr, }; -use soroban_env_host::xdr::{DepthLimitedRead, SorobanAuthorizedFunction}; use soroban_sdk::token; use std::{ fmt::Display,