Skip to content

Commit

Permalink
feat: add data logging to all commands that use a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal authored and gitbutler-client committed Mar 7, 2024
1 parent e0fdd4c commit d959977
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
16 changes: 12 additions & 4 deletions cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::convert::Infallible;
use std::{array::TryFromSliceError, fmt::Debug, num::ParseIntError};

use crate::{
commands::{config, global, NetworkRunnable},
commands::{config::{self, data}, global, network, NetworkRunnable},
rpc::{Client, Error as SorobanRpcError},
utils::{contract_id_hash_from_asset, parsing::parse_asset},
};
Expand All @@ -35,6 +35,10 @@ pub enum Error {
Config(#[from] config::Error),
#[error(transparent)]
ParseAssetError(#[from] crate::utils::parsing::Error),
#[error(transparent)]
Data(#[from] data::Error),
#[error(transparent)]
Network(#[from] network::Error),
}

impl From<Infallible> for Error {
Expand Down Expand Up @@ -103,9 +107,13 @@ impl NetworkRunnable for Cmd {
)?;
let txn = client.create_assembled_transaction(&tx).await?;
let txn = self.fee.apply_to_assembled_txn(txn);
client
.send_assembled_transaction(txn, &key, &[], network_passphrase, None, None)
.await?;
data::write(
client
.send_assembled_transaction(txn, &key, &[], network_passphrase, None, None)
.await?
.try_into()?,
network.rpc_uri()?,
)?;

Ok(stellar_strkey::Contract(contract_id.0).to_string())
}
Expand Down
11 changes: 7 additions & 4 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use soroban_env_host::{
};

use crate::commands::{
contract::{self, id::wasm::get_contract_id},
global, NetworkRunnable,
config::data, contract::{self, id::wasm::get_contract_id}, global, network, NetworkRunnable
};
use crate::{
commands::{config, contract::install, HEADING_RPC},
Expand Down Expand Up @@ -91,6 +90,10 @@ pub enum Error {
Infallible(#[from] std::convert::Infallible),
#[error(transparent)]
WasmId(#[from] contract::id::wasm::Error),
#[error(transparent)]
Data(#[from] data::Error),
#[error(transparent)]
Network(#[from] network::Error),
}

impl Cmd {
Expand Down Expand Up @@ -166,9 +169,9 @@ impl NetworkRunnable for Cmd {
)?;
let txn = client.create_assembled_transaction(&txn).await?;
let txn = self.fee.apply_to_assembled_txn(txn);
client
data::write(client
.send_assembled_transaction(txn, &key, &[], &network.network_passphrase, None, None)
.await?;
.await?.try_into().unwrap(), network.rpc_uri()?)?;
Ok(stellar_strkey::Contract(contract_id.0).to_string())
}
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/soroban-cli/src/commands/contract/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use soroban_env_host::xdr::{
};

use crate::{
commands::{config, global, NetworkRunnable},
commands::{config::{self, data}, global, network, NetworkRunnable},
key,
rpc::{self, Client},
wasm, Pwd,
Expand Down Expand Up @@ -75,6 +75,10 @@ pub enum Error {
Wasm(#[from] wasm::Error),
#[error(transparent)]
Key(#[from] key::Error),
#[error(transparent)]
Data(#[from] data::Error),
#[error(transparent)]
Network(#[from] network::Error),
}

impl Cmd {
Expand Down Expand Up @@ -158,6 +162,7 @@ impl NetworkRunnable for Cmd {
let res = client
.prepare_and_send_transaction(&tx, &key, &[], &network.network_passphrase, None, None)
.await?;
data::write(res.clone().try_into()?, network.rpc_uri()?)?;

let events = res.events()?;
if !events.is_empty() {
Expand Down
18 changes: 11 additions & 7 deletions cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use soroban_env_host::xdr::{
};

use super::restore;
use crate::commands::{global, NetworkRunnable};
use crate::commands::network;
use crate::commands::{global, NetworkRunnable,config::data};
use crate::key;
use crate::rpc::{self, Client};
use crate::{commands::config, utils, wasm};
Expand Down Expand Up @@ -62,6 +63,10 @@ pub enum Error {
wasm: std::path::PathBuf,
version: String,
},
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
Data(#[from] data::Error),
}

impl Cmd {
Expand Down Expand Up @@ -130,16 +135,15 @@ impl NetworkRunnable for Cmd {
.create_assembled_transaction(&tx_without_preflight)
.await?;
let txn = self.fee.apply_to_assembled_txn(txn);

let txn_resp = client
.send_assembled_transaction(txn, &key, &[], &network.network_passphrase, None, None)
.await?;
data::write(txn_resp.clone().try_into().unwrap(), network.rpc_uri()?)?;
// Currently internal errors are not returned if the contract code is expired
if let Some(TransactionResult {
result: TransactionResultResult::TxInternalError,
..
}) = client
.send_assembled_transaction(txn, &key, &[], &network.network_passphrase, None, None)
.await?
.result
.as_ref()
}) = txn_resp.result.as_ref()
{
// Now just need to restore it and don't have to install again
restore::Cmd {
Expand Down
10 changes: 6 additions & 4 deletions cmd/soroban-cli/src/commands/contract/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use stellar_strkey::DecodeError;

use crate::{
commands::{
config::{self, locator},
contract::extend,
global, NetworkRunnable,
config::{self, data, locator}, contract::extend, global, network, NetworkRunnable
},
key,
rpc::{self, Client},
Expand Down Expand Up @@ -83,6 +81,10 @@ pub enum Error {
Key(#[from] key::Error),
#[error(transparent)]
Extend(#[from] extend::Error),
#[error(transparent)]
Data(#[from] data::Error),
#[error(transparent)]
Network(#[from] network::Error),
}

impl Cmd {
Expand Down Expand Up @@ -162,7 +164,7 @@ impl NetworkRunnable for Cmd {
let res = client
.prepare_and_send_transaction(&tx, &key, &[], &network.network_passphrase, None, None)
.await?;

data::write(res.clone().try_into()?, network.rpc_uri()?)?;
let meta = res
.result_meta
.as_ref()
Expand Down

0 comments on commit d959977

Please sign in to comment.