upload method

Future<void> upload(
  1. WriteBlobFlowUploadOptions options
)

Step 3: Upload the quilt blob data.

Implementation

Future<void> upload(WriteBlobFlowUploadOptions options) async {
  if (_step != _WriteFilesFlowStep.registered) {
    throw StateError('Must call register() before upload()');
  }

  final metadata = _metadata!;
  final quiltBytes = _quiltBytes!;

  // Resolve the Blob Sui object ID.
  _blobObjectId = _resolveBlobObjectId(options);

  if (_suiClient == null) {
    throw StateError('A chain client is required to verify registration');
  }
  await verifyFlowBlob(
    client: _suiClient,
    objectId: _blobObjectId!,
    blobId: metadata.blobId,
    blobType: _blobType!,
    size: metadata.unencodedLength,
    deletable: _deletable,
    owner: _owner!,
    certified: false,
    digest: options.digest,
  );

  if (_relayClient != null) {
    // Wait for register tx to be indexed before contacting relay.
    // Mirrors TS SDK's waitForTransaction before writeBlobToUploadRelay.

    final result = await _relayClient.writeBlob(
      blobId: metadata.blobId,
      blob: quiltBytes,
      nonce: metadata.nonce,
      txDigest: options.digest,
      blobObjectId: _blobObjectId ?? '',
      deletable: _deletable,
      requiresTip: _tipConfig != null,
      encodingType: _encodingTypeToString(metadata.encodingType),
    );
    _certificate = result.certificate;
  } else if (_directClient != null &&
      _committee != null &&
      _encodedBlob != null) {
    final client = _directClient;
    final confirmations = await client.writeEncodedBlobToNodes(
      encodedBlob: _encodedBlob!,
      committee: _committee,
      deletable: _deletable,
      blobObjectId: _blobObjectId ?? '',
    );

    _certificate = client.buildCertificateFromConfirmations(
      confirmations: confirmations,
      committee: _committee,
      blobId: metadata.blobId,
      blobObjectId: _blobObjectId!,
      deletable: _deletable,
    );
  } else {
    throw StateError(
      'No relay client or direct mode configuration available.',
    );
  }

  _step = _WriteFilesFlowStep.uploaded;
}