Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added load waiting indicators for "transaction" group commands #358

Merged
merged 10 commits into from
Jul 2, 2024
30 changes: 15 additions & 15 deletions src/commands/account/add_key/access_key_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ pub struct FunctionCallType {
#[interactive_clap(skip_default_input_arg)]
allowance: crate::types::near_allowance::NearAllowance,
#[interactive_clap(long)]
/// Enter a receiver to use by this access key to pay for function call gas and transaction fees:
receiver_account_id: crate::types::account_id::AccountId,
/// You chose to limit the access key to only sign transactions for a specific contract. Enter the contract account ID:
contract_account_id: crate::types::account_id::AccountId,
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
method_names: crate::types::vec_string::VecString,
function_names: crate::types::vec_string::VecString,
#[interactive_clap(subcommand)]
access_key_mode: super::AccessKeyMode,
}
Expand All @@ -69,8 +69,8 @@ pub struct FunctionCallTypeContext {
global_context: crate::GlobalContext,
signer_account_id: near_primitives::types::AccountId,
allowance: Option<crate::types::near_token::NearToken>,
receiver_account_id: crate::types::account_id::AccountId,
method_names: crate::types::vec_string::VecString,
contract_account_id: crate::types::account_id::AccountId,
function_names: crate::types::vec_string::VecString,
}

impl FunctionCallTypeContext {
Expand All @@ -82,8 +82,8 @@ impl FunctionCallTypeContext {
global_context: previous_context.global_context,
signer_account_id: previous_context.owner_account_id.into(),
allowance: scope.allowance.optional_near_token(),
receiver_account_id: scope.receiver_account_id.clone(),
method_names: scope.method_names.clone(),
contract_account_id: scope.contract_account_id.clone(),
function_names: scope.function_names.clone(),
})
}
}
Expand All @@ -96,16 +96,16 @@ impl From<FunctionCallTypeContext> for AccessTypeContext {
permission: near_primitives::account::AccessKeyPermission::FunctionCall(
near_primitives::account::FunctionCallPermission {
allowance: item.allowance.map(|allowance| allowance.as_yoctonear()),
receiver_id: item.receiver_account_id.to_string(),
method_names: item.method_names.into(),
receiver_id: item.contract_account_id.to_string(),
method_names: item.function_names.into(),
},
),
}
}
}

