From 7418e250035d6f1b0e6b80d1d677d903cad96b40 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 6 Sep 2023 11:44:06 -0400 Subject: [PATCH] fix: rebase to main --- cmd/soroban-cli/src/rpc/mod.rs | 41 +++++--------------------- cmd/soroban-cli/src/rpc/transaction.rs | 20 ++++++++----- 2 files changed, 21 insertions(+), 40 deletions(-) diff --git a/cmd/soroban-cli/src/rpc/mod.rs b/cmd/soroban-cli/src/rpc/mod.rs index 21f03cf28d..db5cc72f28 100644 --- a/cmd/soroban-cli/src/rpc/mod.rs +++ b/cmd/soroban-cli/src/rpc/mod.rs @@ -201,18 +201,7 @@ pub struct SimulateHostFunctionResult { pub xdr: String, } -#[derive(serde::Deserialize, serde::Serialize, Debug)] -pub struct SimulateTransactionResponseRestorePreamble { - #[serde(rename = "transactionData")] - pub transaction_data: String, - #[serde( - rename = "minResourceFee", - deserialize_with = "deserialize_number_from_string" - )] - pub min_resource_fee: u32, -} - -#[derive(serde::Deserialize, serde::Serialize, Debug)] +#[derive(serde::Deserialize, serde::Serialize, Debug, Default)] pub struct SimulateTransactionResponse { #[serde( rename = "minResourceFee", @@ -243,13 +232,11 @@ pub struct SimulateTransactionResponse { deserialize_with = "deserialize_number_from_string" )] pub latest_ledger: u32, - #[serde(rename = "restorePreamble")] - restore_preamble: Option, #[serde(skip_serializing_if = "Option::is_none", default)] pub error: Option, } -#[derive(serde::Deserialize, serde::Serialize, Debug)] +#[derive(serde::Deserialize, serde::Serialize, Debug, Default)] pub struct RestorePreamble { #[serde(rename = "transactionData")] pub transaction_data: String, @@ -639,13 +626,7 @@ soroban config identity fund {address} --helper-url "# pub async fn prepare_transaction( &self, tx: &Transaction, - ) -> Result< - ( - Transaction, - Option, - ), - Error, - > { + ) -> Result<(Transaction, Option), Error> { tracing::trace!(?tx); let sim_response = self .simulate_transaction(&TransactionEnvelope::Tx(TransactionV1Envelope { @@ -653,10 +634,7 @@ soroban config identity fund {address} --helper-url "# signatures: VecM::default(), })) .await?; - Ok(( - assemble(tx, &sim_response, log_events)?, - sim_response.restore_preamble, - )) + Ok((assemble(tx, &sim_response)?, sim_response.restore_preamble)) } pub async fn prepare_and_send_transaction( @@ -669,9 +647,8 @@ soroban config identity fund {address} --helper-url "# log_resources: Option, ) -> Result<(TransactionResult, TransactionMeta, Vec), Error> { let GetLatestLedgerResponse { sequence, .. } = self.get_latest_ledger().await?; - let (mut unsigned_tx, restore_preamble) = self - .prepare_transaction(tx_without_preflight, log_events) - .await?; + let (mut unsigned_tx, restore_preamble) = + self.prepare_transaction(tx_without_preflight).await?; if let Some(restore) = restore_preamble { // Build and submit the restore transaction self.send_transaction(&utils::sign_transaction( @@ -699,9 +676,7 @@ soroban config identity fund {address} --helper-url "# (part_signed_tx, events) } else { // re-simulate to calculate the new fees - self.prepare_transaction(&part_signed_tx, log_events) - .await? - .0 + self.prepare_transaction(&part_signed_tx).await?.0 }; // Try logging stuff if requested @@ -719,7 +694,7 @@ soroban config identity fund {address} --helper-url "# .. } = &fee_ready_txn.operations[0] { - log(&resources.footprint, &[auth.clone()], &events); + log(&resources.footprint, &[auth.clone()], &[]); } } if let Some(log) = log_resources { diff --git a/cmd/soroban-cli/src/rpc/transaction.rs b/cmd/soroban-cli/src/rpc/transaction.rs index 57a5dd4aec..520fa3601b 100644 --- a/cmd/soroban-cli/src/rpc/transaction.rs +++ b/cmd/soroban-cli/src/rpc/transaction.rs @@ -1,13 +1,14 @@ use ed25519_dalek::Signer; use sha2::{Digest, Sha256}; use soroban_env_host::xdr::{ - AccountId, Hash, HashIdPreimage, HashIdPreimageSorobanAuthorization, OperationBody, PublicKey, - ReadXdr, ScAddress, ScMap, ScSymbol, ScVal, SorobanAddressCredentials, - SorobanAuthorizationEntry, SorobanCredentials, SorobanTransactionData, Transaction, - TransactionExt, Uint256, VecM, WriteXdr, + AccountId, ExtensionPoint, Hash, HashIdPreimage, HashIdPreimageSorobanAuthorization, Memo, + Operation, OperationBody, Preconditions, PublicKey, ReadXdr, RestoreFootprintOp, ScAddress, + ScMap, ScSymbol, ScVal, SorobanAddressCredentials, SorobanAuthorizationEntry, + SorobanCredentials, SorobanTransactionData, Transaction, TransactionExt, Uint256, VecM, + WriteXdr, }; -use crate::rpc::{Error, SimulateTransactionResponse}; +use crate::rpc::{Error, RestorePreamble, SimulateTransactionResponse}; // Apply the result of a simulateTransaction onto a transaction envelope, preparing it for // submission to the network. @@ -215,13 +216,18 @@ pub fn sign_soroban_authorization_entry( pub fn build_restore_txn( parent: &Transaction, - restore: &SimulateTransactionResponseRestorePreamble, + restore: &RestorePreamble, ) -> Result { let transaction_data = SorobanTransactionData::from_xdr_base64(restore.transaction_data.clone())?; + let fee = u32::try_from(restore.min_resource_fee) + .map_err(|_| Error::LargeFee(restore.min_resource_fee))?; Ok(Transaction { source_account: parent.source_account.clone(), - fee: parent.fee + restore.min_resource_fee, + fee: parent + .fee + .checked_add(fee) + .ok_or(Error::LargeFee(restore.min_resource_fee))?, seq_num: parent.seq_num.clone(), cond: Preconditions::None, memo: Memo::None,