All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.klaytn.caver.JsonRpc2_0Klay Maven / Gradle / Ivy

There is a newer version: 1.12.2-android
Show newest version
/*
 * Copyright 2019 The caver-java Authors
 *
 * Licensed under the Apache License, Version 2.0 (the “License”);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an “AS IS” BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.klaytn.caver;

import com.klaytn.caver.methods.request.CallObject;
import com.klaytn.caver.methods.request.KlayFilter;
import com.klaytn.caver.methods.request.KlayLogFilter;
import com.klaytn.caver.methods.response.Boolean;
import com.klaytn.caver.methods.response.*;
import org.web3j.protocol.Web3jService;
import org.web3j.protocol.admin.Admin;
import org.web3j.protocol.admin.methods.response.NewAccountIdentifier;
import org.web3j.protocol.admin.methods.response.PersonalUnlockAccount;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.DefaultBlockParameterNumber;
import org.web3j.protocol.core.Request;
import org.web3j.utils.Async;
import org.web3j.utils.Numeric;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.ScheduledExecutorService;

/**
 * @deprecated Please use {@link com.klaytn.caver.rpc.Klay} instead.
 * @see com.klaytn.caver.rpc.RPC
 */
@Deprecated
public class JsonRpc2_0Klay implements Klay {

    public static final int DEFAULT_BLOCK_TIME = 1 * 1000;

    protected final Web3jService web3jService;
    //private final JsonRpc2_0Rx web3jRx;
    private final long blockTime;
    private final ScheduledExecutorService scheduledExecutorService;
    private Admin web3j;

    public JsonRpc2_0Klay(Web3jService web3jService, Admin web3j) {
        this(web3jService, DEFAULT_BLOCK_TIME, Async.defaultExecutorService(), web3j);
    }

    public JsonRpc2_0Klay(
            Web3jService web3jService, long pollingInterval,
            ScheduledExecutorService scheduledExecutorService,
            Admin web3j) {
        this.web3jService = web3jService;
        //this.web3jRx = new JsonRpc2_0Rx(this, scheduledExecutorService);
        this.blockTime = pollingInterval;
        this.scheduledExecutorService = scheduledExecutorService;
        this.web3j = web3j;
    }

