Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract system-instruction crate #3007

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ members = [
"sdk/slot-hashes",
"sdk/slot-history",
"sdk/stable-layout",
"sdk/system-instruction",
"sdk/sysvar-id",
"sdk/time-utils",
"sdk/transaction-error",
Expand Down Expand Up @@ -484,6 +485,7 @@ solana-sha256-hasher = { path = "sdk/sha256-hasher", version = "=2.2.0" }
solana-signature = { path = "sdk/signature", version = "=2.2.0", default-features = false }
solana-slot-hashes = { path = "sdk/slot-hashes", version = "=2.2.0" }
solana-slot-history = { path = "sdk/slot-history", version = "=2.2.0" }
solana-system-instruction = { path = "sdk/system-instruction", version = "=2.2.0" }
solana-time-utils = { path = "sdk/time-utils", version = "=2.2.0" }
solana-timings = { path = "timings", version = "=2.2.0" }
solana-unified-scheduler-logic = { path = "unified-scheduler-logic", version = "=2.2.0" }
Expand Down
15 changes: 15 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion sdk/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ solana-short-vec = { workspace = true }
solana-slot-hashes = { workspace = true, features = ["serde", "sysvar"] }
solana-slot-history = { workspace = true, features = ["serde", "sysvar"] }
solana-stable-layout = { workspace = true }
solana-system-instruction = { workspace = true }
solana-sysvar-id = { workspace = true }
thiserror = { workspace = true }

Expand Down Expand Up @@ -148,7 +149,8 @@ frozen-abi = [
"solana-instruction/frozen-abi",
"solana-pubkey/frozen-abi",
"solana-rent/frozen-abi",
"solana-short-vec/frozen-abi"
"solana-short-vec/frozen-abi",
"solana-system-instruction/frozen-abi"
]

[lints]
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ pub mod slot_history;
pub mod stake;
pub mod stake_history;
pub mod syscalls;
pub mod system_instruction;
pub mod system_program;
pub mod sysvar;
pub mod vote;
Expand Down Expand Up @@ -551,6 +550,7 @@ pub use {
entrypoint_no_alloc,
},
solana_program_option as program_option, solana_pubkey as pubkey, solana_rent as rent,
solana_system_instruction as system_instruction,
};
/// The [config native program][np].
///
Expand Down
115 changes: 3 additions & 112 deletions sdk/program/src/wasm/system_instruction.rs
Original file line number Diff line number Diff line change
@@ -1,112 +1,3 @@
//! `SystemInstruction` Javascript interface
#![cfg(target_arch = "wasm32")]
#![allow(non_snake_case)]
use {
crate::{instruction::Instruction, pubkey::Pubkey, system_instruction::*},
wasm_bindgen::prelude::*,
};

#[wasm_bindgen]
impl SystemInstruction {
pub fn createAccount(
from_pubkey: &Pubkey,
to_pubkey: &Pubkey,
lamports: u64,
space: u64,
owner: &Pubkey,
) -> Instruction {
create_account(from_pubkey, to_pubkey, lamports, space, owner)
}

pub fn createAccountWithSeed(
from_pubkey: &Pubkey,
to_pubkey: &Pubkey,
base: &Pubkey,
seed: &str,
lamports: u64,
space: u64,
owner: &Pubkey,
) -> Instruction {
create_account_with_seed(from_pubkey, to_pubkey, base, seed, lamports, space, owner)
}

pub fn assign(pubkey: &Pubkey, owner: &Pubkey) -> Instruction {
assign(pubkey, owner)
}

pub fn assignWithSeed(
pubkey: &Pubkey,
base: &Pubkey,
seed: &str,
owner: &Pubkey,
) -> Instruction {
assign_with_seed(pubkey, base, seed, owner)
}

pub fn transfer(from_pubkey: &Pubkey, to_pubkey: &Pubkey, lamports: u64) -> Instruction {
transfer(from_pubkey, to_pubkey, lamports)
}

pub fn transferWithSeed(
from_pubkey: &Pubkey,
from_base: &Pubkey,
from_seed: String,
from_owner: &Pubkey,
to_pubkey: &Pubkey,
lamports: u64,
) -> Instruction {
transfer_with_seed(
from_pubkey,
from_base,
from_seed,
from_owner,
to_pubkey,
lamports,
)
}

pub fn allocate(pubkey: &Pubkey, space: u64) -> Instruction {
allocate(pubkey, space)
}

pub fn allocateWithSeed(
address: &Pubkey,
base: &Pubkey,
seed: &str,
space: u64,
owner: &Pubkey,
) -> Instruction {
allocate_with_seed(address, base, seed, space, owner)
}

pub fn createNonceAccount(
from_pubkey: &Pubkey,
nonce_pubkey: &Pubkey,
authority: &Pubkey,
lamports: u64,
) -> js_sys::Array {
let instructions = create_nonce_account(from_pubkey, nonce_pubkey, authority, lamports);
instructions.into_iter().map(JsValue::from).collect()
}

pub fn advanceNonceAccount(nonce_pubkey: &Pubkey, authorized_pubkey: &Pubkey) -> Instruction {
advance_nonce_account(nonce_pubkey, authorized_pubkey)
}

pub fn withdrawNonceAccount(
nonce_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
to_pubkey: &Pubkey,
lamports: u64,
) -> Instruction {
withdraw_nonce_account(nonce_pubkey, authorized_pubkey, to_pubkey, lamports)
}

pub fn authorizeNonceAccount(
nonce_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
new_authority: &Pubkey,
) -> Instruction {
authorize_nonce_account(nonce_pubkey, authorized_pubkey, new_authority)
}
}
//! Left empty because deleting this module would technically be a breaking change,
//! but there was never anything you could import from here.
// TODO: delete this in next breaking change.
50 changes: 50 additions & 0 deletions sdk/system-instruction/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[package]
name = "solana-system-instruction"
description = "Instructions and constructors for the Solana system program."
documentation = "https://docs.rs/solana-system-instruction"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
all-features = true
rustdoc-args = ["--cfg=docsrs"]

[dependencies]
num-traits = { workspace = true }
serde = { workspace = true }
serde_derive = { workspace = true }
solana-decode-error = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true }
solana-frozen-abi-macro = { workspace = true, optional = true }
solana-instruction = { workspace = true, features = ["bincode", "std"] }
solana-logger = { workspace = true, optional = true }
solana-pubkey = { workspace = true, default-features = false, features = ["serde"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = { workspace = true }
wasm-bindgen = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
borsh = { workspace = true }
solana-instruction = { workspace = true }
solana-program = { path = "../program", default-features = false }
solana-program-error = { workspace = true, features = ["borsh"] }
static_assertions = { workspace = true }
strum = { workspace = true }
strum_macros = { workspace = true }

[features]
frozen-abi = [
"dep:solana-frozen-abi",
"dep:solana-frozen-abi-macro",
"dep:solana-logger"
]

[lints]
workspace = true
Loading
Loading