forked from anza-xyz/agave
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include simple transfer example in SVM (anza-xyz#388)
- Loading branch information
Showing
4 changed files
with
177 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "simple-transfer-program" | ||
version = "2.0.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
solana-program = { path = "../../../../sdk/program", version = "=2.0.0" } | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[workspace] |
Binary file added
BIN
+65.7 KB
svm/tests/example-programs/simple-transfer/simple_transfer_program.so
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use solana_program::{ | ||
account_info::{AccountInfo, next_account_info}, entrypoint, entrypoint::ProgramResult, pubkey::Pubkey, | ||
program::invoke, system_instruction, | ||
}; | ||
|
||
entrypoint!(process_instruction); | ||
|
||
|
||
fn process_instruction( | ||
_program_id: &Pubkey, | ||
accounts: &[AccountInfo], | ||
data: &[u8] | ||
) -> ProgramResult { | ||
let amount = u64::from_be_bytes(data[0..8].try_into().unwrap()); | ||
let accounts_iter = &mut accounts.iter(); | ||
let payer = next_account_info(accounts_iter)?; | ||
let recipient = next_account_info(accounts_iter)?; | ||
let system_program = next_account_info(accounts_iter)?; | ||
|
||
invoke( | ||
&system_instruction::transfer(payer.key, recipient.key, amount), | ||
&[payer.clone(), recipient.clone(), system_program.clone()], | ||
)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters