diff --git a/programs/native/erc20/Cargo.toml b/programs/native/erc20/Cargo.toml index f0aabc4ce2..91f63ded29 100644 --- a/programs/native/erc20/Cargo.toml +++ b/programs/native/erc20/Cargo.toml @@ -16,5 +16,5 @@ solana-sdk = { path = "../../../sdk", version = "0.11.0" } [lib] name = "solana_erc20" -crate-type = ["cdylib"] +crate-type = ["lib", "cdylib"] diff --git a/programs/native/erc20/src/lib.rs b/programs/native/erc20/src/lib.rs index 9dfb731d99..d877d982a1 100644 --- a/programs/native/erc20/src/lib.rs +++ b/programs/native/erc20/src/lib.rs @@ -10,12 +10,33 @@ extern crate serde_derive; #[macro_use] extern crate solana_sdk; -use solana_sdk::account::KeyedAccount; +use solana_sdk::account::{Account, KeyedAccount}; +use solana_sdk::native_loader; use solana_sdk::pubkey::Pubkey; use std::sync::{Once, ONCE_INIT}; mod token_program; +const ERC20_NAME: &str = "solana_erc20"; +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, +]; + +pub fn id() -> Pubkey { + Pubkey::new(&ERC20_PROGRAM_ID) +} + +pub fn account() -> Account { + Account { + tokens: 1, + owner: id(), + userdata: ERC20_NAME.as_bytes().to_vec(), + executable: true, + loader: native_loader::id(), + } +} + solana_entrypoint!(entrypoint); fn entrypoint( program_id: &Pubkey, diff --git a/src/bank.rs b/src/bank.rs index 9c6e8b27ee..020f6b9b6e 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -22,6 +22,7 @@ use poh_service::NUM_TICKS_PER_SECOND; use rayon::prelude::*; use rpc::RpcSignatureStatus; use runtime::{self, RuntimeError}; +use solana_erc20; use solana_sdk::account::Account; use solana_sdk::hash::{hash, Hash}; use solana_sdk::native_program::ProgramError; @@ -39,7 +40,6 @@ use std::sync::{Arc, Mutex, RwLock}; use std::time::Instant; use system_program; use system_transaction::SystemTransaction; -use token_program; use tokio::prelude::Future; /// The number of most recent `last_id` values that the bank will track the signatures @@ -405,7 +405,7 @@ impl Bank { accounts.store(&bpf_loader::id(), &bpf_loader::account()); // Preload Erc20 token program - accounts.store(&token_program::id(), &token_program::account()); + accounts.store(&solana_erc20::id(), &solana_erc20::account()); } /// Return the last entry ID registered. @@ -2142,7 +2142,7 @@ mod tests { assert_eq!(bpf_loader::id(), bpf); assert_eq!(budget_program::id(), budget); assert_eq!(storage_program::id(), storage); - assert_eq!(token_program::id(), token); + assert_eq!(solana_erc20::id(), token); assert_eq!(vote_program::id(), vote); } @@ -2155,7 +2155,7 @@ mod tests { bpf_loader::id(), budget_program::id(), storage_program::id(), - token_program::id(), + solana_erc20::id(), vote_program::id(), ]; assert!(ids.into_iter().all(move |id| unique.insert(id))); diff --git a/src/lib.rs b/src/lib.rs index ee8bc54187..0c7f8876ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,7 +77,6 @@ pub mod streamer; pub mod system_program; pub mod system_transaction; pub mod thin_client; -pub mod token_program; pub mod tpu; pub mod tpu_forwarder; pub mod tvu; @@ -127,6 +126,7 @@ extern crate solana_jsonrpc_core as jsonrpc_core; extern crate solana_jsonrpc_http_server as jsonrpc_http_server; #[macro_use] extern crate solana_jsonrpc_macros as jsonrpc_macros; +extern crate solana_erc20; extern crate solana_jsonrpc_pubsub as jsonrpc_pubsub; extern crate solana_jsonrpc_ws_server as jsonrpc_ws_server; extern crate solana_metrics; diff --git a/src/token_program.rs b/src/token_program.rs deleted file mode 100644 index adbdf70295..0000000000 --- a/src/token_program.rs +++ /dev/null @@ -1,24 +0,0 @@ -//! ERC20-like Token program -use solana_sdk::account::Account; -use solana_sdk::native_loader; -use solana_sdk::pubkey::Pubkey; - -const ERC20_NAME: &str = "solana_erc20"; -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, -]; - -pub fn id() -> Pubkey { - Pubkey::new(&ERC20_PROGRAM_ID) -} - -pub fn account() -> Account { - Account { - tokens: 1, - owner: id(), - userdata: ERC20_NAME.as_bytes().to_vec(), - executable: true, - loader: native_loader::id(), - } -}