    @Override
    public Request isAccountCreated(String address, DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_accountCreated",
                Arrays.asList(
                        address,
                        defaultBlockParameter
                ),
                web3jService,
                Boolean.class);
    }

    @Override
    public Request getAccounts() {
        return new Request<>(
                "klay_accounts",
                Collections.emptyList(),
                web3jService,
                Addresses.class);
    }

    @Override
    public Request getAccount(String address, DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_getAccount",
                Arrays.asList(
                        address,
                        defaultBlockParameter.getValue()
                ),
                web3jService,
                KlayAccount.class);
    }

    @Override
    public Request getAccountKey(String address, DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_getAccountKey",
                Arrays.asList(
                        address,
                        defaultBlockParameter.getValue()
                ),
                web3jService,
                KlayAccountKey.class);
    }

    @Override
    public Request getBalance(String address, DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_getBalance",
                Arrays.asList(
                        address,
                        defaultBlockParameter
                ),
                web3jService,
                Quantity.class);
    }

    @Override
    public Request getCode(
            String address, DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_getCode",
                Arrays.asList(
                        address,
                        defaultBlockParameter.getValue()
                ),
                web3jService,
                Bytes.class);
    }

    @Override
    public Request getTransactionCount(
            String address, DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_getTransactionCount",
                Arrays.asList(
                        address,
                        defaultBlockParameter.getValue()
                ),
                web3jService,
                Quantity.class);
    }

    @Override
    public Request isContractAccount(String address, DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_isContractAccount",
                Arrays.asList(
                        address,
                        defaultBlockParameter
                ),
                web3jService,
                Boolean.class);
    }

    @Override
    public Request sign(String address, String message) {
        return new Request<>(
                "klay_sign",
                Arrays.asList(
                        address,
                        message
                ),
                web3jService,
                Bytes.class);
    }

    @Override
    public Request getBlockNumber() {
        return new Request<>(
                "klay_blockNumber",
                Collections.emptyList(),
                web3jService,
                Quantity.class);
    }

    @Override
    public Request getBlockByNumber(DefaultBlockParameter defaultBlockParameter, boolean isFullTransaction) {
        return new Request<>(
                "klay_getBlockByNumber",
                Arrays.asList(defaultBlockParameter, isFullTransaction),
                web3jService,
                KlayBlock.class);
    }

    @Override
    public Request getBlockByHash(String blockHash, boolean isFullTransaction) {
        return new Request<>(
                "klay_getBlockByHash",
                Arrays.asList(blockHash, isFullTransaction),
                web3jService,
                KlayBlock.class);
    }

    @Override
    public Request getBlockReceipts(String blockHash) {
        return new Request<>(
                "klay_getBlockReceipts",
                Arrays.asList(blockHash),
                web3jService,
                BlockReceipts.class);
    }

    @Override
    public Request getTransactionCountByNumber(DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_getBlockTransactionCountByNumber",
                Arrays.asList(defaultBlockParameter),
                web3jService,
                Quantity.class);
    }

    @Override
    public Request getTransactionCountByHash(String blockHash) {
        return new Request<>(
                "klay_getBlockTransactionCountByHash",
                Arrays.asList(blockHash),
                web3jService,
                Quantity.class);
    }

    @Override
    public Request getBlockWithConsensusInfoByHash(String blockHash) {
        return new Request<>(
                "klay_getBlockWithConsensusInfoByHash",
                Arrays.asList(blockHash),
                web3jService,
                KlayBlockWithConsensusInfo.class);
    }

    @Override
    public Request getBlockWithConsensusInfoByNumber(DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_getBlockWithConsensusInfoByNumber",
                Arrays.asList(defaultBlockParameter),
                web3jService,
                KlayBlockWithConsensusInfo.class);
    }

    @Override
    public Request getCommittee(DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_getCommittee",
                Arrays.asList(defaultBlockParameter),
                web3jService,
                Addresses.class
        );
    }

    @Override
    public Request getCommitteeSize(DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_getCommitteeSize",
                Arrays.asList(defaultBlockParameter),
                web3jService,
                Quantity.class
        );
    }

    @Override
    public Request getCouncil(DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_getCouncil",
                Arrays.asList(defaultBlockParameter),
                web3jService,
                Addresses.class
        );
    }

    @Override
    public Request getCouncilSize(DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_getCouncilSize",
                Arrays.asList(defaultBlockParameter),
                web3jService,
                Quantity.class
        );
    }

    @Override
    public Request getStorageAt(
            String address, DefaultBlockParameterNumber position, DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_getStorageAt",
                Arrays.asList(
                        address,
                        position,
                        defaultBlockParameter.getValue()
                ),
                web3jService,
                Bytes.class);
    }

    @Override
    public Request getWork() {
        return new Request<>(
                "klay_getWork",
                Collections.emptyList(),
                web3jService,
                Work.class);
    }

    @Override
    public Request isMining() {
        return new Request<>(
                "klay_mining",
                Collections.emptyList(),
                web3jService,
                Boolean.class);
    }

    @Override
    public Request isSyncing() {
        return new Request<>(
                "klay_syncing",
                Collections.emptyList(),
                web3jService,
                KlaySyncing.class);
    }

    @Override
    public Request call(CallObject callObject, DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_call",
                Arrays.asList(callObject, defaultBlockParameter),
                web3jService,
                Bytes.class);
    }

    @Override
    public Request estimateGas(CallObject callObject) {
        return new Request<>(
                "klay_estimateGas",
                Arrays.asList(callObject),
                web3jService,
                Quantity.class);
    }

    @Override
    public Request estimateComputationCost(CallObject callObject, DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_estimateComputationCost",
                Arrays.asList(callObject, defaultBlockParameter),
                web3jService,
                Quantity.class);
    }

    @Override
    public Request getTransactionByBlockHashAndIndex(String blockHash, DefaultBlockParameterNumber index) {
        return new Request<>(
                "klay_getTransactionByBlockHashAndIndex",
                Arrays.asList(blockHash, index),
                web3jService,
                KlayTransaction.class);
    }

    @Override
    public Request getTransactionByBlockNumberAndIndex(DefaultBlockParameter blockNumber, DefaultBlockParameterNumber index) {
        return new Request<>(
                "klay_getTransactionByBlockNumberAndIndex",
                Arrays.asList(blockNumber, index),
                web3jService,
                KlayTransaction.class);
    }

    @Override
    public Request getTransactionByHash(String txHash) {
        return new Request<>(
                "klay_getTransactionByHash",
                Arrays.asList(txHash),
                web3jService,
                KlayTransaction.class);
    }

    @Override
    public Request getTransactionBySenderTxHash(String txHash) {
        return new Request<>(
                "klay_getTransactionBySenderTxHash",
                Arrays.asList(txHash),
                web3jService,
                KlayTransaction.class);
    }

    @Override
    public Request getTransactionReceipt(String transactionHash) {
        return new Request<>(
                "klay_getTransactionReceipt",
                Arrays.asList(transactionHash),
                web3jService,
                KlayTransactionReceipt.class);
    }

    @Override
    public Request getTransactionReceiptBySenderTxHash(String transactionHash) {
        return new Request<>(
                "klay_getTransactionReceiptBySenderTxHash",
                Arrays.asList(transactionHash),
                web3jService,
                KlayTransactionReceipt.class);
    }

    @Override
    public Request sendSignedTransaction(String signedTransactionData) {
        return new Request<>(
                "klay_sendRawTransaction",
                Arrays.asList(signedTransactionData),
                web3jService,
                Bytes32.class);
    }

    @Override
    public Request sendTransaction(com.klaytn.caver.methods.request.KlayTransaction transaction) {
        return new Request<>(
                "klay_sendTransaction",
                Arrays.asList(transaction),
                web3jService,
                Bytes32.class);
    }

    @Override
    public Request signTransaction(com.klaytn.caver.methods.request.KlayTransaction transaction) {
        return new Request<>(
                "klay_signTransaction",
                Arrays.asList(transaction),
                web3jService,
                KlaySignTransaction.class);
    }

    @Override
    public Request getChainID() {
        return new Request<>(
                "klay_chainID",
                Collections.emptyList(),
                web3jService,
                Quantity.class);
    }

    @Override
    public Request getClientVersion() {
        return new Request<>(
                "klay_clientVersion",
                Collections.emptyList(),
                web3jService,
                Bytes.class);
    }

    @Override
    public Request getGasPrice() {
        return new Request<>(
                "klay_gasPrice",
                Collections.emptyList(),
                web3jService,
                Quantity.class);
    }

    @Override
    public Request getGasPrice(DefaultBlockParameter defaultBlockParameter) {
        return new Request<>(
                "klay_gasPrice",
                Arrays.asList(defaultBlockParameter),
                web3jService,
                Quantity.class);
    }

