Skip to content

Commit

Permalink
Compute balances when serializing core.Volume.
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Jun 9, 2022
1 parent 2746192 commit 50987cf
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/core/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ type Volume struct {
Output int64 `json:"output"`
}

func (v Volume) MarshalJSON() ([]byte, error) {
type volume Volume
return json.Marshal(struct {
volume
Balance int64 `json:"balance"`
}{
volume: volume(v),
Balance: v.Input - v.Output,
})
}

func (v Volume) Balance() int64 {
return v.Input - v.Output
}
Expand Down

0 comments on commit 50987cf

Please sign in to comment.