Ai
1 Star 0 Fork 0

艾鸥科技/go-aiou

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
delaytx_handler.go 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
张卓 提交于 2020-05-10 14:55 +08:00 . init
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))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/aiou-official/go-aiou.git
git@gitee.com:aiou-official/go-aiou.git
aiou-official
go-aiou
go-aiou
376a44096468

搜索帮助