Search in sources :

Example 51 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class EthModuleWalletEnabled method sendTransaction.

@Override
public synchronized String sendTransaction(Web3.CallArguments args) {
    Account account = this.getAccount(args.from);
    String s = null;
    try {
        if (account == null) {
            throw new JsonRpcInvalidParamException("From address private key could not be found in this node");
        }
        String toAddress = args.to != null ? Hex.toHexString(stringHexToByteArray(args.to)) : null;
        BigInteger value = args.value != null ? TypeConverter.stringNumberAsBigInt(args.value) : BigInteger.ZERO;
        BigInteger gasPrice = args.gasPrice != null ? TypeConverter.stringNumberAsBigInt(args.gasPrice) : BigInteger.ZERO;
        BigInteger gasLimit = args.gas != null ? TypeConverter.stringNumberAsBigInt(args.gas) : BigInteger.valueOf(GasCost.TRANSACTION_DEFAULT);
        if (args.data != null && args.data.startsWith("0x")) {
            args.data = args.data.substring(2);
        }
        synchronized (transactionPool) {
            BigInteger accountNonce = args.nonce != null ? TypeConverter.stringNumberAsBigInt(args.nonce) : transactionPool.getRepository().getNonce(account.getAddress());
            Transaction tx = Transaction.create(config, toAddress, value, accountNonce, gasPrice, gasLimit, args.data);
            tx.sign(account.getEcKey().getPrivKeyBytes());
            eth.submitTransaction(tx.toImmutableTransaction());
            s = tx.getHash().toJsonString();
        }
        return s;
    } finally {
        LOGGER.debug("eth_sendTransaction({}): {}", args, s);
    }
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) BigInteger(java.math.BigInteger) JsonRpcInvalidParamException(org.ethereum.rpc.exception.JsonRpcInvalidParamException)

Example 52 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class TxPoolModuleImpl method serializeTransactions.

private JsonNode serializeTransactions(Map<RskAddress, Map<BigInteger, List<Transaction>>> groupedTransactions, Function<Transaction, JsonNode> txSerializer) {
    Map<String, JsonNode> senderProps = new HashMap<>();
    for (Map.Entry<RskAddress, Map<BigInteger, List<Transaction>>> entrySender : groupedTransactions.entrySet()) {
        Map<String, JsonNode> nonceProps = new HashMap<>();
        for (Map.Entry<BigInteger, List<Transaction>> entryNonce : entrySender.getValue().entrySet()) {
            ArrayNode txsNodes = jsonNodeFactory.arrayNode();
            for (Transaction tx : entryNonce.getValue()) {
                txsNodes.add(txSerializer.apply(tx));
            }
            nonceProps.put(entryNonce.getKey().toString(), txsNodes);
        }
        senderProps.put(entrySender.getKey().toString(), jsonNodeFactory.objectNode().setAll(nonceProps));
    }
    return jsonNodeFactory.objectNode().setAll(senderProps);
}
Also used : Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 53 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class TxPoolModuleImpl method content.

/**
 * This method should return 2 dictionaries containing pending and queued transactions
 * Each entry is an origin-address to a batch of scheduled transactions
 * These batches themselves are maps associating nonces with actual transactions.
 * When there are no transactions the answer would be
 * "{"pending": {}, "queued": {}}"
 */
@Override
public String content() {
    Map<String, JsonNode> contentProps = new HashMap<>();
    Map<RskAddress, Map<BigInteger, List<Transaction>>> pendingGrouped = groupTransactions(transactionPool.getPendingTransactions());
    Map<RskAddress, Map<BigInteger, List<Transaction>>> queuedGrouped = groupTransactions(transactionPool.getQueuedTransactions());
    contentProps.put(PENDING, serializeTransactions(pendingGrouped, this::fullSerializer));
    contentProps.put(QUEUED, serializeTransactions(queuedGrouped, this::fullSerializer));
    JsonNode node = jsonNodeFactory.objectNode().setAll(contentProps);
    return node.toString();
}
Also used : Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 54 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class TxsMinGasPriceRule method isValid.

@Override
public boolean isValid(Block block) {
    List<Transaction> txs = block.getTransactionsList();
    if (block.getMinimumGasPrice() == null) {
        logger.warn("Could not retrieve block min gas priceß");
        return false;
    }
    Coin blockMgp = block.getMinimumGasPrice();
    if (CollectionUtils.isNotEmpty(block.getTransactionsList())) {
        for (Transaction tx : txs) {
            if (!(tx instanceof RemascTransaction) && tx.getGasPrice().compareTo(blockMgp) < 0) {
                logger.warn("Tx gas price is under the Min gas Price of the block tx={}", tx.getHash());
                return false;
            }
        }
    }
    return true;
}
Also used : Coin(co.rsk.core.Coin) RemascTransaction(co.rsk.remasc.RemascTransaction) RemascTransaction(co.rsk.remasc.RemascTransaction) Transaction(org.ethereum.core.Transaction)

Example 55 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class GasPriceTracker method onBlock.

@Override
public void onBlock(Block block, List<TransactionReceipt> receipts) {
    logger.trace("Start onBlock");
    for (Transaction tx : block.getTransactionsList()) {
        onTransaction(tx);
    }
    logger.trace("End onBlock");
}
Also used : Transaction(org.ethereum.core.Transaction)

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