transactionDataToGrpcTransaction function
Transaction
transactionDataToGrpcTransaction(
- TransactionBlockDataBuilder data, {
- bool includeGas = true,
- bool includeBudget = true,
Maps the transaction builder's internal ($kind-tagged map) representation
to the gRPC structured Transaction message, so it can be simulated with
the gas payment/budget left unset for server-side gas selection — mirroring
Mysten's TS transactionDataToGrpcTransaction.
Inputs must already be resolved (no UnresolvedPure / UnresolvedObject);
Transaction.build's _prepare does that before gas resolution.
Implementation
Transaction transactionDataToGrpcTransaction(
TransactionBlockDataBuilder data, {
bool includeGas = true,
bool includeBudget = true,
}) {
final inputs = (data.inputs).map(_callArgToGrpcInput).toList();
final commands = (data.commands).map(_commandToGrpcCommand).toList();
final tx = Transaction(
version: 1,
kind: TransactionKind(
programmableTransaction: ProgrammableTransaction(
inputs: inputs,
commands: commands,
),
),
);
if (data.sender != null) {
tx.sender = data.sender!;
}
if (includeGas) {
final gas = data.gasData;
final payment = GasPayment(
objects: (gas.payment ?? const [])
.map((ref) => ObjectReference(
objectId: ref.objectId,
version: Int64(ref.version),
digest: ref.digest,
))
.toList(),
);
final owner = gas.owner ?? data.sender;
if (owner != null) payment.owner = owner;
if (gas.price != null) payment.price = Int64.parseInt(gas.price.toString());
// For server-side gas selection (`doGasSelection`) the budget is omitted so
// the node estimates it from the simulation. Honoring a caller/dApp-supplied
// budget here would make the node select coins to satisfy that budget (often
// a conservative 50_000_000 ceiling), which fails for accounts holding less
// than it even though the transaction's real gas is tiny.
if (includeBudget && gas.budget != null) {
payment.budget = Int64.parseInt(gas.budget.toString());
}
tx.gasPayment = payment;
}
return tx;
}