transactionDataToGrpcTransaction function
Transaction
transactionDataToGrpcTransaction(
- TransactionBlockDataBuilder data, {
- bool includeGas = 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,
}) {
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());
if (gas.budget != null) {
payment.budget = Int64.parseInt(gas.budget.toString());
}
tx.gasPayment = payment;
}
return tx;
}