Skip to content

Commit

Permalink
refactored print_transaction_status()
Browse files Browse the repository at this point in the history
  • Loading branch information
FroVolod committed Mar 3, 2025
1 parent bc96dfe commit 86df900
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
17 changes: 15 additions & 2 deletions src/commands/contract/call_function/as_read_only/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ impl FunctionContext {
let function_name = scope.function_name.clone();

move |network_config, block_reference| {
call_view_function(network_config, &account_id, &function_name, function_args.clone(), function_args_type.clone(), block_reference)
call_view_function(
network_config,
&account_id,
&function_name,
function_args.clone(),
function_args_type.clone(),
block_reference,
&previous_context.global_context.verbosity,
)
}
});

Expand Down Expand Up @@ -117,6 +125,7 @@ fn call_view_function(
function_args: String,
function_args_type: super::call_function_args_type::FunctionArgsType,
block_reference: &near_primitives::types::BlockReference,
verbosity: &crate::Verbosity,
) -> crate::CliResult {
let args = super::call_function_args_type::function_args(function_args, function_args_type)?;
let call_result = network_config
Expand All @@ -142,10 +151,14 @@ fn call_view_function(
} else {
info_str.push_str("\nThe returned value is not printable (binary data)");
}

if let crate::Verbosity::Quiet = verbosity {
println!("{}", info_str);
};
info_str.push_str("\n------------------------------------");
tracing::info!(
parent: &tracing::Span::none(),
"--- Result -------------------------{}\n",
"--- Result -------------------------\n{}",
crate::common::indent_payload(&info_str)
);
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/commands/transaction/send_signed_transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum SignedTransactionType {

#[derive(Debug, Clone)]
pub struct SignedTransactionContext {
config: crate::config::Config,
global_context: crate::GlobalContext,
signed_transaction: near_primitives::transaction::SignedTransaction,
}

Expand All @@ -54,7 +54,7 @@ impl Base64SignedTransactionContext {
scope: &<Base64SignedTransaction as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
Ok(Self(SignedTransactionContext {
config: previous_context.config,
global_context: previous_context,
signed_transaction: scope.signed_action.inner.clone(),
}))
}
Expand Down Expand Up @@ -99,7 +99,7 @@ impl FileWithBase64SignedTransactionContext {
.signed_transaction;

Ok(Self(SignedTransactionContext {
config: previous_context.config,
global_context: previous_context,
signed_transaction,
}))
}
Expand Down
11 changes: 9 additions & 2 deletions src/commands/transaction/send_signed_transaction/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct Network {

#[derive(Debug, Clone)]
pub struct NetworkContext {
global_context: crate::GlobalContext,
signed_transaction: near_primitives::transaction::SignedTransaction,
network_config: crate::config::NetworkConfig,
}
Expand All @@ -24,13 +25,15 @@ impl NetworkContext {
scope: &<Network as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let network_config = previous_context
.global_context
.config
.network_connection
.get(&scope.network_name)
.wrap_err("Failed to get network config!")?
.clone();

Ok(Self {
global_context: previous_context.global_context,
signed_transaction: previous_context.signed_transaction,
network_config,
})
Expand All @@ -42,7 +45,7 @@ impl Network {
context: &super::SignedTransactionContext,
) -> color_eyre::eyre::Result<Option<String>> {
crate::common::input_network_name(
&context.config,
&context.global_context.config,
&[context.signed_transaction.transaction.receiver_id().clone()],
)
}
Expand Down Expand Up @@ -73,6 +76,10 @@ impl SubmitContext {
&previous_context.signed_transaction,
)?;

crate::common::print_transaction_status(&transaction_info, &previous_context.network_config)
crate::common::print_transaction_status(
&transaction_info,
&previous_context.network_config,
&previous_context.global_context.verbosity,
)
}
}
1 change: 1 addition & 0 deletions src/transaction_signature_options/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl SendContext {
crate::common::print_transaction_status(
&transaction_info,
&previous_context.network_config,
&previous_context.global_context.verbosity,
)?;

(previous_context.on_after_sending_transaction_callback)(
Expand Down

0 comments on commit 86df900

Please sign in to comment.