-
Notifications
You must be signed in to change notification settings - Fork 113
/
adapter.go
68 lines (58 loc) · 1.12 KB
/
adapter.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
package database
import (
"github.com/iost-official/go-iost/core/version"
)
type database interface {
Rules() *version.Rules
Get(key string) (value string)
Put(key, value string)
Has(key string) bool
Del(key string)
}
const (
// StateTable name
StateTable = "state"
)
type chainbaseAdapter struct {
cb IMultiValue
rules *version.Rules
}
func (c *chainbaseAdapter) Rules() *version.Rules {
return c.rules
}
func (c *chainbaseAdapter) Get(key string) (value string) {
var err error
value, err = c.cb.Get(StateTable, key)
if err != nil {
panic(err)
}
if value == "" {
return NilPrefix
}
return
}
func (c *chainbaseAdapter) Put(key, value string) {
err := c.cb.Put(StateTable, key, value)
if err != nil {
panic(err)
}
}
func (c *chainbaseAdapter) Has(key string) bool {
ok, err := c.cb.Has(StateTable, key)
if err != nil {
panic(err)
}
return ok
}
func (c *chainbaseAdapter) Del(key string) {
err := c.cb.Del(StateTable, key)
if err != nil {
panic(err)
}
}
func newChainbaseAdapter(cb IMultiValue, rules *version.Rules) *chainbaseAdapter {
return &chainbaseAdapter{
cb: cb,
rules: rules,
}
}