go-stellar-base
go-stellar-base copied to clipboard
Add build.OperationBuilder interface
trafficstars
Consider the following code:
var operationBuilder interface{}
if !destinationExists {
operationBuilder = b.CreateAccount(mutators...)
} else {
operationBuilder = b.Payment(mutators...)
}
// Check errors here
txBuilder := b.Transaction(
operationBuilder.(b.TransactionMutator)),
)
If we wanted to check if there were errors after applying mutators (Err field in builders) it's not possible because type assertion works for interfaces only. To solve this we can create an interface:
type OperationBuilder interface {
MutateTransaction(o *TransactionBuilder) error
Mutate(muts ...interface{})
Error() error
}
Really good point. Let me think about this some, since I'm not sure if an interface is specifically how we want to handle it... particularly I'm shying away from using Error() since that method name is used for the builtin error interface (and it returns a string).