Search in sources :

Example 1 with Uint8

use of org.bcos.web3j.abi.datatypes.generated.Uint8 in project web3sdk by FISCO-BCOS.

the class CAActionTools method processCAAction.

static void processCAAction(ApplicationContext ctx, CAAction caActions, String[] args) {
    try {
        switch(args[1]) {
            case "update":
            case "updateStatus":
                if (args.length < 3) {
                    System.out.println("Please input: ca.json");
                    break;
                }
                System.out.println("ca.json=" + args[2]);
                Resource template = ctx.getResource(args[2]);
                InputStream ksInputStream = template.getInputStream();
                ObjectMapper mapper = new ObjectMapper();
                mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
                CaInfo caInfo = mapper.readValue(ksInputStream, CaInfo.class);
                if (args[1].equals("update")) {
                    caActions.update(new Utf8String(caInfo.getHash()), new Utf8String(caInfo.getPubkey()), new Utf8String(caInfo.getOrgname()), new Uint256(caInfo.getNotbefore()), new Uint256(caInfo.getNotafter()), new Uint8(caInfo.getStatus()), new Utf8String(caInfo.getWhitelist()), new Utf8String(caInfo.getBlacklist())).get();
                } else {
                    caActions.updateStatus(new Utf8String(caInfo.getHash()), new Uint8(caInfo.getStatus())).get();
                }
            case "all":
                Uint256 len = caActions.getHashsLength().get();
                System.out.println("HashsLength= " + len);
                for (int i = 0; i < len.getValue().intValue(); i++) {
                    System.out.println("----------CA " + i + "---------");
                    Utf8String hash = caActions.getHash(new Uint256(i)).get();
                    System.out.println("hash=" + hash);
                    List<Type> ca = caActions.get(hash).get();
                    System.out.println("pubkey=" + ca.get(1));
                    System.out.println("orgname=" + ca.get(2));
                    System.out.println("notbefore=" + ca.get(3));
                    System.out.println("notafter=" + ca.get(4));
                    System.out.println("status=" + ca.get(5));
                    System.out.println("blocknumber=" + ca.get(6));
                    List<Type> iplist = caActions.getIp(hash).get();
                    System.out.println("whitelist=" + iplist.get(0));
                    System.out.println("blacklist=" + iplist.get(1));
                }
                break;
            default:
                break;
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}
Also used : Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) Uint8(org.bcos.web3j.abi.datatypes.generated.Uint8) Type(org.bcos.web3j.abi.datatypes.Type) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) Uint256(org.bcos.web3j.abi.datatypes.generated.Uint256) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with Uint8

use of org.bcos.web3j.abi.datatypes.generated.Uint8 in project web3sdk by FISCO-BCOS.

the class NodeActionTools method processNodeAction.

static void processNodeAction(ApplicationContext ctx, NodeAction nodeAction, String[] args) {
    try {
        switch(args[1]) {
            case "cancelNode":
            case "registerNode":
                if (args.length < 3) {
                    System.out.println("Please input: node.json");
                    break;
                }
                System.out.println("node.json=" + args[2]);
                Resource template = ctx.getResource(args[2]);
                InputStream ksInputStream = template.getInputStream();
                ObjectMapper mapper = new ObjectMapper();
                mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
                NodeInfo nodeInfo = mapper.readValue(ksInputStream, NodeInfo.class);
                if (args[1].equals("cancelNode")) {
                    nodeAction.cancelNode(new Utf8String(nodeInfo.getId())).get();
                } else {
                    nodeAction.registerNode(new Utf8String(nodeInfo.getId()), new Utf8String(nodeInfo.getIp()), new Uint256(nodeInfo.getPort()), new Uint8(nodeInfo.getCategory()), new Utf8String(nodeInfo.getDesc()), new Utf8String(nodeInfo.getCAhash()), new Utf8String(nodeInfo.getAgencyinfo()), new Uint256(nodeInfo.getIdx())).get();
                }
            case "all":
                Uint256 len = nodeAction.getNodeIdsLength().get();
                System.out.println("NodeIdsLength= " + len.getValue().intValue());
                for (int i = 0; i < len.getValue().intValue(); i++) {
                    System.out.println("----------node " + i + "---------");
                    Utf8String id = nodeAction.getNodeId(new Uint256(i)).get();
                    System.out.println("id=" + id);
                    List<Type> node = nodeAction.getNode(id).get();
                    System.out.println("ip=" + node.get(0));
                    System.out.println("port=" + ((BigInteger) (node.get(1).getValue())).intValue());
                    System.out.println("category=" + ((BigInteger) (node.get(2).getValue())).intValue());
                    System.out.println("desc=" + node.get(3));
                    System.out.println("CAhash=" + node.get(4));
                    System.out.println("agencyinfo=" + node.get(5));
                    System.out.println("blocknumber=" + ((BigInteger) (node.get(2).getValue())).intValue());
                    System.out.println("Idx=" + ((BigInteger) (nodeAction.getNodeIdx(id).get()).getValue()).intValue());
                }
                break;
            default:
                break;
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}
Also used : Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) Uint8(org.bcos.web3j.abi.datatypes.generated.Uint8) Type(org.bcos.web3j.abi.datatypes.Type) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) BigInteger(java.math.BigInteger) Uint256(org.bcos.web3j.abi.datatypes.generated.Uint256) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 InputStream (java.io.InputStream)2 Type (org.bcos.web3j.abi.datatypes.Type)2 Utf8String (org.bcos.web3j.abi.datatypes.Utf8String)2 Uint256 (org.bcos.web3j.abi.datatypes.generated.Uint256)2 Uint8 (org.bcos.web3j.abi.datatypes.generated.Uint8)2 Resource (org.springframework.core.io.Resource)2 BigInteger (java.math.BigInteger)1