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
3fcb74f9
Commit
3fcb74f9
authored
Feb 01, 2021
by
jiangpeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dapp/vote:classify vote with status
parent
3dc1c260
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
110 additions
and
59 deletions
+110
-59
createtx.go
plugin/dapp/vote/commands/createtx.go
+22
-16
query.go
plugin/dapp/vote/commands/query.go
+25
-16
action.go
plugin/dapp/vote/executor/action.go
+1
-0
exec_local.go
plugin/dapp/vote/executor/exec_local.go
+2
-2
query.go
plugin/dapp/vote/executor/query.go
+34
-5
util.go
plugin/dapp/vote/executor/util.go
+11
-7
vote.proto
plugin/dapp/vote/proto/vote.proto
+4
-3
readme.md
plugin/dapp/vote/readme.md
+11
-10
vote.pb.go
plugin/dapp/vote/types/vote.pb.go
+0
-0
No files found.
plugin/dapp/vote/commands/createtx.go
View file @
3fcb74f9
...
...
@@ -13,6 +13,7 @@ import (
func
createGroupCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"createGroup"
,
Aliases
:
[]
string
{
"cg"
},
Short
:
"create tx(create vote group)"
,
Run
:
createGroup
,
Example
:
"createGroup -n=group1 -a=admin1 -m=member1 -m=member2"
,
...
...
@@ -64,6 +65,7 @@ func createGroup(cmd *cobra.Command, args []string) {
func
updateGroupCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"updateGroup"
,
Aliases
:
[]
string
{
"ug"
},
Short
:
"create tx(update group members or admin)"
,
Run
:
updateGroup
,
Example
:
"updateGroup -g=id -a=addMember1 -a=addMember2 -r=removeMember1 ..."
,
...
...
@@ -74,11 +76,11 @@ func updateGroupCMD() *cobra.Command {
func
updateGroupFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"groupID"
,
"g"
,
""
,
"group id"
)
cmd
.
Flags
()
.
StringArrayP
(
"addMembers"
,
"
a
"
,
nil
,
"group member address array for adding"
)
cmd
.
Flags
()
.
StringArrayP
(
"addMembers"
,
"
m
"
,
nil
,
"group member address array for adding"
)
cmd
.
Flags
()
.
UintSliceP
(
"weights"
,
"w"
,
nil
,
"member vote weight array for adding"
)
cmd
.
Flags
()
.
StringArrayP
(
"removeMembers"
,
"
r
"
,
nil
,
"group member address array for removing"
)
cmd
.
Flags
()
.
StringArrayP
(
"addAdmins"
,
"
d
"
,
nil
,
"group admin address array for adding"
)
cmd
.
Flags
()
.
StringArrayP
(
"removeAdmins"
,
"
m
"
,
nil
,
"group admin address array for removing"
)
cmd
.
Flags
()
.
StringArrayP
(
"removeMembers"
,
"
v
"
,
nil
,
"group member address array for removing"
)
cmd
.
Flags
()
.
StringArrayP
(
"addAdmins"
,
"
a
"
,
nil
,
"group admin address array for adding"
)
cmd
.
Flags
()
.
StringArrayP
(
"removeAdmins"
,
"
r
"
,
nil
,
"group admin address array for removing"
)
markRequired
(
cmd
,
"groupID"
)
}
...
...
@@ -120,9 +122,10 @@ func updateGroup(cmd *cobra.Command, args []string) {
func
createVoteCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"createVote"
,
Short
:
"create tx(create vote)"
,
Run
:
createVote
,
Use
:
"createVote"
,
Aliases
:
[]
string
{
"ctv"
},
Short
:
"create tx(create vote)"
,
Run
:
createVote
,
}
createVoteFlags
(
cmd
)
return
cmd
...
...
@@ -180,9 +183,10 @@ func createVote(cmd *cobra.Command, args []string) {
func
commitVoteCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"commitVote"
,
Short
:
"create tx(commit vote)"
,
Run
:
commitVote
,
Use
:
"commitVote"
,
Aliases
:
[]
string
{
"cmv"
},
Short
:
"create tx(commit vote)"
,
Run
:
commitVote
,
}
commitVoteFlags
(
cmd
)
return
cmd
...
...
@@ -211,9 +215,10 @@ func commitVote(cmd *cobra.Command, args []string) {
func
closeVoteCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"closeVote"
,
Short
:
"create tx(close vote)"
,
Run
:
closeVote
,
Use
:
"closeVote"
,
Aliases
:
[]
string
{
"csv"
},
Short
:
"create tx(close vote)"
,
Run
:
closeVote
,
}
closeVoteFlags
(
cmd
)
return
cmd
...
...
@@ -239,9 +244,10 @@ func closeVote(cmd *cobra.Command, args []string) {
func
updateMemberCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"updateMember"
,
Short
:
"create tx(update member name)"
,
Run
:
updateMember
,
Use
:
"updateMember"
,
Aliases
:
[]
string
{
"um"
},
Short
:
"create tx(update member name)"
,
Run
:
updateMember
,
}
updateMemberFlags
(
cmd
)
return
cmd
...
...
plugin/dapp/vote/commands/query.go
View file @
3fcb74f9
...
...
@@ -12,6 +12,7 @@ import (
func
groupInfoCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"groupInfo"
,
Aliases
:
[]
string
{
"gf"
},
Short
:
"get group infos"
,
Run
:
groupInfo
,
Example
:
"groupInfo -g=id1 -g=id2..."
,
...
...
@@ -41,9 +42,10 @@ func groupInfo(cmd *cobra.Command, args []string) {
func
voteInfoCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"voteInfo"
,
Short
:
"get vote info"
,
Run
:
voteInfo
,
Use
:
"voteInfo"
,
Aliases
:
[]
string
{
"vf"
},
Short
:
"get vote info"
,
Run
:
voteInfo
,
}
voteInfoFlags
(
cmd
)
return
cmd
...
...
@@ -70,9 +72,10 @@ func voteInfo(cmd *cobra.Command, args []string) {
func
memberInfoCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"memberInfo"
,
Short
:
"get member info"
,
Run
:
memberInfo
,
Use
:
"memberInfo"
,
Aliases
:
[]
string
{
"mf"
},
Short
:
"get member info"
,
Run
:
memberInfo
,
}
memberInfoFlags
(
cmd
)
return
cmd
...
...
@@ -99,9 +102,10 @@ func memberInfo(cmd *cobra.Command, args []string) {
func
listGroupCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"listGroup"
,
Short
:
"show group list"
,
Run
:
listGroup
,
Use
:
"listGroup"
,
Aliases
:
[]
string
{
"lg"
},
Short
:
"show group list"
,
Run
:
listGroup
,
}
listCmdFlags
(
cmd
)
return
cmd
...
...
@@ -113,33 +117,38 @@ func listGroup(cmd *cobra.Command, args []string) {
func
listVoteCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"listVote"
,
Short
:
"show vote list"
,
Run
:
listVote
,
Use
:
"listVote"
,
Aliases
:
[]
string
{
"lv"
},
Short
:
"show vote list"
,
Run
:
listVote
,
}
listVoteFlags
(
cmd
)
return
cmd
}
func
listVoteFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"groupID"
,
"g"
,
""
,
"list vote belongs to specified group, list all if not set"
)
cmd
.
Flags
()
.
Uint32P
(
"status"
,
"t"
,
0
,
"vote status"
)
listCmdFlags
(
cmd
)
}
func
listVote
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
groupID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"groupID"
)
status
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"status"
)
listReq
:=
getListReq
(
cmd
)
req
:=
&
vty
.
ReqListVote
{
GroupID
:
groupID
,
ListReq
:
listReq
,
Status
:
status
,
}
sendQueryRPC
(
cmd
,
"ListVote"
,
req
,
&
vty
.
ReplyVoteList
{})
}
func
listMemberCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"listMember"
,
Short
:
"show member list"
,
Run
:
listMember
,
Use
:
"listMember"
,
Aliases
:
[]
string
{
"lm"
},
Short
:
"show member list"
,
Run
:
listMember
,
}
listCmdFlags
(
cmd
)
return
cmd
...
...
@@ -151,7 +160,7 @@ func listMember(cmd *cobra.Command, args []string) {
func
listCmdFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"startItem"
,
"s"
,
""
,
"list start item id, default nil value"
)
cmd
.
Flags
()
.
Uint32P
(
"count"
,
"c"
,
10
,
"list count, default 10
"
)
cmd
.
Flags
()
.
Uint32P
(
"count"
,
"c"
,
5
,
"list count, default 5
"
)
cmd
.
Flags
()
.
Uint32P
(
"direction"
,
"d"
,
1
,
"list direction, default 1 (Ascending order)"
)
}
...
...
plugin/dapp/vote/executor/action.go
View file @
3fcb74f9
...
...
@@ -147,6 +147,7 @@ func (a *action) createVote(create *vty.CreateVote) (*types.Receipt, error) {
vote
.
Name
=
create
.
Name
vote
.
GroupID
=
create
.
GroupID
vote
.
Description
=
create
.
Description
vote
.
Creator
=
a
.
fromAddr
vote
.
VoteOptions
=
make
([]
*
vty
.
VoteOption
,
0
)
for
_
,
option
:=
range
create
.
VoteOptions
{
vote
.
VoteOptions
=
append
(
vote
.
VoteOptions
,
&
vty
.
VoteOption
{
Option
:
option
})
...
...
plugin/dapp/vote/executor/exec_local.go
View file @
3fcb74f9
...
...
@@ -96,7 +96,7 @@ func (v *vote) ExecLocal_CommitVote(payload *vty.CommitVote, tx *types.Transacti
//implement code, add customize kv to dbSet...
commitInfo
:=
decodeCommitInfo
(
receiptData
.
Logs
[
0
]
.
Log
)
table
:=
newVoteTable
(
v
.
GetLocalDB
())
row
,
err
:=
table
.
GetData
([]
byte
(
formatVoteID
(
payload
.
GetVoteID
()
)))
row
,
err
:=
table
.
GetData
([]
byte
(
payload
.
GetVoteID
(
)))
if
err
!=
nil
{
elog
.
Error
(
"execLocal commitVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"voteTable get"
,
err
)
return
nil
,
err
...
...
@@ -127,7 +127,7 @@ func (v *vote) ExecLocal_CommitVote(payload *vty.CommitVote, tx *types.Transacti
func
(
v
*
vote
)
ExecLocal_CloseVote
(
payload
*
vty
.
CloseVote
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
table
:=
newVoteTable
(
v
.
GetLocalDB
())
row
,
err
:=
table
.
GetData
([]
byte
(
formatVoteID
(
payload
.
GetVoteID
()
)))
row
,
err
:=
table
.
GetData
([]
byte
(
payload
.
GetVoteID
(
)))
if
err
!=
nil
{
elog
.
Error
(
"execLocal closeVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"voteTable get"
,
err
)
return
nil
,
err
...
...
plugin/dapp/vote/executor/query.go
View file @
3fcb74f9
...
...
@@ -76,7 +76,9 @@ func (v *vote) Query_GetVotes(in *vty.ReqStrings) (types.Message, error) {
}
voteList
=
append
(
voteList
,
info
)
}
return
classifyVoteList
(
voteList
),
nil
reply
:=
&
vty
.
ReplyVoteList
{
CurrentTimestamp
:
types
.
Now
()
.
Unix
()}
reply
.
VoteList
=
filterVoteWithStatus
(
voteList
,
0
,
reply
.
CurrentTimestamp
)
return
reply
,
nil
}
...
...
@@ -124,13 +126,18 @@ func (v *vote) Query_ListGroup(in *vty.ReqListItem) (types.Message, error) {
table
:=
newGroupTable
(
v
.
GetLocalDB
())
var
primaryKey
[]
byte
primaryKey
=
append
(
primaryKey
,
[]
byte
(
in
.
StartItemID
)
...
)
list
:=
&
vty
.
GroupInfos
{}
rows
,
err
:=
table
.
ListIndex
(
groupTablePrimary
,
nil
,
primaryKey
,
in
.
Count
,
in
.
Direction
)
// 已经没有数据,直接返回
if
err
==
types
.
ErrNotFound
{
return
list
,
nil
}
if
err
!=
nil
{
elog
.
Error
(
"query listGroup"
,
"err"
,
err
,
"param"
,
in
)
return
nil
,
err
}
list
:=
&
vty
.
GroupInfos
{
GroupList
:
make
([]
*
vty
.
GroupInfo
,
0
,
len
(
rows
))}
list
.
GroupList
=
make
([]
*
vty
.
GroupInfo
,
0
,
len
(
rows
))
for
_
,
row
:=
range
rows
{
info
,
ok
:=
row
.
Data
.
(
*
vty
.
GroupInfo
)
if
!
ok
{
...
...
@@ -157,7 +164,16 @@ func (v *vote) Query_ListVote(in *vty.ReqListVote) (types.Message, error) {
prefix
=
[]
byte
(
groupID
)
}
primaryKey
=
append
(
primaryKey
,
[]
byte
(
in
.
GetListReq
()
.
GetStartItemID
())
...
)
rows
,
err
:=
table
.
ListIndex
(
indexName
,
prefix
,
primaryKey
,
in
.
GetListReq
()
.
Count
,
in
.
GetListReq
()
.
Direction
)
reply
:=
&
vty
.
ReplyVoteList
{
CurrentTimestamp
:
types
.
Now
()
.
Unix
()}
listCount
:=
in
.
ListReq
.
GetCount
()
listMore
:
rows
,
err
:=
table
.
ListIndex
(
indexName
,
prefix
,
primaryKey
,
listCount
,
in
.
GetListReq
()
.
Direction
)
// 已经没有数据,直接返回
if
err
==
types
.
ErrNotFound
{
return
reply
,
nil
}
if
err
!=
nil
{
elog
.
Error
(
"query listVote"
,
"err"
,
err
,
"param"
,
in
)
return
nil
,
err
...
...
@@ -171,8 +187,16 @@ func (v *vote) Query_ListVote(in *vty.ReqListVote) (types.Message, error) {
}
list
=
append
(
list
,
info
)
}
primaryKey
=
append
(
primaryKey
[
:
0
],
[]
byte
(
list
[
len
(
list
)
-
1
]
.
ID
)
...
)
list
=
filterVoteWithStatus
(
list
,
in
.
Status
,
reply
.
CurrentTimestamp
)
reply
.
VoteList
=
append
(
reply
.
VoteList
,
list
...
)
//经过筛选后,数量小于请求数量,则需要再次list, 需要满足len(rows)==listCount, 否则表示已经没有数据
if
len
(
rows
)
==
int
(
listCount
)
&&
int
(
listCount
)
>
len
(
list
)
{
listCount
-=
int32
(
len
(
list
))
goto
listMore
}
return
classifyVoteList
(
list
)
,
nil
return
reply
,
nil
}
func
(
v
*
vote
)
Query_ListMember
(
in
*
vty
.
ReqListItem
)
(
types
.
Message
,
error
)
{
...
...
@@ -183,13 +207,18 @@ func (v *vote) Query_ListMember(in *vty.ReqListItem) (types.Message, error) {
table
:=
newMemberTable
(
v
.
GetLocalDB
())
var
primaryKey
[]
byte
primaryKey
=
append
(
primaryKey
,
[]
byte
(
in
.
StartItemID
)
...
)
list
:=
&
vty
.
MemberInfos
{}
rows
,
err
:=
table
.
ListIndex
(
memberTablePrimary
,
nil
,
primaryKey
,
in
.
Count
,
in
.
Direction
)
// 已经没有数据,直接返回
if
err
==
types
.
ErrNotFound
{
return
list
,
nil
}
if
err
!=
nil
{
elog
.
Error
(
"query listMember"
,
"err"
,
err
,
"param"
,
in
)
return
nil
,
err
}
list
:=
&
vty
.
MemberInfos
{
MemberList
:
make
([]
*
vty
.
MemberInfo
,
0
,
len
(
rows
))}
list
.
MemberList
=
make
([]
*
vty
.
MemberInfo
,
0
,
len
(
rows
))
for
_
,
row
:=
range
rows
{
info
,
ok
:=
row
.
Data
.
(
*
vty
.
MemberInfo
)
if
!
ok
{
...
...
plugin/dapp/vote/executor/util.go
View file @
3fcb74f9
...
...
@@ -91,14 +91,12 @@ func decodeCommitInfo(data []byte) *vty.CommitInfo {
return
info
}
func
classifyVoteList
(
voteList
[]
*
vty
.
VoteInfo
)
*
vty
.
ReplyVoteList
{
func
filterVoteWithStatus
(
voteList
[]
*
vty
.
VoteInfo
,
status
uint32
,
currentTime
int64
)
[]
*
vty
.
VoteInfo
{
reply
:=
&
vty
.
ReplyVoteList
{}
currentTime
:=
types
.
Now
()
.
Unix
()
var
filterList
[]
*
vty
.
VoteInfo
for
_
,
voteInfo
:=
range
voteList
{
if
voteInfo
.
Status
==
voteStatusClosed
{
continue
}
else
if
voteInfo
.
BeginTimestamp
>
currentTime
{
voteInfo
.
Status
=
voteStatusPending
}
else
if
voteInfo
.
EndTimestamp
>
currentTime
{
...
...
@@ -106,8 +104,14 @@ func classifyVoteList(voteList []*vty.VoteInfo) *vty.ReplyVoteList {
}
else
{
voteInfo
.
Status
=
voteStatusFinished
}
//remove vote info with other status
if
status
==
voteInfo
.
Status
{
filterList
=
append
(
filterList
,
voteInfo
)
}
}
//设置了状态筛选,返回对应的筛选列表
if
status
>
0
{
return
filterList
}
reply
.
CurrentTimestamp
=
currentTime
reply
.
VoteList
=
voteList
return
reply
return
voteList
}
plugin/dapp/vote/proto/vote.proto
View file @
3fcb74f9
...
...
@@ -124,13 +124,14 @@ message ReqStrings {
//列表请求结构
message
ReqListItem
{
string
startItemID
=
1
;
//列表开始的ID,如请求组列表即groupID,不包含在结果中
int32
count
=
2
;
//请求列表项数量
int32
direction
=
3
;
// 0表示根据ID降序,1表示升序
int32
count
=
2
;
//请求列表项数量
, 0表示请求所有
int32
direction
=
3
;
// 0表示根据ID降序,1表示升序
,目前ID和区块高度正相关
}
message
ReqListVote
{
string
groupID
=
1
;
//所属组ID
string
groupID
=
1
;
//
指定
所属组ID
ReqListItem
listReq
=
2
;
//列表请求
uint32
status
=
3
;
//指定投票状态
}
message
ReplyVoteList
{
...
...
plugin/dapp/vote/readme.md
View file @
3fcb74f9
...
...
@@ -353,9 +353,9 @@ curl -kd '{"method":"Chain33.Query","params":[{"execer":"vote","funcName":"GetM
```
proto
//列表请求结构
message
ReqListItem
{
string
startItemID
=
1
;
//列表开始的
投票组
ID,不包含在结果中
int32
count
=
2
;
//
列表项单次请求数量
int32
direction
=
3
;
// 0表示根据ID降序,1表示升序
string
startItemID
=
1
;
//列表开始的
ID,如请求组列表即group
ID,不包含在结果中
int32
count
=
2
;
//
请求列表项数量, 0表示请求所有
int32
direction
=
3
;
// 0表示根据ID降序,1表示升序
,目前ID和区块高度正相关
}
```
...
...
@@ -381,14 +381,15 @@ curl -kd '{"method":"Chain33.Query","params":[{"execer":"vote","funcName":"List
```
proto
//列表请求结构
message
ReqListVote
{
string
groupID
=
1
;
//
所属组ID,不填时获取全局的投票列表
string
groupID
=
1
;
//
指定所属组ID
ReqListItem
listReq
=
2
;
//列表请求
uint32
status
=
3
;
//指定投票状态
}
message
ReqListItem
{
string
startItemID
=
1
;
//列表开始的
投票
ID,不包含在结果中
int32
count
=
2
;
//
列表项单次请求数量
int32
direction
=
3
;
// 0表示根据ID降序,1表示升序
string
startItemID
=
1
;
//列表开始的
ID,如请求组列表即group
ID,不包含在结果中
int32
count
=
2
;
//
请求列表项数量, 0表示请求所有
int32
direction
=
3
;
// 0表示根据ID降序,1表示升序
,目前ID和区块高度正相关
}
```
...
...
@@ -418,9 +419,9 @@ curl -kd '{"method":"Chain33.Query","params":[{"execer":"vote","funcName":"List
```
proto
//列表请求结构
message
ReqListItem
{
string
startItemID
=
1
;
//列表开始的
用户ID(地址)
int32
count
=
2
;
//
列表项单次请求数量
int32
direction
=
3
;
// 0表示根据ID降序,1表示升序
string
startItemID
=
1
;
//列表开始的
ID,如请求组列表即groupID,不包含在结果中
int32
count
=
2
;
//
请求列表项数量, 0表示请求所有
int32
direction
=
3
;
// 0表示根据ID降序,1表示升序
,目前ID和区块高度正相关
}
```
...
...
plugin/dapp/vote/types/vote.pb.go
View file @
3fcb74f9
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