当前位置: 首页>>代码示例>>Java>>正文


Java StandaloneBlockchain.submitTransaction方法代码示例

本文整理汇总了Java中org.ethereum.util.blockchain.StandaloneBlockchain.submitTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java StandaloneBlockchain.submitTransaction方法的具体用法?Java StandaloneBlockchain.submitTransaction怎么用?Java StandaloneBlockchain.submitTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ethereum.util.blockchain.StandaloneBlockchain的用法示例。


在下文中一共展示了StandaloneBlockchain.submitTransaction方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:26,代码来源:PendingStateTest.java

示例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());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:35,代码来源:PendingStateTest.java

示例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());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:33,代码来源:PendingStateTest.java

示例4: 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);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:30,代码来源:PendingStateTest.java

示例5: 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);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:72,代码来源:PendingStateTest.java

示例6: 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);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:65,代码来源:PendingStateTest.java

示例7: 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());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:49,代码来源:PendingStateTest.java

示例8: 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");
        }
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:44,代码来源:PendingStateTest.java

示例9: 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());
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:43,代码来源:PendingStateTest.java


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