org.fisco.bcos.web3j.tx.txdecode.BaseException Java Examples

The following examples show how to use org.fisco.bcos.web3j.tx.txdecode.BaseException. 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: TypeReferenceUtils.java    From WeBASE-Collect-Bee with Apache License 2.0 6 votes vote down vote up
public static TypeReference<?> getTypeRef(String solType) throws BaseException {
    AbiDefinition.NamedType.Type type = new AbiDefinition.NamedType.Type(solType);
    // nested array , not support now.
    if (type.getDepth() > 1) {
        throw new BaseException(201202, String.format("type:%s unsupported array decoding", type.getName()));
    }

    TypeReference<?> typeReference = null;
    if (type.dynamicArray()) {
        typeReference = DynamicArrayReference.create(type.getBaseName(), false);
    } else if (type.staticArray()) {
        typeReference = StaticArrayReference.create(type.getBaseName(), type.getDimensions(), false);
    } else {
        typeReference = TypeReference.create(ContractTypeUtil.getType(solType), false);
    }
    return typeReference;
}
 
Example #2
Source File: MethodUtils.java    From WeBASE-Collect-Bee with Apache License 2.0 6 votes vote down vote up
/**
 * Translate NamedType list to TypeReference<Type> list.
 * 
 * @param list
 * @return List<TypeReference<Type>>
 * @throws BaseException
 */
public static List<TypeReference<Type>> getMethodTypeReferenceList(List<NamedType> list) {
    List<TypeReference<Type>> referencesTypeList = Lists.newArrayList();
    for (NamedType type : list) {
        TypeReference reference;
        try {
            reference = TypeReferenceUtils.getTypeRef(type.getType().split(" ")[0]);
            log.debug("type: {} TypeReference converted: {}", type.getType(), JacksonUtils.toJson(reference));
            referencesTypeList.add(reference);
        } catch (BaseException e) {
            log.error("BaseException: ", e);
            return null;
        }
    }
    return referencesTypeList;
}
 
Example #3
Source File: TypeReferenceUtils.java    From WeBASE-Codegen-Monkey with Apache License 2.0 6 votes vote down vote up
public static TypeReference<?> getTypeRef(String solType) throws BaseException {
    AbiDefinition.NamedType.Type type = new AbiDefinition.NamedType.Type(solType);
    // nested array , not support now.
    if (type.getDepth() > 1) {
        throw new BaseException(201202, String.format("type:%s unsupported array decoding", type.getName()));
    }

    TypeReference<?> typeReference = null;
    if (type.dynamicArray()) {
        typeReference = DynamicArrayReference.create(type.getBaseName(), false);
    } else if (type.staticArray()) {
        typeReference = StaticArrayReference.create(type.getBaseName(), type.getDimensions(), false);
    } else {
        typeReference = TypeReference.create(ContractTypeUtil.getType(solType), false);
    }
    return typeReference;
}
 
Example #4
Source File: TypeReferenceUtils.java    From WeBASE-Codegen-Monkey with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public static JavaBasicTypeBO convertType(String solType) {
    try {
        TypeReference t = getTypeRef(solType);
        String json = JacksonUtils.toJson(t);
        JavaBasicTypeBO bo = JacksonUtils.fromJson(json, JavaBasicTypeBO.class);
        if (StringUtils.contains(bo.getClassType(), "Array")) {
            JavaArrayTypeBO a = JacksonUtils.fromJson(json, JavaArrayTypeBO.class);
            a.setArray(true);
            return a;
        } else {
            bo.setArray(false);
            return bo;
        }

    } catch (BaseException e) {
        log.error("SolType {} can't be converted", solType);
        return null;
    }

}
 
Example #5
Source File: ContractEventCallback.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
@Override
public LogResult transferLogToLogResult(Log log) {
    try {
        LogResult logResult = getDecoder().decodeEventLogReturnObject(log);
        return logResult;
    } catch (BaseException e) {
        logger.warn(" event log decode failed, log: {}", log);
        return null;
    }
}
 
