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
ae572080
Commit
ae572080
authored
Aug 22, 2019
by
liuyuhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add change 提案
parent
c1016c12
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
688 additions
and
8 deletions
+688
-8
proposal_board.go
plugin/dapp/autonomy/commands/proposal_board.go
+9
-0
proposal_change.go
plugin/dapp/autonomy/commands/proposal_change.go
+282
-0
proposal_rule.go
plugin/dapp/autonomy/commands/proposal_rule.go
+0
-2
boardaction.go
plugin/dapp/autonomy/executor/boardaction.go
+1
-1
change.go
plugin/dapp/autonomy/executor/change.go
+126
-0
changetable.go
plugin/dapp/autonomy/executor/changetable.go
+73
-0
exec.go
plugin/dapp/autonomy/executor/exec.go
+28
-0
exec_local.go
plugin/dapp/autonomy/executor/exec_local.go
+24
-0
query.go
plugin/dapp/autonomy/executor/query.go
+11
-0
ruleaction.go
plugin/dapp/autonomy/executor/ruleaction.go
+17
-5
change_jrpc_channel_test.go
plugin/dapp/autonomy/rpc/change_jrpc_channel_test.go
+98
-0
jrpc_channel_test.go
plugin/dapp/autonomy/rpc/jrpc_channel_test.go
+7
-0
const.go
plugin/dapp/autonomy/types/const.go
+2
-0
types.go
plugin/dapp/autonomy/types/types.go
+10
-0
No files found.
plugin/dapp/autonomy/commands/proposal_board.go
View file @
ae572080
...
...
@@ -58,6 +58,15 @@ func AutonomyCmd() *cobra.Command {
ShowProposalCommentCmd
(),
)
// change
cmd
.
AddCommand
(
ProposalChangeCmd
(),
RevokeProposalChangeCmd
(),
VoteProposalChangeCmd
(),
TerminateProposalChangeCmd
(),
ShowProposalChangeCmd
(),
)
return
cmd
}
...
...
plugin/dapp/autonomy/commands/proposal_change.go
0 → 100644
View file @
ae572080
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
commands
import
(
"strings"
"encoding/json"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/spf13/cobra"
)
// ProposalChangeCmd 创建提案命令
func
ProposalChangeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"proposalchange"
,
Short
:
"create proposal change"
,
Run
:
proposalChange
,
}
addProposalChangeFlags
(
cmd
)
return
cmd
}
func
addProposalChangeFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Int32P
(
"year"
,
"y"
,
0
,
"year"
)
cmd
.
Flags
()
.
Int32P
(
"month"
,
"m"
,
0
,
"month"
)
cmd
.
Flags
()
.
Int32P
(
"day"
,
"d"
,
0
,
"day"
)
cmd
.
Flags
()
.
Int64P
(
"startBlock"
,
"s"
,
0
,
"start block height"
)
cmd
.
MarkFlagRequired
(
"startBlock"
)
cmd
.
Flags
()
.
Int64P
(
"endBlock"
,
"e"
,
0
,
"end block height"
)
cmd
.
MarkFlagRequired
(
"endBlock"
)
cmd
.
Flags
()
.
StringP
(
"changes"
,
"c"
,
""
,
"addr1-true*addr2-false*addr3-true*......*addrN-false (1<=N<20)"
)
cmd
.
MarkFlagRequired
(
"changes"
)
}
func
proposalChange
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
year
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"year"
)
month
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"month"
)
day
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"day"
)
startBlock
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"startBlock"
)
endBlock
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"endBlock"
)
changestr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"changes"
)
changeStr
:=
strings
.
Split
(
changestr
,
"*"
)
var
changes
[]
*
auty
.
Change
for
_
,
chStr
:=
range
changeStr
{
per
:=
strings
.
Split
(
chStr
,
"-"
)
if
len
(
per
)
==
2
{
if
per
[
1
]
==
"true"
{
change
:=
&
auty
.
Change
{
Cancel
:
true
,
Addr
:
per
[
0
],
}
changes
=
append
(
changes
,
change
)
}
else
if
per
[
1
]
==
"false"
{
change
:=
&
auty
.
Change
{
Cancel
:
false
,
Addr
:
per
[
0
],
}
changes
=
append
(
changes
,
change
)
}
}
}
params
:=
&
auty
.
ProposalChange
{
Year
:
year
,
Month
:
month
,
Day
:
day
,
Changes
:
changes
,
StartBlockHeight
:
startBlock
,
EndBlockHeight
:
endBlock
,
}
payLoad
,
err
:=
json
.
Marshal
(
params
)
if
err
!=
nil
{
return
}
pm
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
auty
.
AutonomyX
),
ActionName
:
"PropChange"
,
Payload
:
payLoad
,
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
pm
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// RevokeProposalChangeCmd 撤销提案
func
RevokeProposalChangeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"revokeChange"
,
Short
:
"revoke proposal change"
,
Run
:
revokeProposalChange
,
}
addRevokeProposalChangeFlags
(
cmd
)
return
cmd
}
func
addRevokeProposalChangeFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"proposalID"
,
"p"
,
""
,
"proposal ID"
)
cmd
.
MarkFlagRequired
(
"proposalID"
)
}
func
revokeProposalChange
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
ID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"proposalID"
)
params
:=
&
auty
.
RevokeProposalChange
{
ProposalID
:
ID
,
}
payLoad
,
err
:=
json
.
Marshal
(
params
)
if
err
!=
nil
{
return
}
pm
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
auty
.
AutonomyX
),
ActionName
:
"RvkPropChange"
,
Payload
:
payLoad
,
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
pm
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// VoteProposalChangeCmd 投票提案
func
VoteProposalChangeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"voteChange"
,
Short
:
"vote proposal change"
,
Run
:
voteProposalChange
,
}
addVoteProposalChangeFlags
(
cmd
)
return
cmd
}
func
addVoteProposalChangeFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"proposalID"
,
"p"
,
""
,
"proposal ID"
)
cmd
.
MarkFlagRequired
(
"proposalID"
)
cmd
.
Flags
()
.
Int32P
(
"approve"
,
"r"
,
1
,
"is approve, default true"
)
}
func
voteProposalChange
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
ID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"proposalID"
)
approve
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"approve"
)
var
isapp
bool
if
approve
==
0
{
isapp
=
false
}
else
{
isapp
=
true
}
params
:=
&
auty
.
VoteProposalChange
{
ProposalID
:
ID
,
Approve
:
isapp
,
}
payLoad
,
err
:=
json
.
Marshal
(
params
)
if
err
!=
nil
{
return
}
pm
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
auty
.
AutonomyX
),
ActionName
:
"VotePropChange"
,
Payload
:
payLoad
,
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
pm
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// TerminateProposalChangeCmd 终止提案
func
TerminateProposalChangeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"terminateChange"
,
Short
:
"terminate proposal change"
,
Run
:
terminateProposalChange
,
}
addTerminateProposalChangeFlags
(
cmd
)
return
cmd
}
func
addTerminateProposalChangeFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"proposalID"
,
"p"
,
""
,
"proposal ID"
)
cmd
.
MarkFlagRequired
(
"proposalID"
)
}
func
terminateProposalChange
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
ID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"proposalID"
)
params
:=
&
auty
.
RevokeProposalChange
{
ProposalID
:
ID
,
}
payLoad
,
err
:=
json
.
Marshal
(
params
)
if
err
!=
nil
{
return
}
pm
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
auty
.
AutonomyX
),
ActionName
:
"TmintPropChange"
,
Payload
:
payLoad
,
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
pm
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// ShowProposalChangeCmd 显示提案查询信息
func
ShowProposalChangeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"showChangeInfo"
,
Short
:
"show proposal change info"
,
Run
:
showProposalChange
,
}
addShowProposalChangeflags
(
cmd
)
return
cmd
}
func
addShowProposalChangeflags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uint32P
(
"type"
,
"y"
,
0
,
"type(0:query by hash; 1:list)"
)
cmd
.
MarkFlagRequired
(
"type"
)
cmd
.
Flags
()
.
StringP
(
"proposalID"
,
"p"
,
""
,
"proposal ID"
)
cmd
.
Flags
()
.
Uint32P
(
"status"
,
"s"
,
0
,
"status"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"address"
)
cmd
.
Flags
()
.
Int32P
(
"count"
,
"c"
,
1
,
"count, default is 1"
)
cmd
.
Flags
()
.
Int32P
(
"direction"
,
"d"
,
-
1
,
"direction, default is reserve"
)
cmd
.
Flags
()
.
Int64P
(
"height"
,
"t"
,
-
1
,
"height, default is -1"
)
cmd
.
Flags
()
.
Int32P
(
"index"
,
"i"
,
-
1
,
"index, default is -1"
)
}
func
showProposalChange
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
typ
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"type"
)
propID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"proposalID"
)
status
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"status"
)
addr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
count
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"count"
)
direction
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"direction"
)
height
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"height"
)
index
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"index"
)
var
params
rpctypes
.
Query4Jrpc
var
rep
interface
{}
params
.
Execer
=
auty
.
AutonomyX
if
0
==
typ
{
req
:=
types
.
ReqString
{
Data
:
propID
,
}
params
.
FuncName
=
auty
.
GetProposalChange
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
}
else
if
1
==
typ
{
req
:=
auty
.
ReqQueryProposalChange
{
Status
:
int32
(
status
),
Addr
:
addr
,
Count
:
count
,
Direction
:
direction
,
Height
:
height
,
Index
:
index
,
}
params
.
FuncName
=
auty
.
ListProposalChange
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
}
rep
=
&
auty
.
ReplyQueryProposalChange
{}
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
rep
)
ctx
.
Run
()
}
plugin/dapp/autonomy/commands/proposal_rule.go
View file @
ae572080
...
...
@@ -53,7 +53,6 @@ func proposalRule(cmd *cobra.Command, args []string) {
startBlock
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"startBlock"
)
endBlock
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"endBlock"
)
boardAttendRatio
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"boardAttendRatio"
)
boardApproveRatio
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"boardApproveRatio"
)
pubOpposeRatio
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"pubOpposeRatio"
)
...
...
@@ -66,7 +65,6 @@ func proposalRule(cmd *cobra.Command, args []string) {
Month
:
month
,
Day
:
day
,
RuleCfg
:
&
auty
.
RuleConfig
{
BoardAttendRatio
:
boardAttendRatio
,
BoardApproveRatio
:
boardApproveRatio
,
PubOpposeRatio
:
pubOpposeRatio
,
ProposalAmount
:
proposalAmount
*
types
.
Coin
,
...
...
plugin/dapp/autonomy/executor/boardaction.go
View file @
ae572080
...
...
@@ -24,7 +24,7 @@ const (
publicPeriod
int32
=
17280
*
7
// 公示一周时间,以区块高度计算
ticketPrice
=
types
.
Coin
*
3000
// 单张票价
largeProjectAmount
=
types
.
Coin
*
100
*
10000
// 重大项目公示金额阈值
proposalAmount
=
types
.
Coin
*
1000
// 创建者消耗金额
proposalAmount
=
types
.
Coin
*
500
// 创建者消耗金额
boardApproveRatio
int32
=
66
// 董事会成员赞成率,以%计,可修改
pubAttendRatio
int32
=
75
// 全体持票人参与率,以%计
pubApproveRatio
int32
=
66
// 全体持票人赞成率,以%计
...
...
plugin/dapp/autonomy/executor/change.go
0 → 100644
View file @
ae572080
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
executor
import
(
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
)
func
(
a
*
Autonomy
)
execAutoLocalChange
(
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
set
,
err
:=
a
.
execLocalChange
(
receiptData
)
if
err
!=
nil
{
return
set
,
err
}
dbSet
:=
&
types
.
LocalDBSet
{}
dbSet
.
KV
=
a
.
AddRollbackKV
(
tx
,
tx
.
Execer
,
set
.
KV
)
return
dbSet
,
nil
}
func
(
a
*
Autonomy
)
execLocalChange
(
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
table
:=
NewChangeTable
(
a
.
GetLocalDB
())
for
_
,
log
:=
range
receiptData
.
Logs
{
switch
log
.
Ty
{
case
auty
.
TyLogPropChange
,
auty
.
TyLogRvkPropChange
,
auty
.
TyLogVotePropChange
,
auty
.
TyLogTmintPropChange
:
{
var
receipt
auty
.
ReceiptProposalChange
err
:=
types
.
Decode
(
log
.
Log
,
&
receipt
)
if
err
!=
nil
{
return
nil
,
err
}
err
=
table
.
Replace
(
receipt
.
Current
)
if
err
!=
nil
{
return
nil
,
err
}
}
default
:
break
}
}
kvs
,
err
:=
table
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
dbSet
:=
&
types
.
LocalDBSet
{}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kvs
...
)
return
dbSet
,
nil
}
func
(
a
*
Autonomy
)
getProposalChange
(
req
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
if
req
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
value
,
err
:=
a
.
GetStateDB
()
.
Get
(
propChangeID
(
req
.
Data
))
if
err
!=
nil
{
return
nil
,
err
}
prop
:=
&
auty
.
AutonomyProposalChange
{}
err
=
types
.
Decode
(
value
,
prop
)
if
err
!=
nil
{
return
nil
,
err
}
rep
:=
&
auty
.
ReplyQueryProposalChange
{}
rep
.
PropChanges
=
append
(
rep
.
PropChanges
,
prop
)
return
rep
,
nil
}
func
(
a
*
Autonomy
)
listProposalChange
(
req
*
auty
.
ReqQueryProposalChange
)
(
types
.
Message
,
error
)
{
if
req
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
localDb
:=
a
.
GetLocalDB
()
query
:=
NewChangeTable
(
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
:=
&
ChangeRow
{
AutonomyProposalChange
:
&
auty
.
AutonomyProposalChange
{},
}
cur
.
Address
=
req
.
Addr
cur
.
Status
=
req
.
Status
cur
.
Height
=
req
.
Height
cur
.
Index
=
req
.
Index
prefix
,
err
:=
cur
.
Get
(
indexName
)
if
err
!=
nil
{
alog
.
Error
(
"Get"
,
"indexName"
,
indexName
,
"err"
,
err
)
return
nil
,
err
}
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
(
rows
)
==
0
{
return
nil
,
types
.
ErrNotFound
}
var
rep
auty
.
ReplyQueryProposalChange
for
_
,
row
:=
range
rows
{
r
,
ok
:=
row
.
Data
.
(
*
auty
.
AutonomyProposalChange
)
if
!
ok
{
alog
.
Error
(
"listProposalChange"
,
"err"
,
"bad row type"
)
return
nil
,
types
.
ErrDecode
}
rep
.
PropChanges
=
append
(
rep
.
PropChanges
,
r
)
}
return
&
rep
,
nil
}
plugin/dapp/autonomy/executor/changetable.go
0 → 100644
View file @
ae572080
package
executor
import
(
"fmt"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
)
/*
table struct
data: autonomy change
index: status, addr
*/
var
changeOpt
=
&
table
.
Option
{
Prefix
:
"LODB-autonomy"
,
Name
:
"change"
,
Primary
:
"heightindex"
,
Index
:
[]
string
{
"addr"
,
"status"
,
"addr_status"
},
}
//NewChangeTable 新建表
func
NewChangeTable
(
kvdb
db
.
KV
)
*
table
.
Table
{
rowmeta
:=
NewChangeRow
()
table
,
err
:=
table
.
NewTable
(
rowmeta
,
kvdb
,
changeOpt
)
if
err
!=
nil
{
panic
(
err
)
}
return
table
}
//ChangeRow table meta 结构
type
ChangeRow
struct
{
*
auty
.
AutonomyProposalChange
}
//NewChangeRow 新建一个meta 结构
func
NewChangeRow
()
*
ChangeRow
{
return
&
ChangeRow
{
AutonomyProposalChange
:
&
auty
.
AutonomyProposalChange
{}}
}
//CreateRow 新建数据行(注意index 数据一定也要保存到数据中,不能就保存heightindex)
func
(
r
*
ChangeRow
)
CreateRow
()
*
table
.
Row
{
return
&
table
.
Row
{
Data
:
&
auty
.
AutonomyProposalChange
{}}
}
//SetPayload 设置数据
func
(
r
*
ChangeRow
)
SetPayload
(
data
types
.
Message
)
error
{
if
d
,
ok
:=
data
.
(
*
auty
.
AutonomyProposalChange
);
ok
{
r
.
AutonomyProposalChange
=
d
return
nil
}
return
types
.
ErrTypeAsset
}
//Get 按照indexName 查询 indexValue
func
(
r
*
ChangeRow
)
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/exec.go
View file @
ae572080
...
...
@@ -104,3 +104,30 @@ func (a *Autonomy) Exec_CommentProp(payload *auty.Comment, tx *types.Transaction
action
:=
newAction
(
a
,
tx
,
int32
(
index
))
return
action
.
commentProp
(
payload
)
}
// 提案修改董事会成员相关
// Exec_PropChange 创建提案规则
func
(
a
*
Autonomy
)
Exec_PropChange
(
payload
*
auty
.
ProposalChange
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
a
,
tx
,
int32
(
index
))
return
action
.
propChange
(
payload
)
}
// Exec_RvkPropChange 撤销提案规则
func
(
a
*
Autonomy
)
Exec_RvkPropChange
(
payload
*
auty
.
RevokeProposalChange
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
a
,
tx
,
int32
(
index
))
return
action
.
rvkPropChange
(
payload
)
}
// Exec_VotePropChange 投票提案规则
func
(
a
*
Autonomy
)
Exec_VotePropChange
(
payload
*
auty
.
VoteProposalChange
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
a
,
tx
,
int32
(
index
))
return
action
.
votePropChange
(
payload
)
}
// Exec_TmintPropChange 终止提案规则
func
(
a
*
Autonomy
)
Exec_TmintPropChange
(
payload
*
auty
.
TerminateProposalChange
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
a
,
tx
,
int32
(
index
))
return
action
.
tmintPropChange
(
payload
)
}
\ No newline at end of file
plugin/dapp/autonomy/executor/exec_local.go
View file @
ae572080
...
...
@@ -84,3 +84,26 @@ func (a *Autonomy) ExecLocal_TmintPropRule(payload *auty.TerminateProposalRule,
func
(
a
*
Autonomy
)
ExecLocal_CommentProp
(
payload
*
auty
.
Comment
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
a
.
execAutoLocalCommentProp
(
tx
,
receiptData
)
}
// 提案修改董事会成员相关
// ExecLocal_PropChange 创建提案规则
func
(
a
*
Autonomy
)
ExecLocal_PropChange
(
payload
*
auty
.
ProposalChange
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
a
.
execAutoLocalChange
(
tx
,
receiptData
)
}
// ExecLocal_RvkPropChange 撤销提案规则
func
(
a
*
Autonomy
)
ExecLocal_RvkPropChange
(
payload
*
auty
.
RevokeProposalChange
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
a
.
execAutoLocalChange
(
tx
,
receiptData
)
}
// ExecLocal_VotePropChange 投票提案规则
func
(
a
*
Autonomy
)
ExecLocal_VotePropChange
(
payload
*
auty
.
VoteProposalChange
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
a
.
execAutoLocalChange
(
tx
,
receiptData
)
}
// ExecLocal_TmintPropChange 终止提案规则
func
(
a
*
Autonomy
)
ExecLocal_TmintPropChange
(
payload
*
auty
.
TerminateProposalChange
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
a
.
execAutoLocalChange
(
tx
,
receiptData
)
}
\ No newline at end of file
plugin/dapp/autonomy/executor/query.go
View file @
ae572080
...
...
@@ -43,3 +43,13 @@ func (a *Autonomy) Query_ListProposalRule(in *auty.ReqQueryProposalRule) (types.
func
(
a
*
Autonomy
)
Query_ListProposalComment
(
in
*
auty
.
ReqQueryProposalComment
)
(
types
.
Message
,
error
)
{
return
a
.
listProposalComment
(
in
)
}
// Query_GetProposalChange 查询提案修改董事会成员
func
(
a
*
Autonomy
)
Query_GetProposalChange
(
in
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
return
a
.
getProposalChange
(
in
)
}
// Query_ListProposalChange 批量查询
func
(
a
*
Autonomy
)
Query_ListProposalChange
(
in
*
auty
.
ReqQueryProposalChange
)
(
types
.
Message
,
error
)
{
return
a
.
listProposalChange
(
in
)
}
\ No newline at end of file
plugin/dapp/autonomy/executor/ruleaction.go
View file @
ae572080
...
...
@@ -25,18 +25,30 @@ const (
minPublicPeriod
int32
=
17280
*
7
// 最大公示周期
maxPublicPeriod
int32
=
17280
*
14
// 最小重大项目阈值
minLargeProjectAmount
=
types
.
Coin
*
100
*
10000
// 最大重大项目阈值
maxLargeProjectAmount
=
types
.
Coin
*
300
*
10000
// 最小提案金
minProposalAmount
=
types
.
Coin
*
20
// 最大提案金
maxProposalAmount
=
types
.
Coin
*
2000
)
func
(
a
*
action
)
propRule
(
prob
*
auty
.
ProposalRule
)
(
*
types
.
Receipt
,
error
)
{
//如果全小于等于0,则说明该提案规则参数不正确
if
prob
.
RuleCfg
==
nil
||
prob
.
RuleCfg
.
BoardApproveRatio
<
minBoardApproveRatio
&&
prob
.
RuleCfg
.
PubOpposeRatio
<=
minPubOpposeRatio
&&
prob
.
RuleCfg
.
ProposalAmount
<=
0
&&
prob
.
RuleCfg
.
LargeProjectAmount
<=
0
&&
prob
.
RuleCfg
.
PublicPeriod
<=
0
{
if
prob
.
RuleCfg
==
nil
||
prob
.
RuleCfg
.
BoardApproveRatio
<
=
0
&&
prob
.
RuleCfg
.
PubOpposeRatio
<=
0
&&
prob
.
RuleCfg
.
ProposalAmount
<=
0
&&
prob
.
RuleCfg
.
LargeProjectAmount
<=
0
&&
prob
.
RuleCfg
.
PublicPeriod
<=
0
{
alog
.
Error
(
"propRule "
,
"ProposalRule RuleCfg invaild or have no modify param"
,
prob
.
RuleCfg
)
return
nil
,
types
.
ErrInvalidParam
}
if
prob
.
RuleCfg
.
BoardApproveRatio
>
maxBoardApproveRatio
||
prob
.
RuleCfg
.
PubOpposeRatio
>
maxPubOpposeRatio
{
alog
.
Error
(
"propRule RuleCfg invaild"
,
"BoardApproveRatio"
,
prob
.
RuleCfg
.
BoardApproveRatio
,
"PubOpposeRatio"
,
prob
.
RuleCfg
.
PubOpposeRatio
)
if
prob
.
RuleCfg
.
BoardApproveRatio
>
maxBoardApproveRatio
||
prob
.
RuleCfg
.
BoardApproveRatio
<
minBoardApproveRatio
||
prob
.
RuleCfg
.
PubOpposeRatio
>
maxPubOpposeRatio
||
prob
.
RuleCfg
.
PubOpposeRatio
<
minPubOpposeRatio
||
prob
.
RuleCfg
.
PublicPeriod
>
maxPublicPeriod
||
prob
.
RuleCfg
.
PublicPeriod
<
minPublicPeriod
||
prob
.
RuleCfg
.
LargeProjectAmount
>
maxLargeProjectAmount
||
prob
.
RuleCfg
.
LargeProjectAmount
<
minLargeProjectAmount
||
prob
.
RuleCfg
.
ProposalAmount
>
maxProposalAmount
||
prob
.
RuleCfg
.
ProposalAmount
<
minProposalAmount
{
alog
.
Error
(
"propRule RuleCfg invaild"
,
"ruleCfg"
,
prob
.
RuleCfg
)
return
nil
,
types
.
ErrInvalidParam
}
if
prob
.
StartBlockHeight
<
a
.
height
||
prob
.
EndBlockHeight
<
a
.
height
{
...
...
plugin/dapp/autonomy/rpc/change_jrpc_channel_test.go
0 → 100644
View file @
ae572080
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
rpc_test
import
(
"testing"
"encoding/json"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
_
"github.com/33cn/chain33/system"
"github.com/33cn/chain33/types"
_
"github.com/33cn/plugin/plugin"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
)
func
testPropChangeTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
&
auty
.
ProposalChange
{}
payLoad
,
err
:=
json
.
Marshal
(
params
)
if
err
!=
nil
{
return
err
}
pm
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
auty
.
AutonomyX
),
ActionName
:
"PropChange"
,
Payload
:
payLoad
,
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
pm
,
&
res
)
}
func
testRevokeProposalChangeTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
&
auty
.
RevokeProposalChange
{}
payLoad
,
err
:=
json
.
Marshal
(
params
)
if
err
!=
nil
{
return
err
}
pm
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
auty
.
AutonomyX
),
ActionName
:
"RvkPropChange"
,
Payload
:
payLoad
,
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
pm
,
&
res
)
}
func
testVoteProposalChangeTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
&
auty
.
VoteProposalChange
{}
payLoad
,
err
:=
json
.
Marshal
(
params
)
if
err
!=
nil
{
return
err
}
pm
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
auty
.
AutonomyX
),
ActionName
:
"VotePropChange"
,
Payload
:
payLoad
,
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
pm
,
&
res
)
}
func
testTerminateProposalChangeTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
&
auty
.
TerminateProposalChange
{}
payLoad
,
err
:=
json
.
Marshal
(
params
)
if
err
!=
nil
{
return
err
}
pm
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
auty
.
AutonomyX
),
ActionName
:
"TmintPropChange"
,
Payload
:
payLoad
,
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
pm
,
&
res
)
}
func
testGetProposalChangeCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
types
.
ReqString
{}
params
.
FuncName
=
auty
.
GetProposalChange
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
auty
.
ReplyQueryProposalChange
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testListProposalChangeCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
auty
.
ReqQueryProposalChange
{}
params
.
FuncName
=
auty
.
ListProposalChange
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
auty
.
ReplyQueryProposalChange
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
plugin/dapp/autonomy/rpc/jrpc_channel_test.go
View file @
ae572080
...
...
@@ -61,6 +61,13 @@ func TestJRPCChannel(t *testing.T) {
{
fn
:
testTransferFundTxCmd
},
{
fn
:
testCommentProposalTxCmd
},
{
fn
:
testListProposalCommentCmd
},
{
fn
:
testPropChangeTxCmd
},
{
fn
:
testRevokeProposalChangeTxCmd
},
{
fn
:
testVoteProposalChangeTxCmd
},
{
fn
:
testTerminateProposalChangeTxCmd
},
{
fn
:
testGetProposalChangeCmd
},
{
fn
:
testListProposalChangeCmd
},
}
for
index
,
testCase
:=
range
testCases
{
err
:=
testCase
.
fn
(
t
,
jrpcClient
)
...
...
plugin/dapp/autonomy/types/const.go
View file @
ae572080
...
...
@@ -107,6 +107,8 @@ const (
ListProposalComment
=
"ListProposalComment"
// GetProposalChange 用于在cmd里面的区分不同的查询
GetProposalChange
=
"GetProposalChange"
// ListProposalChange 查询多个
ListProposalChange
=
"ListProposalChange"
)
//包的名字可以通过配置文件来配置
...
...
plugin/dapp/autonomy/types/types.go
View file @
ae572080
...
...
@@ -57,6 +57,11 @@ func (a *AutonomyType) GetLogMap() map[int64]*types.LogInfo {
TyLogTmintPropRule
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptProposalRule
{}),
Name
:
"LogTmintPropRule"
},
TyLogCommentProp
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptProposalComment
{}),
Name
:
"LogCommentProp"
},
TyLogPropChange
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptProposalChange
{}),
Name
:
"LogPropChange"
},
TyLogRvkPropChange
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptProposalChange
{}),
Name
:
"LogRvkPropChange"
},
TyLogVotePropChange
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptProposalChange
{}),
Name
:
"LogVotePropChange"
},
TyLogTmintPropChange
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptProposalChange
{}),
Name
:
"LogTmintPropChange"
},
}
}
...
...
@@ -86,5 +91,10 @@ func (a *AutonomyType) GetTypeMap() map[string]int32 {
"Transfer"
:
AutonomyActionTransfer
,
"CommentProp"
:
AutonomyActionCommentProp
,
"PropChange"
:
AutonomyActionPropChange
,
"RvkPropChange"
:
AutonomyActionRvkPropChange
,
"VotePropChange"
:
AutonomyActionVotePropChange
,
"TmintPropChange"
:
AutonomyActionTmintPropChange
,
}
}
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