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
2dc66974
Commit
2dc66974
authored
Jul 29, 2019
by
liuyuhang
Committed by
33cn
Aug 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify static ticket frozen for votes and add config to total address
parent
1b4e981c
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
81 additions
and
48 deletions
+81
-48
chain33.toml
chain33.toml
+3
-0
autonomy.go
plugin/dapp/autonomy/executor/autonomy.go
+9
-0
boardaction.go
plugin/dapp/autonomy/executor/boardaction.go
+37
-14
boardaction_test.go
plugin/dapp/autonomy/executor/boardaction_test.go
+5
-5
projectaction.go
plugin/dapp/autonomy/executor/projectaction.go
+6
-8
projectaction_test.go
plugin/dapp/autonomy/executor/projectaction_test.go
+4
-4
ruleaction.go
plugin/dapp/autonomy/executor/ruleaction.go
+11
-13
ruleaction_test.go
plugin/dapp/autonomy/executor/ruleaction_test.go
+4
-4
const.go
plugin/dapp/autonomy/types/const.go
+2
-0
No files found.
chain33.toml
View file @
2dc66974
...
...
@@ -223,4 +223,7 @@ nodeGroupFrozenCoins=0
#平行链共识停止后主链等待的高度
paraConsensusStopBlocks
=
30000
[exec.sub.autonomy]
total
=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
useBalance
=
false
plugin/dapp/autonomy/executor/autonomy.go
View file @
2dc66974
...
...
@@ -12,10 +12,16 @@ import (
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
)
type
subConfig
struct
{
Total
string
`json:"total"`
UseBalance
bool
`json:"useBalance"`
}
var
(
alog
=
log
.
New
(
"module"
,
"execs.autonomy"
)
driverName
=
auty
.
AutonomyX
autonomyFundAddr
=
address
.
ExecAddress
(
"autonomyfund"
)
cfg
subConfig
)
func
init
()
{
...
...
@@ -25,6 +31,9 @@ func init() {
// Init 重命名执行器名称
func
Init
(
name
string
,
sub
[]
byte
)
{
if
sub
!=
nil
{
types
.
MustDecode
(
sub
,
&
cfg
)
}
drivers
.
Register
(
GetName
(),
newAutonomy
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
}
...
...
plugin/dapp/autonomy/executor/boardaction.go
View file @
2dc66974
...
...
@@ -198,22 +198,21 @@ func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt
votes
.
Address
=
append
(
votes
.
Address
,
a
.
fromaddr
)
if
cur
.
GetVoteResult
()
.
TotalVotes
==
0
{
//需要统计票数
addr
:=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
account
,
err
:=
a
.
getStartHeightVoteAccount
(
addr
,
start
)
vtCouts
,
err
:=
a
.
getTotalVotes
(
start
)
if
err
!=
nil
{
return
nil
,
err
}
cur
.
VoteResult
.
TotalVotes
=
int32
(
account
.
Balance
/
ticketPrice
)
cur
.
VoteResult
.
TotalVotes
=
vtCouts
}
account
,
err
:=
a
.
getStartHeightVoteAccount
(
a
.
fromaddr
,
start
)
vtCouts
,
err
:=
a
.
getAddressVotes
(
a
.
fromaddr
,
start
)
if
err
!=
nil
{
return
nil
,
err
}
if
voteProb
.
Approve
{
cur
.
VoteResult
.
ApproveVotes
+=
int32
(
account
.
Balance
/
ticketPrice
)
cur
.
VoteResult
.
ApproveVotes
+=
vtCouts
}
else
{
cur
.
VoteResult
.
OpposeVotes
+=
int32
(
account
.
Balance
/
ticketPrice
)
cur
.
VoteResult
.
OpposeVotes
+=
vtCouts
}
var
logs
[]
*
types
.
ReceiptLog
...
...
@@ -232,8 +231,8 @@ func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt
if
cur
.
VoteResult
.
TotalVotes
!=
0
&&
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
!=
0
&&
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
/
float32
(
cur
.
VoteResult
.
TotalVotes
)
>
=
float32
(
pubAttendRatio
)
/
100.0
&&
float32
(
cur
.
VoteResult
.
ApproveVotes
)
/
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
>
=
float32
(
pubApproveRatio
)
/
100.0
{
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
/
float32
(
cur
.
VoteResult
.
TotalVotes
)
>
float32
(
pubAttendRatio
)
/
100.0
&&
float32
(
cur
.
VoteResult
.
ApproveVotes
)
/
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
>
float32
(
pubApproveRatio
)
/
100.0
{
cur
.
VoteResult
.
Pass
=
true
cur
.
PropBoard
.
RealEndBlockHeight
=
a
.
height
}
...
...
@@ -291,16 +290,15 @@ func (a *action) tmintPropBoard(tmintProb *auty.TerminateProposalBoard) (*types.
}
if
cur
.
GetVoteResult
()
.
TotalVotes
==
0
{
//需要统计票数
addr
:=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
account
,
err
:=
a
.
getStartHeightVoteAccount
(
addr
,
start
)
vtCouts
,
err
:=
a
.
getTotalVotes
(
start
)
if
err
!=
nil
{
return
nil
,
err
}
cur
.
VoteResult
.
TotalVotes
=
int32
(
account
.
Balance
/
ticketPrice
)
cur
.
VoteResult
.
TotalVotes
=
vtCouts
}
if
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
/
float32
(
cur
.
VoteResult
.
TotalVotes
)
>
=
float32
(
pubAttendRatio
)
/
100.0
&&
float32
(
cur
.
VoteResult
.
ApproveVotes
)
/
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
>
=
float32
(
pubApproveRatio
)
/
100.0
{
if
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
/
float32
(
cur
.
VoteResult
.
TotalVotes
)
>
float32
(
pubAttendRatio
)
/
100.0
&&
float32
(
cur
.
VoteResult
.
ApproveVotes
)
/
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
>
float32
(
pubApproveRatio
)
/
100.0
{
cur
.
VoteResult
.
Pass
=
true
}
else
{
cur
.
VoteResult
.
Pass
=
false
...
...
@@ -336,7 +334,31 @@ func (a *action) tmintPropBoard(tmintProb *auty.TerminateProposalBoard) (*types.
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
func
(
a
*
action
)
getStartHeightVoteAccount
(
addr
string
,
height
int64
)
(
*
types
.
Account
,
error
)
{
func
(
a
*
action
)
getTotalVotes
(
height
int64
)
(
int32
,
error
)
{
addr
:=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
if
cfg
.
Total
!=
""
{
addr
=
cfg
.
Total
}
account
,
err
:=
a
.
getStartHeightVoteAccount
(
addr
,
""
,
height
)
if
err
!=
nil
{
return
0
,
err
}
return
int32
(
account
.
Balance
/
ticketPrice
),
nil
}
func
(
a
*
action
)
getAddressVotes
(
addr
string
,
height
int64
)
(
int32
,
error
)
{
account
,
err
:=
a
.
getStartHeightVoteAccount
(
addr
,
auty
.
TicketX
,
height
)
if
err
!=
nil
{
return
0
,
err
}
amount
:=
account
.
Frozen
if
cfg
.
UseBalance
{
amount
=
account
.
Balance
}
return
int32
(
amount
/
ticketPrice
),
nil
}
func
(
a
*
action
)
getStartHeightVoteAccount
(
addr
,
execer
string
,
height
int64
)
(
*
types
.
Account
,
error
)
{
param
:=
&
types
.
ReqBlocks
{
Start
:
height
,
End
:
height
,
...
...
@@ -351,6 +373,7 @@ func (a *action) getStartHeightVoteAccount(addr string, height int64) (*types.Ac
account
,
err
:=
a
.
coinsAccount
.
GetBalance
(
a
.
api
,
&
types
.
ReqBalance
{
Addresses
:
[]
string
{
addr
},
Execer
:
execer
,
StateHash
:
stateHash
,
})
if
err
!=
nil
||
len
(
account
)
==
0
{
...
...
plugin/dapp/autonomy/executor/boardaction_test.go
View file @
2dc66974
...
...
@@ -264,7 +264,7 @@ func voteProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
acc
=
&
types
.
Account
{
Currency
:
0
,
Balance
:
total
,
Frozen
:
total
,
}
val1
:=
types
.
Encode
(
acc
)
values1
:=
[][]
byte
{
val1
}
...
...
@@ -279,9 +279,9 @@ func voteProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
}
records
:=
[]
record
{
{
PrivKeyA
,
false
},
{
PrivKeyB
,
fals
e
},
{
PrivKeyB
,
tru
e
},
{
PrivKeyC
,
true
},
{
PrivKeyD
,
true
},
//
{PrivKeyD, true},
}
for
_
,
record
:=
range
records
{
...
...
@@ -321,7 +321,7 @@ func voteProposalBoard(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB
// 每次需要重新设置
acc
:=
&
types
.
Account
{
Currency
:
0
,
Balance
:
total
,
Frozen
:
total
,
}
val
:=
types
.
Encode
(
acc
)
values
:=
[][]
byte
{
val
}
...
...
@@ -447,7 +447,7 @@ func TestGetStartHeightVoteAccount(t *testing.T) {
api
.
On
(
"GetHeaders"
,
mock
.
Anything
)
.
Return
(
&
types
.
Headers
{
Items
:
[]
*
types
.
Header
{
hear
}},
nil
)
account
,
err
:=
action
.
getStartHeightVoteAccount
(
addr
,
0
)
account
,
err
:=
action
.
getStartHeightVoteAccount
(
addr
,
""
,
0
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
account
)
require
.
Equal
(
t
,
types
.
Coin
,
account
.
Balance
)
...
...
plugin/dapp/autonomy/executor/projectaction.go
View file @
2dc66974
...
...
@@ -301,21 +301,20 @@ func (a *action) pubVotePropProject(voteProb *auty.PubVoteProposalProject) (*typ
votes
.
Address
=
append
(
votes
.
Address
,
a
.
fromaddr
)
if
cur
.
GetPubVote
()
.
TotalVotes
==
0
{
//需要统计总票数
addr
:=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
account
,
err
:=
a
.
getStartHeightVoteAccount
(
addr
,
start
)
vtCouts
,
err
:=
a
.
getTotalVotes
(
start
)
if
err
!=
nil
{
return
nil
,
err
}
cur
.
PubVote
.
TotalVotes
=
int32
(
account
.
Balance
/
ticketPrice
)
cur
.
PubVote
.
TotalVotes
=
vtCouts
}
// 获取该地址票数
account
,
err
:=
a
.
getStartHeightVoteAccount
(
a
.
fromaddr
,
start
)
vtCouts
,
err
:=
a
.
getAddressVotes
(
a
.
fromaddr
,
start
)
if
err
!=
nil
{
return
nil
,
err
}
if
voteProb
.
Oppose
{
//投反对票
cur
.
PubVote
.
OpposeVotes
+=
int32
(
account
.
Balance
/
ticketPrice
)
cur
.
PubVote
.
OpposeVotes
+=
vtCouts
}
var
logs
[]
*
types
.
ReceiptLog
...
...
@@ -402,12 +401,11 @@ func (a *action) tmintPropProject(tmintProb *auty.TerminateProposalProject) (*ty
if
cur
.
PubVote
.
Publicity
{
if
cur
.
GetBoardVoteRes
()
.
TotalVotes
==
0
{
//需要统计总票数
addr
:=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
account
,
err
:=
a
.
getStartHeightVoteAccount
(
addr
,
start
)
vtCouts
,
err
:=
a
.
getTotalVotes
(
start
)
if
err
!=
nil
{
return
nil
,
err
}
cur
.
PubVote
.
TotalVotes
=
int32
(
account
.
Balance
/
ticketPrice
)
cur
.
PubVote
.
TotalVotes
=
vtCouts
}
if
cur
.
PubVote
.
TotalVotes
!=
0
&&
float32
(
cur
.
PubVote
.
OpposeVotes
)
/
float32
(
cur
.
PubVote
.
TotalVotes
)
>=
float32
(
cur
.
CurRule
.
PubOpposeRatio
)
/
100.0
{
...
...
plugin/dapp/autonomy/executor/projectaction_test.go
View file @
2dc66974
...
...
@@ -307,7 +307,7 @@ func voteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stateD
acc
=
&
types
.
Account
{
Currency
:
0
,
Balance
:
total
,
Frozen
:
total
,
}
val1
:=
types
.
Encode
(
acc
)
values1
:=
[][]
byte
{
val1
}
...
...
@@ -364,7 +364,7 @@ func voteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, stateD
// 每次需要重新设置
acc
:=
&
types
.
Account
{
Currency
:
0
,
Balance
:
total
,
Frozen
:
total
,
}
val
:=
types
.
Encode
(
acc
)
values
:=
[][]
byte
{
val
}
...
...
@@ -421,7 +421,7 @@ func pubVoteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, sta
acc
=
&
types
.
Account
{
Currency
:
0
,
Balance
:
total
,
Frozen
:
total
,
}
val1
:=
types
.
Encode
(
acc
)
values1
:=
[][]
byte
{
val1
}
...
...
@@ -478,7 +478,7 @@ func pubVoteProposalProject(t *testing.T, env *ExecEnv, exec drivers.Driver, sta
// 每次需要重新设置
acc
:=
&
types
.
Account
{
Currency
:
0
,
Balance
:
total
,
Frozen
:
total
,
}
val
:=
types
.
Encode
(
acc
)
values
:=
[][]
byte
{
val
}
...
...
plugin/dapp/autonomy/executor/ruleaction.go
View file @
2dc66974
...
...
@@ -163,23 +163,22 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt,
votes
.
Address
=
append
(
votes
.
Address
,
a
.
fromaddr
)
if
cur
.
GetVoteResult
()
.
TotalVotes
==
0
{
//需要统计票数
addr
:=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
account
,
err
:=
a
.
getStartHeightVoteAccount
(
addr
,
start
)
vtCouts
,
err
:=
a
.
getTotalVotes
(
start
)
if
err
!=
nil
{
return
nil
,
err
}
cur
.
VoteResult
.
TotalVotes
=
int32
(
account
.
Balance
/
ticketPrice
)
cur
.
VoteResult
.
TotalVotes
=
vtCouts
}
// 获取可投票数
account
,
err
:=
a
.
getStartHeightVoteAccount
(
a
.
fromaddr
,
start
)
vtCouts
,
err
:=
a
.
getAddressVotes
(
a
.
fromaddr
,
start
)
if
err
!=
nil
{
return
nil
,
err
}
if
voteProb
.
Approve
{
cur
.
VoteResult
.
ApproveVotes
+=
int32
(
account
.
Balance
/
ticketPrice
)
cur
.
VoteResult
.
ApproveVotes
+=
vtCouts
}
else
{
cur
.
VoteResult
.
OpposeVotes
+=
int32
(
account
.
Balance
/
ticketPrice
)
cur
.
VoteResult
.
OpposeVotes
+=
vtCouts
}
var
logs
[]
*
types
.
ReceiptLog
...
...
@@ -198,8 +197,8 @@ func (a *action) votePropRule(voteProb *auty.VoteProposalRule) (*types.Receipt,
if
cur
.
VoteResult
.
TotalVotes
!=
0
&&
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
!=
0
&&
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
/
float32
(
cur
.
VoteResult
.
TotalVotes
)
>
=
float32
(
pubAttendRatio
)
/
100.0
&&
float32
(
cur
.
VoteResult
.
ApproveVotes
)
/
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
>
=
float32
(
pubApproveRatio
)
/
100.0
{
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
/
float32
(
cur
.
VoteResult
.
TotalVotes
)
>
float32
(
pubAttendRatio
)
/
100.0
&&
float32
(
cur
.
VoteResult
.
ApproveVotes
)
/
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
>
float32
(
pubApproveRatio
)
/
100.0
{
cur
.
VoteResult
.
Pass
=
true
cur
.
PropRule
.
RealEndBlockHeight
=
a
.
height
}
...
...
@@ -259,16 +258,15 @@ func (a *action) tmintPropRule(tmintProb *auty.TerminateProposalRule) (*types.Re
}
if
cur
.
GetVoteResult
()
.
TotalVotes
==
0
{
//需要统计票数
addr
:=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
account
,
err
:=
a
.
getStartHeightVoteAccount
(
addr
,
start
)
vtCouts
,
err
:=
a
.
getTotalVotes
(
start
)
if
err
!=
nil
{
return
nil
,
err
}
cur
.
VoteResult
.
TotalVotes
=
int32
(
account
.
Balance
/
ticketPrice
)
cur
.
VoteResult
.
TotalVotes
=
vtCouts
}
if
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
/
float32
(
cur
.
VoteResult
.
TotalVotes
)
>
=
float32
(
pubAttendRatio
)
/
100.0
&&
float32
(
cur
.
VoteResult
.
ApproveVotes
)
/
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
>
=
float32
(
pubApproveRatio
)
/
100.0
{
if
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
/
float32
(
cur
.
VoteResult
.
TotalVotes
)
>
float32
(
pubAttendRatio
)
/
100.0
&&
float32
(
cur
.
VoteResult
.
ApproveVotes
)
/
float32
(
cur
.
VoteResult
.
ApproveVotes
+
cur
.
VoteResult
.
OpposeVotes
)
>
float32
(
pubApproveRatio
)
/
100.0
{
cur
.
VoteResult
.
Pass
=
true
}
else
{
cur
.
VoteResult
.
Pass
=
false
...
...
plugin/dapp/autonomy/executor/ruleaction_test.go
View file @
2dc66974
...
...
@@ -204,7 +204,7 @@ func voteProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB d
acc
=
&
types
.
Account
{
Currency
:
0
,
Balance
:
total
,
Frozen
:
total
,
}
val1
:=
types
.
Encode
(
acc
)
values1
:=
[][]
byte
{
val1
}
...
...
@@ -219,9 +219,9 @@ func voteProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB d
}
records
:=
[]
record
{
{
PrivKeyA
,
false
},
{
PrivKeyB
,
fals
e
},
{
PrivKeyB
,
tru
e
},
{
PrivKeyC
,
true
},
{
PrivKeyD
,
true
},
//
{PrivKeyD, true},
}
for
_
,
record
:=
range
records
{
...
...
@@ -261,7 +261,7 @@ func voteProposalRule(t *testing.T, env *ExecEnv, exec drivers.Driver, stateDB d
// 每次需要重新设置
acc
:=
&
types
.
Account
{
Currency
:
0
,
Balance
:
total
,
Frozen
:
total
,
}
val
:=
types
.
Encode
(
acc
)
values
:=
[][]
byte
{
val
}
...
...
plugin/dapp/autonomy/types/const.go
View file @
2dc66974
...
...
@@ -93,4 +93,6 @@ const (
var
(
AutonomyX
=
"autonomy"
ExecerAutonomy
=
[]
byte
(
AutonomyX
)
// TicketX 该模块需要查询ticket合约下的账户余额
TicketX
=
"ticket"
)
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