Skip to content

Commit

Permalink
fix: rebase to main
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Sep 11, 2023
1 parent 6aa54de commit 7418e25
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 40 deletions.
41 changes: 8 additions & 33 deletions cmd/soroban-cli/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -243,13 +232,11 @@ pub struct SimulateTransactionResponse {
deserialize_with = "deserialize_number_from_string"
)]
pub latest_ledger: u32,
#[serde(rename = "restorePreamble")]
restore_preamble: Option<SimulateTransactionResponseRestorePreamble>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub error: Option<String>,
}

#[derive(serde::Deserialize, serde::Serialize, Debug)]
#[derive(serde::Deserialize, serde::Serialize, Debug, Default)]
pub struct RestorePreamble {
#[serde(rename = "transactionData")]
pub transaction_data: String,
Expand Down Expand Up @@ -639,24 +626,15 @@ soroban config identity fund {address} --helper-url <url>"#
pub async fn prepare_transaction(
&self,
tx: &Transaction,
) -> Result<
(
Transaction,
Option<SimulateTransactionResponseRestorePreamble>,
),
Error,
> {
) -> Result<(Transaction, Option<RestorePreamble>), Error> {
tracing::trace!(?tx);
let sim_response = self
.simulate_transaction(&TransactionEnvelope::Tx(TransactionV1Envelope {
tx: tx.clone(),
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(
Expand All @@ -669,9 +647,8 @@ soroban config identity fund {address} --helper-url <url>"#
log_resources: Option<LogResources>,
) -> Result<(TransactionResult, TransactionMeta, Vec<DiagnosticEvent>), 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(
Expand Down Expand Up @@ -699,9 +676,7 @@ soroban config identity fund {address} --helper-url <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
Expand All @@ -719,7 +694,7 @@ soroban config identity fund {address} --helper-url <url>"#
..
} = &fee_ready_txn.operations[0]
{
log(&resources.footprint, &[auth.clone()], &events);
log(&resources.footprint, &[auth.clone()], &[]);
}
}
if let Some(log) = log_resources {
Expand Down
20 changes: 13 additions & 7 deletions cmd/soroban-cli/src/rpc/transaction.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -215,13 +216,18 @@ pub fn sign_soroban_authorization_entry(

pub fn build_restore_txn(
parent: &Transaction,
restore: &SimulateTransactionResponseRestorePreamble,
restore: &RestorePreamble,
) -> Result<Transaction, Error> {
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,
Expand Down

0 comments on commit 7418e25

Please sign in to comment.