Example #6
Source File: FunctionTest.java    From WeBASE-Collect-Bee with Apache License 2.0 5 votes vote down vote up
@Test
public void testInput() throws IOException, BaseException {
    BigInteger bigBlockHeight = new BigInteger(Integer.toString(8));
    Block block = ethClient.getBlock(bigBlockHeight);
    List<TransactionResult> transactionResults = block.getTransactions();
    log.info("transactionResults.size:{}", transactionResults.size());
    for (TransactionResult result : transactionResults) {
        BcosTransactionReceipt ethGetTransactionReceipt = web3j.getTransactionReceipt((String) result.get()).send();
        Optional<TransactionReceipt> opt = ethGetTransactionReceipt.getTransactionReceipt();
        if (opt.isPresent()) {
            log.info("TransactionReceipt hash: {}", opt.get().getTransactionHash());
            Optional<Transaction> optt =
                    web3j.getTransactionByHash(opt.get().getTransactionHash()).send().getTransaction();
            if (optt.isPresent()) {
                String rawInput = optt.get().getInput();

                log.info("input : {}", optt.get().getInput());
                List<TypeReference<Type>> referencesTypeList = new ArrayList<>(1);
                TypeReference exScore = TypeReferenceUtils.getTypeRef("uint128");
                referencesTypeList.add(exScore);
                TypeReference operationType = TypeReferenceUtils.getTypeRef("uint8");
                referencesTypeList.add(operationType);

                List<Type> listT = FunctionReturnDecoder.decode(rawInput.substring(10), referencesTypeList);
                for (Type type : listT) {
                    log.info("type value : {}", type.getValue());
                }
                log.info("type info : {}", JacksonUtils.toJson(listT));
            }
        }
    }
}
 
Example #7
Source File: FunctionTest.java    From WeBASE-Collect-Bee with Apache License 2.0 5 votes vote down vote up
public void testActivity() throws IOException, BaseException {
    BigInteger bigBlockHeight = new BigInteger(Integer.toString(200));
    Block block = ethClient.getBlock(bigBlockHeight);
    List<TransactionResult> transactionResults = block.getTransactions();
    log.info("transactionResults.size:{}", transactionResults.size());
    for (TransactionResult result : transactionResults) {
        BcosTransactionReceipt ethGetTransactionReceipt = web3j.getTransactionReceipt((String) result.get()).send();
        Optional<TransactionReceipt> opt = ethGetTransactionReceipt.getTransactionReceipt();
        if (opt.isPresent()) {
            log.info("TransactionReceipt hash: {}", opt.get().getTransactionHash());
            Optional<Transaction> optt =
                    web3j.getTransactionByHash(opt.get().getTransactionHash()).send().getTransaction();
            if (optt.isPresent()) {
                String rawInput = optt.get().getInput();
                log.info("input : {}", optt.get().getInput());
                List<TypeReference<Type>> referencesTypeList = new ArrayList<>(1);
                TypeReference exScore = TypeReferenceUtils.getTypeRef("uint64");
                referencesTypeList.add(exScore);

                List<Type> listT = FunctionReturnDecoder.decode(rawInput.substring(10), referencesTypeList);
                for (Type type : listT) {
                    log.info("type value : {}", type.getValue());
                }
                log.info("type info : {}", JacksonUtils.toJson(listT));
            }
        }
    }
}
 
