/
balance.go
52 lines (40 loc) · 1 KB
/
balance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2020-2024 Blockwatch Data Inc.
// Author: alex@blockwatch.cc
package model
import (
"blockwatch.cc/packdb/pack"
"errors"
)
const BalanceTableKey = "balance"
var ErrNoBalance = errors.New("balance not indexed")
type Balance struct {
RowId uint64 `pack:"I,pk" json:"row_id"`
AccountId AccountID `pack:"A,bloom" json:"account_id"`
Balance int64 `pack:"B" json:"balance"`
ValidFrom int64 `pack:">,i32" json:"valid_from"`
}
// Ensure Balance implements the pack.Item interface.
var _ pack.Item = (*Balance)(nil)
func (b Balance) ID() uint64 {
return b.RowId
}
func (b *Balance) SetID(id uint64) {
b.RowId = id
}
func (b *Balance) Reset() {
*b = Balance{}
}
func (m Balance) TableKey() string {
return BalanceTableKey
}
func (m Balance) TableOpts() pack.Options {
return pack.Options{
PackSizeLog2: 15,
JournalSizeLog2: 16,
CacheSize: 256,
FillLevel: 100,
}
}
func (m Balance) IndexOpts(key string) pack.Options {
return pack.NoOptions
}