//     @Override
//     public Request getGasPriceAt(DefaultBlockParameter defaultBlockParameter) {
//         return new Request<>(
//                 "klay_gasPriceAt",
//                 Arrays.asList(defaultBlockParameter),
//                 web3jService,
//                 Quantity.class
//         );
//     }

    @Override
    public Request isParallelDBWrite() {
        return new Request<>(
                "klay_isParallelDBWrite",
                Collections.emptyList(),
                web3jService,
                Boolean.class);
    }

    @Override
    public Request isSenderTxHashIndexingEnabled() {
        return new Request<>(
                "klay_isSenderTxHashIndexingEnabled",
                Collections.emptyList(),
                web3jService,
                Boolean.class);
    }

    @Override
    public Request getProtocolVersion() {
        return new Request<>(
                "klay_protocolVersion",
                Collections.emptyList(),
                web3jService,
                Bytes.class);
    }

    @Override
    public Request getRewardbase() {
        return new Request<>(
                "klay_rewardbase",
                Collections.emptyList(),
                web3jService,
                Bytes20.class);
    }

    @Override
    public Request getFilterChanges(BigInteger filterId) {
        return new Request<>(
                "klay_getFilterChanges",
                Arrays.asList(Numeric.toHexStringWithPrefix(filterId)),
                web3jService,
                KlayLogs.class);
    }

    @Override
    public Request getFilterLogs(BigInteger filterId) {
        return new Request<>(
                "klay_getFilterLogs",
                Arrays.asList(Numeric.toHexStringWithPrefix(filterId)),
                web3jService,
                KlayLogs.class);
    }

    @Override
    public Request getLogs(KlayLogFilter filter) {
        return new Request<>(
                "klay_getLogs",
                Arrays.asList(filter),
                web3jService,
                KlayLogs.class);
    }

    @Override
    public Request newBlockFilter() {
        return new Request<>(
                "klay_newBlockFilter",
                Collections.emptyList(),
                web3jService,
                Quantity.class);
    }

    @Override
    public Request newFilter(KlayFilter filter) {
        return new Request<>(
                "klay_newFilter",
                Arrays.asList(filter),
                web3jService,
                Quantity.class);
    }

    @Override
    public Request newPendingTransactionFilter() {
        return new Request<>(
                "klay_newPendingTransactionFilter",
                Collections.emptyList(),
                web3jService,
                Quantity.class);
    }

    @Override
    public Request uninstallFilter(BigInteger filterId) {
        return new Request<>(
                "klay_uninstallFilter",
                Arrays.asList(Numeric.toHexStringWithPrefix(filterId)),
                web3jService,
                Boolean.class);
    }

    @Override
    public Request getSha3(String data) {
        return new Request<>(
                "klay_sha3",
                Arrays.asList(data),
                web3jService,
                Bytes.class);
    }

    //===========================================================

    @Override
    public Request newAccount(String passphrase) {
        return web3j.personalNewAccount(passphrase);
    }

    public Request unlockAccount(String address,
                                                           String passphrase, BigInteger duration) {
        return web3j.personalUnlockAccount(
                address,
                passphrase,
                duration
        );
    }

    @Override
    public Request lockAccount(String address) {
        return new Request<>(
                "personal_lockAccount",
                Arrays.asList(
                        address
                ),
                web3jService,
                Boolean.class);
    }

    @Override
    public Request importRawKey() {
        return new Request<>(
                "personal_importRawKey",
                Collections.emptyList(),
                web3jService,
                Bytes20.class);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy