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 (_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) {
// 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 })`.
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 ?? '',
);
// Build certificate from confirmations.
_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. '
'Configure an upload relay or set committee + encoder for direct mode.',
);
}
_step = _FlowStep.uploaded;
}