Separate the "program" feature of solana-sdk
into a new crate called solana-program
(bp #12989) (#13131)
* Add solana-program-sdk boilerplate (cherry picked from commit3718771ffb
) # Conflicts: # sdk/Cargo.toml * Initial population of solana-program-sdk (cherry picked from commit63db324204
) # Conflicts: # Cargo.lock * Port programs to solana-program-sdk (cherry picked from commitfe68f7f786
) # Conflicts: # programs/bpf/Cargo.lock # programs/bpf/rust/128bit/Cargo.toml # programs/bpf/rust/128bit_dep/Cargo.toml # programs/bpf/rust/alloc/Cargo.toml # programs/bpf/rust/call_depth/Cargo.toml # programs/bpf/rust/custom_heap/Cargo.toml # programs/bpf/rust/dep_crate/Cargo.toml # programs/bpf/rust/deprecated_loader/Cargo.toml # programs/bpf/rust/dup_accounts/Cargo.toml # programs/bpf/rust/error_handling/Cargo.toml # programs/bpf/rust/external_spend/Cargo.toml # programs/bpf/rust/instruction_introspection/Cargo.toml # programs/bpf/rust/invoke/Cargo.toml # programs/bpf/rust/invoked/Cargo.toml # programs/bpf/rust/iter/Cargo.toml # programs/bpf/rust/many_args/Cargo.toml # programs/bpf/rust/many_args_dep/Cargo.toml # programs/bpf/rust/noop/Cargo.toml # programs/bpf/rust/panic/Cargo.toml # programs/bpf/rust/param_passing/Cargo.toml # programs/bpf/rust/param_passing_dep/Cargo.toml # programs/bpf/rust/rand/Cargo.toml # programs/bpf/rust/ristretto/Cargo.toml # programs/bpf/rust/sanity/Cargo.toml # programs/bpf/rust/sha256/Cargo.toml # programs/bpf/rust/sysval/Cargo.toml * Only activate legacy program feature for the solana-sdk crate (cherry picked from commit85c51f5787
) * Run serum-dex unit tests (cherry picked from commit92ce381d60
) * Rename solana-program-sdk to solana-program (cherry picked from commitdd711ab5fb
) # Conflicts: # programs/bpf/rust/128bit/Cargo.toml # programs/bpf/rust/128bit_dep/Cargo.toml # programs/bpf/rust/alloc/Cargo.toml # programs/bpf/rust/call_depth/Cargo.toml # programs/bpf/rust/custom_heap/Cargo.toml # programs/bpf/rust/dep_crate/Cargo.toml # programs/bpf/rust/deprecated_loader/Cargo.toml # programs/bpf/rust/dup_accounts/Cargo.toml # programs/bpf/rust/error_handling/Cargo.toml # programs/bpf/rust/external_spend/Cargo.toml # programs/bpf/rust/instruction_introspection/Cargo.toml # programs/bpf/rust/invoke/Cargo.toml # programs/bpf/rust/invoked/Cargo.toml # programs/bpf/rust/iter/Cargo.toml # programs/bpf/rust/many_args/Cargo.toml # programs/bpf/rust/many_args_dep/Cargo.toml # programs/bpf/rust/noop/Cargo.toml # programs/bpf/rust/panic/Cargo.toml # programs/bpf/rust/param_passing/Cargo.toml # programs/bpf/rust/param_passing_dep/Cargo.toml # programs/bpf/rust/rand/Cargo.toml # programs/bpf/rust/ristretto/Cargo.toml # programs/bpf/rust/sanity/Cargo.toml # programs/bpf/rust/sha256/Cargo.toml # programs/bpf/rust/sysval/Cargo.toml * Update frozen_abi hashes The movement of files in sdk/ caused ABI hashes to change (cherry picked from commita4956844bd
) * Resolve merge conflicts Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
32
Cargo.lock
generated
32
Cargo.lock
generated
@ -4317,6 +4317,36 @@ dependencies = [
|
||||
"solana-version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-program"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"assert_matches",
|
||||
"bincode",
|
||||
"bs58",
|
||||
"bv",
|
||||
"curve25519-dalek 2.1.0",
|
||||
"hex",
|
||||
"itertools 0.9.0",
|
||||
"lazy_static",
|
||||
"log 0.4.8",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"rand 0.7.3",
|
||||
"rustc_version",
|
||||
"rustversion",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"solana-frozen-abi",
|
||||
"solana-frozen-abi-macro",
|
||||
"solana-logger 1.4.3",
|
||||
"solana-sdk-macro 1.4.3",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-ramp-tps"
|
||||
version = "1.4.3"
|
||||
@ -4481,7 +4511,6 @@ dependencies = [
|
||||
"hex",
|
||||
"hmac",
|
||||
"itertools 0.9.0",
|
||||
"lazy_static",
|
||||
"libsecp256k1",
|
||||
"log 0.4.8",
|
||||
"memmap",
|
||||
@ -4502,6 +4531,7 @@ dependencies = [
|
||||
"solana-frozen-abi",
|
||||
"solana-frozen-abi-macro",
|
||||
"solana-logger 1.4.3",
|
||||
"solana-program",
|
||||
"solana-sdk-macro 1.4.3",
|
||||
"thiserror",
|
||||
"tiny-bip39",
|
||||
|
@ -27,8 +27,8 @@ declare print_free_tree=(
|
||||
':sdk/bpf/rust/rust-utils/**.rs'
|
||||
':sdk/**.rs'
|
||||
':^sdk/cargo-build-bpf/**.rs'
|
||||
':^sdk/src/program_option.rs'
|
||||
':^sdk/src/program_stubs.rs'
|
||||
':^sdk/program/src/program_option.rs'
|
||||
':^sdk/program/src/program_stubs.rs'
|
||||
':programs/**.rs'
|
||||
':^**bin**.rs'
|
||||
':^**bench**.rs'
|
||||
|
@ -40,6 +40,9 @@ test-stable)
|
||||
_ cargo +"$rust_stable" test --jobs "$NPROC" --all --exclude solana-local-cluster ${V:+--verbose} -- --nocapture
|
||||
;;
|
||||
test-stable-perf)
|
||||
# BPF solana-sdk legacy compile test
|
||||
./cargo-build-bpf --manifest-path sdk/Cargo.toml
|
||||
|
||||
# BPF program tests
|
||||
_ make -C programs/bpf/c tests
|
||||
_ cargo +"$rust_stable" test \
|
||||
|
@ -356,7 +356,7 @@ pub fn make_accounts_hashes_message(
|
||||
}
|
||||
|
||||
// TODO These messages should go through the gpu pipeline for spam filtering
|
||||
#[frozen_abi(digest = "3ZHQscZ9SgxKh45idzHv3hiagyyPRtDgeySmJn171PTi")]
|
||||
#[frozen_abi(digest = "21UweZ4WXK9RHypF97D1rEJQ4C8Bh4pw52SBSNAKxJvW")]
|
||||
#[derive(Serialize, Deserialize, Debug, AbiEnumVisitor, AbiExample)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum Protocol {
|
||||
|
@ -89,7 +89,7 @@ pub(crate) struct ComputedBankState {
|
||||
pub pubkey_votes: Arc<PubkeyVotes>,
|
||||
}
|
||||
|
||||
#[frozen_abi(digest = "2ZUeCLMVQxmHYbeqMH7M97ifVSKoVErGvRHzyxcQRjgU")]
|
||||
#[frozen_abi(digest = "Eay84NBbJqiMBfE7HHH2o6e51wcvoU79g8zCi5sw6uj3")]
|
||||
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, AbiExample)]
|
||||
pub struct Tower {
|
||||
node_pubkey: Pubkey,
|
||||
|
81
programs/bpf/Cargo.lock
generated
81
programs/bpf/Cargo.lock
generated
@ -1761,35 +1761,35 @@ name = "solana-bpf-rust-128bit"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-bpf-rust-128bit-dep",
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-128bit-dep"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-alloc"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-call-depth"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-custom-heap"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1797,21 +1797,21 @@ name = "solana-bpf-rust-dep-crate"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"byteorder 1.3.4",
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-deprecated_loader"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-dup-accounts"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1820,7 +1820,7 @@ version = "1.4.3"
|
||||
dependencies = [
|
||||
"num-derive 0.2.5",
|
||||
"num-traits",
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
@ -1828,14 +1828,14 @@ dependencies = [
|
||||
name = "solana-bpf-rust-external-spend"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-instruction-introspection"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1843,21 +1843,21 @@ name = "solana-bpf-rust-invoke"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-bpf-rust-invoked",
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-invoked"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-iter"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1865,28 +1865,28 @@ name = "solana-bpf-rust-many-args"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-bpf-rust-many-args-dep",
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-many-args-dep"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-noop"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-panic"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1894,14 +1894,14 @@ name = "solana-bpf-rust-param-passing"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-bpf-rust-param-passing-dep",
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-param-passing-dep"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1910,7 +1910,7 @@ version = "1.4.3"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"rand",
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1919,28 +1919,28 @@ version = "1.4.3"
|
||||
dependencies = [
|
||||
"curve25519-dalek 3.0.0",
|
||||
"getrandom",
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-sanity"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-sha256"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-sysval"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
"solana-program",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2038,6 +2038,34 @@ dependencies = [
|
||||
"solana-sdk",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-program"
|
||||
version = "1.4.3"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"bs58",
|
||||
"bv",
|
||||
"curve25519-dalek 2.1.0",
|
||||
"hex",
|
||||
"itertools",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"num-derive 0.3.0",
|
||||
"num-traits",
|
||||
"rand",
|
||||
"rustc_version",
|
||||
"rustversion",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"serde_derive",
|
||||
"sha2",
|
||||
"solana-frozen-abi",
|
||||
"solana-frozen-abi-macro",
|
||||
"solana-logger",
|
||||
"solana-sdk-macro",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-rayon-threadlimit"
|
||||
version = "1.4.3"
|
||||
@ -2103,14 +2131,12 @@ dependencies = [
|
||||
"bv",
|
||||
"byteorder 1.3.4",
|
||||
"chrono",
|
||||
"curve25519-dalek 2.1.0",
|
||||
"digest 0.9.0",
|
||||
"ed25519-dalek",
|
||||
"generic-array 0.14.3",
|
||||
"hex",
|
||||
"hmac",
|
||||
"itertools",
|
||||
"lazy_static",
|
||||
"libsecp256k1",
|
||||
"log",
|
||||
"memmap",
|
||||
@ -2131,6 +2157,7 @@ dependencies = [
|
||||
"solana-frozen-abi",
|
||||
"solana-frozen-abi-macro",
|
||||
"solana-logger",
|
||||
"solana-program",
|
||||
"solana-sdk-macro",
|
||||
"thiserror",
|
||||
]
|
||||
|
@ -60,6 +60,7 @@ fn main() {
|
||||
let rust_programs = [
|
||||
"128bit",
|
||||
"alloc",
|
||||
"call_depth",
|
||||
"custom_heap",
|
||||
"dep_crate",
|
||||
"deprecated_loader",
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-128bit"
|
||||
version = "1.4.3"
|
||||
@ -11,12 +9,8 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
solana-bpf-rust-128bit-dep = { path = "../128bit_dep", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
solana-bpf-rust-128bit-dep = { path = "../128bit_dep", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_128bit"
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! @brief Example Rust-based BPF program tests loop iteration
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::entrypoint::SUCCESS;
|
||||
extern crate solana_program;
|
||||
use solana_program::entrypoint::SUCCESS;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-128bit-dep"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! @brief Solana Rust-based BPF program utility functions and types
|
||||
|
||||
extern crate solana_sdk;
|
||||
extern crate solana_program;
|
||||
|
||||
pub fn uadd(x: u128, y: u128) -> u128 {
|
||||
x + y
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-alloc"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_alloc"
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate alloc;
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{entrypoint::SUCCESS, info};
|
||||
use solana_program::{entrypoint::SUCCESS, info};
|
||||
use std::{alloc::Layout, mem};
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-call-depth"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_call_depth"
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! @brief Example Rust-based BPF program that tests call depth and stack usage
|
||||
|
||||
use solana_sdk::{entrypoint::SUCCESS, info};
|
||||
use solana_program::{entrypoint::SUCCESS, info};
|
||||
|
||||
#[inline(never)]
|
||||
pub fn recurse(data: &mut [u8]) {
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-custom-heap"
|
||||
version = "1.4.3"
|
||||
@ -11,12 +9,11 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[features]
|
||||
default = ["custom-heap"]
|
||||
custom-heap = []
|
||||
program = ["custom-heap", "solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_custom_heap"
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! @brief Example Rust-based BPF that tests out using a custom heap
|
||||
|
||||
use solana_sdk::{
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
entrypoint,
|
||||
entrypoint::{ProgramResult, HEAP_LENGTH, HEAP_START_ADDRESS},
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-dep-crate"
|
||||
version = "1.4.3"
|
||||
@ -12,11 +10,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
byteorder = { version = "1", default-features = false }
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_dep_crate"
|
||||
|
@ -1,8 +1,8 @@
|
||||
//! @brief Example Rust-based BPF program tests dependent crates
|
||||
|
||||
extern crate solana_sdk;
|
||||
extern crate solana_program;
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use solana_sdk::entrypoint::SUCCESS;
|
||||
use solana_program::entrypoint::SUCCESS;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-deprecated_loader"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_deprecated_loader"
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#![allow(unreachable_code)]
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{
|
||||
extern crate solana_program;
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, bpf_loader, entrypoint_deprecated,
|
||||
entrypoint_deprecated::ProgramResult, info, log::*, pubkey::Pubkey,
|
||||
};
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-dup-accounts"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_dup_accounts"
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! @brief Example Rust-based BPF program that tests duplicate accounts passed via accounts
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{
|
||||
extern crate solana_program;
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, info,
|
||||
program_error::ProgramError, pubkey::Pubkey,
|
||||
};
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-error-handling"
|
||||
version = "1.4.3"
|
||||
@ -13,13 +11,9 @@ edition = "2018"
|
||||
[dependencies]
|
||||
num-derive = "0.2"
|
||||
num-traits = "0.2"
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
thiserror = "1.0"
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_error_handling"
|
||||
crate-type = ["cdylib"]
|
||||
|
@ -1,9 +1,9 @@
|
||||
//! @brief Example Rust-based BPF program that exercises error handling
|
||||
|
||||
extern crate solana_sdk;
|
||||
extern crate solana_program;
|
||||
use num_derive::FromPrimitive;
|
||||
use num_traits::FromPrimitive;
|
||||
use solana_sdk::{
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
decode_error::DecodeError,
|
||||
entrypoint,
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-external-spend"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_external_spend"
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! @brief Example Rust-based BPF program that moves a lamport from one account to another
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{
|
||||
extern crate solana_program;
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-instruction-introspection"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_instruction_introspection"
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! @brief Example Rust-based BPF program that exercises instruction introspection
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{
|
||||
extern crate solana_program;
|
||||
use solana_program::{
|
||||
account_info::next_account_info, account_info::AccountInfo, entrypoint,
|
||||
entrypoint::ProgramResult, info, program_error::ProgramError, pubkey::Pubkey,
|
||||
sysvar::instructions,
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-invoke"
|
||||
version = "1.4.3"
|
||||
@ -12,11 +10,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-bpf-rust-invoked = { path = "../invoked", default-features = false }
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_invoke"
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
#![allow(unreachable_code)]
|
||||
|
||||
extern crate solana_sdk;
|
||||
extern crate solana_program;
|
||||
|
||||
use solana_bpf_rust_invoked::instruction::*;
|
||||
use solana_sdk::{
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
entrypoint,
|
||||
entrypoint::{ProgramResult, MAX_PERMITTED_DATA_INCREASE},
|
||||
@ -52,7 +52,7 @@ fn process_instruction(
|
||||
let from_lamports = accounts[FROM_INDEX].lamports();
|
||||
let to_lamports = accounts[DERIVED_KEY1_INDEX].lamports();
|
||||
assert_eq!(accounts[DERIVED_KEY1_INDEX].data_len(), 0);
|
||||
assert!(solana_sdk::system_program::check_id(
|
||||
assert!(solana_program::system_program::check_id(
|
||||
accounts[DERIVED_KEY1_INDEX].owner
|
||||
));
|
||||
|
||||
|
@ -11,11 +11,11 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
default = ["program"]
|
||||
program = []
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_invoked"
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! @brief Example Rust-based BPF program that issues a cross-program-invocation
|
||||
|
||||
use solana_sdk::{
|
||||
use solana_program::{
|
||||
instruction::{AccountMeta, Instruction},
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
@ -1,5 +1,4 @@
|
||||
//! @brief Example Rust-based BPF program that issues a cross-program-invocation
|
||||
|
||||
pub mod instruction;
|
||||
#[cfg(feature = "program")]
|
||||
pub mod processor;
|
||||
|
@ -1,7 +1,9 @@
|
||||
//! @brief Example Rust-based BPF program that issues a cross-program-invocation
|
||||
|
||||
#![cfg(feature = "program")]
|
||||
|
||||
use crate::instruction::*;
|
||||
use solana_sdk::{
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
bpf_loader, entrypoint,
|
||||
entrypoint::ProgramResult,
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-iter"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_iter"
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! @brief Example Rust-based BPF program tests loop iteration
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{entrypoint::SUCCESS, info};
|
||||
extern crate solana_program;
|
||||
use solana_program::{entrypoint::SUCCESS, info};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-many-args"
|
||||
version = "1.4.3"
|
||||
@ -11,12 +9,8 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
solana-bpf-rust-many-args-dep = { path = "../many_args_dep", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
solana-bpf-rust-many-args-dep = { path = "../many_args_dep", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_many_args"
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! @brief Example Rust-based BPF program tests loop iteration
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::log::*;
|
||||
extern crate solana_program;
|
||||
use solana_program::log::*;
|
||||
|
||||
pub fn many_args(
|
||||
arg1: u64,
|
||||
|
@ -1,8 +1,8 @@
|
||||
//! @brief Example Rust-based BPF program tests loop iteration
|
||||
|
||||
mod helper;
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{entrypoint::SUCCESS, info};
|
||||
extern crate solana_program;
|
||||
use solana_program::{entrypoint::SUCCESS, info};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-many-args-dep"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! @brief Solana Rust-based BPF program utility functions and types
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::info;
|
||||
extern crate solana_program;
|
||||
use solana_program::info;
|
||||
|
||||
pub fn many_args(
|
||||
arg1: u64,
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-noop"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_noop"
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! @brief Example Rust-based BPF noop program
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{
|
||||
extern crate solana_program;
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-panic"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_panic"
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! @brief Example Rust-based BPF program that panics
|
||||
|
||||
extern crate solana_sdk;
|
||||
extern crate solana_program;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-param-passing"
|
||||
version = "1.4.3"
|
||||
@ -11,12 +9,9 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
solana-bpf-rust-param-passing-dep = { path = "../param_passing_dep", version = "1.4.3", default-features = false }
|
||||
solana-bpf-rust-param-passing-dep = { path = "../param_passing_dep", version = "1.4.3" }
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_param_passing"
|
||||
|
@ -1,8 +1,8 @@
|
||||
//! @brief Example Rust-based BPF program tests loop iteration
|
||||
|
||||
extern crate solana_sdk;
|
||||
extern crate solana_program;
|
||||
use solana_bpf_rust_param_passing_dep::{Data, TestDep};
|
||||
use solana_sdk::{entrypoint::SUCCESS, info};
|
||||
use solana_program::{entrypoint::SUCCESS, info};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-param-passing-dep"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! @brief Example Rust-based BPF program tests loop iteration
|
||||
|
||||
extern crate solana_sdk;
|
||||
extern crate solana_program;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Data<'a> {
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-rand"
|
||||
version = "1.4.3"
|
||||
@ -13,11 +11,7 @@ edition = "2018"
|
||||
[dependencies]
|
||||
getrandom = { version = "0.1.14", features = ["dummy"] }
|
||||
rand = "0.7"
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_rand"
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#![allow(unreachable_code)]
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{
|
||||
extern crate solana_program;
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, info, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-ristretto"
|
||||
version = "1.4.3"
|
||||
@ -13,11 +11,7 @@ edition = "2018"
|
||||
[dependencies]
|
||||
curve25519-dalek = "3"
|
||||
getrandom = { version = "0.1.14", features = ["dummy"] }
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_ristretto"
|
||||
|
@ -4,7 +4,7 @@ pub mod ristretto;
|
||||
|
||||
use crate::ristretto::ristretto_mul;
|
||||
use curve25519_dalek::{constants::RISTRETTO_BASEPOINT_POINT, scalar::Scalar};
|
||||
use solana_sdk::{
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, info, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar};
|
||||
#[cfg(all(feature = "program", target_arch = "bpf"))]
|
||||
use solana_sdk::entrypoint::SUCCESS;
|
||||
use solana_sdk::program_error::ProgramError;
|
||||
use solana_program::program_error::ProgramError;
|
||||
|
||||
/// Multiply a ristretto point with a scalar
|
||||
///
|
||||
@ -15,12 +13,12 @@ pub fn ristretto_mul(
|
||||
) -> Result<RistrettoPoint, ProgramError> {
|
||||
// Perform the calculation inline, calling this from within a program is
|
||||
// not supported
|
||||
#[cfg(not(all(feature = "program", target_arch = "bpf")))]
|
||||
#[cfg(not(target_arch = "bpf"))]
|
||||
{
|
||||
Ok(point * scalar)
|
||||
}
|
||||
// Call via a system call to perform the calculation
|
||||
#[cfg(all(feature = "program", target_arch = "bpf"))]
|
||||
#[cfg(target_arch = "bpf")]
|
||||
{
|
||||
extern "C" {
|
||||
fn sol_ristretto_mul(
|
||||
@ -39,7 +37,7 @@ pub fn ristretto_mul(
|
||||
)
|
||||
};
|
||||
match status {
|
||||
SUCCESS => Ok(result),
|
||||
solana_program::entrypoint::SUCCESS => Ok(result),
|
||||
_ => Err(status.into()),
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-sanity"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_sanity"
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#![allow(unreachable_code)]
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{
|
||||
extern crate solana_program;
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, bpf_loader, entrypoint, entrypoint::ProgramResult, info, log::*,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-sha256"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_sha256"
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! @brief SHA256 Syscall test
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{
|
||||
extern crate solana_program;
|
||||
use solana_program::{
|
||||
hash::{hashv, Hasher},
|
||||
info,
|
||||
};
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-sysval"
|
||||
version = "1.4.3"
|
||||
@ -11,11 +9,7 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.3", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.4.3" }
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_sysval"
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! @brief Example Rust-based BPF program that tests sysval use
|
||||
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{
|
||||
extern crate solana_program;
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
clock::DEFAULT_SLOTS_PER_EPOCH,
|
||||
entrypoint,
|
||||
|
@ -32,7 +32,7 @@ pub const INITIAL_LOCKOUT: usize = 2;
|
||||
// smaller numbers makes
|
||||
pub const MAX_EPOCH_CREDITS_HISTORY: usize = 64;
|
||||
|
||||
#[frozen_abi(digest = "69hYtmmcuqPbhpc64ZaNJDidaUcg66CW6wzPFiuYZ3To")]
|
||||
#[frozen_abi(digest = "Ch2vVEwos2EjAVqSHCyJjnN2MNX1yrpapZTGhMSCjWUH")]
|
||||
#[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone, AbiExample)]
|
||||
pub struct Vote {
|
||||
/// A stack of votes starting with the oldest vote
|
||||
@ -150,7 +150,7 @@ impl<I> CircBuf<I> {
|
||||
}
|
||||
}
|
||||
|
||||
#[frozen_abi(digest = "H7z93iz4PiRJqahQ9G1aJXao1huusBz47SA5WfP8g4yd")]
|
||||
#[frozen_abi(digest = "331ZmXrmsUcwbKhzR3C1UEU6uNwZr48ExE54JDKGWA4w")]
|
||||
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq, Clone, AbiExample)]
|
||||
pub struct VoteState {
|
||||
/// the node that votes in this account
|
||||
|
@ -114,7 +114,7 @@ pub const MAX_LEADER_SCHEDULE_STAKES: Epoch = 5;
|
||||
pub const TRANSACTION_LOG_MESSAGES_BYTES_LIMIT: usize = 100 * 1000;
|
||||
|
||||
type BankStatusCache = StatusCache<Result<()>>;
|
||||
#[frozen_abi(digest = "EEFPLdPhngiBojqEnDMkoEGjyYYHNWPHnenRf8b9diqd")]
|
||||
#[frozen_abi(digest = "4nZ6EdivqQPcnrnXisbjuTjpcUBoHLDEQWvbZQDCoQQR")]
|
||||
pub type BankSlotDelta = SlotDelta<Result<()>>;
|
||||
type TransactionAccountRefCells = Vec<Rc<RefCell<Account>>>;
|
||||
type TransactionLoaderRefCells = Vec<Vec<(Pubkey, RefCell<Account>)>>;
|
||||
|
@ -12,7 +12,7 @@ struct HashAge {
|
||||
}
|
||||
|
||||
/// Low memory overhead, so can be cloned for every checkpoint
|
||||
#[frozen_abi(digest = "EwaoLA34VN18E95GvjmkeStUpWqTeBd7FGpd7mppLmEw")]
|
||||
#[frozen_abi(digest = "J1fGiMHyiKEBcWE6mfm7grAEGJgYEaVLzcrNZvd37iA2")]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, AbiExample)]
|
||||
pub struct BlockhashQueue {
|
||||
/// updated whenever an hash is registered
|
||||
|
@ -262,7 +262,7 @@ mod test_bank_serialize {
|
||||
|
||||
// These some what long test harness is required to freeze the ABI of
|
||||
// Bank's serialization due to versioned nature
|
||||
#[frozen_abi(digest = "ULV2jDndxR3JB677ayyjaamtAcZ24q75tCkHS2bKVoy")]
|
||||
#[frozen_abi(digest = "7f8quGr9ia7Dg5o339uKrPd4bLesNVdPuKMLpGQ9c3SR")]
|
||||
#[derive(Serialize, AbiExample)]
|
||||
pub struct BankAbiTestWrapperFuture {
|
||||
#[serde(serialize_with = "wrapper_future")]
|
||||
|
@ -95,6 +95,9 @@ serum_dex() {
|
||||
|
||||
"$solana_dir"/cargo-build-bpf \
|
||||
--manifest-path dex/Cargo.toml --no-default-features --features program
|
||||
|
||||
"$solana_dir"/cargo stable test \
|
||||
--manifest-path dex/Cargo.toml --no-default-features --features program
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,12 @@ license = "Apache-2.0"
|
||||
edition = "2018"
|
||||
|
||||
[features]
|
||||
# On-chain program specific dependencies
|
||||
# "program" feature is a legacy feature retained to support v1.3 and older
|
||||
# programs. New development should not use this feature. Instead use the
|
||||
# solana-program crate
|
||||
program = []
|
||||
# Everything includes functionality that is not compatible or needed for on-chain programs
|
||||
|
||||
# "everything" includes functionality that is not compatible or needed for on-chain programs
|
||||
default = [
|
||||
"everything"
|
||||
]
|
||||
@ -43,12 +46,11 @@ curve25519-dalek = { version = "2.1.0", optional = true }
|
||||
generic-array = { version = "0.14.3", default-features = false, features = ["serde", "more_lengths"], optional = true }
|
||||
hex = "0.4.2"
|
||||
hmac = "0.7.0"
|
||||
itertools = { version = "0.9.0" }
|
||||
lazy_static = "1.4.0"
|
||||
log = { version = "0.4.8" }
|
||||
itertools = "0.9.0"
|
||||
log = "0.4.8"
|
||||
memmap = { version = "0.7.0", optional = true }
|
||||
num-derive = { version = "0.3" }
|
||||
num-traits = { version = "0.2" }
|
||||
num-derive = "0.3"
|
||||
num-traits = "0.2"
|
||||
pbkdf2 = { version = "0.3.0", default-features = false }
|
||||
rand = { version = "0.7.0", optional = true }
|
||||
rand_chacha = { version = "0.2.2", optional = true }
|
||||
@ -63,21 +65,19 @@ solana-crate-features = { path = "../crate-features", version = "1.4.3", optiona
|
||||
solana-frozen-abi = { path = "../frozen-abi", version = "1.4.3" }
|
||||
solana-frozen-abi-macro = { path = "../frozen-abi/macro", version = "1.4.3" }
|
||||
solana-logger = { path = "../logger", version = "1.4.3", optional = true }
|
||||
solana-program = { path = "program", version = "1.4.3" }
|
||||
solana-sdk-macro = { path = "macro", version = "1.4.3" }
|
||||
rustversion = "1.0.3"
|
||||
libsecp256k1 = { version = "0.3.5", optional = true }
|
||||
sha3 = { version = "0.9.1", optional = true }
|
||||
digest = { version = "0.9.0", optional = true }
|
||||
|
||||
[target.'cfg(not(target_arch = "bpf"))'.dependencies]
|
||||
curve25519-dalek = { version = "2.1.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
curve25519-dalek = "2.1.0"
|
||||
tiny-bip39 = "0.7.0"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[build-dependencies]
|
||||
rustc_version = "0.2"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
2
sdk/Xargo.toml
Normal file
2
sdk/Xargo.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[target.bpfel-unknown-unknown.dependencies.std]
|
||||
features = []
|
@ -114,7 +114,7 @@ fn build_bpf(config: Config) {
|
||||
}
|
||||
};
|
||||
|
||||
let legacy_program_feature_present = root_package.features.contains_key("program");
|
||||
let legacy_program_feature_present = root_package.name == "solana-sdk";
|
||||
let root_package_dir = &root_package.manifest_path.parent().unwrap_or_else(|| {
|
||||
eprintln!(
|
||||
"Unable to get directory of {}",
|
||||
|
@ -17,12 +17,13 @@ use syn::{
|
||||
Expr, Ident, LitByte, LitStr, Path, Token,
|
||||
};
|
||||
|
||||
struct Id(proc_macro2::TokenStream);
|
||||
impl Parse for Id {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
let token_stream = if input.peek(syn::LitStr) {
|
||||
fn parse_id(
|
||||
input: ParseStream,
|
||||
pubkey_type: proc_macro2::TokenStream,
|
||||
) -> Result<proc_macro2::TokenStream> {
|
||||
let id = if input.peek(syn::LitStr) {
|
||||
let id_literal: LitStr = input.parse()?;
|
||||
parse_pubkey(&id_literal)?
|
||||
parse_pubkey(&id_literal, &pubkey_type)?
|
||||
} else {
|
||||
let expr: Expr = input.parse()?;
|
||||
quote! { #expr }
|
||||
@ -32,25 +33,25 @@ impl Parse for Id {
|
||||
let stream: proc_macro2::TokenStream = input.parse()?;
|
||||
return Err(syn::Error::new_spanned(stream, "unexpected token"));
|
||||
}
|
||||
|
||||
Ok(Id(token_stream))
|
||||
}
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
impl ToTokens for Id {
|
||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||
let id = &self.0;
|
||||
fn id_to_tokens(
|
||||
id: &proc_macro2::TokenStream,
|
||||
pubkey_type: proc_macro2::TokenStream,
|
||||
tokens: &mut proc_macro2::TokenStream,
|
||||
) {
|
||||
tokens.extend(quote! {
|
||||
/// The static program ID
|
||||
pub static ID: ::solana_sdk::pubkey::Pubkey = #id;
|
||||
pub static ID: #pubkey_type = #id;
|
||||
|
||||
/// Confirms that a given pubkey is equivalent to the program ID
|
||||
pub fn check_id(id: &::solana_sdk::pubkey::Pubkey) -> bool {
|
||||
pub fn check_id(id: &#pubkey_type) -> bool {
|
||||
id == &ID
|
||||
}
|
||||
|
||||
/// Returns the program ID
|
||||
pub fn id() -> ::solana_sdk::pubkey::Pubkey {
|
||||
pub fn id() -> #pubkey_type {
|
||||
ID
|
||||
}
|
||||
|
||||
@ -60,6 +61,33 @@ impl ToTokens for Id {
|
||||
assert!(check_id(&id()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
struct Id(proc_macro2::TokenStream);
|
||||
|
||||
impl Parse for Id {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
parse_id(input, quote! { ::solana_sdk::pubkey::Pubkey }).map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for Id {
|
||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||
id_to_tokens(&self.0, quote! { ::solana_sdk::pubkey::Pubkey }, tokens)
|
||||
}
|
||||
}
|
||||
|
||||
struct ProgramSdkId(proc_macro2::TokenStream);
|
||||
|
||||
impl Parse for ProgramSdkId {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
parse_id(input, quote! { ::solana_program::pubkey::Pubkey }).map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for ProgramSdkId {
|
||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||
id_to_tokens(&self.0, quote! { ::solana_program::pubkey::Pubkey }, tokens)
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +163,16 @@ pub fn declare_id(input: TokenStream) -> TokenStream {
|
||||
TokenStream::from(quote! {#id})
|
||||
}
|
||||
|
||||
fn parse_pubkey(id_literal: &LitStr) -> Result<proc_macro2::TokenStream> {
|
||||
#[proc_macro]
|
||||
pub fn program_declare_id(input: TokenStream) -> TokenStream {
|
||||
let id = parse_macro_input!(input as ProgramSdkId);
|
||||
TokenStream::from(quote! {#id})
|
||||
}
|
||||
|
||||
fn parse_pubkey(
|
||||
id_literal: &LitStr,
|
||||
pubkey_type: &proc_macro2::TokenStream,
|
||||
) -> Result<proc_macro2::TokenStream> {
|
||||
let id_vec = bs58::decode(id_literal.value())
|
||||
.into_vec()
|
||||
.map_err(|_| syn::Error::new_spanned(&id_literal, "failed to decode base58 string"))?;
|
||||
@ -147,7 +184,7 @@ fn parse_pubkey(id_literal: &LitStr) -> Result<proc_macro2::TokenStream> {
|
||||
})?;
|
||||
let bytes = id_array.iter().map(|b| LitByte::new(*b, Span::call_site()));
|
||||
Ok(quote! {
|
||||
::solana_sdk::pubkey::Pubkey::new_from_array(
|
||||
#pubkey_type::new_from_array(
|
||||
[#(#bytes,)*]
|
||||
)
|
||||
})
|
||||
@ -160,11 +197,15 @@ struct Pubkeys {
|
||||
}
|
||||
impl Parse for Pubkeys {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
let pubkey_type = quote! {
|
||||
::solana_sdk::pubkey::Pubkey
|
||||
};
|
||||
|
||||
let method = input.parse()?;
|
||||
let _comma: Token![,] = input.parse()?;
|
||||
let (num, pubkeys) = if input.peek(syn::LitStr) {
|
||||
let id_literal: LitStr = input.parse()?;
|
||||
(1, parse_pubkey(&id_literal)?)
|
||||
(1, parse_pubkey(&id_literal, &pubkey_type)?)
|
||||
} else if input.peek(Bracket) {
|
||||
let pubkey_strings;
|
||||
bracketed!(pubkey_strings in input);
|
||||
@ -172,7 +213,7 @@ impl Parse for Pubkeys {
|
||||
Punctuated::parse_terminated(&pubkey_strings)?;
|
||||
let mut pubkeys: Punctuated<proc_macro2::TokenStream, Token![,]> = Punctuated::new();
|
||||
for string in punctuated.iter() {
|
||||
pubkeys.push(parse_pubkey(string)?);
|
||||
pubkeys.push(parse_pubkey(string, &pubkey_type)?);
|
||||
}
|
||||
(pubkeys.len(), quote! {#pubkeys})
|
||||
} else {
|
||||
@ -195,15 +236,19 @@ impl ToTokens for Pubkeys {
|
||||
num,
|
||||
pubkeys,
|
||||
} = self;
|
||||
|
||||
let pubkey_type = quote! {
|
||||
::solana_sdk::pubkey::Pubkey
|
||||
};
|
||||
if *num == 1 {
|
||||
tokens.extend(quote! {
|
||||
pub fn #method() -> ::solana_sdk::pubkey::Pubkey {
|
||||
pub fn #method() -> #pubkey_type {
|
||||
#pubkeys
|
||||
}
|
||||
});
|
||||
} else {
|
||||
tokens.extend(quote! {
|
||||
pub fn #method() -> ::std::vec::Vec<::solana_sdk::pubkey::Pubkey> {
|
||||
pub fn #method() -> ::std::vec::Vec<#pubkey_type> {
|
||||
vec![#pubkeys]
|
||||
}
|
||||
});
|
||||
|
45
sdk/program/Cargo.toml
Normal file
45
sdk/program/Cargo.toml
Normal file
@ -0,0 +1,45 @@
|
||||
[package]
|
||||
name = "solana-program"
|
||||
version = "1.4.3"
|
||||
description = "Solana Program"
|
||||
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
homepage = "https://solana.com/"
|
||||
license = "Apache-2.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bincode = "1.3.1"
|
||||
bs58 = "0.3.1"
|
||||
bv = { version = "0.11.1", features = ["serde"] }
|
||||
hex = "0.4.2"
|
||||
itertools = "0.9.0"
|
||||
lazy_static = "1.4.0"
|
||||
log = "0.4.8"
|
||||
num-derive = "0.3"
|
||||
num-traits = "0.2"
|
||||
rustversion = "1.0.3"
|
||||
serde = "1.0.112"
|
||||
serde_bytes = "0.11"
|
||||
serde_derive = "1.0.103"
|
||||
sha2 = "0.8.2"
|
||||
solana-frozen-abi = { path = "../../frozen-abi", version = "1.4.3" }
|
||||
solana-frozen-abi-macro = { path = "../../frozen-abi/macro", version = "1.4.3" }
|
||||
solana-sdk-macro = { path = "../macro", version = "1.4.3" }
|
||||
thiserror = "1.0"
|
||||
|
||||
[target.'cfg(not(target_arch = "bpf"))'.dependencies]
|
||||
curve25519-dalek = { version = "2.1.0" }
|
||||
rand = "0.7.0"
|
||||
solana-logger = { path = "../../logger", version = "1.4.3" }
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1.3.0"
|
||||
bincode = "1.3.1"
|
||||
serde_json = "1.0.56"
|
||||
|
||||
[build-dependencies]
|
||||
rustc_version = "0.2"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
2
sdk/program/Xargo.toml
Normal file
2
sdk/program/Xargo.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[target.bpfel-unknown-unknown.dependencies.std]
|
||||
features = []
|
1
sdk/program/build.rs
Symbolic link
1
sdk/program/build.rs
Symbolic link
@ -0,0 +1 @@
|
||||
../../frozen-abi/build.rs
|
@ -8,7 +8,7 @@ use std::{
|
||||
|
||||
/// An Account with data that is stored on chain
|
||||
#[repr(C)]
|
||||
#[frozen_abi(digest = "By9FhuLAM947tkLxbTVQru9ZKTrRQuvCR5W387nPSLNu")]
|
||||
#[frozen_abi(digest = "Upy4zg4EXZTnY371b4JPrGTh2kLcYpRno2K2pvjbN4e")]
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Default, AbiExample)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Account {
|
257
sdk/program/src/entrypoint.rs
Normal file
257
sdk/program/src/entrypoint.rs
Normal file
@ -0,0 +1,257 @@
|
||||
//! @brief Solana Rust-based BPF program entry point supported by the latest
|
||||
//! BPFLoader. For more information see './bpf_loader.rs'
|
||||
|
||||
extern crate alloc;
|
||||
use crate::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey};
|
||||
use alloc::vec::Vec;
|
||||
use std::{
|
||||
alloc::Layout,
|
||||
cell::RefCell,
|
||||
mem::{align_of, size_of},
|
||||
ptr::null_mut,
|
||||
rc::Rc,
|
||||
// Hide Result from bindgen gets confused about generics in non-generic type declarations
|
||||
result::Result as ResultGeneric,
|
||||
slice::{from_raw_parts, from_raw_parts_mut},
|
||||
};
|
||||
|
||||
pub type ProgramResult = ResultGeneric<(), ProgramError>;
|
||||
|
||||
/// User implemented function to process an instruction
|
||||
///
|
||||
/// program_id: Program ID of the currently executing program accounts: Accounts
|
||||
/// passed as part of the instruction instruction_data: Instruction data
|
||||
pub type ProcessInstruction =
|
||||
fn(program_id: &Pubkey, accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult;
|
||||
|
||||
/// Programs indicate success with a return value of 0
|
||||
pub const SUCCESS: u64 = 0;
|
||||
|
||||
/// Start address of the memory region used for program heap.
|
||||
pub const HEAP_START_ADDRESS: usize = 0x300000000;
|
||||
/// Length of the heap memory region used for program heap.
|
||||
pub const HEAP_LENGTH: usize = 32 * 1024;
|
||||
|
||||
/// Declare the entry point of the program and use the default local heap
|
||||
/// implementation
|
||||
///
|
||||
/// Deserialize the program input arguments and call the user defined
|
||||
/// `process_instruction` function. Users must call this macro otherwise an
|
||||
/// entry point for their program will not be created.
|
||||
///
|
||||
/// If the program defines the feature `custom-heap` then the default heap
|
||||
/// implementation will not be included and the program is free to implement
|
||||
/// their own `#[global_allocator]`
|
||||
#[macro_export]
|
||||
macro_rules! entrypoint {
|
||||
($process_instruction:ident) => {
|
||||
#[cfg(all(not(feature = "custom-heap"), not(test)))]
|
||||
#[global_allocator]
|
||||
static A: $crate::entrypoint::BumpAllocator = $crate::entrypoint::BumpAllocator {
|
||||
start: $crate::entrypoint::HEAP_START_ADDRESS,
|
||||
len: $crate::entrypoint::HEAP_LENGTH,
|
||||
};
|
||||
|
||||
/// # Safety
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
|
||||
let (program_id, accounts, instruction_data) =
|
||||
unsafe { $crate::entrypoint::deserialize(input) };
|
||||
match $process_instruction(&program_id, &accounts, &instruction_data) {
|
||||
Ok(()) => $crate::entrypoint::SUCCESS,
|
||||
Err(error) => error.into(),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// The bump allocator used as the default rust heap when running programs.
|
||||
pub struct BumpAllocator {
|
||||
pub start: usize,
|
||||
pub len: usize,
|
||||
}
|
||||
unsafe impl std::alloc::GlobalAlloc for BumpAllocator {
|
||||
#[inline]
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
let pos_ptr = self.start as *mut usize;
|
||||
|
||||
let mut pos = *pos_ptr;
|
||||
if pos == 0 {
|
||||
// First time, set starting position
|
||||
pos = self.start + self.len;
|
||||
}
|
||||
pos = pos.saturating_sub(layout.size());
|
||||
pos &= !(layout.align().wrapping_sub(1));
|
||||
if pos < self.start + size_of::<*mut u8>() {
|
||||
return null_mut();
|
||||
}
|
||||
*pos_ptr = pos;
|
||||
pos as *mut u8
|
||||
}
|
||||
#[inline]
|
||||
unsafe fn dealloc(&self, _: *mut u8, _: Layout) {
|
||||
// I'm a bump allocator, I don't free
|
||||
}
|
||||
}
|
||||
|
||||
/// Maximum number of bytes a program may add to an account during a single realloc
|
||||
pub const MAX_PERMITTED_DATA_INCREASE: usize = 1_024 * 10;
|
||||
|
||||
/// Deserialize the input arguments
|
||||
///
|
||||
/// # Safety
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a>>, &'a [u8]) {
|
||||
let mut offset: usize = 0;
|
||||
|
||||
// Number of accounts present
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let num_accounts = *(input.add(offset) as *const u64) as usize;
|
||||
offset += size_of::<u64>();
|
||||
|
||||
// Account Infos
|
||||
|
||||
let mut accounts = Vec::with_capacity(num_accounts);
|
||||
for _ in 0..num_accounts {
|
||||
let dup_info = *(input.add(offset) as *const u8);
|
||||
offset += size_of::<u8>();
|
||||
if dup_info == std::u8::MAX {
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let is_signer = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let is_writable = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let executable = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
|
||||
offset += size_of::<u32>(); // padding to u64
|
||||
|
||||
let key: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
offset += size_of::<Pubkey>();
|
||||
|
||||
let owner: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
offset += size_of::<Pubkey>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let lamports = Rc::new(RefCell::new(&mut *(input.add(offset) as *mut u64)));
|
||||
offset += size_of::<u64>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let data_len = *(input.add(offset) as *const u64) as usize;
|
||||
offset += size_of::<u64>();
|
||||
|
||||
let data = Rc::new(RefCell::new({
|
||||
from_raw_parts_mut(input.add(offset), data_len)
|
||||
}));
|
||||
offset += data_len + MAX_PERMITTED_DATA_INCREASE;
|
||||
offset += (offset as *const u8).align_offset(align_of::<u128>()); // padding
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let rent_epoch = *(input.add(offset) as *const u64);
|
||||
offset += size_of::<u64>();
|
||||
|
||||
accounts.push(AccountInfo {
|
||||
is_signer,
|
||||
is_writable,
|
||||
key,
|
||||
lamports,
|
||||
data,
|
||||
owner,
|
||||
executable,
|
||||
rent_epoch,
|
||||
});
|
||||
} else {
|
||||
offset += 7; // padding
|
||||
|
||||
// Duplicate account, clone the original
|
||||
accounts.push(accounts[dup_info as usize].clone());
|
||||
}
|
||||
}
|
||||
|
||||
// Instruction data
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let instruction_data_len = *(input.add(offset) as *const u64) as usize;
|
||||
offset += size_of::<u64>();
|
||||
|
||||
let instruction_data = { from_raw_parts(input.add(offset), instruction_data_len) };
|
||||
offset += instruction_data_len;
|
||||
|
||||
// Program Id
|
||||
|
||||
let program_id: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
|
||||
(program_id, accounts, instruction_data)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use std::alloc::GlobalAlloc;
|
||||
|
||||
#[test]
|
||||
fn test_bump_allocator() {
|
||||
// alloc the entire
|
||||
{
|
||||
let heap = vec![0u8; 128];
|
||||
let allocator = BumpAllocator {
|
||||
start: heap.as_ptr() as *const _ as usize,
|
||||
len: heap.len(),
|
||||
};
|
||||
for i in 0..128 - size_of::<*mut u8>() {
|
||||
let ptr = unsafe {
|
||||
allocator.alloc(Layout::from_size_align(1, size_of::<u8>()).unwrap())
|
||||
};
|
||||
assert_eq!(
|
||||
ptr as *const _ as usize,
|
||||
heap.as_ptr() as *const _ as usize + heap.len() - 1 - i
|
||||
);
|
||||
}
|
||||
assert_eq!(null_mut(), unsafe {
|
||||
allocator.alloc(Layout::from_size_align(1, 1).unwrap())
|
||||
});
|
||||
}
|
||||
// check alignment
|
||||
{
|
||||
let heap = vec![0u8; 128];
|
||||
let allocator = BumpAllocator {
|
||||
start: heap.as_ptr() as *const _ as usize,
|
||||
len: heap.len(),
|
||||
};
|
||||
let ptr =
|
||||
unsafe { allocator.alloc(Layout::from_size_align(1, size_of::<u8>()).unwrap()) };
|
||||
assert_eq!(0, ptr.align_offset(size_of::<u8>()));
|
||||
let ptr =
|
||||
unsafe { allocator.alloc(Layout::from_size_align(1, size_of::<u16>()).unwrap()) };
|
||||
assert_eq!(0, ptr.align_offset(size_of::<u16>()));
|
||||
let ptr =
|
||||
unsafe { allocator.alloc(Layout::from_size_align(1, size_of::<u32>()).unwrap()) };
|
||||
assert_eq!(0, ptr.align_offset(size_of::<u32>()));
|
||||
let ptr =
|
||||
unsafe { allocator.alloc(Layout::from_size_align(1, size_of::<u64>()).unwrap()) };
|
||||
assert_eq!(0, ptr.align_offset(size_of::<u64>()));
|
||||
let ptr =
|
||||
unsafe { allocator.alloc(Layout::from_size_align(1, size_of::<u128>()).unwrap()) };
|
||||
assert_eq!(0, ptr.align_offset(size_of::<u128>()));
|
||||
let ptr = unsafe { allocator.alloc(Layout::from_size_align(1, 64).unwrap()) };
|
||||
assert_eq!(0, ptr.align_offset(64));
|
||||
}
|
||||
// alloc entire block (minus the pos ptr)
|
||||
{
|
||||
let heap = vec![0u8; 128];
|
||||
let allocator = BumpAllocator {
|
||||
start: heap.as_ptr() as *const _ as usize,
|
||||
len: heap.len(),
|
||||
};
|
||||
let ptr =
|
||||
unsafe { allocator.alloc(Layout::from_size_align(120, size_of::<u8>()).unwrap()) };
|
||||
assert_ne!(ptr, null_mut());
|
||||
assert_eq!(0, ptr.align_offset(size_of::<u64>()));
|
||||
}
|
||||
}
|
||||
}
|
137
sdk/program/src/entrypoint_deprecated.rs
Normal file
137
sdk/program/src/entrypoint_deprecated.rs
Normal file
@ -0,0 +1,137 @@
|
||||
//! @brief Solana Rust-based BPF program entry point supported by the original
|
||||
//! and now deprecated BPFLoader. For more information see
|
||||
//! './bpf_loader_deprecated.rs'
|
||||
|
||||
extern crate alloc;
|
||||
use crate::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey};
|
||||
use alloc::vec::Vec;
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
mem::size_of,
|
||||
rc::Rc,
|
||||
// Hide Result from bindgen gets confused about generics in non-generic type declarations
|
||||
result::Result as ResultGeneric,
|
||||
slice::{from_raw_parts, from_raw_parts_mut},
|
||||
};
|
||||
|
||||
pub type ProgramResult = ResultGeneric<(), ProgramError>;
|
||||
|
||||
/// User implemented function to process an instruction
|
||||
///
|
||||
/// program_id: Program ID of the currently executing program
|
||||
/// accounts: Accounts passed as part of the instruction
|
||||
/// instruction_data: Instruction data
|
||||
pub type ProcessInstruction =
|
||||
fn(program_id: &Pubkey, accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult;
|
||||
|
||||
/// Programs indicate success with a return value of 0
|
||||
pub const SUCCESS: u64 = 0;
|
||||
|
||||
/// Declare the entry point of the program.
|
||||
///
|
||||
/// Deserialize the program input arguments and call
|
||||
/// the user defined `process_instruction` function.
|
||||
/// Users must call this macro otherwise an entry point for
|
||||
/// their program will not be created.
|
||||
#[macro_export]
|
||||
macro_rules! entrypoint_deprecated {
|
||||
($process_instruction:ident) => {
|
||||
/// # Safety
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
|
||||
let (program_id, accounts, instruction_data) =
|
||||
unsafe { $crate::entrypoint_deprecated::deserialize(input) };
|
||||
match $process_instruction(&program_id, &accounts, &instruction_data) {
|
||||
Ok(()) => $crate::entrypoint_deprecated::SUCCESS,
|
||||
Err(error) => error.into(),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Deserialize the input arguments
|
||||
///
|
||||
/// # Safety
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a>>, &'a [u8]) {
|
||||
let mut offset: usize = 0;
|
||||
|
||||
// Number of accounts present
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let num_accounts = *(input.add(offset) as *const u64) as usize;
|
||||
offset += size_of::<u64>();
|
||||
|
||||
// Account Infos
|
||||
|
||||
let mut accounts = Vec::with_capacity(num_accounts);
|
||||
for _ in 0..num_accounts {
|
||||
let dup_info = *(input.add(offset) as *const u8);
|
||||
offset += size_of::<u8>();
|
||||
if dup_info == std::u8::MAX {
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let is_signer = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let is_writable = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
|
||||
let key: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
offset += size_of::<Pubkey>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let lamports = Rc::new(RefCell::new(&mut *(input.add(offset) as *mut u64)));
|
||||
offset += size_of::<u64>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let data_len = *(input.add(offset) as *const u64) as usize;
|
||||
offset += size_of::<u64>();
|
||||
|
||||
let data = Rc::new(RefCell::new({
|
||||
from_raw_parts_mut(input.add(offset), data_len)
|
||||
}));
|
||||
offset += data_len;
|
||||
|
||||
let owner: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
offset += size_of::<Pubkey>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let executable = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let rent_epoch = *(input.add(offset) as *const u64);
|
||||
offset += size_of::<u64>();
|
||||
|
||||
accounts.push(AccountInfo {
|
||||
is_signer,
|
||||
is_writable,
|
||||
key,
|
||||
lamports,
|
||||
data,
|
||||
owner,
|
||||
executable,
|
||||
rent_epoch,
|
||||
});
|
||||
} else {
|
||||
// Duplicate account, clone the original
|
||||
accounts.push(accounts[dup_info as usize].clone());
|
||||
}
|
||||
}
|
||||
|
||||
// Instruction data
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let instruction_data_len = *(input.add(offset) as *const u64) as usize;
|
||||
offset += size_of::<u64>();
|
||||
|
||||
let instruction_data = { from_raw_parts(input.add(offset), instruction_data_len) };
|
||||
offset += instruction_data_len;
|
||||
|
||||
// Program Id
|
||||
|
||||
let program_id: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
|
||||
(program_id, accounts, instruction_data)
|
||||
}
|
186
sdk/program/src/hash.rs
Normal file
186
sdk/program/src/hash.rs
Normal file
@ -0,0 +1,186 @@
|
||||
//! The `hash` module provides functions for creating SHA-256 hashes.
|
||||
|
||||
use crate::sanitize::Sanitize;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::{convert::TryFrom, fmt, mem, str::FromStr};
|
||||
use thiserror::Error;
|
||||
|
||||
pub const HASH_BYTES: usize = 32;
|
||||
#[derive(
|
||||
Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash, AbiExample,
|
||||
)]
|
||||
#[repr(transparent)]
|
||||
pub struct Hash(pub [u8; HASH_BYTES]);
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Hasher {
|
||||
hasher: Sha256,
|
||||
}
|
||||
|
||||
impl Hasher {
|
||||
pub fn hash(&mut self, val: &[u8]) {
|
||||
self.hasher.input(val);
|
||||
}
|
||||
pub fn hashv(&mut self, vals: &[&[u8]]) {
|
||||
for val in vals {
|
||||
self.hash(val);
|
||||
}
|
||||
}
|
||||
pub fn result(self) -> Hash {
|
||||
// At the time of this writing, the sha2 library is stuck on an old version
|
||||
// of generic_array (0.9.0). Decouple ourselves with a clone to our version.
|
||||
Hash(<[u8; HASH_BYTES]>::try_from(self.hasher.result().as_slice()).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl Sanitize for Hash {}
|
||||
|
||||
impl AsRef<[u8]> for Hash {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
&self.0[..]
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Hash {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", bs58::encode(self.0).into_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Hash {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", bs58::encode(self.0).into_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Error)]
|
||||
pub enum ParseHashError {
|
||||
#[error("string decoded to wrong size for hash")]
|
||||
WrongSize,
|
||||
#[error("failed to decoded string to hash")]
|
||||
Invalid,
|
||||
}
|
||||
|
||||
impl FromStr for Hash {
|
||||
type Err = ParseHashError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let bytes = bs58::decode(s)
|
||||
.into_vec()
|
||||
.map_err(|_| ParseHashError::Invalid)?;
|
||||
if bytes.len() != mem::size_of::<Hash>() {
|
||||
Err(ParseHashError::WrongSize)
|
||||
} else {
|
||||
Ok(Hash::new(&bytes))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash {
|
||||
pub fn new(hash_slice: &[u8]) -> Self {
|
||||
Hash(<[u8; HASH_BYTES]>::try_from(hash_slice).unwrap())
|
||||
}
|
||||
|
||||
pub const fn new_from_array(hash_array: [u8; HASH_BYTES]) -> Self {
|
||||
Self(hash_array)
|
||||
}
|
||||
|
||||
/// unique Hash for tests and benchmarks.
|
||||
pub fn new_unique() -> Self {
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
static I: AtomicU64 = AtomicU64::new(1);
|
||||
|
||||
let mut b = [0u8; HASH_BYTES];
|
||||
let i = I.fetch_add(1, Ordering::Relaxed);
|
||||
b[0..8].copy_from_slice(&i.to_le_bytes());
|
||||
Self::new(&b)
|
||||
}
|
||||
|
||||
pub fn to_bytes(self) -> [u8; HASH_BYTES] {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a Sha256 hash for the given data.
|
||||
pub fn hashv(vals: &[&[u8]]) -> Hash {
|
||||
// Perform the calculation inline, calling this from within a program is
|
||||
// not supported
|
||||
#[cfg(not(target_arch = "bpf"))]
|
||||
{
|
||||
let mut hasher = Hasher::default();
|
||||
hasher.hashv(vals);
|
||||
hasher.result()
|
||||
}
|
||||
// Call via a system call to perform the calculation
|
||||
#[cfg(target_arch = "bpf")]
|
||||
{
|
||||
extern "C" {
|
||||
fn sol_sha256(vals: *const u8, val_len: u64, hash_result: *mut u8) -> u64;
|
||||
};
|
||||
let mut hash_result = [0; HASH_BYTES];
|
||||
unsafe {
|
||||
sol_sha256(
|
||||
vals as *const _ as *const u8,
|
||||
vals.len() as u64,
|
||||
&mut hash_result as *mut _ as *mut u8,
|
||||
);
|
||||
}
|
||||
Hash::new_from_array(hash_result)
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a Sha256 hash for the given data.
|
||||
pub fn hash(val: &[u8]) -> Hash {
|
||||
hashv(&[val])
|
||||
}
|
||||
|
||||
/// Return the hash of the given hash extended with the given value.
|
||||
pub fn extend_and_hash(id: &Hash, val: &[u8]) -> Hash {
|
||||
let mut hash_data = id.as_ref().to_vec();
|
||||
hash_data.extend_from_slice(val);
|
||||
hash(&hash_data)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_new_unique() {
|
||||
assert!(Hash::new_unique() != Hash::new_unique());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hash_fromstr() {
|
||||
let hash = hash(&[1u8]);
|
||||
|
||||
let mut hash_base58_str = bs58::encode(hash).into_string();
|
||||
|
||||
assert_eq!(hash_base58_str.parse::<Hash>(), Ok(hash));
|
||||
|
||||
hash_base58_str.push_str(&bs58::encode(hash.0).into_string());
|
||||
assert_eq!(
|
||||
hash_base58_str.parse::<Hash>(),
|
||||
Err(ParseHashError::WrongSize)
|
||||
);
|
||||
|
||||
hash_base58_str.truncate(hash_base58_str.len() / 2);
|
||||
assert_eq!(hash_base58_str.parse::<Hash>(), Ok(hash));
|
||||
|
||||
hash_base58_str.truncate(hash_base58_str.len() / 2);
|
||||
assert_eq!(
|
||||
hash_base58_str.parse::<Hash>(),
|
||||
Err(ParseHashError::WrongSize)
|
||||
);
|
||||
|
||||
let mut hash_base58_str = bs58::encode(hash.0).into_string();
|
||||
assert_eq!(hash_base58_str.parse::<Hash>(), Ok(hash));
|
||||
|
||||
// throw some non-base58 stuff in there
|
||||
hash_base58_str.replace_range(..1, "I");
|
||||
assert_eq!(
|
||||
hash_base58_str.parse::<Hash>(),
|
||||
Err(ParseHashError::Invalid)
|
||||
);
|
||||
}
|
||||
}
|
71
sdk/program/src/lib.rs
Normal file
71
sdk/program/src/lib.rs
Normal file
@ -0,0 +1,71 @@
|
||||
#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))]
|
||||
#![cfg_attr(RUSTC_NEEDS_PROC_MACRO_HYGIENE, feature(proc_macro_hygiene))]
|
||||
|
||||
// Allows macro expansion of `use ::solana_program::*` to work within this crate
|
||||
extern crate self as solana_program;
|
||||
|
||||
pub mod account;
|
||||
pub mod account_info;
|
||||
pub mod account_utils;
|
||||
pub mod bpf_loader;
|
||||
pub mod bpf_loader_deprecated;
|
||||
pub mod clock;
|
||||
pub mod decode_error;
|
||||
pub mod entrypoint;
|
||||
pub mod entrypoint_deprecated;
|
||||
pub mod epoch_schedule;
|
||||
pub mod fee_calculator;
|
||||
pub mod hash;
|
||||
pub mod incinerator;
|
||||
pub mod instruction;
|
||||
pub mod loader_instruction;
|
||||
pub mod log;
|
||||
pub mod message;
|
||||
pub mod native_token;
|
||||
pub mod nonce;
|
||||
pub mod program;
|
||||
pub mod program_error;
|
||||
pub mod program_option;
|
||||
pub mod program_pack;
|
||||
pub mod program_stubs;
|
||||
pub mod pubkey;
|
||||
pub mod rent;
|
||||
pub mod sanitize;
|
||||
pub mod secp256k1_program;
|
||||
pub mod serialize_utils;
|
||||
pub mod short_vec;
|
||||
pub mod slot_hashes;
|
||||
pub mod slot_history;
|
||||
pub mod stake_history;
|
||||
pub mod system_instruction;
|
||||
pub mod system_program;
|
||||
pub mod sysvar;
|
||||
|
||||
/// Convenience macro to declare a static public key and functions to interact with it
|
||||
///
|
||||
/// Input: a single literal base58 string representation of a program's id
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # // wrapper is used so that the macro invocation occurs in the item position
|
||||
/// # // rather than in the statement position which isn't allowed.
|
||||
/// use std::str::FromStr;
|
||||
/// use solana_program::{declare_id, pubkey::Pubkey};
|
||||
///
|
||||
/// # mod item_wrapper {
|
||||
/// # use solana_program::declare_id;
|
||||
/// declare_id!("My11111111111111111111111111111111111111111");
|
||||
/// # }
|
||||
/// # use item_wrapper::id;
|
||||
///
|
||||
/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
|
||||
/// assert_eq!(id(), my_id);
|
||||
/// ```
|
||||
pub use solana_sdk_macro::program_declare_id as declare_id;
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[macro_use]
|
||||
extern crate solana_frozen_abi_macro;
|
98
sdk/program/src/log.rs
Normal file
98
sdk/program/src/log.rs
Normal file
@ -0,0 +1,98 @@
|
||||
//! @brief Solana Rust-based BPF program logging
|
||||
|
||||
use crate::account_info::AccountInfo;
|
||||
|
||||
/// Prints a string
|
||||
/// There are two forms and are fast
|
||||
/// 1. Single string
|
||||
/// 2. 5 integers
|
||||
#[macro_export]
|
||||
macro_rules! info {
|
||||
($msg:expr) => {
|
||||
$crate::log::sol_log($msg)
|
||||
};
|
||||
($arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr, $arg5:expr) => {
|
||||
$crate::log::sol_log_64(
|
||||
$arg1 as u64,
|
||||
$arg2 as u64,
|
||||
$arg3 as u64,
|
||||
$arg4 as u64,
|
||||
$arg5 as u64,
|
||||
)
|
||||
}; // `format!()` is not supported yet, Issue #3099
|
||||
// `format!()` incurs a very large runtime overhead so it should be used with care
|
||||
// ($($arg:tt)*) => ($crate::log::sol_log(&format!($($arg)*)));
|
||||
}
|
||||
|
||||
/// Prints a string to stdout
|
||||
///
|
||||
/// @param message - Message to print
|
||||
#[inline]
|
||||
pub fn sol_log(message: &str) {
|
||||
#[cfg(target_arch = "bpf")]
|
||||
unsafe {
|
||||
sol_log_(message.as_ptr(), message.len() as u64);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "bpf"))]
|
||||
crate::program_stubs::sol_log(message);
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "bpf")]
|
||||
extern "C" {
|
||||
fn sol_log_(message: *const u8, len: u64);
|
||||
}
|
||||
|
||||
/// Prints 64 bit values represented as hexadecimal to stdout
|
||||
///
|
||||
/// @param argx - integer arguments to print
|
||||
|
||||
#[inline]
|
||||
pub fn sol_log_64(arg1: u64, arg2: u64, arg3: u64, arg4: u64, arg5: u64) {
|
||||
#[cfg(target_arch = "bpf")]
|
||||
unsafe {
|
||||
sol_log_64_(arg1, arg2, arg3, arg4, arg5);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "bpf"))]
|
||||
crate::program_stubs::sol_log_64(arg1, arg2, arg3, arg4, arg5);
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "bpf")]
|
||||
extern "C" {
|
||||
fn sol_log_64_(arg1: u64, arg2: u64, arg3: u64, arg4: u64, arg5: u64);
|
||||
}
|
||||
|
||||
/// Prints the hexadecimal representation of a slice
|
||||
///
|
||||
/// @param slice - The array to print
|
||||
#[allow(dead_code)]
|
||||
pub fn sol_log_slice(slice: &[u8]) {
|
||||
for (i, s) in slice.iter().enumerate() {
|
||||
info!(0, 0, 0, i, *s);
|
||||
}
|
||||
}
|
||||
|
||||
/// Prints the hexadecimal representation of the program's input parameters
|
||||
///
|
||||
/// @param ka - A pointer to an array of `AccountInfo` to print
|
||||
/// @param data - A pointer to the instruction data to print
|
||||
#[allow(dead_code)]
|
||||
pub fn sol_log_params(accounts: &[AccountInfo], data: &[u8]) {
|
||||
for (i, account) in accounts.iter().enumerate() {
|
||||
info!("AccountInfo");
|
||||
info!(0, 0, 0, 0, i);
|
||||
info!("- Is signer");
|
||||
info!(0, 0, 0, 0, account.is_signer);
|
||||
info!("- Key");
|
||||
account.key.log();
|
||||
info!("- Lamports");
|
||||
info!(0, 0, 0, 0, account.lamports());
|
||||
info!("- Account data length");
|
||||
info!(0, 0, 0, 0, account.data_len());
|
||||
info!("- Owner");
|
||||
account.owner.log();
|
||||
}
|
||||
info!("Instruction data");
|
||||
sol_log_slice(data);
|
||||
}
|
@ -160,7 +160,7 @@ pub struct MessageHeader {
|
||||
pub num_readonly_unsigned_accounts: u8,
|
||||
}
|
||||
|
||||
#[frozen_abi(digest = "A18PN3BWKw4hU69STY79SyRS3tS6w54nCgYRRx77vQiL")]
|
||||
#[frozen_abi(digest = "6zcKiPfKoqYChcZfYcxqcmpJetXk8P51ihc4kiujPgdr")]
|
||||
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, AbiExample)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Message {
|
||||
@ -426,10 +426,7 @@ impl Message {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
instruction::AccountMeta,
|
||||
signature::{Keypair, Signer},
|
||||
};
|
||||
use crate::instruction::AccountMeta;
|
||||
|
||||
#[test]
|
||||
fn test_message_unique_program_ids() {
|
||||
@ -444,7 +441,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_message_unique_program_ids_not_adjacent() {
|
||||
let program_id0 = Pubkey::default();
|
||||
let program_id1 = solana_sdk::pubkey::new_rand();
|
||||
let program_id1 = Pubkey::new_unique();
|
||||
let program_ids = get_program_ids(&[
|
||||
Instruction::new(program_id0, &0, vec![]),
|
||||
Instruction::new(program_id1, &0, vec![]),
|
||||
@ -455,7 +452,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_message_unique_program_ids_order_preserved() {
|
||||
let program_id0 = solana_sdk::pubkey::new_rand();
|
||||
let program_id0 = Pubkey::new_unique();
|
||||
let program_id1 = Pubkey::default(); // Key less than program_id0
|
||||
let program_ids = get_program_ids(&[
|
||||
Instruction::new(program_id0, &0, vec![]),
|
||||
@ -558,7 +555,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_message_unique_keys_order_preserved() {
|
||||
let program_id = Pubkey::default();
|
||||
let id0 = solana_sdk::pubkey::new_rand();
|
||||
let id0 = Pubkey::new_unique();
|
||||
let id1 = Pubkey::default(); // Key less than id0
|
||||
let keys = get_keys(
|
||||
&[
|
||||
@ -574,7 +571,7 @@ mod tests {
|
||||
fn test_message_unique_keys_not_adjacent() {
|
||||
let program_id = Pubkey::default();
|
||||
let id0 = Pubkey::default();
|
||||
let id1 = solana_sdk::pubkey::new_rand();
|
||||
let id1 = Pubkey::new_unique();
|
||||
let keys = get_keys(
|
||||
&[
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]),
|
||||
@ -590,7 +587,7 @@ mod tests {
|
||||
fn test_message_signed_keys_first() {
|
||||
let program_id = Pubkey::default();
|
||||
let id0 = Pubkey::default();
|
||||
let id1 = solana_sdk::pubkey::new_rand();
|
||||
let id1 = Pubkey::new_unique();
|
||||
let keys = get_keys(
|
||||
&[
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]),
|
||||
@ -619,9 +616,9 @@ mod tests {
|
||||
fn test_message_readonly_keys_last() {
|
||||
let program_id = Pubkey::default();
|
||||
let id0 = Pubkey::default(); // Identical key/program_id should be de-duped
|
||||
let id1 = solana_sdk::pubkey::new_rand();
|
||||
let id2 = solana_sdk::pubkey::new_rand();
|
||||
let id3 = solana_sdk::pubkey::new_rand();
|
||||
let id1 = Pubkey::new_unique();
|
||||
let id2 = Pubkey::new_unique();
|
||||
let id3 = Pubkey::new_unique();
|
||||
let keys = get_keys(
|
||||
&[
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new_readonly(id0, false)]),
|
||||
@ -639,11 +636,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_message_kitchen_sink() {
|
||||
let program_id0 = solana_sdk::pubkey::new_rand();
|
||||
let program_id1 = solana_sdk::pubkey::new_rand();
|
||||
let program_id0 = Pubkey::new_unique();
|
||||
let program_id1 = Pubkey::new_unique();
|
||||
let id0 = Pubkey::default();
|
||||
let keypair1 = Keypair::new();
|
||||
let id1 = keypair1.pubkey();
|
||||
let id1 = Pubkey::new_unique();
|
||||
let message = Message::new(
|
||||
&[
|
||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id0, false)]),
|
||||
@ -669,7 +665,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_message_payer_first() {
|
||||
let program_id = Pubkey::default();
|
||||
let payer = solana_sdk::pubkey::new_rand();
|
||||
let payer = Pubkey::new_unique();
|
||||
let id0 = Pubkey::default();
|
||||
|
||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]);
|
||||
@ -692,8 +688,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_message_program_last() {
|
||||
let program_id = Pubkey::default();
|
||||
let id0 = solana_sdk::pubkey::new_rand();
|
||||
let id1 = solana_sdk::pubkey::new_rand();
|
||||
let id0 = Pubkey::new_unique();
|
||||
let id1 = Pubkey::new_unique();
|
||||
let keys = get_keys(
|
||||
&[
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new_readonly(id0, false)]),
|
||||
@ -710,8 +706,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_program_position() {
|
||||
let program_id0 = Pubkey::default();
|
||||
let program_id1 = solana_sdk::pubkey::new_rand();
|
||||
let id = solana_sdk::pubkey::new_rand();
|
||||
let program_id1 = Pubkey::new_unique();
|
||||
let id = Pubkey::new_unique();
|
||||
let message = Message::new(
|
||||
&[
|
||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id, false)]),
|
||||
@ -726,12 +722,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_is_writable() {
|
||||
let key0 = solana_sdk::pubkey::new_rand();
|
||||
let key1 = solana_sdk::pubkey::new_rand();
|
||||
let key2 = solana_sdk::pubkey::new_rand();
|
||||
let key3 = solana_sdk::pubkey::new_rand();
|
||||
let key4 = solana_sdk::pubkey::new_rand();
|
||||
let key5 = solana_sdk::pubkey::new_rand();
|
||||
let key0 = Pubkey::new_unique();
|
||||
let key1 = Pubkey::new_unique();
|
||||
let key2 = Pubkey::new_unique();
|
||||
let key3 = Pubkey::new_unique();
|
||||
let key4 = Pubkey::new_unique();
|
||||
let key5 = Pubkey::new_unique();
|
||||
|
||||
let message = Message {
|
||||
header: MessageHeader {
|
||||
@ -754,10 +750,10 @@ mod tests {
|
||||
#[test]
|
||||
fn test_get_account_keys_by_lock_type() {
|
||||
let program_id = Pubkey::default();
|
||||
let id0 = solana_sdk::pubkey::new_rand();
|
||||
let id1 = solana_sdk::pubkey::new_rand();
|
||||
let id2 = solana_sdk::pubkey::new_rand();
|
||||
let id3 = solana_sdk::pubkey::new_rand();
|
||||
let id0 = Pubkey::new_unique();
|
||||
let id1 = Pubkey::new_unique();
|
||||
let id2 = Pubkey::new_unique();
|
||||
let id3 = Pubkey::new_unique();
|
||||
let message = Message::new(
|
||||
&[
|
||||
Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]),
|
||||
@ -776,12 +772,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_decompile_instructions() {
|
||||
solana_logger::setup();
|
||||
let program_id0 = solana_sdk::pubkey::new_rand();
|
||||
let program_id1 = solana_sdk::pubkey::new_rand();
|
||||
let id0 = solana_sdk::pubkey::new_rand();
|
||||
let id1 = solana_sdk::pubkey::new_rand();
|
||||
let id2 = solana_sdk::pubkey::new_rand();
|
||||
let id3 = solana_sdk::pubkey::new_rand();
|
||||
let program_id0 = Pubkey::new_unique();
|
||||
let program_id1 = Pubkey::new_unique();
|
||||
let id0 = Pubkey::new_unique();
|
||||
let id1 = Pubkey::new_unique();
|
||||
let id2 = Pubkey::new_unique();
|
||||
let id3 = Pubkey::new_unique();
|
||||
let instructions = vec![
|
||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id0, false)]),
|
||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id1, true)]),
|
@ -170,12 +170,11 @@ pub fn create_account(lamports: u64) -> RefCell<account::Account> {
|
||||
}
|
||||
|
||||
/// Convenience function for working with keyed accounts in tests
|
||||
#[cfg(feature = "everything")]
|
||||
pub fn with_test_keyed_account<F>(lamports: u64, signer: bool, f: F)
|
||||
where
|
||||
F: Fn(&KeyedAccount),
|
||||
{
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let pubkey = Pubkey::new_unique();
|
||||
let account = create_account(lamports);
|
||||
let keyed_account = KeyedAccount::new(&pubkey, signer, &account);
|
||||
f(&keyed_account)
|
@ -1,4 +1,4 @@
|
||||
use solana_sdk::{
|
||||
use crate::{
|
||||
account::Account,
|
||||
account_utils::StateMut,
|
||||
fee_calculator::FeeCalculator,
|
||||
@ -26,7 +26,7 @@ pub fn fee_calculator_of(account: &Account) -> Option<FeeCalculator> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use solana_sdk::{
|
||||
use crate::{
|
||||
account_utils::State as AccountUtilsState,
|
||||
hash::Hash,
|
||||
nonce::{account::with_test_keyed_account, Account as NonceAccount, State},
|
@ -1,5 +1,3 @@
|
||||
#![cfg(feature = "program")]
|
||||
|
||||
use crate::{account_info::AccountInfo, entrypoint::ProgramResult, instruction::Instruction};
|
||||
|
||||
/// Invoke a cross-program instruction
|
@ -1,13 +1,9 @@
|
||||
use crate::info;
|
||||
use crate::{decode_error::DecodeError, instruction::InstructionError, pubkey::PubkeyError};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
use std::convert::TryFrom;
|
||||
use thiserror::Error;
|
||||
|
||||
#[cfg(feature = "program")]
|
||||
use crate::info;
|
||||
#[cfg(all(feature = "everything", not(feature = "program")))]
|
||||
use log::info;
|
||||
|
||||
/// Reasons the program may fail
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Error, PartialEq, Serialize)]
|
||||
pub enum ProgramError {
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user