upload method
Step 3: Upload the blob data.
For upload relay mode: sends blob to the relay. For direct mode: writes encoded slivers to storage nodes (Phase 3).
options.digest is the transaction digest from signing the
register transaction in Step 2.
Implementation
Future<void> upload(WriteBlobFlowUploadOptions options) async {
if (_step != _FlowStep.registered) {
throw StateError('Must call register() before upload()');
}
final metadata = _metadata!;
// Resolve the Blob Sui object ID.
_blobObjectId = _resolveBlobObjectId(options);
if (_relayClient != null) {
// Relay mode: upload to relay.
//
// We must wait for the register transaction to be indexed so the relay
// can verify the on-chain registration and payment.
// Mirrors TS SDK's `client.waitForTransaction({ digest })`.
await _suiClient.waitForTransaction(options.digest);
final relay = _relayClient;
final result = await relay.writeBlob(
blobId: metadata.blobId,
blob: _blob,
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) {
// Direct mode (Phase 3): write slivers to storage nodes.
// Use the WalrusDirectClient's writeEncodedBlobToNodes method.
final client = _directClient;
final confirmations =
await client.writeEncodedBlobToNodes(
encodedBlob: _encodedBlob,
committee: _committee,
deletable: _deletable,
blobObjectId: _blobObjectId ?? '',
)
as Map<int, StorageConfirmation?>;
// Build certificate from confirmations.
_certificate =
client._buildCertificateFromConfirmations(
confirmations: confirmations,
committee: _committee,
)
as ProtocolMessageCertificate;
} else {
throw StateError(
'No relay client or direct mode configuration available. '
'Configure an upload relay or set committee + encoder for direct mode.',
);
}
_step = _FlowStep.uploaded;
}