Search in sources :

Example 1 with TransactionPoolAddResult

use of org.ethereum.core.TransactionPoolAddResult in project rskj by rsksmart.

the class EthModuleTest method sendTransactionWithGasLimitTest.

@Test
public void sendTransactionWithGasLimitTest() {
    Constants constants = Constants.regtest();
    Wallet wallet = new Wallet(new HashMapDB());
    RskAddress sender = wallet.addAccount();
    RskAddress receiver = wallet.addAccount();
    // Hash of the expected transaction
    CallArguments args = TransactionFactoryHelper.createArguments(sender, receiver);
    Transaction tx = TransactionFactoryHelper.createTransaction(args, constants.getChainId(), wallet.getAccount(sender));
    String txExpectedResult = tx.getHash().toJsonString();
    TransactionPoolAddResult transactionPoolAddResult = mock(TransactionPoolAddResult.class);
    when(transactionPoolAddResult.transactionsWereAdded()).thenReturn(true);
    TransactionGateway transactionGateway = mock(TransactionGateway.class);
    when(transactionGateway.receiveTransaction(any(Transaction.class))).thenReturn(transactionPoolAddResult);
    TransactionPool transactionPool = mock(TransactionPool.class);
    EthModuleTransactionBase ethModuleTransaction = new EthModuleTransactionBase(constants, wallet, transactionPool, transactionGateway);
    // Hash of the actual transaction builded inside the sendTransaction
    String txResult = ethModuleTransaction.sendTransaction(args);
    assertEquals(txExpectedResult, txResult);
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) Transaction(org.ethereum.core.Transaction) Wallet(co.rsk.core.Wallet) RskAddress(co.rsk.core.RskAddress) CallArguments(org.ethereum.rpc.CallArguments) TransactionPoolAddResult(org.ethereum.core.TransactionPoolAddResult) BridgeConstants(co.rsk.config.BridgeConstants) Constants(org.ethereum.config.Constants) HashMapDB(org.ethereum.datasource.HashMapDB) TransactionGateway(co.rsk.net.TransactionGateway) Test(org.junit.Test)

Example 2 with TransactionPoolAddResult

use of org.ethereum.core.TransactionPoolAddResult in project rskj by rsksmart.

the class PersonalModuleTest method sendTransactionWithGasLimitTest.

@Test
public void sendTransactionWithGasLimitTest() throws Exception {
    TestSystemProperties props = new TestSystemProperties();
    Wallet wallet = new Wallet(new HashMapDB());
    RskAddress sender = wallet.addAccount(PASS_FRASE);
    RskAddress receiver = wallet.addAccount();
    // Hash of the expected transaction
    CallArguments args = TransactionFactoryHelper.createArguments(sender, receiver);
    Transaction tx = TransactionFactoryHelper.createTransaction(args, props.getNetworkConstants().getChainId(), wallet.getAccount(sender, PASS_FRASE));
    String txExpectedResult = tx.getHash().toJsonString();
    TransactionPoolAddResult transactionPoolAddResult = mock(TransactionPoolAddResult.class);
    when(transactionPoolAddResult.transactionsWereAdded()).thenReturn(true);
    Ethereum ethereum = mock(Ethereum.class);
    PersonalModuleWalletEnabled personalModuleWalletEnabled = new PersonalModuleWalletEnabled(props, ethereum, wallet, null);
    // Hash of the actual transaction builded inside the sendTransaction
    String txResult = personalModuleWalletEnabled.sendTransaction(args, PASS_FRASE);
    assertEquals(txExpectedResult, txResult);
}
Also used : Transaction(org.ethereum.core.Transaction) Wallet(co.rsk.core.Wallet) Ethereum(org.ethereum.facade.Ethereum) RskAddress(co.rsk.core.RskAddress) CallArguments(org.ethereum.rpc.CallArguments) TransactionPoolAddResult(org.ethereum.core.TransactionPoolAddResult) HashMapDB(org.ethereum.datasource.HashMapDB) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Example 3 with TransactionPoolAddResult

use of org.ethereum.core.TransactionPoolAddResult 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);
    }
}
Also used : Account(org.ethereum.core.Account) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) TransactionArguments(org.ethereum.core.TransactionArguments) RskAddress(co.rsk.core.RskAddress) TransactionPoolAddResult(org.ethereum.core.TransactionPoolAddResult)

Example 4 with TransactionPoolAddResult

use of org.ethereum.core.TransactionPoolAddResult in project rskj by rsksmart.

the class EthModuleTransactionBase method sendRawTransaction.

@Override
public String sendRawTransaction(String rawData) {
    String s = null;
    try {
        Transaction tx = new ImmutableTransaction(stringHexToByteArray(rawData));
        if (null == tx.getGasLimit() || null == tx.getGasPrice() || null == tx.getValue()) {
            throw invalidParamError("Missing parameter, gasPrice, gas or value");
        }
        TransactionPoolAddResult result = transactionGateway.receiveTransaction(tx);
        if (!result.transactionsWereAdded()) {
            throw RskJsonRpcRequestException.transactionError(result.getErrorMessage());
        }
        return s = tx.getHash().toJsonString();
    } finally {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("eth_sendRawTransaction({}): {}", rawData, s);
        }
    }
}
Also used : ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) TransactionPoolAddResult(org.ethereum.core.TransactionPoolAddResult)

Example 5 with TransactionPoolAddResult

use of org.ethereum.core.TransactionPoolAddResult in project rskj by rsksmart.

the class TransactionGatewayTest method receiveTransaction_alreadyAddedTransaction_shouldntAddAndShouldntBroadcast.

@Test
public void receiveTransaction_alreadyAddedTransaction_shouldntAddAndShouldntBroadcast() {
    TransactionPoolAddResult transactionPoolAddResult = TransactionPoolAddResult.withError("Not added");
    receiveTransactionAndVerifyCalls(transactionPoolAddResult, 0);
}
Also used : TransactionPoolAddResult(org.ethereum.core.TransactionPoolAddResult) Test(org.junit.Test)

Aggregations

TransactionPoolAddResult (org.ethereum.core.TransactionPoolAddResult)6 Transaction (org.ethereum.core.Transaction)4 Test (org.junit.Test)4 RskAddress (co.rsk.core.RskAddress)3 Wallet (co.rsk.core.Wallet)2 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)2 HashMapDB (org.ethereum.datasource.HashMapDB)2 CallArguments (org.ethereum.rpc.CallArguments)2 BridgeConstants (co.rsk.config.BridgeConstants)1 TestSystemProperties (co.rsk.config.TestSystemProperties)1 TransactionGateway (co.rsk.net.TransactionGateway)1 Constants (org.ethereum.config.Constants)1 Account (org.ethereum.core.Account)1 TransactionArguments (org.ethereum.core.TransactionArguments)1 TransactionPool (org.ethereum.core.TransactionPool)1 Ethereum (org.ethereum.facade.Ethereum)1