Search in sources :

Example 1 with Uint

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

the class FunctionEncoder method encodeParameters.

private static String encodeParameters(List<Type> parameters, StringBuilder result) {
    int dynamicDataOffset = getLength(parameters) * Type.MAX_BYTE_LENGTH;
    StringBuilder dynamicData = new StringBuilder();
    for (Type parameter : parameters) {
        String encodedValue = TypeEncoder.encode(parameter);
        if (TypeEncoder.isDynamic(parameter)) {
            String encodedDataOffset = TypeEncoder.encodeNumeric(new Uint(BigInteger.valueOf(dynamicDataOffset)));
            result.append(encodedDataOffset);
            dynamicData.append(encodedValue);
            dynamicDataOffset += encodedValue.length() >> 1;
        } else {
            result.append(encodedValue);
        }
    }
    result.append(dynamicData);
    return result.toString();
}
Also used : Type(org.bcos.web3j.abi.datatypes.Type) Uint(org.bcos.web3j.abi.datatypes.Uint) Uint(org.bcos.web3j.abi.datatypes.Uint)

Example 2 with Uint

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

the class TypeEncoder method encodeDynamicBytes.

static String encodeDynamicBytes(DynamicBytes dynamicBytes) {
    int size = dynamicBytes.getValue().length;
    String encodedLength = encode(new Uint(BigInteger.valueOf(size)));
    String encodedValue = encodeBytes(dynamicBytes);
    StringBuilder result = new StringBuilder();
    result.append(encodedLength);
    result.append(encodedValue);
    return result.toString();
}
Also used : Uint(org.bcos.web3j.abi.datatypes.Uint) Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) Uint(org.bcos.web3j.abi.datatypes.Uint)

Example 3 with Uint

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

the class TypeEncoder method encodeDynamicArray.

static <T extends Type> String encodeDynamicArray(DynamicArray<T> value) {
    int size = value.getValue().size();
    String encodedLength = encode(new Uint(BigInteger.valueOf(size)));
    String encodedValues = encodeArrayValues(value);
    StringBuilder result = new StringBuilder();
    result.append(encodedLength);
    result.append(encodedValues);
    return result.toString();
}
Also used : Uint(org.bcos.web3j.abi.datatypes.Uint) Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) Uint(org.bcos.web3j.abi.datatypes.Uint)

Example 4 with Uint

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

the class TypeEncoder method toByteArray.

private static byte[] toByteArray(NumericType numericType) {
    BigInteger value = numericType.getValue();
    if (numericType instanceof Ufixed || numericType instanceof Uint) {
        if (value.bitLength() == MAX_BIT_LENGTH) {
            // As BigInteger is signed, if we have a 256 bit value, the resultant byte array
            // will contain a sign byte in it's MSB, which we should ignore for this unsigned
            // integer type.
            byte[] byteArray = new byte[MAX_BYTE_LENGTH];
            System.arraycopy(value.toByteArray(), 1, byteArray, 0, MAX_BYTE_LENGTH);
            return byteArray;
        }
    }
    return value.toByteArray();
}
Also used : Uint(org.bcos.web3j.abi.datatypes.Uint) Ufixed(org.bcos.web3j.abi.datatypes.Ufixed) BigInteger(java.math.BigInteger)

Aggregations

Uint (org.bcos.web3j.abi.datatypes.Uint)4 Utf8String (org.bcos.web3j.abi.datatypes.Utf8String)2 BigInteger (java.math.BigInteger)1 Type (org.bcos.web3j.abi.datatypes.Type)1 Ufixed (org.bcos.web3j.abi.datatypes.Ufixed)1