getPureBcsSchema function
BcsType?
getPureBcsSchema(
- dynamic typeSignature
Implementation
BcsType? getPureBcsSchema(dynamic typeSignature) {
if (typeSignature is String) {
switch (typeSignature) {
case 'address':
return SuiBcs.Address;
case 'bool':
return SuiBcs.BOOL;
case 'u8':
return SuiBcs.U8;
case 'u16':
return SuiBcs.U16;
case 'u32':
return SuiBcs.U32;
case 'u64':
return SuiBcs.U64;
case 'u128':
return SuiBcs.U128;
case 'u256':
return SuiBcs.U256;
default:
throw ArgumentError("Unknown type signature $typeSignature");
}
}
if (typeSignature is Map<String, dynamic> && typeSignature.containsKey('vector')) {
if (typeSignature['vector'] == 'u8') {
return SuiBcs.VECTOR(SuiBcs.U8).transform(
input: (dynamic val) => val is String ? Uint8List.fromList(val.codeUnits) : val,
output: (val) => val,
);
}
final type = getPureBcsSchema(typeSignature['vector']);
return type != null ? SuiBcs.VECTOR(type) : null;
}
if (typeSignature is Map<String, dynamic> && typeSignature.containsKey('datatype')) {
final datatypeInfo = typeSignature['datatype'] as Map<String, dynamic>;
final pkg = normalizeSuiAddress(datatypeInfo['package']);
if (pkg == normalizeSuiAddress(MOVE_STDLIB_ADDRESS)) {
if (datatypeInfo['module'] == STD_ASCII_MODULE_NAME &&
datatypeInfo['type'] == STD_ASCII_STRUCT_NAME) {
return SuiBcs.STRING;
}
if (datatypeInfo['module'] == STD_UTF8_MODULE_NAME &&
datatypeInfo['type'] == STD_UTF8_STRUCT_NAME) {
return SuiBcs.STRING;
}
if (datatypeInfo['module'] == STD_OPTION_MODULE_NAME &&
datatypeInfo['type'] == STD_OPTION_STRUCT_NAME) {
final type = getPureBcsSchema(datatypeInfo['typeParameters'][0]);
return type != null ? SuiBcs.VECTOR(type) : null;
}
}
if (pkg == normalizeSuiAddress(SUI_FRAMEWORK_ADDRESS) &&
datatypeInfo['module'] == OBJECT_MODULE_NAME &&
datatypeInfo['type'] == ID_STRUCT_NAME) {
return SuiBcs.Address;
}
}
return null;
}