Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feat/config-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
frolvanya committed May 3, 2024
2 parents e222d00 + 378a695 commit 1750ba5
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 122 deletions.
38 changes: 11 additions & 27 deletions src/commands/account/add_key/access_key_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl From<FullAccessTypeContext> for AccessTypeContext {
pub struct FunctionCallType {
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
allowance: Option<crate::types::near_token::NearToken>,
allowance: crate::types::near_token::NearToken,
#[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,
Expand Down Expand Up @@ -81,7 +81,7 @@ impl FunctionCallTypeContext {
Ok(Self {
global_context: previous_context.global_context,
signer_account_id: previous_context.owner_account_id.into(),
allowance: scope.allowance,
allowance: Some(scope.allowance),
receiver_account_id: scope.receiver_account_id.clone(),
method_names: scope.method_names.clone(),
})
Expand Down Expand Up @@ -110,17 +110,17 @@ impl FunctionCallType {
) -> color_eyre::eyre::Result<Option<crate::types::vec_string::VecString>> {
#[derive(strum_macros::Display)]
enum ConfirmOptions {
#[strum(to_string = "Yes, I want to input a list of method names that can be used")]
Yes,
#[strum(
to_string = "No, I don't want to input a list of method names that can be used"
to_string = "Yes, I want to input a list of function names that can be called when transaction is signed by this access key"
)]
Yes,
#[strum(to_string = "No, I allow it to call any functions on the specified contract")]
No,
}

eprintln!();
let select_choose_input = Select::new(
"Do You want to input a list of method names that can be used?",
"Would you like the access key to be valid exclusively for calling specific functions on the contract?",
vec![ConfirmOptions::Yes, ConfirmOptions::No],
)
.prompt()?;
Expand All @@ -145,26 +145,10 @@ impl FunctionCallType {
pub fn input_allowance(
_context: &super::AddKeyCommandContext,
) -> color_eyre::eyre::Result<Option<crate::types::near_token::NearToken>> {
eprintln!();
#[derive(strum_macros::Display)]
enum ConfirmOptions {
#[strum(to_string = "Yes, I want to input allowance for receiver ID")]
Yes,
#[strum(to_string = "No, I don't want to input allowance for receiver ID")]
No,
}
let select_choose_input = Select::new(
"Do You want to input an allowance for receiver ID?",
vec![ConfirmOptions::Yes, ConfirmOptions::No],
)
.prompt()?;
if let ConfirmOptions::Yes = select_choose_input {
let allowance_near_balance: crate::types::near_token::NearToken =
CustomType::new("Enter an allowance which is a balance limit to use by this access key to pay for function call gas and transaction fees (example: 10NEAR or 0.5near or 10000yoctonear):")
.prompt()?;
Ok(Some(allowance_near_balance))
} else {
Ok(None)
}
let allowance_near_balance: crate::types::near_token::NearToken =
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")
.prompt()?;
Ok(Some(allowance_near_balance))
}
}
7 changes: 7 additions & 0 deletions src/commands/staking/delegate/view_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub struct ViewBalance {
pub struct ViewBalanceContext(crate::network_view_at_block::ArgsForViewContext);

impl ViewBalanceContext {
#[tracing::instrument(
name = "View the delegated stake balance for your account ...",
skip_all
)]
pub fn from_previous_context(
previous_context: super::StakeDelegationContext,
scope: &<ViewBalance as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
Expand Down Expand Up @@ -69,6 +73,7 @@ impl ViewBalance {
}
}

#[tracing::instrument(name = "Getting the staked balance for the user ...", skip_all)]
pub fn get_user_staked_balance(
network_config: &crate::config::NetworkConfig,
block_reference: &near_primitives::types::BlockReference,
Expand Down Expand Up @@ -96,6 +101,7 @@ pub fn get_user_staked_balance(
.parse::<u128>()?)
}

#[tracing::instrument(name = "Getting the unstaked balance for the user ...", skip_all)]
pub fn get_user_unstaked_balance(
network_config: &crate::config::NetworkConfig,
block_reference: &near_primitives::types::BlockReference,
Expand Down Expand Up @@ -123,6 +129,7 @@ pub fn get_user_unstaked_balance(
.parse::<u128>()?)
}

#[tracing::instrument(name = "Getting the total balance for the user ...", skip_all)]
pub fn get_user_total_balance(
network_config: &crate::config::NetworkConfig,
block_reference: &near_primitives::types::BlockReference,
Expand Down
1 change: 1 addition & 0 deletions src/commands/staking/validator_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl From<ValidatorListContext> for crate::network::NetworkContext {
}
}

#[tracing::instrument(name = "View the list of validators for delegation ...", skip_all)]
fn display_validators_info(network_config: &crate::config::NetworkConfig) -> crate::CliResult {
let mut table = Table::new();
table.set_titles(prettytable::row![Fg=>"#", "Validator Id", "Fee", "Delegators", "Stake"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl From<FullAccessTypeContext> for AccessKeyPermissionContext {
pub struct FunctionCallType {
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
allowance: Option<crate::types::near_token::NearToken>,
allowance: crate::types::near_token::NearToken,
#[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,
Expand All @@ -70,7 +70,7 @@ impl FunctionCallTypeContext {
) -> color_eyre::eyre::Result<Self> {
let access_key_permission = near_primitives::account::AccessKeyPermission::FunctionCall(
near_primitives::account::FunctionCallPermission {
allowance: scope.allowance.map(|allowance| allowance.as_yoctonear()),
allowance: Some(scope.allowance.as_yoctonear()),
receiver_id: scope.receiver_account_id.to_string(),
method_names: scope.method_names.clone().into(),
},
Expand Down Expand Up @@ -98,15 +98,15 @@ impl FunctionCallType {
eprintln!();
#[derive(strum_macros::Display)]
enum ConfirmOptions {
#[strum(to_string = "Yes, I want to input a list of method names that can be used")]
Yes,
#[strum(
to_string = "No, I don't want to input a list of method names that can be used"
to_string = "Yes, I want to input a list of function names that can be called when transaction is signed by this access key"
)]
Yes,
#[strum(to_string = "No, I allow it to call any functions on the specified contract")]
No,
}
let select_choose_input = Select::new(
"Do You want to input a list of method names that can be used?",
"Would you like the access key to be valid exclusively for calling specific functions on the contract?",
vec![ConfirmOptions::Yes, ConfirmOptions::No],
)
.prompt()?;
Expand All @@ -132,26 +132,10 @@ impl FunctionCallType {
pub fn input_allowance(
_context: &super::super::super::super::ConstructTransactionContext,
) -> color_eyre::eyre::Result<Option<crate::types::near_token::NearToken>> {
eprintln!();
#[derive(strum_macros::Display)]
enum ConfirmOptions {
#[strum(to_string = "Yes, I want to input allowance for receiver ID")]
Yes,
#[strum(to_string = "No, I don't want to input allowance for receiver ID")]
No,
}
let select_choose_input = Select::new(
"Do You want to input an allowance for receiver ID?",
vec![ConfirmOptions::Yes, ConfirmOptions::No],
)
.prompt()?;
if let ConfirmOptions::Yes = select_choose_input {
let allowance_near_balance: crate::types::near_token::NearToken =
CustomType::new("Enter an allowance which is a balance limit to use by this access key to pay for function call gas and transaction fees (example: 10NEAR or 0.5near or 10000yoctonear):")
.prompt()?;
Ok(Some(allowance_near_balance))
} else {
Ok(None)
}
let allowance_near_balance: crate::types::near_token::NearToken =
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")
.prompt()?;
Ok(Some(allowance_near_balance))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl From<FullAccessTypeContext> for AccessKeyPermissionContext {
pub struct FunctionCallType {
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
allowance: Option<crate::types::near_token::NearToken>,
allowance: crate::types::near_token::NearToken,
#[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,
Expand All @@ -70,7 +70,7 @@ impl FunctionCallTypeContext {
) -> color_eyre::eyre::Result<Self> {
let access_key_permission = near_primitives::account::AccessKeyPermission::FunctionCall(
near_primitives::account::FunctionCallPermission {
allowance: scope.allowance.map(|allowance| allowance.as_yoctonear()),
allowance: Some(scope.allowance.as_yoctonear()),
receiver_id: scope.receiver_account_id.to_string(),
method_names: scope.method_names.clone().into(),
},
Expand Down Expand Up @@ -98,15 +98,15 @@ impl FunctionCallType {
eprintln!();
#[derive(strum_macros::Display)]
enum ConfirmOptions {
#[strum(to_string = "Yes, I want to input a list of method names that can be used")]
Yes,
#[strum(
to_string = "No, I don't want to input a list of method names that can be used"
to_string = "Yes, I want to input a list of function names that can be called when transaction is signed by this access key"
)]
Yes,
#[strum(to_string = "No, I allow it to call any functions on the specified contract")]
No,
}
let select_choose_input = Select::new(
"Do You want to input a list of method names that can be used?",
"Would you like the access key to be valid exclusively for calling specific functions on the contract?",
vec![ConfirmOptions::Yes, ConfirmOptions::No],
)
.prompt()?;
Expand All @@ -132,26 +132,10 @@ impl FunctionCallType {
pub fn input_allowance(
_context: &super::super::super::super::ConstructTransactionContext,
) -> color_eyre::eyre::Result<Option<crate::types::near_token::NearToken>> {
eprintln!();
#[derive(strum_macros::Display)]
enum ConfirmOptions {
#[strum(to_string = "Yes, I want to input allowance for receiver ID")]
Yes,
#[strum(to_string = "No, I don't want to input allowance for receiver ID")]
No,
}
let select_choose_input = Select::new(
"Do You want to input an allowance for receiver ID?",
vec![ConfirmOptions::Yes, ConfirmOptions::No],
)
.prompt()?;
if let ConfirmOptions::Yes = select_choose_input {
let allowance_near_balance: crate::types::near_token::NearToken =
CustomType::new("Enter an allowance which is a balance limit to use by this access key to pay for function call gas and transaction fees (example: 10NEAR or 0.5near or 10000yoctonear):")
.prompt()?;
Ok(Some(allowance_near_balance))
} else {
Ok(None)
}
let allowance_near_balance: crate::types::near_token::NearToken =
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")
.prompt()?;
Ok(Some(allowance_near_balance))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl From<FullAccessTypeContext> for AccessKeyPermissionContext {
pub struct FunctionCallType {
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
allowance: Option<crate::types::near_token::NearToken>,
allowance: crate::types::near_token::NearToken,
#[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,
Expand All @@ -70,7 +70,7 @@ impl FunctionCallTypeContext {
) -> color_eyre::eyre::Result<Self> {
let access_key_permission = near_primitives::account::AccessKeyPermission::FunctionCall(
near_primitives::account::FunctionCallPermission {
allowance: scope.allowance.map(|allowance| allowance.as_yoctonear()),
allowance: Some(scope.allowance.as_yoctonear()),
receiver_id: scope.receiver_account_id.to_string(),
method_names: scope.method_names.clone().into(),
},
Expand Down Expand Up @@ -98,15 +98,15 @@ impl FunctionCallType {
eprintln!();
#[derive(strum_macros::Display)]
enum ConfirmOptions {
#[strum(to_string = "Yes, I want to input a list of method names that can be used")]
Yes,
#[strum(
to_string = "No, I don't want to input a list of method names that can be used"
to_string = "Yes, I want to input a list of function names that can be called when transaction is signed by this access key"
)]
Yes,
#[strum(to_string = "No, I allow it to call any functions on the specified contract")]
No,
}
let select_choose_input = Select::new(
"Do You want to input a list of method names that can be used?",
"Would you like the access key to be valid exclusively for calling specific functions on the contract?",
vec![ConfirmOptions::Yes, ConfirmOptions::No],
)
.prompt()?;
Expand All @@ -132,26 +132,10 @@ impl FunctionCallType {
pub fn input_allowance(
_context: &super::super::super::super::ConstructTransactionContext,
) -> color_eyre::eyre::Result<Option<crate::types::near_token::NearToken>> {
eprintln!();
#[derive(strum_macros::Display)]
enum ConfirmOptions {
#[strum(to_string = "Yes, I want to input allowance for receiver ID")]
Yes,
#[strum(to_string = "No, I don't want to input allowance for receiver ID")]
No,
}
let select_choose_input = Select::new(
"Do You want to input an allowance for receiver ID?",
vec![ConfirmOptions::Yes, ConfirmOptions::No],
)
.prompt()?;
if let ConfirmOptions::Yes = select_choose_input {
let allowance_near_balance: crate::types::near_token::NearToken =
CustomType::new("Enter an allowance which is a balance limit to use by this access key to pay for function call gas and transaction fees (example: 10NEAR or 0.5near or 10000yoctonear):")
.prompt()?;
Ok(Some(allowance_near_balance))
} else {
Ok(None)
}
let allowance_near_balance: crate::types::near_token::NearToken =
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")
.prompt()?;
Ok(Some(allowance_near_balance))
}
}
2 changes: 2 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@ pub struct RewardFeeFraction {
pub denominator: u32,
}

#[tracing::instrument(name = "Getting a list of validators ...", skip_all)]
pub fn get_validator_list(
network_config: &crate::config::NetworkConfig,
) -> color_eyre::eyre::Result<Vec<StakingPoolInfo>> {
Expand Down Expand Up @@ -1530,6 +1531,7 @@ pub fn fetch_validators_rpc(
}
}

#[tracing::instrument(name = "Getting a stake of validators ...", skip_all)]
pub fn get_validators_stake(
json_rpc_client: &near_jsonrpc_client::JsonRpcClient,
) -> color_eyre::eyre::Result<
Expand Down
10 changes: 3 additions & 7 deletions src/js_command_match/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,17 @@ impl DeployArgs {
];
};

if let Some(init_args) = &self.init_args {
let mut initial_function = "new".to_string();
if let Some(init_function) = &self.init_function {
initial_function.clone_from(init_function);
}
if self.init_function.is_some() {
vec![
"contract".to_owned(),
"deploy".to_owned(),
contract_account_id.to_owned(),
"use-file".to_owned(),
wasm_file.to_owned(),
"with-init-call".to_owned(),
initial_function,
self.init_function.as_deref().unwrap_or("new").to_owned(),
"json-args".to_owned(),
init_args.to_owned(),
self.init_args.as_deref().unwrap_or("{}").to_owned(),
"prepaid-gas".to_owned(),
format!("{} TeraGas", self.init_gas / 1_000_000_000_000),
"attached-deposit".to_owned(),
Expand Down
10 changes: 3 additions & 7 deletions src/js_command_match/dev_deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ impl DevDeployArgs {
"2. Run the following command, after inserting the name of the created dev-account:"
);

if let Some(init_args) = &self.init_args {
let mut initial_function = "new".to_string();
if let Some(init_function) = &self.init_function {
initial_function.clone_from(init_function);
}
if self.init_function.is_some() {
eprintln!(
" {}",
shell_words::join(vec![
Expand All @@ -43,9 +39,9 @@ impl DevDeployArgs {
"deploy".to_owned(),
"<created-dev-account>".to_owned(),
"with-init-call".to_owned(),
initial_function,
self.init_function.as_deref().unwrap_or("new").to_owned(),
"json-args".to_owned(),
init_args.to_owned(),
self.init_args.as_deref().unwrap_or("{}").to_owned(),
"prepaid-gas".to_owned(),
format!("{} TeraGas", self.init_gas / 1_000_000_000_000),
"attached-deposit".to_owned(),
Expand Down
Loading

0 comments on commit 1750ba5

Please sign in to comment.