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