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 4d583ae
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 30 deletions.
7 changes: 4 additions & 3 deletions cmd/soroban-cli/src/commands/config/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,18 @@ pub fn list_ulids() -> Result<Vec<ulid::Ulid>, Error> {
list.sort();
Ok(list
.iter()
.map(|s|ulid::Ulid::from_str(s))
.map(|s| ulid::Ulid::from_str(s))
.collect::<Result<Vec<_>, _>>()?)
}

pub fn list_actions() -> Result<Vec<(ulid::Ulid, Action, Uri)>, Error> {
list_ulids()?.into_iter()
list_ulids()?
.into_iter()
.map(|id| {
let (action, uri) = read(&id)?;
Ok((id, action, uri))
})
.collect::<Result<Vec<_>,Error>>()
.collect::<Result<Vec<_>, Error>>()
}

#[derive(Serialize, Deserialize)]
Expand Down
19 changes: 15 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,10 @@ 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 +38,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 +110,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
18 changes: 14 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,9 @@ use soroban_env_host::{
};

use crate::commands::{
config::data,
contract::{self, id::wasm::get_contract_id},
global, NetworkRunnable,
global, network, NetworkRunnable,
};
use crate::{
commands::{config, contract::install, HEADING_RPC},
Expand Down Expand Up @@ -91,6 +92,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 +171,14 @@ impl NetworkRunnable for Cmd {
)?;
let txn = client.create_assembled_transaction(&txn).await?;
let txn = self.fee.apply_to_assembled_txn(txn);
client
.send_assembled_transaction(txn, &key, &[], &network.network_passphrase, None, None)
.await?;
data::write(
client
.send_assembled_transaction(txn, &key, &[], &network.network_passphrase, None, None)
.await?
.try_into()
.unwrap(),
network.rpc_uri()?,
)?;
Ok(stellar_strkey::Contract(contract_id.0).to_string())
}
}
Expand Down
10 changes: 9 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,10 @@ 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 +78,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 +165,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::{config::data, global, NetworkRunnable};
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
11 changes: 5 additions & 6 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ use super::super::{
events,
};
use crate::commands::NetworkRunnable;
use crate::{commands::{global, config::data, network}, rpc, Pwd};
use crate::{
commands::{config::data, global, network},
rpc, Pwd,
};
use soroban_spec_tools::{contract, Spec};

#[derive(Parser, Debug, Default, Clone)]
Expand Down Expand Up @@ -345,11 +348,7 @@ impl NetworkRunnable for Cmd {
let sim_res = txn.sim_response();
data::write(sim_res.clone().into(), network.rpc_uri()?)?;
let (return_value, events) = if self.is_view() {
(
sim_res.results()?[0].xdr.clone(),
sim_res.events()?,

)
(sim_res.results()?[0].xdr.clone(), sim_res.events()?)
} else {
let global::Args {
verbose,
Expand Down
10 changes: 7 additions & 3 deletions cmd/soroban-cli/src/commands/contract/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use stellar_strkey::DecodeError;

use crate::{
commands::{
config::{self, locator},
config::{self, data, locator},
contract::extend,
global, NetworkRunnable,
global, network, NetworkRunnable,
},
key,
rpc::{self, Client},
Expand Down Expand Up @@ -83,6 +83,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 +166,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
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/data/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod ls;
pub mod ls;
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
clippy::must_use_candidate,
clippy::missing_panics_doc
)]
pub(crate) use soroban_rpc as rpc;
pub(crate) use soroban_env_host::xdr;
pub(crate) use soroban_rpc as rpc;
use std::path::Path;

pub mod commands;
Expand Down

0 comments on commit 4d583ae

Please sign in to comment.