Search in sources :

Example 11 with RemascTransaction

use of co.rsk.remasc.RemascTransaction in project rskj by rsksmart.

the class BlockChainImplTest method getBlockWithOneTransaction.

private Block getBlockWithOneTransaction() {
    Block bestBlock = blockChain.getBestBlock();
    RepositorySnapshot repository = objects.getRepositoryLocator().snapshotAt(bestBlock.getHeader());
    String toAddress = ByteUtil.toHexString(catKey.getAddress());
    BigInteger nonce = repository.getNonce(new RskAddress(cowKey.getAddress()));
    Transaction tx = Transaction.builder().nonce(nonce).gasPrice(BigInteger.ONE).gasLimit(BigInteger.valueOf(21000)).destination(Hex.decode(toAddress)).chainId(config.getNetworkConstants().getChainId()).value(BigInteger.TEN).build();
    tx.sign(cowKey.getPrivKeyBytes());
    List<Transaction> txs = java.util.Arrays.asList(tx, new RemascTransaction(bestBlock.getNumber() + 1));
    List<BlockHeader> uncles = new ArrayList<>();
    Block block = new BlockGenerator().createChildBlock(bestBlock, txs, uncles, 1, bestBlock.getMinimumGasPrice().asBigInteger());
    blockExecutor.executeAndFill(block, bestBlock.getHeader());
    return block;
}
Also used : RepositorySnapshot(co.rsk.db.RepositorySnapshot) RemascTransaction(co.rsk.remasc.RemascTransaction) RemascTransaction(co.rsk.remasc.RemascTransaction) RskAddress(co.rsk.core.RskAddress) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator)

Example 12 with RemascTransaction

use of co.rsk.remasc.RemascTransaction in project rskj by rsksmart.

the class BlockFactory method parseTxs.

private static List<Transaction> parseTxs(RLPList txTransactions) {
    List<Transaction> parsedTxs = new ArrayList<>();
    for (int i = 0; i < txTransactions.size(); i++) {
        RLPElement transactionRaw = txTransactions.get(i);
        Transaction tx = new ImmutableTransaction(transactionRaw.getRLPData());
        if (tx.isRemascTransaction(i, txTransactions.size())) {
            // It is the remasc transaction
            tx = new RemascTransaction(transactionRaw.getRLPData());
        }
        parsedTxs.add(tx);
    }
    return Collections.unmodifiableList(parsedTxs);
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) RemascTransaction(co.rsk.remasc.RemascTransaction) RLPElement(org.ethereum.util.RLPElement) ArrayList(java.util.ArrayList)

Example 13 with RemascTransaction

use of co.rsk.remasc.RemascTransaction in project rskj by rsksmart.

the class BlockTxSignatureCache method getSender.

@Override
public RskAddress getSender(Transaction transaction) {
    if (transaction instanceof RemascTransaction) {
        return RemascTransaction.REMASC_ADDRESS;
    }
    RskAddress address = addressesCache.get(transaction);
    if (address != null) {
        return address;
    }
    if (internalCache.containsTx(transaction)) {
        RskAddress sender = internalCache.getSender(transaction);
        addressesCache.put(transaction, sender);
        return sender;
    }
    return transaction.getSender();
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) RskAddress(co.rsk.core.RskAddress)

Example 14 with RemascTransaction

use of co.rsk.remasc.RemascTransaction in project rskj by rsksmart.

the class BlockValidatorTest method remascTx.

@Test
public void remascTx() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    List<Transaction> txs = new ArrayList<>();
    byte chainId = config.getNetworkConstants().getChainId();
    Transaction tx = Transaction.builder().nonce(BigInteger.ZERO).gasPrice(BigInteger.valueOf(12L)).gasLimit(BigInteger.TEN).destination(Hex.decode("0000000000000000000000000000000000000006")).chainId(chainId).value(BigInteger.ZERO).build();
    tx.sign(new byte[] {});
    txs.add(tx);
    txs.add(new RemascTransaction(BigInteger.ONE.longValue()));
    Block block = new BlockBuilder(null, null, null).parent(genesis).transactions(txs).build();
    BlockValidatorImpl validator = new BlockValidatorBuilder().addRemascValidationRule().build();
    Assert.assertTrue(validator.isValid(block));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) RemascTransaction(co.rsk.remasc.RemascTransaction) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 15 with RemascTransaction

use of co.rsk.remasc.RemascTransaction in project rskj by rsksmart.

the class TransactionPoolImplTest method remascTxIsReceivedAndShouldntBeInCache.

@Test
public void remascTxIsReceivedAndShouldntBeInCache() {
    RemascTransaction tx = new RemascTransaction(10);
    transactionPool.addTransaction(tx);
    Assert.assertFalse(signatureCache.containsTx(tx));
    verify(signatureCache, times(0)).storeSender(tx);
    signatureCache.storeSender(tx);
    Assert.assertFalse(signatureCache.containsTx(tx));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) Test(org.junit.Test)

Aggregations

RemascTransaction (co.rsk.remasc.RemascTransaction)18 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 RskAddress (co.rsk.core.RskAddress)6 BigInteger (java.math.BigInteger)5 Transaction (org.ethereum.core.Transaction)5 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)3 Coin (co.rsk.core.Coin)3 Keccak256 (co.rsk.crypto.Keccak256)3 Block (org.ethereum.core.Block)3 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)2 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)2 RepositorySnapshot (co.rsk.db.RepositorySnapshot)2 BlockBuilder (co.rsk.test.builders.BlockBuilder)2 IOException (java.io.IOException)2 RLPElement (org.ethereum.util.RLPElement)2 BlockUnclesValidationRule (co.rsk.validators.BlockUnclesValidationRule)1 Random (java.util.Random)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)1