8
programs/bpf/Cargo.lock
generated
8
programs/bpf/Cargo.lock
generated
@ -1987,6 +1987,14 @@ dependencies = [
|
|||||||
"solana-sdk-bpf-test 0.23.0",
|
"solana-sdk-bpf-test 0.23.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "solana-bpf-rust-dup-accounts"
|
||||||
|
version = "0.23.0"
|
||||||
|
dependencies = [
|
||||||
|
"solana-sdk 0.23.0",
|
||||||
|
"solana-sdk-bpf-test 0.23.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "solana-bpf-rust-external-spend"
|
name = "solana-bpf-rust-external-spend"
|
||||||
version = "0.23.0"
|
version = "0.23.0"
|
||||||
|
@ -37,6 +37,7 @@ members = [
|
|||||||
"rust/128bit_dep",
|
"rust/128bit_dep",
|
||||||
"rust/alloc",
|
"rust/alloc",
|
||||||
"rust/dep_crate",
|
"rust/dep_crate",
|
||||||
|
"rust/dup_accounts",
|
||||||
"rust/external_spend",
|
"rust/external_spend",
|
||||||
"rust/iter",
|
"rust/iter",
|
||||||
"rust/many_args",
|
"rust/many_args",
|
||||||
|
@ -70,6 +70,7 @@ fn main() {
|
|||||||
"128bit",
|
"128bit",
|
||||||
"alloc",
|
"alloc",
|
||||||
"dep_crate",
|
"dep_crate",
|
||||||
|
"dup_accounts",
|
||||||
"iter",
|
"iter",
|
||||||
"many_args",
|
"many_args",
|
||||||
"external_spend",
|
"external_spend",
|
||||||
|
26
programs/bpf/rust/dup_accounts/Cargo.toml
Normal file
26
programs/bpf/rust/dup_accounts/Cargo.toml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
# Note: This crate must be built using do.sh
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "solana-bpf-rust-dup-accounts"
|
||||||
|
version = "0.23.0"
|
||||||
|
description = "Solana BPF test program written in Rust"
|
||||||
|
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||||
|
repository = "https://github.com/solana-labs/solana"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
homepage = "https://solana.com/"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
solana-sdk = { path = "../../../../sdk/", version = "0.23.0", default-features = false }
|
||||||
|
|
||||||
|
[dev_dependencies]
|
||||||
|
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.23.0" }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
program = ["solana-sdk/program"]
|
||||||
|
default = ["program"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "solana_bpf_rust_dup_accounts"
|
||||||
|
crate-type = ["cdylib"]
|
2
programs/bpf/rust/dup_accounts/Xargo.toml
Normal file
2
programs/bpf/rust/dup_accounts/Xargo.toml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[target.bpfel-unknown-unknown.dependencies.std]
|
||||||
|
features = []
|
48
programs/bpf/rust/dup_accounts/src/lib.rs
Normal file
48
programs/bpf/rust/dup_accounts/src/lib.rs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
//! @brief Example Rust-based BPF program that tests duplicate accounts passed via accounts
|
||||||
|
|
||||||
|
extern crate solana_sdk;
|
||||||
|
use solana_sdk::{
|
||||||
|
account_info::AccountInfo, entrypoint, entrypoint::SUCCESS, info, pubkey::Pubkey,
|
||||||
|
};
|
||||||
|
|
||||||
|
entrypoint!(process_instruction);
|
||||||
|
fn process_instruction(_program_id: &Pubkey, accounts: &mut [AccountInfo], data: &[u8]) -> u32 {
|
||||||
|
const FAILURE: u32 = 1;
|
||||||
|
|
||||||
|
match data[0] {
|
||||||
|
1 => {
|
||||||
|
info!("modify first account data");
|
||||||
|
accounts[2].data[0] = 1;
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
info!("modify first account data");
|
||||||
|
accounts[3].data[0] = 2;
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
info!("modify both account data, should fail");
|
||||||
|
accounts[2].data[0] = 1;
|
||||||
|
accounts[3].data[0] = 2;
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
info!("modify first account lamports");
|
||||||
|
*accounts[1].lamports -= 1;
|
||||||
|
*accounts[2].lamports += 1;
|
||||||
|
}
|
||||||
|
5 => {
|
||||||
|
info!("modify first account lamports");
|
||||||
|
*accounts[1].lamports -= 2;
|
||||||
|
*accounts[3].lamports += 2;
|
||||||
|
}
|
||||||
|
6 => {
|
||||||
|
info!("modify both account lamports, should fail");
|
||||||
|
*accounts[1].lamports -= 1;
|
||||||
|
*accounts[2].lamports += 1;
|
||||||
|
*accounts[3].lamports += 2;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
info!("Unrecognized command");
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SUCCESS
|
||||||
|
}
|
Reference in New Issue
Block a user