bosnet / bosnet/sebak

Operation Type Implementation

Open
#356 2 comments 3 reactions 1 assignee Claimed by @soonkuk View on GitHub
Dominant language
Go
Stars
44
Forks
12
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.