From 4a05210d8eca37a2528859a835f2c4b7475a4ec5 Mon Sep 17 00:00:00 2001 From: Jack May Date: Wed, 3 Mar 2021 17:39:04 -0800 Subject: [PATCH] Clarify Instruction::new (#15686) Not related to local-cluster, merging --- sdk/program/src/instruction.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sdk/program/src/instruction.rs b/sdk/program/src/instruction.rs index abdc988a9b..1fd7d560dc 100644 --- a/sdk/program/src/instruction.rs +++ b/sdk/program/src/instruction.rs @@ -212,6 +212,14 @@ pub struct Instruction { impl Instruction { pub fn new(program_id: Pubkey, data: &T, accounts: Vec) -> Self { + Self::new_with_bincode(program_id, data, accounts) + } + + pub fn new_with_bincode( + program_id: Pubkey, + data: &T, + accounts: Vec, + ) -> 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) -> Self { + Self { + program_id, + data: data.to_vec(), + accounts, + } + } } pub fn checked_add(a: u64, b: u64) -> Result {