impl FunctionCallType {
pub fn input_method_names(
pub fn input_function_names(
_context: &super::AddKeyCommandContext,
) -> color_eyre::eyre::Result<Option<crate::types::vec_string::VecString>> {
#[derive(strum_macros::Display)]
Expand All @@ -125,16 +125,16 @@ impl FunctionCallType {
)
.prompt()?;
if let ConfirmOptions::Yes = select_choose_input {
let mut input_method_names = Text::new("Enter a comma-separated list of method names that will be allowed to be called in a transaction signed by this access key:")
let mut input_function_names = Text::new("Enter a comma-separated list of function names that will be allowed to be called in a transaction signed by this access key:")
.prompt()?;
if input_method_names.contains('\"') {
input_method_names.clear()
if input_function_names.contains('\"') {
input_function_names.clear()
};
if input_method_names.is_empty() {
if input_function_names.is_empty() {
Ok(Some(crate::types::vec_string::VecString(vec![])))
} else {
Ok(Some(crate::types::vec_string::VecString::from_str(
&input_method_names,
&input_function_names,
)?))
}
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/commands/account/delete_account/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use color_eyre::owo_colors::OwoColorize;
use inquire::Select;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
Expand Down Expand Up @@ -124,6 +125,11 @@ impl BeneficiaryAccount {
return Ok(None);
};

if beneficiary_account_id.0 == context.account_id {
eprintln!("{}", "You have selected a beneficiary account ID that will now be deleted. This will result in the loss of your funds. So make your choice again.".red());
continue;
}

if context.global_context.offline {
return Ok(Some(beneficiary_account_id));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ impl From<FullAccessTypeContext> for AccessKeyPermissionContext {
pub struct FunctionCallType {
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
allowance: crate::types::near_token::NearToken,
allowance: crate::types::near_allowance::NearAllowance,
#[interactive_clap(long)]
/// Enter a receiver to use by this access key to pay for function call gas and transaction fees:
receiver_account_id: crate::types::account_id::AccountId,
/// You chose to limit the access key to only sign transactions for a specific contract. Enter the contract account ID:
contract_account_id: crate::types::account_id::AccountId,
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
method_names: crate::types::vec_string::VecString,
function_names: crate::types::vec_string::VecString,
#[interactive_clap(subcommand)]
access_key_mode: super::AccessKeyMode,
}
Expand All @@ -70,9 +70,12 @@ impl FunctionCallTypeContext {
) -> color_eyre::eyre::Result<Self> {
let access_key_permission = near_primitives::account::AccessKeyPermission::FunctionCall(
near_primitives::account::FunctionCallPermission {
allowance: Some(scope.allowance.as_yoctonear()),
receiver_id: scope.receiver_account_id.to_string(),
method_names: scope.method_names.clone().into(),
allowance: scope
.allowance
.optional_near_token()
.map(|allowance| allowance.as_yoctonear()),
receiver_id: scope.contract_account_id.to_string(),
method_names: scope.function_names.clone().into(),
},
);
Ok(Self(AccessKeyPermissionContext {
Expand All @@ -92,7 +95,7 @@ impl From<FunctionCallTypeContext> for AccessKeyPermissionContext {
}

impl FunctionCallType {
pub fn input_method_names(
pub fn input_function_names(
_context: &super::super::super::super::ConstructTransactionContext,
) -> color_eyre::eyre::Result<Option<crate::types::vec_string::VecString>> {
eprintln!();
Expand All @@ -111,17 +114,17 @@ impl FunctionCallType {
)
.prompt()?;
if let ConfirmOptions::Yes = select_choose_input {
let mut input_method_names =
Text::new("Enter a comma-separated list of method names that will be allowed to be called in a transaction signed by this access key:")
let mut input_function_names =
Text::new("Enter a comma-separated list of function names that will be allowed to be called in a transaction signed by this access key:")
.prompt()?;
if input_method_names.contains('\"') {
input_method_names.clear()
if input_function_names.contains('\"') {
input_function_names.clear()
};
if input_method_names.is_empty() {
if input_function_names.is_empty() {
Ok(Some(crate::types::vec_string::VecString(vec![])))
} else {
Ok(Some(crate::types::vec_string::VecString::from_str(
&input_method_names,
&input_function_names,
)?))
}
} else {
Expand All @@ -131,10 +134,10 @@ impl FunctionCallType {

pub fn input_allowance(
_context: &super::super::super::super::ConstructTransactionContext,
) -> color_eyre::eyre::Result<Option<crate::types::near_token::NearToken>> {
let allowance_near_balance: crate::types::near_token::NearToken =
) -> color_eyre::eyre::Result<Option<crate::types::near_allowance::NearAllowance>> {
let allowance_near_balance: crate::types::near_allowance::NearAllowance =
CustomType::new("Enter the allowance, a budget this access key can use to pay for transaction fees (example: 10NEAR or 0.5near or 10000yoctonear):")
.with_starting_input("0.25 NEAR")
.with_starting_input("unlimited")
.prompt()?;
Ok(Some(allowance_near_balance))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use inquire::CustomType;
#[interactive_clap(input_context = super::super::super::ConstructTransactionContext)]
#[interactive_clap(output_context = FunctionCallActionContext)]
pub struct FunctionCallAction {
#[interactive_clap(skip_default_input_arg)]
/// What is the name of the function?
function_name: String,
#[interactive_clap(value_enum)]
Expand Down Expand Up @@ -58,6 +59,15 @@ impl FunctionCallAction {
crate::commands::contract::call_function::call_function_args_type::input_function_args_type(
)
}

fn input_function_name(
context: &super::super::super::ConstructTransactionContext,
) -> color_eyre::eyre::Result<Option<String>> {
crate::commands::contract::call_function::input_call_function_name(
&context.global_context,
&context.receiver_account_id,
)
}
}

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use inquire::{CustomType, Select};
use color_eyre::owo_colors::OwoColorize;
use inquire::Select;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = super::super::super::ConstructTransactionContext)]
Expand Down Expand Up @@ -46,8 +47,20 @@ impl DeleteAccountAction {
context: &super::super::super::ConstructTransactionContext,
) -> color_eyre::eyre::Result<Option<crate::types::account_id::AccountId>> {
loop {
let beneficiary_account_id: crate::types::account_id::AccountId =
CustomType::new("What is the beneficiary account ID?").prompt()?;
let beneficiary_account_id = if let Some(account_id) =
crate::common::input_non_signer_account_id_from_used_account_list(
&context.global_context.config.credentials_home_dir,
"What is the beneficiary account ID?",
)? {
account_id
} else {
return Ok(None);
};

if beneficiary_account_id.0 == context.signer_account_id {
eprintln!("{}", "You have selected a beneficiary account ID that will now be deleted. This will result in the loss of your funds. So make your choice again.".red());
continue;
}

if context.global_context.offline {
return Ok(Some(beneficiary_account_id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#[interactive_clap(input_context = super::super::super::ConstructTransactionContext)]
#[interactive_clap(output_context = StakeActionContext)]
pub struct StakeAction {
/// Enter the amount to stake: (example: 10000NEAR)
stake_amount: crate::types::near_token::NearToken,
/// Enter the public key of the validator key pair used on your NEAR node (see validator_key.json):
public_key: crate::types::public_key::PublicKey,
#[interactive_clap(subcommand)]
next_action: super::super::super::add_action_2::NextAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ impl From<FullAccessTypeContext> for AccessKeyPermissionContext {
pub struct FunctionCallType {
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
allowance: crate::types::near_token::NearToken,
allowance: crate::types::near_allowance::NearAllowance,
#[interactive_clap(long)]
/// Enter a receiver to use by this access key to pay for function call gas and transaction fees:
receiver_account_id: crate::types::account_id::AccountId,
/// You chose to limit the access key to only sign transactions for a specific contract. Enter the contract account ID:
contract_account_id: crate::types::account_id::AccountId,
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
method_names: crate::types::vec_string::VecString,
function_names: crate::types::vec_string::VecString,
#[interactive_clap(subcommand)]
access_key_mode: super::AccessKeyMode,
}
Expand All @@ -70,9 +70,12 @@ impl FunctionCallTypeContext {
) -> color_eyre::eyre::Result<Self> {
let access_key_permission = near_primitives::account::AccessKeyPermission::FunctionCall(
near_primitives::account::FunctionCallPermission {
allowance: Some(scope.allowance.as_yoctonear()),
receiver_id: scope.receiver_account_id.to_string(),
method_names: scope.method_names.clone().into(),
allowance: scope
.allowance
.optional_near_token()
.map(|allowance| allowance.as_yoctonear()),
receiver_id: scope.contract_account_id.to_string(),
method_names: scope.function_names.clone().into(),
},
);
Ok(Self(AccessKeyPermissionContext {
Expand All @@ -92,7 +95,7 @@ impl From<FunctionCallTypeContext> for AccessKeyPermissionContext {
}

impl FunctionCallType {
pub fn input_method_names(
pub fn input_function_names(
_context: &super::super::super::super::ConstructTransactionContext,
) -> color_eyre::eyre::Result<Option<crate::types::vec_string::VecString>> {
eprintln!();
Expand All @@ -111,17 +114,17 @@ impl FunctionCallType {
)
.prompt()?;
if let ConfirmOptions::Yes = select_choose_input {
let mut input_method_names =
Text::new("Enter a comma-separated list of method names that will be allowed to be called in a transaction signed by this access key:")
let mut input_function_names =
Text::new("Enter a comma-separated list of function names that will be allowed to be called in a transaction signed by this access key:")
.prompt()?;
if input_method_names.contains('\"') {
input_method_names.clear()
if input_function_names.contains('\"') {
input_function_names.clear()
};
if input_method_names.is_empty() {
if input_function_names.is_empty() {
Ok(Some(crate::types::vec_string::VecString(vec![])))
} else {
Ok(Some(crate::types::vec_string::VecString::from_str(
&input_method_names,
&input_function_names,
)?))
}
} else {
Expand All @@ -131,10 +134,10 @@ impl FunctionCallType {

pub fn input_allowance(
_context: &super::super::super::super::ConstructTransactionContext,
) -> color_eyre::eyre::Result<Option<crate::types::near_token::NearToken>> {
let allowance_near_balance: crate::types::near_token::NearToken =
) -> color_eyre::eyre::Result<Option<crate::types::near_allowance::NearAllowance>> {
let allowance_near_balance: crate::types::near_allowance::NearAllowance =
CustomType::new("Enter the allowance, a budget this access key can use to pay for transaction fees (example: 10NEAR or 0.5near or 10000yoctonear):")
.with_starting_input("0.25 NEAR")
.with_starting_input("unlimited")
.prompt()?;
Ok(Some(allowance_near_balance))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use inquire::CustomType;
#[interactive_clap(input_context = super::super::super::ConstructTransactionContext)]
#[interactive_clap(output_context = FunctionCallActionContext)]
pub struct FunctionCallAction {
#[interactive_clap(skip_default_input_arg)]
/// What is the name of the function?
function_name: String,
#[interactive_clap(value_enum)]
Expand Down Expand Up @@ -58,6 +59,15 @@ impl FunctionCallAction {
crate::commands::contract::call_function::call_function_args_type::input_function_args_type(
)
}

fn input_function_name(
context: &super::super::super::ConstructTransactionContext,
) -> color_eyre::eyre::Result<Option<String>> {
crate::commands::contract::call_function::input_call_function_name(
&context.global_context,
&context.receiver_account_id,
)
}
}

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use inquire::{CustomType, Select};
use color_eyre::owo_colors::OwoColorize;
use inquire::Select;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = super::super::super::ConstructTransactionContext)]
Expand Down Expand Up @@ -46,8 +47,20 @@ impl DeleteAccountAction {
context: &super::super::super::ConstructTransactionContext,
) -> color_eyre::eyre::Result<Option<crate::types::account_id::AccountId>> {
loop {
let beneficiary_account_id: crate::types::account_id::AccountId =
CustomType::new("What is the beneficiary account ID?").prompt()?;
let beneficiary_account_id = if let Some(account_id) =
crate::common::input_non_signer_account_id_from_used_account_list(
&context.global_context.config.credentials_home_dir,
"What is the beneficiary account ID?",
)? {
account_id
} else {
return Ok(None);
};

if beneficiary_account_id.0 == context.signer_account_id {
eprintln!("{}", "You have selected a beneficiary account ID that will now be deleted. This will result in the loss of your funds. So make your choice again.".red());
continue;
}

if context.global_context.offline {
return Ok(Some(beneficiary_account_id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#[interactive_clap(input_context = super::super::super::ConstructTransactionContext)]
#[interactive_clap(output_context = StakeActionContext)]
pub struct StakeAction {
/// Enter the amount to stake: (example: 10000NEAR)
stake_amount: crate::types::near_token::NearToken,
/// Enter the public key of the validator key pair used on your NEAR node (see validator_key.json):
public_key: crate::types::public_key::PublicKey,
#[interactive_clap(subcommand)]
next_action: super::super::super::add_action_3::NextAction,
Expand Down
Loading
Loading