createInitialTypes function

Map<String, Type> createInitialTypes()

Create the set of types built-in to the abi format */

Implementation

Map<String, Type> createInitialTypes() {
  var result = {
    "bool": createType(
      name: 'bool',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.push([data ? 1 : 0]);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.get();
      },
    ),
    "uint8": createType(
      name: 'uint8',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.push([checkRange(data, (data as int) & 0xff)]);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.get();
      },
    ),
    "int8": createType(
      name: 'int8',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.push([checkRange(data, (data as int) << 24 >> 24)]);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.get() << 24 >> 24;
      },
    ),
    "uint16": createType(
      name: 'uint16',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushUint16(checkRange(data, (data as int) & 0xffff));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getUint16();
      },
    ),
    "int16": createType(
      name: 'int16',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushUint16(checkRange(data, (data as int) << 16 >> 16));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getUint16() << 16 >> 16;
      },
    ),
    "uint32": createType(
      name: 'uint32',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushUint32(checkRange(data, (data as int) >> 0));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getUint32();
      },
    ),
    "uint64": createType(
      name: 'uint64',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushArray(numeric.decimalToBinary(8, '' + data));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return numeric.binaryToDecimal(buffer.getUint8List(8));
      },
    ),
    "int64": createType(
      name: 'int64',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushArray(numeric.signedDecimalToBinary(8, '' + data));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return numeric.signedBinaryToDecimal(buffer.getUint8List(8));
      },
    ),
    "int32": createType(
      name: 'int32',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushUint32(checkRange(data as int, data | 0));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getUint32() | 0;
      },
    ),
    "varuint32": createType(
      name: 'varuint32',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushVaruint32(checkRange(data, (data as int) >> 0));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getVaruint32();
      },
    ),
    "varint32": createType(
      name: 'varint32',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushVarint32(checkRange(data, data == null ? 0 : data));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getVarint32();
      },
    ),
    "uint128": createType(
      name: 'uint128',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushArray(numeric.decimalToBinary(16, '' + data));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return numeric.binaryToDecimal(buffer.getUint8List(16));
      },
    ),
    "int128": createType(
      name: 'int128',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushArray(numeric.signedDecimalToBinary(16, '' + data));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return numeric.signedBinaryToDecimal(buffer.getUint8List(16));
      },
    ),
    "float32": createType(
      name: 'float32',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushFloat32(data);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getFloat32();
      },
    ),
    "float64": createType(
      name: 'float64',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushFloat64(data);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getFloat64();
      },
    ),
    "float128": createType(
      name: 'float128',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushUint8ListChecked(hexToUint8List(data), 16);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return arrayToHex(buffer.getUint8List(16));
      },
    ),
    "bytes": createType(
      name: 'bytes',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        if (data is Uint8List) {
          buffer.pushBytes(data.toList());
        } else if (data is List) {
          buffer.pushBytes(data.cast<int>());
        } else {
          buffer.pushBytes(hexToUint8List(data));
        }
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        if (state != null && state.options.bytesAsUint8List) {
          return buffer.getBytes();
        } else {
          return arrayToHex(buffer.getBytes());
        }
      },
    ),
    "string": createType(
      name: 'string',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushString(data);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getString();
      },
    ),
    "name": createType(
      name: 'name',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushName(data);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getName();
      },
    ),
    "time_point": createType(
      name: 'time_point',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushNumberAsUint64(dateToTimePoint(data));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return timePointToDate(buffer.getUint64AsNumber());
      },
    ),
    "time_point_sec": createType(
      name: 'time_point_sec',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        var date = dateToTimePointSec(data);
        buffer.pushUint32(date);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return timePointSecToDate(buffer.getUint32());
      },
    ),
    "block_timestamp_type": createType(
      name: 'block_timestamp_type',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushUint32(dateToBlockTimestamp(data));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return blockTimestampToDate(buffer.getUint32());
      },
    ),
    "symbol_code": createType(
      name: 'symbol_code',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushSymbolCode(data);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getSymbolCode();
      },
    ),
    "symbol": createType(
      name: 'symbol',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushSymbol(stringToSymbol(data));
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return symbolToString(buffer.getSymbol());
      },
    ),
    "asset": createType(
      name: 'asset',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushAsset(data);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getAsset();
      },
    ),
    "checksum160": createType(
      name: 'checksum160',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushUint8ListChecked(hexToUint8List(data), 20);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return arrayToHex(buffer.getUint8List(20));
      },
    ),
    "checksum256": createType(
      name: 'checksum256',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushUint8ListChecked(hexToUint8List(data), 32);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return arrayToHex(buffer.getUint8List(32));
      },
    ),
    "checksum512": createType(
      name: 'checksum512',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushUint8ListChecked(hexToUint8List(data), 64);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return arrayToHex(buffer.getUint8List(64));
      },
    ),
    "public_key": createType(
      name: 'public_key',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushPublicKey(data);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getPublicKey();
      },
    ),
    "private_key": createType(
      name: 'private_key',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushPrivateKey(data);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getPrivateKey();
      },
    ),
    "signature": createType(
      name: 'signature',
      serialize: (
        Type self,
        SerialBuffer buffer,
        dynamic data, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        buffer.pushSignature(data);
      },
      deserialize: (
        Type self,
        SerialBuffer buffer, {
        SerializerState? state,
        required bool allowExtensions,
      }) {
        return buffer.getSignature();
      },
    ),
  };

  result['extended_asset'] = createType(
    name: 'extended_asset',
    baseName: '',
    fields: [
      Field(name: 'quantity', typeName: 'asset', type: result['asset']),
      Field(name: 'contract', typeName: 'name', type: result['name']),
    ],
    serialize: serializeStruct,
    deserialize: deserializeStruct,
  );

  return result;
}