transactMulti method

dynamic transactMulti(
  1. Wallet wallet,
  2. List<Clause> clauses, {
  3. int gasPriceCoef = 0,
  4. int gas = 0,
  5. String? dependsOn,
  6. int expiration = 32,
  7. bool force = false,
  8. Wallet? gasPayer,
})

Implementation

transactMulti(Wallet wallet, List<dev.Clause> clauses,
    {int gasPriceCoef = 0,
    int gas = 0,
    String? dependsOn,
    int expiration = 32,
    bool force = false,
    Wallet? gasPayer}) async {
  assert(clauses.isNotEmpty);
  //Emulate transaction first
  List eResponses;
  if (gasPayer != null) {
    eResponses = await callMulti(wallet.adressString, clauses,
        gas: gas, gasPayer: gasPayer.adressString);
  } else {
    eResponses = await callMulti(wallet.adressString, clauses, gas: gas);
  }

  if (anyEmulateFailed(eResponses) && force == false) {
    throw Exception('Transaction will revert $eResponses');
  }

  bool needFeeDelegation = gasPayer != null;
  //parse clauses

  int chainTag = await getChainTag();
  var b = await getBlock();
  //Build body
  var tx = buildTransaction(
      clauses, chainTag, calcBlockRef(b["id"]), calcNonce(),
      expiration: expiration,
      gas: gas,
      gasPriceCoef: gasPriceCoef,
      feeDelegation: needFeeDelegation);
  var txBody = json.decode(tx.toJsonString());
  // Get gas estimation from remote node
  // Calculate a safe gas for user
  var vmGas = readVmGases(eResponses).sum;
  var safeGas = suggestGasForTx(vmGas, json.decode(tx.toJsonString()));
  if (gas < safeGas) {
    if (gas != 0 && force == false) {
      throw Exception("gas $gas < emulated gas $safeGas");
    }
  }

  // Fill out the gas for user
  if (gas == 0) {
    tx.gas.big = BigInt.from(safeGas);
  }

//post to remote node
  if (needFeeDelegation) {
    tx = calcTxSignedWithFeeDelegation(wallet, gasPayer, txBody);
  }

  Uint8List h = blake2b256([tx.encode()]);
  Uint8List sig = sign(h, wallet.priv).serialize();
  tx.signature = sig;
  String raw = '0x' + bytesToHex(tx.encode());

  return postTransaction(raw);
}