Commit 72e879e6 authored by liuyuhang's avatar liuyuhang Committed by 33cn

merge func

parent 158281da
...@@ -57,21 +57,11 @@ func (a *action) propBoard(prob *auty.ProposalBoard) (*types.Receipt, error) { ...@@ -57,21 +57,11 @@ func (a *action) propBoard(prob *auty.ProposalBoard) (*types.Receipt, error) {
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
// 获取当前生效提案规则,并且将不修改的规则补齐 // 获取当前生效提案规则
rule := &auty.RuleConfig{} rule, err := a.getActiveRule()
value, err := a.db.Get(activeRuleID()) if err != nil {
if err == nil { alog.Error("propBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "getActiveRule failed", err)
err = types.Decode(value, rule) return nil, err
if err != nil {
alog.Error("propBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "decode ProposalRule failed", err)
return nil, err
}
} else {// 载入系统默认值
rule.BoardAttendRatio = boardAttendRatio
rule.BoardApproveRatio = boardApproveRatio
rule.PubOpposeRatio = pubOpposeRatio
rule.ProposalAmount = proposalAmount
rule.LargeProjectAmount = largeProjectAmount
} }
receipt, err := a.coinsAccount.ExecFrozen(a.fromaddr, a.execaddr, rule.ProposalAmount) receipt, err := a.coinsAccount.ExecFrozen(a.fromaddr, a.execaddr, rule.ProposalAmount)
...@@ -105,21 +95,13 @@ func (a *action) propBoard(prob *auty.ProposalBoard) (*types.Receipt, error) { ...@@ -105,21 +95,13 @@ func (a *action) propBoard(prob *auty.ProposalBoard) (*types.Receipt, error) {
} }
func (a *action) rvkPropBoard(rvkProb *auty.RevokeProposalBoard) (*types.Receipt, error) { func (a *action) rvkPropBoard(rvkProb *auty.RevokeProposalBoard) (*types.Receipt, error) {
// 获取GameID cur, err := a.getProposalBoard(rvkProb.ProposalID)
value, err := a.db.Get(propBoardID(rvkProb.ProposalID))
if err != nil { if err != nil {
alog.Error("rvkPropBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "get ProposalBoard) failed", alog.Error("rvkPropBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "getProposalBoard failed",
rvkProb.ProposalID, "err", err) rvkProb.ProposalID, "err", err)
return nil, err return nil, err
} }
var cur auty.AutonomyProposalBoard pre := copyAutonomyProposalBoard(cur)
err = types.Decode(value, &cur)
if err != nil {
alog.Error("rvkPropBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "decode ProposalBoard failed",
rvkProb.ProposalID, "err", err)
return nil, err
}
pre := copyAutonomyProposalBoard(&cur)
// 检查当前状态 // 检查当前状态
if cur.Status != auty.AutonomyStatusProposalBoard { if cur.Status != auty.AutonomyStatusProposalBoard {
...@@ -157,29 +139,21 @@ func (a *action) rvkPropBoard(rvkProb *auty.RevokeProposalBoard) (*types.Receipt ...@@ -157,29 +139,21 @@ func (a *action) rvkPropBoard(rvkProb *auty.RevokeProposalBoard) (*types.Receipt
cur.Status = auty.AutonomyStatusRvkPropBoard cur.Status = auty.AutonomyStatusRvkPropBoard
kv = append(kv, &types.KeyValue{Key: propBoardID(rvkProb.ProposalID), Value: types.Encode(&cur)}) kv = append(kv, &types.KeyValue{Key: propBoardID(rvkProb.ProposalID), Value: types.Encode(cur)})
getReceiptLog(pre, &cur, auty.TyLogRvkPropBoard) getReceiptLog(pre, cur, auty.TyLogRvkPropBoard)
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil
} }
func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt, error) { func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt, error) {
// 获取GameID cur, err := a.getProposalBoard(voteProb.ProposalID)
value, err := a.db.Get(propBoardID(voteProb.ProposalID))
if err != nil { if err != nil {
alog.Error("votePropBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "get propBoardID failed", alog.Error("votePropBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "getProposalBoard failed",
voteProb.ProposalID, "err", err) voteProb.ProposalID, "err", err)
return nil, err return nil, err
} }
var cur auty.AutonomyProposalBoard pre := copyAutonomyProposalBoard(cur)
err = types.Decode(value, &cur)
if err != nil {
alog.Error("votePropBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "decode AutonomyProposalBoard failed",
voteProb.ProposalID, "err", err)
return nil, err
}
pre := copyAutonomyProposalBoard(&cur)
// 检查当前状态 // 检查当前状态
if cur.Status != auty.AutonomyStatusProposalBoard && cur.Status != auty.AutonomyStatusVotePropBoard { if cur.Status != auty.AutonomyStatusProposalBoard && cur.Status != auty.AutonomyStatusVotePropBoard {
...@@ -200,27 +174,13 @@ func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt ...@@ -200,27 +174,13 @@ func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt
} }
// 检查是否已经参与投票 // 检查是否已经参与投票
var votes auty.VotesRecord votes, err := a.checkVotesRecord(voteProb.ProposalID)
value, err = a.db.Get(VotesRecord(voteProb.ProposalID)) if err != nil {
if err == nil { alog.Error("votePropBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "checkVotesRecord failed",
err = types.Decode(value, &votes) voteProb.ProposalID, "err", err)
if err != nil { return nil, err
alog.Error("votePropBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "decode VotesRecord failed",
voteProb.ProposalID, "err", err)
return nil, err
}
}
// 检查是否有重复
for _, addr := range votes.Address {
if addr == a.fromaddr {
err := auty.ErrRepeatVoteAddr
alog.Error("votePropBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "repeat address GameID",
voteProb.ProposalID, "err", err)
return nil, err
}
} }
// 加入已经投票的 // 更新投票记录
votes.Address = append(votes.Address, a.fromaddr) votes.Address = append(votes.Address, a.fromaddr)
if cur.GetVoteResult().TotalVotes == 0 { //需要统计票数 if cur.GetVoteResult().TotalVotes == 0 { //需要统计票数
...@@ -266,11 +226,10 @@ func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt ...@@ -266,11 +226,10 @@ func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt
if cur.VoteResult.Pass { if cur.VoteResult.Pass {
cur.Status = auty.AutonomyStatusTmintPropBoard cur.Status = auty.AutonomyStatusTmintPropBoard
} }
value = types.Encode(&cur) kv = append(kv, &types.KeyValue{Key: key, Value: types.Encode(cur)})
kv = append(kv, &types.KeyValue{Key: key, Value: value})
// 更新VotesRecord // 更新VotesRecord
kv = append(kv, &types.KeyValue{Key: VotesRecord(voteProb.ProposalID), Value: types.Encode(&votes)}) kv = append(kv, &types.KeyValue{Key: VotesRecord(voteProb.ProposalID), Value: types.Encode(votes)})
// 更新当前具有权利的董事会成员 // 更新当前具有权利的董事会成员
if cur.VoteResult.Pass { if cur.VoteResult.Pass {
...@@ -281,28 +240,20 @@ func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt ...@@ -281,28 +240,20 @@ func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt
if cur.VoteResult.Pass { if cur.VoteResult.Pass {
ty = auty.TyLogTmintPropBoard ty = auty.TyLogTmintPropBoard
} }
receiptLog := getReceiptLog(pre, &cur, int32(ty)) receiptLog := getReceiptLog(pre, cur, int32(ty))
logs = append(logs, receiptLog) logs = append(logs, receiptLog)
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil
} }
func (a *action) tmintPropBoard(tmintProb *auty.TerminateProposalBoard) (*types.Receipt, error) { func (a *action) tmintPropBoard(tmintProb *auty.TerminateProposalBoard) (*types.Receipt, error) {
// 获取GameID cur, err := a.getProposalBoard(tmintProb.ProposalID)
value, err := a.db.Get(propBoardID(tmintProb.ProposalID))
if err != nil {
alog.Error("tmintPropBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "get propBoardID failed",
tmintProb.ProposalID, "err", err)
return nil, err
}
var cur auty.AutonomyProposalBoard
err = types.Decode(value, &cur)
if err != nil { if err != nil {
alog.Error("tmintPropBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "decode AutonomyProposalBoard failed", alog.Error("tmintPropBoard ", "addr", a.fromaddr, "execaddr", a.execaddr, "getProposalBoard failed",
tmintProb.ProposalID, "err", err) tmintProb.ProposalID, "err", err)
return nil, err return nil, err
} }
pre := copyAutonomyProposalBoard(&cur) pre := copyAutonomyProposalBoard(cur)
// 检查当前状态 // 检查当前状态
if cur.Status == auty.AutonomyStatusTmintPropBoard { if cur.Status == auty.AutonomyStatusTmintPropBoard {
...@@ -350,14 +301,14 @@ func (a *action) tmintPropBoard(tmintProb *auty.TerminateProposalBoard) (*types. ...@@ -350,14 +301,14 @@ func (a *action) tmintPropBoard(tmintProb *auty.TerminateProposalBoard) (*types.
cur.Status = auty.AutonomyStatusTmintPropBoard cur.Status = auty.AutonomyStatusTmintPropBoard
kv = append(kv, &types.KeyValue{Key: propBoardID(tmintProb.ProposalID), Value: types.Encode(&cur)}) kv = append(kv, &types.KeyValue{Key: propBoardID(tmintProb.ProposalID), Value: types.Encode(cur)})
// 更新当前具有权利的董事会成员 // 更新当前具有权利的董事会成员
if cur.VoteResult.Pass { if cur.VoteResult.Pass {
kv = append(kv, &types.KeyValue{Key: activeBoardID(), Value:types.Encode(cur.PropBoard)}) kv = append(kv, &types.KeyValue{Key: activeBoardID(), Value:types.Encode(cur.PropBoard)})
} }
getReceiptLog(pre, &cur, auty.TyLogTmintPropBoard) getReceiptLog(pre, cur, auty.TyLogTmintPropBoard)
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil
} }
...@@ -386,6 +337,57 @@ func (a *action) getStartHeightVoteAccount(addr string, height int64) (*types.Ac ...@@ -386,6 +337,57 @@ func (a *action) getStartHeightVoteAccount(addr string, height int64) (*types.Ac
return account[0], nil return account[0], nil
} }
func (a *action) getProposalBoard(ID string) (*auty.AutonomyProposalBoard, error) {
value, err := a.db.Get(propBoardID(ID))
if err != nil {
return nil, err
}
cur := &auty.AutonomyProposalBoard{}
err = types.Decode(value, cur)
if err != nil {
return nil, err
}
return cur, nil
}
func (a *action) getActiveRule() (*auty.RuleConfig, error) {
// 获取当前生效提案规则,并且将不修改的规则补齐
rule := &auty.RuleConfig{}
value, err := a.db.Get(activeRuleID())
if err == nil {
err = types.Decode(value, rule)
if err != nil {
return nil, err
}
} else {// 载入系统默认值
rule.BoardAttendRatio = boardAttendRatio
rule.BoardApproveRatio = boardApproveRatio
rule.PubOpposeRatio = pubOpposeRatio
rule.ProposalAmount = proposalAmount
rule.LargeProjectAmount = largeProjectAmount
}
return rule, nil
}
func (a *action) checkVotesRecord(ID string) (*auty.VotesRecord, error) {
var votes auty.VotesRecord
value, err := a.db.Get(VotesRecord(ID))
if err == nil {
err = types.Decode(value, &votes)
if err != nil {
return nil, err
}
}
// 检查是否有重复
for _, addr := range votes.Address {
if addr == a.fromaddr {
err := auty.ErrRepeatVoteAddr
return nil, err
}
}
return &votes, nil
}
// getReceiptLog 根据提案信息获取log // getReceiptLog 根据提案信息获取log
// 状态变化: // 状态变化:
func getReceiptLog(pre, cur *auty.AutonomyProposalBoard, ty int32) *types.ReceiptLog { func getReceiptLog(pre, cur *auty.AutonomyProposalBoard, ty int32) *types.ReceiptLog {
......
...@@ -175,7 +175,7 @@ func testPropBoard(t *testing.T, env *execEnv, exec drivers.Driver, stateDB dbm. ...@@ -175,7 +175,7 @@ func testPropBoard(t *testing.T, env *execEnv, exec drivers.Driver, stateDB dbm.
accCoin := account.NewCoinsAccount() accCoin := account.NewCoinsAccount()
accCoin.SetDB(stateDB) accCoin.SetDB(stateDB)
account := accCoin.LoadExecAccount(AddrA, address.ExecAddress(auty.AutonomyX)) account := accCoin.LoadExecAccount(AddrA, address.ExecAddress(auty.AutonomyX))
require.Equal(t, lockAmount, account.Frozen) require.Equal(t, proposalAmount, account.Frozen)
} }
func propBoardTx(parm *auty.ProposalBoard) (*types.Transaction, error) { func propBoardTx(parm *auty.ProposalBoard) (*types.Transaction, error) {
...@@ -267,10 +267,10 @@ func voteProposalBoard(t *testing.T, env *execEnv, exec drivers.Driver, stateDB ...@@ -267,10 +267,10 @@ func voteProposalBoard(t *testing.T, env *execEnv, exec drivers.Driver, stateDB
appr bool appr bool
} }
records := []record{ records := []record{
{PrivKeyA, true}, {PrivKeyA, false},
{PrivKeyB, false}, {PrivKeyB, false},
{PrivKeyC, true}, {PrivKeyC, true},
//{PrivKeyD, true}, {PrivKeyD, true},
} }
for _, record := range records { for _, record := range records {
...@@ -320,7 +320,7 @@ func voteProposalBoard(t *testing.T, env *execEnv, exec drivers.Driver, stateDB ...@@ -320,7 +320,7 @@ func voteProposalBoard(t *testing.T, env *execEnv, exec drivers.Driver, stateDB
account := accCoin.LoadExecAccount(AddrA, address.ExecAddress(auty.AutonomyX)) account := accCoin.LoadExecAccount(AddrA, address.ExecAddress(auty.AutonomyX))
require.Equal(t, int64(0), account.Frozen) require.Equal(t, int64(0), account.Frozen)
account = accCoin.LoadExecAccount(autonomyAddr, address.ExecAddress(auty.AutonomyX)) account = accCoin.LoadExecAccount(autonomyAddr, address.ExecAddress(auty.AutonomyX))
require.Equal(t, int64(lockAmount), account.Balance) require.Equal(t, int64(proposalAmount), account.Balance)
// status // status
value, err := stateDB.Get(propBoardID(proposalID)) value, err := stateDB.Get(propBoardID(proposalID))
require.NoError(t, err) require.NoError(t, err)
......
...@@ -25,21 +25,12 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) { ...@@ -25,21 +25,12 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) {
} }
// 获取当前生效提案规则,并且将不修改的规则补齐 // 获取当前生效提案规则,并且将不修改的规则补齐
rule := &auty.RuleConfig{} rule, err := a.getActiveRule()
value, err := a.db.Get(activeRuleID()) if err != nil {
if err == nil { alog.Error("propRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "getActiveRule failed", err)
err = types.Decode(value, rule) return nil, err
if err != nil {
alog.Error("propRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "decode ProposalRule failed", err)
return nil, err
}
} else {// 载入系统默认值
rule.BoardAttendRatio = boardAttendRatio
rule.BoardApproveRatio = boardApproveRatio
rule.PubOpposeRatio = pubOpposeRatio
rule.ProposalAmount = proposalAmount
rule.LargeProjectAmount = largeProjectAmount
} }
if prob.RuleCfg.BoardAttendRatio > 0 { if prob.RuleCfg.BoardAttendRatio > 0 {
rule.BoardAttendRatio = prob.RuleCfg.BoardAttendRatio rule.BoardAttendRatio = prob.RuleCfg.BoardAttendRatio
} }
...@@ -79,7 +70,7 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) { ...@@ -79,7 +70,7 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) {
} }
key := propRuleID(common.ToHex(a.txhash)) key := propRuleID(common.ToHex(a.txhash))
value = types.Encode(cur) value := types.Encode(cur)
kv = append(kv, &types.KeyValue{Key: key, Value: value}) kv = append(kv, &types.KeyValue{Key: key, Value: value})
receiptLog := getRuleReceiptLog(nil, cur, auty.TyLogPropRule) receiptLog := getRuleReceiptLog(nil, cur, auty.TyLogPropRule)
...@@ -89,21 +80,13 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) { ...@@ -89,21 +80,13 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) {
} }
func (a *action) rvkPropRule(rvkProb *auty.RevokeProposalRule) (*types.Receipt, error) { func (a *action) rvkPropRule(rvkProb *auty.RevokeProposalRule) (*types.Receipt, error) {
// 获取GameID cur, err := a.getProposalRule(rvkProb.ProposalID)
value, err := a.db.Get(propRuleID(rvkProb.ProposalID))
if err != nil {
alog.Error("rvkPropRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "get ProposalRule) failed",
rvkProb.ProposalID, "err", err)
return nil, err
}
var cur auty.AutonomyProposalRule
err = types.Decode(value, &cur)
if err != nil { if err != nil {
alog.Error("rvkPropRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "decode ProposalRule failed", alog.Error("rvkPropRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "getProposalRule failed",
rvkProb.ProposalID, "err", err) rvkProb.ProposalID, "err", err)
return nil, err return nil, err
} }
pre := copyAutonomyProposalRule(&cur) pre := copyAutonomyProposalRule(cur)
// 检查当前状态 // 检查当前状态
if cur.Status != auty.AutonomyStatusProposalRule { if cur.Status != auty.AutonomyStatusProposalRule {
...@@ -141,29 +124,21 @@ func (a *action) rvkPropRule(rvkProb *auty.RevokeProposalRule) (*types.Receipt, ...@@ -141,29 +124,21 @@ func (a *action) rvkPropRule(rvkProb *auty.RevokeProposalRule) (*types.Receipt,
cur.Status = auty.AutonomyStatusRvkPropRule cur.Status = auty.AutonomyStatusRvkPropRule
kv = append(kv, &types.KeyValue{Key: propRuleID(rvkProb.ProposalID), Value: types.Encode(&cur)}) kv = append(kv, &types.KeyValue{Key: propRuleID(rvkProb.ProposalID), Value: types.Encode(cur)})
getRuleReceiptLog(pre, &cur, auty.TyLogRvkPropRule) getRuleReceiptLog(pre, cur, auty.TyLogRvkPropRule)
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil
} }
func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt, error) { func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt, error) {
// 获取GameID cur, err := a.getProposalRule(voteProb.ProposalID)
value, err := a.db.Get(propRuleID(voteProb.ProposalID))
if err != nil { if err != nil {
alog.Error("votePropRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "get propRuleID failed", alog.Error("votePropRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "getProposalRule failed",
voteProb.ProposalID, "err", err) voteProb.ProposalID, "err", err)
return nil, err return nil, err
} }
var cur auty.AutonomyProposalRule pre := copyAutonomyProposalRule(cur)
err = types.Decode(value, &cur)
if err != nil {
alog.Error("votePropRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "decode AutonomyProposalRule failed",
voteProb.ProposalID, "err", err)
return nil, err
}
pre := copyAutonomyProposalRule(&cur)
// 检查当前状态 // 检查当前状态
if cur.Status != auty.AutonomyStatusProposalRule && cur.Status != auty.AutonomyStatusVotePropRule { if cur.Status != auty.AutonomyStatusProposalRule && cur.Status != auty.AutonomyStatusVotePropRule {
...@@ -184,27 +159,13 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt, ...@@ -184,27 +159,13 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt,
} }
// 检查是否已经参与投票 // 检查是否已经参与投票
var votes auty.VotesRecord votes, err := a.checkVotesRecord(voteProb.ProposalID)
value, err = a.db.Get(VotesRecord(voteProb.ProposalID)) if err != nil {
if err == nil { alog.Error("votePropRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "checkVotesRecord failed",
err = types.Decode(value, &votes) voteProb.ProposalID, "err", err)
if err != nil { return nil, err
alog.Error("votePropRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "decode VotesRecord failed",
voteProb.ProposalID, "err", err)
return nil, err
}
}
// 检查是否有重复
for _, addr := range votes.Address {
if addr == a.fromaddr {
err := auty.ErrRepeatVoteAddr
alog.Error("votePropRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "repeat address GameID",
voteProb.ProposalID, "err", err)
return nil, err
}
} }
// 加入已经投票的 // 更新投票记录
votes.Address = append(votes.Address, a.fromaddr) votes.Address = append(votes.Address, a.fromaddr)
if cur.GetVoteResult().TotalVotes == 0 { //需要统计票数 if cur.GetVoteResult().TotalVotes == 0 { //需要统计票数
...@@ -216,6 +177,7 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt, ...@@ -216,6 +177,7 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt,
cur.VoteResult.TotalVotes = int32(account.Balance/ticketPrice) cur.VoteResult.TotalVotes = int32(account.Balance/ticketPrice)
} }
// 获取可投票数
account, err := a.getStartHeightVoteAccount(a.fromaddr, start) account, err := a.getStartHeightVoteAccount(a.fromaddr, start)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -250,13 +212,12 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt, ...@@ -250,13 +212,12 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt,
if cur.VoteResult.Pass { if cur.VoteResult.Pass {
cur.Status = auty.AutonomyStatusTmintPropRule cur.Status = auty.AutonomyStatusTmintPropRule
} }
value = types.Encode(&cur) kv = append(kv, &types.KeyValue{Key: key, Value: types.Encode(cur)})
kv = append(kv, &types.KeyValue{Key: key, Value: value})
// 更新VotesRecord // 更新VotesRecord
kv = append(kv, &types.KeyValue{Key: VotesRecord(voteProb.ProposalID), Value: types.Encode(&votes)}) kv = append(kv, &types.KeyValue{Key: VotesRecord(voteProb.ProposalID), Value: types.Encode(votes)})
// 更新当前具有权利的董事会成员 // 更新系统规则
if cur.VoteResult.Pass { if cur.VoteResult.Pass {
kv = append(kv, &types.KeyValue{Key: activeRuleID(), Value:types.Encode(cur.Rule)}) kv = append(kv, &types.KeyValue{Key: activeRuleID(), Value:types.Encode(cur.Rule)})
} }
...@@ -265,28 +226,21 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt, ...@@ -265,28 +226,21 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt,
if cur.VoteResult.Pass { if cur.VoteResult.Pass {
ty = auty.TyLogTmintPropRule ty = auty.TyLogTmintPropRule
} }
receiptLog := getRuleReceiptLog(pre, &cur, int32(ty)) receiptLog := getRuleReceiptLog(pre, cur, int32(ty))
logs = append(logs, receiptLog) logs = append(logs, receiptLog)
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil
} }
func (a *action) tmintPropRule(tmintProb *auty.TerminateProposalRule) (*types.Receipt, error) { func (a *action) tmintPropRule(tmintProb *auty.TerminateProposalRule) (*types.Receipt, error) {
// 获取GameID cur, err := a.getProposalRule(tmintProb.ProposalID)
value, err := a.db.Get(propRuleID(tmintProb.ProposalID))
if err != nil {
alog.Error("tmintPropRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "get propRuleID failed",
tmintProb.ProposalID, "err", err)
return nil, err
}
var cur auty.AutonomyProposalRule
err = types.Decode(value, &cur)
if err != nil { if err != nil {
alog.Error("tmintPropRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "decode AutonomyProposalRule failed", alog.Error("tmintPropRule ", "addr", a.fromaddr, "execaddr", a.execaddr, "getProposalRule failed",
tmintProb.ProposalID, "err", err) tmintProb.ProposalID, "err", err)
return nil, err return nil, err
} }
pre := copyAutonomyProposalRule(&cur)
pre := copyAutonomyProposalRule(cur)
// 检查当前状态 // 检查当前状态
if cur.Status == auty.AutonomyStatusTmintPropRule { if cur.Status == auty.AutonomyStatusTmintPropRule {
...@@ -334,18 +288,31 @@ func (a *action) tmintPropRule(tmintProb *auty.TerminateProposalRule) (*types.Re ...@@ -334,18 +288,31 @@ func (a *action) tmintPropRule(tmintProb *auty.TerminateProposalRule) (*types.Re
cur.Status = auty.AutonomyStatusTmintPropRule cur.Status = auty.AutonomyStatusTmintPropRule
kv = append(kv, &types.KeyValue{Key: propRuleID(tmintProb.ProposalID), Value: types.Encode(&cur)}) kv = append(kv, &types.KeyValue{Key: propRuleID(tmintProb.ProposalID), Value: types.Encode(cur)})
// 更新当前具有权利的董事会成员 // 更新系统规则
if cur.VoteResult.Pass { if cur.VoteResult.Pass {
kv = append(kv, &types.KeyValue{Key: activeRuleID(), Value:types.Encode(cur.Rule)}) kv = append(kv, &types.KeyValue{Key: activeRuleID(), Value:types.Encode(cur.Rule)})
} }
getRuleReceiptLog(pre, &cur, auty.TyLogTmintPropRule) getRuleReceiptLog(pre, cur, auty.TyLogTmintPropRule)
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil
} }
func (a *action) getProposalRule(ID string) (*auty.AutonomyProposalRule, error) {
value, err := a.db.Get(propRuleID(ID))
if err != nil {
return nil, err
}
cur := &auty.AutonomyProposalRule{}
err = types.Decode(value, cur)
if err != nil {
return nil, err
}
return cur, nil
}
// getReceiptLog 根据提案信息获取log // getReceiptLog 根据提案信息获取log
// 状态变化: // 状态变化:
func getRuleReceiptLog(pre, cur *auty.AutonomyProposalRule, ty int32) *types.ReceiptLog { func getRuleReceiptLog(pre, cur *auty.AutonomyProposalRule, ty int32) *types.ReceiptLog {
......
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