• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java EthereumListenerAdapter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.ethereum.listener.EthereumListenerAdapter的典型用法代码示例。如果您正苦于以下问题:Java EthereumListenerAdapter类的具体用法?Java EthereumListenerAdapter怎么用?Java EthereumListenerAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



EthereumListenerAdapter类属于org.ethereum.listener包,在下文中一共展示了EthereumListenerAdapter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: callConstantImpl

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
private org.ethereum.core.TransactionExecutor callConstantImpl(Transaction tx, Block block) {

        Repository repository = ((Repository) worldManager.getRepository())
                .getSnapshotTo(block.getStateRoot())
                .startTracking();

        try {
            org.ethereum.core.TransactionExecutor executor = new org.ethereum.core.TransactionExecutor
                    (tx, block.getCoinbase(), repository, worldManager.getBlockStore(),
                            programInvokeFactory, block, new EthereumListenerAdapter(), 0)
                    .withCommonConfig(commonConfig)
                    .setLocalCall(true);

            executor.init();
            executor.execute();
            executor.go();
            executor.finalization();

            return executor;
        } finally {
            repository.rollback();
        }
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:24,代码来源:EthereumImpl.java


示例2: executeTx

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
private TransactionReceipt executeTx(Transaction tx) {

        logger.trace("Apply pending state tx: {}", Hex.toHexString(tx.getHash()));

        Block best = getBestBlock();

        TransactionExecutor executor = new TransactionExecutor(
                tx, best.getCoinbase(), getRepository(),
                blockStore, programInvokeFactory, createFakePendingBlock(), new EthereumListenerAdapter(), 0)
                .withCommonConfig(commonConfig);

        executor.init();
        executor.execute();
        executor.go();
        executor.finalization();

        return executor.getReceipt();
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:19,代码来源:PendingStateImpl.java


示例3: test1

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
@Test
public void test1() throws InterruptedException {

    setupPeers();

    // A == b10, B == genesis

    final CountDownLatch semaphore = new CountDownLatch(1);
    ethereumB.addListener(new EthereumListenerAdapter() {
        @Override
        public void onBlock(Block block, List<TransactionReceipt> receipts) {
            if (block.isEqual(b10)) {
                semaphore.countDown();
            }
        }
    });

    semaphore.await(40, SECONDS);

    // check if B == b10
    if(semaphore.getCount() > 0) {
        fail("PeerB bestBlock is incorrect");
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:25,代码来源:LongSyncTest.java


示例4: relaunchTest

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
@Ignore
@Test
public void relaunchTest() throws InterruptedException {

    while (true) {
        Ethereum ethereum = EthereumFactory.createEthereum();
        Block bestBlock = ethereum.getBlockchain().getBestBlock();
        Assert.assertNotNull(bestBlock);
        final CountDownLatch latch = new CountDownLatch(1);
        ethereum.addListener(new EthereumListenerAdapter() {
            int counter = 0;
            @Override
            public void onBlock(Block block, List<TransactionReceipt> receipts) {
                counter++;
                if (counter > 1100) latch.countDown();
            }
        });
        System.out.println("### Waiting for some blocks to be imported...");
        latch.await();
        System.out.println("### Closing Ethereum instance");
        ethereum.close();
        Thread.sleep(5000);
        System.out.println("### Closed.");
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:26,代码来源:CloseTest.java


示例5: createCallTxAndExecute

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
public TransactionReceipt createCallTxAndExecute(CallArguments args, Block block, Repository repository, BlockStore blockStore) throws Exception {
    BinaryCallArguments bca = new BinaryCallArguments();
    bca.setArguments(args);
    Transaction tx = CallTransaction.createRawTransaction(0,
            bca.gasPrice,
            bca.gasLimit,
            bca.toAddress,
            bca.value,
            bca.data);

    // put mock signature if not present
    if (tx.getSignature() == null) {
        tx.sign(ECKey.fromPrivate(new byte[32]));
    }

    try {
        TransactionExecutor executor = new TransactionExecutor
                (tx, block.getCoinbase(), repository, blockStore,
                        programInvokeFactory, block, new EthereumListenerAdapter(), 0)
                .withCommonConfig(commonConfig)
                .setLocalCall(true);

        executor.init();
        executor.execute();
        executor.go();
        executor.finalization();

        return executor.getReceipt();
    } finally {
        repository.rollback();
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:33,代码来源:JsonRpcImpl.java


示例6: setEthereumListener

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
@Autowired
public void setEthereumListener(CompositeEthereumListener listener) {
    if (!flushAfterSyncDone) return;
    listener.addListener(new EthereumListenerAdapter() {
        @Override
        public void onSyncDone(SyncState state) {
            if (state == SyncState.COMPLETE) {
                logger.info("DbFlushManager: long sync done, flushing each block now");
                syncDone = true;
            }
        }
    });
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:14,代码来源:DbFlushManager.java


示例7: getBlockchain

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
@Override
public BlockchainImpl getBlockchain() {
    if (blockchain == null) {
        blockchain = createBlockchain(genesis);
        blockchain.setMinerCoinbase(coinbase);
        addEthereumListener(new EthereumListenerAdapter() {
            @Override
            public void onBlock(BlockSummary blockSummary) {
                lastSummary = blockSummary;
            }
        });
    }
    return blockchain;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:15,代码来源:StandaloneBlockchain.java


示例8: onSyncDone

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
@Override
public void onSyncDone() {
    ethereum.addListener(new EthereumListenerAdapter() {
        // listening here when the PendingState is updated with new transactions
        @Override
        public void onPendingTransactionsReceived(List<Transaction> transactions) {
            for (Transaction tx : transactions) {
                PendingStateSample.this.onPendingTransactionReceived(tx);
            }
        }

        // when block arrives look for our included transactions
        @Override
        public void onBlock(Block block, List<TransactionReceipt> receipts) {
            PendingStateSample.this.onBlock(block, receipts);
        }
    });

    new Thread("PendingStateSampleThread") {
        @Override
        public void run() {
            try {
                sendTransactions();
            } catch (Exception e) {
                logger.error("Error while sending transactions", e);
            }
        }
    }.start();
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:30,代码来源:PendingStateSample.java


示例9: onSyncDone

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
@Override
public void onSyncDone() throws Exception {
    ethereum.addListener(new EthereumListenerAdapter() {
        // when block arrives look for our included transactions
        @Override
        public void onBlock(Block block, List<TransactionReceipt> receipts) {
            SendTransaction.this.onBlock(block, receipts);
        }
    });


    String toAddress = "";
    logger.info("Sending transaction to net and waiting for inclusion");
    sendTxAndWait(Hex.decode(toAddress), new byte[0]);
    logger.info("Transaction included!");}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:16,代码来源:SendTransaction.java


示例10: BlockchainImpl

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
public BlockchainImpl(final BlockStore blockStore, final Repository repository) {
    this.blockStore = blockStore;
    this.repository = repository;
    this.adminInfo = new AdminInfo();
    this.listener = new EthereumListenerAdapter();
    this.parentHeaderValidator = null;
    this.transactionStore = new TransactionStore(new HashMapDB());
    this.eventDispatchThread = EventDispatchThread.getDefault();
    this.programInvokeFactory = new ProgramInvokeFactoryImpl();
    initConst(SystemProperties.getDefault());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:12,代码来源:BlockchainImpl.java


示例11: init

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
@PostConstruct
void init() {
    System.out.println("========= init");
    worldManager.addListener(new EthereumListenerAdapter() {
        @Override
        public void onHandShakePeer(Channel channel, HelloMessage helloMessage) {
            System.out.println("========= onHandShakePeer");
            if (!isAlive()) {
                start();
            }
        }
    });
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:14,代码来源:ShhLongRun.java


示例12: test2

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
@Test
public void test2() throws InterruptedException {

    SysPropConfigA.eth62 = new Eth62() {

        @Override
        protected void processGetBlockBodies(GetBlockBodiesMessage msg) {
            List<byte[]> bodies = Arrays.asList(
                    mainB1B10.get(0).getEncodedBody()
            );

            BlockBodiesMessage response = new BlockBodiesMessage(bodies);
            sendMessage(response);
        }
    };

    setupPeers();

    // A == b10, B == genesis

    final CountDownLatch semaphoreDisconnect = new CountDownLatch(1);
    ethereumA.addListener(new EthereumListenerAdapter() {
        @Override
        public void onRecvMessage(Channel channel, Message message) {
            if (message instanceof DisconnectMessage) {
                semaphoreDisconnect.countDown();
            }
        }
    });

    semaphoreDisconnect.await(10, SECONDS);

    // check if peer was dropped
    if(semaphoreDisconnect.getCount() > 0) {
        fail("PeerA is not dropped");
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:38,代码来源:LongSyncTest.java


示例13: setupPeers

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
private void setupPeers(Block best) throws InterruptedException {

        ethereumA = EthereumFactory.createEthereum(SysPropConfigA.class);

        Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain();
        for (Block b : mainB1B10) {
            ImportResult result = blockchainA.tryToConnect(b);
            Assert.assertEquals(result, ImportResult.IMPORTED_BEST);
            if (b.equals(best)) break;
        }

        // A == best

        ethereumB = EthereumFactory.createEthereum(SysPropConfigB.props, SysPropConfigB.class);

        ethereumA.addListener(new EthereumListenerAdapter() {
            @Override
            public void onEthStatusUpdated(Channel channel, StatusMessage statusMessage) {
                ethA = (EthHandler) channel.getEthHandler();
            }
        });

        final CountDownLatch semaphore = new CountDownLatch(1);

        ethereumB.addListener(new EthereumListenerAdapter() {
            @Override
            public void onPeerAddedToSyncPool(Channel peer) {
                semaphore.countDown();
            }
        });

        ethereumB.connect(nodeA);

        semaphore.await(10, SECONDS);
        if(semaphore.getCount() > 0) {
            fail("Failed to set up peers");
        }
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:39,代码来源:LongSyncTest.java


示例14: test1

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
@Test
public void test1() throws InterruptedException {

    setupPeers();

    // A == B == genesis

    Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain();

    for (Block b : mainB1B10) {
        blockchainA.tryToConnect(b);
    }

    // A == b10, B == genesis

    final CountDownLatch semaphore = new CountDownLatch(1);
    ethereumB.addListener(new EthereumListenerAdapter() {
        @Override
        public void onBlock(Block block, List<TransactionReceipt> receipts) {
            if (block.isEqual(b10)) {
                semaphore.countDown();
            }
        }
    });

    ethA.sendNewBlock(b10);

    semaphore.await(10, SECONDS);

    // check if B == b10
    if(semaphore.getCount() > 0) {
        fail("PeerB bestBlock is incorrect");
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:35,代码来源:ShortSyncTest.java


示例15: test2

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
@Test
public void test2() throws InterruptedException {

    setupPeers();

    // A == B == genesis

    Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain();

    for (Block b : forkB1B5B8_) {
        blockchainA.tryToConnect(b);
    }

    // A == b8', B == genesis

    final CountDownLatch semaphore = new CountDownLatch(1);
    ethereumB.addListener(new EthereumListenerAdapter() {
        @Override
        public void onBlock(Block block, List<TransactionReceipt> receipts) {
            if (block.isEqual(b8_)) {
                semaphore.countDown();
            }
        }
    });

    ethA.sendNewBlock(b8_);

    semaphore.await(10, SECONDS);

    // check if B == b8'
    if(semaphore.getCount() > 0) {
        fail("PeerB bestBlock is incorrect");
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:35,代码来源:ShortSyncTest.java


示例16: setupPeers

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
private void setupPeers() throws InterruptedException {

        ethereumA = EthereumFactory.createEthereum(SysPropConfigA.props, SysPropConfigA.class);
        ethereumB = EthereumFactory.createEthereum(SysPropConfigB.props, SysPropConfigB.class);

        ethereumA.addListener(new EthereumListenerAdapter() {
            @Override
            public void onEthStatusUpdated(Channel channel, StatusMessage statusMessage) {
                ethA = (EthHandler) channel.getEthHandler();
            }
        });

        final CountDownLatch semaphore = new CountDownLatch(1);

        ethereumB.addListener(new EthereumListenerAdapter() {
            @Override
            public void onPeerAddedToSyncPool(Channel peer) {
                semaphore.countDown();
            }
        });

        ethereumB.connect(nodeA);

        semaphore.await(10, SECONDS);
        if(semaphore.getCount() > 0) {
            fail("Failed to set up peers");
        }
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:29,代码来源:ShortSyncTest.java


示例17: TransactionExecutor

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
public TransactionExecutor(RskSystemProperties config, Transaction tx, int txindex, byte[] coinbase, Repository track, BlockStore blockStore, ReceiptStore receiptStore,
                           ProgramInvokeFactory programInvokeFactory, Block executionBlock) {
    this(config, tx, txindex, coinbase, track, blockStore, receiptStore, programInvokeFactory, executionBlock, new EthereumListenerAdapter(), 0);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:5,代码来源:TransactionExecutor.java


示例18: processBlock

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
public void processBlock( Block block, Block parent) {
    latestStateRootHash = null;
    totalGasUsed = 0;
    totalPaidFees = BigInteger.ZERO;
    txReceipts = new ArrayList<>();

    //Repository originalRepo  = ((Repository) ethereum.getRepository()).getSnapshotTo(parent.getStateRoot());

    // This creates a snapshot WITHOUT history of the current "parent" reponsitory.
    Repository originalRepo  = repository.getSnapshotTo(parent.getStateRoot());

    Repository track = originalRepo.startTracking();

    // Repository track = new RepositoryTrack((Repository)ethereum.getRepository());

    // this variable is set before iterating transactions in case list is empty
    latestStateRootHash = originalRepo.getRoot();

    // RSK test, remove
    String stateHash1 = Hex.toHexString(blockchain.getBestBlock().getStateRoot());
    String stateHash2 = Hex.toHexString(repository.getRoot());
    if (stateHash1.compareTo(stateHash2) != 0) {
        logger.error("Strange state in block {} {}", block.getNumber(), Hex.toHexString(block.getHash()));
        panicProcessor.panic("minerserver", String.format("Strange state in block %d %s", block.getNumber(), Hex.toHexString(block.getHash())));
    }

    int txindex = 0;

    for (Transaction tx : block.getTransactionsList()) {

        TransactionExecutor executor = new TransactionExecutor(ConfigHelper.CONFIG, tx, txindex++, block.getCoinbase(),
                track, blockStore, blockchain.getReceiptStore(),
                programInvokeFactory, block, new EthereumListenerAdapter(), totalGasUsed);

        executor.init();
        executor.execute();
        executor.go();
        executor.finalization();

        long gasUsed = executor.getGasUsed();
        BigInteger paidFees = executor.getPaidFees();
        totalGasUsed += gasUsed;
        totalPaidFees = totalPaidFees.add(paidFees);

        track.commit();

        TransactionReceipt receipt = new TransactionReceipt();
        receipt.setGasUsed(gasUsed);
        receipt.setCumulativeGas(totalGasUsed);
        latestStateRootHash = originalRepo.getRoot();
        receipt.setPostTxState(latestStateRootHash);
        receipt.setTxStatus(executor.getReceipt().isSuccessful());
        receipt.setStatus(executor.getReceipt().getStatus());
        receipt.setTransaction(tx);
        receipt.setLogInfoList(executor.getVMLogs());

        txReceipts.add(receipt);

    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:61,代码来源:MinerHelper.java


示例19: createBlockchain

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
public static BlockChainImpl createBlockchain(Genesis genesis) {
    IndexedBlockStore blockStore = new IndexedBlockStore(ConfigHelper.CONFIG);
    blockStore.init(new HashMap<>(), new HashMapDB(), null);

    Repository repository = new RepositoryImpl(ConfigHelper.CONFIG, new TrieStoreImpl(new HashMapDB()));

    EthereumListenerAdapter listener = new EthereumListenerAdapter();

    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);

    BlockChainImpl blockchain = new BlockChainImpl(
            ConfigHelper.CONFIG, repository,
            blockStore,
            receiptStore,
            null,
            listener,
            new AdminInfo(),
            new DummyBlockValidator()
    );

    blockchain.setNoValidation(true);

    PendingStateImpl pendingState = new PendingStateImpl(ConfigHelper.CONFIG, blockchain, repository, null, null, listener, 10, 100);

    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).getAccountState().getBalance());
    }

    track.commit();

    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();

    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);

    blockchain.setBestBlock(genesis);
    blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty());

    return blockchain;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:47,代码来源:ImportLightTest.java


示例20: syncUnsecure

import org.ethereum.listener.EthereumListenerAdapter; //导入依赖的package包/类
private void syncUnsecure(BlockHeader pivot) {
        byte[] pivotStateRoot = pivot.getStateRoot();
        TrieNodeRequest request = new TrieNodeRequest(TrieNodeType.STATE, pivotStateRoot);
        nodesQueue.add(request);
        logger.info("FastSync: downloading state trie at pivot block: " + pivot.getShortDescr());

        setSyncStage(UNSECURE);

        retrieveLoop();

        logger.info("FastSync: state trie download complete! (Nodes count: state: " + stateNodesCnt + ", storage: " +storageNodesCnt + ", code: " +codeNodesCnt + ")");
        last = 0;
        logStat();

        logger.info("FastSync: downloading 256 blocks prior to pivot block (" + pivot.getShortDescr() + ")");
        downloader.startImporting(pivot.getHash(), 260);
        downloader.waitForStop();

        logger.info("FastSync: complete downloading 256 blocks prior to pivot block (" + pivot.getShortDescr() + ")");

        blockchain.setBestBlock(blockStore.getBlockByHash(pivot.getHash()));

        logger.info("FastSync: proceeding to regular sync...");

        final CountDownLatch syncDoneLatch = new CountDownLatch(1);
        listener.addListener(new EthereumListenerAdapter() {
            @Override
            public void onSyncDone(SyncState state) {
                syncDoneLatch.countDown();
            }
        });
        syncManager.initRegularSync(UNSECURE);
        logger.info("FastSync: waiting for regular sync to reach the blockchain head...");

//        try {
//            syncDoneLatch.await();
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }

        blockchainDB.put(FASTSYNC_DB_KEY_PIVOT, pivot.getEncoded());
        dbFlushManager.commit();
        dbFlushManager.flush();

        logger.info("FastSync: regular sync reached the blockchain head.");
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:47,代码来源:FastSyncManager.java



注:本文中的org.ethereum.listener.EthereumListenerAdapter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OpTable类代码示例发布时间:2022-05-22
下一篇:
Java Languages类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap