diff --git a/sdk/src/instruction.rs b/sdk/src/instruction.rs index 1bd5457f7a..f999b5c15e 100644 --- a/sdk/src/instruction.rs +++ b/sdk/src/instruction.rs @@ -69,19 +69,22 @@ impl InstructionError { } } -/// An instruction to execute a program -#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] -pub struct GenericInstruction { - /// Index into the transaction program ids array indicating the program account that executes this instruction - pub program_ids_index: P, - /// Ordered indices into the transaction keys array indicating which accounts to pass to the program - pub accounts: Vec, - /// The program input data +#[derive(Debug, PartialEq)] +pub struct Instruction { + /// Pubkey of the instruction processor that executes this instruction + pub program_ids_index: Pubkey, + /// Metadata for what accounts should be passed to the instruction processor + pub accounts: Vec, + /// Opaque data passed to the instruction processor pub data: Vec, } -impl GenericInstruction { - pub fn new(program_ids_index: P, data: &T, accounts: Vec) -> Self { +impl Instruction { + pub fn new( + program_ids_index: Pubkey, + data: &T, + accounts: Vec, + ) -> Self { let data = serialize(data).unwrap(); Self { program_ids_index, @@ -106,10 +109,27 @@ impl AccountMeta { } } -pub type Instruction = GenericInstruction; -pub type CompiledInstruction = GenericInstruction; +/// An instruction to execute a program +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] +pub struct CompiledInstruction { + /// Index into the transaction program ids array indicating the program account that executes this instruction + pub program_ids_index: u8, + /// Ordered indices into the transaction keys array indicating which accounts to pass to the program + pub accounts: Vec, + /// The program input data + pub data: Vec, +} impl CompiledInstruction { + pub fn new(program_ids_index: u8, data: &T, accounts: Vec) -> Self { + let data = serialize(data).unwrap(); + Self { + program_ids_index, + data, + accounts, + } + } + pub fn serialize_with(mut writer: &mut Cursor<&mut [u8]>, ix: &Self) -> Result<(), Error> { writer.write_all(&[ix.program_ids_index])?; serialize_vec_bytes(&mut writer, &ix.accounts[..])?;