本文整理汇总了Java中org.ethereum.util.blockchain.StandaloneBlockchain.addEthereumListener方法的典型用法代码示例。如果您正苦于以下问题:Java StandaloneBlockchain.addEthereumListener方法的具体用法?Java StandaloneBlockchain.addEthereumListener怎么用?Java StandaloneBlockchain.addEthereumListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ethereum.util.blockchain.StandaloneBlockchain
的用法示例。
在下文中一共展示了StandaloneBlockchain.addEthereumListener方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBlockOnlyIncluded
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testBlockOnlyIncluded() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
bc.submitTransaction(tx1);
Block b2 = bc.createBlock();
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Block b3_ = bc.createForkBlock(b2_);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), PENDING);
}
示例2: testOldBlockIncluded
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testOldBlockIncluded() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
for (int i = 0; i < 16; i++) {
bc.createBlock();
}
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
bc.submitTransaction(tx1);
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
bc.submitTransaction(tx1);
Block b18 = bc.createBlock();
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b18.getHash());
}
示例3: testTrackTx1
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testTrackTx1() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Block b2 = bc.createBlock();
Block b3 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
bc.submitTransaction(tx1);
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
pendingState.trackTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
Block b3_ = bc.createForkBlock(b2_);
Block b4_ = bc.createForkBlock(b3_);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b2_.getHash());
}
示例4: testPrevBlock
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testPrevBlock() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
SolidityContract contract = bc.submitNewContract("contract A {" +
" function getPrevBlockHash() returns (bytes32) {" +
" return block.blockhash(block.number - 1);" +
" }" +
"}");
bc.sendEther(bob.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Block b2 = bc.createBlock();
Block b3 = bc.createBlock();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd;
contract.callFunction("getPrevBlockHash");
bc.generatePendingTransactions();
txUpd = l.onPendingTransactionUpdate.values().iterator().next().poll();
Assert.assertArrayEquals(txUpd.getLeft().getExecutionResult(), b3.getHash());
}
示例5: testTrackTx2
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testTrackTx2() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
bc.submitTransaction(tx1);
Block b2 = bc.createBlock();
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
pendingState.trackTransaction(tx1);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b2.getHash());
Block b2_ = bc.createForkBlock(b1);
Block b3_ = bc.createForkBlock(b2_);
Assert.assertEquals(l.pollTxUpdateState(tx1), PENDING);
}
示例6: testSimple
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testSimple() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
bc.sendEther(new byte[20], BigInteger.valueOf(100000));
bc.sendEther(new byte[20], BigInteger.valueOf(100000));
bc.createBlock();
l.onBlock.poll(5, SECONDS);
Transaction tx1 = bc.createTransaction(100, new byte[32], 1000, new byte[0]);
pendingState.addPendingTransaction(tx1);
// dropped due to large nonce
Assert.assertEquals(l.pollTxUpdateState(tx1), DROPPED);
Transaction tx1_ = bc.createTransaction(0, new byte[32], 1000, new byte[0]);
pendingState.addPendingTransaction(tx1_);
// dropped due to low nonce
Assert.assertEquals(l.pollTxUpdateState(tx1_), DROPPED);
Transaction tx2 = bc.createTransaction(2, alice.getAddress(), 1000000, new byte[0]);
Transaction tx3 = bc.createTransaction(3, alice.getAddress(), 1000000, new byte[0]);
pendingState.addPendingTransaction(tx2);
pendingState.addPendingTransaction(tx3);
txUpd = l.pollTxUpdate(tx2);
Assert.assertEquals(txUpd.getMiddle(), NEW_PENDING);
Assert.assertTrue(txUpd.getLeft().isValid());
txUpd = l.pollTxUpdate(tx3);
Assert.assertEquals(txUpd.getMiddle(), NEW_PENDING);
Assert.assertTrue(txUpd.getLeft().isValid());
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000 - 100000)) > 0);
pendingState.addPendingTransaction(tx2); // double transaction submit
Assert.assertTrue(l.getQueueFor(tx2).isEmpty());
bc.createBlock();
Assert.assertEquals(l.pollTxUpdateState(tx2), PENDING);
Assert.assertEquals(l.pollTxUpdateState(tx3), PENDING);
bc.submitTransaction(tx2);
Block b3 = bc.createBlock();
txUpd = l.pollTxUpdate(tx2);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertEquals(txUpd.getRight(), b3);
Assert.assertEquals(l.pollTxUpdateState(tx3), PENDING);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000 - 100000)) > 0);
for (int i = 0; i < SystemProperties.getDefault().txOutdatedThreshold() + 1; i++) {
bc.createBlock();
txUpd = l.pollTxUpdate(tx3);
if (txUpd.getMiddle() != PENDING) break;
}
// tx3 dropped due to timeout
Assert.assertEquals(txUpd.getMiddle(), DROPPED);
Assert.assertEquals(txUpd.getLeft().getTransaction(), tx3);
Assert.assertFalse(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000 - 100000)) > 0);
}
示例7: testRebranch1
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testRebranch1() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
bc.sendEther(charlie.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Transaction tx2 = bc.createTransaction(charlie, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);;
pendingState.addPendingTransaction(tx2);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
Assert.assertEquals(l.pollTxUpdateState(tx2), NEW_PENDING);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
bc.submitTransaction(tx1);
Block b2 = bc.createBlock();
Assert.assertEquals(l.pollTxUpdateState(tx1), INCLUDED);
Assert.assertEquals(l.pollTxUpdateState(tx2), PENDING);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
bc.submitTransaction(tx2);
Block b3 = bc.createBlock();
Assert.assertEquals(l.pollTxUpdateState(tx2), INCLUDED);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
Block b2_ = bc.createForkBlock(b1);
Block b3_ = bc.createForkBlock(b2_);
bc.submitTransaction(tx2);
Block b4_ = bc.createForkBlock(b3_);
Assert.assertEquals(l.pollTxUpdateState(tx1), PENDING);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Assert.assertEquals(l.pollTxUpdateState(tx2), INCLUDED);
Assert.assertTrue(l.getQueueFor(tx2).isEmpty());
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
bc.submitTransaction(tx1);
Block b5_ = bc.createForkBlock(b4_);
Assert.assertEquals(l.pollTxUpdateState(tx1), INCLUDED);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Assert.assertTrue(l.getQueueFor(tx2).isEmpty());
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
}
示例8: testRebranch3
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testRebranch3() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
bc.sendEther(charlie.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
bc.submitTransaction(tx1);
Block b2 = bc.createBlock();
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Block b3 = bc.createBlock();
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
bc.submitTransaction(tx1);
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Block b3_ = bc.createForkBlock(b2_);
Block b4_ = bc.createForkBlock(b3_);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b2_.getHash());
Block b4 = bc.createForkBlock(b3);
Block b5 = bc.createForkBlock(b4);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b2.getHash());
}
示例9: testRejected1
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testRejected1() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
bc.sendEther(charlie.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
bc.submitTransaction(tx1);
Block b2_ = bc.createForkBlock(b1);
Assert.assertEquals(l.pollTxUpdateState(tx1), INCLUDED);
Block b2 = bc.createForkBlock(b1);
Block b3 = bc.createForkBlock(b2);
Assert.assertEquals(l.pollTxUpdateState(tx1), PENDING);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
for (int i = 0; i < 16; i++) {
bc.createBlock();
EthereumListener.PendingTransactionState state = l.pollTxUpdateState(tx1);
if (state == EthereumListener.PendingTransactionState.DROPPED) {
break;
}
if (i == 15) {
throw new RuntimeException("Transaction was not dropped");
}
}
}
示例10: testIncludedRejected
import org.ethereum.util.blockchain.StandaloneBlockchain; //导入方法依赖的package包/类
@Test
public void testIncludedRejected() throws InterruptedException {
// check INCLUDED => DROPPED state transition when a new (long) fork without
// the transaction becomes the main chain
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
bc.sendEther(charlie.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
bc.submitTransaction(tx1);
Block b2 = bc.createForkBlock(b1);
Assert.assertEquals(l.pollTxUpdateState(tx1), INCLUDED);
for (int i = 0; i < 10; i++) {
bc.createBlock();
}
Block b_ = bc.createForkBlock(b1);
for (int i = 0; i < 11; i++) {
b_ = bc.createForkBlock(b_);
}
Assert.assertEquals(l.pollTxUpdateState(tx1), DROPPED);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
}