Search in sources :

Example 16 with Utf8String

use of org.fisco.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.

the class RevertResolver method tryResolveRevertMessage.

/**
 * @param status
 * @param output
 * @return
 */
public static Tuple2<Boolean, String> tryResolveRevertMessage(String status, String output) {
    if (!hasRevertMessage(status, output)) {
        return new Tuple2<>(false, null);
    }
    try {
        // 00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030497373756572526f6c653a2063616c6c657220646f6573206e6f742068617665207468652049737375657220726f6c6500000000000000000000000000000000
        String rawOutput = Numeric.containsHexPrefix(output) ? output.substring(RevertMethodWithHexPrefix.length()) : output.substring(RevertMethod.length());
        List<Type> result = FunctionReturnDecoder.decode(rawOutput, revertFunction.getOutputParameters());
        if (result.get(0) instanceof Utf8String) {
            String message = ((Utf8String) result.get(0)).getValue();
            if (logger.isDebugEnabled()) {
                logger.debug(" ABI: {} , RevertMessage: {}", output, message);
            }
            return new Tuple2<>(true, message);
        }
    } catch (Exception e) {
        logger.warn(" ABI: {}, e: {}", output, e);
    }
    return new Tuple2<>(false, null);
}
Also used : Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Type(org.fisco.bcos.web3j.abi.datatypes.Type) Tuple2(org.fisco.bcos.web3j.tuples.generated.Tuple2) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String)

Example 17 with Utf8String

use of org.fisco.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.

the class EvidenceVerify method getInsertEvidenceInput.

public Tuple8<String, String, String, String, byte[], BigInteger, byte[], byte[]> getInsertEvidenceInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function = new Function(FUNC_INSERTEVIDENCE, Arrays.<Type>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
    }, new TypeReference<Utf8String>() {
    }, new TypeReference<Utf8String>() {
    }, new TypeReference<Address>() {
    }, new TypeReference<Bytes32>() {
    }, new TypeReference<Uint8>() {
    }, new TypeReference<Bytes32>() {
    }, new TypeReference<Bytes32>() {
    }));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple8<String, String, String, String, byte[], BigInteger, byte[], byte[]>((String) results.get(0).getValue(), (String) results.get(1).getValue(), (String) results.get(2).getValue(), (String) results.get(3).getValue(), (byte[]) results.get(4).getValue(), (BigInteger) results.get(5).getValue(), (byte[]) results.get(6).getValue(), (byte[]) results.get(7).getValue());
}
Also used : Function(org.fisco.bcos.web3j.abi.datatypes.Function) EncryptType(org.fisco.bcos.web3j.crypto.EncryptType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) TypeReference(org.fisco.bcos.web3j.abi.TypeReference) Tuple8(org.fisco.bcos.web3j.tuples.generated.Tuple8)

Example 18 with Utf8String

use of org.fisco.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.

the class ResultEntity method typeToObject.

public static Object typeToObject(Type type) {
    Object obj = null;
    if (type instanceof NumericType) {
        // uint int
        obj = ((NumericType) type).getValue();
    } else if (type instanceof Bool) {
        // bool
        obj = ((Bool) type).getValue();
    } else if (type instanceof Address) {
        // address
        obj = type.toString();
    } else if (type instanceof Bytes) {
        // bytes32
        obj = new String(((Bytes) type).getValue()).trim();
    } else if (type instanceof DynamicBytes) {
        // bytes
        obj = new String(((DynamicBytes) type).getValue()).trim();
    } else if (type instanceof Utf8String) {
        // string
        obj = ((Utf8String) type).getValue();
    } else if (type instanceof Array) {
        // T[] T[k]
        List<Object> r = new ArrayList<Object>();
        List l = ((Array) type).getValue();
        for (int i = 0; i < l.size(); ++i) {
            r.add(typeToObject((Type) l.get(i)));
        }
        obj = (Object) r;
    } else {
        obj = (Object) obj;
    }
    return obj;
}
Also used : NumericType(org.fisco.bcos.web3j.abi.datatypes.NumericType) Address(org.fisco.bcos.web3j.abi.datatypes.Address) ArrayList(java.util.ArrayList) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Array(org.fisco.bcos.web3j.abi.datatypes.Array) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Bytes(org.fisco.bcos.web3j.abi.datatypes.Bytes) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) NumericType(org.fisco.bcos.web3j.abi.datatypes.NumericType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) Bool(org.fisco.bcos.web3j.abi.datatypes.Bool) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with Utf8String

use of org.fisco.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.

the class ABICodecJsonWrapper method encodeNode.

