upload method
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 (_relayClient != null) {
// Wait for register tx to be indexed before contacting relay.
// Mirrors TS SDK's waitForTransaction before writeBlobToUploadRelay.
await _suiClient.waitForTransaction(options.digest);
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 ?? '',
)
as Map<int, StorageConfirmation?>;
_certificate =
client._buildCertificateFromConfirmations(
confirmations: confirmations,
committee: _committee,
)
as ProtocolMessageCertificate;
} else {
throw StateError(
'No relay client or direct mode configuration available.',
);
}
_step = _WriteFilesFlowStep.uploaded;
}