Load predefined tokens into db at start
@@ -12,13 +12,45 @@ pub mod tree_state;
use crate::data_restore_driver::DataRestoreDriver;
use clap::{App, Arg};
-use models::config_options::ConfigurationOptions;
+use models::{
+ config_options::ConfigurationOptions,
+ node::{
+ tokens::{get_genesis_token_list, Token},
+ TokenId,
+ },
+};
use storage::ConnectionPool;
use web3::transports::Http;
const ETH_BLOCKS_STEP: u64 = 1;
const END_ETH_BLOCKS_OFFSET: u64 = 40;
+fn add_tokens_to_db(pool: &ConnectionPool, eth_network: &str) {
+ let genesis_tokens =
+ get_genesis_token_list(&eth_network).expect("Initial token list not found");
+ for (id, token) in (1..).zip(genesis_tokens) {
+ log::info!(
+ "Adding token: {}, id:{}, address: {}, decimals: {}",
+ token.symbol,
+ id,
+ token.address,
+ token.decimals
+ );
+ pool.access_storage()
+ .expect("failed to access db")
+ .tokens_schema()
+ .store_token(Token {
+ id: id as TokenId,
+ symbol: token.symbol,
+ address: token.address[2..]
+ .parse()
+ .expect("failed to parse token address"),
+ decimals: token.decimals,
+ })
+ .expect("failed to store token");
+ }
+}
+
fn main() {
info!("Restoring zkSync state from the contract");
env_logger::init();
@@ -35,7 +67,7 @@ fn main() {
.arg(
Arg::with_name("continue")
.long("continue")
- .help("Continues data restoreing"),
+ .help("Continues data restoring"),
)
.get_matches();
@@ -58,6 +90,10 @@ fn main() {
// If genesis is argument is present - there will be fetching contracts creation transactions to get first eth block and genesis acc address
if cli.is_present("genesis") {
+ // We have to load pre-defined tokens into the database before restoring state,
+ // since these tokens do not have a corresponding Ethereum events.
+ add_tokens_to_db(&driver.connection_pool, &config_opts.eth_network);
+
driver.set_genesis_state(genesis_tx_hash);
}
