Search in sources :

Example 16 with JSONRPC2SessionException

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

the class TvlTest method testTvl.

@Test
public void testTvl() {
    try {
        ContractRPCClient client = new ContractRPCClient(new URL("http://barnard1.seed.starcoin.org:9850"));
        ContractCall call = new ContractCall();
        call.setFunctionId("0xbd7e8be8fae9f60f2f5136433e36a091::TokenSwap::get_reserves");
        List<String> typeTags = new ArrayList<>();
        typeTags.add("0x00000000000000000000000000000001::STC::STC");
        typeTags.add("0xbd7e8be8fae9f60f2f5136433e36a091::Usdx::Usdx");
        call.setTypeArgs(typeTags);
        call.setArgs(new ArrayList<>());
        List<Object> result = client.call(call);
        System.out.println(result);
    } catch (JSONRPC2SessionException | MalformedURLException e) {
        e.printStackTrace();
    }
}
Also used : ContractRPCClient(org.starcoin.api.ContractRPCClient) MalformedURLException(java.net.MalformedURLException) JSONRPC2SessionException(com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException) ArrayList(java.util.ArrayList) ContractCall(org.starcoin.bean.ContractCall) URL(java.net.URL) Test(org.junit.Test)

Example 17 with JSONRPC2SessionException

use of com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException in project junit-plugin by kiwitcms.

the class BaseRpcClient method executeViaNamedParams.

protected Object executeViaNamedParams(String serviceMethod, Map<String, Object> params) {
    JSONRPC2Session mySession = prepareSession();
    // Construct new request
    int requestID = 1;
    JSONRPC2Request request = new JSONRPC2Request(serviceMethod, requestID);
    request.setNamedParams(params);
    // Send request
    try {
        return getResponse(mySession.send(request));
    } catch (JSONRPC2SessionException e) {
        System.err.println(e.getMessage());
        return null;
    }
}
Also used : JSONRPC2SessionException(com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException) JSONRPC2Session(com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session) JSONRPC2Request(com.thetransactioncompany.jsonrpc2.JSONRPC2Request)

Example 18 with JSONRPC2SessionException

use of com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException in project junit-plugin by kiwitcms.

the class RpcClient method logout.

public void logout() {
    JSONRPC2Session mySession = prepareSession();
    // Construct new request
    int requestID = 1;
    JSONRPC2Request request = new JSONRPC2Request(LOGOUT_METHOD, requestID);
    // Send request
    try {
        getResponse(mySession.send(request));
    } catch (JSONRPC2SessionException e) {
        System.err.println(e.getMessage());
    }
}
Also used : JSONRPC2SessionException(com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException) JSONRPC2Session(com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session) JSONRPC2Request(com.thetransactioncompany.jsonrpc2.JSONRPC2Request)

Example 19 with JSONRPC2SessionException

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

the class JsonRPCClient method getObjectParseJackson.

/**
 * 获取单个对象的接口(返回用Jackson封装,某些json格式用fastjson解析有问题,故此增加此方法)
 *
 * @param session
 * @param method    rpc接口的方法名
 * @param params    rpc接口的参数列表
 * @param requestId 请求id
 * @param clazz     返回对象的封装类
 * @return
 * @throws JSONRPC2SessionException
 */
protected T getObjectParseJackson(JSONRPC2Session session, String method, List<Object> params, int requestId, Class<T> clazz) throws JSONRPC2SessionException, IOException {
    JSONRPC2Request request = new JSONRPC2Request(method, params, requestId);
    JSONRPC2Response response = session.send(request);
    if (response.indicatesSuccess()) {
        Object result = response.getResult();
        if (result != null) {
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper.readValue(result.toString(), clazz);
        }
    }
    return null;
}
Also used : JSONRPC2Response(com.thetransactioncompany.jsonrpc2.JSONRPC2Response) JSONObject(com.alibaba.fastjson.JSONObject) JSONRPC2Request(com.thetransactioncompany.jsonrpc2.JSONRPC2Request) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 20 with JSONRPC2SessionException

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

the class JsonRPCClient method getSubObject.

/**
 * 获取单个对象的属性值接口
 *
 * @param session
 * @param method    rpc接口的方法名
 * @param params    rpc接口的参数列表
 * @param requestId 请求id
 * @param clazz     返回对象的封装类
 * @return
 * @throws JSONRPC2SessionException
 */
protected T getSubObject(JSONRPC2Session session, String method, List<Object> params, int requestId, String subKey, Class<T> clazz) throws JSONRPC2SessionException {
    JSONRPC2Request request = new JSONRPC2Request(method, params, requestId);
    JSONRPC2Response response = session.send(request);
    if (response.indicatesSuccess()) {
        Object result = response.getResult();
        if (result != null) {
            JSONObject jb = JSON.parseObject(result.toString());
            return jb.getObject(subKey, clazz);
        }
    }
    return null;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONRPC2Response(com.thetransactioncompany.jsonrpc2.JSONRPC2Response) JSONObject(com.alibaba.fastjson.JSONObject) JSONRPC2Request(com.thetransactioncompany.jsonrpc2.JSONRPC2Request)

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