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