Clarify Instruction::new (#15686)

Not related to local-cluster, merging
This commit is contained in:
Jack May 2021-03-03 17:39:04 -08:00 committed by GitHub
parent bbf7ded997
commit 4a05210d8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -212,6 +212,14 @@ pub struct Instruction {
impl Instruction {
pub fn new<T: Serialize>(program_id: Pubkey, data: &T, accounts: Vec<AccountMeta>) -> Self {
Self::new_with_bincode(program_id, data, accounts)
}
pub fn new_with_bincode<T: Serialize>(
program_id: Pubkey,
data: &T,
accounts: Vec<AccountMeta>,
) -> Self {
let data = serialize(data).unwrap();
Self {
program_id,
@ -232,6 +240,14 @@ impl Instruction {
accounts,
}
}
pub fn new_with_bytes(program_id: Pubkey, data: &[u8], accounts: Vec<AccountMeta>) -> Self {
Self {
program_id,
data: data.to_vec(),
accounts,
}
}
}
pub fn checked_add(a: u64, b: u64) -> Result<u64, InstructionError> {