cancel method
Future<Uint8List>
cancel({
- required String signerAddress,
- required SigningCallback signingCallback,
- required Uint8List callHash,
- int eraPeriod = 64,
- int? nonce,
Cancels a pending multisig transaction and refunds the deposit.
Only the depositor (the signatory who initiated the transaction) can cancel it. Cancelling refunds the storage deposit to the depositor and removes the pending transaction from chain storage.
Parameters:
signerAddress: The address of the depositor cancelling the transactionsigningCallback: Callback function to sign the cancellation transactioncallHash: The hash of the call to cancel (obtained from MultisigResponse.callHash)eraPeriod: The era period for transaction mortality (default: 64 blocks)nonce: Optional nonce override for the transaction
Returns: A Uint8List containing the transaction hash of the cancellation.
Throws:
- StateError if no pending transaction exists for the given call hash
- StateError if the signer is not the depositor (only depositor can cancel)
- Exception if the transaction submission fails
Example:
// Alice initiated the transaction and wants to cancel it
final txHash = await multisig.cancel(
signerAddress: alice.address,
signingCallback: alice.sign,
callHash: response.callHash,
);
print('Transaction cancelled with hash: $txHash');
Implementation
Future<Uint8List> cancel({
required final String signerAddress,
required final SigningCallback signingCallback,
required final Uint8List callHash,
final int eraPeriod = 64,
final int? nonce,
}) async {
final storage = await MultisigStorage.fetch(
provider: provider,
multisigPubkey: multisigAccount.multisigPubkey,
callHash: callHash,
);
if (storage == null) {
throw StateError('No pending transaction to cancel');
}
if (!storage.isDepositor(signerAddress)) {
throw StateError('Only the depositor can cancel this transaction');
}
final cancelCall = _createCancelAsMultiRuntimeCall(
signerAddress: signerAddress,
maybeTimepoint: storage.when,
callHash: callHash,
);
final txHash = await _submitCall(
call: cancelCall,
signerAddress: signerAddress,
signCallback: signingCallback,
eraPeriod: eraPeriod,
nonce: nonce,
);
return txHash;
}