Search in sources :

Example 61 with Transaction

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);
}
Also used : ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction)

Example 62 with Transaction

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;
}
Also used : Account(org.ethereum.core.Account) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Example 63 with Transaction

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));
    }
}
Also used : Transaction(org.ethereum.core.Transaction) Keccak256(co.rsk.crypto.Keccak256)

Example 64 with Transaction

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;
}
Also used : Transaction(org.ethereum.core.Transaction) BigInteger(java.math.BigInteger) LinkedList(java.util.LinkedList)

Example 65 with Transaction

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;
}
Also used : Coin(co.rsk.core.Coin) Random(java.util.Random) Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256)

Aggregations

Transaction (org.ethereum.core.Transaction)131 Test (org.junit.Test)82 BigInteger (java.math.BigInteger)33 Coin (co.rsk.core.Coin)23 Account (org.ethereum.core.Account)20 ArrayList (java.util.ArrayList)17 Block (org.ethereum.core.Block)17 RskAddress (co.rsk.core.RskAddress)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Repository (org.ethereum.core.Repository)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 AccountState (org.ethereum.core.AccountState)10 RemascTransaction (co.rsk.remasc.RemascTransaction)9 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)9 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)8 ECKey (org.ethereum.crypto.ECKey)8 Keccak256 (co.rsk.crypto.Keccak256)7 AccountBuilder (co.rsk.test.builders.AccountBuilder)7 DslParser (co.rsk.test.dsl.DslParser)6 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)6