diff --git a/cmd/soroban-cli/src/commands/contract/deploy/asset.rs b/cmd/soroban-cli/src/commands/contract/deploy/asset.rs index 1f8d4544f..2f78a0dd6 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy/asset.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy/asset.rs @@ -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, }; @@ -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}, @@ -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(()) } } diff --git a/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs b/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs index dc4632043..0b944c78a 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs @@ -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, }; @@ -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::{ @@ -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(()) } } diff --git a/cmd/soroban-cli/src/commands/contract/extend.rs b/cmd/soroban-cli/src/commands/contract/extend.rs index 117568c20..544fdde3d 100644 --- a/cmd/soroban-cli/src/commands/contract/extend.rs +++ b/cmd/soroban-cli/src/commands/contract/extend.rs @@ -12,7 +12,7 @@ use crate::{ commands::{ config::{self, data}, global, network, - txn_result::TxnResult, + txn_result::{TxnEnvelopeResult, TxnResult}, NetworkRunnable, }, key, @@ -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 { diff --git a/cmd/soroban-cli/src/commands/contract/install.rs b/cmd/soroban-cli/src/commands/contract/install.rs index 4e1b83d9a..39b039792 100644 --- a/cmd/soroban-cli/src/commands/contract/install.rs +++ b/cmd/soroban-cli/src/commands/contract/install.rs @@ -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}; @@ -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(()) } } diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index ef1fd7db1..e9c30598f 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -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, }; @@ -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}, @@ -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(()) } diff --git a/cmd/soroban-cli/src/commands/contract/restore.rs b/cmd/soroban-cli/src/commands/contract/restore.rs index f78316886..ad824d34e 100644 --- a/cmd/soroban-cli/src/commands/contract/restore.rs +++ b/cmd/soroban-cli/src/commands/contract/restore.rs @@ -14,7 +14,7 @@ use crate::{ config::{self, data, locator}, contract::extend, global, network, - txn_result::TxnResult, + txn_result::{TxnEnvelopeResult, TxnResult}, NetworkRunnable, }, key, @@ -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 { diff --git a/cmd/soroban-cli/src/commands/txn_result.rs b/cmd/soroban-cli/src/commands/txn_result.rs index 6b189f25b..08482e94f 100644 --- a/cmd/soroban-cli/src/commands/txn_result.rs +++ b/cmd/soroban-cli/src/commands/txn_result.rs @@ -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 { @@ -15,21 +13,22 @@ impl TxnResult { TxnResult::Txn(_) => None, } } -} -impl Display for TxnResult -where - V: Display, -{ - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + pub fn to_envelope(self) -> TxnEnvelopeResult { 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 { + TxnEnvelope(TransactionEnvelope), + Res(R), +}