go-stellar-base icon indicating copy to clipboard operation
go-stellar-base copied to clipboard

Add build.OperationBuilder interface

Open bartekn opened this issue 9 years ago • 1 comments
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
}

bartekn avatar Jan 29 '16 13:01 bartekn

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).

nullstyle avatar Jan 29 '16 18:01 nullstyle