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();
}
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();
}
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();
}
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();
}
Aggregations