Search in sources :

Example 1 with Ufixed

use of org.bcos.web3j.abi.datatypes.Ufixed 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

BigInteger (java.math.BigInteger)1 Ufixed (org.bcos.web3j.abi.datatypes.Ufixed)1 Uint (org.bcos.web3j.abi.datatypes.Uint)1