approveAsMulti static method

Future<bool> approveAsMulti({
  1. required MultisigResponse multisigResponse,
  2. required Provider provider,
  3. required KeyPair signer,
  4. Duration storageKeyDelay = const Duration(seconds: 20),
  5. int tip = 0,
  6. int eraPeriod = 64,
})

ApproveAsMulti

It approves the multisig transaction and sends for further approval to other signatories.

Implementation

static Future<bool> approveAsMulti({
  required MultisigResponse multisigResponse,
  required Provider provider,
  required KeyPair signer,
  Duration storageKeyDelay = const Duration(seconds: 20),
  int tip = 0,
  int eraPeriod = 64,
}) async {
  final MultisigStorage? multisigStorage = await fetchMultisigStorage(
      provider,
      storageKeyDelay,
      multisigResponse.callHash.hexToUint8List(),
      multisigResponse.multisigBytes);

  if (multisigStorage != null) {
    if (multisigStorage
        .isApprovedByAll(multisigResponse.allSignatories.length)) {
      return true;
    }

    if (multisigStorage
        .isAlreadyApprovedBy(signer.publicKey.bytes.toUint8List())) {
      return true;
    }

    // Cannot do approveAsMulti if only one approval is left.
    // The last approval should be done with asMulti.
    if (multisigStorage
        .isOnlyOneApprovalLeft(multisigResponse.allSignatories.length)) {
      throw FinalApprovalException(
          'The final approval call should be done with method `asMulti(...)` to execute the transaction.');
    }
  }

  final meta = await MultiSigMeta.fromProvider(provider: provider);
  final signatories = Signatories.fromAddresses(
      multisigResponse.allSignatories, multisigResponse.threshold);

  await _createAndSubmitPayload(
    meta: meta,
    method: approveAsMultiMethod(
      chainInfo: meta.runtimeMetadata.chainInfo,
      otherSignatories:
          signatories.signatoriesExcludeBytes(signer.publicKey.bytes),
      threshold: multisigResponse.threshold,
      callHash: Uint8List.fromList(hex.decode(multisigResponse.callHash)),
      maxWeight: Weight(
        refTime: BigInt.from(640000000),
        proofSize: BigInt.from(0),
      ),
      multiSigStorage: multisigStorage,
    ),
    tip: tip,
    eraPeriod: eraPeriod,
    signer: signer,
    provider: provider,
  );
  return true;
}