Search in sources :

Example 66 with Transaction

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;
}
Also used : NodeFilter(org.ethereum.config.NodeFilter) java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) LRUMap(org.apache.commons.collections4.map.LRUMap) Autowired(org.springframework.beans.factory.annotation.Autowired) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Block(org.ethereum.core.Block) InetAddress(java.net.InetAddress) EthMessage(org.ethereum.net.eth.message.EthMessage) Status(co.rsk.net.Status) SyncPool(org.ethereum.sync.SyncPool) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Metrics(co.rsk.net.Metrics) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BlockIdentifier(org.ethereum.core.BlockIdentifier) RskMessage(co.rsk.net.eth.RskMessage) Logger(org.slf4j.Logger) co.rsk.net.messages(co.rsk.net.messages) ReasonCode(org.ethereum.net.message.ReasonCode) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Component(org.springframework.stereotype.Component) NodeID(co.rsk.net.NodeID) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RskSystemProperties(co.rsk.config.RskSystemProperties) Transaction(org.ethereum.core.Transaction) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Transaction(org.ethereum.core.Transaction) EthMessage(org.ethereum.net.eth.message.EthMessage) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NodeID(co.rsk.net.NodeID) RskMessage(co.rsk.net.eth.RskMessage) Nonnull(javax.annotation.Nonnull)

Example 67 with Transaction

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));
}
Also used : Transaction(org.ethereum.core.Transaction) TransactionReceipt(org.ethereum.core.TransactionReceipt) BigInteger(java.math.BigInteger)

Example 68 with Transaction

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());
}
Also used : Transaction(org.ethereum.core.Transaction)

Example 69 with Transaction

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;
}
Also used : Transaction(org.ethereum.core.Transaction)

Example 70 with 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())));
}
Also used : Transaction(org.ethereum.core.Transaction)

Aggregations

Transaction (org.ethereum.core.Transaction)131 Test (org.junit.Test)82 BigInteger (java.math.BigInteger)33 Coin (co.rsk.core.Coin)23 Account (org.ethereum.core.Account)20 ArrayList (java.util.ArrayList)17 Block (org.ethereum.core.Block)17 RskAddress (co.rsk.core.RskAddress)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Repository (org.ethereum.core.Repository)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 AccountState (org.ethereum.core.AccountState)10 RemascTransaction (co.rsk.remasc.RemascTransaction)9 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)9 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)8 ECKey (org.ethereum.crypto.ECKey)8 Keccak256 (co.rsk.crypto.Keccak256)7 AccountBuilder (co.rsk.test.builders.AccountBuilder)7 DslParser (co.rsk.test.dsl.DslParser)6 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)6