use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class ChannelManagerImpl method broadcastTransaction.
/**
* broadcastTransaction Propagates a transaction message across active peers with exclusion of
* the peers with an id belonging to the skip set.
*
* @param transaction new Transaction to be sent
* @param skip the set of peers to avoid sending the message.
* @return a set containing the ids of the peers that received the transaction.
*/
@Nonnull
public Set<NodeID> broadcastTransaction(@Nonnull final Transaction transaction, @Nullable final Set<NodeID> skip) {
Metrics.broadcastTransaction(transaction);
List<Transaction> transactions = new ArrayList<>();
transactions.add(transaction);
final Set<NodeID> res = new HashSet<>();
final EthMessage newTransactions = new RskMessage(config, new TransactionsMessage(transactions));
synchronized (activePeers) {
final Vector<Channel> peers = activePeers.values().stream().filter(p -> skip == null || !skip.contains(p.getNodeId())).collect(Collectors.toCollection(Vector::new));
for (Channel peer : peers) {
res.add(peer.getNodeId());
peer.sendMessage(newTransactions);
}
}
return res;
}
use of org.ethereum.core.Transaction in project eth-propeller-ethj by adridadou.
the class EthJEventListener method toReceipt.
static org.adridadou.ethereum.propeller.values.TransactionReceipt toReceipt(TransactionReceipt transactionReceipt, EthHash blockHash) {
Transaction tx = transactionReceipt.getTransaction();
BigInteger txValue = tx.getValue().length > 0 ? new BigInteger(tx.getValue()) : BigInteger.ZERO;
if (txValue.signum() == -1) {
txValue = BigInteger.ZERO;
}
return new org.adridadou.ethereum.propeller.values.TransactionReceipt(EthHash.of(tx.getHash()), blockHash, EthAddress.of(tx.getSender()), EthAddress.of(tx.getReceiveAddress()), EthAddress.of(tx.getContractAddress()), transactionReceipt.getError(), EthData.of(transactionReceipt.getExecutionResult()), transactionReceipt.isSuccessful() && transactionReceipt.isValid(), createEventInfoList(EthHash.of(tx.getHash()), transactionReceipt.getLogInfoList()), ethValueDecoder.decode(0, EthData.of(txValue), EthValue.class));
}
use of org.ethereum.core.Transaction in project eth-propeller-ethj by adridadou.
the class EthereumReal method submit.
@Override
public EthHash submit(TransactionRequest request, Nonce nonce) {
Transaction tx = ethereum.createTransaction(nonce.getValue(), getGasPrice().getPrice().inWei(), request.getGasLimit().getUsage(), request.getAddress().address, request.getValue().inWei(), request.getData().data);
tx.sign(getKey(request.getAccount()));
ethereum.submitTransaction(tx);
return EthHash.of(tx.getHash());
}
use of org.ethereum.core.Transaction in project eth-propeller-ethj by adridadou.
the class EthereumTest method createTransaction.
private Transaction createTransaction(TransactionRequest request, Nonce nonce) {
Transaction transaction = new Transaction(ByteUtil.bigIntegerToBytes(nonce.getValue()), ByteUtil.bigIntegerToBytes(BigInteger.ZERO), ByteUtil.bigIntegerToBytes(request.getGasLimit().getUsage()), request.getAddress().address, ByteUtil.bigIntegerToBytes(request.getValue().inWei()), request.getData().data, null);
transaction.sign(getKey(request.getAccount()));
return transaction;
}
use of org.ethereum.core.Transaction in project account-identity by cryptofiat.
the class EthereumService method sendTransaction.
private String sendTransaction(ECKey signer, byte[] callData, String _contract, int nonceIncrement) throws IOException {
// TODO: maybe a queue of pending transactions, otherwise one goes through at a time
long transactionCount = getTransactionCount(hex(signer.getAddress())) + nonceIncrement;
long gasPriceWei = wsService.getGasPriceWei();
log.info("Current gas price: " + String.valueOf(gasPriceWei));
byte[] nonce = ByteUtil.longToBytesNoLeadZeroes(transactionCount);
byte[] gasPrice = ByteUtil.longToBytesNoLeadZeroes(gasPriceWei);
byte[] gasLimit = ByteUtil.longToBytesNoLeadZeroes(GAS_LIMIT);
byte[] toAddress = Hex.decode(without0x(_contract));
Transaction transaction = new Transaction(nonce, gasPrice, gasLimit, toAddress, null, callData);
// noinspection ConstantConditions
transaction.sign(signer.getPrivKeyBytes());
return send(json("eth_sendRawTransaction", hex(transaction.getEncoded())));
}
Aggregations