Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 8b989d5

Browse files
committed
spl-token-cli: Simplify owner resolution
1 parent 67cb90f commit 8b989d5

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

token/cli/src/main.rs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use solana_clap_utils::{
1414
is_amount, is_amount_or_all, is_parsable, is_url_or_moniker, is_valid_pubkey,
1515
is_valid_signer, normalize_to_url_if_moniker,
1616
},
17-
keypair::{pubkey_from_path, signer_from_path, DefaultSigner},
17+
keypair::{signer_from_path, DefaultSigner, SignerFromPathConfig},
1818
nonce::*,
1919
offline::{self, *},
2020
ArgConstant,
@@ -1915,32 +1915,19 @@ fn main() {
19151915
arg_name: default_signer_arg_name,
19161916
};
19171917

1918-
// Owner doesn't sign when using a mulitisig...
1919-
let owner = if matches.is_present(MULTISIG_SIGNER_ARG.name)
1920-
|| sub_command == "accounts" // when calling the `accounts` command...
1921-
|| sub_command == "address" // when calling the `address` command...
1922-
|| (sub_command == "create-account" // or when creating an associated token account.
1923-
&& !matches.is_present("account_keypair"))
1924-
{
1925-
let owner_val = matches
1926-
.value_of("owner")
1927-
.unwrap_or(&cli_config.keypair_path);
1928-
pubkey_from_path(&matches, owner_val, "owner", &mut wallet_manager).unwrap_or_else(
1929-
|e| {
1930-
eprintln!("error: {}", e);
1931-
exit(1);
1932-
},
1933-
)
1934-
} else {
1935-
bulk_signers.push(None);
1936-
default_signer
1937-
.signer_from_path(&matches, &mut wallet_manager)
1918+
let (owner, signer) = {
1919+
let config = SignerFromPathConfig {
1920+
allow_null_signer: true,
1921+
};
1922+
let owner = default_signer
1923+
.signer_from_path_with_config(&matches, &mut wallet_manager, &config)
19381924
.unwrap_or_else(|e| {
19391925
eprintln!("error: {}", e);
19401926
exit(1);
1941-
})
1942-
.pubkey()
1927+
});
1928+
(owner.pubkey(), Some(owner))
19431929
};
1930+
bulk_signers.push(signer);
19441931

19451932
let (signer, fee_payer) = signer_from_path(
19461933
&matches,
@@ -2306,13 +2293,14 @@ fn main() {
23062293
)?;
23072294
}
23082295

2296+
let signers = signer_info.signers_for_message(&message);
23092297
let mut transaction = Transaction::new_unsigned(message);
23102298

23112299
if config.sign_only {
2312-
transaction.try_partial_sign(&signer_info.signers, recent_blockhash)?;
2300+
transaction.try_partial_sign(&signers, recent_blockhash)?;
23132301
println!("{}", return_signers(&transaction, &OutputFormat::Display)?);
23142302
} else {
2315-
transaction.try_sign(&signer_info.signers, recent_blockhash)?;
2303+
transaction.try_sign(&signers, recent_blockhash)?;
23162304
let signature = if no_wait {
23172305
config.rpc_client.send_transaction(&transaction)?
23182306
} else {

0 commit comments

Comments
 (0)