本文整理汇总了Java中org.ethereum.listener.EthereumListenerAdapter类的典型用法代码示例。如果您正苦于以下问题:Java EthereumListenerAdapter类的具体用法?Java EthereumListenerAdapter怎么用?Java EthereumListenerAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EthereumListenerAdapter类属于org.ethereum.listener包,在下文中一共展示了EthereumListenerAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例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();
}
示例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");
}
}
示例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.");
}
}
示例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();
}
}
示例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;
}
}
});
}
示例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;
}
示例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();
}
示例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!");}
示例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());
}
示例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();
}
}
});
}
示例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");
}
}
示例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");
}
}
示例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");
}
}
示例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");
}
}