void MixClient::resetState(std::unordered_map<Address, Account> const& _accounts, Secret const& _miner) { WriteGuard l(x_state); Guard fl(x_filtersWatches); m_filters.clear(); for (auto& i: m_specialFilters) i.second.clear(); m_watches.clear(); m_stateDB = OverlayDB(); SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB); accountState.init(); dev::eth::commit(_accounts, accountState); h256 stateRoot = accountState.root(); m_bc.reset(); m_bc.reset(new MixBlockChain(m_dbPath, stateRoot)); Block b(m_stateDB, BaseState::PreExisting, KeyPair(_miner).address()); b.sync(bc()); m_preMine = b; m_postMine = b; WriteGuard lx(x_executions); m_executions.clear(); }
void MixClient::resetState(std::map<Secret, u256> _accounts, Secret _miner) { WriteGuard l(x_state); Guard fl(x_filtersWatches); m_filters.clear(); m_watches.clear(); m_stateDB = OverlayDB(); SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB); accountState.init(); m_userAccounts.clear(); std::map<Address, Account> genesisState; for (auto account: _accounts) { KeyPair a = KeyPair(account.first); m_userAccounts.push_back(a); genesisState.insert(std::make_pair(a.address(), Account(account.second, Account::NormalCreation))); } dev::eth::commit(genesisState, static_cast<MemoryDB&>(m_stateDB), accountState); h256 stateRoot = accountState.root(); m_bc.reset(); m_bc.reset(new MixBlockChain(m_dbPath, stateRoot)); m_state = eth::State(m_stateDB, BaseState::PreExisting, KeyPair(_miner).address()); m_state.sync(bc()); m_startState = m_state; WriteGuard lx(x_executions); m_executions.clear(); }