use of org.ethereum.core.TransactionArguments in project rskj by rsksmart.
the class TransactionArgumentsUtil method processArguments.
/**
* transform the Web3.CallArguments in TransactionArguments that can be used in
* the TransactionBuilder
*/
public static TransactionArguments processArguments(CallArguments argsParam, TransactionPool transactionPool, Account senderAccount, byte defaultChainId) {
TransactionArguments argsRet = new TransactionArguments();
argsRet.setFrom(argsParam.getFrom());
argsRet.setTo(stringHexToByteArray(argsParam.getTo()));
argsRet.setNonce(strHexOrStrNumberToBigInteger(argsParam.getNonce(), () -> transactionPool.getPendingState().getNonce(senderAccount.getAddress())));
argsRet.setValue(strHexOrStrNumberToBigInteger(argsParam.getValue(), () -> BigInteger.ZERO));
argsRet.setGasPrice(strHexOrStrNumberToBigInteger(argsParam.getGasPrice(), () -> BigInteger.ZERO));
argsRet.setGasLimit(strHexOrStrNumberToBigInteger(argsParam.getGas(), () -> null));
if (argsRet.getGasLimit() == null) {
argsRet.setGasLimit(strHexOrStrNumberToBigInteger(argsParam.getGasLimit(), () -> DEFAULT_GAS_LIMIT));
}
if (argsParam.getData() != null && argsParam.getData().startsWith("0x")) {
argsRet.setData(argsParam.getData().substring(2));
// needs to change the parameter because some places expect the changed value after sendTransaction call
argsParam.setData(argsRet.getData());
}
argsRet.setChainId(hexToChainId(argsParam.getChainId()));
if (argsRet.getChainId() == 0) {
argsRet.setChainId(defaultChainId);
}
return argsRet;
}
use of org.ethereum.core.TransactionArguments 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.TransactionArguments in project rskj by rsksmart.
the class EthModuleTransactionBase method sendTransaction.
@Override
public synchronized String sendTransaction(CallArguments args) {
Account senderAccount = this.wallet.getAccount(new RskAddress(args.getFrom()));
if (senderAccount == null) {
throw RskJsonRpcRequestException.invalidParamError(TransactionArgumentsUtil.ERR_COULD_NOT_FIND_ACCOUNT + args.getFrom());
}
String txHash = null;
try {
synchronized (transactionPool) {
TransactionArguments txArgs = TransactionArgumentsUtil.processArguments(args, transactionPool, senderAccount, constants.getChainId());
Transaction tx = Transaction.builder().withTransactionArguments(txArgs).build();
tx.sign(senderAccount.getEcKey().getPrivKeyBytes());
if (!tx.acceptTransactionSignature(constants.getChainId())) {
throw RskJsonRpcRequestException.invalidParamError(TransactionArgumentsUtil.ERR_INVALID_CHAIN_ID + args.getChainId());
}
TransactionPoolAddResult result = transactionGateway.receiveTransaction(tx.toImmutableTransaction());
if (!result.transactionsWereAdded()) {
throw RskJsonRpcRequestException.transactionError(result.getErrorMessage());
}
txHash = tx.getHash().toJsonString();
}
return txHash;
} finally {
LOGGER.debug("eth_sendTransaction({}): {}", args, txHash);
}
}
use of org.ethereum.core.TransactionArguments in project rskj by rsksmart.
the class TransactionArgumentsUtilTest method processArguments.
@Test
public void processArguments() {
Constants constants = Constants.regtest();
Wallet wallet = new Wallet(new HashMapDB());
RskAddress sender = wallet.addAccount();
RskAddress receiver = wallet.addAccount();
CallArguments args = TransactionFactoryHelper.createArguments(sender, receiver);
TransactionArguments txArgs = TransactionArgumentsUtil.processArguments(args, null, wallet.getAccount(sender), constants.getChainId());
assertEquals(txArgs.getValue(), BigInteger.valueOf(100000L));
assertEquals(txArgs.getGasPrice(), BigInteger.valueOf(10000000000000L));
assertEquals(txArgs.getGasLimit(), BigInteger.valueOf(30400L));
assertEquals(txArgs.getChainId(), 33);
assertEquals(txArgs.getNonce(), BigInteger.ONE);
assertEquals(txArgs.getData(), null);
assertArrayEquals(txArgs.getTo(), receiver.getBytes());
}
Aggregations