Operation Type Implementation
Background
We defined operation type for the transfer feature(payment, createAccount) until now.
And the methods which is defined in OperationBody interface are Validate(), IsWellFormed(), TargetAddress(), GetAmount().
There is a need to define more operation type increasingly.
But the methods of OperationBody interface isn't general for other operation type.(e.g. operation_voting_result, operation_proposal ...). However OperationBody implementation for voting result should have GetAmount() method to satisfy interface.
It will be good if OperationBody struct doesn't need to implement unnecessary methods repeatedly and use current OperationBody interface continually.
Solution
type OperationBody interface {
Validate(*storage.LevelDBBackend) error
IsWellFormed([]byte) error
TargetAddress() string
GetAmount() common.Amount
}
type OperationBodyImpl struct {
}
func (opb OperationBodyImpl) Validate(*storage.LevelDBBackend) error {
// To Do default return
}
func (opb OperationBodyImpl) IsWellFormed([]byte) error {
// To Do default return
}
func (opb OperationBodyImpl) TargetAddress() string {
// To Do default return
}
func (opb OperationBodyImpl) GetAmount() common.Amount {
// To Do default return
}
type OperationBodyVotingResult struct {
OperationBodyImpl
Target string `json:"target"`
Amount common.Amount `json:"amount"`
}
func (opv OperationBodyVotingResult) Validate(*storage.LevelDBBackend) error {
// Implementation
}
func (opv OperationBodyVotingResult) IsWellFormed([]byte) error {
// Implementation
}
Implement default struct about interface. The default struct define the methods which should be generated. Each operation type inherit default struct and define the method only needed for it.
It makes sense. Could you make a PR for it? We can discuss further in the PR
Ok, then I'll make a PR.