use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class FreeBlock method getTransactionsEncoded.
private byte[] getTransactionsEncoded() {
byte[][] transactionsEncoded = new byte[transactionsList.size()][];
int i = 0;
for (Transaction tx : transactionsList) {
transactionsEncoded[i] = tx.getEncoded();
++i;
}
return RLP.encodeList(transactionsEncoded);
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class ImmutableTransactionTest method createImmutableTransaction.
private static Transaction createImmutableTransaction() {
Account sender = new AccountBuilder().name("sender").build();
Account receiver = new AccountBuilder().name("receiver").build();
Transaction tx = new TransactionBuilder().sender(sender).receiver(receiver).value(BigInteger.TEN).nonce(2).immutable().build();
return tx;
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class NodeMessageHandler method relayTransactions.
private void relayTransactions(@Nonnull MessageChannel sender, List<Transaction> acceptedTxs) {
for (Transaction tx : acceptedTxs) {
Keccak256 txHash = tx.getHash();
transactionNodeInformation.addTransactionToNode(txHash, sender.getPeerNodeID());
final Set<NodeID> nodesToSkip = new HashSet<>(transactionNodeInformation.getNodesByTransaction(txHash));
final Set<NodeID> newNodes = channelManager.broadcastTransaction(tx, nodesToSkip);
newNodes.forEach(nodeID -> transactionNodeInformation.addTransactionToNode(txHash, nodeID));
}
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class TxsPerAccount method readyToBeSent.
List<Transaction> readyToBeSent(BigInteger accountNonce) {
if (nextNonce == null || nextNonce.compareTo(accountNonce) < 0) {
nextNonce = accountNonce;
}
List<Transaction> ret = new LinkedList<>();
for (Transaction tx : txs) {
BigInteger nonce = new BigInteger(1, tx.getNonce());
if (nextNonce.compareTo(nonce) == 0) {
nextNonce = nonce.add(BigInteger.valueOf(1));
ret.add(tx);
}
}
return ret;
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class Tx method create.
public static Transaction create(RskSystemProperties config, long value, long gaslimit, long gasprice, long nonce, long data, long sender) {
Random r = new Random(sender);
Transaction transaction = Mockito.mock(Transaction.class);
Mockito.when(transaction.getValue()).thenReturn(new Coin(BigInteger.valueOf(value)));
Mockito.when(transaction.getGasLimit()).thenReturn(BigInteger.valueOf(gaslimit).toByteArray());
Mockito.when(transaction.getGasLimitAsInteger()).thenReturn(BigInteger.valueOf(gaslimit));
Mockito.when(transaction.getGasPrice()).thenReturn(Coin.valueOf(gasprice));
Mockito.when(transaction.getNonce()).thenReturn(BigInteger.valueOf(nonce).toByteArray());
Mockito.when(transaction.getNonceAsInteger()).thenReturn(BigInteger.valueOf(nonce));
byte[] returnSenderBytes = new byte[20];
r.nextBytes(returnSenderBytes);
RskAddress returnSender = new RskAddress(returnSenderBytes);
byte[] returnReceiveAddressBytes = new byte[20];
r.nextBytes(returnReceiveAddressBytes);
RskAddress returnReceiveAddress = new RskAddress(returnReceiveAddressBytes);
Mockito.when(transaction.getSender()).thenReturn(returnSender);
Mockito.when(transaction.getHash()).thenReturn(new Keccak256(TestUtils.randomBytes(32)));
Mockito.when(transaction.acceptTransactionSignature(config.getBlockchainConfig().getCommonConstants().getChainId())).thenReturn(Boolean.TRUE);
Mockito.when(transaction.getReceiveAddress()).thenReturn(returnReceiveAddress);
ArrayList<Byte> bytes = new ArrayList();
long amount = 21000;
if (data != 0) {
data /= 2;
for (int i = 0; i < data / 4; i++) {
bytes.add((byte) 0);
amount += 4;
}
for (int i = 0; i < data / 68; i++) {
bytes.add((byte) 1);
amount += 68;
}
}
int n = bytes.size();
byte[] b = new byte[n];
for (int i = 0; i < n; i++) {
b[i] = bytes.get(i);
}
Mockito.when(transaction.getData()).thenReturn(b);
Mockito.when(transaction.transactionCost(eq(config), any(Block.class))).thenReturn(amount);
return transaction;
}
Aggregations