new data restore driver
@@ -55,7 +55,7 @@ impl DataRestoreDriver {
) -> Self {
let (_eloop, transport) = web3::transports::Http::new(&web3_endpoint).unwrap();
let web3 = web3::Web3::new(transport);
- let contract = {
+ let franklin_contract = {
let abi_string = serde_json::Value::from_str(models::abi::FRANKLIN_CONTRACT)
.unwrap()
.get("abi")
@@ -67,13 +67,17 @@ impl DataRestoreDriver {
Contract::new(web3.eth(), contract_eth_addr, abi.clone()),
)
};
+
+ let genesis_acc_map = get_genesis_state(web3, contract_genesis_tx_hash)?;
+ let accounts_state = FranklinAccountsState::load(genesis_acc_map.0, genesis_acc_map.1);
+
Self {
connection_pool,
web3,
- franklin_contract: contract,
+ franklin_contract,
run_updates: false,
events_state: EventsState::new(web3, contract, contract_genesis_tx_hash, eth_blocks_delta, end_eth_blocks_delta),
- accounts_state: FranklinAccountsState::new(),
+ accounts_state,
}
}
@@ -83,8 +87,7 @@ impl DataRestoreDriver {
}
pub fn load_state_from_storage(&mut self) -> Result<(), failure::Error> {
- let state = storage_interactor::get_storage_state(self.connection_pool.clone());
- if let Ok(state) = state {
+ let state = storage_interactor::get_storage_state(self.connection_pool.clone())?;
let tree_state = storage_interactor::get_tree_state(self.connection_pool.clone())?;
self.accounts_state = FranklinAccountsState::load(tree_state.0, tree_state.1);
match state {
@@ -111,12 +114,6 @@ impl DataRestoreDriver {
StorageUpdateState::None => {}
}
Ok(())
- } else {
- // If state is unknown then its empty or broken - start from beginning
- let genesis_acc_map = get_genesis_state()?;
- self.accounts_state = FranklinAccountsState::load(genesis_acc_map.0, genesis_acc_map.1);
- Ok(())
- }
}
pub fn run_state_updates(&mut self) -> Result<(), failure::Error> {