Example #8
Source File: MethodParserTest.java    From WeBASE-Codegen-Monkey with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testGetField() throws BaseException, ClassNotFoundException {
    String methodMetaInfoStr =
            "{\"contractName\":\"AccessRestriction\",\"name\":\"revokeUser\",\"shardingNO\":1,\"list\":null}";
    String inputsAddress = "[{\"name\":\"_user\",\"type\":\"address\",\"type0\":null,\"indexed\":false}]";
    String fieldList =
            "[{\"sqlName\":\"_user_\",\"solidityName\":\"_user\",\"javaName\":\"_user\",\"sqlType\":\"varchar(255)\",\"solidityType\":\"Address\",\"javaType\":\"String\",\"entityType\":null,\"typeMethod\":\"AddressUtils.bigIntegerToString\",\"javaCapName\":\"_user\",\"length\":0}]";
    MethodMetaInfo mmi = JacksonUtils.fromJson(methodMetaInfoStr, MethodMetaInfo.class);
    List<NamedType> nt = JacksonUtils.fromJson(inputsAddress, List.class, NamedType.class);
    List<FieldVO> list = methodParser.getFieldList(mmi, nt);
    
    String methodMetaInfoStaticArrayStr =
            "{\"contractName\":\"RecordData\",\"name\":\"insertRecord\",\"shardingNO\":1,\"list\":null}";
    String inputsStaticArray = "[{\"name\":\"record\",\"type\":\"bytes[]\",\"type0\":null,\"indexed\":false}]";
    String fieldList2 =
            "[{\"sqlName\":\"_record_\",\"solidityName\":\"record\",\"javaName\":\"record\",\"sqlType\":\"varchar(10240)\",\"solidityType\":\"DynamicArray<bytes>\",\"javaType\":\"String\",\"entityType\":null,\"typeMethod\":\"BytesUtils.dynamicBytesListObjectToString\",\"javaCapName\":\"Record\",\"length\":0}]";
    MethodMetaInfo mmi2 = JacksonUtils.fromJson(methodMetaInfoStaticArrayStr, MethodMetaInfo.class);
    List<NamedType> nt2 = JacksonUtils.fromJson(inputsStaticArray, List.class, NamedType.class);
    List<FieldVO> list2 = methodParser.getFieldList(mmi2, nt2);
    
    List<TypeReference<?>> listOfTypeReference = ContractAbiUtil.paramFormat(nt);
    System.out.println(JacksonUtils.toJson(listOfTypeReference));
    System.out.println(JacksonUtils.toJson(ContractAbiUtil.paramFormat(nt2)));
    
    for(NamedType n : nt2) {
       Type type = new Type(n.getType());
       System.out.println(JacksonUtils.toJson(type));
       TypeReference<?> tr = DynamicArrayReference.create(type.getBaseName(), n.isIndexed());
       System.out.println(tr.getClass().getSimpleName());
    }     
}
 
Example #9
Source File: AbiTypeRefUtilsTest.java    From WeBASE-Codegen-Monkey with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Test
public void testTypeReference() throws BaseException {
    System.out.println(JacksonUtils.toJson(TypeReferenceUtils.getTypeRef("address")));
    System.out.println(JacksonUtils.toJson(TypeReferenceUtils.getTypeRef("bytes[]")));
    System.out.println(JacksonUtils.toJson(TypeReferenceUtils.getTypeRef("address[2]")));
    System.out.println(JacksonUtils.toJson(TypeReferenceUtils.getTypeRef("uint8[2]")));
    TypeReference t = TypeReferenceUtils.getTypeRef("address[2]");
    JavaArrayTypeBO bo = JacksonUtils.fromJson(JacksonUtils.toJson(t), JavaArrayTypeBO.class);
    System.out.println();
    Assertions.assertEquals("org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray2", bo.getType().getRawType());
    Assertions.assertEquals("org.fisco.bcos.web3j.abi.datatypes.Address",
            bo.getType().getActualTypeArguments().get(0));    
}
 
Example #10
Source File: EventLogPushWithDecodeCallback.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@Override
public LogResult transferLogToLogResult(Log log) {
    try {
        LogResult logResult = getDecoder().decodeEventLogReturnObject(log);
        return logResult;
    } catch (BaseException e) {
        logger.warn(" event log decode failed, log: {}", log);
        return null;
    }
}