Search in sources :

Example 16 with Transaction

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

the class PersonalModuleWalletEnabled method sendTransaction.

private String sendTransaction(CallArguments args, Account senderAccount) throws Exception {
    if (senderAccount == null) {
        throw new Exception("From address private key could not be found in this node");
    }
    TransactionArguments txArgs = TransactionArgumentsUtil.processArguments(args, transactionPool, senderAccount, config.getNetworkConstants().getChainId());
    Transaction tx = Transaction.builder().withTransactionArguments(txArgs).build();
    tx.sign(senderAccount.getEcKey().getPrivKeyBytes());
    eth.submitTransaction(tx);
    return tx.getHash().toJsonString();
}
Also used : Transaction(org.ethereum.core.Transaction) TransactionArguments(org.ethereum.core.TransactionArguments)

Example 17 with Transaction

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

the class RskModuleImpl method getTransactionReceiptNodesByHash.

@Override
public String[] getTransactionReceiptNodesByHash(String blockHash, String transactionHash) {
    String[] encodedNodes = null;
    try {
        Keccak256 txHash = new Keccak256(stringHexToByteArray(transactionHash));
        Keccak256 bhash = new Keccak256(stringHexToByteArray(blockHash));
        Block block = this.blockchain.getBlockByHash(bhash.getBytes());
        List<Transaction> transactions = block.getTransactionsList();
        List<TransactionReceipt> receipts = new ArrayList<>();
        int ntxs = transactions.size();
        int ntx = -1;
        for (int k = 0; k < ntxs; k++) {
            Transaction transaction = transactions.get(k);
            Keccak256 txh = transaction.getHash();
            Optional<TransactionInfo> txInfoOpt = this.receiptStore.get(txh.getBytes(), bhash.getBytes());
            if (!txInfoOpt.isPresent()) {
                logger.error("Missing receipt for transaction {} in block {}", txh, bhash);
                continue;
            }
            TransactionInfo txInfo = txInfoOpt.get();
            receipts.add(txInfo.getReceipt());
            if (txh.equals(txHash)) {
                ntx = k;
            }
        }
        if (ntx == -1) {
            return null;
        }
        Trie trie = BlockHashesHelper.calculateReceiptsTrieRootFor(receipts);
        List<Trie> nodes = trie.getNodes(RLP.encodeInt(ntx));
        encodedNodes = new String[nodes.size()];
        for (int k = 0; k < encodedNodes.length; k++) {
            encodedNodes[k] = TypeConverter.toUnformattedJsonHex(nodes.get(k).toMessage());
        }
        return encodedNodes;
    } finally {
        if (logger.isDebugEnabled()) {
            logger.debug("rsk_getTransactionReceiptNodesByHash({}): {}", blockHash, Arrays.toString(encodedNodes));
        }
    }
}
Also used : TransactionReceipt(org.ethereum.core.TransactionReceipt) ArrayList(java.util.ArrayList) Keccak256(co.rsk.crypto.Keccak256) Transaction(org.ethereum.core.Transaction) Block(org.ethereum.core.Block) TransactionInfo(org.ethereum.db.TransactionInfo) Trie(co.rsk.trie.Trie)

Example 18 with Transaction

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

the class TraceModuleImpl method traceTransaction.

@Override
public JsonNode traceTransaction(String transactionHash) throws Exception {
    logger.trace("trace_transaction({})", transactionHash);
    byte[] hash = stringHexToByteArray(transactionHash);
    TransactionInfo txInfo = this.receiptStore.getInMainChain(hash, this.blockStore).orElse(null);
    if (txInfo == null) {
        logger.trace("No transaction info for {}", transactionHash);
        return null;
    }
    Block block = this.blockchain.getBlockByHash(txInfo.getBlockHash());
    Block parent = this.blockchain.getBlockByHash(block.getParentHash().getBytes());
    Transaction tx = block.getTransactionsList().get(txInfo.getIndex());
    txInfo.setTransaction(tx);
    ProgramTraceProcessor programTraceProcessor = new ProgramTraceProcessor();
    this.blockExecutor.traceBlock(programTraceProcessor, VmConfig.LIGHT_TRACE, block, parent.getHeader(), false, false);
    SummarizedProgramTrace programTrace = (SummarizedProgramTrace) programTraceProcessor.getProgramTrace(tx.getHash());
    if (programTrace == null) {
        return null;
    }
    List<TransactionTrace> traces = TraceTransformer.toTraces(programTrace, txInfo, block.getNumber());
    return OBJECT_MAPPER.valueToTree(traces);
}
Also used : ProgramTraceProcessor(org.ethereum.vm.trace.ProgramTraceProcessor) Transaction(org.ethereum.core.Transaction) TransactionInfo(org.ethereum.db.TransactionInfo) Block(org.ethereum.core.Block) SummarizedProgramTrace(org.ethereum.vm.trace.SummarizedProgramTrace)

Example 19 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 JsonNode 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;
}
Also used : Transaction(org.ethereum.core.Transaction) HashMap(java.util.HashMap) RskAddress(co.rsk.core.RskAddress) JsonNode(com.fasterxml.jackson.databind.JsonNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 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) HashMap(java.util.HashMap) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Transaction (org.ethereum.core.Transaction)257 Test (org.junit.Test)166 Block (org.ethereum.core.Block)73 RskAddress (co.rsk.core.RskAddress)69 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)57 InternalTransaction (org.ethereum.vm.program.InternalTransaction)57 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)39 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)39 BigInteger (java.math.BigInteger)38 ArrayList (java.util.ArrayList)38 Repository (org.ethereum.core.Repository)35 JsonNode (com.fasterxml.jackson.databind.JsonNode)32 ECKey (org.ethereum.crypto.ECKey)30 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)29 Keccak256 (co.rsk.crypto.Keccak256)28 Account (org.ethereum.core.Account)26 World (co.rsk.test.World)23 DslParser (co.rsk.test.dsl.DslParser)23 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)23 MutableRepository (org.ethereum.db.MutableRepository)22