parent
bb950ec93e
commit
1a18f0ca55
|
@ -1987,6 +1987,14 @@ dependencies = [
|
|||
"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]]
|
||||
name = "solana-bpf-rust-external-spend"
|
||||
version = "0.23.0"
|
||||
|
|
|
@ -37,6 +37,7 @@ members = [
|
|||
"rust/128bit_dep",
|
||||
"rust/alloc",
|
||||
"rust/dep_crate",
|
||||
"rust/dup_accounts",
|
||||
"rust/external_spend",
|
||||
"rust/iter",
|
||||
"rust/many_args",
|
||||
|
|
|
@ -70,6 +70,7 @@ fn main() {
|
|||
"128bit",
|
||||
"alloc",
|
||||
"dep_crate",
|
||||
"dup_accounts",
|
||||
"iter",
|
||||
"many_args",
|
||||
"external_spend",
|
||||
|
|
|
@ -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"]
|
|
@ -0,0 +1,2 @@
|
|||
[target.bpfel-unknown-unknown.dependencies.std]
|
||||
features = []
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue