Skip to content

Commit

Permalink
fix: use correct config and add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Jun 11, 2024
1 parent b7f4163 commit 4b7829c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl NetworkRunnable for Cmd {
return Ok(TxnResult::Txn(txn));
}
let get_txn_resp = client
.send_transaction_polling(&self.config.sign_with_local_key(txn).await?)
.send_transaction_polling(&config.sign_with_local_key(txn).await?)
.await?
.try_into()?;
if global_args.map_or(true, |a| !a.no_cache) {
Expand Down
45 changes: 39 additions & 6 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ use heck::ToKebabCase;

use soroban_env_host::{
xdr::{
self, Hash, HostFunction, InvokeContractArgs, InvokeHostFunctionOp, LedgerEntryData,
Limits, Memo, MuxedAccount, Operation, OperationBody, Preconditions, PublicKey, ScAddress,
ScSpecEntry, ScSpecFunctionV0, ScSpecTypeDef, ScVal, ScVec, SequenceNumber, String32,
StringM, Transaction, TransactionExt, Uint256, VecM, WriteXdr,
self, AccountEntry, AccountEntryExt, AccountId, Hash, HostFunction, InvokeContractArgs,
InvokeHostFunctionOp, LedgerEntryData, Limits, Memo, MuxedAccount, Operation,
OperationBody, Preconditions, PublicKey, ScAddress, ScSpecEntry, ScSpecFunctionV0,
ScSpecTypeDef, ScVal, ScVec, SequenceNumber, SorobanAuthorizationEntry,
SorobanAuthorizedFunction, SorobanResources, SorobanTransactionData, String32, StringM,
Thresholds, Transaction, TransactionExt, Uint256, VecM, WriteXdr,
},
HostError,
};

use soroban_env_host::xdr::{AccountEntry, AccountEntryExt, AccountId, Thresholds};
use soroban_spec::read::FromWasmError;
use stellar_strkey::DecodeError;

Expand Down Expand Up @@ -375,15 +376,19 @@ impl NetworkRunnable for Cmd {
data::write(sim_res.clone().into(), &network.rpc_uri()?)?;
}
let (return_value, events) = if self.is_view() {
// log_auth_cost_and_footprint(Some(&sim_res.transaction_data()?.resources));
(sim_res.results()?[0].xdr.clone(), sim_res.events()?)
} else {
let global::Args { no_cache, .. } = global_args.cloned().unwrap_or_default();
// Need to sign all auth entries
let mut txn = txn.transaction().clone();
// let auth = auth_entries(&txn);
// crate::log::auth(&[auth]);

if let Some(tx) = config.sign_soroban_authorizations(&txn, &signers).await? {
txn = tx;
}
// let txn = self.config.sign_with_local_key(tx)
// log_auth_cost_and_footprint(resources(&txn));
let res = client
.send_transaction_polling(&config.sign_with_local_key(txn).await?)
.await?;
Expand All @@ -400,6 +405,34 @@ impl NetworkRunnable for Cmd {

const DEFAULT_ACCOUNT_ID: AccountId = AccountId(PublicKey::PublicKeyTypeEd25519(Uint256([0; 32])));

fn log_auth_cost_and_footprint(resources: Option<&SorobanResources>) {
if let Some(resources) = resources {
crate::log::footprint(&resources.footprint);
crate::log::cost(resources);
}
}

fn resources(tx: &Transaction) -> Option<&SorobanResources> {
let TransactionExt::V1(SorobanTransactionData { resources, .. }) = &tx.ext else {
return None;
};
Some(resources)
}

fn auth_entries(tx: &Transaction) -> VecM<SorobanAuthorizationEntry> {
tx.operations
.first()
.and_then(|op| match op.body {
OperationBody::InvokeHostFunction(ref body) => (matches!(
body.auth.first().map(|x| &x.root_invocation.function),
Some(&SorobanAuthorizedFunction::ContractFn(_))
))
.then_some(body.auth.clone()),
_ => None,
})
.unwrap_or_default()
}

fn default_account_entry() -> AccountEntry {
AccountEntry {
account_id: DEFAULT_ACCOUNT_ID,
Expand Down

0 comments on commit 4b7829c

Please sign in to comment.