getBlobObjectInfo method

Future<Map<String, dynamic>?> getBlobObjectInfo({
  1. required String objectId,
})

Read full on-chain info for a Walrus Blob object.

Returns a map with keys: objectId, blobId, size, certifiedEpoch, registeredEpoch, endEpoch, startEpoch, deletable, encodingType.

Returns null if the object doesn't exist or isn't a Blob.

Implementation

Future<Map<String, dynamic>?> getBlobObjectInfo({
  required String objectId,
}) async {
  final resp = await suiClient.getObject(
    objectId,
    options: SuiObjectDataOptions(showContent: true, showType: true),
  );
  if (resp.error != null) {
    if (resp.error!.code == 'notExists' || resp.error!.code == 'deleted') {
      return null;
    }
    throw WalrusClientError('Cannot read Blob $objectId: ${resp.error}');
  }
  if (resp.data?.type != await getBlobType()) return null;
  final content = resp.data?.content;
  if (content == null) return null;

  Map<String, dynamic>? fields;
  if (content.fields is Map<String, dynamic>) {
    fields = content.fields as Map<String, dynamic>;
  }
  if (fields == null) return null;

  final blobIdRaw = fields['blob_id'] ?? fields['blobId'];
  String? blobIdBase64;
  if (blobIdRaw is String) {
    final bigInt = BigInt.tryParse(blobIdRaw);
    if (bigInt != null) {
      blobIdBase64 = blobIdFromInt(bigInt);
    } else {
      blobIdBase64 = blobIdRaw;
    }
  } else if (blobIdRaw is int) {
    blobIdBase64 = blobIdFromInt(BigInt.from(blobIdRaw));
  }
  if (blobIdBase64 == null) return null;

  final certifiedEpoch = certifiedEpochFromJson(
    fields['certified_epoch'] ?? fields['certifiedEpoch'],
  );

  // Parse storage sub-object for epoch range.
  int? startEpoch;
  int? endEpoch;
  final storage = fields['storage'];
  if (storage is Map<String, dynamic>) {
    final storageFields =
        (storage['fields'] as Map<String, dynamic>?) ?? storage;
    final startRaw =
        storageFields['start_epoch'] ?? storageFields['startEpoch'];
    final endRaw = storageFields['end_epoch'] ?? storageFields['endEpoch'];
    if (startRaw is int) startEpoch = startRaw;
    if (startRaw is String) startEpoch = int.tryParse(startRaw);
    if (endRaw is int) endEpoch = endRaw;
    if (endRaw is String) endEpoch = int.tryParse(endRaw);
  }

  return {
    'objectId': objectId,
    'blobId': blobIdBase64,
    'size': fields['size'],
    'certifiedEpoch': certifiedEpoch,
    'registeredEpoch':
        fields['registered_epoch'] ?? fields['registeredEpoch'],
    'startEpoch': startEpoch,
    'endEpoch': endEpoch,
    'deletable': fields['deletable'],
    'encodingType': fields['encoding_type'] ?? fields['erasure_code_type'],
  };
}