Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
4dbe1874
Commit
4dbe1874
authored
Nov 25, 2021
by
yxq
Committed by
vipwzw
Dec 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: prune expired kv
parent
822bd87c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
ticket.go
plugin/dapp/ticket/executor/ticket.go
+22
-0
ticketdb.go
plugin/dapp/ticket/executor/ticketdb.go
+7
-2
No files found.
plugin/dapp/ticket/executor/ticket.go
View file @
4dbe1874
...
@@ -17,6 +17,7 @@ EventTransfer -> 转移资产
...
@@ -17,6 +17,7 @@ EventTransfer -> 转移资产
//nofee transaction will not pack into block
//nofee transaction will not pack into block
import
(
import
(
"bytes"
"fmt"
"fmt"
log
"github.com/33cn/chain33/common/log/log15"
log
"github.com/33cn/chain33/common/log/log15"
...
@@ -31,6 +32,7 @@ var driverName = "ticket"
...
@@ -31,6 +32,7 @@ var driverName = "ticket"
// Init initial
// Init initial
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
GetName
(),
newTicket
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
Register
(
cfg
,
GetName
(),
newTicket
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
RegisterKVExpiredChecker
(
ty
.
TicketX
,
expiredKVChecker
)
InitExecType
()
InitExecType
()
}
}
...
@@ -193,3 +195,23 @@ func (t *Ticket) CheckTx(tx *types.Transaction, index int) error {
...
@@ -193,3 +195,23 @@ func (t *Ticket) CheckTx(tx *types.Transaction, index int) error {
func
(
t
*
Ticket
)
CheckReceiptExecOk
()
bool
{
func
(
t
*
Ticket
)
CheckReceiptExecOk
()
bool
{
return
true
return
true
}
}
// 自定义接口,用于删除不再需要保存的kv
// 比如 ticket 已经 close 之后就废弃了,可以删除
func
expiredKVChecker
(
key
,
value
[]
byte
)
bool
{
// 由于 ticketBindKeyPrefix 包含了 ticketKeyPrefix,所以需要多做一次检查
if
bytes
.
HasPrefix
(
key
,
ticketBindKeyPrefix
)
{
return
false
}
if
!
bytes
.
HasPrefix
(
key
,
ticketKeyPrefix
)
{
return
false
}
var
tk
ty
.
Ticket
if
err
:=
types
.
Decode
(
value
,
&
tk
);
err
!=
nil
{
return
false
}
if
tk
.
Status
==
ty
.
TicketClosed
{
return
true
}
return
false
}
plugin/dapp/ticket/executor/ticketdb.go
View file @
4dbe1874
...
@@ -29,6 +29,11 @@ var tlog = log.New("module", "ticket.db")
...
@@ -29,6 +29,11 @@ var tlog = log.New("module", "ticket.db")
//var genesisKey = []byte("mavl-acc-genesis")
//var genesisKey = []byte("mavl-acc-genesis")
//var addrSeed = []byte("address seed bytes for public key")
//var addrSeed = []byte("address seed bytes for public key")
var
(
ticketKeyPrefix
=
[]
byte
(
"mavl-ticket-"
)
ticketBindKeyPrefix
=
[]
byte
(
"mavl-ticket-tbind-"
)
)
// DB db
// DB db
type
DB
struct
{
type
DB
struct
{
ty
.
Ticket
ty
.
Ticket
...
@@ -106,14 +111,14 @@ func (t *DB) Save(db dbm.KV) {
...
@@ -106,14 +111,14 @@ func (t *DB) Save(db dbm.KV) {
//Key address to save key
//Key address to save key
func
Key
(
id
string
)
(
key
[]
byte
)
{
func
Key
(
id
string
)
(
key
[]
byte
)
{
key
=
append
(
key
,
[]
byte
(
"mavl-ticket-"
)
...
)
key
=
append
(
key
,
ticketKeyPrefix
...
)
key
=
append
(
key
,
[]
byte
(
id
)
...
)
key
=
append
(
key
,
[]
byte
(
id
)
...
)
return
key
return
key
}
}
// BindKey bind key
// BindKey bind key
func
BindKey
(
id
string
)
(
key
[]
byte
)
{
func
BindKey
(
id
string
)
(
key
[]
byte
)
{
key
=
append
(
key
,
[]
byte
(
"mavl-ticket-tbind-"
)
...
)
key
=
append
(
key
,
ticketBindKeyPrefix
...
)
key
=
append
(
key
,
[]
byte
(
id
)
...
)
key
=
append
(
key
,
[]
byte
(
id
)
...
)
return
key
return
key
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment