Search in sources :

Example 51 with RpcClientResult

use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.

the class GetDepositedInfoProcessor method execute.

@Override
public CommandResult execute(String[] args) {
    String address = args[1];
    RpcClientResult result = restFul.get("/consensus/address/" + address, null);
    if (result.isFailed()) {
        return CommandResult.getFailed(result);
    }
    Map<String, Object> map = (Map) result.getData();
    map.put("usableBalance", CommandHelper.naToNuls(map.get("usableBalance")));
    map.put("totalDeposit", CommandHelper.naToNuls(map.get("totalDeposit")));
    map.put("reward", CommandHelper.naToNuls(map.get("reward")));
    map.put("rewardOfDay", CommandHelper.naToNuls(map.get("rewardOfDay")));
    result.setData(map);
    return CommandResult.getResult(result);
}
Also used : RpcClientResult(io.nuls.kernel.model.RpcClientResult) Map(java.util.Map)

Example 52 with RpcClientResult

use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.

the class GetAccountTxListProcessor method execute.

@Override
public CommandResult execute(String[] args) {
    int type = 0;
    int pageNumber = 0;
    int pageSize = 0;
    if (args.length == 4) {
        pageNumber = Integer.parseInt(args[2]);
        pageSize = Integer.parseInt(args[3]);
    } else {
        type = Integer.parseInt(args[2]);
        pageNumber = Integer.parseInt(args[3]);
        pageSize = Integer.parseInt(args[4]);
    }
    String address = args[1];
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("type", type);
    parameters.put("pageNumber", pageNumber);
    parameters.put("pageSize", pageSize);
    RpcClientResult result = restFul.get("/accountledger/tx/list/" + address, parameters);
    if (result.isFailed()) {
        return CommandResult.getFailed(result);
    }
    List<Map<String, Object>> list = (List<Map<String, Object>>) ((Map) result.getData()).get("list");
    for (Map<String, Object> map : list) {
        map.put("time", DateUtil.convertDate(new Date((Long) map.get("time"))));
        map.put("txType", CommandHelper.txTypeExplain((Integer) map.get("txType")));
    }
    result.setData(list);
    return CommandResult.getResult(result);
}
Also used : HashMap(java.util.HashMap) RpcClientResult(io.nuls.kernel.model.RpcClientResult) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Example 53 with RpcClientResult

use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.

the class TransferProcessor method execute.

@Override
public CommandResult execute(String[] args) {
    TransferForm form = paramsData.get();
    if (null == form) {
        form = getTransferForm(args);
    }
    String address = form.getAddress();
    RpcClientResult res = CommandHelper.getPassword(address, restFul);
    if (!res.isSuccess()) {
        return CommandResult.getFailed(res);
    }
    String password = (String) res.getData();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("address", form.getAddress());
    parameters.put("toAddress", form.getToAddress());
    parameters.put("password", password);
    parameters.put("amount", form.getAmount());
    parameters.put("remark", form.getRemark());
    RpcClientResult result = restFul.post("/accountledger/transfer", parameters);
    if (result.isFailed()) {
        return CommandResult.getFailed(result);
    }
    return CommandResult.getResult(CommandResult.dataTransformValue(result));
}
Also used : HashMap(java.util.HashMap) RpcClientResult(io.nuls.kernel.model.RpcClientResult) TransferForm(io.nuls.accout.ledger.rpc.form.TransferForm)

Example 54 with RpcClientResult

use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.

the class ContractTxTest method loadUTXOs.

public List<InputDto> loadUTXOs() {
    String address = sender;
    Long limit = 100L;
    String url = "/utxo/limit/" + address + "/" + limit;
    RpcClientResult result = restFul.get(url, new HashMap());
    List<InputDto> utxos = new ArrayList<>();
    Map data = (Map) result.getData();
    List<Map<String, Object>> utxoList = (List<Map<String, Object>>) data.get("utxoDtoList");
    for (Map<String, Object> utxo : utxoList) {
        InputDto input = new InputDto();
        input.setAddress(address);
        input.setFromHash(utxo.get("txHash").toString());
        input.setFromIndex((int) utxo.get("txIndex"));
        input.setValue(Long.parseLong(utxo.get("value").toString()));
        input.setLockTime(Long.valueOf(utxo.get("lockTime").toString()));
        utxos.add(input);
    }
    return utxos;
}
Also used : RpcClientResult(io.nuls.kernel.model.RpcClientResult) InputDto(io.nuls.accout.ledger.rpc.dto.InputDto)

Example 55 with RpcClientResult

use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.

the class ContractTxTest method callContract.

@Test
public void callContract() {
    List<InputDto> utxos = loadUTXOs();
    String url = "/contract/sdk/call";
    String contractAddress = "NseA4LYf5kBXjrnag4xN8BjzgWx7YrVm";
    String sender = this.sender;
    Long value = 100_0000_0000L;
    Long gasLimit = 81325l;
    Long price = 25L;
    String methodName = "create";
    String methodDesc = "";
    Object[] args = { "test", "test desc", Arrays.asList("1", "2", "3"), "1542042000000", "1542646800000", "false", "1", "1", "false" };
    String remark = "test call contract";
    Map<String, Object> paramsMap = new HashMap<>();
    paramsMap.put("sender", sender);
    paramsMap.put("value", value);
    paramsMap.put("gasLimit", gasLimit);
    paramsMap.put("price", price);
    paramsMap.put("contractAddress", contractAddress);
    paramsMap.put("methodName", methodName);
    paramsMap.put("methodDesc", methodDesc);
    paramsMap.put("args", args);
    paramsMap.put("remark", remark);
    paramsMap.put("utxos", utxos);
    try {
        logger.info("{}", JSONUtils.obj2json(paramsMap));
        RpcClientResult result = restFul.post(url, paramsMap);
        logger.info("result {}", result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : RpcClientResult(io.nuls.kernel.model.RpcClientResult) InputDto(io.nuls.accout.ledger.rpc.dto.InputDto) Test(org.junit.Test)

Aggregations

RpcClientResult (io.nuls.kernel.model.RpcClientResult)88 HashMap (java.util.HashMap)49 Map (java.util.Map)24 Date (java.util.Date)14 List (java.util.List)14 Result (io.nuls.kernel.model.Result)7 InputDto (io.nuls.accout.ledger.rpc.dto.InputDto)5 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 NulsException (io.nuls.kernel.exception.NulsException)3 Na (io.nuls.kernel.model.Na)3 Node (io.nuls.network.model.Node)3 Test (org.junit.Test)3 RandomSeedDTO (io.nuls.consensus.poc.rpc.model.RandomSeedDTO)2 Coin (io.nuls.kernel.model.Coin)2 IOException (java.io.IOException)2 AccountKeyStoreDto (io.nuls.account.rpc.model.AccountKeyStoreDto)1