-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
78 lines (64 loc) · 1.57 KB
/
data.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package data_v1
import (
"github.com/axis-cash/go-axis-import/c_type"
"github.com/axis-cash/go-axis/zero/localdb"
"github.com/axis-cash/go-axis/zero/txs/zstate/txstate/data"
"github.com/axis-cash/go-axis/zero/utils"
)
const ZSTATE0_ROOT_OUT = "$ZState0$ROOT-OUT$"
type Data struct {
Num uint64
Root2Out map[c_type.Uint256]localdb.RootState
Dels utils.Dirtys
Nils utils.HSet
Roots utils.HSet
PKr2Count map[c_type.PKr]int
}
func NewData(num uint64) (ret *Data) {
ret = &Data{}
ret.Num = num
ret.Nils = utils.NewHSet(data.ZSTATE0_INNAME)
ret.Roots = utils.NewHSet(ZSTATE0_ROOT_OUT)
return
}
func (state *Data) Clear() {
state.Root2Out = make(map[c_type.Uint256]localdb.RootState)
state.PKr2Count = make(map[c_type.PKr]int)
state.Dels.Clear()
state.Nils.Clear()
state.Roots.Clear()
}
func (self *Data) AddTxOut(pkr *c_type.PKr) int {
if count, ok := self.PKr2Count[*pkr]; !ok {
self.PKr2Count[*pkr] = 1
return 1
} else {
count++
self.PKr2Count[*pkr] = count
return count
}
}
func (self *Data) AddOut(root *c_type.Uint256, out *localdb.OutState, txhash *c_type.Uint256) {
self.Roots.Append(root)
rs := localdb.RootState{}
rs.Num = self.Num
rs.OS = *out
if txhash != nil {
rs.TxHash = *txhash
}
self.Root2Out[*root] = rs
return
}
func (self *Data) AddNil(in *c_type.Uint256) {
self.Nils.Append(in)
self.Dels.Append(in)
}
func (self *Data) AddDel(in *c_type.Uint256) {
self.Dels.Append(in)
}
func (self *Data) GetRoots() (roots []c_type.Uint256) {
return self.Roots.List()
}
func (self *Data) GetDels() (dels []c_type.Uint256) {
return self.Dels.List()
}