Add token_program.rs to sdk/
This commit is contained in:
parent
e6fa74fe69
commit
a594f56c02
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
}
|
11
src/bank.rs
11
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)));
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue