Search in sources :

Example 1 with JsonRpcInvalidParamException

use of org.ethereum.rpc.exception.JsonRpcInvalidParamException in project rskj by rsksmart.

the class Web3ImplScoringTest method addBannedAddressWithInvalidMask.

@Test
public void addBannedAddressWithInvalidMask() throws UnknownHostException {
    PeerScoringManager peerScoringManager = createPeerScoringManager();
    Web3Impl web3 = createWeb3(peerScoringManager);
    try {
        web3.sco_banAddress("192.168.56.1/a");
        Assert.fail();
    } catch (JsonRpcInvalidParamException ex) {
        Assert.assertEquals("invalid banned address 192.168.56.1/a", ex.getMessage());
    }
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) JsonRpcInvalidParamException(org.ethereum.rpc.exception.JsonRpcInvalidParamException) Test(org.junit.Test)

Example 2 with JsonRpcInvalidParamException

use of org.ethereum.rpc.exception.JsonRpcInvalidParamException 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);
    }
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) BigInteger(java.math.BigInteger) JsonRpcInvalidParamException(org.ethereum.rpc.exception.JsonRpcInvalidParamException)

Example 3 with JsonRpcInvalidParamException

use of org.ethereum.rpc.exception.JsonRpcInvalidParamException in project rskj by rsksmart.

the class Web3Impl method eth_getBlocksByNumber.

public BlockInformationResult[] eth_getBlocksByNumber(String number) {
    long blockNumber;
    try {
        blockNumber = TypeConverter.stringNumberAsBigInt(number).longValue();
    } catch (NumberFormatException | StringIndexOutOfBoundsException e) {
        throw new JsonRpcInvalidParamException("invalid blocknumber " + number);
    }
    List<BlockInformationResult> result = new ArrayList<>();
    List<BlockInformation> binfos = blockchain.getBlocksInformationByNumber(blockNumber);
    for (BlockInformation binfo : binfos) {
        result.add(getBlockInformationResult(binfo));
    }
    return result.toArray(new BlockInformationResult[result.size()]);
}
Also used : JsonRpcInvalidParamException(org.ethereum.rpc.exception.JsonRpcInvalidParamException) BlockInformation(org.ethereum.db.BlockInformation)

Example 4 with JsonRpcInvalidParamException

use of org.ethereum.rpc.exception.JsonRpcInvalidParamException in project rskj by rsksmart.

the class Web3Impl method evm_increaseTime.

@Override
public String evm_increaseTime(String seconds) {
    try {
        long nseconds = stringNumberAsBigInt(seconds).longValue();
        String result = toJsonHex(minerServer.increaseTime(nseconds));
        if (logger.isDebugEnabled()) {
            logger.debug("evm_increaseTime({}): {}", nseconds, result);
        }
        return result;
    } catch (NumberFormatException | StringIndexOutOfBoundsException e) {
        throw new JsonRpcInvalidParamException("invalid number of seconds " + seconds, e);
    }
}
Also used : JsonRpcInvalidParamException(org.ethereum.rpc.exception.JsonRpcInvalidParamException)

Example 5 with JsonRpcInvalidParamException

use of org.ethereum.rpc.exception.JsonRpcInvalidParamException in project rskj by rsksmart.

the class Web3ImplScoringTest method removeBannedAddressWithInvalidMask.

@Test
public void removeBannedAddressWithInvalidMask() throws UnknownHostException {
    PeerScoringManager peerScoringManager = createPeerScoringManager();
    Web3Impl web3 = createWeb3(peerScoringManager);
    try {
        web3.sco_unbanAddress("192.168.56.1/a");
        Assert.fail();
    } catch (JsonRpcInvalidParamException ex) {
        Assert.assertEquals("invalid banned address 192.168.56.1/a", ex.getMessage());
    }
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) JsonRpcInvalidParamException(org.ethereum.rpc.exception.JsonRpcInvalidParamException) Test(org.junit.Test)

Aggregations

JsonRpcInvalidParamException (org.ethereum.rpc.exception.JsonRpcInvalidParamException)5 PeerScoringManager (co.rsk.scoring.PeerScoringManager)2 Test (org.junit.Test)2 BigInteger (java.math.BigInteger)1 Account (org.ethereum.core.Account)1 Transaction (org.ethereum.core.Transaction)1 BlockInformation (org.ethereum.db.BlockInformation)1