@Override public void setSender(ECKey senderPrivateKey) { txSender = senderPrivateKey; if (!getBlockchain().getRepository().isExist(senderPrivateKey.getAddress())) { Repository repository = getBlockchain().getRepository(); Repository track = repository.startTracking(); track.createAccount(senderPrivateKey.getAddress()); track.commit(); } }
private BlockchainImpl createBlockchain(Genesis genesis) { IndexedBlockStore blockStore = new IndexedBlockStore(); blockStore.init(new HashMapDB(), new HashMapDB()); Repository repository = new RepositoryImpl(new HashMapDB(), new HashMapDB()); ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl(); EthereumListenerAdapter listener = new EthereumListenerAdapter(); BlockchainImpl blockchain = new BlockchainImpl(blockStore, repository); blockchain.setParentHeaderValidator(new DependentBlockHeaderRuleAdapter()); blockchain.setProgramInvokeFactory(programInvokeFactory); programInvokeFactory.setBlockchain(blockchain); blockchain.byTest = true; PendingStateImpl pendingState = new PendingStateImpl(listener, blockchain); pendingState.init(); pendingState.setBlockchain(blockchain); blockchain.setPendingState(pendingState); Repository track = repository.startTracking(); for (ByteArrayWrapper key : genesis.getPremine().keySet()) { track.createAccount(key.getData()); track.addBalance(key.getData(), genesis.getPremine().get(key).getBalance()); } for (Pair<byte[], BigInteger> acc : initialBallances) { track.createAccount(acc.getLeft()); track.addBalance(acc.getLeft(), acc.getRight()); } track.commit(); blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true); blockchain.setBestBlock(genesis); blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty()); return blockchain; }