Cli error cleanup 1.0 (#8834)
* Don't use move semantics if not needed (#8793) * SDK: Deboilerplate `TransportError` with thiserror * Enable interchange between `TransportError` and `ClientError` * SDK: Retval consistency between `Client` and `AsyncClient` traits * Client: Introduce/use `Result` type * Client: Remove unused `RpcResponseIn` type * Client: Rename `RpcResponse` to more appropriate `RpcResult` * Client: Death to `io::Result` return types * Client: Struct-ify `ClientError` * Client: Add optional `command` parameter to `ClientError` * RpcClient: Stop abusing `io::Error` (low-fruit) * ClientError: Use `thiserror`'s `Display` impl * Extend `RpcError`'s utility * RpcClient: Stop abusing `io::Error` (the rest) * CLI: Shim `main()` so we can `Display` format errors * claputils: format input validator errors with `Display` They are intended to be displayed to users * SDK: `thiserror` for hash and sig parse erros * Keygen: Shim main to format errors with `Display` * SDK: `thiserror` for `InstructionError` * CLI: `thiserror` for `CliError` * CLI: Format user messages with `Display` * Client: Tweak `Display` for `ClientError` * RpcClient: Improve messaging when TX cannot be confirmed * fu death io res retval * CLI/Keygen - fix shell return value on error * Tweak `InstructionError` `Display` messages as per review * Cleanup hackjob return code fix * Embrace that which you hate most * Too much... Co-authored-by: Jack May <jack@solana.com>
This commit is contained in:
@@ -36,7 +36,7 @@ impl Client for BankClient {
|
||||
}
|
||||
|
||||
impl AsyncClient for BankClient {
|
||||
fn async_send_transaction(&self, transaction: Transaction) -> io::Result<Signature> {
|
||||
fn async_send_transaction(&self, transaction: Transaction) -> Result<Signature> {
|
||||
let signature = transaction.signatures.get(0).cloned().unwrap_or_default();
|
||||
let transaction_sender = self.transaction_sender.lock().unwrap();
|
||||
transaction_sender.send(transaction).unwrap();
|
||||
@@ -48,7 +48,7 @@ impl AsyncClient for BankClient {
|
||||
keypairs: &T,
|
||||
message: Message,
|
||||
recent_blockhash: Hash,
|
||||
) -> io::Result<Signature> {
|
||||
) -> Result<Signature> {
|
||||
let transaction = Transaction::new(keypairs, message, recent_blockhash);
|
||||
self.async_send_transaction(transaction)
|
||||
}
|
||||
@@ -58,8 +58,8 @@ impl AsyncClient for BankClient {
|
||||
keypair: &Keypair,
|
||||
instruction: Instruction,
|
||||
recent_blockhash: Hash,
|
||||
) -> io::Result<Signature> {
|
||||
let message = Message::new(vec![instruction]);
|
||||
) -> Result<Signature> {
|
||||
let message = Message::new(&[instruction]);
|
||||
self.async_send_message(&[keypair], message, recent_blockhash)
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ impl AsyncClient for BankClient {
|
||||
keypair: &Keypair,
|
||||
pubkey: &Pubkey,
|
||||
recent_blockhash: Hash,
|
||||
) -> io::Result<Signature> {
|
||||
) -> Result<Signature> {
|
||||
let transfer_instruction =
|
||||
system_instruction::transfer(&keypair.pubkey(), pubkey, lamports);
|
||||
self.async_send_instruction(keypair, transfer_instruction, recent_blockhash)
|
||||
@@ -87,7 +87,7 @@ impl SyncClient for BankClient {
|
||||
|
||||
/// Create and process a transaction from a single instruction.
|
||||
fn send_instruction(&self, keypair: &Keypair, instruction: Instruction) -> Result<Signature> {
|
||||
let message = Message::new(vec![instruction]);
|
||||
let message = Message::new(&[instruction]);
|
||||
self.send_message(&[keypair], message)
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ mod tests {
|
||||
.accounts
|
||||
.push(AccountMeta::new(jane_pubkey, true));
|
||||
|
||||
let message = Message::new(vec![transfer_instruction]);
|
||||
let message = Message::new(&[transfer_instruction]);
|
||||
bank_client.send_message(&doe_keypairs, message).unwrap();
|
||||
assert_eq!(bank_client.get_balance(&bob_pubkey).unwrap(), 42);
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ pub fn load_program<T: Client>(
|
||||
bank_client
|
||||
.send_message(
|
||||
&[from_keypair, &program_keypair],
|
||||
Message::new(vec![instruction]),
|
||||
Message::new(&[instruction]),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -37,7 +37,7 @@ pub fn load_program<T: Client>(
|
||||
for chunk in program.chunks(chunk_size) {
|
||||
let instruction =
|
||||
loader_instruction::write(&program_pubkey, loader_pubkey, offset, chunk.to_vec());
|
||||
let message = Message::new_with_payer(vec![instruction], Some(&from_keypair.pubkey()));
|
||||
let message = Message::new_with_payer(&[instruction], Some(&from_keypair.pubkey()));
|
||||
bank_client
|
||||
.send_message(&[from_keypair, &program_keypair], message)
|
||||
.unwrap();
|
||||
@@ -45,7 +45,7 @@ pub fn load_program<T: Client>(
|
||||
}
|
||||
|
||||
let instruction = loader_instruction::finalize(&program_pubkey, loader_pubkey);
|
||||
let message = Message::new_with_payer(vec![instruction], Some(&from_keypair.pubkey()));
|
||||
let message = Message::new_with_payer(&[instruction], Some(&from_keypair.pubkey()));
|
||||
bank_client
|
||||
.send_message(&[from_keypair, &program_keypair], message)
|
||||
.unwrap();
|
||||
|
@@ -800,7 +800,7 @@ mod tests {
|
||||
AccountMeta::new(from_pubkey, true),
|
||||
AccountMeta::new_readonly(to_pubkey, false),
|
||||
];
|
||||
let message = Message::new(vec![Instruction::new(
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::Correct,
|
||||
account_metas.clone(),
|
||||
@@ -811,7 +811,7 @@ mod tests {
|
||||
assert_eq!(accounts[0].borrow().lamports, 100);
|
||||
assert_eq!(accounts[1].borrow().lamports, 0);
|
||||
|
||||
let message = Message::new(vec![Instruction::new(
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::AttemptCredit { lamports: 50 },
|
||||
account_metas.clone(),
|
||||
@@ -826,7 +826,7 @@ mod tests {
|
||||
))
|
||||
);
|
||||
|
||||
let message = Message::new(vec![Instruction::new(
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::AttemptDataChange { data: 50 },
|
||||
account_metas,
|
||||
@@ -923,7 +923,7 @@ mod tests {
|
||||
];
|
||||
|
||||
// Try to borrow mut the same account
|
||||
let message = Message::new(vec![Instruction::new(
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::BorrowFail,
|
||||
account_metas.clone(),
|
||||
@@ -938,7 +938,7 @@ mod tests {
|
||||
);
|
||||
|
||||
// Try to borrow mut the same account in a safe way
|
||||
let message = Message::new(vec![Instruction::new(
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::MultiBorrowMut,
|
||||
account_metas.clone(),
|
||||
@@ -947,7 +947,7 @@ mod tests {
|
||||
assert_eq!(result, Ok(()));
|
||||
|
||||
// Do work on the same account but at different location in keyed_accounts[]
|
||||
let message = Message::new(vec![Instruction::new(
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::DoWork {
|
||||
lamports: 10,
|
||||
|
@@ -111,7 +111,7 @@ pub(crate) mod tests {
|
||||
let bank = Arc::new(bank);
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
|
||||
let message = Message::new(storage_instruction::create_storage_account(
|
||||
let message = Message::new(&storage_instruction::create_storage_account(
|
||||
&mint_pubkey,
|
||||
&Pubkey::default(),
|
||||
&archiver_pubkey,
|
||||
@@ -122,7 +122,7 @@ pub(crate) mod tests {
|
||||
.send_message(&[&mint_keypair, &archiver_keypair], message)
|
||||
.unwrap();
|
||||
|
||||
let message = Message::new(storage_instruction::create_storage_account(
|
||||
let message = Message::new(&storage_instruction::create_storage_account(
|
||||
&mint_pubkey,
|
||||
&Pubkey::default(),
|
||||
&validator_pubkey,
|
||||
|
@@ -926,7 +926,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let allocate_with_seed = Message::new_with_payer(
|
||||
vec![system_instruction::allocate_with_seed(
|
||||
&[system_instruction::allocate_with_seed(
|
||||
&alice_with_seed,
|
||||
&alice_pubkey,
|
||||
seed,
|
||||
@@ -978,7 +978,7 @@ mod tests {
|
||||
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 0, len1, &program);
|
||||
let message = Message::new(vec![ix]);
|
||||
let message = Message::new(&[ix]);
|
||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||
assert!(r.is_ok());
|
||||
|
||||
@@ -996,7 +996,7 @@ mod tests {
|
||||
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 1, len2, &program);
|
||||
let message = Message::new(vec![ix]);
|
||||
let message = Message::new(&[ix]);
|
||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||
assert!(r.is_ok());
|
||||
}
|
||||
@@ -1036,7 +1036,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let assign_with_seed = Message::new_with_payer(
|
||||
vec![system_instruction::assign_with_seed(
|
||||
&[system_instruction::assign_with_seed(
|
||||
&alice_with_seed,
|
||||
&alice_pubkey,
|
||||
seed,
|
||||
|
@@ -53,7 +53,7 @@ fn fill_epoch_with_votes(
|
||||
let parent = bank.parent().unwrap();
|
||||
|
||||
let message = Message::new_with_payer(
|
||||
vec![vote_instruction::vote(
|
||||
&[vote_instruction::vote(
|
||||
&vote_pubkey,
|
||||
&vote_pubkey,
|
||||
Vote::new(vec![parent.slot() as u64], parent.hash()),
|
||||
@@ -121,7 +121,7 @@ fn test_stake_create_and_split_single_signature() {
|
||||
let lamports = 1_000_000;
|
||||
|
||||
// Create stake account with seed
|
||||
let message = Message::new(stake_instruction::create_account_with_seed(
|
||||
let message = Message::new(&stake_instruction::create_account_with_seed(
|
||||
&staker_pubkey, // from
|
||||
&stake_address, // to
|
||||
&staker_pubkey, // base
|
||||
@@ -141,7 +141,7 @@ fn test_stake_create_and_split_single_signature() {
|
||||
create_address_with_seed(&staker_pubkey, "split_stake", &solana_stake_program::id())
|
||||
.unwrap();
|
||||
// Test split
|
||||
let message = Message::new(stake_instruction::split_with_seed(
|
||||
let message = Message::new(&stake_instruction::split_with_seed(
|
||||
&stake_address, // original
|
||||
&staker_pubkey, // authorized
|
||||
lamports / 2,
|
||||
@@ -179,7 +179,7 @@ fn test_stake_account_lifetime() {
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
|
||||
// Create Vote Account
|
||||
let message = Message::new(vote_instruction::create_account(
|
||||
let message = Message::new(&vote_instruction::create_account(
|
||||
&mint_pubkey,
|
||||
&vote_pubkey,
|
||||
&VoteInit {
|
||||
@@ -196,7 +196,7 @@ fn test_stake_account_lifetime() {
|
||||
|
||||
let authorized = stake_state::Authorized::auto(&stake_pubkey);
|
||||
// Create stake account and delegate to vote account
|
||||
let message = Message::new(stake_instruction::create_account_and_delegate_stake(
|
||||
let message = Message::new(&stake_instruction::create_account_and_delegate_stake(
|
||||
&mint_pubkey,
|
||||
&stake_pubkey,
|
||||
&vote_pubkey,
|
||||
@@ -219,7 +219,7 @@ fn test_stake_account_lifetime() {
|
||||
|
||||
// Test that we cannot withdraw anything until deactivation
|
||||
let message = Message::new_with_payer(
|
||||
vec![stake_instruction::withdraw(
|
||||
&[stake_instruction::withdraw(
|
||||
&stake_pubkey,
|
||||
&stake_pubkey,
|
||||
&Pubkey::new_rand(),
|
||||
@@ -282,7 +282,7 @@ fn test_stake_account_lifetime() {
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
// Test split
|
||||
let message = Message::new_with_payer(
|
||||
stake_instruction::split(
|
||||
&stake_instruction::split(
|
||||
&stake_pubkey,
|
||||
&stake_pubkey,
|
||||
lamports / 2,
|
||||
@@ -299,7 +299,7 @@ fn test_stake_account_lifetime() {
|
||||
|
||||
// Deactivate the split
|
||||
let message = Message::new_with_payer(
|
||||
vec![stake_instruction::deactivate_stake(
|
||||
&[stake_instruction::deactivate_stake(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
)],
|
||||
@@ -313,7 +313,7 @@ fn test_stake_account_lifetime() {
|
||||
|
||||
// Test that we cannot withdraw above what's staked
|
||||
let message = Message::new_with_payer(
|
||||
vec![stake_instruction::withdraw(
|
||||
&[stake_instruction::withdraw(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
&Pubkey::new_rand(),
|
||||
@@ -334,7 +334,7 @@ fn test_stake_account_lifetime() {
|
||||
|
||||
// withdrawal in cooldown
|
||||
let message = Message::new_with_payer(
|
||||
vec![stake_instruction::withdraw(
|
||||
&[stake_instruction::withdraw(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
&Pubkey::new_rand(),
|
||||
@@ -349,7 +349,7 @@ fn test_stake_account_lifetime() {
|
||||
|
||||
// but we can withdraw unstaked
|
||||
let message = Message::new_with_payer(
|
||||
vec![stake_instruction::withdraw(
|
||||
&[stake_instruction::withdraw(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
&Pubkey::new_rand(),
|
||||
@@ -373,7 +373,7 @@ fn test_stake_account_lifetime() {
|
||||
|
||||
// Test that we can withdraw everything else out of the split
|
||||
let message = Message::new_with_payer(
|
||||
vec![stake_instruction::withdraw(
|
||||
&[stake_instruction::withdraw(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
&Pubkey::new_rand(),
|
||||
@@ -414,7 +414,7 @@ fn test_create_stake_account_from_seed() {
|
||||
create_address_with_seed(&mint_pubkey, seed, &solana_stake_program::id()).unwrap();
|
||||
|
||||
// Create Vote Account
|
||||
let message = Message::new(vote_instruction::create_account(
|
||||
let message = Message::new(&vote_instruction::create_account(
|
||||
&mint_pubkey,
|
||||
&vote_pubkey,
|
||||
&VoteInit {
|
||||
@@ -432,7 +432,7 @@ fn test_create_stake_account_from_seed() {
|
||||
let authorized = stake_state::Authorized::auto(&mint_pubkey);
|
||||
// Create stake account and delegate to vote account
|
||||
let message = Message::new(
|
||||
stake_instruction::create_account_with_seed_and_delegate_stake(
|
||||
&stake_instruction::create_account_with_seed_and_delegate_stake(
|
||||
&mint_pubkey,
|
||||
&stake_pubkey,
|
||||
&mint_pubkey,
|
||||
|
@@ -49,7 +49,7 @@ fn test_account_owner() {
|
||||
let bank = Arc::new(bank);
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
|
||||
let message = Message::new(storage_instruction::create_storage_account(
|
||||
let message = Message::new(&storage_instruction::create_storage_account(
|
||||
&mint_pubkey,
|
||||
&account_owner,
|
||||
&validator_storage_pubkey,
|
||||
@@ -69,7 +69,7 @@ fn test_account_owner() {
|
||||
assert!(false, "wrong account type found")
|
||||
}
|
||||
|
||||
let message = Message::new(storage_instruction::create_storage_account(
|
||||
let message = Message::new(&storage_instruction::create_storage_account(
|
||||
&mint_pubkey,
|
||||
&account_owner,
|
||||
&archiver_storage_pubkey,
|
||||
@@ -137,7 +137,7 @@ fn test_validate_mining() {
|
||||
|
||||
// advertise for storage segment 1
|
||||
let message = Message::new_with_payer(
|
||||
vec![storage_instruction::advertise_recent_blockhash(
|
||||
&[storage_instruction::advertise_recent_blockhash(
|
||||
&validator_storage_id,
|
||||
Hash::default(),
|
||||
1,
|
||||
@@ -172,7 +172,7 @@ fn test_validate_mining() {
|
||||
));
|
||||
}
|
||||
let message = Message::new_with_payer(
|
||||
vec![storage_instruction::advertise_recent_blockhash(
|
||||
&[storage_instruction::advertise_recent_blockhash(
|
||||
&validator_storage_id,
|
||||
Hash::default(),
|
||||
2,
|
||||
@@ -195,7 +195,7 @@ fn test_validate_mining() {
|
||||
);
|
||||
|
||||
let message = Message::new_with_payer(
|
||||
vec![storage_instruction::proof_validation(
|
||||
&[storage_instruction::proof_validation(
|
||||
&validator_storage_id,
|
||||
proof_segment as u64,
|
||||
checked_proofs.into_iter().map(|entry| entry).collect(),
|
||||
@@ -209,7 +209,7 @@ fn test_validate_mining() {
|
||||
);
|
||||
|
||||
let message = Message::new_with_payer(
|
||||
vec![storage_instruction::advertise_recent_blockhash(
|
||||
&[storage_instruction::advertise_recent_blockhash(
|
||||
&validator_storage_id,
|
||||
Hash::default(),
|
||||
3,
|
||||
@@ -244,7 +244,7 @@ fn test_validate_mining() {
|
||||
.map(|account| Rewards::from_account(&account).unwrap())
|
||||
.unwrap();
|
||||
let message = Message::new_with_payer(
|
||||
vec![storage_instruction::claim_reward(
|
||||
&[storage_instruction::claim_reward(
|
||||
&owner_pubkey,
|
||||
&validator_storage_id,
|
||||
)],
|
||||
@@ -264,7 +264,7 @@ fn test_validate_mining() {
|
||||
assert_eq!(bank_client.get_balance(&archiver_1_storage_id).unwrap(), 10);
|
||||
|
||||
let message = Message::new_with_payer(
|
||||
vec![storage_instruction::claim_reward(
|
||||
&[storage_instruction::claim_reward(
|
||||
&owner_pubkey,
|
||||
&archiver_1_storage_id,
|
||||
)],
|
||||
@@ -278,7 +278,7 @@ fn test_validate_mining() {
|
||||
);
|
||||
|
||||
let message = Message::new_with_payer(
|
||||
vec![storage_instruction::claim_reward(
|
||||
&[storage_instruction::claim_reward(
|
||||
&owner_pubkey,
|
||||
&archiver_2_storage_id,
|
||||
)],
|
||||
@@ -328,7 +328,7 @@ fn init_storage_accounts(
|
||||
StorageAccountType::Archiver,
|
||||
))
|
||||
});
|
||||
let message = Message::new(ixs);
|
||||
let message = Message::new(&ixs);
|
||||
client.send_message(&signers, message).unwrap();
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ fn submit_proof(
|
||||
) -> ProofStatus {
|
||||
let sha_state = Hash::new(Pubkey::new_rand().as_ref());
|
||||
let message = Message::new_with_payer(
|
||||
vec![storage_instruction::mining_proof(
|
||||
&[storage_instruction::mining_proof(
|
||||
&storage_keypair.pubkey(),
|
||||
sha_state,
|
||||
segment_index,
|
||||
@@ -422,7 +422,7 @@ fn test_bank_storage() {
|
||||
let x2 = x * 2;
|
||||
let storage_blockhash = hash(&[x2]);
|
||||
|
||||
let message = Message::new(storage_instruction::create_storage_account(
|
||||
let message = Message::new(&storage_instruction::create_storage_account(
|
||||
&mint_pubkey,
|
||||
&Pubkey::default(),
|
||||
&archiver_pubkey,
|
||||
@@ -433,7 +433,7 @@ fn test_bank_storage() {
|
||||
.send_message(&[&mint_keypair, &archiver_keypair], message)
|
||||
.unwrap();
|
||||
|
||||
let message = Message::new(storage_instruction::create_storage_account(
|
||||
let message = Message::new(&storage_instruction::create_storage_account(
|
||||
&mint_pubkey,
|
||||
&Pubkey::default(),
|
||||
&validator_pubkey,
|
||||
@@ -445,7 +445,7 @@ fn test_bank_storage() {
|
||||
.unwrap();
|
||||
|
||||
let message = Message::new_with_payer(
|
||||
vec![storage_instruction::advertise_recent_blockhash(
|
||||
&[storage_instruction::advertise_recent_blockhash(
|
||||
&validator_pubkey,
|
||||
storage_blockhash,
|
||||
1,
|
||||
@@ -460,7 +460,7 @@ fn test_bank_storage() {
|
||||
|
||||
let slot = 0;
|
||||
let message = Message::new_with_payer(
|
||||
vec![storage_instruction::mining_proof(
|
||||
&[storage_instruction::mining_proof(
|
||||
&archiver_pubkey,
|
||||
Hash::default(),
|
||||
slot,
|
||||
|
Reference in New Issue
Block a user