Search in sources :

Example 21 with JSONRPC2SessionException

use of com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException in project starcoin-java by starcoinorg.

the class TokenContractRPCClient method getTreasurBalance.

/**
 * 用于获取某个 token 在国库中的数量
 */
public BigInteger getTreasurBalance(String tokenTypeTag) throws JSONRPC2SessionException {
    ContractCall call = new ContractCall();
    call.setFunctionId(TreasuryBalanceTypeTag);
    List<String> typeTags = new ArrayList<>();
    typeTags.add(tokenTypeTag);
    call.setTypeArgs(typeTags);
    call.setArgs(new ArrayList<>());
    List result = this.call(call);
    if (result != null && result.size() > 0) {
        String capInString = String.valueOf(result.get(0));
        return new BigInteger(capInString);
    } else {
        throw new JSONRPC2SessionException("fetch token" + tokenTypeTag + " market cap failed");
    }
}
Also used : JSONRPC2SessionException(com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) List(java.util.List) ArrayList(java.util.ArrayList) ContractCall(org.starcoin.bean.ContractCall)

Example 22 with JSONRPC2SessionException

use of com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException in project starcoin-java by starcoinorg.

the class StateRPCClientTest method testGetState.

@Ignore
public void testGetState() {
    try {
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd-HH:mm:ss");
        System.out.println(format.format(new Date()));
        stateRPCClient.getState("0x5c04bb88984f933151bf69504692074d");
        long amount = stateRPCClient.getAddressAmount("0x5c04bb88984f933151bf69504692074d", "0x9350502a3af6c617e9a42fa9e306a385::BX_USDT::BX_USDT");
        System.out.println("amount: " + amount);
        amount = stateRPCClient.getAddressAmount("0x5c04bb88984f933151bf69504692074d", "0x00000000000000000000000000000001::STC::STC");
        System.out.println("amount: " + amount);
        TokenInfo tokenInfo = stateRPCClient.getTokenInfo("0x44366bba9bc9ed51bc8f564ecb18b12a", "0x44366bba9bc9ed51bc8f564ecb18b12a::DummyToken::BBB");
        System.out.println(tokenInfo);
        tokenInfo = stateRPCClient.getTokenInfo("0x1", "0x1::STC::STC");
        System.out.println(tokenInfo);
    } catch (JSONRPC2SessionException e) {
        e.printStackTrace();
    }
}
Also used : JSONRPC2SessionException(com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException) TokenInfo(org.starcoin.bean.TokenInfo) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Ignore(org.junit.Ignore)

Aggregations

JSONRPC2SessionException (com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException)18 ArrayList (java.util.ArrayList)10 JSONRPC2Request (com.thetransactioncompany.jsonrpc2.JSONRPC2Request)7 Block (org.starcoin.bean.Block)5 ContractCall (org.starcoin.bean.ContractCall)5 JSONObject (com.alibaba.fastjson.JSONObject)4 JSONRPC2Response (com.thetransactioncompany.jsonrpc2.JSONRPC2Response)4 List (java.util.List)4 JSONRPC2Session (com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session)3 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 BlockHeader (org.starcoin.bean.BlockHeader)2 BlockOffset (org.starcoin.bean.BlockOffset)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DeserializationError (com.novi.serde.DeserializationError)1 BigDecimal (java.math.BigDecimal)1 ConnectException (java.net.ConnectException)1