-
Notifications
You must be signed in to change notification settings - Fork 113
/
delaytx_handler.go
48 lines (39 loc) · 1.02 KB
/
delaytx_handler.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
package database
import (
"strings"
)
const (
delaytxPrefix = "t-"
deferSep = "@"
)
// DelaytxHandler handler of delay tx
type DelaytxHandler struct {
db database
}
func (m *DelaytxHandler) delaytxKey(txHash string) string {
return delaytxPrefix + txHash
}
// StoreDelaytx stores delaytx hash.
func (m *DelaytxHandler) StoreDelaytx(txHash, publisher, deferTxHash string) {
m.db.Put(m.delaytxKey(txHash), publisher+deferSep+deferTxHash)
}
// GetDelaytx gets the delay tx's publisher and deferTxHash.
func (m *DelaytxHandler) GetDelaytx(txHash string) (string, string) {
str := m.db.Get(m.delaytxKey(txHash))
if str == NilPrefix {
return "", ""
}
arr := strings.SplitN(str, deferSep, 2)
if len(arr) != 2 {
return "", ""
}
return arr[0], arr[1]
}
// HasDelaytx checks whether the delaytx exists.
func (m *DelaytxHandler) HasDelaytx(txHash string) bool {
return m.db.Has(m.delaytxKey(txHash))
}
// DelDelaytx deletes the delaytx hash.
func (m *DelaytxHandler) DelDelaytx(txHash string) {
m.db.Del(m.delaytxKey(txHash))
}