utility_cli_rs/commands/transaction/construct_transaction/
mod.rs1pub mod add_action_1;
2pub mod add_action_2;
3pub mod add_action_3;
4pub mod add_action_last;
5pub mod skip_action;
6
7#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
8#[interactive_clap(input_context = crate::GlobalContext)]
9#[interactive_clap(output_context = ConstructTransactionContext)]
10pub struct ConstructTransaction {
11 #[interactive_clap(skip_default_input_arg)]
12 pub sender_account_id: crate::types::account_id::AccountId,
14 #[interactive_clap(skip_default_input_arg)]
15 pub receiver_account_id: crate::types::account_id::AccountId,
17 #[interactive_clap(subcommand)]
18 pub next_actions: self::add_action_1::NextAction,
19}
20
21#[derive(Debug, Clone)]
22pub struct ConstructTransactionContext {
23 pub global_context: crate::GlobalContext,
24 pub signer_account_id: unc_primitives::types::AccountId,
25 pub receiver_account_id: unc_primitives::types::AccountId,
26 pub actions: Vec<unc_primitives::transaction::Action>,
27}
28
29impl ConstructTransactionContext {
30 pub fn from_previous_context(
31 previous_context: crate::GlobalContext,
32 scope: &<ConstructTransaction as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
33 ) -> color_eyre::eyre::Result<Self> {
34 Ok(Self {
35 global_context: previous_context,
36 signer_account_id: scope.sender_account_id.clone().into(),
37 receiver_account_id: scope.receiver_account_id.clone().into(),
38 actions: vec![],
39 })
40 }
41}
42
43impl ConstructTransaction {
44 pub fn input_sender_account_id(
45 context: &crate::GlobalContext,
46 ) -> color_eyre::eyre::Result<Option<crate::types::account_id::AccountId>> {
47 crate::common::input_signer_account_id_from_used_account_list(
48 &context.config.credentials_home_dir,
49 "What is the sender account ID?",
50 )
51 }
52
53 pub fn input_receiver_account_id(
54 context: &crate::GlobalContext,
55 ) -> color_eyre::eyre::Result<Option<crate::types::account_id::AccountId>> {
56 crate::common::input_non_signer_account_id_from_used_account_list(
57 &context.config.credentials_home_dir,
58 "What is the receiver account ID?",
59 )
60 }
61}