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

Revert "cli: Remove explicit decoding depths" #958

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 8 additions & 4 deletions cmd/soroban-cli/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -519,8 +519,9 @@ soroban config identity fund {address} --helper-url <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::from_xdr_base64(ledger_entry.xdr.as_bytes())?
LedgerEntryData::read_xdr_base64(&mut depth_limit_read)?
{
tracing::trace!(account=?entry);
Ok(entry)
Expand Down Expand Up @@ -549,8 +550,11 @@ soroban config identity fund {address} --helper-url <url>"#
let error = error_result_xdr
.ok_or(Error::MissingError)
.and_then(|x| {
TransactionResult::from_xdr_base64(x.as_bytes())
.map_err(|_| Error::InvalidResponse)
TransactionResult::read_xdr_base64(&mut DepthLimitedRead::new(
x.as_bytes(),
100,
))
.map_err(|_| Error::InvalidResponse)
})
.map(|r| r.result);
tracing::error!(?error);
Expand Down
26 changes: 19 additions & 7 deletions cmd/soroban-cli/src/utils/contract_spec.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use base64::{engine::general_purpose::STANDARD as base64, Engine as _};
use std::{fmt::Display, io};
use std::{
fmt::Display,
io::{self, Cursor},
};

use soroban_env_host::xdr::{
self, ReadXdr, ScEnvMetaEntry, ScMetaEntry, ScMetaV0, ScSpecEntry, ScSpecFunctionV0,
ScSpecUdtEnumV0, ScSpecUdtErrorEnumV0, ScSpecUdtStructV0, ScSpecUdtUnionV0, StringM, WriteXdr,
self, DepthLimitedRead, 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<String>,
Expand Down Expand Up @@ -56,23 +59,32 @@ 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));
VecM::<ScEnvMetaEntry>::from_xdr(env_meta)?.into()
let cursor = Cursor::new(env_meta);
let mut depth_limit_read = DepthLimitedRead::new(cursor, 100);
ScEnvMetaEntry::read_xdr_iter(&mut depth_limit_read)
.collect::<Result<Vec<_>, xdr::Error>>()?
} else {
vec![]
};

let mut meta_base64 = None;
let meta = if let Some(meta) = meta {
meta_base64 = Some(base64.encode(meta));
VecM::<ScMetaEntry>::from_xdr(meta)?.into()
let cursor = Cursor::new(meta);
let mut depth_limit_read = DepthLimitedRead::new(cursor, 100);
ScMetaEntry::read_xdr_iter(&mut depth_limit_read)
.collect::<Result<Vec<_>, xdr::Error>>()?
} else {
vec![]
};

let mut spec_base64 = None;
let spec = if let Some(spec) = spec {
spec_base64 = Some(base64.encode(spec));
VecM::<ScSpecEntry>::from_xdr(spec)?.into()
let cursor = Cursor::new(spec);
let mut depth_limit_read = DepthLimitedRead::new(cursor, 100);
ScSpecEntry::read_xdr_iter(&mut depth_limit_read)
.collect::<Result<Vec<_>, xdr::Error>>()?
} else {
vec![]
};
Expand Down
Loading