diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 2ca2b5582e..dd58148d79 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -10,6 +10,7 @@ pub mod signature; pub mod system_instruction; pub mod system_program; pub mod timing; +pub mod token_program; pub mod transaction; extern crate bincode; diff --git a/sdk/src/token_program.rs b/sdk/src/token_program.rs new file mode 100644 index 0000000000..c1fdd12ffd --- /dev/null +++ b/sdk/src/token_program.rs @@ -0,0 +1,11 @@ +//! An ERC20-like Token +use pubkey::Pubkey; + +const TOKEN_PROGRAM_ID: [u8; 32] = [ + 131, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, +]; + +pub fn id() -> Pubkey { + Pubkey::new(&TOKEN_PROGRAM_ID) +} diff --git a/src/bank.rs b/src/bank.rs index 223ad786f1..c25a440b17 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -31,6 +31,7 @@ use solana_sdk::signature::Signature; use solana_sdk::system_instruction::SystemInstruction; use solana_sdk::system_program; use solana_sdk::timing::{duration_as_us, timestamp}; +use solana_sdk::token_program; use solana_sdk::transaction::Transaction; use std; use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; @@ -428,13 +429,13 @@ impl Bank { // Erc20 token program let erc20_account = Account { tokens: 1, - owner: runtime::erc20_id(), + owner: token_program::id(), userdata: b"solana_erc20".to_vec(), executable: true, loader: native_loader::id(), }; - accounts.store(&runtime::erc20_id(), &erc20_account); + accounts.store(&token_program::id(), &erc20_account); } /// Return the last entry ID registered. @@ -2158,7 +2159,7 @@ mod tests { 130, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]); - let erc20 = Pubkey::new(&[ + let token = Pubkey::new(&[ 131, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]); @@ -2172,7 +2173,7 @@ mod tests { assert_eq!(bpf_loader::id(), bpf); assert_eq!(budget_program::id(), budget); assert_eq!(storage_program::id(), storage); - assert_eq!(runtime::erc20_id(), erc20); + assert_eq!(token_program::id(), token); assert_eq!(vote_program::id(), vote); } @@ -2185,7 +2186,7 @@ mod tests { bpf_loader::id(), budget_program::id(), storage_program::id(), - runtime::erc20_id(), + token_program::id(), vote_program::id(), ]; assert!(ids.into_iter().all(move |id| unique.insert(id))); diff --git a/src/runtime.rs b/src/runtime.rs index 207e141d7f..f0dca5fb0b 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -21,16 +21,6 @@ pub fn is_legacy_program(program_id: &Pubkey) -> bool { || vote_program::check_id(program_id) } -// TODO: Rename and find a better home for this in the sdk/ -pub fn erc20_id() -> Pubkey { - const ERC20_PROGRAM_ID: [u8; 32] = [ - 131, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, - ]; - - Pubkey::new(&ERC20_PROGRAM_ID) -} - /// Process an instruction /// This method calls the instruction's program entrypoint method fn process_instruction(