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
60f2071b
Commit
60f2071b
authored
Jan 22, 2021
by
jiangpeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dapp/vote:update
parent
d42515f7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
595 additions
and
228 deletions
+595
-228
commands.go
plugin/dapp/vote/commands/commands.go
+1
-1
createtx.go
plugin/dapp/vote/commands/createtx.go
+101
-32
query.go
plugin/dapp/vote/commands/query.go
+55
-36
action.go
plugin/dapp/vote/executor/action.go
+72
-18
checktx.go
plugin/dapp/vote/executor/checktx.go
+71
-35
errors.go
plugin/dapp/vote/executor/errors.go
+2
-0
exec.go
plugin/dapp/vote/executor/exec.go
+12
-2
exec_local.go
plugin/dapp/vote/executor/exec_local.go
+83
-33
query.go
plugin/dapp/vote/executor/query.go
+73
-23
table.go
plugin/dapp/vote/executor/table.go
+8
-5
util.go
plugin/dapp/vote/executor/util.go
+34
-5
vote.proto
plugin/dapp/vote/proto/vote.proto
+64
-31
vote.go
plugin/dapp/vote/types/vote.go
+19
-7
vote.pb.go
plugin/dapp/vote/types/vote.pb.go
+0
-0
No files found.
plugin/dapp/vote/commands/commands.go
View file @
60f2071b
...
@@ -23,7 +23,7 @@ func Cmd() *cobra.Command {
...
@@ -23,7 +23,7 @@ func Cmd() *cobra.Command {
cmd
.
AddCommand
(
cmd
.
AddCommand
(
//create tx
//create tx
createGroupCMD
(),
createGroupCMD
(),
update
Member
CMD
(),
update
Group
CMD
(),
createVoteCMD
(),
createVoteCMD
(),
commitVoteCMD
(),
commitVoteCMD
(),
//query rpc
//query rpc
...
...
plugin/dapp/vote/commands/createtx.go
View file @
60f2071b
...
@@ -3,6 +3,7 @@ package commands
...
@@ -3,6 +3,7 @@ package commands
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"time"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
vty
"github.com/33cn/plugin/plugin/dapp/vote/types"
vty
"github.com/33cn/plugin/plugin/dapp/vote/types"
...
@@ -22,7 +23,7 @@ func createGroupCMD() *cobra.Command {
...
@@ -22,7 +23,7 @@ func createGroupCMD() *cobra.Command {
func
createGroupFlags
(
cmd
*
cobra
.
Command
)
{
func
createGroupFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"name"
,
"n"
,
""
,
"group name"
)
cmd
.
Flags
()
.
StringP
(
"name"
,
"n"
,
""
,
"group name"
)
cmd
.
Flags
()
.
StringArrayP
(
"admins"
,
"a"
,
nil
,
"group admin address array"
)
cmd
.
Flags
()
.
StringArrayP
(
"admins"
,
"a"
,
nil
,
"group admin address array
, default set creator as admin
"
)
cmd
.
Flags
()
.
StringArrayP
(
"members"
,
"m"
,
nil
,
"group member address array"
)
cmd
.
Flags
()
.
StringArrayP
(
"members"
,
"m"
,
nil
,
"group member address array"
)
cmd
.
Flags
()
.
UintSliceP
(
"weights"
,
"w"
,
nil
,
"member vote weight array"
)
cmd
.
Flags
()
.
UintSliceP
(
"weights"
,
"w"
,
nil
,
"member vote weight array"
)
markRequired
(
cmd
,
"name"
)
markRequired
(
cmd
,
"name"
)
...
@@ -37,12 +38,14 @@ func createGroup(cmd *cobra.Command, args []string) {
...
@@ -37,12 +38,14 @@ func createGroup(cmd *cobra.Command, args []string) {
if
name
==
""
{
if
name
==
""
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilGroupName"
)
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilGroupName"
)
return
}
}
if
len
(
weights
)
==
0
{
if
len
(
weights
)
==
0
{
weights
=
make
([]
uint
,
len
(
memberAddrs
))
weights
=
make
([]
uint
,
len
(
memberAddrs
))
}
}
if
len
(
weights
)
!=
len
(
memberAddrs
)
{
if
len
(
weights
)
!=
len
(
memberAddrs
)
{
fmt
.
Fprintf
(
os
.
Stderr
,
"member address array length should equal with vote weight array length"
)
fmt
.
Fprintf
(
os
.
Stderr
,
"member address array length should equal with vote weight array length"
)
return
}
}
members
:=
make
([]
*
vty
.
GroupMember
,
0
)
members
:=
make
([]
*
vty
.
GroupMember
,
0
)
...
@@ -58,40 +61,46 @@ func createGroup(cmd *cobra.Command, args []string) {
...
@@ -58,40 +61,46 @@ func createGroup(cmd *cobra.Command, args []string) {
sendCreateTxRPC
(
cmd
,
vty
.
NameCreateGroupAction
,
params
)
sendCreateTxRPC
(
cmd
,
vty
.
NameCreateGroupAction
,
params
)
}
}
func
update
Member
CMD
()
*
cobra
.
Command
{
func
update
Group
CMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"update
Member
"
,
Use
:
"update
Group
"
,
Short
:
"create tx(update group members)"
,
Short
:
"create tx(update group members
or admin
)"
,
Run
:
update
Member
,
Run
:
update
Group
,
Example
:
"update
Member
-g=id -a=addMember1 -a=addMember2 -r=removeMember1 ..."
,
Example
:
"update
Group
-g=id -a=addMember1 -a=addMember2 -r=removeMember1 ..."
,
}
}
update
Member
Flags
(
cmd
)
update
Group
Flags
(
cmd
)
return
cmd
return
cmd
}
}
func
update
Member
Flags
(
cmd
*
cobra
.
Command
)
{
func
update
Group
Flags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"groupID"
,
"g"
,
""
,
"group id"
)
cmd
.
Flags
()
.
StringP
(
"groupID"
,
"g"
,
""
,
"group id"
)
cmd
.
Flags
()
.
StringArrayP
(
"addMembers"
,
"a"
,
nil
,
"group member address array for adding"
)
cmd
.
Flags
()
.
StringArrayP
(
"addMembers"
,
"a"
,
nil
,
"group member address array for adding"
)
cmd
.
Flags
()
.
UintSliceP
(
"weights"
,
"w"
,
nil
,
"member vote weight 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
(
"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"
)
markRequired
(
cmd
,
"groupID"
)
markRequired
(
cmd
,
"groupID"
)
}
}
func
update
Member
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
update
Group
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
groupID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"groupID"
)
groupID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"groupID"
)
addAddrs
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"addMembers"
)
addAddrs
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"addMembers"
)
weights
,
_
:=
cmd
.
Flags
()
.
GetUintSlice
(
"weights"
)
weights
,
_
:=
cmd
.
Flags
()
.
GetUintSlice
(
"weights"
)
removeAddrs
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"removeMembers"
)
removeAddrs
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"removeMembers"
)
addAdmins
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"addAdmins"
)
removeAdmins
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"removeAdmins"
)
if
groupID
==
""
{
if
groupID
==
""
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilGroupID"
)
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilGroupID"
)
return
}
}
if
len
(
weights
)
==
0
{
if
len
(
weights
)
==
0
{
weights
=
make
([]
uint
,
len
(
addAddrs
))
weights
=
make
([]
uint
,
len
(
addAddrs
))
}
}
if
len
(
weights
)
!=
len
(
addAddrs
)
{
if
len
(
weights
)
!=
len
(
addAddrs
)
{
fmt
.
Fprintf
(
os
.
Stderr
,
"member address array length should equal with vote weight array length"
)
fmt
.
Fprintf
(
os
.
Stderr
,
"member address array length should equal with vote weight array length"
)
return
}
}
addMembers
:=
make
([]
*
vty
.
GroupMember
,
0
)
addMembers
:=
make
([]
*
vty
.
GroupMember
,
0
)
...
@@ -99,12 +108,14 @@ func updateMember(cmd *cobra.Command, args []string) {
...
@@ -99,12 +108,14 @@ func updateMember(cmd *cobra.Command, args []string) {
addMembers
=
append
(
addMembers
,
&
vty
.
GroupMember
{
Addr
:
addr
,
VoteWeight
:
uint32
(
weights
[
i
])})
addMembers
=
append
(
addMembers
,
&
vty
.
GroupMember
{
Addr
:
addr
,
VoteWeight
:
uint32
(
weights
[
i
])})
}
}
params
:=
&
vty
.
UpdateMember
{
params
:=
&
vty
.
UpdateGroup
{
GroupID
:
groupID
,
GroupID
:
groupID
,
RemoveMemberAddrs
:
removeAddrs
,
RemoveMembers
:
removeAddrs
,
AddMembers
:
addMembers
,
AddMembers
:
addMembers
,
AddAdmins
:
addAdmins
,
RemoveAdmins
:
removeAdmins
,
}
}
sendCreateTxRPC
(
cmd
,
vty
.
NameUpdate
Member
Action
,
params
)
sendCreateTxRPC
(
cmd
,
vty
.
NameUpdate
Group
Action
,
params
)
}
}
func
createVoteCMD
()
*
cobra
.
Command
{
func
createVoteCMD
()
*
cobra
.
Command
{
...
@@ -119,40 +130,47 @@ func createVoteCMD() *cobra.Command {
...
@@ -119,40 +130,47 @@ func createVoteCMD() *cobra.Command {
func
createVoteFlags
(
cmd
*
cobra
.
Command
)
{
func
createVoteFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"name"
,
"n"
,
""
,
"vote name"
)
cmd
.
Flags
()
.
StringP
(
"name"
,
"n"
,
""
,
"vote name"
)
cmd
.
Flags
()
.
String
ArrayP
(
"groupIDs"
,
"g"
,
nil
,
"related group id array
"
)
cmd
.
Flags
()
.
String
P
(
"groupID"
,
"g"
,
""
,
"belonging group id
"
)
cmd
.
Flags
()
.
StringArrayP
(
"options"
,
"o"
,
nil
,
"vote option array"
)
cmd
.
Flags
()
.
StringArrayP
(
"options"
,
"o"
,
nil
,
"vote option array"
)
cmd
.
Flags
()
.
Int64P
(
"beginTime"
,
"b"
,
0
,
"vote begin unix timestamp, default set
now
time"
)
cmd
.
Flags
()
.
Int64P
(
"beginTime"
,
"b"
,
0
,
"vote begin unix timestamp, default set
current
time"
)
cmd
.
Flags
()
.
Int64P
(
"endTime"
,
"e"
,
0
,
"vote end unix timestamp, default set beginTime + 300 seconds
"
)
cmd
.
Flags
()
.
StringP
(
"duration"
,
"d"
,
"24h"
,
"vote duration time, such as(10s, 10m, 10h), default 24h
"
)
markRequired
(
cmd
,
"name"
,
"groupID
s
"
,
"options"
)
markRequired
(
cmd
,
"name"
,
"groupID"
,
"options"
)
}
}
func
createVote
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
createVote
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
name
,
_
:=
cmd
.
Flags
()
.
GetString
(
"name"
)
name
,
_
:=
cmd
.
Flags
()
.
GetString
(
"name"
)
groupID
s
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"groupIDs
"
)
groupID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"groupID
"
)
options
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"options"
)
options
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"options"
)
beginTime
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"beginTime"
)
beginTime
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"beginTime"
)
endTime
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"endTime
"
)
duration
,
_
:=
cmd
.
Flags
()
.
GetString
(
"duration
"
)
if
name
==
""
{
if
name
==
""
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilVoteName"
)
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilVoteName"
)
return
}
}
if
len
(
groupIDs
)
==
0
{
if
len
(
groupID
)
==
0
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilGroupIDs"
)
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilGroupID"
)
return
}
}
if
len
(
options
)
==
0
{
if
len
(
options
)
==
0
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilOptions"
)
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilOptions"
)
return
}
}
if
beginTime
==
0
{
if
beginTime
==
0
{
beginTime
=
types
.
Now
()
.
Unix
()
beginTime
=
types
.
Now
()
.
Unix
()
}
}
if
endTime
==
0
{
endTime
=
beginTime
+
300
dt
,
err
:=
time
.
ParseDuration
(
duration
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"InvalidDurationTime:"
+
err
.
Error
())
return
}
}
endTime
:=
beginTime
+
int64
(
dt
/
time
.
Second
)
params
:=
&
vty
.
CreateVote
{
params
:=
&
vty
.
CreateVote
{
Name
:
name
,
Name
:
name
,
VoteGroups
:
groupIDs
,
GroupID
:
groupID
,
VoteOptions
:
options
,
VoteOptions
:
options
,
BeginTimestamp
:
beginTime
,
BeginTimestamp
:
beginTime
,
EndTimestamp
:
endTime
,
EndTimestamp
:
endTime
,
...
@@ -172,26 +190,77 @@ func commitVoteCMD() *cobra.Command {
...
@@ -172,26 +190,77 @@ func commitVoteCMD() *cobra.Command {
func
commitVoteFlags
(
cmd
*
cobra
.
Command
)
{
func
commitVoteFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"voteID"
,
"v"
,
""
,
"vote id"
)
cmd
.
Flags
()
.
StringP
(
"voteID"
,
"v"
,
""
,
"vote id"
)
cmd
.
Flags
()
.
StringP
(
"groupID"
,
"g"
,
""
,
"belonging group id"
)
cmd
.
Flags
()
.
Uint32P
(
"optionIndex"
,
"o"
,
0
,
"voting option index in option array"
)
cmd
.
Flags
()
.
Uint32P
(
"optionIndex"
,
"o"
,
0
,
"voting option index in option array"
)
markRequired
(
cmd
,
"voteID"
,
"
groupID"
,
"
optionIndex"
)
markRequired
(
cmd
,
"voteID"
,
"optionIndex"
)
}
}
func
commitVote
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
commitVote
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
voteID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"voteID"
)
voteID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"voteID"
)
groupID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"groupID"
)
optionIndex
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"optionIndex"
)
optionIndex
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"optionIndex"
)
if
voteID
==
""
{
if
voteID
==
""
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilVoteID"
)
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilVoteID"
)
}
return
if
len
(
groupID
)
==
0
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilGroupID"
)
}
}
params
:=
&
vty
.
CommitVote
{
params
:=
&
vty
.
CommitVote
{
VoteID
:
voteID
,
VoteID
:
voteID
,
GroupID
:
groupID
,
OptionIndex
:
optionIndex
,
OptionIndex
:
optionIndex
,
}
}
sendCreateTxRPC
(
cmd
,
vty
.
NameCommitVoteAction
,
params
)
sendCreateTxRPC
(
cmd
,
vty
.
NameCommitVoteAction
,
params
)
}
}
func
closeVoteCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"closeVote"
,
Short
:
"create tx(close vote)"
,
Run
:
closeVote
,
}
closeVoteFlags
(
cmd
)
return
cmd
}
func
closeVoteFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"voteID"
,
"v"
,
""
,
"vote id"
)
markRequired
(
cmd
,
"voteID"
)
}
func
closeVote
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
voteID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"voteID"
)
if
voteID
==
""
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilVoteID"
)
return
}
params
:=
&
vty
.
CloseVote
{
VoteID
:
voteID
,
}
sendCreateTxRPC
(
cmd
,
vty
.
NameCloseVoteAction
,
params
)
}
func
updateMemberCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"updateMember"
,
Short
:
"create tx(update member name)"
,
Run
:
updateMember
,
}
updateMemberFlags
(
cmd
)
return
cmd
}
func
updateMemberFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"name"
,
"n"
,
""
,
"member name"
)
markRequired
(
cmd
,
"name"
)
}
func
updateMember
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
name
,
_
:=
cmd
.
Flags
()
.
GetString
(
"name"
)
if
name
==
""
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilMemberName"
)
return
}
params
:=
&
vty
.
UpdateMember
{
Name
:
name
,
}
sendCreateTxRPC
(
cmd
,
vty
.
NameUpdateMemberAction
,
params
)
}
plugin/dapp/vote/commands/query.go
View file @
60f2071b
...
@@ -11,36 +11,38 @@ import (
...
@@ -11,36 +11,38 @@ import (
func
groupInfoCMD
()
*
cobra
.
Command
{
func
groupInfoCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"groupInfo"
,
Use
:
"groupInfo"
,
Short
:
"show group info"
,
Short
:
"get group infos"
,
Run
:
groupInfo
,
Run
:
groupInfo
,
Example
:
"groupInfo -g=id1 -g=id2..."
,
}
}
groupInfoFlags
(
cmd
)
groupInfoFlags
(
cmd
)
return
cmd
return
cmd
}
}
func
groupInfoFlags
(
cmd
*
cobra
.
Command
)
{
func
groupInfoFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
String
P
(
"groupID"
,
"g"
,
""
,
"group id
"
)
cmd
.
Flags
()
.
String
ArrayP
(
"groupIDs"
,
"g"
,
nil
,
"group id array
"
)
markRequired
(
cmd
,
"groupID"
)
markRequired
(
cmd
,
"groupID
s
"
)
}
}
func
groupInfo
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
groupInfo
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
groupID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"groupID"
)
groupIDs
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"groupIDs"
)
if
len
(
groupID
)
==
0
{
if
len
(
groupIDs
)
==
0
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilGroupID"
)
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilGroupIDs"
)
return
}
}
params
:=
&
types
.
ReqString
{
params
:=
&
vty
.
ReqStrings
{
Data
:
groupID
,
Items
:
groupIDs
,
}
}
info
:=
&
vty
.
Group
VoteInfo
{}
info
:=
&
vty
.
Group
Infos
{}
sendQueryRPC
(
cmd
,
"GetGroup"
,
params
,
info
)
sendQueryRPC
(
cmd
,
"GetGroup
s
"
,
params
,
info
)
}
}
func
voteInfoCMD
()
*
cobra
.
Command
{
func
voteInfoCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"voteInfo"
,
Use
:
"voteInfo"
,
Short
:
"
show
vote info"
,
Short
:
"
get
vote info"
,
Run
:
voteInfo
,
Run
:
voteInfo
,
}
}
voteInfoFlags
(
cmd
)
voteInfoFlags
(
cmd
)
...
@@ -48,27 +50,28 @@ func voteInfoCMD() *cobra.Command {
...
@@ -48,27 +50,28 @@ func voteInfoCMD() *cobra.Command {
}
}
func
voteInfoFlags
(
cmd
*
cobra
.
Command
)
{
func
voteInfoFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
String
P
(
"voteID"
,
"v"
,
""
,
"vote id
"
)
cmd
.
Flags
()
.
String
ArrayP
(
"voteIDs"
,
"v"
,
nil
,
"vote id array
"
)
markRequired
(
cmd
,
"voteID"
)
markRequired
(
cmd
,
"voteID"
)
}
}
func
voteInfo
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
voteInfo
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
voteID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"voteID
"
)
voteID
s
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"voteIDs
"
)
if
len
(
voteID
)
==
0
{
if
len
(
voteID
s
)
==
0
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilVoteID"
)
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilVoteID"
)
return
}
}
params
:=
&
types
.
ReqString
{
params
:=
&
vty
.
ReqStrings
{
Data
:
voteID
,
Items
:
voteIDs
,
}
}
info
:=
&
vty
.
VoteInfo
{}
info
:=
&
vty
.
ReplyVoteList
{}
sendQueryRPC
(
cmd
,
"GetVote"
,
params
,
info
)
sendQueryRPC
(
cmd
,
"GetVote
s
"
,
params
,
info
)
}
}
func
memberInfoCMD
()
*
cobra
.
Command
{
func
memberInfoCMD
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"memberInfo"
,
Use
:
"memberInfo"
,
Short
:
"
show
member info"
,
Short
:
"
get
member info"
,
Run
:
memberInfo
,
Run
:
memberInfo
,
}
}
memberInfoFlags
(
cmd
)
memberInfoFlags
(
cmd
)
...
@@ -76,21 +79,22 @@ func memberInfoCMD() *cobra.Command {
...
@@ -76,21 +79,22 @@ func memberInfoCMD() *cobra.Command {
}
}
func
memberInfoFlags
(
cmd
*
cobra
.
Command
)
{
func
memberInfoFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
String
P
(
"addr"
,
"a"
,
""
,
"member address
"
)
cmd
.
Flags
()
.
String
ArrayP
(
"addrs"
,
"a"
,
nil
,
"member address array
"
)
markRequired
(
cmd
,
"addr"
)
markRequired
(
cmd
,
"addr"
)
}
}
func
memberInfo
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
memberInfo
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
addr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
addr
s
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"addr"
)
if
len
(
addr
)
==
0
{
if
len
(
addr
s
)
==
0
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilAddress"
)
fmt
.
Fprintf
(
os
.
Stderr
,
"ErrNilAddress"
)
return
}
}
params
:=
&
types
.
ReqString
{
params
:=
&
vty
.
ReqStrings
{
Data
:
addr
,
Items
:
addrs
,
}
}
info
:=
&
vty
.
MemberInfo
{}
info
:=
&
vty
.
MemberInfo
s
{}
sendQueryRPC
(
cmd
,
"GetMember"
,
params
,
info
)
sendQueryRPC
(
cmd
,
"GetMember
s
"
,
params
,
info
)
}
}
func
listGroupCMD
()
*
cobra
.
Command
{
func
listGroupCMD
()
*
cobra
.
Command
{
...
@@ -104,7 +108,7 @@ func listGroupCMD() *cobra.Command {
...
@@ -104,7 +108,7 @@ func listGroupCMD() *cobra.Command {
}
}
func
listGroup
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
listGroup
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runListCMD
(
cmd
,
args
,
"ListGroup"
,
&
vty
.
GroupVote
Infos
{})
runListCMD
(
cmd
,
"ListGroup"
,
&
vty
.
Group
Infos
{})
}
}
func
listVoteCMD
()
*
cobra
.
Command
{
func
listVoteCMD
()
*
cobra
.
Command
{
...
@@ -113,12 +117,22 @@ func listVoteCMD() *cobra.Command {
...
@@ -113,12 +117,22 @@ func listVoteCMD() *cobra.Command {
Short
:
"show vote list"
,
Short
:
"show vote list"
,
Run
:
listVote
,
Run
:
listVote
,
}
}
list
Cmd
Flags
(
cmd
)
list
Vote
Flags
(
cmd
)
return
cmd
return
cmd
}
}
func
listVoteFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"groupID"
,
"g"
,
""
,
"list vote belongs to specified group, list all if not set"
)
listCmdFlags
(
cmd
)
}
func
listVote
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
listVote
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runListCMD
(
cmd
,
args
,
"ListVote"
,
&
vty
.
VoteInfos
{})
groupID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"groupID"
)
listReq
:=
getListReq
(
cmd
)
req
:=
&
vty
.
ReqListVote
{
GroupID
:
groupID
,
ListReq
:
listReq
,
}
sendQueryRPC
(
cmd
,
"ListVote"
,
req
,
&
vty
.
ReplyVoteList
{})
}
}
func
listMemberCMD
()
*
cobra
.
Command
{
func
listMemberCMD
()
*
cobra
.
Command
{
...
@@ -132,23 +146,28 @@ func listMemberCMD() *cobra.Command {
...
@@ -132,23 +146,28 @@ func listMemberCMD() *cobra.Command {
}
}
func
listMember
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
listMember
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runListCMD
(
cmd
,
args
,
"ListMember"
,
&
vty
.
MemberInfos
{})
runListCMD
(
cmd
,
"ListMember"
,
&
vty
.
MemberInfos
{})
}
}
func
listCmdFlags
(
cmd
*
cobra
.
Command
)
{
func
listCmdFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"startItem"
,
"s"
,
""
,
"list start item id, default nil value"
)
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"
,
10
,
"list count, default 10"
)
cmd
.
Flags
()
.
Uint32P
(
"direction"
,
"d"
,
0
,
"list direction, default 1 (Ascending order)"
)
cmd
.
Flags
()
.
Uint32P
(
"direction"
,
"d"
,
1
,
"list direction, default 1 (Ascending order)"
)
}
func
runListCMD
(
cmd
*
cobra
.
Command
,
funcName
string
,
reply
types
.
Message
)
{
req
:=
getListReq
(
cmd
)
sendQueryRPC
(
cmd
,
funcName
,
req
,
reply
)
}
}
func
runListCMD
(
cmd
*
cobra
.
Command
,
args
[]
string
,
funcName
string
,
reply
types
.
Message
)
{
func
getListReq
(
cmd
*
cobra
.
Command
)
*
vty
.
ReqListItem
{
startID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"startItem"
)
startID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"startItem"
)
count
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"count"
)
count
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"count"
)
direction
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"direction"
)
direction
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"direction"
)
params
:=
&
vty
.
ReqListItem
{
req
:=
&
vty
.
ReqListItem
{
StartItemID
:
startID
,
StartItemID
:
startID
,
Count
:
int32
(
count
),
Count
:
int32
(
count
),
Direction
:
int32
(
direction
),
Direction
:
int32
(
direction
),
}
}
sendQueryRPC
(
cmd
,
funcName
,
params
,
reply
)
return
req
}
}
plugin/dapp/vote/executor/action.go
View file @
60f2071b
...
@@ -3,6 +3,8 @@ package executor
...
@@ -3,6 +3,8 @@ package executor
import
(
import
(
"encoding/hex"
"encoding/hex"
"github.com/33cn/chain33/system/dapp"
dbm
"github.com/33cn/chain33/common/db"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
vty
"github.com/33cn/plugin/plugin/dapp/vote/types"
vty
"github.com/33cn/plugin/plugin/dapp/vote/types"
...
@@ -51,14 +53,15 @@ func (a *action) createGroup(create *vty.CreateGroup) (*types.Receipt, error) {
...
@@ -51,14 +53,15 @@ func (a *action) createGroup(create *vty.CreateGroup) (*types.Receipt, error) {
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
xhash
:=
hex
.
EncodeToString
(
a
.
txHash
)
group
:=
&
vty
.
GroupInfo
{}
group
:=
&
vty
.
GroupInfo
{}
group
.
Name
=
create
.
Name
group
.
Name
=
create
.
Name
group
.
ID
=
formatGroupID
(
xhash
)
group
.
ID
=
formatGroupID
(
dapp
.
HeightIndexStr
(
a
.
height
,
int64
(
a
.
index
))
)
//添加创建者作为默认管理员
//添加创建者作为默认管理员
group
.
Admins
=
append
(
group
.
Admins
,
create
.
Admins
...
)
group
.
Admins
=
append
(
group
.
Admins
,
a
.
fromAddr
)
if
!
checkSliceItemExist
(
a
.
fromAddr
,
create
.
Admins
)
{
for
_
,
addr
:=
range
create
.
GetAdmins
()
{
group
.
Admins
=
append
(
group
.
Admins
,
a
.
fromAddr
)
if
addr
!=
a
.
fromAddr
{
group
.
Admins
=
append
(
group
.
Admins
,
addr
)
}
}
}
group
.
Members
=
create
.
Members
group
.
Members
=
create
.
Members
...
@@ -77,13 +80,13 @@ func (a *action) createGroup(create *vty.CreateGroup) (*types.Receipt, error) {
...
@@ -77,13 +80,13 @@ func (a *action) createGroup(create *vty.CreateGroup) (*types.Receipt, error) {
return
receipt
,
nil
return
receipt
,
nil
}
}
func
(
a
*
action
)
update
Member
(
update
*
vty
.
UpdateMember
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
update
Group
(
update
*
vty
.
UpdateGroup
)
(
*
types
.
Receipt
,
error
)
{
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
group
,
err
:=
a
.
getGroupInfo
(
update
.
GroupID
)
group
,
err
:=
a
.
getGroupInfo
(
update
.
GroupID
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"vote exec update
Member
"
,
"txHash"
,
a
.
txHash
,
"err"
,
err
)
elog
.
Error
(
"vote exec update
Group
"
,
"txHash"
,
a
.
txHash
,
"err"
,
err
)
return
nil
,
errStateDBGet
return
nil
,
errStateDBGet
}
}
addrMap
:=
make
(
map
[
string
]
int
)
addrMap
:=
make
(
map
[
string
]
int
)
...
@@ -91,20 +94,43 @@ func (a *action) updateMember(update *vty.UpdateMember) (*types.Receipt, error)
...
@@ -91,20 +94,43 @@ func (a *action) updateMember(update *vty.UpdateMember) (*types.Receipt, error)
addrMap
[
member
.
Addr
]
=
index
addrMap
[
member
.
Addr
]
=
index
}
}
// remove members
// remove members
for
_
,
addr
:=
range
update
.
GetRemoveMember
Addr
s
()
{
for
_
,
addr
:=
range
update
.
GetRemoveMembers
()
{
if
index
,
ok
:=
addrMap
[
addr
];
ok
{
if
index
,
ok
:=
addrMap
[
addr
];
ok
{
group
.
Members
=
append
(
group
.
Members
[
:
index
],
group
.
Members
[
index
+
1
:
]
...
)
group
.
Members
=
append
(
group
.
Members
[
:
index
],
group
.
Members
[
index
+
1
:
]
...
)
delete
(
addrMap
,
addr
)
}
}
}
}
// add members
// add members
for
_
,
member
:=
range
update
.
GetAddMembers
()
{
for
_
,
member
:=
range
update
.
GetAddMembers
()
{
group
.
Members
=
append
(
group
.
Members
,
member
)
if
_
,
ok
:=
addrMap
[
member
.
Addr
];
!
ok
{
group
.
Members
=
append
(
group
.
Members
,
member
)
}
}
adminMap
:=
make
(
map
[
string
]
int
)
for
index
,
addr
:=
range
group
.
Admins
{
adminMap
[
addr
]
=
index
}
// remove admins
for
_
,
addr
:=
range
update
.
GetRemoveAdmins
()
{
if
index
,
ok
:=
adminMap
[
addr
];
ok
{
group
.
Admins
=
append
(
group
.
Admins
[
:
index
],
group
.
Admins
[
index
+
1
:
]
...
)
delete
(
adminMap
,
addr
)
}
}
// add admins
for
_
,
addr
:=
range
update
.
GetAddAdmins
()
{
if
_
,
ok
:=
adminMap
[
addr
];
!
ok
{
group
.
Admins
=
append
(
group
.
Admins
,
addr
)
}
}
}
groupValue
:=
types
.
Encode
(
group
)
groupValue
:=
types
.
Encode
(
group
)
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types
.
KeyValue
{
Key
:
formatStateIDKey
(
group
.
ID
),
Value
:
groupValue
})
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types
.
KeyValue
{
Key
:
formatStateIDKey
(
group
.
ID
),
Value
:
groupValue
})
receipt
.
Logs
=
append
(
receipt
.
Logs
,
&
types
.
ReceiptLog
{
Ty
:
vty
.
TyUpdate
Member
Log
,
Log
:
groupValue
})
receipt
.
Logs
=
append
(
receipt
.
Logs
,
&
types
.
ReceiptLog
{
Ty
:
vty
.
TyUpdate
Group
Log
,
Log
:
groupValue
})
return
receipt
,
nil
return
receipt
,
nil
}
}
...
@@ -114,17 +140,17 @@ func (a *action) createVote(create *vty.CreateVote) (*types.Receipt, error) {
...
@@ -114,17 +140,17 @@ func (a *action) createVote(create *vty.CreateVote) (*types.Receipt, error) {
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
vote
:=
&
vty
.
VoteInfo
{}
vote
:=
&
vty
.
VoteInfo
{}
vote
.
ID
=
formatVoteID
(
hex
.
EncodeToString
(
a
.
txHash
))
vote
.
ID
=
formatVoteID
(
dapp
.
HeightIndexStr
(
a
.
height
,
int64
(
a
.
index
)
))
vote
.
BeginTimestamp
=
create
.
BeginTimestamp
vote
.
BeginTimestamp
=
create
.
BeginTimestamp
vote
.
EndTimestamp
=
create
.
EndTimestamp
vote
.
EndTimestamp
=
create
.
EndTimestamp
vote
.
Name
=
create
.
Name
vote
.
Name
=
create
.
Name
vote
.
VoteGroups
=
create
.
VoteGroups
vote
.
GroupID
=
create
.
GroupID
vote
.
VoteOptions
=
make
([]
*
vty
.
VoteOption
,
0
)
vote
.
VoteOptions
=
make
([]
*
vty
.
VoteOption
,
0
)
for
_
,
option
:=
range
create
.
VoteOptions
{
for
_
,
option
:=
range
create
.
VoteOptions
{
vote
.
VoteOptions
=
append
(
vote
.
VoteOptions
,
&
vty
.
VoteOption
{
Option
:
option
})
vote
.
VoteOptions
=
append
(
vote
.
VoteOptions
,
&
vty
.
VoteOption
{
Option
:
option
})
}
}
vote
.
Creator
=
a
.
fromAddr
voteValue
:=
types
.
Encode
(
vote
)
voteValue
:=
types
.
Encode
(
vote
)
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types
.
KeyValue
{
Key
:
formatStateIDKey
(
vote
.
ID
),
Value
:
voteValue
})
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types
.
KeyValue
{
Key
:
formatStateIDKey
(
vote
.
ID
),
Value
:
voteValue
})
receipt
.
Logs
=
append
(
receipt
.
Logs
,
&
types
.
ReceiptLog
{
Ty
:
vty
.
TyCreateVoteLog
,
Log
:
voteValue
})
receipt
.
Logs
=
append
(
receipt
.
Logs
,
&
types
.
ReceiptLog
{
Ty
:
vty
.
TyCreateVoteLog
,
Log
:
voteValue
})
...
@@ -136,9 +162,13 @@ func (a *action) commitVote(commit *vty.CommitVote) (*types.Receipt, error) {
...
@@ -136,9 +162,13 @@ func (a *action) commitVote(commit *vty.CommitVote) (*types.Receipt, error) {
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
vote
,
err
:=
a
.
getVoteInfo
(
commit
.
VoteID
)
vote
,
err
:=
a
.
getVoteInfo
(
commit
.
VoteID
)
group
,
err1
:=
a
.
getGroupInfo
(
commit
.
GroupID
)
if
err
!=
nil
{
if
err
!=
nil
||
err1
!=
nil
{
elog
.
Error
(
"vote exec commitVote"
,
"txHash"
,
a
.
txHash
,
"get vote err"
,
err
)
elog
.
Error
(
"vote exec commitVote"
,
"txHash"
,
a
.
txHash
,
"err"
,
err
,
"err1"
,
err1
)
return
nil
,
errStateDBGet
}
group
,
err
:=
a
.
getGroupInfo
(
vote
.
GroupID
)
if
err
!=
nil
{
elog
.
Error
(
"vote exec commitVote"
,
"txHash"
,
a
.
txHash
,
"get group err"
,
err
)
return
nil
,
errStateDBGet
return
nil
,
errStateDBGet
}
}
...
@@ -147,10 +177,34 @@ func (a *action) commitVote(commit *vty.CommitVote) (*types.Receipt, error) {
...
@@ -147,10 +177,34 @@ func (a *action) commitVote(commit *vty.CommitVote) (*types.Receipt, error) {
vote
.
VoteOptions
[
commit
.
OptionIndex
]
.
Score
+=
member
.
VoteWeight
vote
.
VoteOptions
[
commit
.
OptionIndex
]
.
Score
+=
member
.
VoteWeight
}
}
}
}
vote
.
VotedMembers
=
append
(
vote
.
VotedMembers
,
a
.
fromAddr
)
info
:=
&
vty
.
CommitInfo
{
Addr
:
a
.
fromAddr
}
vote
.
CommitInfos
=
append
(
vote
.
CommitInfos
,
info
)
voteValue
:=
types
.
Encode
(
vote
)
voteValue
:=
types
.
Encode
(
vote
)
info
.
TxHash
=
hex
.
EncodeToString
(
a
.
txHash
)
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types
.
KeyValue
{
Key
:
formatStateIDKey
(
vote
.
ID
),
Value
:
voteValue
})
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types
.
KeyValue
{
Key
:
formatStateIDKey
(
vote
.
ID
),
Value
:
voteValue
})
receipt
.
Logs
=
append
(
receipt
.
Logs
,
&
types
.
ReceiptLog
{
Ty
:
vty
.
TyCommitVoteLog
,
Log
:
voteValue
})
receipt
.
Logs
=
append
(
receipt
.
Logs
,
&
types
.
ReceiptLog
{
Ty
:
vty
.
TyCommitVoteLog
,
Log
:
types
.
Encode
(
info
)
})
return
receipt
,
nil
return
receipt
,
nil
}
}
func
(
a
*
action
)
closeVote
(
close
*
vty
.
CloseVote
)
(
*
types
.
Receipt
,
error
)
{
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
vote
,
err
:=
a
.
getVoteInfo
(
close
.
VoteID
)
if
err
!=
nil
{
elog
.
Error
(
"vote exec commitVote"
,
"txHash"
,
a
.
txHash
,
"get vote err"
,
err
)
return
nil
,
errStateDBGet
}
vote
.
Status
=
voteStatusClosed
voteValue
:=
types
.
Encode
(
vote
)
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types
.
KeyValue
{
Key
:
formatStateIDKey
(
vote
.
ID
),
Value
:
voteValue
})
receipt
.
Logs
=
append
(
receipt
.
Logs
,
&
types
.
ReceiptLog
{
Ty
:
vty
.
TyCloseVoteLog
,
Log
:
voteValue
})
return
receipt
,
nil
}
func
(
a
*
action
)
updateMember
(
update
*
vty
.
UpdateMember
)
(
*
types
.
Receipt
,
error
)
{
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
return
receipt
,
nil
}
plugin/dapp/vote/executor/checktx.go
View file @
60f2071b
...
@@ -20,12 +20,16 @@ func (v *vote) CheckTx(tx *types.Transaction, index int) error {
...
@@ -20,12 +20,16 @@ func (v *vote) CheckTx(tx *types.Transaction, index int) error {
}
}
if
action
.
Ty
==
vty
.
TyCreateGroupAction
{
if
action
.
Ty
==
vty
.
TyCreateGroupAction
{
err
=
v
.
checkCreateGroup
(
action
.
GetCreateGroup
())
err
=
v
.
checkCreateGroup
(
action
.
GetCreateGroup
())
}
else
if
action
.
Ty
==
vty
.
TyUpdate
Member
Action
{
}
else
if
action
.
Ty
==
vty
.
TyUpdate
Group
Action
{
err
=
v
.
checkUpdate
Member
(
action
.
GetUpdateMember
()
)
err
=
v
.
checkUpdate
Group
(
action
.
GetUpdateGroup
(),
tx
,
index
)
}
else
if
action
.
Ty
==
vty
.
TyCreateVoteAction
{
}
else
if
action
.
Ty
==
vty
.
TyCreateVoteAction
{
err
=
v
.
checkCreateVote
(
action
.
GetCreateVote
())
err
=
v
.
checkCreateVote
(
action
.
GetCreateVote
()
,
tx
,
index
)
}
else
if
action
.
Ty
==
vty
.
TyCommitVoteAction
{
}
else
if
action
.
Ty
==
vty
.
TyCommitVoteAction
{
err
=
v
.
checkCommitVote
(
action
.
GetCommitVote
(),
tx
,
index
)
err
=
v
.
checkCommitVote
(
action
.
GetCommitVote
(),
tx
,
index
)
}
else
if
action
.
Ty
==
vty
.
TyCloseVoteAction
{
err
=
v
.
checkCloseVote
(
action
.
GetCloseVote
(),
tx
,
index
)
}
else
if
action
.
Ty
==
vty
.
TyUpdateMemberAction
{
err
=
v
.
checkUpdateMember
(
action
.
GetUpdateMember
())
}
else
{
}
else
{
err
=
types
.
ErrActionNotSupport
err
=
types
.
ErrActionNotSupport
}
}
...
@@ -68,19 +72,35 @@ func (v *vote) checkCreateGroup(create *vty.CreateGroup) error {
...
@@ -68,19 +72,35 @@ func (v *vote) checkCreateGroup(create *vty.CreateGroup) error {
return
nil
return
nil
}
}
func
(
v
*
vote
)
checkUpdateMember
(
update
*
vty
.
UpdateMember
)
error
{
func
(
v
*
vote
)
checkUpdateGroup
(
update
*
vty
.
UpdateGroup
,
tx
*
types
.
Transaction
,
index
int
)
error
{
action
:=
newAction
(
v
,
tx
,
index
)
groupInfo
,
err
:=
action
.
getGroupInfo
(
update
.
GetGroupID
())
if
err
!=
nil
{
return
err
}
if
!
checkSliceItemExist
(
action
.
fromAddr
,
groupInfo
.
GetAdmins
())
{
return
errAddrPermissionDenied
}
if
len
(
update
.
GetGroupID
())
!=
IDLen
{
//防止将管理员全部删除
return
errInvalidGroupID
if
len
(
update
.
RemoveAdmins
)
>=
len
(
update
.
AddAdmins
)
+
len
(
groupInfo
.
GetAdmins
())
{
return
errAddrPermissionDenied
}
}
addrs
:=
make
([]
string
,
0
,
len
(
update
.
RemoveMembers
)
+
len
(
update
.
AddAdmins
)
+
len
(
update
.
RemoveAdmins
))
addrs
=
append
(
addrs
,
update
.
RemoveMembers
...
)
addrs
=
append
(
addrs
,
update
.
AddAdmins
...
)
addrs
=
append
(
addrs
,
update
.
RemoveAdmins
...
)
for
_
,
member
:=
range
update
.
AddMembers
{
for
_
,
member
:=
range
update
.
AddMembers
{
if
len
(
member
.
Addr
)
!=
addrLen
{
if
len
(
member
.
Addr
)
!=
addrLen
{
return
types
.
ErrInvalidAddress
return
types
.
ErrInvalidAddress
}
}
}
}
for
_
,
addr
:=
range
update
.
RemoveMemberA
ddrs
{
for
_
,
addr
:=
range
a
ddrs
{
if
len
(
addr
)
!=
addrLen
{
if
len
(
addr
)
!=
addrLen
{
elog
.
Error
(
"checkUpdateGroup"
,
"invalid addr"
,
addr
)
return
types
.
ErrInvalidAddress
return
types
.
ErrInvalidAddress
}
}
}
}
...
@@ -88,12 +108,21 @@ func (v *vote) checkUpdateMember(update *vty.UpdateMember) error {
...
@@ -88,12 +108,21 @@ func (v *vote) checkUpdateMember(update *vty.UpdateMember) error {
return
nil
return
nil
}
}
func
(
v
*
vote
)
checkCreateVote
(
create
*
vty
.
CreateVote
)
error
{
func
(
v
*
vote
)
checkCreateVote
(
create
*
vty
.
CreateVote
,
tx
*
types
.
Transaction
,
index
int
)
error
{
if
create
.
GetName
()
==
""
{
if
create
.
GetName
()
==
""
{
return
errEmptyName
return
errEmptyName
}
}
action
:=
newAction
(
v
,
tx
,
index
)
groupInfo
,
err
:=
action
.
getGroupInfo
(
create
.
GetGroupID
())
if
err
!=
nil
{
return
err
}
if
!
checkSliceItemExist
(
action
.
fromAddr
,
groupInfo
.
GetAdmins
())
{
return
errAddrPermissionDenied
}
if
create
.
GetEndTimestamp
()
<=
v
.
GetBlockTime
()
||
create
.
EndTimestamp
<=
create
.
BeginTimestamp
{
if
create
.
GetEndTimestamp
()
<=
v
.
GetBlockTime
()
||
create
.
EndTimestamp
<=
create
.
BeginTimestamp
{
return
errInvalidVoteTime
return
errInvalidVoteTime
}
}
...
@@ -102,29 +131,13 @@ func (v *vote) checkCreateVote(create *vty.CreateVote) error {
...
@@ -102,29 +131,13 @@ func (v *vote) checkCreateVote(create *vty.CreateVote) error {
return
errInvalidVoteOption
return
errInvalidVoteOption
}
}
if
len
(
create
.
VoteGroups
)
==
0
{
return
errEmptyVoteGroup
}
if
checkSliceItemDuplicate
(
create
.
VoteGroups
)
{
return
errDuplicateGroup
}
return
nil
return
nil
}
}
func
(
v
*
vote
)
checkCommitVote
(
commit
*
vty
.
CommitVote
,
tx
*
types
.
Transaction
,
index
int
)
error
{
func
(
v
*
vote
)
checkCommitVote
(
commit
*
vty
.
CommitVote
,
tx
*
types
.
Transaction
,
index
int
)
error
{
voteID
:=
commit
.
GetVoteID
()
groupID
:=
commit
.
GetGroupID
()
if
len
(
voteID
)
!=
IDLen
{
return
errInvalidVoteID
}
if
len
(
groupID
)
!=
IDLen
{
return
errInvalidGroupID
}
action
:=
newAction
(
v
,
tx
,
index
)
action
:=
newAction
(
v
,
tx
,
index
)
voteInfo
,
err
:=
action
.
getVoteInfo
(
voteID
)
voteInfo
,
err
:=
action
.
getVoteInfo
(
commit
.
GetVoteID
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -133,29 +146,52 @@ func (v *vote) checkCommitVote(commit *vty.CommitVote, tx *types.Transaction, in
...
@@ -133,29 +146,52 @@ func (v *vote) checkCommitVote(commit *vty.CommitVote, tx *types.Transaction, in
return
errVoteAlreadyFinished
return
errVoteAlreadyFinished
}
}
if
voteInfo
.
Status
==
voteStatusClosed
{
return
errVoteAlreadyClosed
}
if
commit
.
OptionIndex
>=
uint32
(
len
(
voteInfo
.
VoteOptions
))
{
if
commit
.
OptionIndex
>=
uint32
(
len
(
voteInfo
.
VoteOptions
))
{
return
errInvalidOptionIndex
return
errInvalidOptionIndex
}
}
//check group validity
groupInfo
,
err
:=
action
.
getGroupInfo
(
voteInfo
.
GroupID
)
if
!
checkSliceItemExist
(
commit
.
GroupID
,
voteInfo
.
VoteGroups
)
{
if
err
!=
nil
{
return
err
InvalidGroupID
return
err
}
}
// check if exist in group members
if
!
checkMemberExist
(
action
.
fromAddr
,
groupInfo
.
Members
)
{
return
errAddrPermissionDenied
}
// check if already vote
// check if already vote
if
checkSliceItemExist
(
action
.
fromAddr
,
voteInfo
.
VotedMembers
)
{
for
_
,
info
:=
range
voteInfo
.
GetCommitInfos
()
{
return
errAlreadyVoted
if
action
.
fromAddr
==
info
.
Addr
{
return
errAlreadyVoted
}
}
}
groupInfo
,
err
:=
action
.
getGroupInfo
(
commit
.
GroupID
)
return
nil
}
func
(
v
*
vote
)
checkCloseVote
(
close
*
vty
.
CloseVote
,
tx
*
types
.
Transaction
,
index
int
)
error
{
action
:=
newAction
(
v
,
tx
,
index
)
voteInfo
,
err
:=
action
.
getVoteInfo
(
close
.
GetVoteID
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
voteInfo
.
Creator
!=
action
.
fromAddr
{
// check if exist in group members
return
errAddrPermissionDenied
if
!
checkMemberExist
(
action
.
fromAddr
,
groupInfo
.
Members
)
{
}
return
errInvalidGroupMember
if
voteInfo
.
Status
==
voteStatusClosed
{
return
errVoteAlreadyClosed
}
}
return
nil
}
func
(
v
*
vote
)
checkUpdateMember
(
update
*
vty
.
UpdateMember
)
error
{
if
update
.
GetName
()
==
""
{
return
errEmptyName
}
return
nil
return
nil
}
}
plugin/dapp/vote/executor/errors.go
View file @
60f2071b
...
@@ -21,4 +21,6 @@ var (
...
@@ -21,4 +21,6 @@ var (
errAlreadyVoted
=
errors
.
New
(
"errAlreadyVoted"
)
errAlreadyVoted
=
errors
.
New
(
"errAlreadyVoted"
)
errInvalidGroupMember
=
errors
.
New
(
"errInvalidGroupMember"
)
errInvalidGroupMember
=
errors
.
New
(
"errInvalidGroupMember"
)
errVoteAlreadyFinished
=
errors
.
New
(
"errVoteAlreadyFinished"
)
errVoteAlreadyFinished
=
errors
.
New
(
"errVoteAlreadyFinished"
)
errVoteAlreadyClosed
=
errors
.
New
(
"errVoteAlreadyClosed"
)
errAddrPermissionDenied
=
errors
.
New
(
"errAddrPermissionDenied"
)
)
)
plugin/dapp/vote/executor/exec.go
View file @
60f2071b
...
@@ -15,9 +15,9 @@ func (v *vote) Exec_CreateGroup(payload *votetypes.CreateGroup, tx *types.Transa
...
@@ -15,9 +15,9 @@ func (v *vote) Exec_CreateGroup(payload *votetypes.CreateGroup, tx *types.Transa
return
action
.
createGroup
(
payload
)
return
action
.
createGroup
(
payload
)
}
}
func
(
v
*
vote
)
Exec_Update
Member
(
payload
*
votetypes
.
UpdateMember
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
v
*
vote
)
Exec_Update
Group
(
payload
*
votetypes
.
UpdateGroup
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
v
,
tx
,
index
)
action
:=
newAction
(
v
,
tx
,
index
)
return
action
.
update
Member
(
payload
)
return
action
.
update
Group
(
payload
)
}
}
func
(
v
*
vote
)
Exec_CreateVote
(
payload
*
votetypes
.
CreateVote
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
v
*
vote
)
Exec_CreateVote
(
payload
*
votetypes
.
CreateVote
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
...
@@ -29,3 +29,13 @@ func (v *vote) Exec_CommitVote(payload *votetypes.CommitVote, tx *types.Transact
...
@@ -29,3 +29,13 @@ func (v *vote) Exec_CommitVote(payload *votetypes.CommitVote, tx *types.Transact
action
:=
newAction
(
v
,
tx
,
index
)
action
:=
newAction
(
v
,
tx
,
index
)
return
action
.
commitVote
(
payload
)
return
action
.
commitVote
(
payload
)
}
}
func
(
v
*
vote
)
Exec_CloseVote
(
payload
*
votetypes
.
CloseVote
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
v
,
tx
,
index
)
return
action
.
closeVote
(
payload
)
}
func
(
v
*
vote
)
Exec_UpdateMember
(
payload
*
votetypes
.
UpdateMember
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
v
,
tx
,
index
)
return
action
.
updateMember
(
payload
)
}
plugin/dapp/vote/executor/exec_local.go
View file @
60f2071b
...
@@ -17,7 +17,7 @@ func (v *vote) ExecLocal_CreateGroup(payload *vty.CreateGroup, tx *types.Transac
...
@@ -17,7 +17,7 @@ func (v *vote) ExecLocal_CreateGroup(payload *vty.CreateGroup, tx *types.Transac
groupInfo
:=
decodeGroupInfo
(
receiptData
.
Logs
[
0
]
.
Log
)
groupInfo
:=
decodeGroupInfo
(
receiptData
.
Logs
[
0
]
.
Log
)
table
:=
newGroupTable
(
v
.
GetLocalDB
())
table
:=
newGroupTable
(
v
.
GetLocalDB
())
err
:=
table
.
Add
(
&
vty
.
GroupVoteInfo
{
GroupInfo
:
groupInfo
}
)
err
:=
table
.
Add
(
groupInfo
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"execLocal createGroup"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"table add"
,
err
)
elog
.
Error
(
"execLocal createGroup"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"table add"
,
err
)
return
nil
,
err
return
nil
,
err
...
@@ -40,31 +40,31 @@ func (v *vote) ExecLocal_CreateGroup(payload *vty.CreateGroup, tx *types.Transac
...
@@ -40,31 +40,31 @@ func (v *vote) ExecLocal_CreateGroup(payload *vty.CreateGroup, tx *types.Transac
return
v
.
addAutoRollBack
(
tx
,
dbSet
.
KV
),
nil
return
v
.
addAutoRollBack
(
tx
,
dbSet
.
KV
),
nil
}
}
func
(
v
*
vote
)
ExecLocal_Update
Member
(
update
*
vty
.
UpdateMember
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
v
*
vote
)
ExecLocal_Update
Group
(
update
*
vty
.
UpdateGroup
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
dbSet
:=
&
types
.
LocalDBSet
{}
groupInfo
:=
decodeGroupInfo
(
receiptData
.
Logs
[
0
]
.
Log
)
groupInfo
:=
decodeGroupInfo
(
receiptData
.
Logs
[
0
]
.
Log
)
table
:=
newGroupTable
(
v
.
GetLocalDB
())
table
:=
newGroupTable
(
v
.
GetLocalDB
())
err
:=
table
.
Replace
(
&
vty
.
GroupVoteInfo
{
GroupInfo
:
groupInfo
}
)
err
:=
table
.
Replace
(
groupInfo
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"execLocal
updateMember
"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"groupID"
,
groupInfo
.
ID
,
"table replace"
,
err
)
elog
.
Error
(
"execLocal
UpdateGroup
"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"groupID"
,
groupInfo
.
ID
,
"table replace"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
kvs
,
err
:=
table
.
Save
()
kvs
,
err
:=
table
.
Save
()
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"execLocal
updateMember
"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"groupID"
,
groupInfo
.
ID
,
"table save"
,
err
)
elog
.
Error
(
"execLocal
UpdateGroup
"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"groupID"
,
groupInfo
.
ID
,
"table save"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
dbSet
.
KV
=
kvs
dbSet
.
KV
=
kvs
kvs
,
err
=
v
.
addGroupMember
(
groupInfo
.
GetID
(),
update
.
AddMembers
)
kvs
,
err
=
v
.
addGroupMember
(
groupInfo
.
GetID
(),
update
.
AddMembers
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"execLocal
updateMember
"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"addMemberErr"
,
err
)
elog
.
Error
(
"execLocal
UpdateGroup
"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"addMemberErr"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kvs
...
)
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kvs
...
)
kvs
,
err
=
v
.
removeGroupMember
(
groupInfo
.
GetID
(),
update
.
RemoveMember
Addr
s
)
kvs
,
err
=
v
.
removeGroupMember
(
groupInfo
.
GetID
(),
update
.
RemoveMembers
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"execLocal
updateMember
"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"removeMemberErr"
,
err
)
elog
.
Error
(
"execLocal
UpdateGroup
"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"removeMemberErr"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kvs
...
)
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kvs
...
)
...
@@ -87,47 +87,97 @@ func (v *vote) ExecLocal_CreateVote(payload *vty.CreateVote, tx *types.Transacti
...
@@ -87,47 +87,97 @@ func (v *vote) ExecLocal_CreateVote(payload *vty.CreateVote, tx *types.Transacti
return
nil
,
err
return
nil
,
err
}
}
dbSet
.
KV
=
kvs
dbSet
.
KV
=
kvs
//auto gen for localdb auto rollback
return
v
.
addAutoRollBack
(
tx
,
dbSet
.
KV
),
nil
}
// 在关联的投票组表中记录voteID信息
func
(
v
*
vote
)
ExecLocal_CommitVote
(
payload
*
vty
.
CommitVote
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
table
=
newGroupTable
(
v
.
GetLocalDB
())
dbSet
:=
&
types
.
LocalDBSet
{}
for
_
,
groupID
:=
range
voteInfo
.
VoteGroups
{
//implement code, add customize kv to dbSet...
row
,
err
:=
table
.
GetData
([]
byte
(
groupID
))
commitInfo
:=
decodeCommitInfo
(
receiptData
.
Logs
[
0
]
.
Log
)
if
err
!=
nil
{
table
:=
newVoteTable
(
v
.
GetLocalDB
())
continue
row
,
err
:=
table
.
GetData
([]
byte
(
formatVoteID
(
payload
.
GetVoteID
())))
}
if
err
!=
nil
{
if
info
,
ok
:=
row
.
Data
.
(
*
vty
.
GroupVoteInfo
);
ok
{
elog
.
Error
(
"execLocal commitVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"voteTable get"
,
err
)
info
.
VoteIDs
=
append
(
info
.
VoteIDs
,
voteInfo
.
ID
)
return
nil
,
err
err
=
table
.
Replace
(
info
)
if
err
!=
nil
{
elog
.
Error
(
"execLocal createVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"groupID"
,
groupID
,
"groupTable replace"
,
err
)
return
nil
,
err
}
}
}
}
kvs
,
err
=
table
.
Save
()
voteInfo
,
ok
:=
row
.
Data
.
(
*
vty
.
VoteInfo
)
if
!
ok
{
elog
.
Error
(
"execLocal commitVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"voteInfo type asset"
,
err
)
return
nil
,
types
.
ErrTypeAsset
}
voteInfo
.
CommitInfos
=
append
(
voteInfo
.
CommitInfos
,
commitInfo
)
err
=
table
.
Replace
(
voteInfo
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"execLocal c
reateVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"groupTable sav
e"
,
err
)
elog
.
Error
(
"execLocal c
ommitVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"voteTable replac
e"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kvs
...
)
kvs
,
err
:=
table
.
Save
()
if
err
!=
nil
{
elog
.
Error
(
"execLocal commitVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"voteTable save"
,
err
)
return
nil
,
err
}
dbSet
.
KV
=
kvs
//auto gen for localdb auto rollback
//auto gen for localdb auto rollback
return
v
.
addAutoRollBack
(
tx
,
dbSet
.
KV
),
nil
return
v
.
addAutoRollBack
(
tx
,
dbSet
.
KV
),
nil
}
}
func
(
v
*
vote
)
ExecLocal_C
ommitVote
(
payload
*
vty
.
Commit
Vote
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
v
*
vote
)
ExecLocal_C
loseVote
(
payload
*
vty
.
Close
Vote
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
dbSet
:=
&
types
.
LocalDBSet
{}
//implement code, add customize kv to dbSet...
voteInfo
:=
decodeVoteInfo
(
receiptData
.
Logs
[
0
]
.
Log
)
table
:=
newVoteTable
(
v
.
GetLocalDB
())
table
:=
newVoteTable
(
v
.
GetLocalDB
())
err
:=
table
.
Replace
(
voteInfo
)
row
,
err
:=
table
.
GetData
([]
byte
(
formatVoteID
(
payload
.
GetVoteID
()))
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"execLocal commitVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"voteTable add"
,
err
)
elog
.
Error
(
"execLocal closeVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"voteTable get"
,
err
)
return
nil
,
err
}
voteInfo
,
ok
:=
row
.
Data
.
(
*
vty
.
VoteInfo
)
if
!
ok
{
elog
.
Error
(
"execLocal closeVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"voteInfo type asset"
,
err
)
return
nil
,
types
.
ErrTypeAsset
}
voteInfo
.
Status
=
voteStatusClosed
err
=
table
.
Replace
(
voteInfo
)
if
err
!=
nil
{
elog
.
Error
(
"execLocal closeVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"voteTable replace"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
kvs
,
err
:=
table
.
Save
()
kvs
,
err
:=
table
.
Save
()
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"execLocal commitVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"voteTable save"
,
err
)
elog
.
Error
(
"execLocal closeVote"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"voteTable save"
,
err
)
return
nil
,
err
}
dbSet
.
KV
=
kvs
//auto gen for localdb auto rollback
return
v
.
addAutoRollBack
(
tx
,
dbSet
.
KV
),
nil
}
func
(
v
*
vote
)
ExecLocal_UpdateMember
(
payload
*
vty
.
UpdateMember
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
table
:=
newMemberTable
(
v
.
GetLocalDB
())
row
,
err
:=
table
.
GetData
([]
byte
(
tx
.
From
()))
if
err
!=
nil
{
elog
.
Error
(
"execLocal updateMember"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"memberTable get"
,
err
)
return
nil
,
err
}
memberInfo
,
ok
:=
row
.
Data
.
(
*
vty
.
MemberInfo
)
if
!
ok
{
elog
.
Error
(
"execLocal updateMember"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"memberInfo type asset"
,
err
)
return
nil
,
types
.
ErrTypeAsset
}
memberInfo
.
Name
=
payload
.
GetName
()
err
=
table
.
Replace
(
memberInfo
)
if
err
!=
nil
{
elog
.
Error
(
"execLocal updateMember"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"memberTable replace"
,
err
)
return
nil
,
err
}
kvs
,
err
:=
table
.
Save
()
if
err
!=
nil
{
elog
.
Error
(
"execLocal updateMember"
,
"txHash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"memberTable save"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
dbSet
.
KV
=
kvs
dbSet
.
KV
=
kvs
...
...
plugin/dapp/vote/executor/query.go
View file @
60f2071b
...
@@ -5,36 +5,48 @@ import (
...
@@ -5,36 +5,48 @@ import (
vty
"github.com/33cn/plugin/plugin/dapp/vote/types"
vty
"github.com/33cn/plugin/plugin/dapp/vote/types"
)
)
// Query_GroupInfo query group info
func
(
v
*
vote
)
getGroup
(
groupID
string
)
(
*
vty
.
GroupInfo
,
error
)
{
func
(
v
*
vote
)
Query_GetGroup
(
in
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
if
len
(
in
.
GetData
()
)
!=
IDLen
{
if
len
(
groupID
)
!=
IDLen
{
return
nil
,
errInvalidGroupID
return
nil
,
errInvalidGroupID
}
}
groupID
:=
in
.
Data
table
:=
newGroupTable
(
v
.
GetLocalDB
())
table
:=
newGroupTable
(
v
.
GetLocalDB
())
row
,
err
:=
table
.
GetData
([]
byte
(
groupID
))
row
,
err
:=
table
.
GetData
([]
byte
(
groupID
))
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"query getGroup"
,
"
id
"
,
groupID
,
"err"
,
err
)
elog
.
Error
(
"query getGroup"
,
"
groupID
"
,
groupID
,
"err"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
info
,
ok
:=
row
.
Data
.
(
*
vty
.
Group
Vote
Info
)
info
,
ok
:=
row
.
Data
.
(
*
vty
.
GroupInfo
)
if
!
ok
{
if
!
ok
{
return
nil
,
types
.
ErrTypeAsset
return
nil
,
types
.
ErrTypeAsset
}
}
return
info
,
nil
return
info
,
nil
}
}
func
(
v
*
vote
)
Query_GetVote
(
in
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
// Query_GroupInfo query group info
func
(
v
*
vote
)
Query_GetGroups
(
in
*
vty
.
ReqStrings
)
(
types
.
Message
,
error
)
{
if
len
(
in
.
GetData
())
!=
IDLen
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
infos
:=
&
vty
.
GroupInfos
{
GroupList
:
make
([]
*
vty
.
GroupInfo
,
0
,
len
(
in
.
GetItems
()))}
for
_
,
id
:=
range
in
.
GetItems
()
{
info
,
err
:=
v
.
getGroup
(
id
)
if
err
!=
nil
{
return
nil
,
err
}
infos
.
GroupList
=
append
(
infos
.
GroupList
,
info
)
}
return
infos
,
nil
}
func
(
v
*
vote
)
getVote
(
voteID
string
)
(
*
vty
.
VoteInfo
,
error
)
{
if
len
(
voteID
)
!=
IDLen
{
return
nil
,
errInvalidVoteID
return
nil
,
errInvalidVoteID
}
}
voteID
:=
in
.
Data
table
:=
newVoteTable
(
v
.
GetLocalDB
())
table
:=
newVoteTable
(
v
.
GetLocalDB
())
row
,
err
:=
table
.
GetData
([]
byte
(
voteID
))
row
,
err
:=
table
.
GetData
([]
byte
(
voteID
))
...
@@ -49,15 +61,30 @@ func (v *vote) Query_GetVote(in *types.ReqString) (types.Message, error) {
...
@@ -49,15 +61,30 @@ func (v *vote) Query_GetVote(in *types.ReqString) (types.Message, error) {
}
}
return
info
,
nil
return
info
,
nil
}
func
(
v
*
vote
)
Query_GetVotes
(
in
*
vty
.
ReqStrings
)
(
types
.
Message
,
error
)
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
infos
:=
&
vty
.
VoteInfos
{
VoteList
:
make
([]
*
vty
.
VoteInfo
,
0
,
len
(
in
.
GetItems
()))}
for
_
,
id
:=
range
in
.
GetItems
()
{
info
,
err
:=
v
.
getVote
(
id
)
if
err
!=
nil
{
return
nil
,
err
}
infos
.
VoteList
=
append
(
infos
.
VoteList
,
info
)
}
return
classifyVoteList
(
infos
),
nil
}
}
func
(
v
*
vote
)
Query_GetMember
(
in
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
func
(
v
*
vote
)
getMember
(
addr
string
)
(
*
vty
.
MemberInfo
,
error
)
{
if
len
(
in
.
GetData
()
)
!=
addrLen
{
if
len
(
addr
)
!=
addrLen
{
return
nil
,
types
.
ErrInvalidAddress
return
nil
,
types
.
ErrInvalidAddress
}
}
addr
:=
in
.
Data
table
:=
newMemberTable
(
v
.
GetLocalDB
())
table
:=
newMemberTable
(
v
.
GetLocalDB
())
row
,
err
:=
table
.
GetData
([]
byte
(
addr
))
row
,
err
:=
table
.
GetData
([]
byte
(
addr
))
...
@@ -73,6 +100,22 @@ func (v *vote) Query_GetMember(in *types.ReqString) (types.Message, error) {
...
@@ -73,6 +100,22 @@ func (v *vote) Query_GetMember(in *types.ReqString) (types.Message, error) {
return
info
,
nil
return
info
,
nil
}
}
func
(
v
*
vote
)
Query_GetMembers
(
in
*
vty
.
ReqStrings
)
(
types
.
Message
,
error
)
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
infos
:=
&
vty
.
MemberInfos
{
MemberList
:
make
([]
*
vty
.
MemberInfo
,
0
,
len
(
in
.
GetItems
()))}
for
_
,
id
:=
range
in
.
GetItems
()
{
info
,
err
:=
v
.
getMember
(
id
)
if
err
!=
nil
{
return
nil
,
err
}
infos
.
MemberList
=
append
(
infos
.
MemberList
,
info
)
}
return
infos
,
nil
}
func
(
v
*
vote
)
Query_ListGroup
(
in
*
vty
.
ReqListItem
)
(
types
.
Message
,
error
)
{
func
(
v
*
vote
)
Query_ListGroup
(
in
*
vty
.
ReqListItem
)
(
types
.
Message
,
error
)
{
if
in
==
nil
{
if
in
==
nil
{
...
@@ -87,9 +130,9 @@ func (v *vote) Query_ListGroup(in *vty.ReqListItem) (types.Message, error) {
...
@@ -87,9 +130,9 @@ func (v *vote) Query_ListGroup(in *vty.ReqListItem) (types.Message, error) {
return
nil
,
err
return
nil
,
err
}
}
list
:=
&
vty
.
Group
VoteInfos
{
GroupList
:
make
([]
*
vty
.
GroupVoteInfo
,
0
)}
list
:=
&
vty
.
Group
Infos
{
GroupList
:
make
([]
*
vty
.
GroupInfo
,
0
,
len
(
rows
)
)}
for
_
,
row
:=
range
rows
{
for
_
,
row
:=
range
rows
{
info
,
ok
:=
row
.
Data
.
(
*
vty
.
Group
Vote
Info
)
info
,
ok
:=
row
.
Data
.
(
*
vty
.
GroupInfo
)
if
!
ok
{
if
!
ok
{
return
nil
,
types
.
ErrTypeAsset
return
nil
,
types
.
ErrTypeAsset
}
}
...
@@ -99,21 +142,28 @@ func (v *vote) Query_ListGroup(in *vty.ReqListItem) (types.Message, error) {
...
@@ -99,21 +142,28 @@ func (v *vote) Query_ListGroup(in *vty.ReqListItem) (types.Message, error) {
return
list
,
nil
return
list
,
nil
}
}
func
(
v
*
vote
)
Query_ListVote
(
in
*
vty
.
ReqList
Item
)
(
types
.
Message
,
error
)
{
func
(
v
*
vote
)
Query_ListVote
(
in
*
vty
.
ReqList
Vote
)
(
types
.
Message
,
error
)
{
if
in
==
nil
{
if
in
.
GetListReq
()
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
table
:=
newVoteTable
(
v
.
GetLocalDB
())
table
:=
newVoteTable
(
v
.
GetLocalDB
())
var
primaryKey
[]
byte
//指定了组ID,则查询对应组下的投票列表
primaryKey
=
append
(
primaryKey
,
[]
byte
(
in
.
StartItemID
)
...
)
groupID
:=
in
.
GetGroupID
()
rows
,
err
:=
table
.
ListIndex
(
voteTablePrimary
,
nil
,
primaryKey
,
in
.
Count
,
in
.
Direction
)
indexName
:=
voteTablePrimary
var
prefix
,
primaryKey
[]
byte
if
len
(
groupID
)
>
0
{
indexName
=
groupTablePrimary
prefix
=
[]
byte
(
groupID
)
}
primaryKey
=
append
(
primaryKey
,
[]
byte
(
in
.
GetListReq
()
.
GetStartItemID
())
...
)
rows
,
err
:=
table
.
ListIndex
(
indexName
,
prefix
,
primaryKey
,
in
.
GetListReq
()
.
Count
,
in
.
GetListReq
()
.
Direction
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"query listVote"
,
"err"
,
err
,
"param"
,
in
)
elog
.
Error
(
"query listVote"
,
"err"
,
err
,
"param"
,
in
)
return
nil
,
err
return
nil
,
err
}
}
list
:=
&
vty
.
VoteInfos
{
VoteList
:
make
([]
*
vty
.
VoteInfo
,
0
)}
list
:=
&
vty
.
VoteInfos
{
VoteList
:
make
([]
*
vty
.
VoteInfo
,
0
,
len
(
rows
)
)}
for
_
,
row
:=
range
rows
{
for
_
,
row
:=
range
rows
{
info
,
ok
:=
row
.
Data
.
(
*
vty
.
VoteInfo
)
info
,
ok
:=
row
.
Data
.
(
*
vty
.
VoteInfo
)
if
!
ok
{
if
!
ok
{
...
@@ -122,7 +172,7 @@ func (v *vote) Query_ListVote(in *vty.ReqListItem) (types.Message, error) {
...
@@ -122,7 +172,7 @@ func (v *vote) Query_ListVote(in *vty.ReqListItem) (types.Message, error) {
list
.
VoteList
=
append
(
list
.
VoteList
,
info
)
list
.
VoteList
=
append
(
list
.
VoteList
,
info
)
}
}
return
list
,
nil
return
classifyVoteList
(
list
)
,
nil
}
}
func
(
v
*
vote
)
Query_ListMember
(
in
*
vty
.
ReqListItem
)
(
types
.
Message
,
error
)
{
func
(
v
*
vote
)
Query_ListMember
(
in
*
vty
.
ReqListItem
)
(
types
.
Message
,
error
)
{
...
@@ -139,7 +189,7 @@ func (v *vote) Query_ListMember(in *vty.ReqListItem) (types.Message, error) {
...
@@ -139,7 +189,7 @@ func (v *vote) Query_ListMember(in *vty.ReqListItem) (types.Message, error) {
return
nil
,
err
return
nil
,
err
}
}
list
:=
&
vty
.
MemberInfos
{
MemberList
:
make
([]
*
vty
.
MemberInfo
,
0
)}
list
:=
&
vty
.
MemberInfos
{
MemberList
:
make
([]
*
vty
.
MemberInfo
,
0
,
len
(
rows
)
)}
for
_
,
row
:=
range
rows
{
for
_
,
row
:=
range
rows
{
info
,
ok
:=
row
.
Data
.
(
*
vty
.
MemberInfo
)
info
,
ok
:=
row
.
Data
.
(
*
vty
.
MemberInfo
)
if
!
ok
{
if
!
ok
{
...
...
plugin/dapp/vote/executor/table.go
View file @
60f2071b
...
@@ -22,6 +22,7 @@ var voteTableOpt = &table.Option{
...
@@ -22,6 +22,7 @@ var voteTableOpt = &table.Option{
Prefix
:
keyPrefixLocalDB
,
Prefix
:
keyPrefixLocalDB
,
Name
:
"vote"
,
Name
:
"vote"
,
Primary
:
voteTablePrimary
,
Primary
:
voteTablePrimary
,
Index
:
[]
string
{
groupTablePrimary
},
}
}
var
memberTableOpt
=
&
table
.
Option
{
var
memberTableOpt
=
&
table
.
Option
{
...
@@ -53,18 +54,18 @@ func newMemberTable(kvDB db.KV) *table.Table {
...
@@ -53,18 +54,18 @@ func newMemberTable(kvDB db.KV) *table.Table {
//groupTableRow table meta 结构
//groupTableRow table meta 结构
type
groupTableRow
struct
{
type
groupTableRow
struct
{
*
vty
.
Group
Vote
Info
*
vty
.
GroupInfo
}
}
//CreateRow 新建数据行
//CreateRow 新建数据行
func
(
r
*
groupTableRow
)
CreateRow
()
*
table
.
Row
{
func
(
r
*
groupTableRow
)
CreateRow
()
*
table
.
Row
{
return
&
table
.
Row
{
Data
:
&
vty
.
Group
Vote
Info
{}}
return
&
table
.
Row
{
Data
:
&
vty
.
GroupInfo
{}}
}
}
//SetPayload 设置数据
//SetPayload 设置数据
func
(
r
*
groupTableRow
)
SetPayload
(
data
types
.
Message
)
error
{
func
(
r
*
groupTableRow
)
SetPayload
(
data
types
.
Message
)
error
{
if
d
,
ok
:=
data
.
(
*
vty
.
Group
Vote
Info
);
ok
{
if
d
,
ok
:=
data
.
(
*
vty
.
GroupInfo
);
ok
{
r
.
Group
Vote
Info
=
d
r
.
GroupInfo
=
d
return
nil
return
nil
}
}
return
types
.
ErrTypeAsset
return
types
.
ErrTypeAsset
...
@@ -73,7 +74,7 @@ func (r *groupTableRow) SetPayload(data types.Message) error {
...
@@ -73,7 +74,7 @@ func (r *groupTableRow) SetPayload(data types.Message) error {
//Get 按照indexName 查询 indexValue
//Get 按照indexName 查询 indexValue
func
(
r
*
groupTableRow
)
Get
(
key
string
)
([]
byte
,
error
)
{
func
(
r
*
groupTableRow
)
Get
(
key
string
)
([]
byte
,
error
)
{
if
key
==
groupTablePrimary
{
if
key
==
groupTablePrimary
{
return
[]
byte
(
r
.
Group
VoteInfo
.
GetGroupInfo
()
.
GetID
()),
nil
return
[]
byte
(
r
.
Group
Info
.
GetID
()),
nil
}
}
return
nil
,
types
.
ErrNotFound
return
nil
,
types
.
ErrNotFound
}
}
...
@@ -101,6 +102,8 @@ func (r *voteTableRow) SetPayload(data types.Message) error {
...
@@ -101,6 +102,8 @@ func (r *voteTableRow) SetPayload(data types.Message) error {
func
(
r
*
voteTableRow
)
Get
(
key
string
)
([]
byte
,
error
)
{
func
(
r
*
voteTableRow
)
Get
(
key
string
)
([]
byte
,
error
)
{
if
key
==
voteTablePrimary
{
if
key
==
voteTablePrimary
{
return
[]
byte
(
r
.
VoteInfo
.
GetID
()),
nil
return
[]
byte
(
r
.
VoteInfo
.
GetID
()),
nil
}
else
if
key
==
groupTablePrimary
{
return
[]
byte
(
r
.
VoteInfo
.
GetGroupID
()),
nil
}
}
return
nil
,
types
.
ErrNotFound
return
nil
,
types
.
ErrNotFound
}
}
...
...
plugin/dapp/vote/executor/util.go
View file @
60f2071b
...
@@ -7,17 +7,22 @@ import (
...
@@ -7,17 +7,22 @@ import (
)
)
const
(
const
(
voteStatusNormal
=
iota
voteStatusClosed
)
const
(
// IDLen length of groupID or voteID
// IDLen length of groupID or voteID
IDLen
=
65
IDLen
=
19
addrLen
=
34
addrLen
=
34
)
)
func
formatGroupID
(
txHash
string
)
string
{
func
formatGroupID
(
id
string
)
string
{
return
"g"
+
txHash
return
"g"
+
id
}
}
func
formatVoteID
(
txHash
string
)
string
{
func
formatVoteID
(
id
string
)
string
{
return
"v"
+
txHash
return
"v"
+
id
}
}
func
checkMemberExist
(
addr
string
,
members
[]
*
vty
.
GroupMember
)
bool
{
func
checkMemberExist
(
addr
string
,
members
[]
*
vty
.
GroupMember
)
bool
{
...
@@ -76,3 +81,27 @@ func decodeVoteInfo(data []byte) *vty.VoteInfo {
...
@@ -76,3 +81,27 @@ func decodeVoteInfo(data []byte) *vty.VoteInfo {
mustDecodeProto
(
data
,
info
)
mustDecodeProto
(
data
,
info
)
return
info
return
info
}
}
func
decodeCommitInfo
(
data
[]
byte
)
*
vty
.
CommitInfo
{
info
:=
&
vty
.
CommitInfo
{}
mustDecodeProto
(
data
,
info
)
return
info
}
func
classifyVoteList
(
infos
*
vty
.
VoteInfos
)
*
vty
.
ReplyVoteList
{
reply
:=
&
vty
.
ReplyVoteList
{}
for
_
,
voteInfo
:=
range
infos
.
GetVoteList
()
{
if
voteInfo
.
Status
==
voteStatusClosed
{
reply
.
ClosedList
=
append
(
reply
.
ClosedList
,
voteInfo
)
}
else
if
voteInfo
.
BeginTimestamp
>
types
.
Now
()
.
Unix
()
{
reply
.
PendingList
=
append
(
reply
.
PendingList
,
voteInfo
)
}
else
if
voteInfo
.
EndTimestamp
>
types
.
Now
()
.
Unix
()
{
reply
.
OngoingList
=
append
(
reply
.
OngoingList
,
voteInfo
)
}
else
{
reply
.
FinishedList
=
append
(
reply
.
FinishedList
,
voteInfo
)
}
}
return
reply
}
plugin/dapp/vote/proto/vote.proto
View file @
60f2071b
...
@@ -7,9 +7,11 @@ message VoteAction {
...
@@ -7,9 +7,11 @@ message VoteAction {
int32
ty
=
1
;
int32
ty
=
1
;
oneof
value
{
oneof
value
{
CreateGroup
createGroup
=
2
;
//创建投票组
CreateGroup
createGroup
=
2
;
//创建投票组
Update
Member
updateMember
=
3
;
//更新组成员
Update
Group
updateGroup
=
3
;
//更新组成员
CreateVote
createVote
=
4
;
//创建一个投票
CreateVote
createVote
=
4
;
//创建一个投票
CommitVote
commitVote
=
5
;
//组员提交投票
CommitVote
commitVote
=
5
;
//组员提交投票
CloseVote
closeVote
=
6
;
UpdateMember
updateMember
=
7
;
}
}
}
}
...
@@ -20,27 +22,35 @@ message GroupMember {
...
@@ -20,27 +22,35 @@ message GroupMember {
//创建投票组
//创建投票组
message
CreateGroup
{
message
CreateGroup
{
string
name
=
1
;
//投票组名称
string
name
=
1
;
//投票组名称
repeated
string
admins
=
2
;
//管理员地址列表
repeated
string
admins
=
2
;
//管理员地址列表
repeated
GroupMember
members
=
3
;
//组员
repeated
GroupMember
members
=
3
;
//组员
string
description
=
4
;
}
}
//更新投票组
//更新投票组
message
UpdateMember
{
message
UpdateGroup
{
string
groupID
=
1
;
//投票组ID
string
groupID
=
1
;
//投票组ID
repeated
GroupMember
addMembers
=
2
;
//需要增加的组成员
repeated
GroupMember
addMembers
=
2
;
//需要增加的组成员
repeated
string
removeMemberAddrs
=
3
;
//删除组成员的地址列表
repeated
string
removeMembers
=
3
;
//删除组成员的地址列表
repeated
string
addAdmins
=
4
;
repeated
string
removeAdmins
=
5
;
}
}
// 投票组信息
// 投票组信息
message
GroupInfo
{
message
GroupInfo
{
string
ID
=
1
;
//投票组ID
string
ID
=
1
;
//投票组ID
string
name
=
2
;
//投票组名称
string
name
=
2
;
//投票组名称
uint32
memberNum
=
3
;
//组员数量
uint32
memberNum
=
3
;
//组员数量
string
creator
=
4
;
//创建者
string
creator
=
4
;
//创建者
repeated
string
admins
=
5
;
//管理员列表
repeated
string
admins
=
5
;
//管理员列表
repeated
GroupMember
members
=
6
;
//成员列表
repeated
GroupMember
members
=
6
;
//成员列表
string
description
=
7
;
}
message
GroupInfos
{
repeated
GroupInfo
groupList
=
1
;
//投票组信息列表
}
}
//投票选项
//投票选项
...
@@ -52,17 +62,30 @@ message VoteOption {
...
@@ -52,17 +62,30 @@ message VoteOption {
// 创建投票交易,请求结构
// 创建投票交易,请求结构
message
CreateVote
{
message
CreateVote
{
string
name
=
1
;
//投票名称
string
name
=
1
;
//投票名称
repeated
string
voteGroups
=
2
;
//投票关联组列表
string
groupID
=
2
;
//投票关联组列表
repeated
string
voteOptions
=
3
;
//投票选项列表
repeated
string
voteOptions
=
3
;
//投票选项列表
int64
beginTimestamp
=
4
;
//投票开始时间戳
int64
beginTimestamp
=
4
;
//投票开始时间戳
int64
endTimestamp
=
5
;
//投票结束时间戳
int64
endTimestamp
=
5
;
//投票结束时间戳
string
description
=
6
;
}
}
// 创建提交投票交易,请求结构
// 创建提交投票交易,请求结构
message
CommitVote
{
message
CommitVote
{
string
voteID
=
1
;
//投票ID
string
voteID
=
1
;
//投票ID
string
groupID
=
2
;
//所属投票组ID
uint32
optionIndex
=
2
;
//投票选项数组下标,下标对应投票内容
uint32
optionIndex
=
3
;
//投票选项数组下标,下标对应投票内容
}
message
CommitInfo
{
string
addr
=
1
;
string
txHash
=
2
;
}
message
CloseVote
{
string
voteID
=
1
;
}
message
UpdateMember
{
string
name
=
1
;
}
}
//投票信息
//投票信息
...
@@ -70,40 +93,50 @@ message VoteInfo {
...
@@ -70,40 +93,50 @@ message VoteInfo {
string
ID
=
1
;
//投票ID
string
ID
=
1
;
//投票ID
string
name
=
2
;
//投票名称
string
name
=
2
;
//投票名称
string
creator
=
3
;
//
投票
创建者
string
creator
=
3
;
//创建者
repeated
string
voteGroups
=
4
;
//投票关联的投票组
string
groupID
=
4
;
//投票关联的投票组
repeated
VoteOption
voteOptions
=
5
;
//投票的选项
repeated
VoteOption
voteOptions
=
5
;
//投票的选项
int64
beginTimestamp
=
6
;
//投票开始时间戳
int64
beginTimestamp
=
6
;
//投票开始时间戳
int64
endTimestamp
=
7
;
//投票结束时间戳
int64
endTimestamp
=
7
;
//投票结束时间戳
repeated
string
votedMembers
=
8
;
//已投票的成员
repeated
CommitInfo
commitInfos
=
8
;
//已投票的提交信息
string
description
=
9
;
uint32
status
=
10
;
}
}
message
VoteInfos
{
message
VoteInfos
{
repeated
VoteInfo
voteList
=
1
;
//投票信息列表
repeated
VoteInfo
voteList
=
1
;
//投票信息列表
}
}
message
GroupVoteInfo
{
GroupInfo
groupInfo
=
1
;
// 投票组信息
repeated
string
voteIDs
=
2
;
//投票组关联的投票ID信息
}
message
GroupVoteInfos
{
repeated
GroupVoteInfo
groupList
=
1
;
//投票组信息列表
}
message
MemberInfo
{
message
MemberInfo
{
string
addr
=
1
;
//地址
string
addr
=
1
;
//地址
repeated
string
groupIDs
=
2
;
//所属投票组的ID列表
string
name
=
2
;
repeated
string
groupIDs
=
3
;
//所属投票组的ID列表
}
}
message
MemberInfos
{
message
MemberInfos
{
repeated
MemberInfo
memberList
=
1
;
//投票组成员信息列表
repeated
MemberInfo
memberList
=
1
;
//投票组成员信息列表
}
}
message
ReqStrings
{
repeated
string
items
=
1
;
}
//列表请求结构
//列表请求结构
message
ReqListItem
{
message
ReqListItem
{
string
startItemID
=
1
;
//列表开始的ID,如请求组列表即groupID,不包含在结果中
string
startItemID
=
1
;
//列表开始的ID,如请求组列表即groupID,不包含在结果中
int32
count
=
2
;
//请求列表项数量
int32
count
=
2
;
//请求列表项数量
int32
direction
=
3
;
// 0表示根据ID降序,1表示升序
int32
direction
=
3
;
// 0表示根据ID降序,1表示升序
}
}
message
ReqListVote
{
string
groupID
=
1
;
ReqListItem
listReq
=
2
;
}
message
ReplyVoteList
{
repeated
VoteInfo
pendingList
=
1
;
repeated
VoteInfo
ongoingList
=
2
;
repeated
VoteInfo
finishedList
=
3
;
repeated
VoteInfo
closedList
=
4
;
}
plugin/dapp/vote/types/vote.go
View file @
60f2071b
...
@@ -17,28 +17,36 @@ import (
...
@@ -17,28 +17,36 @@ import (
const
(
const
(
TyUnknowAction
=
iota
+
100
TyUnknowAction
=
iota
+
100
TyCreateGroupAction
TyCreateGroupAction
TyUpdate
Member
Action
TyUpdate
Group
Action
TyCreateVoteAction
TyCreateVoteAction
TyCommitVoteAction
TyCommitVoteAction
TyCloseVoteAction
TyUpdateMemberAction
NameCreateGroupAction
=
"CreateGroup"
NameCreateGroupAction
=
"CreateGroup"
NameUpdate
MemberAction
=
"UpdateMember
"
NameUpdate
GroupAction
=
"UpdateGroup
"
NameCreateVoteAction
=
"CreateVote"
NameCreateVoteAction
=
"CreateVote"
NameCommitVoteAction
=
"CommitVote"
NameCommitVoteAction
=
"CommitVote"
NameCloseVoteAction
=
"CloseVote"
NameUpdateMemberAction
=
"UpdateMember"
)
)
// log类型id值
// log类型id值
const
(
const
(
TyUnknownLog
=
iota
+
100
TyUnknownLog
=
iota
+
100
TyCreateGroupLog
TyCreateGroupLog
TyUpdate
Member
Log
TyUpdate
Group
Log
TyCreateVoteLog
TyCreateVoteLog
TyCommitVoteLog
TyCommitVoteLog
TyCloseVoteLog
TyUpdateMemberLog
NameCreateGroupLog
=
"CreateGroupLog"
NameCreateGroupLog
=
"CreateGroupLog"
NameUpdate
MemberLog
=
"UpdateMember
Log"
NameUpdate
GroupLog
=
"UpdateGroup
Log"
NameCreateVoteLog
=
"CreateVoteLog"
NameCreateVoteLog
=
"CreateVoteLog"
NameCommitVoteLog
=
"CommitVoteLog"
NameCommitVoteLog
=
"CommitVoteLog"
NameCloseVoteLog
=
"CloseVoteLog"
NameUpdateMemberLog
=
"UpdateMemberLog"
)
)
var
(
var
(
...
@@ -47,16 +55,20 @@ var (
...
@@ -47,16 +55,20 @@ var (
//定义actionMap
//定义actionMap
actionMap
=
map
[
string
]
int32
{
actionMap
=
map
[
string
]
int32
{
NameCreateGroupAction
:
TyCreateGroupAction
,
NameCreateGroupAction
:
TyCreateGroupAction
,
NameUpdate
MemberAction
:
TyUpdateMember
Action
,
NameUpdate
GroupAction
:
TyUpdateGroup
Action
,
NameCreateVoteAction
:
TyCreateVoteAction
,
NameCreateVoteAction
:
TyCreateVoteAction
,
NameCommitVoteAction
:
TyCommitVoteAction
,
NameCommitVoteAction
:
TyCommitVoteAction
,
NameCloseVoteAction
:
TyCloseVoteAction
,
NameUpdateMemberAction
:
TyUpdateMemberAction
,
}
}
//定义log的id和具体log类型及名称,填入具体自定义log类型
//定义log的id和具体log类型及名称,填入具体自定义log类型
logMap
=
map
[
int64
]
*
types
.
LogInfo
{
logMap
=
map
[
int64
]
*
types
.
LogInfo
{
TyCreateGroupLog
:
{
Ty
:
reflect
.
TypeOf
(
GroupInfo
{}),
Name
:
NameCreateGroupLog
},
TyCreateGroupLog
:
{
Ty
:
reflect
.
TypeOf
(
GroupInfo
{}),
Name
:
NameCreateGroupLog
},
TyUpdate
MemberLog
:
{
Ty
:
reflect
.
TypeOf
(
GroupInfo
{}),
Name
:
NameUpdateMember
Log
},
TyUpdate
GroupLog
:
{
Ty
:
reflect
.
TypeOf
(
GroupInfo
{}),
Name
:
NameUpdateGroup
Log
},
TyCreateVoteLog
:
{
Ty
:
reflect
.
TypeOf
(
VoteInfo
{}),
Name
:
NameCreateVoteLog
},
TyCreateVoteLog
:
{
Ty
:
reflect
.
TypeOf
(
VoteInfo
{}),
Name
:
NameCreateVoteLog
},
TyCommitVoteLog
:
{
Ty
:
reflect
.
TypeOf
(
VoteInfo
{}),
Name
:
NameCommitVoteLog
},
TyCommitVoteLog
:
{
Ty
:
reflect
.
TypeOf
(
CommitInfo
{}),
Name
:
NameCommitVoteLog
},
TyCloseVoteLog
:
{
Ty
:
reflect
.
TypeOf
(
VoteInfo
{}),
Name
:
NameCloseVoteLog
},
TyUpdateMemberLog
:
{
Ty
:
reflect
.
TypeOf
(
MemberInfo
{}),
Name
:
NameUpdateMemberLog
},
}
}
tlog
=
log
.
New
(
"module"
,
"vote.types"
)
tlog
=
log
.
New
(
"module"
,
"vote.types"
)
)
)
...
...
plugin/dapp/vote/types/vote.pb.go
View file @
60f2071b
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