encodeStruct static method
Encodes a struct with the specified type and data, returning the result as a list of integers. The struct is defined in the Eip712TypedData, and the data parameter contains field values.
Implementation
static List<int> encodeStruct(
Eip712TypedData typedData, String type, Map<String, dynamic> data) {
final List<String> types = [bytes32TypeName];
final List<dynamic> inputBytes = [getMethodSigature(typedData, type)];
if (typedData.types[type] == null) {
throw SolidityAbiException(
'EIP-712 type definition not found for "$type".');
}
for (final Eip712TypeDetails field in typedData.types[type]!) {
if (data[field.name] == null) {
if (typedData.version == EIP712Version.v3) continue;
throw SolidityAbiException(
'Invalid Eip712TypedData data. data mising for field ${field.name}',
details: {'data': data, 'field': field});
}
final dynamic value = data[field.name];
final encodedValue = encodeValue(typedData, field.type, value);
types.add(encodedValue.item1);
inputBytes.add(encodedValue.item2);
}
return abiEncode(types, inputBytes);
}