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

cmd/starcoin/account: bail when pass multsig account as arg for rotat… #3454

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions cmd/starcoin/src/account/rotate_auth_key_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use starcoin_types::identifier::Identifier;
use starcoin_types::language_storage::ModuleId;
use starcoin_vm_types::account_address::AccountAddress;
use starcoin_vm_types::account_config::core_code_address;
use starcoin_vm_types::transaction::authenticator::AccountPrivateKey;
use starcoin_vm_types::transaction::authenticator::{AccountPrivateKey, AccountPublicKey};
use starcoin_vm_types::transaction::{ScriptFunction, TransactionArgument, TransactionPayload};
use starcoin_vm_types::value::MoveValue;

Expand Down Expand Up @@ -67,6 +67,7 @@ impl CommandAction for RotateAuthenticationKeyCommand {
) -> Result<Self::ReturnItem> {
let client = ctx.state().account_client();
let opt: &RotateAuthKeyOpt = ctx.opt();

let private_key = match (opt.from_input.as_ref(), opt.from_file.as_ref()) {
(Some(p), _) => AccountPrivateKey::from_encoded_string(p)?,
(None, Some(p)) => {
Expand All @@ -77,7 +78,18 @@ impl CommandAction for RotateAuthenticationKeyCommand {
bail!("private key should be specified, use <input>, <from-file>")
}
};
let auth_key = private_key.public_key().authentication_key();

let account_public_key = match &private_key.public_key() {
AccountPublicKey::Multi(_) => {
bail!(
"{} is multisig address, you could use execute-function to rotate it step by step",
opt.account_address
jolestar marked this conversation as resolved.
Show resolved Hide resolved
);
}
m => m.clone(),
};

let auth_key = account_public_key.authentication_key();
let mut txn_opt = opt.transaction_opts.clone();
txn_opt.blocking = true;
txn_opt.sender = Option::from(opt.account_address);
Expand Down
23 changes: 13 additions & 10 deletions cmd/starcoin/src/account/sign_multisig_txn_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// Copyright (c) The Starcoin Core Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::cli_state::CliState;
use crate::StarcoinOpt;
use std::convert::TryInto;
use std::env::current_dir;
use std::fs::File;
use std::path::PathBuf;

use anyhow::{bail, Result};
use clap::Parser;
use scmd::{CommandAction, ExecContext};
use starcoin_account_api::AccountPublicKey;
use starcoin_crypto::hash::PlainCryptoHash;
use starcoin_crypto::multi_ed25519::multi_shard::MultiEd25519SignatureShard;

use scmd::{CommandAction, ExecContext};
use starcoin_account_api::AccountPublicKey;
use starcoin_rpc_api::types::{FunctionIdView, RawUserTransactionView, TransactionStatusView};
use starcoin_rpc_client::StateRootOption;
use starcoin_state_api::StateReaderExt;
Expand All @@ -22,10 +26,9 @@ use starcoin_vm_types::token::stc::STC_TOKEN_CODE_STR;
use starcoin_vm_types::transaction::{ScriptFunction, TransactionPayload};
use starcoin_vm_types::transaction_argument::convert_txn_args;
use starcoin_vm_types::{language_storage::TypeTag, parser::parse_type_tag};
use std::convert::TryInto;
use std::env::current_dir;
use std::fs::File;
use std::path::PathBuf;

use crate::cli_state::CliState;
use crate::StarcoinOpt;

#[derive(Debug, Parser)]
#[clap(name = "sign-multisig-txn")]
Expand Down Expand Up @@ -56,7 +59,7 @@ pub struct GenerateMultisigTxnOpt {
)]
type_tags: Option<Vec<TypeTag>>,

#[clap(long = "arg", name = "transaction-arg", parse(try_from_str = parse_transaction_argument))]
#[clap(long = "arg", name = "transaction-arg", parse(try_from_str = parse_transaction_argument))]
/// transaction arguments
args: Option<Vec<TransactionArgument>>,

Expand Down Expand Up @@ -111,7 +114,7 @@ impl CommandAction for GenerateMultisigTxnCommand {
// gen multisig txn or read from file sent by other participants.
let (raw_txn, existing_signatures) =
if let Some(function_id) = opt.script_function.clone().map(|t| t.0) {
let sender = ctx.opt().sender.expect("sender adress should be provided");
let sender = ctx.opt().sender.expect("sender address should be provided");
let script_function = ScriptFunction::new(
function_id.module,
function_id.function,
Expand Down