Skip to content

Commit

Permalink
Output TransactionEnvelope instead of Transaction for --build-only (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored May 10, 2024
1 parent eb69038 commit 38d0fa6
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 48 deletions.
15 changes: 10 additions & 5 deletions cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use soroban_env_host::{
xdr::{
Asset, ContractDataDurability, ContractExecutable, ContractIdPreimage, CreateContractArgs,
Error as XdrError, Hash, HostFunction, InvokeHostFunctionOp, LedgerKey::ContractData,
LedgerKeyContractData, Memo, MuxedAccount, Operation, OperationBody, Preconditions,
ScAddress, ScVal, SequenceNumber, Transaction, TransactionExt, Uint256, VecM,
LedgerKeyContractData, Limits, Memo, MuxedAccount, Operation, OperationBody, Preconditions,
ScAddress, ScVal, SequenceNumber, Transaction, TransactionExt, Uint256, VecM, WriteXdr,
},
HostError,
};
Expand All @@ -15,7 +15,7 @@ use crate::{
commands::{
config::{self, data},
global, network,
txn_result::TxnResult,
txn_result::{TxnEnvelopeResult, TxnResult},
NetworkRunnable,
},
rpc::{Client, Error as SorobanRpcError},
Expand Down Expand Up @@ -67,8 +67,13 @@ pub struct Cmd {

impl Cmd {
pub async fn run(&self) -> Result<(), Error> {
let res_str = self.run_against_rpc_server(None, None).await?;
println!("{res_str}");
let res = self.run_against_rpc_server(None, None).await?.to_envelope();
match res {
TxnEnvelopeResult::TxnEnvelope(tx) => println!("{}", tx.to_xdr_base64(Limits::none())?),
TxnEnvelopeResult::Res(contract) => {
println!("{contract}");
}
}
Ok(())
}
}
Expand Down
17 changes: 11 additions & 6 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use rand::Rng;
use soroban_env_host::{
xdr::{
AccountId, ContractExecutable, ContractIdPreimage, ContractIdPreimageFromAddress,
CreateContractArgs, Error as XdrError, Hash, HostFunction, InvokeHostFunctionOp, Memo,
MuxedAccount, Operation, OperationBody, Preconditions, PublicKey, ScAddress,
SequenceNumber, Transaction, TransactionExt, Uint256, VecM,
CreateContractArgs, Error as XdrError, Hash, HostFunction, InvokeHostFunctionOp, Limits,
Memo, MuxedAccount, Operation, OperationBody, Preconditions, PublicKey, ScAddress,
SequenceNumber, Transaction, TransactionExt, Uint256, VecM, WriteXdr,
},
HostError,
};
Expand All @@ -18,7 +18,7 @@ use crate::commands::{
config::data,
contract::{self, id::wasm::get_contract_id},
global, network,
txn_result::TxnResult,
txn_result::{TxnEnvelopeResult, TxnResult},
NetworkRunnable,
};
use crate::{
Expand Down Expand Up @@ -104,8 +104,13 @@ pub enum Error {

impl Cmd {
pub async fn run(&self) -> Result<(), Error> {
let res_str = self.run_against_rpc_server(None, None).await?;
println!("{res_str}");
let res = self.run_against_rpc_server(None, None).await?.to_envelope();
match res {
TxnEnvelopeResult::TxnEnvelope(tx) => println!("{}", tx.to_xdr_base64(Limits::none())?),
TxnEnvelopeResult::Res(contract) => {
println!("{contract}");
}
}
Ok(())
}
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/soroban-cli/src/commands/contract/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
commands::{
config::{self, data},
global, network,
txn_result::TxnResult,
txn_result::{TxnEnvelopeResult, TxnResult},
NetworkRunnable,
},
key,
Expand Down Expand Up @@ -89,10 +89,10 @@ pub enum Error {
impl Cmd {
#[allow(clippy::too_many_lines)]
pub async fn run(&self) -> Result<(), Error> {
let res = self.run_against_rpc_server(None, None).await?;
let res = self.run_against_rpc_server(None, None).await?.to_envelope();
match res {
TxnResult::Txn(tx) => println!("{}", tx.to_xdr_base64(Limits::none())?),
TxnResult::Res(ttl_ledger) => {
TxnEnvelopeResult::TxnEnvelope(tx) => println!("{}", tx.to_xdr_base64(Limits::none())?),
TxnEnvelopeResult::Res(ttl_ledger) => {
if self.ttl_ledger_only {
println!("{ttl_ledger}");
} else {
Expand Down
10 changes: 5 additions & 5 deletions cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use soroban_env_host::xdr::{

use super::restore;
use crate::commands::network;
use crate::commands::txn_result::TxnResult;
use crate::commands::txn_result::{TxnEnvelopeResult, TxnResult};
use crate::commands::{config::data, global, NetworkRunnable};
use crate::key;
use crate::rpc::{self, Client};
Expand Down Expand Up @@ -73,11 +73,11 @@ pub enum Error {

impl Cmd {
pub async fn run(&self) -> Result<(), Error> {
let res_str = match self.run_against_rpc_server(None, None).await? {
TxnResult::Txn(tx) => tx.to_xdr_base64(Limits::none())?,
TxnResult::Res(hash) => hex::encode(hash),
let res = self.run_against_rpc_server(None, None).await?.to_envelope();
match res {
TxnEnvelopeResult::TxnEnvelope(tx) => println!("{}", tx.to_xdr_base64(Limits::none())?),
TxnEnvelopeResult::Res(hash) => println!("{}", hex::encode(hash)),
};
println!("{res_str}");
Ok(())
}
}
Expand Down
19 changes: 12 additions & 7 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use heck::ToKebabCase;
use soroban_env_host::{
xdr::{
self, Hash, HostFunction, InvokeContractArgs, InvokeHostFunctionOp, LedgerEntryData,
LedgerFootprint, Memo, MuxedAccount, Operation, OperationBody, Preconditions, PublicKey,
ScAddress, ScSpecEntry, ScSpecFunctionV0, ScSpecTypeDef, ScVal, ScVec, SequenceNumber,
SorobanAuthorizationEntry, SorobanResources, String32, StringM, Transaction,
TransactionExt, Uint256, VecM,
LedgerFootprint, Limits, Memo, MuxedAccount, Operation, OperationBody, Preconditions,
PublicKey, ScAddress, ScSpecEntry, ScSpecFunctionV0, ScSpecTypeDef, ScVal, ScVec,
SequenceNumber, SorobanAuthorizationEntry, SorobanResources, String32, StringM,
Transaction, TransactionExt, Uint256, VecM, WriteXdr,
},
HostError,
};
Expand All @@ -31,7 +31,7 @@ use super::super::{
config::{self, locator},
events,
};
use crate::commands::txn_result::TxnResult;
use crate::commands::txn_result::{TxnEnvelopeResult, TxnResult};
use crate::commands::NetworkRunnable;
use crate::{
commands::{config::data, global, network},
Expand Down Expand Up @@ -272,8 +272,13 @@ impl Cmd {
}

pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
let res = self.invoke(global_args).await?;
println!("{res}");
let res = self.invoke(global_args).await?.to_envelope();
match res {
TxnEnvelopeResult::TxnEnvelope(tx) => println!("{}", tx.to_xdr_base64(Limits::none())?),
TxnEnvelopeResult::Res(output) => {
println!("{output}");
}
}
Ok(())
}

Expand Down
11 changes: 6 additions & 5 deletions cmd/soroban-cli/src/commands/contract/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
config::{self, data, locator},
contract::extend,
global, network,
txn_result::TxnResult,
txn_result::{TxnEnvelopeResult, TxnResult},
NetworkRunnable,
},
key,
Expand Down Expand Up @@ -94,12 +94,13 @@ pub enum Error {
impl Cmd {
#[allow(clippy::too_many_lines)]
pub async fn run(&self) -> Result<(), Error> {
let expiration_ledger_seq = match self.run_against_rpc_server(None, None).await? {
TxnResult::Res(res) => res,
TxnResult::Txn(xdr) => {
println!("{}", xdr.to_xdr_base64(Limits::none())?);
let res = self.run_against_rpc_server(None, None).await?.to_envelope();
let expiration_ledger_seq = match res {
TxnEnvelopeResult::TxnEnvelope(tx) => {
println!("{}", tx.to_xdr_base64(Limits::none())?);
return Ok(());
}
TxnEnvelopeResult::Res(res) => res,
};
if let Some(ledgers_to_extend) = self.ledgers_to_extend {
extend::Cmd {
Expand Down
31 changes: 15 additions & 16 deletions cmd/soroban-cli/src/commands/txn_result.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::fmt::{Display, Formatter};

use soroban_env_host::xdr::{Limits, Transaction, WriteXdr};
use soroban_env_host::xdr::{Transaction, TransactionEnvelope, TransactionV1Envelope, VecM};

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum TxnResult<R> {
Expand All @@ -15,21 +13,22 @@ impl<R> TxnResult<R> {
TxnResult::Txn(_) => None,
}
}
}

impl<V> Display for TxnResult<V>
where
V: Display,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
pub fn to_envelope(self) -> TxnEnvelopeResult<R> {
match self {
TxnResult::Txn(tx) => write!(
f,
"{}",
tx.to_xdr_base64(Limits::none())
.map_err(|_| std::fmt::Error)?
),
TxnResult::Res(value) => write!(f, "{value}"),
TxnResult::Txn(tx) => {
TxnEnvelopeResult::TxnEnvelope(TransactionEnvelope::Tx(TransactionV1Envelope {
tx,
signatures: VecM::default(),
}))
}
TxnResult::Res(res) => TxnEnvelopeResult::Res(res),
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum TxnEnvelopeResult<R> {
TxnEnvelope(TransactionEnvelope),
Res(R),
}

0 comments on commit 38d0fa6

Please sign in to comment.