def restart_nonce( logger: Logger, dbsession: Session, network: str, ethereum_node_url: str, ethereum_private_key: str, ethereum_gas_limit: str, ethereum_gas_price: str, ): check_good_private_key(ethereum_private_key) web3 = create_web3(ethereum_node_url) service = EthereumStoredTXService(network, dbsession, web3, ethereum_private_key, ethereum_gas_price, ethereum_gas_limit, BroadcastAccount, PreparedTransaction) service.ensure_accounts_in_sync() account = service.get_or_create_broadcast_account() txs = service.get_last_transactions(limit=1) if txs.count() > 0: raise HistoryDeleteNeeded( "Cannot reset nonce as the database contains txs for {}. Delete database to restart." .format(service.address)) # read nonce from the network and record to the database tx_count = web3.eth.getTransactionCount(service.address) account.current_nonce = tx_count logger.info("Address %s, nonce is now set to %d", service.address, account.current_nonce) dbsession.flush()
def get_last_transactions(logger: Logger, dbsession: Session, network: str, limit: int, ethereum_node_url: str, ethereum_private_key: str, ethereum_gas_limit: str, ethereum_gas_price: str, ): """Issue out a new Ethereum token.""" check_good_private_key(ethereum_private_key) web3 = create_web3(ethereum_node_url) service = EthereumStoredTXService(network, dbsession, web3, ethereum_private_key, ethereum_gas_price, ethereum_gas_limit, BroadcastAccount, PreparedTransaction) last_txs = service.get_last_transactions(limit) if last_txs.count() == 0: logger.info("No transactions yet") return [] return list(last_txs)