Search in sources :

Example 46 with RpcClientResult

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

the class CreateMultiAgentProcessor method execute.

@Override
public CommandResult execute(String[] args) {
    String signAddress = args[3];
    RpcClientResult res = CommandHelper.getPassword(signAddress, restFul);
    if (!res.isSuccess()) {
        return CommandResult.getFailed(res);
    }
    String password = (String) res.getData();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("agentAddress", args[1]);
    parameters.put("packingAddress", args[2]);
    parameters.put("signAddress", args[3]);
    parameters.put("commissionRate", Double.valueOf(args[4]));
    Long deposit = null;
    try {
        Na na = Na.parseNuls(args[5]);
        deposit = na.getValue();
    } catch (Exception e) {
        return CommandResult.getFailed("Parameter deposit error");
    }
    parameters.put("deposit", deposit);
    parameters.put("password", password);
    if (args.length == 7) {
        parameters.put("rewardAddress", args[6]);
    }
    RpcClientResult result = restFul.post("/consensus/multiAccount/createMultiAgent", parameters);
    if (result.isFailed()) {
        return CommandResult.getFailed(result);
    }
    return CommandResult.getResult(CommandResult.dataMultiTransformValue(result));
}
Also used : Na(io.nuls.kernel.model.Na) HashMap(java.util.HashMap) RpcClientResult(io.nuls.kernel.model.RpcClientResult)

Example 47 with RpcClientResult

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

the class GetAgentsProcessor method execute.

@Override
public CommandResult execute(String[] args) {
    int pageNumber = Integer.parseInt(args[1]);
    int pageSize = Integer.parseInt(args[2]);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("pageNumber", pageNumber);
    parameters.put("pageSize", pageSize);
    RpcClientResult result = restFul.get("/consensus/agent/list", 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("deposit", CommandHelper.naToNuls(map.get("deposit")));
        map.put("totalDeposit", CommandHelper.naToNuls(map.get("totalDeposit")));
        map.put("time", DateUtil.convertDate(new Date((Long) map.get("time"))));
        map.put("status", CommandHelper.consensusExplain((Integer) map.get("status")));
    }
    result.setData(list);
    return CommandResult.getResult(result);
}
Also used : HashMap(java.util.HashMap) RpcClientResult(io.nuls.kernel.model.RpcClientResult) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) Date(java.util.Date)

Example 48 with RpcClientResult

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

the class WithdrawMultiProcessor method execute.

@Override
public CommandResult execute(String[] args) {
    String signAddress = args[2];
    RpcClientResult res = CommandHelper.getPassword(signAddress, restFul);
    if (!res.isSuccess()) {
        return CommandResult.getFailed(res);
    }
    String password = (String) res.getData();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("address", args[1]);
    parameters.put("signAddress", args[2]);
    if (args.length == 4) {
        parameters.put("txdata", args[3]);
    } else {
        String[] pubkeys = args[3].split(",");
        parameters.put("pubkeys", Arrays.asList(pubkeys));
        parameters.put("m", Integer.parseInt(args[4]));
        parameters.put("txHash", Integer.parseInt(args[5]));
    }
    RpcClientResult result = restFul.post("/consensus/withdrawMutil", 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)

Example 49 with RpcClientResult

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

the class CreateAgentProcessor method execute.

@Override
public CommandResult execute(String[] args) {
    String address = args[1];
    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("agentAddress", address);
    parameters.put("packingAddress", args[2]);
    parameters.put("commissionRate", Double.valueOf(args[3]));
    Long deposit = null;
    try {
        Na na = Na.parseNuls(args[4]);
        deposit = na.getValue();
    } catch (Exception e) {
        return CommandResult.getFailed("Parameter deposit error");
    }
    parameters.put("deposit", deposit);
    parameters.put("password", password);
    if (args.length == 6) {
        parameters.put("rewardAddress", args[5]);
    }
    RpcClientResult result = restFul.post("/consensus/agent", parameters);
    if (result.isFailed()) {
        return CommandResult.getFailed(result);
    }
    return CommandResult.getResult(CommandResult.dataTransformValue(result));
}
Also used : Na(io.nuls.kernel.model.Na) HashMap(java.util.HashMap) RpcClientResult(io.nuls.kernel.model.RpcClientResult)

Example 50 with RpcClientResult

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

the class CreateMultiDepositProcessor method execute.

@Override
public CommandResult execute(String[] args) {
    String signAddress = args[2];
    RpcClientResult res = CommandHelper.getPassword(signAddress, restFul);
    if (!res.isSuccess()) {
        return CommandResult.getFailed(res);
    }
    String password = (String) res.getData();
    Long amount = Na.parseNuls(args[4]).getValue();
    Map<String, Object> parameters = new HashMap<>(4);
    parameters.put("address", args[1]);
    parameters.put("signAddress", args[2]);
    parameters.put("agentHash", args[3]);
    parameters.put("deposit", amount);
    parameters.put("password", password);
    RpcClientResult result = restFul.post("/consensus/multiAccount/createMultiDeposit", parameters);
    if (result.isFailed()) {
        return CommandResult.getFailed(result);
    }
    return CommandResult.getResult(CommandResult.dataMultiTransformValue(result));
}
Also used : HashMap(java.util.HashMap) RpcClientResult(io.nuls.kernel.model.RpcClientResult)

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