I'm trying to submit many operations in a single transaction that are built up dynamically. How can I convert these operations to a Stellar Transaction?
Please provide code samples if possible.
You could use the spread operator on an object of type []build.TransactionMutator
that is passed into the build.Transaction
method (on github.com/stellar/go/build
).
Here's a code sample:
import (
“github.com/stellar/go/build"
)
// BuildWithOps builds a transaction with a dynamic list of operations
func BuildWithOps(sourceAccount string, seq uint64, network build.Network, ops []build.TransactionMutator) (*build.TransactionBuilder, error) {
// build an array of mutators initialized with the essential values
muts := []build.TransactionMutator{
build.Sequence{Sequence: seq},
network,
build.SourceAccount{AddressOrSeed: sourceAccount},
}
// dynamically add more mutators/operations as needed
muts = append(muts, ops...)
// build the transaction from these mutators and check for an error
tx, err := build.Transaction(muts...)
if err != nil {
return nil, err
}
return tx, nil
}
tx.Err
not longer exists. build.Transaction
returns tx
and err
.
Commented
Feb 1, 2018 at 22:19