Java Code Examples for org.fisco.bcos.web3j.protocol.ObjectMapperFactory#getObjectMapper()

The following examples show how to use org.fisco.bcos.web3j.protocol.ObjectMapperFactory#getObjectMapper() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransService.java    From WeBASE-Front with Apache License 2.0 6 votes vote down vote up
/**
 * checkAndSaveAbiFromDb.
 *
 * @param req request
 */
public boolean checkAndSaveAbiFromDb(ContractOfTrans req) throws Exception {
    Contract contract = contractRepository.findByGroupIdAndContractPathAndContractName(
            req.getGroupId(), req.getContractPath(), req.getContractName());
    log.info("checkAndSaveAbiFromDb contract:{}", contract);
    if (Objects.isNull(contract)) {
        log.info("checkAndSaveAbiFromDb contract is null");
        return false;
    }
    // save abi
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    List<AbiDefinition> abiDefinitionList =
            objectMapper.readValue(contract.getContractAbi(), objectMapper.getTypeFactory()
                    .constructCollectionType(List.class, AbiDefinition.class));
    ContractAbiUtil.setFunctionFromAbi(req.getContractName(), req.getContractPath(),
            abiDefinitionList, new ArrayList<>());
    return true;
}
 
Example 2
Source File: WalletUtils.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
public static String generateWalletFile(
        String password, ECKeyPair ecKeyPair, File destinationDirectory, boolean useFullScrypt)
        throws CipherException, IOException {

    WalletFile walletFile;
    if (useFullScrypt) {
        walletFile = Wallet.createStandard(password, ecKeyPair);
    } else {
        walletFile = Wallet.createLight(password, ecKeyPair);
    }

    String fileName = getWalletFileName(walletFile);
    File destination = new File(destinationDirectory, fileName);

    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    objectMapper.writeValue(destination, walletFile);

    return fileName;
}
 
Example 3
Source File: TransactionDecoder.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
/**
 * @param logs
 * @return
 * @throws BaseException
 * @throws IOException
 */
public String decodeEventReturnJson(String logs) throws BaseException, IOException {
    // log json trans to list log
    ObjectMapper mapper = ObjectMapperFactory.getObjectMapper();
    CollectionType listType =
            mapper.getTypeFactory().constructCollectionType(ArrayList.class, Log.class);
    @SuppressWarnings("unchecked")
    List<Log> logList = (List<Log>) mapper.readValue(logs, listType);

    // decode event
    Map<String, List<List<EventResultEntity>>> resultEntityMap =
            decodeEventReturnObject(logList);
    String result = mapper.writeValueAsString(resultEntityMap);

    return result;
}
 
Example 4
Source File: ContractAbiUtil.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
/**
 * @param contractAbi
 * @return
 */
public static AbiDefinition getConstructorAbiDefinition(String contractAbi) {
    try {
        ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
        AbiDefinition[] abiDefinitions =
                objectMapper.readValue(contractAbi, AbiDefinition[].class);

        for (AbiDefinition abiDefinition : abiDefinitions) {
            if (TYPE_CONSTRUCTOR.equals(abiDefinition.getType())) {
                return abiDefinition;
            }
        }
    } catch (JsonProcessingException e) {
        logger.warn(" invalid  json, abi: {}, e: {} ", contractAbi, e);
    }
    return null;
}
 
Example 5
Source File: ContractAbiUtil.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
/**
 * @param contractAbi
 * @return
 */
public static List<AbiDefinition> getFuncAbiDefinition(String contractAbi) {
    List<AbiDefinition> result = new ArrayList<>();
    try {
        ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
        AbiDefinition[] abiDefinitions =
                objectMapper.readValue(contractAbi, AbiDefinition[].class);

        for (AbiDefinition abiDefinition : abiDefinitions) {
            if (TYPE_FUNCTION.equals(abiDefinition.getType())
                    || TYPE_CONSTRUCTOR.equals(abiDefinition.getType())) {
                result.add(abiDefinition);
            }
        }
    } catch (JsonProcessingException e) {
        logger.warn(" invalid json, abi: {}, e: {} ", contractAbi, e);
    }
    return result;
}
 
Example 6
Source File: ContractAbiUtil.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
/**
 * @param contractAbi
 * @return
 */
public static List<AbiDefinition> getEventAbiDefinitions(String contractAbi) {

    List<AbiDefinition> result = new ArrayList<>();
    try {
        ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
        AbiDefinition[] abiDefinitions =
                objectMapper.readValue(contractAbi, AbiDefinition[].class);

        for (AbiDefinition abiDefinition : abiDefinitions) {
            if (TYPE_EVENT.equals(abiDefinition.getType())) {
                result.add(abiDefinition);
            }
        }
    } catch (JsonProcessingException e) {
        logger.warn(" invalid json, abi: {}, e: {} ", contractAbi, e);
    }
    return result;
}
 
Example 7
Source File: ChainGovernanceService.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public List<PermissionInfo> listCommitteeMembers() throws Exception {
    String committeeMembersInfo = chainGovernance.listCommitteeMembers().send();
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    return objectMapper.readValue(
            committeeMembersInfo,
            objectMapper
                    .getTypeFactory()
                    .constructCollectionType(List.class, PermissionInfo.class));
}
 
Example 8
Source File: CRUDService.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public List<Map<String, String>> select(Table table, Condition condition) throws Exception {

    if (table.getKey().length() > PrecompiledCommon.TABLE_KEY_MAX_LENGTH) {
        throw new PrecompileMessageException(
                "The value of the table key exceeds the maximum limit("
                        + PrecompiledCommon.TABLE_KEY_MAX_LENGTH
                        + ").");
    }
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    String conditionJsonStr = objectMapper.writeValueAsString(condition.getConditions());
    String resultStr =
            crud.select(
                            table.getTableName(),
                            table.getKey(),
                            conditionJsonStr,
                            table.getOptional())
                    .send();
    List<Map<String, String>> result =
            (List<Map<String, String>>)
                    objectMapper.readValue(
                            resultStr,
                            objectMapper
                                    .getTypeFactory()
                                    .constructCollectionType(List.class, Map.class));
    return result;
}
 
Example 9
Source File: CnsService.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
private List<CnsInfo> jsonToCNSInfos(String contractAddressInfo) throws IOException {

        ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
        List<CnsInfo> cnsInfo =
                objectMapper.readValue(
                        contractAddressInfo,
                        objectMapper
                                .getTypeFactory()
                                .constructCollectionType(List.class, CnsInfo.class));
        return cnsInfo;
    }
 
Example 10
Source File: CnsService.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public List<CnsInfo> queryCnsByNameAndVersion(String name, String version) throws Exception {
    CNS cns = lookupResolver();
    String cnsInfo = cns.selectByNameAndVersion(name, version).send();
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    return objectMapper.readValue(
            cnsInfo,
            objectMapper.getTypeFactory().constructCollectionType(List.class, CnsInfo.class));
}
 
Example 11
Source File: CnsService.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public List<CnsInfo> queryCnsByName(String name) throws Exception {
    CNS cns = lookupResolver();
    String cnsInfo = cns.selectByName(name).send();
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    return objectMapper.readValue(
            cnsInfo,
            objectMapper.getTypeFactory().constructCollectionType(List.class, CnsInfo.class));
}
 
Example 12
Source File: PermissionService.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
private List<PermissionInfo> list(String tableName) throws Exception {
    String permissionyInfo = permission.queryByName(tableName).send();
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    return objectMapper.readValue(
            permissionyInfo,
            objectMapper
                    .getTypeFactory()
                    .constructCollectionType(List.class, PermissionInfo.class));
}
 
Example 13
Source File: PermissionService.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public List<PermissionInfo> queryPermission(String address) throws Exception {
    String permissionyInfo = permission.queryPermission(address).send();
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    return objectMapper.readValue(
            permissionyInfo,
            objectMapper
                    .getTypeFactory()
                    .constructCollectionType(List.class, PermissionInfo.class));
}
 
Example 14
Source File: ChainGovernanceService.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public List<PermissionInfo> listOperators() throws Exception {
    String operatorsInfo = chainGovernance.listOperators().send();
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    return objectMapper.readValue(
            operatorsInfo,
            objectMapper
                    .getTypeFactory()
                    .constructCollectionType(List.class, PermissionInfo.class));
}
 
Example 15
Source File: WebSocketService.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public WebSocketService(
        WebSocketClient webSocketClient,
        ScheduledExecutorService executor,
        boolean includeRawResponses) {
    this.webSocketClient = webSocketClient;
    this.executor = executor;
    this.objectMapper = ObjectMapperFactory.getObjectMapper(includeRawResponses);
}
 
Example 16
Source File: Web3Tools.java    From WeBASE-Node-Manager with Apache License 2.0 4 votes vote down vote up
/**
 * abi string to AbiDefinition.
 */
public static List<AbiDefinition> loadContractDefinition(String abi) throws IOException {
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    AbiDefinition[] abiDefinition = objectMapper.readValue(abi, AbiDefinition[].class);
    return Arrays.asList(abiDefinition);
}
 
Example 17
Source File: TruffleJsonFunctionWrapperGenerator.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
static Contract loadContractDefinition(File jsonFile) throws IOException {
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    return objectMapper.readValue(jsonFile, Contract.class);
}
 
Example 18
Source File: ContractAbiUtil.java    From WeBASE-Front with Apache License 2.0 4 votes vote down vote up
/**
 * loadContractDefinition.
 *
 * @param abiFile file
 */
public static List<AbiDefinition> loadContractDefinition(File abiFile) throws IOException {
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    AbiDefinition[] abiDefinition = objectMapper.readValue(abiFile, AbiDefinition[].class);
    return Arrays.asList(abiDefinition);
}
 
Example 19
Source File: WalletUtils.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
public static Credentials loadCredentials(String password, File source)
        throws IOException, CipherException {
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    WalletFile walletFile = objectMapper.readValue(source, WalletFile.class);
    return Credentials.create(Wallet.decrypt(password, walletFile));
}
 
Example 20
Source File: SolidityFunctionWrapperGenerator.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
static List<AbiDefinition> loadContractDefinition(File absFile) throws IOException {
    ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
    AbiDefinition[] abiDefinition = objectMapper.readValue(absFile, AbiDefinition[].class);
    return Arrays.asList(abiDefinition);
}