simulateRawTransaction method

Future simulateRawTransaction(
  1. dynamic accountOrPubkey,
  2. RawTransaction rawTransaction, {
  3. bool estimateGasUnitPrice = false,
  4. bool estimateMaxGasAmount = false,
  5. bool estimatePrioritizedGasUnitPrice = false,
})

accountOrPubkey type is AptosAccount | Ed25519PublicKey | MultiEd25519PublicKey

Implementation

Future<dynamic> simulateRawTransaction(
  dynamic accountOrPubkey,
  RawTransaction rawTransaction,
  {
    bool estimateGasUnitPrice = false,
    bool estimateMaxGasAmount = false,
    bool estimatePrioritizedGasUnitPrice = false
  }
) async {
  Uint8List signedTxn;
  if (accountOrPubkey is AptosAccount) {
    signedTxn = await AptosClient.generateBCSSimulation(accountOrPubkey, rawTransaction);
  } else if (accountOrPubkey is MultiEd25519PublicKey) {
    final txnBuilder = TransactionBuilderMultiEd25519(
      accountOrPubkey,
      (_) {
        final bits = <int>[];
        final signatures = <Ed25519Signature>[];
        for (int i = 0; i < accountOrPubkey.threshold; i += 1) {
          bits.add(i);
          signatures.add(Ed25519Signature(Uint8List(64)));
        }
        final bitmap = MultiEd25519Signature.createBitmap(bits);
        return MultiEd25519Signature(signatures, bitmap);
      }
    );

    signedTxn = txnBuilder.sign(rawTransaction);
  } else if (accountOrPubkey is Ed25519PublicKey) {
    final txnBuilder = TransactionBuilderEd25519(
      accountOrPubkey.value,
      (_) {
        return Ed25519Signature(Uint8List(64));
      }
    );

    signedTxn = txnBuilder.sign(rawTransaction);
  } else {
    throw ArgumentError("Invalid account value $accountOrPubkey");
  }

  return submitBCSSimulate(
    signedTxn,
    estimateGasUnitPrice: estimateGasUnitPrice,
    estimateMaxGasAmount: estimateMaxGasAmount,
    estimatePrioritizedGasUnitPrice: estimatePrioritizedGasUnitPrice
  );
}