Add initial wasm bindings for Instruction
, SystemProgram
and Transaction
(cherry picked from commit a35df1cb02
)
This commit is contained in:
28
sdk/program/src/wasm/instructions.rs
Normal file
28
sdk/program/src/wasm/instructions.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
//! The `Instructions` struct is a workaround for the lack of Vec<T> support in wasm-bindgen
|
||||
//! (ref: https://github.com/rustwasm/wasm-bindgen/issues/111)
|
||||
#![cfg(target_arch = "wasm32")]
|
||||
use {crate::instruction::Instruction, wasm_bindgen::prelude::*};
|
||||
|
||||
#[wasm_bindgen]
|
||||
#[derive(Default)]
|
||||
pub struct Instructions {
|
||||
instructions: Vec<Instruction>,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Instructions {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn constructor() -> Instructions {
|
||||
Instructions::default()
|
||||
}
|
||||
|
||||
pub fn push(&mut self, instruction: Instruction) {
|
||||
self.instructions.push(instruction);
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Instructions> for Vec<Instruction> {
|
||||
fn from(instructions: Instructions) -> Self {
|
||||
instructions.instructions
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user