private ABIObject encodeNode(String path, ABIObject template, JsonNode node) {
    ABIObject abiObject = template.newObject();
    switch(abiObject.getType()) {
        case VALUE:
            {
                if (!node.isValueNode()) {
                    errorReport(path, abiObject.getType().toString(), node.getNodeType().toString());
                }
                switch(template.getValueType()) {
                    case BOOL:
                        {
                            if (!node.isBoolean()) {
                                errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
                            }
                            abiObject.setBoolValue(new Bool(node.asBoolean()));
                            break;
                        }
                    case INT:
                        {
                            if (!node.isNumber() && !node.isBigInteger()) {
                                errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
                            }
                            if (node.isNumber()) {
                                abiObject.setNumericValue(new Int256(node.asLong()));
                            } else {
                                abiObject.setNumericValue(new Int256(node.bigIntegerValue()));
                            }
                            break;
                        }
                    case UINT:
                        {
                            if (!node.isNumber() && !node.isBigInteger()) {
                                errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
                            }
                            if (node.isNumber()) {
                                abiObject.setNumericValue(new Uint256(node.asLong()));
                            } else {
                                abiObject.setNumericValue(new Uint256(node.bigIntegerValue()));
                            }
                            break;
                        }
                    case ADDRESS:
                        {
                            if (!node.isTextual()) {
                                errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
                            }
                            try {
                                abiObject.setAddressValue(new Address(node.asText()));
                            } catch (Exception e) {
                                errorReport(path, "Invalid address, address value: " + node.asText());
                            }
                            break;
                        }
                    case BYTES:
                        {
                            if (!node.isTextual()) {
                                errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
                            }
                            // Binary data requires base64 encoding
                            byte[] bytesValue = Base64.getDecoder().decode(node.asText());
                            abiObject.setBytesValue(new Bytes(bytesValue.length, bytesValue));
                            break;
                        }
                    case DBYTES:
                        {
                            if (!node.isTextual()) {
                                errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
                            }
                            byte[] bytesValue = Base64.getDecoder().decode(node.asText());
                            abiObject.setDynamicBytesValue(new DynamicBytes(bytesValue));
                            break;
                        }
                    case STRING:
                        {
                            if (!node.isTextual()) {
                                errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
                            }
                            abiObject.setStringValue(new Utf8String(node.asText()));
                            break;
                        }
                }
                break;
            }
        case LIST:
            {
                if (!node.isArray()) {
                    errorReport(path, abiObject.getType().toString(), node.getNodeType().toString());
                }
                if ((abiObject.getListType() == ListType.FIXED) && (node.size() != abiObject.getListLength())) {
                    errorReport("fixed list arguments size", String.valueOf(abiObject.getListLength()), String.valueOf(node.size()));
                }
                int i = 0;
                Iterator<JsonNode> iterator = node.iterator();
                while (iterator.hasNext()) {
                    abiObject.getListValues().add(encodeNode(path + ".<" + String.valueOf(i) + ">", abiObject.getListValueType(), iterator.next()));
                }
                break;
            }
        case STRUCT:
            {
                if (!node.isArray() && !node.isObject()) {
                    errorReport(path, abiObject.getType().toString(), node.getNodeType().toString());
                }
                if (node.size() != abiObject.getStructFields().size()) {
                    errorReport("struct arguments size", String.valueOf(abiObject.getListLength()), String.valueOf(node.size()));
                }
                if (node.isArray()) {
                    for (int i = 0; i < abiObject.getStructFields().size(); i++) {
                        ABIObject field = abiObject.getStructFields().get(i);
                        abiObject.getStructFields().set(i, encodeNode(path + "." + field.getName(), field, node.get(i)));
                    }
                } else {
                    for (int i = 0; i < abiObject.getStructFields().size(); ++i) {
                        ABIObject field = abiObject.getStructFields().get(i);
                        JsonNode structNode = node.get(field.getName());
                        if (structNode == null) {
                            errorReport(path, " Missing struct field, field name: " + field.getName());
                        }
                        abiObject.getStructFields().set(i, encodeNode(path + "." + field.getName(), field, structNode));
                    }
                }
                break;
            }
    }
    return abiObject;
}
Also used : Int256(org.fisco.bcos.web3j.abi.datatypes.generated.Int256) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Bytes(org.fisco.bcos.web3j.abi.datatypes.Bytes) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Address(org.fisco.bcos.web3j.abi.datatypes.Address) Bool(org.fisco.bcos.web3j.abi.datatypes.Bool) Iterator(java.util.Iterator) JsonNode(com.fasterxml.jackson.databind.JsonNode) Uint256(org.fisco.bcos.web3j.abi.datatypes.generated.Uint256) IOException(java.io.IOException) InvalidParameterException(java.security.InvalidParameterException)

Example 20 with Utf8String

use of org.fisco.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.

the class Permission method getInsertInput.

public Tuple2<String, String> getInsertInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function = new Function(FUNC_INSERT, Arrays.<Type>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
    }, new TypeReference<Utf8String>() {
    }));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple2<String, String>((String) results.get(0).getValue(), (String) results.get(1).getValue());
}
Also used : Function(org.fisco.bcos.web3j.abi.datatypes.Function) Type(org.fisco.bcos.web3j.abi.datatypes.Type) EncryptType(org.fisco.bcos.web3j.crypto.EncryptType) Tuple2(org.fisco.bcos.web3j.tuples.generated.Tuple2) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Aggregations

Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)30 DynamicBytes (org.fisco.bcos.web3j.abi.datatypes.DynamicBytes)20 Bool (org.fisco.bcos.web3j.abi.datatypes.Bool)19 Int256 (org.fisco.bcos.web3j.abi.datatypes.generated.Int256)19 Type (org.fisco.bcos.web3j.abi.datatypes.Type)18 Test (org.junit.Test)18 Address (org.fisco.bcos.web3j.abi.datatypes.Address)17 Uint256 (org.fisco.bcos.web3j.abi.datatypes.generated.Uint256)17 TypeReference (org.fisco.bcos.web3j.abi.TypeReference)13 Bytes32 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32)12 NamedType (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType)11 Function (org.fisco.bcos.web3j.abi.datatypes.Function)10 DynamicArray (org.fisco.bcos.web3j.abi.datatypes.DynamicArray)9 Event (org.fisco.bcos.web3j.abi.datatypes.Event)9 ArrayList (java.util.ArrayList)7 List (java.util.List)6 Log (org.fisco.bcos.web3j.protocol.core.methods.response.Log)5 Bytes (org.fisco.bcos.web3j.abi.datatypes.Bytes)4 AbiDefinition (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition)4 EncryptType (org.fisco.bcos.web3j.crypto.EncryptType)3