Commit a7b48dc4 authored by liuyuhang's avatar liuyuhang

add show active cmd

parent 1b1a2106
......@@ -31,6 +31,7 @@ func AutonomyCmd() *cobra.Command {
VoteProposalBoardCmd(),
TerminateProposalBoardCmd(),
ShowProposalBoardCmd(),
ShowActiveBoardCmd(),
)
// project
......@@ -322,3 +323,26 @@ func showProposalBoard(cmd *cobra.Command, args []string) {
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, rep)
ctx.Run()
}
// ShowActiveBoardCmd 显示提案查询信息
func ShowActiveBoardCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "showActiveBoardInfo",
Short: "show active board info",
Run: showActiveBoard,
}
return cmd
}
func showActiveBoard(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
params := rpctypes.Query4Jrpc{}
params.Execer = auty.AutonomyX
params.FuncName = auty.GetActiveBoard
params.Payload = types.MustPBToJSON(&types.ReqString{})
rep := &auty.ActiveBoard{}
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, rep)
ctx.Run()
}
......@@ -134,3 +134,16 @@ func (a *Autonomy) listProposalBoard(req *auty.ReqQueryProposalBoard) (types.Mes
}
return &rep, nil
}
func (a *Autonomy) getActiveBoard() (types.Message, error) {
value, err := a.GetStateDB().Get(activeBoardID())
if err != nil {
return nil, err
}
prop := &auty.ActiveBoard{}
err = types.Decode(value, prop)
if err != nil {
return nil, err
}
return prop, nil
}
......@@ -357,6 +357,19 @@ func TestListProposalBoard(t *testing.T) {
assert.Equal(t, rsp.(*auty.ReplyQueryProposalBoard).PropBoards[1].Index, int32(testcase2[0].index))
}
func TestGetActiveBoard(t *testing.T) {
au := &Autonomy{
dapp.DriverBase{},
}
_, storedb, _ := util.CreateTestDB()
au.SetStateDB(storedb)
storedb.Set(activeBoardID(), types.Encode(&auty.ActiveBoard{Boards: []string{"111"}}))
rsp, err := au.getActiveBoard()
assert.NoError(t, err)
assert.NotNil(t, rsp)
assert.Equal(t, len(rsp.(*auty.ActiveBoard).Boards), 1)
}
func checkExecLocalBoard(t *testing.T, kvdb db.KVDB, cur *auty.AutonomyProposalBoard) {
table := NewBoardTable(kvdb)
query := table.GetQuery(kvdb)
......
......@@ -387,13 +387,6 @@ func (a *action) pubVotePropProject(voteProb *auty.PubVoteProposalProject) (*typ
}
logs = append(logs, receiptPrj.Logs...)
kv = append(kv, receiptPrj.KV...)
// 需要更新该董事会的累计审批金
pakv, err := a.updatePeriodAmount(cur.PropProject.Amount)
if err != nil {
alog.Error("pubVotePropProject ", "addr", cur.Address, "execaddr", a.execaddr, "updatePeriodAmount fail", err)
return nil, err
}
kv = append(kv, pakv)
}
key := propProjectID(voteProb.ProposalID)
......
......@@ -458,6 +458,14 @@ func checkVoteProposalProjectResult(t *testing.T, stateDB dbm.KV, proposalID str
assert.NoError(t, err)
assert.Equal(t, int32(auty.AutonomyStatusTmintPropProject), cur.Status)
assert.Equal(t, AddrA, cur.Address)
// 更新董事会累计审批金
value, err = stateDB.Get(activeBoardID())
assert.NoError(t, err)
aBd := &auty.ActiveBoard{}
err = types.Decode(value, aBd)
assert.NoError(t, err)
assert.Equal(t, testProjectAmount, aBd.Amount)
}
func pubVoteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB dbm.KV, kvdb dbm.KVDB, save bool) {
......@@ -486,7 +494,7 @@ func pubVoteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, sta
exec.SetAPI(api)
proposalID := env.txHash
// 4人参与投票,3人赞成票,1人反对票
// 3人参与投票,2人赞成票,1人反对票
type record struct {
priv string
appr bool
......@@ -566,6 +574,14 @@ func checkPubVoteProposalProjectResult(t *testing.T, stateDB dbm.KV, proposalID
assert.NoError(t, err)
assert.Equal(t, int32(auty.AutonomyStatusTmintPropProject), cur.Status)
assert.Equal(t, AddrA, cur.Address)
// 更新董事会累计审批金
value, err = stateDB.Get(activeBoardID())
assert.NoError(t, err)
aBd := &auty.ActiveBoard{}
err = types.Decode(value, aBd)
assert.NoError(t, err)
assert.Equal(t, int64(0), aBd.Amount)
}
func pubVoteProposalProjectTx(parm *auty.PubVoteProposalProject) (*types.Transaction, error) {
......
......@@ -19,6 +19,11 @@ func (a *Autonomy) Query_ListProposalBoard(in *auty.ReqQueryProposalBoard) (type
return a.listProposalBoard(in)
}
// Query_GetActiveBoard 查询当前board
func (a *Autonomy) Query_GetActiveBoard(in *types.ReqString) (types.Message, error) {
return a.getActiveBoard()
}
// Query_GetProposalProject 查询提案项目
func (a *Autonomy) Query_GetProposalProject(in *types.ReqString) (types.Message, error) {
return a.getProposalProject(in)
......
......@@ -45,9 +45,9 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) {
}
if (prob.RuleCfg.BoardApproveRatio > 0 && (prob.RuleCfg.BoardApproveRatio > maxBoardApproveRatio || prob.RuleCfg.BoardApproveRatio < minBoardApproveRatio)) ||
(prob.RuleCfg.PubOpposeRatio > 0 && (prob.RuleCfg.PubOpposeRatio > maxPubOpposeRatio || prob.RuleCfg.PubOpposeRatio < minPubOpposeRatio)) ||
(prob.RuleCfg.PublicPeriod > 0 && (prob.RuleCfg.PublicPeriod > maxPublicPeriod || prob.RuleCfg.PublicPeriod < minPublicPeriod )) ||
(prob.RuleCfg.PublicPeriod > 0 && (prob.RuleCfg.PublicPeriod > maxPublicPeriod || prob.RuleCfg.PublicPeriod < minPublicPeriod)) ||
(prob.RuleCfg.LargeProjectAmount > 0 && (prob.RuleCfg.LargeProjectAmount > maxLargeProjectAmount || prob.RuleCfg.LargeProjectAmount < minLargeProjectAmount)) ||
(prob.RuleCfg.ProposalAmount > 0 && (prob.RuleCfg.ProposalAmount > maxProposalAmount || prob.RuleCfg.ProposalAmount < minProposalAmount )){
(prob.RuleCfg.ProposalAmount > 0 && (prob.RuleCfg.ProposalAmount > maxProposalAmount || prob.RuleCfg.ProposalAmount < minProposalAmount)) {
alog.Error("propRule RuleCfg invaild", "ruleCfg", prob.RuleCfg)
return nil, types.ErrInvalidParam
}
......
......@@ -80,6 +80,17 @@ func TestPropRule(t *testing.T) {
StartBlockHeight: env.blockHeight + 5,
EndBlockHeight: env.blockHeight + startEndBlockPeriod + 10,
},
{ // 配置参数其中之一不合法
RuleCfg: &auty.RuleConfig{
BoardApproveRatio: 1,
PubOpposeRatio: minPubOpposeRatio + 1,
ProposalAmount: minProposalAmount + 1,
LargeProjectAmount: minLargeProjectAmount + 1,
PublicPeriod: minPublicPeriod + 1,
},
StartBlockHeight: env.blockHeight + 5,
EndBlockHeight: env.blockHeight + startEndBlockPeriod + 10,
},
}
result := []error{
......@@ -88,6 +99,7 @@ func TestPropRule(t *testing.T) {
nil,
types.ErrInvalidParam,
types.ErrInvalidParam,
types.ErrInvalidParam,
}
exec.SetEnv(env.blockHeight, env.blockTime, env.difficulty)
......
......@@ -96,3 +96,12 @@ func testListProposalBoardCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
rep = &auty.ReplyQueryProposalBoard{}
return jrpc.Call("Chain33.Query", params, rep)
}
func testGetActiveBoardCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var rep interface{}
var params rpctypes.Query4Jrpc
params.FuncName = auty.GetActiveBoard
params.Payload = types.MustPBToJSON(&types.ReqString{})
rep = &auty.ActiveBoard{}
return jrpc.Call("Chain33.Query", params, rep)
}
......@@ -42,6 +42,7 @@ func TestJRPCChannel(t *testing.T) {
{fn: testTerminateProposalBoardTxCmd},
{fn: testGetProposalBoardCmd},
{fn: testListProposalBoardCmd},
{fn: testGetActiveBoardCmd},
{fn: testPropProjectTxCmd},
{fn: testRevokeProposalProjectTxCmd},
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -93,6 +93,8 @@ const (
GetProposalBoard = "GetProposalBoard"
// ListProposalBoard 查询多个
ListProposalBoard = "ListProposalBoard"
// GetActiveBoard 查询当前的
GetActiveBoard = "GetActiveBoard"
// GetProposalProject 用于在cmd里面的区分不同的查询
GetProposalProject = "GetProposalProject"
// ListProposalProject 查询多个
......
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: lcommon.proto
package types
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
type VoteResult struct {
// 总票数
TotalVotes int32 `protobuf:"varint,1,opt,name=totalVotes" json:"totalVotes,omitempty"`
// 赞成票
ApproveVotes int32 `protobuf:"varint,2,opt,name=approveVotes" json:"approveVotes,omitempty"`
// 反对票
OpposeVotes int32 `protobuf:"varint,3,opt,name=opposeVotes" json:"opposeVotes,omitempty"`
// 是否通过
Pass bool `protobuf:"varint,4,opt,name=pass" json:"pass,omitempty"`
}
func (m *VoteResult) Reset() { *m = VoteResult{} }
func (m *VoteResult) String() string { return proto.CompactTextString(m) }
func (*VoteResult) ProtoMessage() {}
func (*VoteResult) Descriptor() ([]byte, []int) { return fileDescriptor3, []int{0} }
func (m *VoteResult) GetTotalVotes() int32 {
if m != nil {
return m.TotalVotes
}
return 0
}
func (m *VoteResult) GetApproveVotes() int32 {
if m != nil {
return m.ApproveVotes
}
return 0
}
func (m *VoteResult) GetOpposeVotes() int32 {
if m != nil {
return m.OpposeVotes
}
return 0
}
func (m *VoteResult) GetPass() bool {
if m != nil {
return m.Pass
}
return false
}
type PublicVote struct {
// 是否需要公示
Publicity bool `protobuf:"varint,1,opt,name=publicity" json:"publicity,omitempty"`
// 总票数
TotalVotes int32 `protobuf:"varint,2,opt,name=totalVotes" json:"totalVotes,omitempty"`
// 全体持票人反对票
OpposeVotes int32 `protobuf:"varint,3,opt,name=opposeVotes" json:"opposeVotes,omitempty"`
// 是否通过
PubPass bool `protobuf:"varint,4,opt,name=pubPass" json:"pubPass,omitempty"`
}
func (m *PublicVote) Reset() { *m = PublicVote{} }
func (m *PublicVote) String() string { return proto.CompactTextString(m) }
func (*PublicVote) ProtoMessage() {}
func (*PublicVote) Descriptor() ([]byte, []int) { return fileDescriptor3, []int{1} }
func (m *PublicVote) GetPublicity() bool {
if m != nil {
return m.Publicity
}
return false
}
func (m *PublicVote) GetTotalVotes() int32 {
if m != nil {
return m.TotalVotes
}
return 0
}
func (m *PublicVote) GetOpposeVotes() int32 {
if m != nil {
return m.OpposeVotes
}
return 0
}
func (m *PublicVote) GetPubPass() bool {
if m != nil {
return m.PubPass
}
return false
}
type VotesRecord struct {
Address []string `protobuf:"bytes,1,rep,name=address" json:"address,omitempty"`
}
func (m *VotesRecord) Reset() { *m = VotesRecord{} }
func (m *VotesRecord) String() string { return proto.CompactTextString(m) }
func (*VotesRecord) ProtoMessage() {}
func (*VotesRecord) Descriptor() ([]byte, []int) { return fileDescriptor3, []int{2} }
func (m *VotesRecord) GetAddress() []string {
if m != nil {
return m.Address
}
return nil
}
type RuleConfig struct {
// 董事会成员赞成率,以%为单位,只保留整数部分
BoardApproveRatio int32 `protobuf:"varint,1,opt,name=boardApproveRatio" json:"boardApproveRatio,omitempty"`
// 全体持票人否决率
PubOpposeRatio int32 `protobuf:"varint,2,opt,name=pubOpposeRatio" json:"pubOpposeRatio,omitempty"`
// 提案金额
ProposalAmount int64 `protobuf:"varint,3,opt,name=proposalAmount" json:"proposalAmount,omitempty"`
// 重大项目公示金额阈值
LargeProjectAmount int64 `protobuf:"varint,4,opt,name=largeProjectAmount" json:"largeProjectAmount,omitempty"`
// 重大项目公示时间(以区块数为单位)
PublicPeriod int32 `protobuf:"varint,5,opt,name=publicPeriod" json:"publicPeriod,omitempty"`
}
func (m *RuleConfig) Reset() { *m = RuleConfig{} }
func (m *RuleConfig) String() string { return proto.CompactTextString(m) }
func (*RuleConfig) ProtoMessage() {}
func (*RuleConfig) Descriptor() ([]byte, []int) { return fileDescriptor3, []int{3} }
func (m *RuleConfig) GetBoardApproveRatio() int32 {
if m != nil {
return m.BoardApproveRatio
}
return 0
}
func (m *RuleConfig) GetPubOpposeRatio() int32 {
if m != nil {
return m.PubOpposeRatio
}
return 0
}
func (m *RuleConfig) GetProposalAmount() int64 {
if m != nil {
return m.ProposalAmount
}
return 0
}
func (m *RuleConfig) GetLargeProjectAmount() int64 {
if m != nil {
return m.LargeProjectAmount
}
return 0
}
func (m *RuleConfig) GetPublicPeriod() int32 {
if m != nil {
return m.PublicPeriod
}
return 0
}
type ActiveBoard struct {
Boards []string `protobuf:"bytes,1,rep,name=boards" json:"boards,omitempty"`
Revboards []string `protobuf:"bytes,2,rep,name=revboards" json:"revboards,omitempty"`
Amount int64 `protobuf:"varint,3,opt,name=amount" json:"amount,omitempty"`
StartHeight int64 `protobuf:"varint,4,opt,name=startHeight" json:"startHeight,omitempty"`
}
func (m *ActiveBoard) Reset() { *m = ActiveBoard{} }
func (m *ActiveBoard) String() string { return proto.CompactTextString(m) }
func (*ActiveBoard) ProtoMessage() {}
func (*ActiveBoard) Descriptor() ([]byte, []int) { return fileDescriptor3, []int{4} }
func (m *ActiveBoard) GetBoards() []string {
if m != nil {
return m.Boards
}
return nil
}
func (m *ActiveBoard) GetRevboards() []string {
if m != nil {
return m.Revboards
}
return nil
}
func (m *ActiveBoard) GetAmount() int64 {
if m != nil {
return m.Amount
}
return 0
}
func (m *ActiveBoard) GetStartHeight() int64 {
if m != nil {
return m.StartHeight
}
return 0
}
func init() {
proto.RegisterType((*VoteResult)(nil), "types.VoteResult")
proto.RegisterType((*PublicVote)(nil), "types.PublicVote")
proto.RegisterType((*VotesRecord)(nil), "types.VotesRecord")
proto.RegisterType((*RuleConfig)(nil), "types.RuleConfig")
proto.RegisterType((*ActiveBoard)(nil), "types.ActiveBoard")
}
func init() { proto.RegisterFile("lcommon.proto", fileDescriptor3) }
var fileDescriptor3 = []byte{
// 352 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xbf, 0x4e, 0xe3, 0x40,
0x10, 0x87, 0xe5, 0xfc, 0xbb, 0x64, 0x72, 0x77, 0xd2, 0x6d, 0x71, 0x72, 0x81, 0x50, 0xe4, 0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b, 0x50, 0xf9, 0x6a, 0xdd, 0xec, 0x42, 0x2a,
0x32, 0xd8, 0x6e, 0xf0, 0xbc, 0x21, 0xae, 0xe0, 0xaf, 0xab, 0x8b, 0x47, 0x36, 0x6a, 0xd0, 0x66,
0x8a, 0x93, 0x94, 0x39, 0x8f, 0x0e, 0x83, 0xb2, 0xeb, 0x2d, 0xd6, 0x3b, 0xe2, 0x61, 0x86, 0xf2,
0x24, 0x15, 0x2b, 0x10, 0x56, 0xf9, 0x8d, 0xce, 0x3d, 0xbe, 0xea, 0x92, 0x5a, 0x76, 0xc4, 0xec,
0x37, 0x9d, 0x78, 0xc8, 0x66, 0x9d, 0xb9, 0xf6, 0x06, 0xab, 0x74, 0xdc, 0x1c, 0xb2, 0x9f, 0x65,
0x6f, 0x30, 0x5f, 0x97, 0x64, 0xf6, 0xfa, 0x2e, 0xea, 0x8b, 0xff, 0x30, 0xe1, 0x39, 0xba, 0x45,
0xb4, 0x55, 0x3c, 0x95, 0xd7, 0xfb, 0xb6, 0x35, 0xe0, 0xd6, 0x31, 0x88, 0x7f, 0xa9, 0xbe, 0x78,
0x5b, 0xc5, 0x13, 0x05, 0x52, 0x9e, 0x1e, 0xb4, 0xd9, 0xbc, 0x74, 0xa6, 0xfd, 0xa8, 0x98, 0xf0,
0x43, 0xbd, 0xfd, 0x0c, 0x00, 0x00, 0xff, 0xff, 0xaf, 0xca, 0x0f, 0x60, 0xb9, 0x02, 0x00, 0x00,
}
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment