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;
}
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);
}
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();
}
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));
}
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));
}
Aggregations