@Bean StoreBuilder storeBuilder(DefaultConfig defaultConfig) { return new StoreBuilder(defaultConfig); }
private Contract getContract(ContractId contractId) { try { // get System Contracts // TODO remove this // TODO Check System Contract ContractMeta contractMeta = ContractClassLoader.loadContractById( storeBuilder.getConfig().getContractPath(), contractId); return contractMeta.getContract().getDeclaredConstructor().newInstance(); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new FailedOperationException(e); } }
public TransactionStore buildTxStore(BranchId branchId) { return new TransactionStore(getDbSource(branchId + "/txs")); }
blockStore = storeBuilder.buildBlockStore(genesisBlock.getBranchId()); transactionStore = storeBuilder.buildTxStore(genesisBlock.getBranchId()); metaStore = storeBuilder.buildMetaStore(genesisBlock.getBranchId()); stateStore = storeBuilder.buildStateStore(genesisBlock.getBranchId()); transactionReceiptStore = storeBuilder.buildTransactionReciptStore( genesisBlock.getBranchId());
@Test public void executorTest() { CoinContract contract = new CoinContract(); Runtime runtime = new Runtime<>( new StateStore<>(new HashMapDbSource()), new TransactionReceiptStore(new HashMapDbSource()) ); runtime.addContract(ContractId.of("c10e873655becf550c4aece75a091f4553d6202d"), contract); // Block Store // Blockchain Runtime StoreBuilder builder = new StoreBuilder(new DefaultConfig(false)); BlockStore store = builder.buildBlockStore(BRANCH_ID); MetaStore meta = builder.buildMetaStore(BRANCH_ID); BlockExecutor ex = new BlockExecutor(store, meta, runtime); // BlockStore add genesis block and other ex.runExecuteBlocks(); } }
@Test public void shouldBeBuiltMetaStore() { BlockHusk block = BlockChainTestUtils.genesisBlock(); StoreBuilder builder = new StoreBuilder(new DefaultConfig()); MetaStore store = builder.buildMetaStore(BRANCH_ID); store.setBestBlock(block); assertThat(store.contains(BlockchainMetaInfo.BRANCH.toString())).isTrue(); assertThat(store.getBestBlockHash()).isEqualTo(block.getHash()); }
public static PeerTable createPeerTable(int port) { Peer owner = Peer.valueOf(NODE_URI_PREFIX + port); PeerTable peerTable = new KademliaPeerTable(owner, storeBuilder.buildPeerStore()); List<String> seedList = Collections.singletonList(NODE_URI_PREFIX + 32918); peerTable.setSeedPeerList(seedList); return peerTable; } }
@Test public void buildBlockStore() { BlockHusk block = BlockChainTestUtils.genesisBlock(); BlockStore store = builder.buildBlockStore(BRANCH_ID); store.put(block.getHash(), block); assert store.contains(block.getHash()); assert store.get(block.getHash()).equals(block); }
@Test public void buildTxStore() { TransactionHusk tx = BlockChainTestUtils.createTransferTxHusk(); TransactionStore store = builder.buildTxStore(BRANCH_ID); store.put(tx.getHash(), tx); assert store.contains(tx.getHash()); assert store.get(tx.getHash()).equals(tx); }
@Bean PeerTable peerTable(Wallet wallet, StoreBuilder storeBuilder) { Peer owner = Peer.valueOf(wallet.getNodeId(), nodeProperties.getGrpc().getHost(), nodeProperties.getGrpc().getPort()); PeerStore peerStore = storeBuilder.buildPeerStore(); PeerTable peerTable = new KademliaPeerTable(owner, peerStore); peerTable.setSeedPeerList(nodeProperties.getSeedPeerList()); return peerTable; }
public static StoreBuilder getProdMockBuilder() { return new StoreBuilder(new ProdDefaultConfig()); }
@Test public void buildPeerStore() { Peer peer = Peer.valueOf("ynode://75bff16c@127.0.0.1:32918"); PeerStore store = builder.buildPeerStore(); store.put(peer.getPeerId(), peer); assert store.contains(peer.getPeerId()); assert store.get(peer.getPeerId()).equals(peer); } }
public PeerStore buildPeerStore() { return new PeerStore(getDbSource("peers")); }
@Before public void setUp() { StoreBuilder builder = new StoreBuilder(config); this.branchConfig = new BranchConfiguration(builder); this.peerHandlerGroup = new SimplePeerHandlerGroup(PeerHandlerMock.factory); }
public TransactionReceiptStore buildTransactionReciptStore(BranchId branchId) { return new TransactionReceiptStore(getDbSource(branchId + "/txreceipt")); }
@Before public void setUp() { builder = new StoreBuilder(new DefaultConfig()); }
public StateStore buildStateStore(BranchId branchId) { return new StateStore(getDbSource(branchId + "/state")); }
public static BlockChain createBlockChain(boolean isProductionMode) { StoreBuilder storeBuilder; if (isProductionMode) { storeBuilder = StoreTestUtils.getProdMockBuilder(); } else { storeBuilder = new StoreBuilder(new DefaultConfig()); } return BlockChainBuilder.Builder() .addGenesis(genesis) .setStoreBuilder(storeBuilder) .build(); }
public BlockStore buildBlockStore(BranchId branchId) { return new BlockStore(getDbSource(branchId + "/blocks")); }
public MetaStore buildMetaStore(BranchId branchId) { MetaStore store = new MetaStore(getDbSource(branchId + "/meta")); store.put(BlockchainMetaInfo.BRANCH.toString(), branchId.toString()); return store; }