resolveGasData method

  1. @override
Future<ResolvedGasData?> resolveGasData(
  1. TransactionBlockDataBuilder data
)
override

One-shot server-side gas resolution for a fully input-resolved transaction: the server selects the gas coin and computes the budget (gRPC simulate with doGasSelection). Returns null when the transport does not support it (e.g. JSON-RPC); the builder then falls back to local coin selection + a budget dry-run.

Implementation

@override
Future<ResolvedGasData?> resolveGasData(
    TransactionBlockDataBuilder data) async {
  // Structured message (not BCS, which cannot express an unset budget) +
  // `doGasSelection` — mirrors Mysten's TS gRPC `resolveTransactionPlugin`.
  final grpcTx = transactionDataToGrpcTransaction(data);
  final sim = await core.simulateStructured(
    grpcTx,
    doGasSelection: true,
    readMask: const [
      'transaction.transaction.gas_payment',
      'transaction.effects.status',
    ],
  );
  final status = sim.transaction.effects.status;
  if (!status.success) {
    throw StateError(
        'Gas resolution simulation failed: ${status.error.description}');
  }
  final gp = sim.transaction.transaction.gasPayment;
  if (gp.objects.isEmpty) {
    // Server did not resolve a gas payment; let the caller fall back.
    return null;
  }
  return ResolvedGasData(
    budget: BigInt.parse(gp.budget.toString()),
    price: gp.hasPrice() ? BigInt.parse(gp.price.toString()) : null,
    payment: gp.objects
        .map((o) => SuiObjectRef(o.digest, o.objectId, o.version.toInt()))
        .toList(),
  );
}