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

Add build.OperationBuilder interface

Open bartekn opened this issue 8 years ago • 1 comments

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