Search in sources :

Example 1 with Function

use of com.citahub.cita.abi.datatypes.Function in project PCNGateway-Java-SDK by BSNDA.

the class TransactionService method getAddFuncData.

/**
 * Get FuncData
 *
 * @param req
 * @return
 */
@NotNull
private static String getAddFuncData(@NotNull ReqKeyUpload req) {
    // params
    List<Type> inputs = new ArrayList<>();
    switch(req.getFuncName()) {
        case "insert":
        case "update":
            inputs.add(new Bytes32(Common.getByte32String(req.getArgs()[0])));
            inputs.add(new DynamicBytes(req.getArgs()[1].getBytes()));
            break;
        case "retrieve":
        case "remove":
            inputs.add(new Bytes32(Common.getByte32String(req.getArgs()[0])));
            break;
        case "keyAtIndex":
            inputs.add(new Uint256(Long.parseLong(req.getArgs()[0])));
            break;
        default:
    }
    if (inputs.size() == 0) {
        throw new GlobalException(ResultInfoEnum.FUNCTION_ERROR);
    }
    // Function
    Function addFunc = new Function(req.getFuncName(), inputs, Collections.emptyList());
    return FunctionEncoder.encode(addFunc);
}
Also used : Function(com.citahub.cita.abi.datatypes.Function) Type(com.citahub.cita.abi.datatypes.Type) DynamicBytes(com.citahub.cita.abi.datatypes.DynamicBytes) ArrayList(java.util.ArrayList) Uint256(com.citahub.cita.abi.datatypes.generated.Uint256) Bytes32(com.citahub.cita.abi.datatypes.generated.Bytes32) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GlobalException (com.bsnbase.sdk.util.exception.GlobalException)1 DynamicBytes (com.citahub.cita.abi.datatypes.DynamicBytes)1 Function (com.citahub.cita.abi.datatypes.Function)1 Type (com.citahub.cita.abi.datatypes.Type)1 Bytes32 (com.citahub.cita.abi.datatypes.generated.Bytes32)1 Uint256 (com.citahub.cita.abi.datatypes.generated.Uint256)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1