Remove fee-payer guesswork from Message and Transaction (#10776)
* Make Message::new_with_payer the default constructor * Remove Transaction::new_[un]signed_instructions These guess the fee-payer instead of stating it explicitly
This commit is contained in:
parent
d5d5ad0071
commit
1c498369b5
|
@ -14,6 +14,7 @@ use solana_metrics::datapoint_info;
|
|||
use solana_sdk::{
|
||||
client::{Client, SyncClient},
|
||||
commitment_config::CommitmentConfig,
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
timing::{duration_as_ms, duration_as_s},
|
||||
|
@ -457,16 +458,14 @@ fn swapper<T>(
|
|||
.map(|(signer, swap, profit)| {
|
||||
let s: &Keypair = &signer;
|
||||
let owner = &signer.pubkey();
|
||||
Transaction::new_signed_instructions(
|
||||
&[s],
|
||||
&[exchange_instruction::swap_request(
|
||||
owner,
|
||||
&swap.0.pubkey,
|
||||
&swap.1.pubkey,
|
||||
&profit,
|
||||
)],
|
||||
blockhash,
|
||||
)
|
||||
let instruction = exchange_instruction::swap_request(
|
||||
owner,
|
||||
&swap.0.pubkey,
|
||||
&swap.1.pubkey,
|
||||
&profit,
|
||||
);
|
||||
let message = Message::new(&[instruction], Some(&s.pubkey()));
|
||||
Transaction::new(&[s], message, blockhash)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
@ -588,28 +587,26 @@ fn trader<T>(
|
|||
let owner_pubkey = &owner.pubkey();
|
||||
let trade_pubkey = &trade.pubkey();
|
||||
let space = mem::size_of::<ExchangeState>() as u64;
|
||||
Transaction::new_signed_instructions(
|
||||
&[owner.as_ref(), trade],
|
||||
&[
|
||||
system_instruction::create_account(
|
||||
owner_pubkey,
|
||||
trade_pubkey,
|
||||
1,
|
||||
space,
|
||||
&id(),
|
||||
),
|
||||
exchange_instruction::trade_request(
|
||||
owner_pubkey,
|
||||
trade_pubkey,
|
||||
*side,
|
||||
pair,
|
||||
tokens,
|
||||
price,
|
||||
src,
|
||||
),
|
||||
],
|
||||
blockhash,
|
||||
)
|
||||
let instructions = [
|
||||
system_instruction::create_account(
|
||||
owner_pubkey,
|
||||
trade_pubkey,
|
||||
1,
|
||||
space,
|
||||
&id(),
|
||||
),
|
||||
exchange_instruction::trade_request(
|
||||
owner_pubkey,
|
||||
trade_pubkey,
|
||||
*side,
|
||||
pair,
|
||||
tokens,
|
||||
price,
|
||||
src,
|
||||
),
|
||||
];
|
||||
let message = Message::new(&instructions, Some(&owner_pubkey));
|
||||
Transaction::new(&[owner.as_ref(), trade], message, blockhash)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
@ -747,13 +744,9 @@ pub fn fund_keys<T: Client>(client: &T, source: &Keypair, dests: &[Arc<Keypair>]
|
|||
let mut to_fund_txs: Vec<_> = chunk
|
||||
.par_iter()
|
||||
.map(|(k, m)| {
|
||||
(
|
||||
k.clone(),
|
||||
Transaction::new_unsigned_instructions(&system_instruction::transfer_many(
|
||||
&k.pubkey(),
|
||||
&m,
|
||||
)),
|
||||
)
|
||||
let instructions = system_instruction::transfer_many(&k.pubkey(), &m);
|
||||
let message = Message::new(&instructions, Some(&k.pubkey()));
|
||||
(k.clone(), Transaction::new_unsigned(message))
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
@ -848,9 +841,10 @@ pub fn create_token_accounts<T: Client>(
|
|||
);
|
||||
let request_ix =
|
||||
exchange_instruction::account_request(owner_pubkey, &new_keypair.pubkey());
|
||||
let message = Message::new(&[create_ix, request_ix], Some(&owner_pubkey));
|
||||
(
|
||||
(from_keypair, new_keypair),
|
||||
Transaction::new_unsigned_instructions(&[create_ix, request_ix]),
|
||||
Transaction::new_unsigned(message),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
|
|
@ -14,6 +14,7 @@ use solana_sdk::{
|
|||
commitment_config::CommitmentConfig,
|
||||
fee_calculator::FeeCalculator,
|
||||
hash::Hash,
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
system_instruction, system_transaction,
|
||||
|
@ -652,10 +653,9 @@ impl<'a> FundingTransactions<'a> for Vec<(&'a Keypair, Transaction)> {
|
|||
let to_fund_txs: Vec<(&Keypair, Transaction)> = to_fund
|
||||
.par_iter()
|
||||
.map(|(k, t)| {
|
||||
let tx = Transaction::new_unsigned_instructions(
|
||||
&system_instruction::transfer_many(&k.pubkey(), &t),
|
||||
);
|
||||
(*k, tx)
|
||||
let instructions = system_instruction::transfer_many(&k.pubkey(), &t);
|
||||
let message = Message::new(&instructions, Some(&k.pubkey()));
|
||||
(*k, Transaction::new_unsigned(message))
|
||||
})
|
||||
.collect();
|
||||
make_txs.stop();
|
||||
|
@ -1023,11 +1023,9 @@ fn fund_move_keys<T: Client>(
|
|||
.iter()
|
||||
.map(|key| (key.pubkey(), total / NUM_FUNDING_KEYS as u64))
|
||||
.collect();
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[funding_key],
|
||||
&system_instruction::transfer_many(&funding_key.pubkey(), &pubkey_amounts),
|
||||
blockhash,
|
||||
);
|
||||
let instructions = system_instruction::transfer_many(&funding_key.pubkey(), &pubkey_amounts);
|
||||
let message = Message::new(&instructions, Some(&funding_key.pubkey()));
|
||||
let tx = Transaction::new(&[funding_key], message, blockhash);
|
||||
client.send_message(&[funding_key], tx.message).unwrap();
|
||||
let mut balance = 0;
|
||||
for _ in 0..20 {
|
||||
|
|
|
@ -137,11 +137,11 @@ mod tests {
|
|||
let pubkey0 = Pubkey::new(&[0; 32]);
|
||||
let pubkey1 = Pubkey::new(&[1; 32]);
|
||||
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||
let message0 = Message::new(&[ix0]);
|
||||
let message0 = Message::new(&[ix0], Some(&pubkey0));
|
||||
|
||||
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||
let ix1 = system_instruction::transfer(&pubkey1, &pubkey0, 1);
|
||||
let message1 = Message::new(&[ix0, ix1]);
|
||||
let message1 = Message::new(&[ix0, ix1], Some(&pubkey0));
|
||||
|
||||
let mut mocks = HashMap::new();
|
||||
mocks.insert(RpcRequest::GetBalance, account_balance_response.clone());
|
||||
|
@ -225,13 +225,13 @@ mod tests {
|
|||
let pubkey0 = Pubkey::new(&[0; 32]);
|
||||
let pubkey1 = Pubkey::new(&[1; 32]);
|
||||
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||
let message0 = Message::new(&[ix0]);
|
||||
let message0 = Message::new(&[ix0], Some(&pubkey0));
|
||||
assert_eq!(calculate_fee(&fee_calculator, &[&message0]), 1);
|
||||
|
||||
// Two messages, additive fees.
|
||||
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||
let ix1 = system_instruction::transfer(&pubkey1, &pubkey0, 1);
|
||||
let message1 = Message::new(&[ix0, ix1]);
|
||||
let message1 = Message::new(&[ix0, ix1], Some(&pubkey0));
|
||||
assert_eq!(calculate_fee(&fee_calculator, &[&message0, &message1]), 3);
|
||||
}
|
||||
|
||||
|
|
|
@ -1377,7 +1377,7 @@ fn process_deploy(
|
|||
program_data.len() as u64,
|
||||
&bpf_loader::id(),
|
||||
);
|
||||
let message = Message::new(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||
let mut create_account_tx = Transaction::new_unsigned(message);
|
||||
let signers = [config.signers[0], program_id];
|
||||
create_account_tx.try_sign(&signers, blockhash)?;
|
||||
|
@ -1390,7 +1390,7 @@ fn process_deploy(
|
|||
(i * DATA_CHUNK_SIZE) as u32,
|
||||
chunk.to_vec(),
|
||||
);
|
||||
let message = Message::new_with_payer(&[instruction], Some(&signers[0].pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&signers[0].pubkey()));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
tx.try_sign(&signers, blockhash)?;
|
||||
write_transactions.push(tx);
|
||||
|
@ -1400,7 +1400,7 @@ fn process_deploy(
|
|||
}
|
||||
|
||||
let instruction = loader_instruction::finalize(&program_id.pubkey(), &bpf_loader::id());
|
||||
let message = Message::new_with_payer(&[instruction], Some(&signers[0].pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&signers[0].pubkey()));
|
||||
let mut finalize_tx = Transaction::new_unsigned(message);
|
||||
finalize_tx.try_sign(&signers, blockhash)?;
|
||||
messages.push(&finalize_tx.message);
|
||||
|
@ -1483,7 +1483,7 @@ fn process_pay(
|
|||
if let Some(nonce_account) = &nonce_account {
|
||||
Message::new_with_nonce(vec![ix], None, nonce_account, &nonce_authority.pubkey())
|
||||
} else {
|
||||
Message::new(&[ix])
|
||||
Message::new(&[ix], Some(&config.signers[0].pubkey()))
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1539,7 +1539,7 @@ fn process_pay(
|
|||
cancelable,
|
||||
lamports,
|
||||
);
|
||||
Message::new(&ixs)
|
||||
Message::new(&ixs, Some(&config.signers[0].pubkey()))
|
||||
};
|
||||
let (message, _) = resolve_spend_tx_and_check_account_balance(
|
||||
rpc_client,
|
||||
|
@ -1590,7 +1590,7 @@ fn process_pay(
|
|||
cancelable,
|
||||
lamports,
|
||||
);
|
||||
Message::new(&ixs)
|
||||
Message::new(&ixs, Some(&config.signers[0].pubkey()))
|
||||
};
|
||||
let (message, _) = resolve_spend_tx_and_check_account_balance(
|
||||
rpc_client,
|
||||
|
@ -1633,7 +1633,7 @@ fn process_cancel(rpc_client: &RpcClient, config: &CliConfig, pubkey: &Pubkey) -
|
|||
pubkey,
|
||||
&config.signers[0].pubkey(),
|
||||
);
|
||||
let message = Message::new(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
tx.try_sign(&config.signers, blockhash)?;
|
||||
check_account_for_fee_with_commitment(
|
||||
|
@ -1663,7 +1663,7 @@ fn process_time_elapsed(
|
|||
.value;
|
||||
|
||||
let ix = budget_instruction::apply_timestamp(&config.signers[0].pubkey(), pubkey, to, dt);
|
||||
let message = Message::new(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
tx.try_sign(&config.signers, blockhash)?;
|
||||
check_account_for_fee_with_commitment(
|
||||
|
@ -1714,7 +1714,7 @@ fn process_transfer(
|
|||
&nonce_authority.pubkey(),
|
||||
)
|
||||
} else {
|
||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
||||
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1765,7 +1765,7 @@ fn process_witness(
|
|||
.value;
|
||||
|
||||
let ix = budget_instruction::apply_signature(&config.signers[0].pubkey(), pubkey, to);
|
||||
let message = Message::new(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
tx.try_sign(&config.signers, blockhash)?;
|
||||
check_account_for_fee_with_commitment(
|
||||
|
|
|
@ -892,7 +892,7 @@ pub fn process_ping(
|
|||
|
||||
let build_message = |lamports| {
|
||||
let ix = system_instruction::transfer(&config.signers[0].pubkey(), &to, lamports);
|
||||
Message::new(&[ix])
|
||||
Message::new(&[ix], Some(&config.signers[0].pubkey()))
|
||||
};
|
||||
let (message, _) = resolve_spend_tx_and_check_account_balance(
|
||||
rpc_client,
|
||||
|
|
|
@ -453,7 +453,7 @@ pub fn process_authorize_nonce_account(
|
|||
|
||||
let nonce_authority = config.signers[nonce_authority];
|
||||
let ix = authorize_nonce_account(nonce_account, &nonce_authority.pubkey(), new_authority);
|
||||
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
||||
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||
|
||||
|
@ -512,7 +512,7 @@ pub fn process_create_nonce_account(
|
|||
lamports,
|
||||
)
|
||||
};
|
||||
Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()))
|
||||
Message::new(&ixs, Some(&config.signers[0].pubkey()))
|
||||
};
|
||||
|
||||
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||
|
@ -600,7 +600,7 @@ pub fn process_new_nonce(
|
|||
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||
.value;
|
||||
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
||||
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||
check_account_for_fee_with_commitment(
|
||||
|
@ -667,7 +667,7 @@ pub fn process_withdraw_from_nonce_account(
|
|||
destination_account_pubkey,
|
||||
lamports,
|
||||
);
|
||||
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
||||
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||
check_account_for_fee_with_commitment(
|
||||
|
|
|
@ -891,7 +891,7 @@ pub fn process_create_stake_account(
|
|||
&nonce_authority.pubkey(),
|
||||
)
|
||||
} else {
|
||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
||||
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -996,7 +996,7 @@ pub fn process_stake_authorize(
|
|||
&nonce_authority.pubkey(),
|
||||
)
|
||||
} else {
|
||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
||||
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||
};
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
|
||||
|
@ -1056,7 +1056,7 @@ pub fn process_deactivate_stake_account(
|
|||
&nonce_authority.pubkey(),
|
||||
)
|
||||
} else {
|
||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
||||
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||
};
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
|
||||
|
@ -1125,7 +1125,7 @@ pub fn process_withdraw_stake(
|
|||
&nonce_authority.pubkey(),
|
||||
)
|
||||
} else {
|
||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
||||
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||
};
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
|
||||
|
@ -1265,7 +1265,7 @@ pub fn process_split_stake(
|
|||
&nonce_authority.pubkey(),
|
||||
)
|
||||
} else {
|
||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
||||
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||
};
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
|
||||
|
@ -1364,7 +1364,7 @@ pub fn process_merge_stake(
|
|||
&nonce_authority.pubkey(),
|
||||
)
|
||||
} else {
|
||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
||||
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||
};
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
|
||||
|
@ -1427,7 +1427,7 @@ pub fn process_stake_set_lockup(
|
|||
&nonce_authority.pubkey(),
|
||||
)
|
||||
} else {
|
||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
||||
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||
};
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
|
||||
|
@ -1712,7 +1712,7 @@ pub fn process_delegate_stake(
|
|||
&nonce_authority.pubkey(),
|
||||
)
|
||||
} else {
|
||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
||||
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||
};
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
|
||||
|
|
|
@ -346,7 +346,7 @@ pub fn process_set_validator_info(
|
|||
keys,
|
||||
&validator_info,
|
||||
)]);
|
||||
Message::new(&instructions)
|
||||
Message::new(&instructions, Some(&config.signers[0].pubkey()))
|
||||
} else {
|
||||
println!(
|
||||
"Updating Validator {:?} info at: {:?}",
|
||||
|
@ -359,7 +359,7 @@ pub fn process_set_validator_info(
|
|||
keys,
|
||||
&validator_info,
|
||||
)];
|
||||
Message::new_with_payer(&instructions, Some(&config.signers[0].pubkey()))
|
||||
Message::new(&instructions, Some(&config.signers[0].pubkey()))
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -469,7 +469,7 @@ pub fn process_create_vote_account(
|
|||
lamports,
|
||||
)
|
||||
};
|
||||
Message::new(&ixs)
|
||||
Message::new(&ixs, Some(&config.signers[0].pubkey()))
|
||||
};
|
||||
|
||||
if let Ok(response) =
|
||||
|
@ -540,7 +540,7 @@ pub fn process_vote_authorize(
|
|||
vote_authorize, // vote or withdraw
|
||||
)];
|
||||
|
||||
let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()));
|
||||
let message = Message::new(&ixs, Some(&config.signers[0].pubkey()));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||
check_account_for_fee_with_commitment(
|
||||
|
@ -580,7 +580,7 @@ pub fn process_vote_update_validator(
|
|||
&new_identity_pubkey,
|
||||
)];
|
||||
|
||||
let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()));
|
||||
let message = Message::new(&ixs, Some(&config.signers[0].pubkey()));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||
check_account_for_fee_with_commitment(
|
||||
|
@ -614,7 +614,7 @@ pub fn process_vote_update_commission(
|
|||
commission,
|
||||
)];
|
||||
|
||||
let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()));
|
||||
let message = Message::new(&ixs, Some(&config.signers[0].pubkey()));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||
check_account_for_fee_with_commitment(
|
||||
|
@ -743,7 +743,7 @@ pub fn process_withdraw_from_vote_account(
|
|||
destination_account_pubkey,
|
||||
);
|
||||
|
||||
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
||||
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||
let mut transaction = Transaction::new_unsigned(message);
|
||||
transaction.try_sign(&config.signers, recent_blockhash)?;
|
||||
check_account_for_fee_with_commitment(
|
||||
|
|
|
@ -336,7 +336,7 @@ impl SyncClient for ThinClient {
|
|||
keypair: &Keypair,
|
||||
instruction: Instruction,
|
||||
) -> TransportResult<Signature> {
|
||||
let message = Message::new(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&keypair.pubkey()));
|
||||
self.send_message(&[keypair], message)
|
||||
}
|
||||
|
||||
|
@ -574,7 +574,7 @@ impl AsyncClient for ThinClient {
|
|||
instruction: Instruction,
|
||||
recent_blockhash: Hash,
|
||||
) -> TransportResult<Signature> {
|
||||
let message = Message::new(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&keypair.pubkey()));
|
||||
self.async_send_message(&[keypair], message, recent_blockhash)
|
||||
}
|
||||
fn async_transfer(
|
||||
|
|
|
@ -19,6 +19,7 @@ use solana_perf::test_tx::test_tx;
|
|||
use solana_runtime::bank::Bank;
|
||||
use solana_sdk::genesis_config::GenesisConfig;
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::message::Message;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::Keypair;
|
||||
use solana_sdk::signature::Signature;
|
||||
|
@ -116,9 +117,8 @@ fn make_programs_txs(txes: usize, hash: Hash) -> Vec<Transaction> {
|
|||
let to_key = Pubkey::new_rand();
|
||||
instructions.push(system_instruction::transfer(&from_key.pubkey(), &to_key, 1));
|
||||
}
|
||||
let mut new = Transaction::new_unsigned_instructions(&instructions);
|
||||
new.sign(&[&from_key], hash);
|
||||
new
|
||||
let message = Message::new(&instructions, Some(&from_key.pubkey()));
|
||||
Transaction::new(&[&from_key], message, hash)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
|
@ -1711,7 +1711,7 @@ pub mod tests {
|
|||
&leader_vote_keypair.pubkey(),
|
||||
vote,
|
||||
);
|
||||
let vote_msg = Message::new_with_payer(&[vote_ix], Some(&leader_vote_keypair.pubkey()));
|
||||
let vote_msg = Message::new(&[vote_ix], Some(&leader_vote_keypair.pubkey()));
|
||||
let vote_tx = Transaction::new(&[&leader_vote_keypair], vote_msg, Hash::default());
|
||||
let shreds = entries_to_test_shreds(
|
||||
vec![next_entry_mut(&mut Hash::default(), 0, vec![vote_tx])],
|
||||
|
@ -3425,7 +3425,7 @@ pub mod tests {
|
|||
bank.get_minimum_balance_for_rent_exemption(VoteState::size_of()),
|
||||
);
|
||||
|
||||
let message = Message::new_with_payer(&instructions, Some(&alice.pubkey()));
|
||||
let message = Message::new(&instructions, Some(&alice.pubkey()));
|
||||
let transaction = Transaction::new(
|
||||
&[&alice, &alice_vote_keypair],
|
||||
message,
|
||||
|
|
|
@ -376,6 +376,7 @@ mod tests {
|
|||
};
|
||||
use solana_sdk::{
|
||||
hash::Hash,
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
system_program, system_transaction,
|
||||
|
@ -571,11 +572,8 @@ mod tests {
|
|||
None,
|
||||
51,
|
||||
);
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&contract_funds, &contract_state],
|
||||
&ixs,
|
||||
blockhash,
|
||||
);
|
||||
let message = Message::new(&ixs, Some(&contract_funds.pubkey()));
|
||||
let tx = Transaction::new(&[&contract_funds, &contract_state], message, blockhash);
|
||||
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions, 1).unwrap();
|
||||
sleep(Duration::from_millis(200));
|
||||
|
||||
|
@ -617,7 +615,8 @@ mod tests {
|
|||
&contract_state.pubkey(),
|
||||
&bob_pubkey,
|
||||
);
|
||||
let tx = Transaction::new_signed_instructions(&[&witness], &[ix], blockhash);
|
||||
let message = Message::new(&[ix], Some(&witness.pubkey()));
|
||||
let tx = Transaction::new(&[&witness], message, blockhash);
|
||||
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions, 1).unwrap();
|
||||
sleep(Duration::from_millis(200));
|
||||
|
||||
|
|
|
@ -125,9 +125,10 @@ impl Faucet {
|
|||
);
|
||||
info!("Requesting airdrop of {} to {:?}", lamports, to);
|
||||
|
||||
let mint_pubkey = self.mint_keypair.pubkey();
|
||||
let create_instruction =
|
||||
system_instruction::transfer(&self.mint_keypair.pubkey(), &to, lamports);
|
||||
let message = Message::new(&[create_instruction]);
|
||||
system_instruction::transfer(&mint_pubkey, &to, lamports);
|
||||
let message = Message::new(&[create_instruction], Some(&mint_pubkey));
|
||||
Ok(Transaction::new(&[&self.mint_keypair], message, blockhash))
|
||||
} else {
|
||||
Err(Error::new(
|
||||
|
@ -413,7 +414,7 @@ mod tests {
|
|||
|
||||
let keypair = Keypair::new();
|
||||
let expected_instruction = system_instruction::transfer(&keypair.pubkey(), &to, lamports);
|
||||
let message = Message::new(&[expected_instruction]);
|
||||
let message = Message::new(&[expected_instruction], Some(&keypair.pubkey()));
|
||||
let expected_tx = Transaction::new(&[&keypair], message, blockhash);
|
||||
let expected_bytes = serialize(&expected_tx).unwrap();
|
||||
let mut expected_vec_with_length = vec![0; 2];
|
||||
|
|
|
@ -16,7 +16,7 @@ fn test_local_faucet() {
|
|||
let lamports = 50;
|
||||
let blockhash = Hash::new(&to.as_ref());
|
||||
let create_instruction = system_instruction::transfer(&keypair.pubkey(), &to, lamports);
|
||||
let message = Message::new(&[create_instruction]);
|
||||
let message = Message::new(&[create_instruction], Some(&keypair.pubkey()));
|
||||
let expected_tx = Transaction::new(&[&keypair], message, blockhash);
|
||||
|
||||
let (sender, receiver) = channel();
|
||||
|
|
|
@ -218,9 +218,9 @@ fn new_update_manifest(
|
|||
lamports,
|
||||
vec![], // additional keys
|
||||
);
|
||||
let mut transaction = Transaction::new_unsigned_instructions(&instructions);
|
||||
let message = Message::new(&instructions, Some(&from_keypair.pubkey()));
|
||||
let signers = [from_keypair, update_manifest_keypair];
|
||||
transaction.sign(&signers, recent_blockhash);
|
||||
let transaction = Transaction::new(&signers, message, recent_blockhash);
|
||||
rpc_client.send_and_confirm_transaction(&transaction)?;
|
||||
}
|
||||
Ok(())
|
||||
|
@ -243,7 +243,7 @@ fn store_update_manifest(
|
|||
update_manifest,
|
||||
);
|
||||
|
||||
let message = Message::new_with_payer(&[instruction], Some(&from_keypair.pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&from_keypair.pubkey()));
|
||||
let transaction = Transaction::new(&signers, message, recent_blockhash);
|
||||
rpc_client.send_and_confirm_transaction(&transaction)?;
|
||||
Ok(())
|
||||
|
|
|
@ -592,11 +592,14 @@ fn do_main(matches: &ArgMatches<'_>) -> Result<(), Box<dyn error::Error>> {
|
|||
}
|
||||
("verify", Some(matches)) => {
|
||||
let keypair = get_keypair_from_matches(matches, config, &mut wallet_manager)?;
|
||||
let simple_message = Message::new(&[Instruction::new(
|
||||
Pubkey::default(),
|
||||
&0,
|
||||
vec![AccountMeta::new(keypair.pubkey(), true)],
|
||||
)])
|
||||
let simple_message = Message::new(
|
||||
&[Instruction::new(
|
||||
Pubkey::default(),
|
||||
&0,
|
||||
vec![AccountMeta::new(keypair.pubkey(), true)],
|
||||
)],
|
||||
Some(&keypair.pubkey()),
|
||||
)
|
||||
.serialize();
|
||||
let signature = keypair.try_sign_message(&simple_message)?;
|
||||
let pubkey_bs58 = matches.value_of("pubkey").unwrap();
|
||||
|
|
|
@ -5225,7 +5225,7 @@ pub mod tests {
|
|||
timestamp,
|
||||
};
|
||||
let vote_ix = vote_instruction::vote(&keypair.pubkey(), &keypair.pubkey(), vote);
|
||||
let vote_msg = Message::new_with_payer(&[vote_ix], Some(&keypair.pubkey()));
|
||||
let vote_msg = Message::new(&[vote_ix], Some(&keypair.pubkey()));
|
||||
let vote_tx = Transaction::new(&[keypair], vote_msg, Hash::default());
|
||||
|
||||
vote_entries.push(next_entry_mut(&mut Hash::default(), 0, vec![vote_tx]));
|
||||
|
|
|
@ -677,6 +677,7 @@ mod tests {
|
|||
use solana_budget_program::budget_instruction;
|
||||
use solana_sdk::{
|
||||
hash::{hash, Hash},
|
||||
message::Message,
|
||||
signature::{Keypair, Signer},
|
||||
system_transaction,
|
||||
transaction::Transaction,
|
||||
|
@ -687,19 +688,22 @@ mod tests {
|
|||
let budget_contract = Keypair::new();
|
||||
let budget_pubkey = budget_contract.pubkey();
|
||||
let ixs = budget_instruction::payment(&pubkey, &pubkey, &budget_pubkey, 1);
|
||||
Transaction::new_signed_instructions(&[keypair, &budget_contract], &ixs, hash)
|
||||
let message = Message::new(&ixs, Some(&pubkey));
|
||||
Transaction::new(&[keypair, &budget_contract], message, hash)
|
||||
}
|
||||
|
||||
fn create_sample_timestamp(keypair: &Keypair, hash: Hash) -> Transaction {
|
||||
let pubkey = keypair.pubkey();
|
||||
let ix = budget_instruction::apply_timestamp(&pubkey, &pubkey, &pubkey, Utc::now());
|
||||
Transaction::new_signed_instructions(&[keypair], &[ix], hash)
|
||||
let message = Message::new(&[ix], Some(&pubkey));
|
||||
Transaction::new(&[keypair], message, hash)
|
||||
}
|
||||
|
||||
fn create_sample_apply_signature(keypair: &Keypair, hash: Hash) -> Transaction {
|
||||
let pubkey = keypair.pubkey();
|
||||
let ix = budget_instruction::apply_signature(&pubkey, &pubkey, &pubkey);
|
||||
Transaction::new_signed_instructions(&[keypair], &[ix], hash)
|
||||
let message = Message::new(&[ix], Some(&pubkey));
|
||||
Transaction::new(&[keypair], message, hash)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -21,6 +21,7 @@ use solana_sdk::{
|
|||
commitment_config::CommitmentConfig,
|
||||
epoch_schedule::EpochSchedule,
|
||||
genesis_config::{GenesisConfig, OperatingMode},
|
||||
message::Message,
|
||||
poh_config::PohConfig,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
|
@ -407,19 +408,21 @@ impl LocalCluster {
|
|||
{
|
||||
// 1) Create vote account
|
||||
|
||||
let mut transaction = Transaction::new_signed_instructions(
|
||||
let instructions = vote_instruction::create_account(
|
||||
&from_account.pubkey(),
|
||||
&vote_account_pubkey,
|
||||
&VoteInit {
|
||||
node_pubkey,
|
||||
authorized_voter: vote_account_pubkey,
|
||||
authorized_withdrawer: vote_account_pubkey,
|
||||
commission: 0,
|
||||
},
|
||||
amount,
|
||||
);
|
||||
let message = Message::new(&instructions, Some(&from_account.pubkey()));
|
||||
let mut transaction = Transaction::new(
|
||||
&[from_account.as_ref(), vote_account],
|
||||
&vote_instruction::create_account(
|
||||
&from_account.pubkey(),
|
||||
&vote_account_pubkey,
|
||||
&VoteInit {
|
||||
node_pubkey,
|
||||
authorized_voter: vote_account_pubkey,
|
||||
authorized_withdrawer: vote_account_pubkey,
|
||||
commission: 0,
|
||||
},
|
||||
amount,
|
||||
),
|
||||
message,
|
||||
client
|
||||
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
||||
.unwrap()
|
||||
|
@ -436,16 +439,18 @@ impl LocalCluster {
|
|||
)
|
||||
.expect("get balance");
|
||||
|
||||
let mut transaction = Transaction::new_signed_instructions(
|
||||
let instructions = stake_instruction::create_account_and_delegate_stake(
|
||||
&from_account.pubkey(),
|
||||
&stake_account_pubkey,
|
||||
&vote_account_pubkey,
|
||||
&Authorized::auto(&stake_account_pubkey),
|
||||
&Lockup::default(),
|
||||
amount,
|
||||
);
|
||||
let message = Message::new(&instructions, Some(&from_account.pubkey()));
|
||||
let mut transaction = Transaction::new(
|
||||
&[from_account.as_ref(), &stake_account_keypair],
|
||||
&stake_instruction::create_account_and_delegate_stake(
|
||||
&from_account.pubkey(),
|
||||
&stake_account_pubkey,
|
||||
&vote_account_pubkey,
|
||||
&Authorized::auto(&stake_account_pubkey),
|
||||
&Lockup::default(),
|
||||
amount,
|
||||
),
|
||||
message,
|
||||
client
|
||||
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
||||
.unwrap()
|
||||
|
|
|
@ -308,7 +308,6 @@ mod bpf {
|
|||
result.unwrap_err().unwrap(),
|
||||
TransactionError::InstructionError(0, InstructionError::MaxSeedLengthExceeded)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,10 +363,12 @@ mod bpf {
|
|||
let derived_key2 =
|
||||
Pubkey::create_program_address(&[b"Lil'", b"Bits"], &invoked_program_id).unwrap();
|
||||
let derived_key3 =
|
||||
Pubkey::create_program_address(&[derived_key2.as_ref()], &invoked_program_id).unwrap();
|
||||
Pubkey::create_program_address(&[derived_key2.as_ref()], &invoked_program_id)
|
||||
.unwrap();
|
||||
|
||||
let mint_pubkey = mint_keypair.pubkey();
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(mint_keypair.pubkey(), true),
|
||||
AccountMeta::new(mint_pubkey, true),
|
||||
AccountMeta::new(argument_keypair.pubkey(), true),
|
||||
AccountMeta::new_readonly(invoked_program_id, false),
|
||||
AccountMeta::new(invoked_argument_keypair.pubkey(), true),
|
||||
|
@ -384,7 +385,7 @@ mod bpf {
|
|||
|
||||
let instruction =
|
||||
Instruction::new(invoke_program_id, &TEST_SUCCESS, account_metas.clone());
|
||||
let message = Message::new(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&mint_pubkey));
|
||||
assert!(bank_client
|
||||
.send_message(
|
||||
&[
|
||||
|
@ -404,7 +405,7 @@ mod bpf {
|
|||
&TEST_PRIVILEGE_ESCALATION_SIGNER,
|
||||
account_metas.clone(),
|
||||
);
|
||||
let message = Message::new(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&mint_pubkey));
|
||||
assert_eq!(
|
||||
bank_client
|
||||
.send_message(
|
||||
|
@ -426,7 +427,7 @@ mod bpf {
|
|||
&TEST_PRIVILEGE_ESCALATION_WRITABLE,
|
||||
account_metas.clone(),
|
||||
);
|
||||
let message = Message::new(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&mint_pubkey));
|
||||
assert_eq!(
|
||||
bank_client
|
||||
.send_message(
|
||||
|
|
|
@ -774,7 +774,7 @@ fn call<'a>(
|
|||
ro_regions,
|
||||
)?;
|
||||
verify_instruction(syscall, &instruction, &signers)?;
|
||||
let message = Message::new_with_payer(&[instruction], None);
|
||||
let message = Message::new(&[instruction], None);
|
||||
let callee_program_id_index = message.instructions[0].program_id_index as usize;
|
||||
let callee_program_id = message.account_keys[callee_program_id_index];
|
||||
let (accounts, refs) = syscall.translate_accounts(
|
||||
|
|
|
@ -256,7 +256,7 @@ mod tests {
|
|||
budget_instruction::payment(&alice_pubkey, &bob_pubkey, &budget_pubkey, 1);
|
||||
instructions[1].accounts = vec![]; // <!-- Attack! Prevent accounts from being passed into processor.
|
||||
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
assert_eq!(
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
|
@ -276,7 +276,7 @@ mod tests {
|
|||
let budget_pubkey = budget_keypair.pubkey();
|
||||
let instructions =
|
||||
budget_instruction::payment(&alice_pubkey, &bob_pubkey, &budget_pubkey, 100);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
.unwrap();
|
||||
|
@ -302,7 +302,7 @@ mod tests {
|
|||
None,
|
||||
1,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
.unwrap();
|
||||
|
@ -315,7 +315,7 @@ mod tests {
|
|||
.unwrap();
|
||||
let instruction =
|
||||
budget_instruction::apply_signature(&mallory_pubkey, &budget_pubkey, &bob_pubkey);
|
||||
let mut message = Message::new(&[instruction]);
|
||||
let mut message = Message::new(&[instruction], Some(&mallory_pubkey));
|
||||
|
||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||
message.account_keys.insert(3, alice_pubkey);
|
||||
|
@ -352,7 +352,7 @@ mod tests {
|
|||
None,
|
||||
1,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
.unwrap();
|
||||
|
@ -365,7 +365,7 @@ mod tests {
|
|||
.unwrap();
|
||||
let instruction =
|
||||
budget_instruction::apply_timestamp(&mallory_pubkey, &budget_pubkey, &bob_pubkey, dt);
|
||||
let mut message = Message::new(&[instruction]);
|
||||
let mut message = Message::new(&[instruction], Some(&mallory_pubkey));
|
||||
|
||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||
message.account_keys.insert(3, alice_pubkey);
|
||||
|
@ -402,7 +402,7 @@ mod tests {
|
|||
None,
|
||||
1,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
.unwrap();
|
||||
|
@ -472,7 +472,7 @@ mod tests {
|
|||
Some(alice_pubkey),
|
||||
1,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
.unwrap();
|
||||
|
@ -550,7 +550,7 @@ mod tests {
|
|||
game_hash,
|
||||
41,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
.unwrap();
|
||||
|
@ -570,7 +570,7 @@ mod tests {
|
|||
|
||||
// Anyone can sign the message, but presumably it's Bob, since he's the
|
||||
// one claiming the payout.
|
||||
let message = Message::new_with_payer(&[instruction], Some(&bob_pubkey));
|
||||
let message = Message::new(&[instruction], Some(&bob_pubkey));
|
||||
bank_client.send_message(&[&bob_keypair], message).unwrap();
|
||||
|
||||
assert_eq!(bank_client.get_balance(&alice_pubkey).unwrap(), 0);
|
||||
|
|
|
@ -604,7 +604,10 @@ mod test {
|
|||
);
|
||||
|
||||
client
|
||||
.send_message(&[owner, &new], Message::new(&[instruction]))
|
||||
.send_message(
|
||||
&[owner, &new],
|
||||
Message::new(&[instruction], Some(&owner.pubkey())),
|
||||
)
|
||||
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
|
||||
new.pubkey()
|
||||
}
|
||||
|
|
|
@ -30,11 +30,14 @@ pub fn create_genesis<T: Client>(from: &Keypair, client: &T, amount: u64) -> Key
|
|||
);
|
||||
|
||||
client
|
||||
.send_message(&[&from, &genesis], Message::new(&[instruction]))
|
||||
.send_message(
|
||||
&[&from, &genesis],
|
||||
Message::new(&[instruction], Some(&from.pubkey())),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let instruction = librapay_instruction::genesis(&genesis.pubkey(), amount);
|
||||
let message = Message::new_with_payer(&[instruction], Some(&from.pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&from.pubkey()));
|
||||
client.send_message(&[from, &genesis], message).unwrap();
|
||||
|
||||
genesis
|
||||
|
|
|
@ -8,6 +8,7 @@ use solana_sdk::{
|
|||
client::Client,
|
||||
commitment_config::CommitmentConfig,
|
||||
hash::Hash,
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
system_instruction,
|
||||
|
@ -87,7 +88,8 @@ pub fn create_accounts(
|
|||
|
||||
let mut from_signers = vec![from_keypair];
|
||||
from_signers.extend_from_slice(to_keypair);
|
||||
Transaction::new_signed_instructions(&from_signers, &instructions, recent_blockhash)
|
||||
let message = Message::new(&instructions, Some(&from_keypair.pubkey()));
|
||||
Transaction::new(&from_signers, message, recent_blockhash)
|
||||
}
|
||||
|
||||
pub fn create_account(
|
||||
|
|
|
@ -93,7 +93,7 @@ mod tests {
|
|||
owner_pubkey,
|
||||
lamports,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&payer_keypair.pubkey()));
|
||||
bank_client.send_message(&[payer_keypair, account_keypair], message)
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ mod tests {
|
|||
&old_owner_keypair.pubkey(),
|
||||
new_owner_pubkey,
|
||||
);
|
||||
let message = Message::new_with_payer(&[instruction], Some(&payer_keypair.pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&payer_keypair.pubkey()));
|
||||
bank_client.send_message(&[payer_keypair, old_owner_keypair], message)
|
||||
}
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ mod tests {
|
|||
date_instruction::create_account(&payer_keypair.pubkey(), &date_pubkey, 1);
|
||||
instructions.push(date_instruction::store(&date_pubkey, date));
|
||||
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&payer_keypair.pubkey()));
|
||||
bank_client.send_message(&[payer_keypair, date_keypair], message)
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ mod tests {
|
|||
) -> Result<Signature> {
|
||||
let date_pubkey = date_keypair.pubkey();
|
||||
let instruction = date_instruction::store(&date_pubkey, date);
|
||||
let message = Message::new_with_payer(&[instruction], Some(&payer_keypair.pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&payer_keypair.pubkey()));
|
||||
bank_client.send_message(&[payer_keypair, date_keypair], message)
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ mod tests {
|
|||
&date_pubkey,
|
||||
lamports,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&payer_keypair.pubkey()));
|
||||
bank_client.send_message(&[payer_keypair, contract_keypair], message)
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ mod tests {
|
|||
) -> Result<Signature> {
|
||||
let instruction =
|
||||
vest_instruction::redeem_tokens(&contract_pubkey, &date_pubkey, &payee_pubkey);
|
||||
let message = Message::new_with_payer(&[instruction], Some(&payer_keypair.pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&payer_keypair.pubkey()));
|
||||
bank_client.send_message(&[payer_keypair], message)
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,7 @@ mod tests {
|
|||
);
|
||||
instructions[1].accounts = vec![]; // <!-- Attack! Prevent accounts from being passed into processor.
|
||||
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_keypair.pubkey()));
|
||||
assert_eq!(
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &contract_keypair], message)
|
||||
|
|
|
@ -5,6 +5,7 @@ use solana_notifier::Notifier;
|
|||
use solana_sdk::{
|
||||
clock::Slot,
|
||||
epoch_schedule::EpochSchedule,
|
||||
message::Message,
|
||||
native_token::sol_to_lamports,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
|
@ -138,16 +139,18 @@ fn delegate_stake(
|
|||
}
|
||||
};
|
||||
|
||||
let transaction = Transaction::new_signed_instructions(
|
||||
let instructions = stake_instruction::create_account_and_delegate_stake(
|
||||
&faucet_keypair.pubkey(),
|
||||
&stake_account_keypair.pubkey(),
|
||||
&vote_account_pubkey,
|
||||
&StakeAuthorized::auto(&faucet_keypair.pubkey()),
|
||||
&Lockup::default(),
|
||||
sol_to_lamports(sol_gift as f64),
|
||||
);
|
||||
let message = Message::new(&instructions, Some(&faucet_keypair.pubkey()));
|
||||
let transaction = Transaction::new(
|
||||
&[faucet_keypair, &stake_account_keypair],
|
||||
&stake_instruction::create_account_and_delegate_stake(
|
||||
&faucet_keypair.pubkey(),
|
||||
&stake_account_keypair.pubkey(),
|
||||
&vote_account_pubkey,
|
||||
&StakeAuthorized::auto(&faucet_keypair.pubkey()),
|
||||
&Lockup::default(),
|
||||
sol_to_lamports(sol_gift as f64),
|
||||
),
|
||||
message,
|
||||
recent_blockhash,
|
||||
);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use solana_sdk::{
|
|||
clock::MAX_RECENT_BLOCKHASHES,
|
||||
genesis_config::create_genesis_config,
|
||||
instruction::InstructionError,
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
transaction::Transaction,
|
||||
|
@ -52,7 +53,8 @@ pub fn create_builtin_transactions(
|
|||
|
||||
let instruction = create_invoke_instruction(rando0.pubkey(), program_id, &1u8);
|
||||
let (blockhash, _fee_calculator) = bank_client.get_recent_blockhash().unwrap();
|
||||
Transaction::new_signed_instructions(&[&rando0], &[instruction], blockhash)
|
||||
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey()));
|
||||
Transaction::new(&[&rando0], message, blockhash)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -73,7 +75,8 @@ pub fn create_native_loader_transactions(
|
|||
|
||||
let instruction = create_invoke_instruction(rando0.pubkey(), program_id, &1u8);
|
||||
let (blockhash, _fee_calculator) = bank_client.get_recent_blockhash().unwrap();
|
||||
Transaction::new_signed_instructions(&[&rando0], &[instruction], blockhash)
|
||||
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey()));
|
||||
Transaction::new(&[&rando0], message, blockhash)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
|
@ -4273,11 +4273,8 @@ mod tests {
|
|||
let bank = Bank::new(&genesis_config);
|
||||
let instructions =
|
||||
system_instruction::transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&mint_keypair],
|
||||
&instructions,
|
||||
genesis_config.hash(),
|
||||
);
|
||||
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||
let tx = Transaction::new(&[&mint_keypair], message, genesis_config.hash());
|
||||
assert_eq!(
|
||||
bank.process_transaction(&tx).unwrap_err(),
|
||||
TransactionError::InstructionError(
|
||||
|
@ -4298,11 +4295,8 @@ mod tests {
|
|||
let bank = Bank::new(&genesis_config);
|
||||
let instructions =
|
||||
system_instruction::transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&mint_keypair],
|
||||
&instructions,
|
||||
genesis_config.hash(),
|
||||
);
|
||||
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||
let tx = Transaction::new(&[&mint_keypair], message, genesis_config.hash());
|
||||
bank.process_transaction(&tx).unwrap();
|
||||
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), 0);
|
||||
assert_eq!(bank.get_balance(&key1), 1);
|
||||
|
@ -5452,7 +5446,7 @@ mod tests {
|
|||
let mut transfer_instruction =
|
||||
system_instruction::transfer(&mint_keypair.pubkey(), &key.pubkey(), 0);
|
||||
transfer_instruction.accounts[0].is_signer = false;
|
||||
let message = Message::new_with_payer(&[transfer_instruction], None);
|
||||
let message = Message::new(&[transfer_instruction], None);
|
||||
let tx = Transaction::new(&[&Keypair::new(); 0], message, bank.last_blockhash());
|
||||
|
||||
assert_eq!(
|
||||
|
@ -5633,9 +5627,10 @@ mod tests {
|
|||
10,
|
||||
);
|
||||
|
||||
let transaction = Transaction::new_signed_instructions(
|
||||
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||
let transaction = Transaction::new(
|
||||
&[&mint_keypair, &vote_keypair],
|
||||
&instructions,
|
||||
message,
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
|
||||
|
@ -5690,9 +5685,10 @@ mod tests {
|
|||
10,
|
||||
));
|
||||
|
||||
let transaction = Transaction::new_signed_instructions(
|
||||
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||
let transaction = Transaction::new(
|
||||
&[&mint_keypair, &vote_keypair, &stake_keypair],
|
||||
&instructions,
|
||||
message,
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
|
||||
|
@ -5889,9 +5885,10 @@ mod tests {
|
|||
);
|
||||
instructions[1].program_id = mock_vote_program_id();
|
||||
|
||||
let transaction = Transaction::new_signed_instructions(
|
||||
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||
let transaction = Transaction::new(
|
||||
&[&mint_keypair, &mock_account, &mock_validator_identity],
|
||||
&instructions,
|
||||
message,
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
|
||||
|
@ -5933,9 +5930,10 @@ mod tests {
|
|||
1,
|
||||
);
|
||||
|
||||
let transaction = Transaction::new_signed_instructions(
|
||||
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||
let transaction = Transaction::new(
|
||||
&[&mint_keypair, &mock_account, &mock_validator_identity],
|
||||
&instructions,
|
||||
message,
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
|
||||
|
@ -6123,9 +6121,10 @@ mod tests {
|
|||
&nonce_authority,
|
||||
nonce_lamports,
|
||||
));
|
||||
let setup_tx = Transaction::new_signed_instructions(
|
||||
let message = Message::new(&setup_ixs, Some(&mint_keypair.pubkey()));
|
||||
let setup_tx = Transaction::new(
|
||||
&[mint_keypair, &custodian_keypair, &nonce_keypair],
|
||||
&setup_ixs,
|
||||
message,
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
bank.process_transaction(&setup_tx)?;
|
||||
|
@ -6286,14 +6285,9 @@ mod tests {
|
|||
let blockhash = bank.last_blockhash();
|
||||
bank.store_account(&nonce.pubkey(), &nonce_account);
|
||||
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&nonce],
|
||||
&[system_instruction::assign(
|
||||
&nonce.pubkey(),
|
||||
&Pubkey::new(&[9u8; 32]),
|
||||
)],
|
||||
blockhash,
|
||||
);
|
||||
let ix = system_instruction::assign(&nonce.pubkey(), &Pubkey::new(&[9u8; 32]));
|
||||
let message = Message::new(&[ix], Some(&nonce.pubkey()));
|
||||
let tx = Transaction::new(&[&nonce], message, blockhash);
|
||||
|
||||
let expect = Err(TransactionError::InstructionError(
|
||||
0,
|
||||
|
|
|
@ -60,7 +60,7 @@ impl AsyncClient for BankClient {
|
|||
instruction: Instruction,
|
||||
recent_blockhash: Hash,
|
||||
) -> Result<Signature> {
|
||||
let message = Message::new(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&keypair.pubkey()));
|
||||
self.async_send_message(&[keypair], message, recent_blockhash)
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,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(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&keypair.pubkey()));
|
||||
self.send_message(&[keypair], message)
|
||||
}
|
||||
|
||||
|
@ -306,7 +306,7 @@ mod tests {
|
|||
.accounts
|
||||
.push(AccountMeta::new(jane_pubkey, true));
|
||||
|
||||
let message = Message::new(&[transfer_instruction]);
|
||||
let message = Message::new(&[transfer_instruction], Some(&john_pubkey));
|
||||
bank_client.send_message(&doe_keypairs, message).unwrap();
|
||||
assert_eq!(bank_client.get_balance(&bob_pubkey).unwrap(), 42);
|
||||
}
|
||||
|
|
|
@ -906,7 +906,7 @@ mod tests {
|
|||
.transfer(50, &mint_keypair, &alice_pubkey)
|
||||
.unwrap();
|
||||
|
||||
let allocate_with_seed = Message::new_with_payer(
|
||||
let allocate_with_seed = Message::new(
|
||||
&[system_instruction::allocate_with_seed(
|
||||
&alice_with_seed,
|
||||
&alice_pubkey,
|
||||
|
@ -959,7 +959,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(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&alice_pubkey));
|
||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||
assert!(r.is_ok());
|
||||
|
||||
|
@ -977,7 +977,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(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&alice_pubkey));
|
||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||
assert!(r.is_ok());
|
||||
}
|
||||
|
@ -1016,7 +1016,7 @@ mod tests {
|
|||
.transfer(50, &mint_keypair, &alice_pubkey)
|
||||
.unwrap();
|
||||
|
||||
let assign_with_seed = Message::new_with_payer(
|
||||
let assign_with_seed = Message::new(
|
||||
&[system_instruction::assign_with_seed(
|
||||
&alice_with_seed,
|
||||
&alice_pubkey,
|
||||
|
|
|
@ -28,7 +28,7 @@ pub fn load_program<T: Client>(
|
|||
bank_client
|
||||
.send_message(
|
||||
&[from_keypair, &program_keypair],
|
||||
Message::new(&[instruction]),
|
||||
Message::new(&[instruction], Some(&from_keypair.pubkey())),
|
||||
)
|
||||
.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(&[instruction], Some(&from_keypair.pubkey()));
|
||||
let message = Message::new(&[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(&[instruction], Some(&from_keypair.pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&from_keypair.pubkey()));
|
||||
bank_client
|
||||
.send_message(&[from_keypair, &program_keypair], message)
|
||||
.unwrap();
|
||||
|
|
|
@ -606,7 +606,7 @@ mod tests {
|
|||
AccountMeta::new(keys[not_owned_index], false),
|
||||
AccountMeta::new(keys[owned_index], false),
|
||||
];
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[Instruction::new(program_ids[owned_index], &[0_u8], metas)],
|
||||
None,
|
||||
);
|
||||
|
@ -1103,11 +1103,14 @@ mod tests {
|
|||
AccountMeta::new(from_pubkey, true),
|
||||
AccountMeta::new_readonly(to_pubkey, false),
|
||||
];
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::Correct,
|
||||
account_metas.clone(),
|
||||
)]);
|
||||
let message = Message::new(
|
||||
&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::Correct,
|
||||
account_metas.clone(),
|
||||
)],
|
||||
Some(&from_pubkey),
|
||||
);
|
||||
|
||||
let result =
|
||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||
|
@ -1115,11 +1118,14 @@ mod tests {
|
|||
assert_eq!(accounts[0].borrow().lamports, 100);
|
||||
assert_eq!(accounts[1].borrow().lamports, 0);
|
||||
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::AttemptCredit { lamports: 50 },
|
||||
account_metas.clone(),
|
||||
)]);
|
||||
let message = Message::new(
|
||||
&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::AttemptCredit { lamports: 50 },
|
||||
account_metas.clone(),
|
||||
)],
|
||||
Some(&from_pubkey),
|
||||
);
|
||||
|
||||
let result =
|
||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||
|
@ -1131,11 +1137,14 @@ mod tests {
|
|||
))
|
||||
);
|
||||
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::AttemptDataChange { data: 50 },
|
||||
account_metas,
|
||||
)]);
|
||||
let message = Message::new(
|
||||
&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::AttemptDataChange { data: 50 },
|
||||
account_metas,
|
||||
)],
|
||||
Some(&from_pubkey),
|
||||
);
|
||||
|
||||
let result =
|
||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||
|
@ -1229,11 +1238,14 @@ mod tests {
|
|||
];
|
||||
|
||||
// Try to borrow mut the same account
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::BorrowFail,
|
||||
account_metas.clone(),
|
||||
)]);
|
||||
let message = Message::new(
|
||||
&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::BorrowFail,
|
||||
account_metas.clone(),
|
||||
)],
|
||||
Some(&from_pubkey),
|
||||
);
|
||||
let result =
|
||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||
assert_eq!(
|
||||
|
@ -1245,24 +1257,30 @@ mod tests {
|
|||
);
|
||||
|
||||
// Try to borrow mut the same account in a safe way
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::MultiBorrowMut,
|
||||
account_metas.clone(),
|
||||
)]);
|
||||
let message = Message::new(
|
||||
&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::MultiBorrowMut,
|
||||
account_metas.clone(),
|
||||
)],
|
||||
Some(&from_pubkey),
|
||||
);
|
||||
let result =
|
||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||
assert_eq!(result, Ok(()));
|
||||
|
||||
// Do work on the same account but at different location in keyed_accounts[]
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::DoWork {
|
||||
lamports: 10,
|
||||
data: 42,
|
||||
},
|
||||
account_metas,
|
||||
)]);
|
||||
let message = Message::new(
|
||||
&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::DoWork {
|
||||
lamports: 10,
|
||||
data: 42,
|
||||
},
|
||||
account_metas,
|
||||
)],
|
||||
Some(&from_pubkey),
|
||||
);
|
||||
let result =
|
||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||
assert_eq!(result, Ok(()));
|
||||
|
@ -1349,7 +1367,7 @@ mod tests {
|
|||
&MockInstruction::NoopSuccess,
|
||||
metas.clone(),
|
||||
);
|
||||
let message = Message::new_with_payer(&[instruction], None);
|
||||
let message = Message::new(&[instruction], None);
|
||||
assert_eq!(
|
||||
message_processor.process_cross_program_instruction(
|
||||
&message,
|
||||
|
@ -1376,7 +1394,7 @@ mod tests {
|
|||
|
||||
for case in cases {
|
||||
let instruction = Instruction::new(callee_program_id, &case.0, metas.clone());
|
||||
let message = Message::new_with_payer(&[instruction], None);
|
||||
let message = Message::new(&[instruction], None);
|
||||
assert_eq!(
|
||||
message_processor.process_cross_program_instruction(
|
||||
&message,
|
||||
|
|
|
@ -93,6 +93,7 @@ mod tests {
|
|||
account_utils::State as AccountUtilsState,
|
||||
hash::Hash,
|
||||
instruction::InstructionError,
|
||||
message::Message,
|
||||
nonce::{self, account::with_test_keyed_account, Account as NonceAccount, State},
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
|
@ -106,14 +107,12 @@ mod tests {
|
|||
let from_pubkey = from_keypair.pubkey();
|
||||
let nonce_keypair = Keypair::new();
|
||||
let nonce_pubkey = nonce_keypair.pubkey();
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&from_keypair, &nonce_keypair],
|
||||
&[
|
||||
system_instruction::advance_nonce_account(&nonce_pubkey, &nonce_pubkey),
|
||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||
],
|
||||
Hash::default(),
|
||||
);
|
||||
let instructions = [
|
||||
system_instruction::advance_nonce_account(&nonce_pubkey, &nonce_pubkey),
|
||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||
];
|
||||
let message = Message::new(&instructions, Some(&nonce_pubkey));
|
||||
let tx = Transaction::new(&[&from_keypair, &nonce_keypair], message, Hash::default());
|
||||
(from_pubkey, nonce_pubkey, tx)
|
||||
}
|
||||
|
||||
|
@ -141,14 +140,12 @@ mod tests {
|
|||
let from_pubkey = from_keypair.pubkey();
|
||||
let nonce_keypair = Keypair::new();
|
||||
let nonce_pubkey = nonce_keypair.pubkey();
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&from_keypair, &nonce_keypair],
|
||||
&[
|
||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||
system_instruction::advance_nonce_account(&nonce_pubkey, &nonce_pubkey),
|
||||
],
|
||||
Hash::default(),
|
||||
);
|
||||
let instructions = [
|
||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||
system_instruction::advance_nonce_account(&nonce_pubkey, &nonce_pubkey),
|
||||
];
|
||||
let message = Message::new(&instructions, Some(&from_pubkey));
|
||||
let tx = Transaction::new(&[&from_keypair, &nonce_keypair], message, Hash::default());
|
||||
assert!(transaction_uses_durable_nonce(&tx).is_none());
|
||||
}
|
||||
|
||||
|
@ -158,19 +155,17 @@ mod tests {
|
|||
let from_pubkey = from_keypair.pubkey();
|
||||
let nonce_keypair = Keypair::new();
|
||||
let nonce_pubkey = nonce_keypair.pubkey();
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&from_keypair, &nonce_keypair],
|
||||
&[
|
||||
system_instruction::withdraw_nonce_account(
|
||||
&nonce_pubkey,
|
||||
&nonce_pubkey,
|
||||
&from_pubkey,
|
||||
42,
|
||||
),
|
||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||
],
|
||||
Hash::default(),
|
||||
);
|
||||
let instructions = [
|
||||
system_instruction::withdraw_nonce_account(
|
||||
&nonce_pubkey,
|
||||
&nonce_pubkey,
|
||||
&from_pubkey,
|
||||
42,
|
||||
),
|
||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||
];
|
||||
let message = Message::new(&instructions, Some(&nonce_pubkey));
|
||||
let tx = Transaction::new(&[&from_keypair, &nonce_keypair], message, Hash::default());
|
||||
assert!(transaction_uses_durable_nonce(&tx).is_none());
|
||||
}
|
||||
|
||||
|
|
|
@ -909,7 +909,7 @@ mod tests {
|
|||
.transfer(50, &mint_keypair, &alice_pubkey)
|
||||
.unwrap();
|
||||
|
||||
let allocate_with_seed = Message::new_with_payer(
|
||||
let allocate_with_seed = Message::new(
|
||||
&[system_instruction::allocate_with_seed(
|
||||
&alice_with_seed,
|
||||
&alice_pubkey,
|
||||
|
@ -962,7 +962,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(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&alice_keypair.pubkey()));
|
||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||
assert!(r.is_ok());
|
||||
|
||||
|
@ -980,7 +980,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(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&alice_pubkey));
|
||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||
assert!(r.is_ok());
|
||||
}
|
||||
|
@ -1019,7 +1019,7 @@ mod tests {
|
|||
.transfer(50, &mint_keypair, &alice_pubkey)
|
||||
.unwrap();
|
||||
|
||||
let assign_with_seed = Message::new_with_payer(
|
||||
let assign_with_seed = Message::new(
|
||||
&[system_instruction::assign_with_seed(
|
||||
&alice_with_seed,
|
||||
&alice_pubkey,
|
||||
|
|
|
@ -53,7 +53,7 @@ fn fill_epoch_with_votes(
|
|||
let bank_client = BankClient::new_shared(&bank);
|
||||
let parent = bank.parent().unwrap();
|
||||
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[vote_instruction::vote(
|
||||
&vote_pubkey,
|
||||
&vote_pubkey,
|
||||
|
@ -119,15 +119,18 @@ 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(
|
||||
&staker_pubkey, // from
|
||||
&stake_address, // to
|
||||
&staker_pubkey, // base
|
||||
"stake", // seed
|
||||
&authorized,
|
||||
&stake_state::Lockup::default(),
|
||||
lamports,
|
||||
));
|
||||
let message = Message::new(
|
||||
&stake_instruction::create_account_with_seed(
|
||||
&staker_pubkey, // from
|
||||
&stake_address, // to
|
||||
&staker_pubkey, // base
|
||||
"stake", // seed
|
||||
&authorized,
|
||||
&stake_state::Lockup::default(),
|
||||
lamports,
|
||||
),
|
||||
Some(&staker_pubkey),
|
||||
);
|
||||
|
||||
// only one signature required
|
||||
bank_client
|
||||
|
@ -139,7 +142,7 @@ fn test_stake_create_and_split_single_signature() {
|
|||
Pubkey::create_with_seed(&staker_pubkey, "split_stake", &solana_stake_program::id())
|
||||
.unwrap();
|
||||
// Test split
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&stake_instruction::split_with_seed(
|
||||
&stake_address, // original
|
||||
&staker_pubkey, // authorized
|
||||
|
@ -183,15 +186,18 @@ fn test_stake_create_and_split_to_existing_system_account() {
|
|||
let lamports = 1_000_000;
|
||||
|
||||
// Create stake account with seed
|
||||
let message = Message::new(&stake_instruction::create_account_with_seed(
|
||||
&staker_pubkey, // from
|
||||
&stake_address, // to
|
||||
&staker_pubkey, // base
|
||||
"stake", // seed
|
||||
&authorized,
|
||||
&stake_state::Lockup::default(),
|
||||
lamports,
|
||||
));
|
||||
let message = Message::new(
|
||||
&stake_instruction::create_account_with_seed(
|
||||
&staker_pubkey, // from
|
||||
&stake_address, // to
|
||||
&staker_pubkey, // base
|
||||
"stake", // seed
|
||||
&authorized,
|
||||
&stake_state::Lockup::default(),
|
||||
lamports,
|
||||
),
|
||||
Some(&staker_pubkey),
|
||||
);
|
||||
|
||||
bank_client
|
||||
.send_message(&[&staker_keypair], message)
|
||||
|
@ -212,7 +218,7 @@ fn test_stake_create_and_split_to_existing_system_account() {
|
|||
);
|
||||
|
||||
// Verify the split fails because the account is already in use
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&stake_instruction::split_with_seed(
|
||||
&stake_address, // original
|
||||
&staker_pubkey, // authorized
|
||||
|
@ -256,31 +262,37 @@ fn test_stake_account_lifetime() {
|
|||
let bank_client = BankClient::new_shared(&bank);
|
||||
|
||||
// Create Vote Account
|
||||
let message = Message::new(&vote_instruction::create_account(
|
||||
&mint_pubkey,
|
||||
&vote_pubkey,
|
||||
&VoteInit {
|
||||
node_pubkey: identity_pubkey,
|
||||
authorized_voter: vote_pubkey,
|
||||
authorized_withdrawer: vote_pubkey,
|
||||
commission: 50,
|
||||
},
|
||||
10,
|
||||
));
|
||||
let message = Message::new(
|
||||
&vote_instruction::create_account(
|
||||
&mint_pubkey,
|
||||
&vote_pubkey,
|
||||
&VoteInit {
|
||||
node_pubkey: identity_pubkey,
|
||||
authorized_voter: vote_pubkey,
|
||||
authorized_withdrawer: vote_pubkey,
|
||||
commission: 50,
|
||||
},
|
||||
10,
|
||||
),
|
||||
Some(&mint_pubkey),
|
||||
);
|
||||
bank_client
|
||||
.send_message(&[&mint_keypair, &vote_keypair, &identity_keypair], message)
|
||||
.expect("failed to create vote account");
|
||||
|
||||
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(
|
||||
&mint_pubkey,
|
||||
&stake_pubkey,
|
||||
&vote_pubkey,
|
||||
&authorized,
|
||||
&stake_state::Lockup::default(),
|
||||
1_000_000,
|
||||
));
|
||||
let message = Message::new(
|
||||
&stake_instruction::create_account_and_delegate_stake(
|
||||
&mint_pubkey,
|
||||
&stake_pubkey,
|
||||
&vote_pubkey,
|
||||
&authorized,
|
||||
&stake_state::Lockup::default(),
|
||||
1_000_000,
|
||||
),
|
||||
Some(&mint_pubkey),
|
||||
);
|
||||
bank_client
|
||||
.send_message(&[&mint_keypair, &stake_keypair], message)
|
||||
.expect("failed to create and delegate stake account");
|
||||
|
@ -295,7 +307,7 @@ fn test_stake_account_lifetime() {
|
|||
}
|
||||
|
||||
// Test that we cannot withdraw anything until deactivation
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[stake_instruction::withdraw(
|
||||
&stake_pubkey,
|
||||
&stake_pubkey,
|
||||
|
@ -359,7 +371,7 @@ fn test_stake_account_lifetime() {
|
|||
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
// Test split
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&stake_instruction::split(
|
||||
&stake_pubkey,
|
||||
&stake_pubkey,
|
||||
|
@ -376,7 +388,7 @@ fn test_stake_account_lifetime() {
|
|||
.is_ok());
|
||||
|
||||
// Deactivate the split
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[stake_instruction::deactivate_stake(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
|
@ -390,7 +402,7 @@ fn test_stake_account_lifetime() {
|
|||
let split_staked = get_staked(&bank, &split_stake_pubkey);
|
||||
|
||||
// Test that we cannot withdraw above what's staked
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[stake_instruction::withdraw(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
|
@ -412,7 +424,7 @@ fn test_stake_account_lifetime() {
|
|||
assert!(split_staked > 0);
|
||||
|
||||
// withdrawal in cooldown
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[stake_instruction::withdraw(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
|
@ -428,7 +440,7 @@ fn test_stake_account_lifetime() {
|
|||
.is_err());
|
||||
|
||||
// but we can withdraw unstaked
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[stake_instruction::withdraw(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
|
@ -453,7 +465,7 @@ fn test_stake_account_lifetime() {
|
|||
let bank_client = BankClient::new_shared(&bank);
|
||||
|
||||
// Test that we can withdraw everything else out of the split
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[stake_instruction::withdraw(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
|
@ -494,17 +506,20 @@ fn test_create_stake_account_from_seed() {
|
|||
Pubkey::create_with_seed(&mint_pubkey, seed, &solana_stake_program::id()).unwrap();
|
||||
|
||||
// Create Vote Account
|
||||
let message = Message::new(&vote_instruction::create_account(
|
||||
&mint_pubkey,
|
||||
&vote_pubkey,
|
||||
&VoteInit {
|
||||
node_pubkey: identity_pubkey,
|
||||
authorized_voter: vote_pubkey,
|
||||
authorized_withdrawer: vote_pubkey,
|
||||
commission: 50,
|
||||
},
|
||||
10,
|
||||
));
|
||||
let message = Message::new(
|
||||
&vote_instruction::create_account(
|
||||
&mint_pubkey,
|
||||
&vote_pubkey,
|
||||
&VoteInit {
|
||||
node_pubkey: identity_pubkey,
|
||||
authorized_voter: vote_pubkey,
|
||||
authorized_withdrawer: vote_pubkey,
|
||||
commission: 50,
|
||||
},
|
||||
10,
|
||||
),
|
||||
Some(&mint_pubkey),
|
||||
);
|
||||
bank_client
|
||||
.send_message(&[&mint_keypair, &vote_keypair, &identity_keypair], message)
|
||||
.expect("failed to create vote account");
|
||||
|
@ -522,6 +537,7 @@ fn test_create_stake_account_from_seed() {
|
|||
&stake_state::Lockup::default(),
|
||||
1_000_000,
|
||||
),
|
||||
Some(&mint_pubkey),
|
||||
);
|
||||
bank_client
|
||||
.send_message(&[&mint_keypair], message)
|
||||
|
|
|
@ -193,13 +193,13 @@ mod tests {
|
|||
let pubkey0 = Pubkey::new(&[0; 32]);
|
||||
let pubkey1 = Pubkey::new(&[1; 32]);
|
||||
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||
let message = Message::new(&[ix0]);
|
||||
let message = Message::new(&[ix0], Some(&pubkey0));
|
||||
assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 2);
|
||||
|
||||
// Two signatures, double the fee.
|
||||
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||
let ix1 = system_instruction::transfer(&pubkey1, &pubkey0, 1);
|
||||
let message = Message::new(&[ix0, ix1]);
|
||||
let message = Message::new(&[ix0, ix1], Some(&pubkey0));
|
||||
assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 4);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,18 +57,6 @@ impl InstructionKeys {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return the pubkey of the first writable signer in the given set of instructions.
|
||||
fn find_writable_signer(instructions: &[Instruction]) -> Option<&Pubkey> {
|
||||
for instruction in instructions {
|
||||
for account in &instruction.accounts {
|
||||
if account.is_signer && account.is_writable {
|
||||
return Some(&account.pubkey);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Return pubkeys referenced by all instructions, with the ones needing signatures first. If the
|
||||
/// payer key is provided, it is always placed first in the list of signed keys. Read-only signed
|
||||
/// accounts are placed last in the set of signed accounts. Read-only unsigned accounts,
|
||||
|
@ -245,12 +233,7 @@ impl Message {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(instructions: &[Instruction]) -> Self {
|
||||
let payer = find_writable_signer(instructions).expect("no suitable key for fee-payer");
|
||||
Self::new_with_payer(instructions, Some(payer))
|
||||
}
|
||||
|
||||
pub fn new_with_payer(instructions: &[Instruction], payer: Option<&Pubkey>) -> Self {
|
||||
pub fn new(instructions: &[Instruction], payer: Option<&Pubkey>) -> Self {
|
||||
let InstructionKeys {
|
||||
mut signed_keys,
|
||||
unsigned_keys,
|
||||
|
@ -281,7 +264,7 @@ impl Message {
|
|||
&nonce_authority_pubkey,
|
||||
);
|
||||
instructions.insert(0, nonce_ix);
|
||||
Self::new_with_payer(&instructions, payer)
|
||||
Self::new(&instructions, payer)
|
||||
}
|
||||
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
|
@ -523,11 +506,11 @@ mod tests {
|
|||
let program_id = Pubkey::default();
|
||||
let id0 = Pubkey::default();
|
||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]);
|
||||
let message = Message::new_with_payer(&[ix], None);
|
||||
let message = Message::new(&[ix], None);
|
||||
assert_eq!(message.header.num_required_signatures, 0);
|
||||
|
||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, true)]);
|
||||
let message = Message::new(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&id0));
|
||||
assert_eq!(message.header.num_required_signatures, 1);
|
||||
}
|
||||
|
||||
|
@ -560,11 +543,14 @@ mod tests {
|
|||
let id0 = Pubkey::default();
|
||||
let keypair1 = Keypair::new();
|
||||
let id1 = keypair1.pubkey();
|
||||
let message = Message::new(&[
|
||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id0, false)]),
|
||||
Instruction::new(program_id1, &0, vec![AccountMeta::new(id1, true)]),
|
||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id1, false)]),
|
||||
]);
|
||||
let message = Message::new(
|
||||
&[
|
||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id0, false)]),
|
||||
Instruction::new(program_id1, &0, vec![AccountMeta::new(id1, true)]),
|
||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id1, false)]),
|
||||
],
|
||||
Some(&id1),
|
||||
);
|
||||
assert_eq!(
|
||||
message.instructions[0],
|
||||
CompiledInstruction::new(2, &0, vec![1])
|
||||
|
@ -586,11 +572,11 @@ mod tests {
|
|||
let id0 = Pubkey::default();
|
||||
|
||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]);
|
||||
let message = Message::new_with_payer(&[ix], Some(&payer));
|
||||
let message = Message::new(&[ix], Some(&payer));
|
||||
assert_eq!(message.header.num_required_signatures, 1);
|
||||
|
||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, true)]);
|
||||
let message = Message::new_with_payer(&[ix], Some(&payer));
|
||||
let message = Message::new(&[ix], Some(&payer));
|
||||
assert_eq!(message.header.num_required_signatures, 2);
|
||||
|
||||
let ix = Instruction::new(
|
||||
|
@ -598,7 +584,7 @@ mod tests {
|
|||
&0,
|
||||
vec![AccountMeta::new(payer, true), AccountMeta::new(id0, true)],
|
||||
);
|
||||
let message = Message::new_with_payer(&[ix], Some(&payer));
|
||||
let message = Message::new(&[ix], Some(&payer));
|
||||
assert_eq!(message.header.num_required_signatures, 2);
|
||||
}
|
||||
|
||||
|
@ -625,10 +611,13 @@ mod tests {
|
|||
let program_id0 = Pubkey::default();
|
||||
let program_id1 = Pubkey::new_rand();
|
||||
let id = Pubkey::new_rand();
|
||||
let message = Message::new(&[
|
||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id, false)]),
|
||||
Instruction::new(program_id1, &0, vec![AccountMeta::new(id, true)]),
|
||||
]);
|
||||
let message = Message::new(
|
||||
&[
|
||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id, false)]),
|
||||
Instruction::new(program_id1, &0, vec![AccountMeta::new(id, true)]),
|
||||
],
|
||||
Some(&id),
|
||||
);
|
||||
assert_eq!(message.program_position(0), None);
|
||||
assert_eq!(message.program_position(1), Some(0));
|
||||
assert_eq!(message.program_position(2), Some(1));
|
||||
|
@ -668,12 +657,15 @@ mod tests {
|
|||
let id1 = Pubkey::new_rand();
|
||||
let id2 = Pubkey::new_rand();
|
||||
let id3 = Pubkey::new_rand();
|
||||
let message = Message::new(&[
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]),
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new(id1, true)]),
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new_readonly(id2, false)]),
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new_readonly(id3, true)]),
|
||||
]);
|
||||
let message = Message::new(
|
||||
&[
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]),
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new(id1, true)]),
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new_readonly(id2, false)]),
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new_readonly(id3, true)]),
|
||||
],
|
||||
Some(&id1),
|
||||
);
|
||||
assert_eq!(
|
||||
message.get_account_keys_by_lock_type(),
|
||||
(vec![&id1, &id0], vec![&id3, &id2, &program_id])
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use crate::{
|
||||
hash::Hash,
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
system_instruction,
|
||||
|
@ -19,20 +20,18 @@ pub fn create_account(
|
|||
) -> Transaction {
|
||||
let from_pubkey = from_keypair.pubkey();
|
||||
let to_pubkey = to_keypair.pubkey();
|
||||
let create_instruction =
|
||||
let instruction =
|
||||
system_instruction::create_account(&from_pubkey, &to_pubkey, lamports, space, program_id);
|
||||
Transaction::new_signed_instructions(
|
||||
&[from_keypair, to_keypair],
|
||||
&[create_instruction],
|
||||
recent_blockhash,
|
||||
)
|
||||
let message = Message::new(&[instruction], Some(&from_pubkey));
|
||||
Transaction::new(&[from_keypair, to_keypair], message, recent_blockhash)
|
||||
}
|
||||
|
||||
/// Create and sign new system_instruction::Assign transaction
|
||||
pub fn assign(from_keypair: &Keypair, recent_blockhash: Hash, program_id: &Pubkey) -> Transaction {
|
||||
let from_pubkey = from_keypair.pubkey();
|
||||
let assign_instruction = system_instruction::assign(&from_pubkey, program_id);
|
||||
Transaction::new_signed_instructions(&[from_keypair], &[assign_instruction], recent_blockhash)
|
||||
let instruction = system_instruction::assign(&from_pubkey, program_id);
|
||||
let message = Message::new(&[instruction], Some(&from_pubkey));
|
||||
Transaction::new(&[from_keypair], message, recent_blockhash)
|
||||
}
|
||||
|
||||
/// Create and sign new system_instruction::Transfer transaction
|
||||
|
@ -43,8 +42,9 @@ pub fn transfer(
|
|||
recent_blockhash: Hash,
|
||||
) -> Transaction {
|
||||
let from_pubkey = from_keypair.pubkey();
|
||||
let transfer_instruction = system_instruction::transfer(&from_pubkey, to, lamports);
|
||||
Transaction::new_signed_instructions(&[from_keypair], &[transfer_instruction], recent_blockhash)
|
||||
let instruction = system_instruction::transfer(&from_pubkey, to, lamports);
|
||||
let message = Message::new(&[instruction], Some(&from_pubkey));
|
||||
Transaction::new(&[from_keypair], message, recent_blockhash)
|
||||
}
|
||||
|
||||
/// Create and sign new nonced system_instruction::Transfer transaction
|
||||
|
@ -57,14 +57,12 @@ pub fn nonced_transfer(
|
|||
nonce_hash: Hash,
|
||||
) -> Transaction {
|
||||
let from_pubkey = from_keypair.pubkey();
|
||||
let transfer_instruction = system_instruction::transfer(&from_pubkey, to, lamports);
|
||||
let instructions = vec![transfer_instruction];
|
||||
Transaction::new_signed_with_nonce(
|
||||
instructions,
|
||||
let instruction = system_instruction::transfer(&from_pubkey, to, lamports);
|
||||
let message = Message::new_with_nonce(
|
||||
vec![instruction],
|
||||
Some(&from_pubkey),
|
||||
&[from_keypair, nonce_authority],
|
||||
nonce_account,
|
||||
&nonce_authority.pubkey(),
|
||||
nonce_hash,
|
||||
)
|
||||
);
|
||||
Transaction::new(&[from_keypair, nonce_authority], message, nonce_hash)
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ use crate::{
|
|||
short_vec,
|
||||
signature::{Signature, SignerError},
|
||||
signers::Signers,
|
||||
system_instruction,
|
||||
};
|
||||
use std::result;
|
||||
use thiserror::Error;
|
||||
|
@ -122,7 +121,7 @@ impl Transaction {
|
|||
}
|
||||
|
||||
pub fn new_with_payer(instructions: &[Instruction], payer: Option<&Pubkey>) -> Self {
|
||||
let message = Message::new_with_payer(instructions, payer);
|
||||
let message = Message::new(instructions, payer);
|
||||
Self::new_unsigned(message)
|
||||
}
|
||||
|
||||
|
@ -132,31 +131,10 @@ impl Transaction {
|
|||
signing_keypairs: &T,
|
||||
recent_blockhash: Hash,
|
||||
) -> Self {
|
||||
let message = Message::new_with_payer(instructions, payer);
|
||||
let message = Message::new(instructions, payer);
|
||||
Self::new(signing_keypairs, message, recent_blockhash)
|
||||
}
|
||||
|
||||
pub fn new_signed_with_nonce<T: Signers>(
|
||||
mut instructions: Vec<Instruction>,
|
||||
payer: Option<&Pubkey>,
|
||||
signing_keypairs: &T,
|
||||
nonce_account_pubkey: &Pubkey,
|
||||
nonce_authority_pubkey: &Pubkey,
|
||||
nonce_hash: Hash,
|
||||
) -> Self {
|
||||
let nonce_ix = system_instruction::advance_nonce_account(
|
||||
&nonce_account_pubkey,
|
||||
&nonce_authority_pubkey,
|
||||
);
|
||||
instructions.insert(0, nonce_ix);
|
||||
Self::new_signed_with_payer(&instructions, payer, signing_keypairs, nonce_hash)
|
||||
}
|
||||
|
||||
pub fn new_unsigned_instructions(instructions: &[Instruction]) -> Self {
|
||||
let message = Message::new(instructions);
|
||||
Self::new_unsigned(message)
|
||||
}
|
||||
|
||||
pub fn new<T: Signers>(
|
||||
from_keypairs: &T,
|
||||
message: Message,
|
||||
|
@ -167,15 +145,6 @@ impl Transaction {
|
|||
tx
|
||||
}
|
||||
|
||||
pub fn new_signed_instructions<T: Signers>(
|
||||
from_keypairs: &T,
|
||||
instructions: &[Instruction],
|
||||
recent_blockhash: Hash,
|
||||
) -> Transaction {
|
||||
let message = Message::new(instructions);
|
||||
Self::new(from_keypairs, message, recent_blockhash)
|
||||
}
|
||||
|
||||
/// Create a signed transaction
|
||||
/// * `from_keypairs` - The keys used to sign the transaction.
|
||||
/// * `keys` - The keys for the transaction. These are the program state
|
||||
|
@ -563,7 +532,7 @@ mod tests {
|
|||
AccountMeta::new(to, false),
|
||||
];
|
||||
let instruction = Instruction::new(program_id, &(1u8, 2u8, 3u8), account_metas);
|
||||
let message = Message::new(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&keypair.pubkey()));
|
||||
Transaction::new(&[&keypair], message, Hash::default())
|
||||
}
|
||||
|
||||
|
@ -594,7 +563,7 @@ mod tests {
|
|||
let expected_instruction_size = 1 + 1 + ix.accounts.len() + 1 + expected_data_size;
|
||||
assert_eq!(expected_instruction_size, 17);
|
||||
|
||||
let message = Message::new(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&alice_pubkey));
|
||||
assert_eq!(
|
||||
serialized_size(&message.instructions[0]).unwrap() as usize,
|
||||
expected_instruction_size,
|
||||
|
@ -650,19 +619,22 @@ mod tests {
|
|||
#[should_panic]
|
||||
fn test_transaction_missing_key() {
|
||||
let keypair = Keypair::new();
|
||||
Transaction::new_unsigned_instructions(&[]).sign(&[&keypair], Hash::default());
|
||||
let message = Message::new(&[], None);
|
||||
Transaction::new_unsigned(message).sign(&[&keypair], Hash::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_partial_sign_mismatched_key() {
|
||||
let keypair = Keypair::new();
|
||||
Transaction::new_unsigned_instructions(&[Instruction::new(
|
||||
let fee_payer = Pubkey::new_rand();
|
||||
let ix = Instruction::new(
|
||||
Pubkey::default(),
|
||||
&0,
|
||||
vec![AccountMeta::new(Pubkey::new_rand(), true)],
|
||||
)])
|
||||
.partial_sign(&[&keypair], Hash::default());
|
||||
vec![AccountMeta::new(fee_payer, true)],
|
||||
);
|
||||
let message = Message::new(&[ix], Some(&fee_payer));
|
||||
Transaction::new_unsigned(message).partial_sign(&[&keypair], Hash::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -670,7 +642,7 @@ mod tests {
|
|||
let keypair0 = Keypair::new();
|
||||
let keypair1 = Keypair::new();
|
||||
let keypair2 = Keypair::new();
|
||||
let mut tx = Transaction::new_unsigned_instructions(&[Instruction::new(
|
||||
let ix = Instruction::new(
|
||||
Pubkey::default(),
|
||||
&0,
|
||||
vec![
|
||||
|
@ -678,7 +650,9 @@ mod tests {
|
|||
AccountMeta::new(keypair1.pubkey(), true),
|
||||
AccountMeta::new(keypair2.pubkey(), true),
|
||||
],
|
||||
)]);
|
||||
);
|
||||
let message = Message::new(&[ix], Some(&keypair0.pubkey()));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
|
||||
tx.partial_sign(&[&keypair0, &keypair2], Hash::default());
|
||||
assert!(!tx.is_signed());
|
||||
|
@ -699,8 +673,8 @@ mod tests {
|
|||
let keypair0 = Keypair::new();
|
||||
let id0 = keypair0.pubkey();
|
||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, true)]);
|
||||
Transaction::new_unsigned_instructions(&[ix])
|
||||
.sign(&Vec::<&Keypair>::new(), Hash::default());
|
||||
let message = Message::new(&[ix], Some(&id0));
|
||||
Transaction::new_unsigned(message).sign(&Vec::<&Keypair>::new(), Hash::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -710,7 +684,8 @@ mod tests {
|
|||
let keypair0 = Keypair::new();
|
||||
let wrong_id = Pubkey::default();
|
||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(wrong_id, true)]);
|
||||
Transaction::new_unsigned_instructions(&[ix]).sign(&[&keypair0], Hash::default());
|
||||
let message = Message::new(&[ix], Some(&wrong_id));
|
||||
Transaction::new_unsigned(message).sign(&[&keypair0], Hash::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -719,7 +694,8 @@ mod tests {
|
|||
let keypair0 = Keypair::new();
|
||||
let id0 = keypair0.pubkey();
|
||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, true)]);
|
||||
let mut tx = Transaction::new_unsigned_instructions(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&id0));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
tx.sign(&[&keypair0], Hash::default());
|
||||
assert_eq!(
|
||||
tx.message.instructions[0],
|
||||
|
@ -744,7 +720,8 @@ mod tests {
|
|||
AccountMeta::new(id1, false),
|
||||
],
|
||||
);
|
||||
let mut tx = Transaction::new_unsigned_instructions(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&id0));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
tx.sign(&[&keypair0], Hash::default());
|
||||
assert_eq!(
|
||||
tx.message.instructions[0],
|
||||
|
@ -769,7 +746,8 @@ mod tests {
|
|||
AccountMeta::new(presigner_pubkey, true),
|
||||
],
|
||||
);
|
||||
let mut tx = Transaction::new_unsigned_instructions(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&pubkey));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
|
||||
let presigner_sig = presigner_keypair.sign_message(&tx.message_data());
|
||||
let presigner = Presigner::new(&presigner_pubkey, &presigner_sig);
|
||||
|
@ -791,7 +769,8 @@ mod tests {
|
|||
AccountMeta::new(presigner_pubkey, true),
|
||||
],
|
||||
);
|
||||
let mut tx = Transaction::new_unsigned_instructions(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&another_pubkey));
|
||||
let mut tx = Transaction::new_unsigned(message);
|
||||
|
||||
let res = tx.try_sign(&signers, Hash::default());
|
||||
assert!(res.is_err());
|
||||
|
|
|
@ -51,7 +51,7 @@ pub(crate) fn new_stake_account(
|
|||
&lockup,
|
||||
lamports,
|
||||
);
|
||||
Message::new_with_payer(&instructions, Some(fee_payer_pubkey))
|
||||
Message::new(&instructions, Some(fee_payer_pubkey))
|
||||
}
|
||||
|
||||
fn authorize_stake_accounts_instructions(
|
||||
|
@ -96,7 +96,7 @@ fn rebase_stake_account(
|
|||
new_base_pubkey,
|
||||
&i.to_string(),
|
||||
);
|
||||
let message = Message::new_with_payer(&instructions, Some(&fee_payer_pubkey));
|
||||
let message = Message::new(&instructions, Some(&fee_payer_pubkey));
|
||||
Some(message)
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ fn move_stake_account(
|
|||
);
|
||||
|
||||
instructions.extend(authorize_instructions.into_iter());
|
||||
let message = Message::new_with_payer(&instructions, Some(&fee_payer_pubkey));
|
||||
let message = Message::new(&instructions, Some(&fee_payer_pubkey));
|
||||
Some(message)
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ pub(crate) fn authorize_stake_accounts(
|
|||
new_stake_authority_pubkey,
|
||||
new_withdraw_authority_pubkey,
|
||||
);
|
||||
Message::new_with_payer(&instructions, Some(&fee_payer_pubkey))
|
||||
Message::new(&instructions, Some(&fee_payer_pubkey))
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ pub(crate) fn lockup_stake_accounts(
|
|||
return None;
|
||||
}
|
||||
let instruction = stake_instruction::set_lockup(address, &lockup, custodian_pubkey);
|
||||
let message = Message::new_with_payer(&[instruction], Some(&fee_payer_pubkey));
|
||||
let message = Message::new(&[instruction], Some(&fee_payer_pubkey));
|
||||
Some(message)
|
||||
})
|
||||
.collect()
|
||||
|
|
|
@ -396,16 +396,18 @@ mod test {
|
|||
|
||||
// Configure stake1
|
||||
let stake1_keypair = Keypair::new();
|
||||
let instructions = stake_instruction::create_account(
|
||||
&payer.pubkey(),
|
||||
&stake1_keypair.pubkey(),
|
||||
&Authorized::auto(&payer.pubkey()),
|
||||
&Lockup::default(),
|
||||
one_sol,
|
||||
);
|
||||
let message = Message::new(&instructions, Some(&payer.pubkey()));
|
||||
let stake1_signature = rpc_client
|
||||
.send_transaction(&Transaction::new_signed_instructions(
|
||||
.send_transaction(&Transaction::new(
|
||||
&[&payer, &stake1_keypair],
|
||||
&stake_instruction::create_account(
|
||||
&payer.pubkey(),
|
||||
&stake1_keypair.pubkey(),
|
||||
&Authorized::auto(&payer.pubkey()),
|
||||
&Lockup::default(),
|
||||
one_sol,
|
||||
),
|
||||
message,
|
||||
blockhash,
|
||||
))
|
||||
.unwrap();
|
||||
|
@ -426,35 +428,39 @@ mod test {
|
|||
|
||||
// Configure stake2 with non-compliant lockup
|
||||
let stake2_keypair = Keypair::new();
|
||||
let instructions = stake_instruction::create_account(
|
||||
&payer.pubkey(),
|
||||
&stake2_keypair.pubkey(),
|
||||
&Authorized::auto(&payer.pubkey()),
|
||||
&Lockup {
|
||||
custodian: payer.pubkey(),
|
||||
..Lockup::default()
|
||||
},
|
||||
one_sol,
|
||||
);
|
||||
let message = Message::new(&instructions, Some(&payer.pubkey()));
|
||||
let stake2_signature = rpc_client
|
||||
.send_transaction(&Transaction::new_signed_instructions(
|
||||
.send_transaction(&Transaction::new(
|
||||
&[&payer, &stake2_keypair],
|
||||
&stake_instruction::create_account(
|
||||
&payer.pubkey(),
|
||||
&stake2_keypair.pubkey(),
|
||||
&Authorized::auto(&payer.pubkey()),
|
||||
&Lockup {
|
||||
custodian: payer.pubkey(),
|
||||
..Lockup::default()
|
||||
},
|
||||
one_sol,
|
||||
),
|
||||
message,
|
||||
blockhash,
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
// Configure stake3
|
||||
let stake3_keypair = Keypair::new();
|
||||
let instructions = stake_instruction::create_account(
|
||||
&payer.pubkey(),
|
||||
&stake3_keypair.pubkey(),
|
||||
&Authorized::auto(&payer.pubkey()),
|
||||
&Lockup::default(),
|
||||
one_sol,
|
||||
);
|
||||
let message = Message::new(&instructions, Some(&payer.pubkey()));
|
||||
let stake3_initialize_signature = rpc_client
|
||||
.send_transaction(&Transaction::new_signed_instructions(
|
||||
.send_transaction(&Transaction::new(
|
||||
&[&payer, &stake3_keypair],
|
||||
&stake_instruction::create_account(
|
||||
&payer.pubkey(),
|
||||
&stake3_keypair.pubkey(),
|
||||
&Authorized::auto(&payer.pubkey()),
|
||||
&Lockup::default(),
|
||||
one_sol,
|
||||
),
|
||||
message,
|
||||
blockhash,
|
||||
))
|
||||
.unwrap();
|
||||
|
@ -471,7 +477,7 @@ mod test {
|
|||
.send_transaction_with_config(
|
||||
&Transaction::new(
|
||||
&[&payer, &stake3_keypair],
|
||||
Message::new_with_payer(
|
||||
Message::new(
|
||||
&[stake_instruction::withdraw(
|
||||
&stake3_keypair.pubkey(),
|
||||
&stake3_keypair.pubkey(),
|
||||
|
@ -498,16 +504,18 @@ mod test {
|
|||
|
||||
// Configure stake4
|
||||
let stake4_keypair = Keypair::new();
|
||||
let instructions = stake_instruction::create_account(
|
||||
&payer.pubkey(),
|
||||
&stake4_keypair.pubkey(),
|
||||
&Authorized::auto(&payer.pubkey()),
|
||||
&Lockup::default(),
|
||||
2 * one_sol,
|
||||
);
|
||||
let message = Message::new(&instructions, Some(&payer.pubkey()));
|
||||
let stake4_initialize_signature = rpc_client
|
||||
.send_transaction(&Transaction::new_signed_instructions(
|
||||
.send_transaction(&Transaction::new(
|
||||
&[&payer, &stake4_keypair],
|
||||
&stake_instruction::create_account(
|
||||
&payer.pubkey(),
|
||||
&stake4_keypair.pubkey(),
|
||||
&Authorized::auto(&payer.pubkey()),
|
||||
&Lockup::default(),
|
||||
2 * one_sol,
|
||||
),
|
||||
message,
|
||||
blockhash,
|
||||
))
|
||||
.unwrap();
|
||||
|
@ -525,7 +533,7 @@ mod test {
|
|||
.send_transaction_with_config(
|
||||
&Transaction::new(
|
||||
&[&payer, &stake5_keypair],
|
||||
Message::new_with_payer(
|
||||
Message::new(
|
||||
&stake_instruction::split(
|
||||
&stake4_keypair.pubkey(),
|
||||
&payer.pubkey(),
|
||||
|
|
|
@ -642,7 +642,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
);
|
||||
source_stake_lamports_required += config.baseline_stake_amount;
|
||||
create_stake_transactions.push((
|
||||
Transaction::new_unsigned(Message::new_with_payer(
|
||||
Transaction::new_unsigned(Message::new(
|
||||
&stake_instruction::split_with_seed(
|
||||
&config.source_stake_address,
|
||||
&config.authorized_staker.pubkey(),
|
||||
|
@ -680,7 +680,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
);
|
||||
source_stake_lamports_required += config.bonus_stake_amount;
|
||||
create_stake_transactions.push((
|
||||
Transaction::new_unsigned(Message::new_with_payer(
|
||||
Transaction::new_unsigned(Message::new(
|
||||
&stake_instruction::split_with_seed(
|
||||
&config.source_stake_address,
|
||||
&config.authorized_staker.pubkey(),
|
||||
|
@ -712,7 +712,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
// Delegate baseline stake
|
||||
if !stake_activated_in_current_epoch.contains(&baseline_stake_address) {
|
||||
delegate_stake_transactions.push((
|
||||
Transaction::new_unsigned(Message::new_with_payer(
|
||||
Transaction::new_unsigned(Message::new(
|
||||
&[stake_instruction::delegate_stake(
|
||||
&baseline_stake_address,
|
||||
&config.authorized_staker.pubkey(),
|
||||
|
@ -734,7 +734,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
if !stake_activated_in_current_epoch.contains(&bonus_stake_address) {
|
||||
delegate_stake_transactions.push((
|
||||
Transaction::new_unsigned(
|
||||
Message::new_with_payer(
|
||||
Message::new(
|
||||
&[stake_instruction::delegate_stake(
|
||||
&bonus_stake_address,
|
||||
&config.authorized_staker.pubkey(),
|
||||
|
@ -754,7 +754,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
// Deactivate bonus stake
|
||||
delegate_stake_transactions.push((
|
||||
Transaction::new_unsigned(
|
||||
Message::new_with_payer(
|
||||
Message::new(
|
||||
&[stake_instruction::deactivate_stake(
|
||||
&bonus_stake_address,
|
||||
&config.authorized_staker.pubkey(),
|
||||
|
@ -779,7 +779,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
{
|
||||
// Deactivate baseline stake
|
||||
delegate_stake_transactions.push((
|
||||
Transaction::new_unsigned(Message::new_with_payer(
|
||||
Transaction::new_unsigned(Message::new(
|
||||
&[stake_instruction::deactivate_stake(
|
||||
&baseline_stake_address,
|
||||
&config.authorized_staker.pubkey(),
|
||||
|
@ -795,7 +795,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
|
||||
// Deactivate bonus stake
|
||||
delegate_stake_transactions.push((
|
||||
Transaction::new_unsigned(Message::new_with_payer(
|
||||
Transaction::new_unsigned(Message::new(
|
||||
&[stake_instruction::deactivate_stake(
|
||||
&bonus_stake_address,
|
||||
&config.authorized_staker.pubkey(),
|
||||
|
|
|
@ -158,7 +158,7 @@ fn distribute_tokens(
|
|||
};
|
||||
|
||||
let fee_payer_pubkey = args.fee_payer.pubkey();
|
||||
let message = Message::new_with_payer(&instructions, Some(&fee_payer_pubkey));
|
||||
let message = Message::new(&instructions, Some(&fee_payer_pubkey));
|
||||
match client.send_message(message, &signers) {
|
||||
Ok((transaction, last_valid_slot)) => {
|
||||
db::set_transaction_info(
|
||||
|
@ -508,7 +508,7 @@ pub fn test_process_distribute_stake_with_client<C: Client>(client: C, sender_ke
|
|||
&lockup,
|
||||
sol_to_lamports(3000.0),
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&sender_keypair.pubkey()));
|
||||
let signers = [&sender_keypair, &stake_account_keypair];
|
||||
thin_client.send_message(message, &signers).unwrap();
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@ impl<'a> ThinClient<'a> {
|
|||
) -> Result<(Transaction, u64)> {
|
||||
let create_instruction =
|
||||
system_instruction::transfer(&sender_keypair.pubkey(), &to_pubkey, lamports);
|
||||
let message = Message::new(&[create_instruction]);
|
||||
let message = Message::new(&[create_instruction], Some(&sender_keypair.pubkey()));
|
||||
self.send_message(message, &[sender_keypair])
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue