org.fisco.bcos.web3j.precompile.exception.PrecompileMessageException Java Examples

The following examples show how to use org.fisco.bcos.web3j.precompile.exception.PrecompileMessageException. 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: CRUDService.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
public int insert(Table table, Entry entry) 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
                            + ").");
        }
        String entryJsonStr =
                ObjectMapperFactory.getObjectMapper().writeValueAsString(entry.getFields());

        TransactionReceipt receipt =
                crud.insert(table.getTableName(), table.getKey(), entryJsonStr, table.getOptional())
                        .send();
        return PrecompiledCommon.handleTransactionReceiptForCRUD(receipt);
    }
 
Example #2
Source File: CRUDService.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
public int update(Table table, Entry entry, 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
                            + ").");
        }
        String entryJsonStr =
                ObjectMapperFactory.getObjectMapper().writeValueAsString(entry.getFields());
        String conditionStr =
                ObjectMapperFactory.getObjectMapper().writeValueAsString(condition.getConditions());
        TransactionReceipt receipt =
                crud.update(
                                table.getTableName(),
                                table.getKey(),
                                entryJsonStr,
                                conditionStr,
                                table.getOptional())
                        .send();
        return PrecompiledCommon.handleTransactionReceiptForCRUD(receipt);
    }
 
Example #3
Source File: PrecompiledWithSignService.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
private void checkTableKeyLength(Table table) throws PrecompileMessageException {
    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 + ").");
    }
}
 
Example #4
Source File: CRUDService.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public int remove(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
                            + ").");
        }
        String conditionStr =
                ObjectMapperFactory.getObjectMapper().writeValueAsString(condition.getConditions());
        TransactionReceipt receipt =
                crud.remove(table.getTableName(), table.getKey(), conditionStr, table.getOptional())
                        .send();
        return PrecompiledCommon.handleTransactionReceiptForCRUD(receipt);
    }
 
Example #5
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 #6
Source File: CRUDService.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public Table desc(String tableName) throws Exception {
    Table table = new Table();
    table.setTableName(PrecompiledCommon.SYS_TABLE);

    /** Compatible with node version 2.2.0 */
    try {
        String supportedVersion =
                crud.getTransactionManager().getNodeVersion().getSupportedVersion();
        EnumNodeVersion.Version version = EnumNodeVersion.getClassVersion(supportedVersion);

        logger.debug("desc, table: {}, node version: {}", tableName, version);

        // less than 2.2.0
        if ((version.getMajor() == 2) && (version.getMinor() < 2)) {
            table.setKey(PrecompiledCommon.USER_TABLE_PREFIX + tableName);
        } else {
            table.setKey(PrecompiledCommon.USER_TABLE_PREFIX_2_2_0_VERSION + tableName);
        }
    } catch (Exception e) {
        throw new PrecompileMessageException(
                " Cannot query node version, maybe disconnect to all nodes.");
    }

    Condition condition = table.getCondition();
    List<Map<String, String>> userTable = select(table, condition);
    Table tableInfo = new Table();
    if ((userTable != null)
            && (userTable.size() != 0)
            && (null != userTable.get(0))
            && !userTable.get(0).isEmpty()) {
        tableInfo.setTableName(tableName);
        tableInfo.setKey(userTable.get(0).get("key_field"));
        tableInfo.setValueFields(userTable.get(0).get("value_field"));
    } else {
        throw new PrecompileMessageException("The table '" + tableName + "' does not exist.");
    }
    return tableInfo;
}
 
Example #7
Source File: CnsService.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
public String getAddressByContractNameAndVersion(String contractNameAndVersion) {

        if (!isValidCnsName(contractNameAndVersion)) {
            return contractNameAndVersion;
        }
        CNS cns;
        cns = lookupResolver();
        String contractAddressInfo;
        String address;

        try {
            // if has version
            if (contractNameAndVersion.contains(":")) {
                String contractName = contractNameAndVersion.split(":")[0];
                String contractVersion = contractNameAndVersion.split(":")[1];
                contractAddressInfo =
                        cns.selectByNameAndVersion(contractName, contractVersion).send();
                if ("[\n]".equals(contractAddressInfo)) {
                    throw new PrecompileMessageException("The contract version does not exist.");
                }
                logger.debug("query contractName {}", contractAddressInfo);
                List<CnsInfo> cNSInfos = jsonToCNSInfos(contractAddressInfo);
                address = cNSInfos.get(0).getAddress();
            } else {
                // only contract name
                contractAddressInfo = cns.selectByName(contractNameAndVersion).send();
                if ("[\n]".equals(contractAddressInfo)) {
                    throw new PrecompileMessageException("The contract version does not exist.");
                }
                logger.debug("query contractName {} ", contractAddressInfo);
                List<CnsInfo> CNSInfos = jsonToCNSInfos(contractAddressInfo);
                CnsInfo c = CNSInfos.get(CNSInfos.size() - 1);
                address = c.getAddress();
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        if (!WalletUtils.isValidAddress(address)) {
            throw new RuntimeException(
                    "Unable to resolve address for name: " + contractNameAndVersion);
        } else {
            return address;
        }
    }
 
Example #8
Source File: PermissionServiceTest.java    From web3sdk with Apache License 2.0 2 votes vote down vote up
@Test(expected= PrecompileMessageException.class) 
public void userTableManager() throws Exception {
	
 permissionService.grantUserTableManager("tt", Common.TX_ORIGIN);

}