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
af4f3531
Commit
af4f3531
authored
Aug 01, 2019
by
liuyuhang
Committed by
33cn
Aug 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add db table to poard
parent
a624910f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
258 additions
and
242 deletions
+258
-242
board.go
plugin/dapp/autonomy/executor/board.go
+69
-30
board_test.go
plugin/dapp/autonomy/executor/board_test.go
+4
-2
boardtable.go
plugin/dapp/autonomy/executor/boardtable.go
+73
-0
project.go
plugin/dapp/autonomy/executor/project.go
+27
-27
project_test.go
plugin/dapp/autonomy/executor/project_test.go
+2
-2
rule.go
plugin/dapp/autonomy/executor/rule.go
+27
-27
rule_test.go
plugin/dapp/autonomy/executor/rule_test.go
+2
-2
board.proto
plugin/dapp/autonomy/proto/board.proto
+6
-5
project.proto
plugin/dapp/autonomy/proto/project.proto
+6
-5
rule.proto
plugin/dapp/autonomy/proto/rule.proto
+6
-5
autonomy.pb.go
plugin/dapp/autonomy/types/autonomy.pb.go
+0
-0
board.pb.go
plugin/dapp/autonomy/types/board.pb.go
+0
-0
lcommon.pb.go
plugin/dapp/autonomy/types/lcommon.pb.go
+36
-137
project.pb.go
plugin/dapp/autonomy/types/project.pb.go
+0
-0
rule.pb.go
plugin/dapp/autonomy/types/rule.pb.go
+0
-0
No files found.
plugin/dapp/autonomy/executor/board.go
View file @
af4f3531
...
...
@@ -14,7 +14,7 @@ import (
func
(
a
*
Autonomy
)
execLocalBoard
(
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
var
set
[]
*
types
.
KeyValue
table
:=
NewBoardTable
(
a
.
GetLocalDB
())
for
_
,
log
:=
range
receiptData
.
Logs
{
switch
log
.
Ty
{
case
auty
.
TyLogPropBoard
,
...
...
@@ -27,14 +27,23 @@ func (a *Autonomy) execLocalBoard(receiptData *types.ReceiptData) (*types.LocalD
if
err
!=
nil
{
return
nil
,
err
}
kv
:=
saveBoardHeightIndex
(
&
receipt
)
set
=
append
(
set
,
kv
...
)
err
=
table
.
Replace
(
receipt
.
Current
)
if
err
!=
nil
{
return
nil
,
err
}
}
default
:
break
}
}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
set
...
)
kvs
,
err
:=
table
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kvs
...
)
return
dbSet
,
nil
}
...
...
@@ -56,27 +65,41 @@ func saveBoardHeightIndex(res *auty.ReceiptProposalBoard) (kvs []*types.KeyValue
func
(
a
*
Autonomy
)
execDelLocalBoard
(
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
var
set
[]
*
types
.
KeyValue
table
:=
NewBoardTable
(
a
.
GetLocalDB
())
for
_
,
log
:=
range
receiptData
.
Logs
{
var
receipt
auty
.
ReceiptProposalBoard
err
:=
types
.
Decode
(
log
.
Log
,
&
receipt
)
if
err
!=
nil
{
return
nil
,
err
}
switch
log
.
Ty
{
case
auty
.
TyLogPropBoard
,
auty
.
TyLogRvkPropBoard
,
case
auty
.
TyLogPropBoard
:
{
heightIndex
:=
dapp
.
HeightIndexStr
(
receipt
.
Current
.
Height
,
int64
(
receipt
.
Current
.
Index
))
err
=
table
.
Del
([]
byte
(
heightIndex
))
if
err
!=
nil
{
return
nil
,
err
}
}
case
auty
.
TyLogRvkPropBoard
,
auty
.
TyLogVotePropBoard
,
auty
.
TyLogTmintPropBoard
:
{
var
receipt
auty
.
ReceiptProposalBoard
err
:=
types
.
Decode
(
log
.
Log
,
&
receipt
)
err
=
table
.
Replace
(
receipt
.
Prev
)
if
err
!=
nil
{
return
nil
,
err
}
kv
:=
delBoardHeightIndex
(
&
receipt
)
set
=
append
(
set
,
kv
...
)
}
default
:
break
}
}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
set
...
)
kvs
,
err
:=
table
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kvs
...
)
return
dbSet
,
nil
}
...
...
@@ -117,38 +140,54 @@ func (a *Autonomy) listProposalBoard(req *auty.ReqQueryProposalBoard) (types.Mes
if
req
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
var
key
[]
byte
var
values
[][]
byte
var
err
error
localDb
:=
a
.
GetLocalDB
()
if
req
.
GetIndex
()
==
-
1
{
key
=
nil
}
else
{
//翻页查找指定的txhash列表
heightstr
:=
genHeightIndexStr
(
req
.
GetIndex
())
key
=
calcBoardKey4StatusHeight
(
req
.
Status
,
heightstr
)
}
prefix
:=
calcBoardKey4StatusHeight
(
req
.
Status
,
""
)
values
,
err
=
localDb
.
List
(
prefix
,
key
,
req
.
Count
,
req
.
GetDirection
())
query
:=
NewBoardTable
(
localDb
)
.
GetQuery
(
localDb
)
var
primary
[]
byte
if
req
.
Height
>
0
{
primary
=
[]
byte
(
dapp
.
HeightIndexStr
(
req
.
Height
,
int64
(
req
.
Index
)))
}
indexName
:=
""
if
req
.
Status
>
0
&&
req
.
Addr
!=
""
{
indexName
=
"addr_status"
}
else
if
req
.
Status
>
0
{
indexName
=
"status"
}
else
if
req
.
Addr
!=
""
{
indexName
=
"addr"
}
cur
:=
&
BoardRow
{
AutonomyProposalBoard
:
&
auty
.
AutonomyProposalBoard
{},
}
cur
.
Address
=
req
.
Addr
cur
.
Status
=
req
.
Status
cur
.
Height
=
req
.
Height
cur
.
Index
=
req
.
Index
prefix
,
err
:=
cur
.
Get
(
indexName
)
rows
,
err
:=
query
.
ListIndex
(
indexName
,
prefix
,
primary
,
req
.
Count
,
req
.
Direction
)
if
err
!=
nil
{
alog
.
Error
(
"query List failed"
,
"indexName"
,
indexName
,
"prefix"
,
"prefix"
,
"key"
,
string
(
primary
),
"err"
,
err
)
return
nil
,
err
}
if
len
(
value
s
)
==
0
{
if
len
(
row
s
)
==
0
{
return
nil
,
types
.
ErrNotFound
}
var
rep
auty
.
ReplyQueryProposalBoard
for
_
,
value
:=
range
value
s
{
prop
:=
&
auty
.
AutonomyProposalBoard
{}
err
=
types
.
Decode
(
value
,
prop
)
if
err
!=
nil
{
return
nil
,
err
for
_
,
row
:=
range
row
s
{
r
,
ok
:=
row
.
Data
.
(
*
auty
.
AutonomyProposalBoard
)
if
!
ok
{
alog
.
Error
(
"listProposalBoard"
,
"err"
,
"bad row type"
)
return
nil
,
types
.
ErrDecode
}
rep
.
PropBoards
=
append
(
rep
.
PropBoards
,
prop
)
rep
.
PropBoards
=
append
(
rep
.
PropBoards
,
r
)
}
return
&
rep
,
nil
}
func
genHeightIndexStr
(
index
int64
)
string
{
return
fmt
.
Sprintf
(
"%018d"
,
index
)
}
plugin/dapp/autonomy/executor/board_test.go
View file @
af4f3531
...
...
@@ -15,7 +15,9 @@ import (
)
func
TestExecLocalBoard
(
t
*
testing
.
T
)
{
_
,
_
,
kvdb
:=
util
.
CreateTestDB
()
au
:=
&
Autonomy
{}
au
.
SetLocalDB
(
kvdb
)
//TyLogPropBoard
cur
:=
&
auty
.
AutonomyProposalBoard
{
PropBoard
:
&
auty
.
ProposalBoard
{},
...
...
@@ -247,12 +249,12 @@ func TestListProposalBoard(t *testing.T) {
require
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
require
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
//
Index
:=
height
*
types
.
MaxTxsPerBlock
+
int64
(
index
)
req
=
&
auty
.
ReqQueryProposalBoard
{
Status
:
auty
.
AutonomyStatusProposalBoard
,
Count
:
10
,
Direction
:
0
,
Index
:
Index
,
Height
:
height
,
Index
:
index
,
}
rsp
,
err
=
au
.
listProposalBoard
(
req
)
require
.
NoError
(
t
,
err
)
...
...
plugin/dapp/autonomy/executor/boardtable.go
0 → 100644
View file @
af4f3531
package
executor
import
(
"fmt"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/types"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/33cn/chain33/system/dapp"
)
/*
table struct
data: autonomy board
index: status, addr
*/
var
opt
=
&
table
.
Option
{
Prefix
:
"LODB-autonomy"
,
Name
:
"board"
,
Primary
:
"heightindex"
,
Index
:
[]
string
{
"addr"
,
"status"
,
"addr_status"
},
}
//NewTable 新建表
func
NewBoardTable
(
kvdb
db
.
KV
)
*
table
.
Table
{
rowmeta
:=
NewBoardRow
()
table
,
err
:=
table
.
NewTable
(
rowmeta
,
kvdb
,
opt
)
if
err
!=
nil
{
panic
(
err
)
}
return
table
}
//BoardRow table meta 结构
type
BoardRow
struct
{
*
auty
.
AutonomyProposalBoard
}
//NewBoardRow 新建一个meta 结构
func
NewBoardRow
()
*
BoardRow
{
return
&
BoardRow
{
AutonomyProposalBoard
:
&
auty
.
AutonomyProposalBoard
{}}
}
//CreateRow 新建数据行(注意index 数据一定也要保存到数据中,不能就保存heightindex)
func
(
r
*
BoardRow
)
CreateRow
()
*
table
.
Row
{
return
&
table
.
Row
{
Data
:
&
auty
.
AutonomyProposalBoard
{}}
}
//SetPayload 设置数据
func
(
r
*
BoardRow
)
SetPayload
(
data
types
.
Message
)
error
{
if
d
,
ok
:=
data
.
(
*
auty
.
AutonomyProposalBoard
);
ok
{
r
.
AutonomyProposalBoard
=
d
return
nil
}
return
types
.
ErrTypeAsset
}
//Get 按照indexName 查询 indexValue
func
(
r
*
BoardRow
)
Get
(
key
string
)
([]
byte
,
error
)
{
if
key
==
"heightindex"
{
return
[]
byte
(
dapp
.
HeightIndexStr
(
r
.
Height
,
int64
(
r
.
Index
))),
nil
}
else
if
key
==
"status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%2d"
,
r
.
Status
)),
nil
}
else
if
key
==
"addr"
{
return
[]
byte
(
r
.
Address
),
nil
}
else
if
key
==
"addr_status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%s:%2d"
,
r
.
Address
,
r
.
Status
)),
nil
}
return
nil
,
types
.
ErrNotFound
}
plugin/dapp/autonomy/executor/project.go
View file @
af4f3531
...
...
@@ -117,34 +117,34 @@ func (a *Autonomy) listProposalProject(req *auty.ReqQueryProposalProject) (types
if
req
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
var
key
[]
byte
var
values
[][]
byte
var
err
error
localDb
:=
a
.
GetLocalDB
()
if
req
.
GetIndex
()
==
-
1
{
key
=
nil
}
else
{
//翻页查找指定的txhash列表
heightstr
:=
genHeightIndexStr
(
req
.
GetIndex
())
key
=
calcProjectKey4StatusHeight
(
req
.
Status
,
heightstr
)
}
prefix
:=
calcProjectKey4StatusHeight
(
req
.
Status
,
""
)
values
,
err
=
localDb
.
List
(
prefix
,
key
,
req
.
Count
,
req
.
GetDirection
())
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
values
)
==
0
{
return
nil
,
types
.
ErrNotFound
}
//
var key []byte
//
var values [][]byte
//
var err error
//
//
localDb := a.GetLocalDB()
//
if req.GetIndex() == -1 {
//
key = nil
//
} else { //翻页查找指定的txhash列表
//
heightstr := genHeightIndexStr(req.GetIndex())
//
key = calcProjectKey4StatusHeight(req.Status, heightstr)
//
}
//
prefix := calcProjectKey4StatusHeight(req.Status, "")
//
values, err = localDb.List(prefix, key, req.Count, req.GetDirection())
//
if err != nil {
//
return nil, err
//
}
//
if len(values) == 0 {
//
return nil, types.ErrNotFound
//
}
var
rep
auty
.
ReplyQueryProposalProject
for
_
,
value
:=
range
values
{
prop
:=
&
auty
.
AutonomyProposalProject
{}
err
=
types
.
Decode
(
value
,
prop
)
if
err
!=
nil
{
return
nil
,
err
}
rep
.
PropProjects
=
append
(
rep
.
PropProjects
,
prop
)
}
//
for _, value := range values {
//
prop := &auty.AutonomyProposalProject{}
//
err = types.Decode(value, prop)
//
if err != nil {
//
return nil, err
//
}
//
rep.PropProjects = append(rep.PropProjects, prop)
//
}
return
&
rep
,
nil
}
plugin/dapp/autonomy/executor/project_test.go
View file @
af4f3531
...
...
@@ -253,12 +253,12 @@ func TestListProposalProject(t *testing.T) {
require
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
require
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
//
Index
:=
height
*
types
.
MaxTxsPerBlock
+
int64
(
index
)
req
=
&
auty
.
ReqQueryProposalProject
{
Status
:
auty
.
AutonomyStatusProposalProject
,
Count
:
10
,
Direction
:
0
,
Index
:
Index
,
Height
:
height
,
Index
:
index
,
}
rsp
,
err
=
au
.
listProposalProject
(
req
)
require
.
NoError
(
t
,
err
)
...
...
plugin/dapp/autonomy/executor/rule.go
View file @
af4f3531
...
...
@@ -115,35 +115,35 @@ func (a *Autonomy) listProposalRule(req *auty.ReqQueryProposalRule) (types.Messa
if
req
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
var
key
[]
byte
var
values
[][]
byte
var
err
error
localDb
:=
a
.
GetLocalDB
()
if
req
.
GetIndex
()
==
-
1
{
key
=
nil
}
else
{
//翻页查找指定的txhash列表
heightstr
:=
genHeightIndexStr
(
req
.
GetIndex
())
key
=
calcRuleKey4StatusHeight
(
req
.
Status
,
heightstr
)
}
prefix
:=
calcRuleKey4StatusHeight
(
req
.
Status
,
""
)
values
,
err
=
localDb
.
List
(
prefix
,
key
,
req
.
Count
,
req
.
GetDirection
())
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
values
)
==
0
{
return
nil
,
types
.
ErrNotFound
}
//
var key []byte
//
var values [][]byte
//
var err error
//
//
localDb := a.GetLocalDB()
//
if req.GetIndex() == -1 {
//
key = nil
//
} else { //翻页查找指定的txhash列表
//
heightstr := genHeightIndexStr(req.GetIndex())
//
key = calcRuleKey4StatusHeight(req.Status, heightstr)
//
}
//
prefix := calcRuleKey4StatusHeight(req.Status, "")
//
values, err = localDb.List(prefix, key, req.Count, req.GetDirection())
//
if err != nil {
//
return nil, err
//
}
//
if len(values) == 0 {
//
return nil, types.ErrNotFound
//
}
var
rep
auty
.
ReplyQueryProposalRule
for
_
,
value
:=
range
values
{
prop
:=
&
auty
.
AutonomyProposalRule
{}
err
=
types
.
Decode
(
value
,
prop
)
if
err
!=
nil
{
return
nil
,
err
}
rep
.
PropRules
=
append
(
rep
.
PropRules
,
prop
)
}
//
for _, value := range values {
//
prop := &auty.AutonomyProposalRule{}
//
err = types.Decode(value, prop)
//
if err != nil {
//
return nil, err
//
}
//
rep.PropRules = append(rep.PropRules, prop)
//
}
return
&
rep
,
nil
}
...
...
plugin/dapp/autonomy/executor/rule_test.go
View file @
af4f3531
...
...
@@ -247,12 +247,12 @@ func TestListProposalRule(t *testing.T) {
require
.
Equal
(
t
,
height
,
testcase2
[
2
]
.
height
)
require
.
Equal
(
t
,
index
,
int32
(
testcase2
[
2
]
.
index
))
//
Index
:=
height
*
types
.
MaxTxsPerBlock
+
int64
(
index
)
req
=
&
auty
.
ReqQueryProposalRule
{
Status
:
auty
.
AutonomyStatusProposalRule
,
Count
:
10
,
Direction
:
0
,
Index
:
Index
,
Height
:
height
,
Index
:
index
,
}
rsp
,
err
=
au
.
listProposalRule
(
req
)
require
.
NoError
(
t
,
err
)
...
...
plugin/dapp/autonomy/proto/board.proto
View file @
af4f3531
...
...
@@ -65,11 +65,12 @@ message LocalProposalBoard {
// query
message
ReqQueryProposalBoard
{
//优先根据status查询
int32
status
=
1
;
int32
count
=
2
;
int32
direction
=
3
;
int64
index
=
4
;
int32
count
=
1
;
int32
direction
=
2
;
int64
height
=
3
;
int32
index
=
4
;
int32
status
=
5
;
string
addr
=
6
;
}
message
ReplyQueryProposalBoard
{
...
...
plugin/dapp/autonomy/proto/project.proto
View file @
af4f3531
...
...
@@ -82,11 +82,12 @@ message LocalProposalProject {
// query
message
ReqQueryProposalProject
{
//优先根据status查询
int32
status
=
1
;
int32
count
=
2
;
int32
direction
=
3
;
int64
index
=
4
;
int32
count
=
1
;
int32
direction
=
2
;
int64
height
=
3
;
int32
index
=
4
;
int32
status
=
5
;
string
addr
=
6
;
}
message
ReplyQueryProposalProject
{
...
...
plugin/dapp/autonomy/proto/rule.proto
View file @
af4f3531
...
...
@@ -61,11 +61,12 @@ message LocalProposalRule {
// query
message
ReqQueryProposalRule
{
//优先根据status查询
int32
status
=
1
;
int32
count
=
2
;
int32
direction
=
3
;
int64
index
=
4
;
int32
count
=
1
;
int32
direction
=
2
;
int64
height
=
3
;
int32
index
=
4
;
int32
status
=
5
;
string
addr
=
6
;
}
message
ReplyQueryProposalRule
{
...
...
plugin/dapp/autonomy/types/autonomy.pb.go
View file @
af4f3531
This diff is collapsed.
Click to expand it.
plugin/dapp/autonomy/types/board.pb.go
View file @
af4f3531
This diff is collapsed.
Click to expand it.
plugin/dapp/autonomy/types/lcommon.pb.go
View file @
af4f3531
This diff is collapsed.
Click to expand it.
plugin/dapp/autonomy/types/project.pb.go
View file @
af4f3531
This diff is collapsed.
Click to expand it.
plugin/dapp/autonomy/types/rule.pb.go
View file @
af4f3531
This diff is collapsed.
Click to expand it.
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