1#![cfg(target_arch = "wasm32")]
3#![allow(non_snake_case)]
4use {
5 solana_sdk_wasm_js::{address::Address, instruction::Instruction},
6 solana_system_interface::instruction::{
7 advance_nonce_account, allocate, allocate_with_seed, assign, assign_with_seed,
8 authorize_nonce_account, create_account, create_account_with_seed, create_nonce_account,
9 transfer, transfer_with_seed, withdraw_nonce_account,
10 },
11 wasm_bindgen::prelude::*,
12};
13
14#[wasm_bindgen]
15pub struct SystemInstruction;
16
17#[wasm_bindgen]
18impl SystemInstruction {
19 pub fn createAccount(
20 from: &Address,
21 to: &Address,
22 lamports: u64,
23 space: u64,
24 owner: &Address,
25 ) -> Instruction {
26 create_account(from, to, lamports, space, owner).into()
27 }
28
29 pub fn createAccountWithSeed(
30 from: &Address,
31 to: &Address,
32 base: &Address,
33 seed: &str,
34 lamports: u64,
35 space: u64,
36 owner: &Address,
37 ) -> Instruction {
38 create_account_with_seed(from, to, base, seed, lamports, space, owner).into()
39 }
40
41 pub fn assign(address: &Address, owner: &Address) -> Instruction {
42 assign(address, owner).into()
43 }
44
45 pub fn assignWithSeed(
46 address: &Address,
47 base: &Address,
48 seed: &str,
49 owner: &Address,
50 ) -> Instruction {
51 assign_with_seed(address, base, seed, owner).into()
52 }
53
54 pub fn transfer(from: &Address, to: &Address, lamports: u64) -> Instruction {
55 transfer(from, to, lamports).into()
56 }
57
58 pub fn transferWithSeed(
59 from: &Address,
60 from_base: &Address,
61 from_seed: String,
62 from_owner: &Address,
63 to: &Address,
64 lamports: u64,
65 ) -> Instruction {
66 transfer_with_seed(from, from_base, from_seed, from_owner, to, lamports).into()
67 }
68
69 pub fn allocate(address: &Address, space: u64) -> Instruction {
70 allocate(address, space).into()
71 }
72
73 pub fn allocateWithSeed(
74 address: &Address,
75 base: &Address,
76 seed: &str,
77 space: u64,
78 owner: &Address,
79 ) -> Instruction {
80 allocate_with_seed(address, base, seed, space, owner).into()
81 }
82
83 pub fn createNonceAccount(
84 from: &Address,
85 nonce: &Address,
86 authority: &Address,
87 lamports: u64,
88 ) -> js_sys::Array {
89 let instructions = create_nonce_account(from, nonce, authority, lamports);
90 instructions
91 .into_iter()
92 .map(|x| JsValue::from(Instruction::from(x)))
93 .collect()
94 }
95
96 pub fn advanceNonceAccount(nonce: &Address, authorized: &Address) -> Instruction {
97 advance_nonce_account(nonce, authorized).into()
98 }
99
100 pub fn withdrawNonceAccount(
101 nonce: &Address,
102 authorized: &Address,
103 to: &Address,
104 lamports: u64,
105 ) -> Instruction {
106 withdraw_nonce_account(nonce, authorized, to, lamports).into()
107 }
108
109 pub fn authorizeNonceAccount(
110 nonce: &Address,
111 authorized: &Address,
112 new_authority: &Address,
113 ) -> Instruction {
114 authorize_nonce_account(nonce, authorized, new_authority).into()
115 }
116}