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
Registry
Registry
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
af0be445
Commit
af0be445
authored
Oct 09, 2019
by
liuyuhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify dapp consense global config
parent
8e521d5c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
70 changed files
with
637 additions
and
443 deletions
+637
-443
dpos.go
plugin/consensus/dpos/dpos.go
+13
-8
state_machine.go
plugin/consensus/dpos/state_machine.go
+6
-4
block.go
plugin/consensus/raft/block.go
+4
-4
tendermint.go
plugin/consensus/tendermint/tendermint.go
+7
-3
ticket.go
plugin/consensus/ticket/ticket.go
+27
-18
action.go
plugin/dapp/blackwhite/executor/action.go
+11
-5
rpc.go
plugin/dapp/blackwhite/rpc/rpc.go
+8
-4
echo.go
plugin/dapp/echo/types/echo/echo.go
+5
-4
evm.go
plugin/dapp/evm/executor/evm.go
+3
-2
exec.go
plugin/dapp/evm/executor/exec.go
+10
-9
address.go
plugin/dapp/evm/executor/vm/common/address.go
+2
-2
evm.go
plugin/dapp/evm/executor/vm/runtime/evm.go
+4
-4
account.go
plugin/dapp/evm/executor/vm/state/account.go
+8
-4
fork.go
plugin/dapp/evm/executor/vm/state/fork.go
+3
-3
snapshot.go
plugin/dapp/evm/executor/vm/state/snapshot.go
+2
-1
statedb.go
plugin/dapp/evm/executor/vm/state/statedb.go
+14
-6
rpc.go
plugin/dapp/evm/rpc/rpc.go
+10
-7
gamedb.go
plugin/dapp/game/executor/gamedb.go
+19
-15
query.go
plugin/dapp/game/executor/query.go
+2
-1
guess.go
plugin/dapp/guess/executor/guess.go
+8
-7
types.go
plugin/dapp/guess/types/types.go
+12
-3
hashlockdb.go
plugin/dapp/hashlock/executor/hashlockdb.go
+5
-2
exec.go
plugin/dapp/js/executor/exec.go
+4
-2
js.go
plugin/dapp/js/executor/js.go
+6
-3
key.go
plugin/dapp/js/executor/key.go
+2
-2
table.go
plugin/dapp/js/executor/table.go
+3
-2
lotterydb.go
plugin/dapp/lottery/executor/lotterydb.go
+14
-8
rpc.go
plugin/dapp/multisig/rpc/rpc.go
+12
-7
multisig.go
plugin/dapp/multisig/wallet/multisig.go
+5
-5
norm.go
plugin/dapp/norm/types/norm.go
+2
-2
action.go
plugin/dapp/paracross/executor/action.go
+0
-0
asset.go
plugin/dapp/paracross/executor/asset.go
+8
-6
exec.go
plugin/dapp/paracross/executor/exec.go
+2
-1
exec_del_local.go
plugin/dapp/paracross/executor/exec_del_local.go
+4
-2
exec_local.go
plugin/dapp/paracross/executor/exec_local.go
+15
-12
filtertxs.go
plugin/dapp/paracross/executor/filtertxs.go
+5
-5
query.go
plugin/dapp/paracross/executor/query.go
+13
-7
reward.go
plugin/dapp/paracross/executor/reward.go
+4
-3
superaccount.go
plugin/dapp/paracross/executor/superaccount.go
+37
-27
rpc.go
plugin/dapp/paracross/rpc/rpc.go
+28
-16
exec.go
plugin/dapp/privacy/wallet/exec.go
+2
-1
privacy.go
plugin/dapp/privacy/wallet/privacy.go
+24
-20
relay.go
plugin/dapp/relay/executor/relay.go
+0
-1
relaydb.go
plugin/dapp/relay/executor/relaydb.go
+5
-1
rpc.go
plugin/dapp/relay/rpc/rpc.go
+20
-15
exec_del_local.go
plugin/dapp/retrieve/executor/exec_del_local.go
+3
-3
exec_local.go
plugin/dapp/retrieve/executor/exec_local.go
+3
-2
retrievedb.go
plugin/dapp/retrieve/executor/retrievedb.go
+9
-5
rpc.go
plugin/dapp/retrieve/rpc/rpc.go
+8
-4
ticketdb.go
plugin/dapp/ticket/executor/ticketdb.go
+30
-24
ticketnum.go
plugin/dapp/ticket/executor/ticketnum.go
+2
-1
rpc.go
plugin/dapp/ticket/rpc/rpc.go
+5
-4
ticket.go
plugin/dapp/ticket/types/ticket.go
+2
-2
ticket.go
plugin/dapp/ticket/wallet/ticket.go
+10
-5
exec.go
plugin/dapp/token/executor/exec.go
+2
-1
token.go
plugin/dapp/token/executor/token.go
+0
-1
tokendb.go
plugin/dapp/token/executor/tokendb.go
+26
-21
transwithdraw.go
plugin/dapp/token/executor/transwithdraw.go
+3
-2
rpc.go
plugin/dapp/token/rpc/rpc.go
+12
-6
query.go
plugin/dapp/trade/executor/query.go
+6
-4
tradedb.go
plugin/dapp/trade/executor/tradedb.go
+29
-19
util.go
plugin/dapp/trade/executor/util.go
+13
-13
rpc.go
plugin/dapp/trade/rpc/rpc.go
+12
-6
trade.go
plugin/dapp/trade/types/trade.go
+19
-18
exec.go
plugin/dapp/unfreeze/executor/exec.go
+11
-6
means.go
plugin/dapp/unfreeze/executor/means.go
+2
-2
query.go
plugin/dapp/unfreeze/executor/query.go
+6
-5
rpc.go
plugin/dapp/unfreeze/rpc/rpc.go
+6
-3
types.go
plugin/dapp/unfreeze/types/types.go
+20
-17
valnode.go
plugin/dapp/valnode/types/valnode.go
+0
-5
No files found.
plugin/consensus/dpos/dpos.go
View file @
af0be445
...
...
@@ -436,13 +436,14 @@ func (client *Client) ProcEvent(msg *queue.Message) bool {
// CreateBlock a routine monitor whether some transactions available and tell client by available channel
func
(
client
*
Client
)
CreateBlock
()
{
lastBlock
:=
client
.
GetCurrentBlock
()
txs
:=
client
.
RequestTx
(
int
(
types
.
GetP
(
lastBlock
.
Height
+
1
)
.
MaxTxNumber
),
nil
)
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
txs
:=
client
.
RequestTx
(
int
(
cfg
.
GetP
(
lastBlock
.
Height
+
1
)
.
MaxTxNumber
),
nil
)
if
len
(
txs
)
==
0
{
block
:=
client
.
GetCurrentBlock
()
if
createEmptyBlocks
{
emptyBlock
:=
&
types
.
Block
{}
emptyBlock
.
StateHash
=
block
.
StateHash
emptyBlock
.
ParentHash
=
block
.
Hash
()
emptyBlock
.
ParentHash
=
block
.
Hash
(
cfg
)
emptyBlock
.
Height
=
block
.
Height
+
1
emptyBlock
.
Txs
=
nil
emptyBlock
.
TxHash
=
zeroHash
[
:
]
...
...
@@ -461,11 +462,11 @@ func (client *Client) CreateBlock() {
//check dup
txs
=
client
.
CheckTxDup
(
txs
,
client
.
GetCurrentHeight
())
var
newblock
types
.
Block
newblock
.
ParentHash
=
lastBlock
.
Hash
()
newblock
.
ParentHash
=
lastBlock
.
Hash
(
cfg
)
newblock
.
Height
=
lastBlock
.
Height
+
1
client
.
AddTxsToBlock
(
&
newblock
,
txs
)
//
newblock
.
Difficulty
=
types
.
GetP
(
0
)
.
PowLimitBits
newblock
.
Difficulty
=
cfg
.
GetP
(
0
)
.
PowLimitBits
newblock
.
TxHash
=
merkle
.
CalcMerkleRoot
(
newblock
.
Txs
)
newblock
.
BlockTime
=
client
.
blockTime
...
...
@@ -580,7 +581,8 @@ func (client *Client) CreateRecordCBTx(info *dty.DposCBInfo) (tx *types.Transact
RecordCB
:
info
,
}
action
.
Ty
=
dty
.
DposVoteActionRecordCB
tx
,
err
=
types
.
CreateFormatTx
(
"dpos"
,
types
.
Encode
(
&
action
))
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
tx
,
err
=
types
.
CreateFormatTx
(
cfg
,
"dpos"
,
types
.
Encode
(
&
action
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -595,7 +597,8 @@ func (client *Client) CreateRegVrfMTx(info *dty.DposVrfMRegist) (tx *types.Trans
RegistVrfM
:
info
,
}
action
.
Ty
=
dty
.
DposVoteActionRegistVrfM
tx
,
err
=
types
.
CreateFormatTx
(
"dpos"
,
types
.
Encode
(
&
action
))
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
tx
,
err
=
types
.
CreateFormatTx
(
cfg
,
"dpos"
,
types
.
Encode
(
&
action
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -610,7 +613,8 @@ func (client *Client) CreateRegVrfRPTx(info *dty.DposVrfRPRegist) (tx *types.Tra
RegistVrfRP
:
info
,
}
action
.
Ty
=
dty
.
DposVoteActionRegistVrfRP
tx
,
err
=
types
.
CreateFormatTx
(
"dpos"
,
types
.
Encode
(
&
action
))
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
tx
,
err
=
types
.
CreateFormatTx
(
cfg
,
"dpos"
,
types
.
Encode
(
&
action
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -708,7 +712,8 @@ func (client *Client) CreateTopNRegistTx(reg *dty.TopNCandidatorRegist) (tx *typ
RegistTopN
:
reg
,
}
action
.
Ty
=
dty
.
DPosVoteActionRegistTopNCandidator
tx
,
err
=
types
.
CreateFormatTx
(
"dpos"
,
types
.
Encode
(
&
action
))
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
tx
,
err
=
types
.
CreateFormatTx
(
cfg
,
"dpos"
,
types
.
Encode
(
&
action
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/consensus/dpos/state_machine.go
View file @
af0be445
...
...
@@ -572,6 +572,7 @@ func (voted *VotedState) timeOut(cs *ConsensusState) {
now
:=
time
.
Now
()
.
Unix
()
block
:=
cs
.
client
.
GetCurrentBlock
()
task
:=
DecideTaskByTime
(
now
)
cfg
:=
cs
.
client
.
GetAPI
()
.
GetConfig
()
dposlog
.
Info
(
"address info"
,
"privValidatorAddr"
,
hex
.
EncodeToString
(
cs
.
privValidator
.
GetAddress
()),
"VotedNodeAddress"
,
hex
.
EncodeToString
(
cs
.
currentVote
.
VotedNodeAddress
))
if
bytes
.
Equal
(
cs
.
privValidator
.
GetAddress
(),
cs
.
currentVote
.
VotedNodeAddress
)
{
...
...
@@ -598,7 +599,7 @@ func (voted *VotedState) timeOut(cs *ConsensusState) {
info
:=
&
dty
.
DposCBInfo
{
Cycle
:
cs
.
currentVote
.
Cycle
,
StopHeight
:
block
.
Height
,
StopHash
:
hex
.
EncodeToString
(
block
.
Hash
()),
StopHash
:
hex
.
EncodeToString
(
block
.
Hash
(
cfg
)),
Pubkey
:
strings
.
ToUpper
(
hex
.
EncodeToString
(
cs
.
privValidator
.
GetPubKey
()
.
Bytes
())),
}
...
...
@@ -622,7 +623,7 @@ func (voted *VotedState) timeOut(cs *ConsensusState) {
DPosNotify
:
&
dpostype
.
DPosNotify
{
Vote
:
cs
.
currentVote
,
HeightStop
:
block
.
Height
,
HashStop
:
block
.
Hash
(),
HashStop
:
block
.
Hash
(
cfg
),
NotifyTimestamp
:
now
,
NotifyNodeAddress
:
cs
.
privValidator
.
GetAddress
(),
NotifyNodeIndex
:
int32
(
cs
.
privValidatorIndex
),
...
...
@@ -833,6 +834,7 @@ func (wait *WaitNofifyState) sendNotify(cs *ConsensusState, notify *dpostype.DPo
func
(
wait
*
WaitNofifyState
)
recvNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
dposlog
.
Info
(
"WaitNofifyState recvNotify"
)
cfg
:=
cs
.
client
.
GetAPI
()
.
GetConfig
()
//记录Notify,校验区块,标记不可逆区块高度
if
!
cs
.
VerifyNotify
(
notify
)
{
dposlog
.
Info
(
"VotedState verify notify failed"
)
...
...
@@ -843,7 +845,7 @@ func (wait *WaitNofifyState) recvNotify(cs *ConsensusState, notify *dpostype.DPo
if
block
.
Height
>
notify
.
HeightStop
{
dposlog
.
Info
(
"Local block height is advanced than notify, discard it."
,
"localheight"
,
block
.
Height
,
"notify"
,
printNotify
(
notify
))
return
}
else
if
block
.
Height
==
notify
.
HeightStop
&&
bytes
.
Equal
(
block
.
Hash
(),
notify
.
HashStop
)
{
}
else
if
block
.
Height
==
notify
.
HeightStop
&&
bytes
.
Equal
(
block
.
Hash
(
cfg
),
notify
.
HashStop
)
{
dposlog
.
Info
(
"Local block height is sync with notify"
,
"notify"
,
printNotify
(
notify
))
}
else
{
dposlog
.
Info
(
"Local block height is not sync with notify"
,
"localheight"
,
cs
.
client
.
GetCurrentHeight
(),
"notify"
,
printNotify
(
notify
))
...
...
@@ -856,7 +858,7 @@ func (wait *WaitNofifyState) recvNotify(cs *ConsensusState, notify *dpostype.DPo
case
<-
hint
.
C
:
dposlog
.
Info
(
"Still catching up max height......"
,
"Height"
,
cs
.
client
.
GetCurrentHeight
(),
"notifyHeight"
,
notify
.
HeightStop
,
"cost"
,
time
.
Since
(
beg
))
if
cs
.
client
.
IsCaughtUp
()
&&
cs
.
client
.
GetCurrentHeight
()
>=
notify
.
HeightStop
{
dposlog
.
Info
(
"This node has caught up max height"
,
"Height"
,
cs
.
client
.
GetCurrentHeight
(),
"isHashSame"
,
bytes
.
Equal
(
block
.
Hash
(),
notify
.
HashStop
))
dposlog
.
Info
(
"This node has caught up max height"
,
"Height"
,
cs
.
client
.
GetCurrentHeight
(),
"isHashSame"
,
bytes
.
Equal
(
block
.
Hash
(
cfg
),
notify
.
HashStop
))
break
OuterLoop
}
...
...
plugin/consensus/raft/block.go
View file @
af0be445
...
...
@@ -112,7 +112,7 @@ func (client *Client) CreateBlock() {
retry
:=
0
infoflag
:=
0
count
:=
0
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
//打包区块前先同步到最大高度
for
{
if
client
.
IsCaughtUp
()
{
...
...
@@ -147,7 +147,7 @@ func (client *Client) CreateBlock() {
block
:=
client
.
GetCurrentBlock
()
emptyBlock
:=
&
types
.
Block
{}
emptyBlock
.
StateHash
=
block
.
StateHash
emptyBlock
.
ParentHash
=
block
.
Hash
()
emptyBlock
.
ParentHash
=
block
.
Hash
(
cfg
)
emptyBlock
.
Height
=
block
.
Height
+
1
emptyBlock
.
Txs
=
nil
emptyBlock
.
TxHash
=
zeroHash
[
:
]
...
...
@@ -166,7 +166,7 @@ func (client *Client) CreateBlock() {
}
lastBlock
:=
client
.
GetCurrentBlock
()
txs
:=
client
.
RequestTx
(
int
(
types
.
GetP
(
lastBlock
.
Height
+
1
)
.
MaxTxNumber
),
nil
)
txs
:=
client
.
RequestTx
(
int
(
cfg
.
GetP
(
lastBlock
.
Height
+
1
)
.
MaxTxNumber
),
nil
)
if
len
(
txs
)
==
0
{
issleep
=
true
continue
...
...
@@ -175,7 +175,7 @@ func (client *Client) CreateBlock() {
count
=
0
rlog
.
Debug
(
"==================start create new block!====================="
)
var
newblock
types
.
Block
newblock
.
ParentHash
=
lastBlock
.
Hash
()
newblock
.
ParentHash
=
lastBlock
.
Hash
(
cfg
)
newblock
.
Height
=
lastBlock
.
Height
+
1
client
.
AddTxsToBlock
(
&
newblock
,
txs
)
newblock
.
TxHash
=
merkle
.
CalcMerkleRoot
(
newblock
.
Txs
)
...
...
plugin/consensus/tendermint/tendermint.go
View file @
af0be445
...
...
@@ -419,7 +419,8 @@ func (client *Client) CheckTxDup(txs []*types.Transaction, height int64) (transa
// BuildBlock build a new block contains some transactions
func
(
client
*
Client
)
BuildBlock
()
*
types
.
Block
{
lastHeight
:=
client
.
GetCurrentHeight
()
txs
:=
client
.
RequestTx
(
int
(
types
.
GetP
(
lastHeight
+
1
)
.
MaxTxNumber
)
-
1
,
nil
)
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
txs
:=
client
.
RequestTx
(
int
(
cfg
.
GetP
(
lastHeight
+
1
)
.
MaxTxNumber
)
-
1
,
nil
)
newblock
:=
&
types
.
Block
{}
newblock
.
Height
=
lastHeight
+
1
client
.
AddTxsToBlock
(
newblock
,
txs
)
...
...
@@ -434,13 +435,16 @@ func (client *Client) CommitBlock(propBlock *types.Block) error {
tendermintlog
.
Error
(
"RequestBlock fail"
,
"err"
,
err
)
return
err
}
newblock
.
ParentHash
=
lastBlock
.
Hash
()
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
newblock
.
ParentHash
=
lastBlock
.
Hash
(
cfg
)
newblock
.
TxHash
=
merkle
.
CalcMerkleRoot
(
newblock
.
Txs
)
newblock
.
BlockTime
=
time
.
Now
()
.
Unix
()
if
lastBlock
.
BlockTime
>=
newblock
.
BlockTime
{
newblock
.
BlockTime
=
lastBlock
.
BlockTime
+
1
}
newblock
.
Difficulty
=
types
.
GetP
(
0
)
.
PowLimitBits
newblock
.
Difficulty
=
cfg
.
GetP
(
0
)
.
PowLimitBits
err
=
client
.
WriteBlock
(
lastBlock
.
StateHash
,
&
newblock
)
if
err
!=
nil
{
...
...
plugin/consensus/ticket/ticket.go
View file @
af0be445
...
...
@@ -109,15 +109,16 @@ func (client *Client) Close() {
// CreateGenesisTx ticket create genesis tx
func
(
client
*
Client
)
CreateGenesisTx
()
(
ret
[]
*
types
.
Transaction
)
{
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
for
_
,
genesis
:=
range
client
.
subcfg
.
Genesis
{
tx1
:=
createTicket
(
genesis
.
MinerAddr
,
genesis
.
ReturnAddr
,
genesis
.
Count
,
0
)
tx1
:=
createTicket
(
cfg
,
genesis
.
MinerAddr
,
genesis
.
ReturnAddr
,
genesis
.
Count
,
0
)
ret
=
append
(
ret
,
tx1
...
)
}
return
ret
}
//316190000 coins
func
createTicket
(
minerAddr
,
returnAddr
string
,
count
int32
,
height
int64
)
(
ret
[]
*
types
.
Transaction
)
{
func
createTicket
(
cfg
*
types
.
Chain33Config
,
minerAddr
,
returnAddr
string
,
count
int32
,
height
int64
)
(
ret
[]
*
types
.
Transaction
)
{
tx1
:=
types
.
Transaction
{}
tx1
.
Execer
=
[]
byte
(
"coins"
)
...
...
@@ -125,7 +126,7 @@ func createTicket(minerAddr, returnAddr string, count int32, height int64) (ret
tx1
.
To
=
minerAddr
//gen payload
g
:=
&
cty
.
CoinsAction_Genesis
{}
g
.
Genesis
=
&
types
.
AssetsGenesis
{
Amount
:
ty
.
GetTicketMinerParam
(
height
)
.
TicketPrice
}
g
.
Genesis
=
&
types
.
AssetsGenesis
{
Amount
:
ty
.
GetTicketMinerParam
(
cfg
,
height
)
.
TicketPrice
}
tx1
.
Payload
=
types
.
Encode
(
&
cty
.
CoinsAction
{
Value
:
g
,
Ty
:
cty
.
CoinsActionGenesis
})
ret
=
append
(
ret
,
&
tx1
)
...
...
@@ -135,7 +136,7 @@ func createTicket(minerAddr, returnAddr string, count int32, height int64) (ret
tx2
.
To
=
driver
.
ExecAddress
(
"ticket"
)
//gen payload
g
=
&
cty
.
CoinsAction_Genesis
{}
g
.
Genesis
=
&
types
.
AssetsGenesis
{
Amount
:
int64
(
count
)
*
ty
.
GetTicketMinerParam
(
height
)
.
TicketPrice
,
ReturnAddress
:
returnAddr
}
g
.
Genesis
=
&
types
.
AssetsGenesis
{
Amount
:
int64
(
count
)
*
ty
.
GetTicketMinerParam
(
cfg
,
height
)
.
TicketPrice
,
ReturnAddress
:
returnAddr
}
tx2
.
Payload
=
types
.
Encode
(
&
cty
.
CoinsAction
{
Value
:
g
,
Ty
:
cty
.
CoinsActionGenesis
})
ret
=
append
(
ret
,
&
tx2
)
...
...
@@ -307,7 +308,8 @@ func (client *Client) getModify(beg, end int64) ([]byte, error) {
// CheckBlock ticket implete checkblock func
func
(
client
*
Client
)
CheckBlock
(
parent
*
types
.
Block
,
current
*
types
.
BlockDetail
)
error
{
cfg
:=
ty
.
GetTicketMinerParam
(
current
.
Block
.
Height
)
chain33Cfg
:=
client
.
GetAPI
()
.
GetConfig
()
cfg
:=
ty
.
GetTicketMinerParam
(
chain33Cfg
,
current
.
Block
.
Height
)
if
current
.
Block
.
BlockTime
-
types
.
Now
()
.
Unix
()
>
cfg
.
FutureBlockTime
{
return
types
.
ErrFutureBlock
}
...
...
@@ -367,7 +369,7 @@ func (client *Client) CheckBlock(parent *types.Block, current *types.BlockDetail
return
types
.
ErrBlockSize
}
//vrf verify
if
types
.
IsDappFork
(
current
.
Block
.
Height
,
ty
.
TicketX
,
"ForkTicketVrf"
)
{
if
chain33Cfg
.
IsDappFork
(
current
.
Block
.
Height
,
ty
.
TicketX
,
"ForkTicketVrf"
)
{
var
input
[]
byte
if
current
.
Block
.
Height
>
1
{
LastTicketAction
,
err
:=
client
.
getMinerTx
(
parent
)
...
...
@@ -413,8 +415,9 @@ func vrfVerify(pub []byte, input []byte, proof []byte, hash []byte) error {
}
func
(
client
*
Client
)
getNextTarget
(
block
*
types
.
Block
,
bits
uint32
)
(
*
big
.
Int
,
[]
byte
,
error
)
{
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
if
block
.
Height
==
0
{
powLimit
:=
difficulty
.
CompactToBig
(
types
.
GetP
(
0
)
.
PowLimitBits
)
powLimit
:=
difficulty
.
CompactToBig
(
cfg
.
GetP
(
0
)
.
PowLimitBits
)
return
powLimit
,
defaultModify
,
nil
}
targetBits
,
modify
,
err
:=
client
.
getNextRequiredDifficulty
(
block
,
bits
)
...
...
@@ -440,12 +443,13 @@ func (client *Client) getCurrentTarget(blocktime int64, id string, modify []byte
// the exported version uses the current best chain as the previous block node
// while this function accepts any block node.
func
(
client
*
Client
)
getNextRequiredDifficulty
(
block
*
types
.
Block
,
bits
uint32
)
(
uint32
,
[]
byte
,
error
)
{
chain33Cfg
:=
client
.
GetAPI
()
.
GetConfig
()
// Genesis block.
if
block
==
nil
{
return
types
.
GetP
(
0
)
.
PowLimitBits
,
defaultModify
,
nil
return
chain33Cfg
.
GetP
(
0
)
.
PowLimitBits
,
defaultModify
,
nil
}
powLimitBits
:=
types
.
GetP
(
block
.
Height
)
.
PowLimitBits
cfg
:=
ty
.
GetTicketMinerParam
(
block
.
Height
)
powLimitBits
:=
chain33Cfg
.
GetP
(
block
.
Height
)
.
PowLimitBits
cfg
:=
ty
.
GetTicketMinerParam
(
chain33Cfg
,
block
.
Height
)
blocksPerRetarget
:=
int64
(
cfg
.
TargetTimespan
/
cfg
.
TargetTimePerBlock
)
// Return the previous block's difficulty requirements if this block
// is not at a difficulty retarget interval.
...
...
@@ -527,6 +531,7 @@ func printBInt(data *big.Int) string {
}
func
(
client
*
Client
)
searchTargetTicket
(
parent
,
block
*
types
.
Block
)
(
*
ty
.
Ticket
,
crypto
.
PrivKey
,
*
big
.
Int
,
[]
byte
,
string
,
error
)
{
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
bits
:=
parent
.
Difficulty
diff
,
modify
,
err
:=
client
.
getNextTarget
(
parent
,
bits
)
if
err
!=
nil
{
...
...
@@ -543,7 +548,7 @@ func (client *Client) searchTargetTicket(parent, block *types.Block) (*ty.Ticket
continue
}
//已经到成熟期
if
!
ticket
.
GetIsGenesis
()
&&
(
block
.
BlockTime
-
ticket
.
GetCreateTime
()
<=
ty
.
GetTicketMinerParam
(
block
.
Height
)
.
TicketFrozenTime
)
{
if
!
ticket
.
GetIsGenesis
()
&&
(
block
.
BlockTime
-
ticket
.
GetCreateTime
()
<=
ty
.
GetTicketMinerParam
(
cfg
,
block
.
Height
)
.
TicketFrozenTime
)
{
continue
}
// 查找私钥
...
...
@@ -632,6 +637,7 @@ func genPrivHash(priv crypto.PrivKey, tid string) ([]byte, error) {
func
(
client
*
Client
)
addMinerTx
(
parent
,
block
*
types
.
Block
,
diff
*
big
.
Int
,
priv
crypto
.
PrivKey
,
tid
string
,
modify
[]
byte
)
error
{
//return 0 always
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
fee
:=
calcTotalFee
(
block
)
var
ticketAction
ty
.
TicketAction
...
...
@@ -639,14 +645,14 @@ func (client *Client) addMinerTx(parent, block *types.Block, diff *big.Int, priv
miner
.
TicketId
=
tid
miner
.
Bits
=
difficulty
.
BigToCompact
(
diff
)
miner
.
Modify
=
modify
miner
.
Reward
=
ty
.
GetTicketMinerParam
(
block
.
Height
)
.
CoinReward
+
fee
miner
.
Reward
=
ty
.
GetTicketMinerParam
(
cfg
,
block
.
Height
)
.
CoinReward
+
fee
privHash
,
err
:=
genPrivHash
(
priv
,
tid
)
if
err
!=
nil
{
return
err
}
miner
.
PrivHash
=
privHash
//add vrf
if
types
.
IsDappFork
(
block
.
Height
,
ty
.
TicketX
,
"ForkTicketVrf"
)
{
if
cfg
.
IsDappFork
(
block
.
Height
,
ty
.
TicketX
,
"ForkTicketVrf"
)
{
var
input
[]
byte
if
block
.
Height
>
1
{
LastTicketAction
,
err
:=
client
.
getMinerTx
(
parent
)
...
...
@@ -686,7 +692,8 @@ func (client *Client) addMinerTx(parent, block *types.Block, diff *big.Int, priv
}
func
(
client
*
Client
)
createMinerTx
(
ticketAction
proto
.
Message
,
priv
crypto
.
PrivKey
)
*
types
.
Transaction
{
tx
,
err
:=
types
.
CreateFormatTx
(
"ticket"
,
types
.
Encode
(
ticketAction
))
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
tx
,
err
:=
types
.
CreateFormatTx
(
cfg
,
"ticket"
,
types
.
Encode
(
ticketAction
))
if
err
!=
nil
{
return
nil
}
...
...
@@ -695,20 +702,22 @@ func (client *Client) createMinerTx(ticketAction proto.Message, priv crypto.Priv
}
func
(
client
*
Client
)
createBlock
()
(
*
types
.
Block
,
*
types
.
Block
)
{
cfg
:=
client
.
GetAPI
()
.
GetConfig
()
lastBlock
:=
client
.
GetCurrentBlock
()
var
newblock
types
.
Block
newblock
.
ParentHash
=
lastBlock
.
Hash
()
newblock
.
ParentHash
=
lastBlock
.
Hash
(
cfg
)
newblock
.
Height
=
lastBlock
.
Height
+
1
newblock
.
BlockTime
=
types
.
Now
()
.
Unix
()
if
lastBlock
.
BlockTime
>=
newblock
.
BlockTime
{
newblock
.
BlockTime
=
lastBlock
.
BlockTime
}
txs
:=
client
.
RequestTx
(
int
(
types
.
GetP
(
newblock
.
Height
)
.
MaxTxNumber
)
-
1
,
nil
)
txs
:=
client
.
RequestTx
(
int
(
cfg
.
GetP
(
newblock
.
Height
)
.
MaxTxNumber
)
-
1
,
nil
)
client
.
AddTxsToBlock
(
&
newblock
,
txs
)
return
&
newblock
,
lastBlock
}
func
(
client
*
Client
)
updateBlock
(
block
*
types
.
Block
,
txHashList
[][]
byte
)
(
*
types
.
Block
,
*
types
.
Block
,
[][]
byte
)
{
chain33Cfg
:=
client
.
GetAPI
()
.
GetConfig
()
lastBlock
:=
client
.
GetCurrentBlock
()
newblock
:=
*
block
newblock
.
BlockTime
=
types
.
Now
()
.
Unix
()
...
...
@@ -718,9 +727,9 @@ func (client *Client) updateBlock(block *types.Block, txHashList [][]byte) (*typ
newblock
.
Txs
=
client
.
CheckTxDup
(
newblock
.
Txs
)
newblock
.
Txs
=
client
.
CheckTxExpire
(
newblock
.
Txs
,
lastBlock
.
Height
+
1
,
newblock
.
BlockTime
)
}
newblock
.
ParentHash
=
lastBlock
.
Hash
()
newblock
.
ParentHash
=
lastBlock
.
Hash
(
chain33Cfg
)
newblock
.
Height
=
lastBlock
.
Height
+
1
cfg
:=
types
.
GetP
(
newblock
.
Height
)
cfg
:=
chain33Cfg
.
GetP
(
newblock
.
Height
)
var
txs
[]
*
types
.
Transaction
if
len
(
newblock
.
Txs
)
<
int
(
cfg
.
MaxTxNumber
-
1
)
{
txs
=
client
.
RequestTx
(
int
(
cfg
.
MaxTxNumber
)
-
1
-
len
(
newblock
.
Txs
),
txHashList
)
...
...
plugin/dapp/blackwhite/executor/action.go
View file @
af0be445
...
...
@@ -16,6 +16,7 @@ import (
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
gt
"github.com/33cn/plugin/plugin/dapp/blackwhite/types"
"github.com/33cn/chain33/client"
)
const
(
...
...
@@ -41,6 +42,7 @@ type action struct {
height
int64
index
int32
execaddr
string
api
client
.
QueueProtocolAPI
}
type
resultCalc
struct
{
...
...
@@ -59,7 +61,7 @@ func newAction(t *Blackwhite, tx *types.Transaction, index int32) *action {
hash
:=
tx
.
Hash
()
fromaddr
:=
tx
.
From
()
return
&
action
{
t
.
GetCoinsAccount
(),
t
.
GetStateDB
(),
hash
,
fromaddr
,
t
.
GetBlockTime
(),
t
.
GetHeight
(),
index
,
dapp
.
ExecAddress
(
string
(
tx
.
Execer
))}
t
.
GetBlockTime
(),
t
.
GetHeight
(),
index
,
dapp
.
ExecAddress
(
string
(
tx
.
Execer
))
,
t
.
GetAPI
()
}
}
func
(
a
*
action
)
Create
(
create
*
gt
.
BlackwhiteCreate
)
(
*
types
.
Receipt
,
error
)
{
...
...
@@ -180,7 +182,8 @@ func (a *action) Play(play *gt.BlackwhitePlay) (*types.Receipt, error) {
key1
:=
calcMavlRoundKey
(
round
.
GameID
)
value1
:=
types
.
Encode
(
&
round
)
if
types
.
IsDappFork
(
a
.
height
,
gt
.
BlackwhiteX
,
"ForkBlackWhiteV2"
)
{
cfg
:=
a
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
a
.
height
,
gt
.
BlackwhiteX
,
"ForkBlackWhiteV2"
)
{
//将当前游戏状态保存,便于同一区块中游戏参数的累加
a
.
db
.
Set
(
key1
,
value1
)
}
...
...
@@ -264,7 +267,8 @@ func (a *action) Show(show *gt.BlackwhiteShow) (*types.Receipt, error) {
key1
:=
calcMavlRoundKey
(
round
.
GameID
)
value1
:=
types
.
Encode
(
&
round
)
if
types
.
IsDappFork
(
a
.
height
,
gt
.
BlackwhiteX
,
"ForkBlackWhiteV2"
)
{
cfg
:=
a
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
a
.
height
,
gt
.
BlackwhiteX
,
"ForkBlackWhiteV2"
)
{
//将当前游戏状态保存,便于同一区块中游戏参数的累加
a
.
db
.
Set
(
key1
,
value1
)
}
...
...
@@ -360,7 +364,8 @@ func (a *action) TimeoutDone(done *gt.BlackwhiteTimeoutDone) (*types.Receipt, er
key1
:=
calcMavlRoundKey
(
round
.
GameID
)
value1
:=
types
.
Encode
(
&
round
)
if
types
.
IsDappFork
(
a
.
height
,
gt
.
BlackwhiteX
,
"ForkBlackWhiteV2"
)
{
cfg
:=
a
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
a
.
height
,
gt
.
BlackwhiteX
,
"ForkBlackWhiteV2"
)
{
//将当前游戏状态保存,便于同一区块中游戏参数的累加
a
.
db
.
Set
(
key1
,
value1
)
}
...
...
@@ -528,12 +533,13 @@ func (a *action) getWinner(round *gt.BlackwhiteRound) ([]*addrResult, *gt.ReplyL
addrRes
:=
round
.
AddrResult
loop
:=
int
(
round
.
Loop
)
cfg
:=
a
.
api
.
GetConfig
()
for
_
,
address
:=
range
addrRes
{
if
len
(
address
.
ShowSecret
)
>
0
&&
len
(
address
.
HashValues
)
==
loop
{
var
isBlack
[]
bool
// 加入分叉高度判断:分叉高度在ForkV25BlackWhite到ForkV25BlackWhiteV2之间的执行原来逻辑,大于ForkV25BlackWhiteV2执行新逻辑,
// 小于ForkV25BlackWhite则无法进入
if
!
types
.
IsDappFork
(
a
.
height
,
gt
.
BlackwhiteX
,
"ForkBlackWhiteV2"
)
{
if
!
cfg
.
IsDappFork
(
a
.
height
,
gt
.
BlackwhiteX
,
"ForkBlackWhiteV2"
)
{
for
_
,
hash
:=
range
address
.
HashValues
{
if
bytes
.
Equal
(
common
.
Sha256
([]
byte
(
address
.
ShowSecret
+
black
)),
hash
)
{
isBlack
=
append
(
isBlack
,
true
)
...
...
plugin/dapp/blackwhite/rpc/rpc.go
View file @
af0be445
...
...
@@ -19,7 +19,8 @@ func (c *channelClient) Create(ctx context.Context, head *bw.BlackwhiteCreate) (
tx
:=
&
types
.
Transaction
{
Payload
:
types
.
Encode
(
val
),
}
data
,
err
:=
types
.
FormatTxEncode
(
types
.
ExecName
(
string
(
bw
.
ExecerBlackwhite
)),
tx
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
types
.
FormatTxEncode
(
cfg
,
cfg
.
ExecName
(
string
(
bw
.
ExecerBlackwhite
)),
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -34,7 +35,8 @@ func (c *channelClient) Show(ctx context.Context, head *bw.BlackwhiteShow) (*typ
tx
:=
&
types
.
Transaction
{
Payload
:
types
.
Encode
(
val
),
}
data
,
err
:=
types
.
FormatTxEncode
(
types
.
ExecName
(
string
(
bw
.
ExecerBlackwhite
)),
tx
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
types
.
FormatTxEncode
(
cfg
,
cfg
.
ExecName
(
string
(
bw
.
ExecerBlackwhite
)),
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -49,7 +51,8 @@ func (c *channelClient) Play(ctx context.Context, head *bw.BlackwhitePlay) (*typ
tx
:=
&
types
.
Transaction
{
Payload
:
types
.
Encode
(
val
),
}
data
,
err
:=
types
.
FormatTxEncode
(
types
.
ExecName
(
string
(
bw
.
ExecerBlackwhite
)),
tx
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
types
.
FormatTxEncode
(
cfg
,
cfg
.
ExecName
(
string
(
bw
.
ExecerBlackwhite
)),
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -64,7 +67,8 @@ func (c *channelClient) TimeoutDone(ctx context.Context, head *bw.BlackwhiteTime
tx
:=
&
types
.
Transaction
{
Payload
:
types
.
Encode
(
val
),
}
data
,
err
:=
types
.
FormatTxEncode
(
types
.
ExecName
(
string
(
bw
.
ExecerBlackwhite
)),
tx
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
types
.
FormatTxEncode
(
cfg
,
cfg
.
ExecName
(
string
(
bw
.
ExecerBlackwhite
)),
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/dapp/echo/types/echo/echo.go
View file @
af0be445
...
...
@@ -14,6 +14,7 @@ import (
func
(
e
*
Type
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
elog
.
Debug
(
"echo.CreateTx"
,
"action"
,
action
)
// 只接受ping/pang两种交易操作
cfg
:=
e
.
GetConfig
()
if
action
==
"ping"
||
action
==
"pang"
{
var
param
Tx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -21,12 +22,12 @@ func (e *Type) CreateTx(action string, message json.RawMessage) (*types.Transact
elog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
createPingTx
(
action
,
&
param
)
return
createPingTx
(
cfg
,
action
,
&
param
)
}
return
nil
,
types
.
ErrNotSupport
}
func
createPingTx
(
op
string
,
parm
*
Tx
)
(
*
types
.
Transaction
,
error
)
{
func
createPingTx
(
cfg
*
types
.
Chain33Config
,
op
string
,
parm
*
Tx
)
(
*
types
.
Transaction
,
error
)
{
var
action
*
EchoAction
var
err
error
if
strings
.
EqualFold
(
op
,
"ping"
)
{
...
...
@@ -38,10 +39,10 @@ func createPingTx(op string, parm *Tx) (*types.Transaction, error) {
return
nil
,
err
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
EchoX
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
EchoX
)),
Payload
:
types
.
Encode
(
action
),
Nonce
:
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
.
Int63
(),
To
:
address
.
ExecAddress
(
types
.
ExecName
(
EchoX
)),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
EchoX
)),
}
return
tx
,
nil
}
...
...
plugin/dapp/evm/executor/evm.go
View file @
af0be445
...
...
@@ -25,7 +25,7 @@ var (
evmDebug
=
false
// EvmAddress 本合约地址
EvmAddress
=
address
.
ExecAddress
(
types
.
ExecName
(
evmtypes
.
ExecutorName
)
)
EvmAddress
=
address
.
ExecAddress
(
evmtypes
.
ExecutorName
)
)
var
driverName
=
evmtypes
.
ExecutorName
...
...
@@ -137,7 +137,8 @@ func (evm *EVMExecutor) CheckReceiptExecOk() bool {
// 生成一个新的合约对象地址
func
(
evm
*
EVMExecutor
)
getNewAddr
(
txHash
[]
byte
)
common
.
Address
{
return
common
.
NewAddress
(
txHash
)
cfg
:=
evm
.
GetAPI
()
.
GetConfig
()
return
common
.
NewAddress
(
cfg
,
txHash
)
}
// CheckTx 校验交易
...
...
plugin/dapp/evm/executor/exec.go
View file @
af0be445
...
...
@@ -48,6 +48,7 @@ func (evm *EVMExecutor) innerExec(msg *common.Message, txHash []byte, index int,
execName
string
methodName
string
)
cfg
:=
evm
.
GetAPI
()
.
GetConfig
()
// 为了方便计费,即使合约为新生成,也将地址的初始化放到外面操作
if
isCreate
{
...
...
@@ -57,7 +58,7 @@ func (evm *EVMExecutor) innerExec(msg *common.Message, txHash []byte, index int,
return
receipt
,
model
.
ErrContractAddressCollision
}
// 只有新创建的合约才能生成合约名称
execName
=
fmt
.
Sprintf
(
"%s%s"
,
types
.
ExecName
(
evmtypes
.
EvmPrefix
),
common
.
BytesToHash
(
txHash
)
.
Hex
())
execName
=
fmt
.
Sprintf
(
"%s%s"
,
cfg
.
ExecName
(
evmtypes
.
EvmPrefix
),
common
.
BytesToHash
(
txHash
)
.
Hex
())
}
else
{
contractAddr
=
*
msg
.
To
()
}
...
...
@@ -67,17 +68,17 @@ func (evm *EVMExecutor) innerExec(msg *common.Message, txHash []byte, index int,
if
isCreate
{
// 如果携带ABI数据,则对数据合法性进行检查
if
len
(
msg
.
ABI
())
>
0
&&
types
.
IsDappFork
(
evm
.
GetHeight
(),
"evm"
,
evmtypes
.
ForkEVMABI
)
{
if
len
(
msg
.
ABI
())
>
0
&&
cfg
.
IsDappFork
(
evm
.
GetHeight
(),
"evm"
,
evmtypes
.
ForkEVMABI
)
{
_
,
err
=
abi
.
JSON
(
strings
.
NewReader
(
msg
.
ABI
()))
if
err
!=
nil
{
return
receipt
,
err
}
}
ret
,
snapshot
,
leftOverGas
,
vmerr
=
env
.
Create
(
runtime
.
AccountRef
(
msg
.
From
()),
contractAddr
,
msg
.
Data
(),
context
.
GasLimit
,
execName
,
msg
.
Alias
(),
msg
.
ABI
())
ret
,
snapshot
,
leftOverGas
,
vmerr
=
env
.
Create
(
cfg
,
runtime
.
AccountRef
(
msg
.
From
()),
contractAddr
,
msg
.
Data
(),
context
.
GasLimit
,
execName
,
msg
.
Alias
(),
msg
.
ABI
())
}
else
{
inData
:=
msg
.
Data
()
// 在这里进行ABI和十六进制的调用参数转换
if
len
(
msg
.
ABI
())
>
0
&&
types
.
IsDappFork
(
evm
.
GetHeight
(),
"evm"
,
evmtypes
.
ForkEVMABI
)
{
if
len
(
msg
.
ABI
())
>
0
&&
cfg
.
IsDappFork
(
evm
.
GetHeight
(),
"evm"
,
evmtypes
.
ForkEVMABI
)
{
funcName
,
packData
,
err
:=
abi
.
Pack
(
msg
.
ABI
(),
evm
.
mStateDB
.
GetAbi
(
msg
.
To
()
.
String
()),
readOnly
)
if
err
!=
nil
{
return
receipt
,
err
...
...
@@ -85,7 +86,7 @@ func (evm *EVMExecutor) innerExec(msg *common.Message, txHash []byte, index int,
inData
=
packData
methodName
=
funcName
}
ret
,
snapshot
,
leftOverGas
,
vmerr
=
env
.
Call
(
runtime
.
AccountRef
(
msg
.
From
()),
*
msg
.
To
(),
inData
,
context
.
GasLimit
,
msg
.
Value
())
ret
,
snapshot
,
leftOverGas
,
vmerr
=
env
.
Call
(
cfg
,
runtime
.
AccountRef
(
msg
.
From
()),
*
msg
.
To
(),
inData
,
context
.
GasLimit
,
msg
.
Value
())
}
log
.
Debug
(
"call(create) contract "
,
"input"
,
common
.
Bytes2Hex
(
msg
.
Data
()))
...
...
@@ -126,7 +127,7 @@ func (evm *EVMExecutor) innerExec(msg *common.Message, txHash []byte, index int,
kvSet
,
logs
:=
evm
.
mStateDB
.
GetChangedData
(
curVer
.
GetID
())
contractReceipt
:=
&
evmtypes
.
ReceiptEVMContract
{
Caller
:
msg
.
From
()
.
String
(),
ContractName
:
execName
,
ContractAddr
:
contractAddr
.
String
(),
UsedGas
:
usedGas
,
Ret
:
ret
}
// 这里进行ABI调用结果格式化
if
len
(
methodName
)
>
0
&&
len
(
msg
.
ABI
())
>
0
&&
types
.
IsDappFork
(
evm
.
GetHeight
(),
"evm"
,
evmtypes
.
ForkEVMABI
)
{
if
len
(
methodName
)
>
0
&&
len
(
msg
.
ABI
())
>
0
&&
cfg
.
IsDappFork
(
evm
.
GetHeight
(),
"evm"
,
evmtypes
.
ForkEVMABI
)
{
jsonRet
,
err
:=
abi
.
Unpack
(
ret
,
methodName
,
evm
.
mStateDB
.
GetAbi
(
msg
.
To
()
.
String
()))
if
err
!=
nil
{
// 这里出错不影响整体执行,只打印错误信息
...
...
@@ -137,7 +138,7 @@ func (evm *EVMExecutor) innerExec(msg *common.Message, txHash []byte, index int,
logs
=
append
(
logs
,
&
types
.
ReceiptLog
{
Ty
:
evmtypes
.
TyLogCallContract
,
Log
:
types
.
Encode
(
contractReceipt
)})
logs
=
append
(
logs
,
evm
.
mStateDB
.
GetReceiptLogs
(
contractAddr
.
String
())
...
)
if
types
.
IsDappFork
(
evm
.
GetHeight
(),
"evm"
,
evmtypes
.
ForkEVMKVHash
)
{
if
cfg
.
IsDappFork
(
evm
.
GetHeight
(),
"evm"
,
evmtypes
.
ForkEVMKVHash
)
{
// 将执行时生成的合约状态数据变更信息也计算哈希并保存
hashKV
:=
evm
.
calcKVHash
(
contractAddr
,
logs
)
if
hashKV
!=
nil
{
...
...
@@ -153,7 +154,7 @@ func (evm *EVMExecutor) innerExec(msg *common.Message, txHash []byte, index int,
}
// 替换导致分叉的执行数据信息
state
.
ProcessFork
(
evm
.
GetHeight
(),
txHash
,
receipt
)
state
.
ProcessFork
(
cfg
,
evm
.
GetHeight
(),
txHash
,
receipt
)
evm
.
collectEvmTxLog
(
txHash
,
contractReceipt
,
receipt
)
...
...
@@ -163,7 +164,7 @@ func (evm *EVMExecutor) innerExec(msg *common.Message, txHash []byte, index int,
// CheckInit 检查是否初始化数据库
func
(
evm
*
EVMExecutor
)
CheckInit
()
{
if
evm
.
mStateDB
==
nil
{
evm
.
mStateDB
=
state
.
NewMemoryStateDB
(
evm
.
GetStateDB
(),
evm
.
GetLocalDB
(),
evm
.
GetCoinsAccount
(),
evm
.
GetHeight
())
evm
.
mStateDB
=
state
.
NewMemoryStateDB
(
evm
.
GetStateDB
(),
evm
.
GetLocalDB
(),
evm
.
GetCoinsAccount
(),
evm
.
GetHeight
()
,
evm
.
GetAPI
()
)
}
}
...
...
plugin/dapp/evm/executor/vm/common/address.go
View file @
af0be445
...
...
@@ -91,8 +91,8 @@ func (h Hash160Address) ToAddress() Address {
}
// NewAddress xHash生成EVM合约地址
func
NewAddress
(
txHash
[]
byte
)
Address
{
execAddr
:=
address
.
GetExecAddress
(
types
.
ExecName
(
"user.evm."
)
+
BytesToHash
(
txHash
)
.
Hex
())
func
NewAddress
(
cfg
*
types
.
Chain33Config
,
txHash
[]
byte
)
Address
{
execAddr
:=
address
.
GetExecAddress
(
cfg
.
ExecName
(
"user.evm."
)
+
BytesToHash
(
txHash
)
.
Hex
())
return
Address
{
addr
:
execAddr
}
}
...
...
plugin/dapp/evm/executor/vm/runtime/evm.go
View file @
af0be445
...
...
@@ -169,7 +169,7 @@ func (evm *EVM) preCheck(caller ContractRef, recipient common.Address, value uin
// Call 此方法提供合约外部调用入口
// 根据合约地址调用已经存在的合约,input为合约调用参数
// 合约调用逻辑支持在合约调用的同时进行向合约转账的操作
func
(
evm
*
EVM
)
Call
(
caller
ContractRef
,
addr
common
.
Address
,
input
[]
byte
,
gas
uint64
,
value
uint64
)
(
ret
[]
byte
,
snapshot
int
,
leftOverGas
uint64
,
err
error
)
{
func
(
evm
*
EVM
)
Call
(
c
fg
*
types
.
Chain33Config
,
c
aller
ContractRef
,
addr
common
.
Address
,
input
[]
byte
,
gas
uint64
,
value
uint64
)
(
ret
[]
byte
,
snapshot
int
,
leftOverGas
uint64
,
err
error
)
{
pass
,
err
:=
evm
.
preCheck
(
caller
,
addr
,
value
)
if
!
pass
{
return
nil
,
-
1
,
gas
,
err
...
...
@@ -223,7 +223,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
}
// 从ForkV20EVMState开始,状态数据存储发生变更,需要做数据迁移
if
types
.
IsDappFork
(
evm
.
BlockNumber
.
Int64
(),
"evm"
,
evmtypes
.
ForkEVMState
)
{
if
cfg
.
IsDappFork
(
evm
.
BlockNumber
.
Int64
(),
"evm"
,
evmtypes
.
ForkEVMState
)
{
evm
.
StateDB
.
TransferStateData
(
addr
.
String
())
}
...
...
@@ -357,7 +357,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
// 使用传入的部署代码创建新的合约;
// 目前chain33为了保证账户安全,不允许合约中涉及到外部账户的转账操作,
// 所以,本步骤不接收转账金额参数
func
(
evm
*
EVM
)
Create
(
caller
ContractRef
,
contractAddr
common
.
Address
,
code
[]
byte
,
gas
uint64
,
execName
,
alias
,
abi
string
)
(
ret
[]
byte
,
snapshot
int
,
leftOverGas
uint64
,
err
error
)
{
func
(
evm
*
EVM
)
Create
(
c
fg
*
types
.
Chain33Config
,
c
aller
ContractRef
,
contractAddr
common
.
Address
,
code
[]
byte
,
gas
uint64
,
execName
,
alias
,
abi
string
)
(
ret
[]
byte
,
snapshot
int
,
leftOverGas
uint64
,
err
error
)
{
pass
,
err
:=
evm
.
preCheck
(
caller
,
contractAddr
,
0
)
if
!
pass
{
return
nil
,
-
1
,
gas
,
err
...
...
@@ -388,7 +388,7 @@ func (evm *EVM) Create(caller ContractRef, contractAddr common.Address, code []b
if
contract
.
UseGas
(
createDataGas
)
{
evm
.
StateDB
.
SetCode
(
contractAddr
.
String
(),
ret
)
// 设置 ABI (如果有的话),这个动作不单独计费
if
len
(
abi
)
>
0
&&
types
.
IsDappFork
(
evm
.
StateDB
.
GetBlockHeight
(),
"evm"
,
evmtypes
.
ForkEVMABI
)
{
if
len
(
abi
)
>
0
&&
cfg
.
IsDappFork
(
evm
.
StateDB
.
GetBlockHeight
(),
"evm"
,
evmtypes
.
ForkEVMABI
)
{
evm
.
StateDB
.
SetAbi
(
contractAddr
.
String
(),
abi
)
}
}
else
{
...
...
plugin/dapp/evm/executor/vm/state/account.go
View file @
af0be445
...
...
@@ -50,7 +50,8 @@ func NewContractAccount(addr string, db *MemoryStateDB) *ContractAccount {
// 获取数据分为两层,一层是从当前的缓存中获取,如果获取不到,再从localdb中获取
func
(
ca
*
ContractAccount
)
GetState
(
key
common
.
Hash
)
common
.
Hash
{
// 从ForkV19开始,状态数据使用单独的KEY存储
if
types
.
IsDappFork
(
ca
.
mdb
.
blockHeight
,
"evm"
,
evmtypes
.
ForkEVMState
)
{
cfg
:=
ca
.
mdb
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
ca
.
mdb
.
blockHeight
,
"evm"
,
evmtypes
.
ForkEVMState
)
{
if
val
,
ok
:=
ca
.
stateCache
[
key
.
Hex
()];
ok
{
return
val
}
...
...
@@ -76,7 +77,8 @@ func (ca *ContractAccount) SetState(key, value common.Hash) {
key
:
key
,
prevalue
:
ca
.
GetState
(
key
),
})
if
types
.
IsDappFork
(
ca
.
mdb
.
blockHeight
,
"evm"
,
evmtypes
.
ForkEVMState
)
{
cfg
:=
ca
.
mdb
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
ca
.
mdb
.
blockHeight
,
"evm"
,
evmtypes
.
ForkEVMState
)
{
ca
.
stateCache
[
key
.
Hex
()]
=
value
//需要设置到localdb中,以免同一个区块中同一个合约多次调用时,状态数据丢失
keyStr
:=
getStateItemKey
(
ca
.
Addr
,
key
.
Hex
())
...
...
@@ -107,7 +109,8 @@ func (ca *ContractAccount) TransferState() {
func
(
ca
*
ContractAccount
)
updateStorageHash
()
{
// 从ForkV20开始,状态数据使用单独KEY存储
if
types
.
IsDappFork
(
ca
.
mdb
.
blockHeight
,
"evm"
,
evmtypes
.
ForkEVMState
)
{
cfg
:=
ca
.
mdb
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
ca
.
mdb
.
blockHeight
,
"evm"
,
evmtypes
.
ForkEVMState
)
{
return
}
var
state
=
&
evmtypes
.
EVMContractState
{
Suicided
:
ca
.
State
.
Suicided
,
Nonce
:
ca
.
State
.
Nonce
}
...
...
@@ -183,7 +186,8 @@ func (ca *ContractAccount) SetCode(code []byte) {
// SetAbi 设置合约绑定的ABI数据
func
(
ca
*
ContractAccount
)
SetAbi
(
abi
string
)
{
if
types
.
IsDappFork
(
ca
.
mdb
.
GetBlockHeight
(),
"evm"
,
evmtypes
.
ForkEVMABI
)
{
cfg
:=
ca
.
mdb
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
ca
.
mdb
.
GetBlockHeight
(),
"evm"
,
evmtypes
.
ForkEVMABI
)
{
ca
.
mdb
.
addChange
(
abiChange
{
baseChange
:
baseChange
{},
account
:
ca
.
Addr
,
...
...
plugin/dapp/evm/executor/vm/state/fork.go
View file @
af0be445
...
...
@@ -75,13 +75,13 @@ func InitForkData() {
}
// ProcessFork 处理硬分叉逻辑
func
ProcessFork
(
blockHeight
int64
,
txHash
[]
byte
,
receipt
*
types
.
Receipt
)
{
if
types
.
IsLocal
()
{
func
ProcessFork
(
cfg
*
types
.
Chain33Config
,
blockHeight
int64
,
txHash
[]
byte
,
receipt
*
types
.
Receipt
)
{
if
cfg
.
IsLocal
()
{
return
}
// 目前的分叉信息只在测试网中存在
if
!
types
.
IsTestNet
()
{
if
!
cfg
.
IsTestNet
()
{
return
}
...
...
plugin/dapp/evm/executor/vm/state/snapshot.go
View file @
af0be445
...
...
@@ -275,7 +275,8 @@ func (ch storageChange) getData(mdb *MemoryStateDB) []*types.KeyValue {
}
func
(
ch
storageChange
)
getLog
(
mdb
*
MemoryStateDB
)
[]
*
types
.
ReceiptLog
{
if
types
.
IsDappFork
(
mdb
.
blockHeight
,
"evm"
,
evmtypes
.
ForkEVMState
)
{
cfg
:=
mdb
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
mdb
.
blockHeight
,
"evm"
,
evmtypes
.
ForkEVMState
)
{
acc
:=
mdb
.
accounts
[
ch
.
account
]
if
acc
!=
nil
{
currentVal
:=
acc
.
GetState
(
ch
.
key
)
...
...
plugin/dapp/evm/executor/vm/state/statedb.go
View file @
af0be445
...
...
@@ -15,6 +15,7 @@ import (
"github.com/33cn/plugin/plugin/dapp/evm/executor/vm/common"
"github.com/33cn/plugin/plugin/dapp/evm/executor/vm/model"
evmtypes
"github.com/33cn/plugin/plugin/dapp/evm/types"
"github.com/33cn/chain33/client"
)
// MemoryStateDB 内存状态数据库,保存在区块操作时内部的数据变更操作
...
...
@@ -61,12 +62,13 @@ type MemoryStateDB struct {
// 用户保存合约账户的状态数据或合约代码数据有没有发生变更
stateDirty
map
[
string
]
interface
{}
dataDirty
map
[
string
]
interface
{}
api
client
.
QueueProtocolAPI
}
// NewMemoryStateDB 基于执行器框架的三个DB构建内存状态机对象
// 此对象的生命周期对应一个区块,在同一个区块内的多个交易执行时共享同一个DB对象
// 开始执行下一个区块时(执行器框架调用setEnv设置的区块高度发生变更时),会重新创建此DB对象
func
NewMemoryStateDB
(
StateDB
db
.
KV
,
LocalDB
db
.
KVDB
,
CoinsAccount
*
account
.
DB
,
blockHeight
int64
)
*
MemoryStateDB
{
func
NewMemoryStateDB
(
StateDB
db
.
KV
,
LocalDB
db
.
KVDB
,
CoinsAccount
*
account
.
DB
,
blockHeight
int64
,
api
client
.
QueueProtocolAPI
)
*
MemoryStateDB
{
mdb
:=
&
MemoryStateDB
{
StateDB
:
StateDB
,
LocalDB
:
LocalDB
,
...
...
@@ -79,6 +81,7 @@ func NewMemoryStateDB(StateDB db.KV, LocalDB db.KVDB, CoinsAccount *account.DB,
blockHeight
:
blockHeight
,
refund
:
0
,
txIndex
:
0
,
api
:
api
,
}
return
mdb
}
...
...
@@ -131,7 +134,8 @@ func (mdb *MemoryStateDB) GetBalance(addr string) uint64 {
isExec
:=
mdb
.
Exist
(
addr
)
var
ac
*
types
.
Account
if
isExec
{
if
types
.
IsDappFork
(
mdb
.
GetBlockHeight
(),
"evm"
,
evmtypes
.
ForkEVMFrozen
)
{
cfg
:=
mdb
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
mdb
.
GetBlockHeight
(),
"evm"
,
evmtypes
.
ForkEVMFrozen
)
{
ac
=
mdb
.
CoinsAccount
.
LoadExecAccount
(
addr
,
addr
)
}
else
{
contract
:=
mdb
.
GetAccount
(
addr
)
...
...
@@ -268,7 +272,8 @@ func (mdb *MemoryStateDB) SetState(addr string, key common.Hash, value common.Ha
if
acc
!=
nil
{
acc
.
SetState
(
key
,
value
)
// 新的分叉中状态数据变更不需要单独进行标识
if
!
types
.
IsDappFork
(
mdb
.
blockHeight
,
"evm"
,
evmtypes
.
ForkEVMState
)
{
cfg
:=
mdb
.
api
.
GetConfig
()
if
!
cfg
.
IsDappFork
(
mdb
.
blockHeight
,
"evm"
,
evmtypes
.
ForkEVMState
)
{
mdb
.
stateDirty
[
addr
]
=
true
}
}
...
...
@@ -481,7 +486,8 @@ func (mdb *MemoryStateDB) checkExecAccount(execAddr string, value int64) bool {
}
var
accFrom
*
types
.
Account
if
types
.
IsDappFork
(
mdb
.
GetBlockHeight
(),
"evm"
,
evmtypes
.
ForkEVMFrozen
)
{
cfg
:=
mdb
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
mdb
.
GetBlockHeight
(),
"evm"
,
evmtypes
.
ForkEVMFrozen
)
{
// 分叉后,需要检查合约地址下的金额是否足够
accFrom
=
mdb
.
CoinsAccount
.
LoadExecAccount
(
execAddr
,
execAddr
)
}
else
{
...
...
@@ -613,7 +619,8 @@ func (mdb *MemoryStateDB) transfer2Contract(sender, recipient string, amount int
ret
=
&
types
.
Receipt
{}
if
types
.
IsDappFork
(
mdb
.
GetBlockHeight
(),
"evm"
,
evmtypes
.
ForkEVMFrozen
)
{
cfg
:=
mdb
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
mdb
.
GetBlockHeight
(),
"evm"
,
evmtypes
.
ForkEVMFrozen
)
{
// 用户向合约转账时,将钱转到合约地址下execAddr:execAddr
rs
,
err
:=
mdb
.
CoinsAccount
.
ExecTransfer
(
sender
,
execAddr
,
execAddr
,
amount
)
if
err
!=
nil
{
...
...
@@ -653,7 +660,8 @@ func (mdb *MemoryStateDB) transfer2External(sender, recipient string, amount int
execAddr
:=
sender
if
types
.
IsDappFork
(
mdb
.
GetBlockHeight
(),
"evm"
,
evmtypes
.
ForkEVMFrozen
)
{
cfg
:=
mdb
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
mdb
.
GetBlockHeight
(),
"evm"
,
evmtypes
.
ForkEVMFrozen
)
{
// 合约向用户地址转账时,从合约地址下的钱中转出到用户合约地址
ret
,
err
=
mdb
.
CoinsAccount
.
ExecTransfer
(
execAddr
,
recipient
,
execAddr
,
amount
)
if
err
!=
nil
{
...
...
plugin/dapp/evm/rpc/rpc.go
View file @
af0be445
...
...
@@ -28,11 +28,12 @@ func (c *channelClient) Create(ctx context.Context, in evmtypes.EvmContractCreat
action
:=
evmtypes
.
EVMContractAction
{
Amount
:
0
,
Code
:
bCode
,
GasLimit
:
0
,
GasPrice
:
0
,
Note
:
in
.
Note
,
Abi
:
in
.
Abi
}
execer
:=
types
.
ExecName
(
in
.
ParaName
+
"evm"
)
addr
:=
address
.
ExecAddress
(
types
.
ExecName
(
in
.
ParaName
+
"evm"
))
cfg
:=
c
.
GetConfig
()
execer
:=
cfg
.
ExecName
(
in
.
ParaName
+
"evm"
)
addr
:=
address
.
ExecAddress
(
cfg
.
ExecName
(
in
.
ParaName
+
"evm"
))
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
execer
),
Payload
:
types
.
Encode
(
&
action
),
Fee
:
0
,
To
:
addr
}
tx
.
Fee
,
_
=
tx
.
GetRealFee
(
types
.
GInt
(
"MinFee"
))
tx
.
Fee
,
_
=
tx
.
GetRealFee
(
cfg
.
GInt
(
"MinFee"
))
if
tx
.
Fee
<
in
.
Fee
{
tx
.
Fee
+=
in
.
Fee
}
...
...
@@ -60,7 +61,8 @@ func (c *channelClient) Call(ctx context.Context, in evmtypes.EvmContractCallReq
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
in
.
Exec
),
Payload
:
types
.
Encode
(
&
action
),
Fee
:
0
,
To
:
toAddr
}
tx
.
Fee
,
_
=
tx
.
GetRealFee
(
types
.
GInt
(
"MinFee"
))
cfg
:=
c
.
GetConfig
()
tx
.
Fee
,
_
=
tx
.
GetRealFee
(
cfg
.
GInt
(
"MinFee"
))
if
tx
.
Fee
<
feeInt64
{
tx
.
Fee
+=
feeInt64
}
...
...
@@ -86,14 +88,15 @@ func (c *channelClient) Transfer(ctx context.Context, in evmtypes.EvmContractTra
transfer
.
Value
=
&
cty
.
CoinsAction_TransferToExec
{
TransferToExec
:
&
types
.
AssetsTransferToExec
{
Amount
:
amountInt64
,
ExecName
:
execName
,
To
:
address
.
ExecAddress
(
execName
)}}
transfer
.
Ty
=
cty
.
CoinsActionTransferToExec
}
cfg
:=
c
.
GetConfig
()
if
in
.
ParaName
==
""
{
tx
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
in
.
ParaName
+
"coins"
)),
Payload
:
types
.
Encode
(
transfer
),
To
:
address
.
ExecAddress
(
execName
)}
tx
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
in
.
ParaName
+
"coins"
)),
Payload
:
types
.
Encode
(
transfer
),
To
:
address
.
ExecAddress
(
execName
)}
}
else
{
tx
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
in
.
ParaName
+
"coins"
)),
Payload
:
types
.
Encode
(
transfer
),
To
:
address
.
ExecAddress
(
types
.
ExecName
(
in
.
ParaName
+
"coins"
))}
tx
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
in
.
ParaName
+
"coins"
)),
Payload
:
types
.
Encode
(
transfer
),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
in
.
ParaName
+
"coins"
))}
}
var
err
error
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
types
.
GInt
(
"MinFee"
))
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
cfg
.
GInt
(
"MinFee"
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/dapp/game/executor/gamedb.go
View file @
af0be445
...
...
@@ -17,6 +17,7 @@ import (
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
gt
"github.com/33cn/plugin/plugin/dapp/game/types"
"github.com/33cn/chain33/client"
)
const
(
...
...
@@ -166,6 +167,7 @@ type Action struct {
execaddr
string
localDB
dbm
.
Lister
index
int
api
client
.
QueueProtocolAPI
}
// NewAction new action
...
...
@@ -173,7 +175,7 @@ func NewAction(g *Game, tx *types.Transaction, index int) *Action {
hash
:=
tx
.
Hash
()
fromaddr
:=
tx
.
From
()
return
&
Action
{
g
.
GetCoinsAccount
(),
g
.
GetStateDB
(),
hash
,
fromaddr
,
g
.
GetBlockTime
(),
g
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
)),
g
.
GetLocalDB
(),
index
}
g
.
GetBlockTime
(),
g
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
)),
g
.
GetLocalDB
(),
index
,
g
.
GetAPI
()
}
}
func
(
action
*
Action
)
checkExecAccountBalance
(
fromAddr
string
,
ToFrozen
,
ToActive
int64
)
bool
{
...
...
@@ -189,12 +191,13 @@ func (action *Action) GameCreate(create *gt.GameCreate) (*types.Receipt, error)
gameID
:=
common
.
ToHex
(
action
.
txhash
)
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
maxGameAmount
:=
getConfValue
(
action
.
db
,
ConfNameMaxGameAmount
,
MaxGameAmount
)
cfg
:=
action
.
api
.
GetConfig
()
maxGameAmount
:=
getConfValue
(
cfg
,
action
.
db
,
ConfNameMaxGameAmount
,
MaxGameAmount
)
if
create
.
GetValue
()
>
maxGameAmount
*
types
.
Coin
{
glog
.
Error
(
"Create the game, the deposit is too big "
,
"value"
,
create
.
GetValue
(),
"err"
,
gt
.
ErrGameCreateAmount
.
Error
())
return
nil
,
gt
.
ErrGameCreateAmount
}
minGameAmount
:=
getConfValue
(
action
.
db
,
ConfNameMinGameAmount
,
MinGameAmount
)
minGameAmount
:=
getConfValue
(
cfg
,
action
.
db
,
ConfNameMinGameAmount
,
MinGameAmount
)
if
create
.
GetValue
()
<
minGameAmount
*
types
.
Coin
||
math
.
Remainder
(
float64
(
create
.
GetValue
()),
2
)
!=
0
{
return
nil
,
fmt
.
Errorf
(
"%s"
,
"The amount you participate in cannot be less than 2 and must be an even number!"
)
}
...
...
@@ -486,7 +489,8 @@ func (action *Action) GameClose(close *gt.GameClose) (*types.Receipt, error) {
// 检查开奖是否超时,若超过一天,则不让庄家开奖,但其他人可以开奖,
// 若没有一天,则其他人没有开奖权限,只有庄家有开奖权限
func
(
action
*
Action
)
checkGameIsTimeOut
(
game
*
gt
.
Game
)
bool
{
activeTime
:=
getConfValue
(
action
.
db
,
ConfNameActiveTime
,
ActiveTime
)
cfg
:=
action
.
api
.
GetConfig
()
activeTime
:=
getConfValue
(
cfg
,
action
.
db
,
ConfNameActiveTime
,
ActiveTime
)
DurTime
:=
60
*
60
*
activeTime
return
action
.
blocktime
>
(
game
.
GetMatchTime
()
+
DurTime
)
}
...
...
@@ -551,26 +555,26 @@ func (action *Action) readGame(id string) (*gt.Game, error) {
}
// List query game list
func
List
(
db
dbm
.
Lister
,
stateDB
dbm
.
KV
,
param
*
gt
.
QueryGameListByStatusAndAddr
)
(
types
.
Message
,
error
)
{
return
QueryGameListByPage
(
db
,
stateDB
,
param
)
func
List
(
cfg
*
types
.
Chain33Config
,
db
dbm
.
Lister
,
stateDB
dbm
.
KV
,
param
*
gt
.
QueryGameListByStatusAndAddr
)
(
types
.
Message
,
error
)
{
return
QueryGameListByPage
(
cfg
,
db
,
stateDB
,
param
)
}
// QueryGameListByPage 分页查询
func
QueryGameListByPage
(
db
dbm
.
Lister
,
stateDB
dbm
.
KV
,
param
*
gt
.
QueryGameListByStatusAndAddr
)
(
types
.
Message
,
error
)
{
func
QueryGameListByPage
(
cfg
*
types
.
Chain33Config
,
db
dbm
.
Lister
,
stateDB
dbm
.
KV
,
param
*
gt
.
QueryGameListByStatusAndAddr
)
(
types
.
Message
,
error
)
{
switch
param
.
GetStatus
()
{
case
gt
.
GameActionCreate
,
gt
.
GameActionMatch
,
gt
.
GameActionClose
,
gt
.
GameActionCancel
:
return
queryGameListByStatusAndAddr
(
db
,
stateDB
,
param
)
return
queryGameListByStatusAndAddr
(
cfg
,
db
,
stateDB
,
param
)
}
return
nil
,
fmt
.
Errorf
(
"%s"
,
"the status only fill in 1,2,3,4!"
)
}
func
queryGameListByStatusAndAddr
(
db
dbm
.
Lister
,
stateDB
dbm
.
KV
,
param
*
gt
.
QueryGameListByStatusAndAddr
)
(
types
.
Message
,
error
)
{
func
queryGameListByStatusAndAddr
(
cfg
*
types
.
Chain33Config
,
db
dbm
.
Lister
,
stateDB
dbm
.
KV
,
param
*
gt
.
QueryGameListByStatusAndAddr
)
(
types
.
Message
,
error
)
{
direction
:=
ListDESC
if
param
.
GetDirection
()
==
ListASC
{
direction
=
ListASC
}
count
:=
int32
(
getConfValue
(
stateDB
,
ConfNameDefaultCount
,
DefaultCount
))
maxCount
:=
int32
(
getConfValue
(
stateDB
,
ConfNameMaxCount
,
MaxCount
))
count
:=
int32
(
getConfValue
(
cfg
,
stateDB
,
ConfNameDefaultCount
,
DefaultCount
))
maxCount
:=
int32
(
getConfValue
(
cfg
,
stateDB
,
ConfNameMaxCount
,
MaxCount
))
if
0
<
param
.
GetCount
()
&&
param
.
GetCount
()
<=
maxCount
{
count
=
param
.
GetCount
()
}
...
...
@@ -679,9 +683,9 @@ func GetGameList(db dbm.KV, values []string) []*gt.Game {
}
return
games
}
func
getConfValue
(
db
dbm
.
KV
,
key
string
,
defaultValue
int64
)
int64
{
func
getConfValue
(
cfg
*
types
.
Chain33Config
,
db
dbm
.
KV
,
key
string
,
defaultValue
int64
)
int64
{
var
item
types
.
ConfigItem
value
,
err
:=
getManageKey
(
key
,
db
)
value
,
err
:=
getManageKey
(
cfg
,
key
,
db
)
if
err
!=
nil
{
return
defaultValue
}
...
...
@@ -705,11 +709,11 @@ func getConfValue(db dbm.KV, key string, defaultValue int64) int64 {
}
return
v
}
func
getManageKey
(
key
string
,
db
dbm
.
KV
)
([]
byte
,
error
)
{
func
getManageKey
(
cfg
*
types
.
Chain33Config
,
key
string
,
db
dbm
.
KV
)
([]
byte
,
error
)
{
manageKey
:=
types
.
ManageKey
(
key
)
value
,
err
:=
db
.
Get
([]
byte
(
manageKey
))
if
err
!=
nil
{
if
types
.
IsPara
()
{
//平行链只有一种存储方式
if
cfg
.
IsPara
()
{
//平行链只有一种存储方式
glog
.
Error
(
"gamedb getManage"
,
"can't get value from db,key:"
,
key
,
"err"
,
err
.
Error
())
return
nil
,
err
}
...
...
plugin/dapp/game/executor/query.go
View file @
af0be445
...
...
@@ -21,7 +21,8 @@ func (g *Game) Query_QueryGameListCount(in *gt.QueryGameListCount) (types.Messag
// Query_QueryGameListByStatusAndAddr query game list by status and addr
func
(
g
*
Game
)
Query_QueryGameListByStatusAndAddr
(
in
*
gt
.
QueryGameListByStatusAndAddr
)
(
types
.
Message
,
error
)
{
return
List
(
g
.
GetLocalDB
(),
g
.
GetStateDB
(),
in
)
cfg
:=
g
.
GetAPI
()
.
GetConfig
()
return
List
(
cfg
,
g
.
GetLocalDB
(),
g
.
GetStateDB
(),
in
)
}
// Query_QueryGameById query game by gameID
...
...
plugin/dapp/guess/executor/guess.go
View file @
af0be445
...
...
@@ -15,19 +15,20 @@ var logger = log.New("module", "execs.guess")
var
driverName
=
gty
.
GuessX
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Guess
{}))
}
// Init Guess
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
driverName
:=
GetName
()
if
name
!=
driverName
{
panic
(
"system dapp can't be rename"
)
}
drivers
.
Register
(
driverName
,
newGuessGame
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
Register
(
cfg
,
driverName
,
newGuessGame
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Guess
{}))
}
//Guess 执行器,用于竞猜合约的具体执行
...
...
plugin/dapp/guess/types/types.go
View file @
af0be445
...
...
@@ -12,9 +12,17 @@ import (
func
init
()
{
// init executor type
types
.
RegistorExecutor
(
GuessX
,
NewType
())
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
ExecerGuess
)
types
.
RegisterDappFork
(
GuessX
,
"Enable"
,
0
)
types
.
RegFork
(
GuessX
,
InitFork
)
types
.
RegExec
(
GuessX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
GuessX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
GuessX
,
NewType
(
cfg
))
}
// GuessType struct
...
...
@@ -23,9 +31,10 @@ type GuessType struct {
}
// NewType method
func
NewType
()
*
GuessType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
GuessType
{
c
:=
&
GuessType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/hashlock/executor/hashlockdb.go
View file @
af0be445
...
...
@@ -15,6 +15,7 @@ import (
log
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/hashlock/types"
"github.com/33cn/chain33/client"
)
var
hlog
=
log
.
New
(
"module"
,
"hashlock.db"
)
...
...
@@ -75,13 +76,14 @@ type Action struct {
blocktime
int64
height
int64
execaddr
string
api
client
.
QueueProtocolAPI
}
// NewAction gen action instance
func
NewAction
(
h
*
Hashlock
,
tx
*
types
.
Transaction
,
execaddr
string
)
*
Action
{
hash
:=
tx
.
Hash
()
fromaddr
:=
tx
.
From
()
return
&
Action
{
h
.
GetCoinsAccount
(),
h
.
GetStateDB
(),
hash
,
fromaddr
,
h
.
GetBlockTime
(),
h
.
GetHeight
(),
execaddr
}
return
&
Action
{
h
.
GetCoinsAccount
(),
h
.
GetStateDB
(),
hash
,
fromaddr
,
h
.
GetBlockTime
(),
h
.
GetHeight
(),
execaddr
,
h
.
GetAPI
()
}
}
// Hashlocklock Action
...
...
@@ -91,7 +93,8 @@ func (action *Action) Hashlocklock(hlock *pty.HashlockLock) (*types.Receipt, err
var
kv
[]
*
types
.
KeyValue
var
err
error
//不存在相同的hashlock,假定采用sha256
if
types
.
IsDappFork
(
action
.
height
,
pty
.
HashlockX
,
pty
.
ForkBadRepeatSecretX
)
{
cfg
:=
action
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
action
.
height
,
pty
.
HashlockX
,
pty
.
ForkBadRepeatSecretX
)
{
_
,
err
=
readHashlock
(
action
.
db
,
hlock
.
Hash
)
}
else
{
_
,
err
=
readHashlock
(
action
.
db
,
common
.
Sha256
(
hlock
.
Hash
))
...
...
plugin/dapp/js/executor/exec.go
View file @
af0be445
...
...
@@ -10,7 +10,8 @@ import (
func
(
c
*
js
)
userExecName
(
name
string
,
local
bool
)
string
{
execer
:=
"user."
+
ptypes
.
JsX
+
"."
+
name
if
local
{
execer
=
types
.
ExecName
(
execer
)
cfg
:=
c
.
GetAPI
()
.
GetConfig
()
execer
=
cfg
.
ExecName
(
execer
)
}
return
execer
}
...
...
@@ -18,7 +19,8 @@ func (c *js) userExecName(name string, local bool) string {
// execName 在create 时为 jsvm
// 在 call 时为 user.jsvm.game
func
(
c
*
js
)
checkTxExec
(
txExec
string
,
execName
string
)
bool
{
return
txExec
==
types
.
ExecName
(
execName
)
cfg
:=
c
.
GetAPI
()
.
GetConfig
()
return
txExec
==
cfg
.
ExecName
(
execName
)
}
func
(
c
*
js
)
Exec_Create
(
payload
*
jsproto
.
Create
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
...
...
plugin/dapp/js/executor/js.go
View file @
af0be445
...
...
@@ -193,7 +193,8 @@ func (u *js) getContext(tx *types.Transaction, index int64) *blockContext {
}
func
(
u
*
js
)
statedbFunc
(
vm
*
otto
.
Otto
,
name
string
)
{
prefix
,
_
:=
calcAllPrefix
(
name
)
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
prefix
,
_
:=
calcAllPrefix
(
cfg
,
name
)
vm
.
Set
(
"getstatedb"
,
func
(
call
otto
.
FunctionCall
)
otto
.
Value
{
key
,
err
:=
call
.
Argument
(
0
)
.
ToString
()
if
err
!=
nil
{
...
...
@@ -215,7 +216,8 @@ func (u *js) statedbFunc(vm *otto.Otto, name string) {
}
func
(
u
*
js
)
localdbFunc
(
vm
*
otto
.
Otto
,
name
string
)
{
_
,
prefix
:=
calcAllPrefix
(
name
)
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
_
,
prefix
:=
calcAllPrefix
(
cfg
,
name
)
vm
.
Set
(
"getlocaldb"
,
func
(
call
otto
.
FunctionCall
)
otto
.
Value
{
key
,
err
:=
call
.
Argument
(
0
)
.
ToString
()
if
err
!=
nil
{
...
...
@@ -261,7 +263,8 @@ func (u *js) randnumFunc(vm *otto.Otto, name string) {
func
(
u
*
js
)
listdbFunc
(
vm
*
otto
.
Otto
,
name
string
)
{
//List(prefix, key []byte, count, direction int32) ([][]byte, error)
_
,
plocal
:=
calcAllPrefix
(
name
)
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
_
,
plocal
:=
calcAllPrefix
(
cfg
,
name
)
vm
.
Set
(
"listdb"
,
func
(
call
otto
.
FunctionCall
)
otto
.
Value
{
prefix
,
err
:=
call
.
Argument
(
0
)
.
ToString
()
if
err
!=
nil
{
...
...
plugin/dapp/js/executor/key.go
View file @
af0be445
...
...
@@ -5,8 +5,8 @@ import (
ptypes
"github.com/33cn/plugin/plugin/dapp/js/types"
)
func
calcAllPrefix
(
name
string
)
([]
byte
,
[]
byte
)
{
execer
:=
types
.
ExecName
(
"user."
+
ptypes
.
JsX
+
"."
+
name
)
func
calcAllPrefix
(
cfg
*
types
.
Chain33Config
,
name
string
)
([]
byte
,
[]
byte
)
{
execer
:=
cfg
.
ExecName
(
"user."
+
ptypes
.
JsX
+
"."
+
name
)
state
:=
types
.
CalcStatePrefix
([]
byte
(
execer
))
local
:=
types
.
CalcLocalPrefix
([]
byte
(
execer
))
return
state
,
local
...
...
plugin/dapp/js/executor/table.go
View file @
af0be445
...
...
@@ -45,14 +45,15 @@ func (u *js) newTable(name, config, defaultvalue string) (id int64, err error) {
if
err
!=
nil
{
return
0
,
err
}
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
var
kvdb
db
.
KV
var
prefix
[]
byte
if
row
.
config
[
"#db"
]
==
"localdb"
{
kvdb
=
u
.
GetLocalDB
()
_
,
prefix
=
calcAllPrefix
(
name
)
_
,
prefix
=
calcAllPrefix
(
cfg
,
name
)
}
else
if
row
.
config
[
"#db"
]
==
"statedb"
{
kvdb
=
u
.
GetStateDB
()
prefix
,
_
=
calcAllPrefix
(
name
)
prefix
,
_
=
calcAllPrefix
(
cfg
,
name
)
}
else
{
return
0
,
ptypes
.
ErrDBType
}
...
...
plugin/dapp/lottery/executor/lotterydb.go
View file @
af0be445
...
...
@@ -13,6 +13,7 @@ import (
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/lottery/types"
"github.com/33cn/chain33/client"
)
const
(
...
...
@@ -120,6 +121,7 @@ type Action struct {
difficulty
uint64
index
int
lottery
*
Lottery
api
client
.
QueueProtocolAPI
}
// NewLotteryAction generate New Action
...
...
@@ -130,7 +132,9 @@ func NewLotteryAction(l *Lottery, tx *types.Transaction, index int) *Action {
coinsAccount
:
l
.
GetCoinsAccount
(),
db
:
l
.
GetStateDB
(),
txhash
:
hash
,
fromaddr
:
fromaddr
,
blocktime
:
l
.
GetBlockTime
(),
height
:
l
.
GetHeight
(),
execaddr
:
dapp
.
ExecAddress
(
string
(
tx
.
Execer
)),
difficulty
:
l
.
GetDifficulty
(),
index
:
index
,
lottery
:
l
}
difficulty
:
l
.
GetDifficulty
(),
index
:
index
,
lottery
:
l
,
api
:
l
.
GetAPI
(),
}
}
// GetLottCommonRecipt generate logs for lottery common action
...
...
@@ -262,7 +266,8 @@ func (action *Action) LotteryCreate(create *pty.LotteryCreate) (*types.Receipt,
lott
.
TotalAddrNum
=
0
lott
.
BuyAmount
=
0
llog
.
Debug
(
"LotteryCreate"
,
"OpRewardRatio"
,
lott
.
OpRewardRatio
,
"DevRewardRatio"
,
lott
.
DevRewardRatio
)
if
types
.
IsPara
()
{
cfg
:=
action
.
api
.
GetConfig
()
if
cfg
.
IsPara
()
{
lott
.
CreateOnMain
=
action
.
lottery
.
GetMainHeight
()
}
...
...
@@ -306,19 +311,19 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
return
nil
,
pty
.
ErrLotteryStatus
}
}
cfg
:=
action
.
api
.
GetConfig
()
if
lott
.
Status
==
pty
.
LotteryCreated
||
lott
.
Status
==
pty
.
LotteryDrawed
{
llog
.
Debug
(
"LotteryBuy switch to purchasestate"
)
lott
.
LastTransToPurState
=
action
.
height
lott
.
Status
=
pty
.
LotteryPurchase
lott
.
Round
++
if
types
.
IsPara
()
{
if
cfg
.
IsPara
()
{
lott
.
LastTransToPurStateOnMain
=
action
.
lottery
.
GetMainHeight
()
}
}
if
lott
.
Status
==
pty
.
LotteryPurchase
{
if
types
.
IsPara
()
{
if
cfg
.
IsPara
()
{
mainHeight
:=
action
.
lottery
.
GetMainHeight
()
if
mainHeight
-
lott
.
LastTransToPurStateOnMain
>
lott
.
GetPurBlockNum
()
{
llog
.
Error
(
"LotteryBuy"
,
"action.height"
,
action
.
height
,
"mainHeight"
,
mainHeight
,
"LastTransToPurStateOnMain"
,
lott
.
LastTransToPurStateOnMain
)
...
...
@@ -423,8 +428,8 @@ func (action *Action) LotteryDraw(draw *pty.LotteryDraw) (*types.Receipt, error)
llog
.
Error
(
"LotteryDraw"
,
"lott.Status"
,
lott
.
Status
)
return
nil
,
pty
.
ErrLotteryStatus
}
if
types
.
IsPara
()
{
cfg
:=
action
.
api
.
GetConfig
()
if
cfg
.
IsPara
()
{
mainHeight
:=
action
.
lottery
.
GetMainHeight
()
if
mainHeight
-
lott
.
GetLastTransToPurStateOnMain
()
<
lott
.
GetDrawBlockNum
()
{
llog
.
Error
(
"LotteryDraw"
,
"action.height"
,
action
.
height
,
"mainHeight"
,
mainHeight
,
"GetLastTransToPurStateOnMain"
,
lott
.
GetLastTransToPurState
())
...
...
@@ -688,7 +693,8 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp
lott
.
BuyAmount
=
0
action
.
recordMissing
(
lott
)
if
types
.
IsPara
()
{
cfg
:=
action
.
api
.
GetConfig
()
if
cfg
.
IsPara
()
{
lott
.
LastTransToDrawStateOnMain
=
action
.
lottery
.
GetMainHeight
()
}
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
&
updateInfo
,
&
gainInfos
,
luckyAddrNum
,
totalFund
,
factor
,
nil
...
...
plugin/dapp/multisig/rpc/rpc.go
View file @
af0be445
...
...
@@ -16,8 +16,8 @@ func (c *Jrpc) MultiSigAccCreateTx(param *mty.MultiSigAccCreate, result *interfa
if
param
==
nil
{
return
types
.
ErrInvalidParam
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
mty
.
MultiSigX
),
"MultiSigAccCreate"
,
param
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
mty
.
MultiSigX
),
"MultiSigAccCreate"
,
param
)
if
err
!=
nil
{
return
err
}
...
...
@@ -30,7 +30,8 @@ func (c *Jrpc) MultiSigOwnerOperateTx(param *mty.MultiSigOwnerOperate, result *i
if
param
==
nil
{
return
types
.
ErrInvalidParam
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
mty
.
MultiSigX
),
"MultiSigOwnerOperate"
,
param
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
mty
.
MultiSigX
),
"MultiSigOwnerOperate"
,
param
)
if
err
!=
nil
{
return
err
}
...
...
@@ -43,7 +44,8 @@ func (c *Jrpc) MultiSigAccOperateTx(param *mty.MultiSigAccOperate, result *inter
if
param
==
nil
{
return
types
.
ErrInvalidParam
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
mty
.
MultiSigX
),
"MultiSigAccOperate"
,
param
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
mty
.
MultiSigX
),
"MultiSigAccOperate"
,
param
)
if
err
!=
nil
{
return
err
}
...
...
@@ -56,7 +58,8 @@ func (c *Jrpc) MultiSigConfirmTx(param *mty.MultiSigConfirmTx, result *interface
if
param
==
nil
{
return
types
.
ErrInvalidParam
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
mty
.
MultiSigX
),
"MultiSigConfirmTx"
,
param
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
mty
.
MultiSigX
),
"MultiSigConfirmTx"
,
param
)
if
err
!=
nil
{
return
err
}
...
...
@@ -70,7 +73,8 @@ func (c *Jrpc) MultiSigAccTransferInTx(param *mty.MultiSigExecTransferTo, result
return
types
.
ErrInvalidParam
}
v
:=
*
param
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
mty
.
MultiSigX
),
"MultiSigExecTransferTo"
,
&
v
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
mty
.
MultiSigX
),
"MultiSigExecTransferTo"
,
&
v
)
if
err
!=
nil
{
return
err
}
...
...
@@ -84,7 +88,8 @@ func (c *Jrpc) MultiSigAccTransferOutTx(param *mty.MultiSigExecTransferFrom, res
return
types
.
ErrInvalidParam
}
v
:=
*
param
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
mty
.
MultiSigX
),
"MultiSigExecTransferFrom"
,
&
v
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
mty
.
MultiSigX
),
"MultiSigExecTransferFrom"
,
&
v
)
if
err
!=
nil
{
return
err
}
...
...
plugin/dapp/multisig/wallet/multisig.go
View file @
af0be445
...
...
@@ -409,9 +409,9 @@ func (policy *multisigPolicy) rescanOwnerAttrByAddr(addr string) {
}
operater
:=
policy
.
getWalletOperate
()
cfg
:=
policy
.
getWalletOperate
()
.
GetAPI
()
.
GetConfig
()
//获取全网中多重签名账户数量
msg
,
err
:=
operater
.
GetAPI
()
.
Query
(
types
.
ExecName
(
mtypes
.
MultiSigX
),
"MultiSigAccCount"
,
&
types
.
ReqNil
{})
msg
,
err
:=
operater
.
GetAPI
()
.
Query
(
cfg
.
ExecName
(
mtypes
.
MultiSigX
),
"MultiSigAccCount"
,
&
types
.
ReqNil
{})
if
err
!=
nil
{
bizlog
.
Error
(
"rescanOwnerAttrByAddr Query MultiSigAccCount err"
,
"MultiSigX"
,
mtypes
.
MultiSigX
,
"addr"
,
addr
,
"err"
,
err
)
return
...
...
@@ -438,7 +438,7 @@ func (policy *multisigPolicy) rescanOwnerAttrByAddr(addr string) {
req
.
End
=
req
.
Start
+
MaxCountPerTime
curCount
=
req
.
End
}
msg
,
err
:=
operater
.
GetAPI
()
.
Query
(
types
.
ExecName
(
mtypes
.
MultiSigX
),
"MultiSigAccounts"
,
&
req
)
msg
,
err
:=
operater
.
GetAPI
()
.
Query
(
cfg
.
ExecName
(
mtypes
.
MultiSigX
),
"MultiSigAccounts"
,
&
req
)
if
err
!=
nil
{
bizlog
.
Error
(
"rescanOwnerAttrByAddr"
,
"MultiSigAccounts error"
,
err
,
"addr"
,
addr
)
return
...
...
@@ -458,12 +458,12 @@ func (policy *multisigPolicy) rescanOwnerAttrByAddr(addr string) {
}
func
(
policy
*
multisigPolicy
)
proceMultiSigAcc
(
multiSigAccs
*
mtypes
.
ReplyMultiSigAccs
,
owneraddr
string
)
{
operater
:=
policy
.
getWalletOperate
()
cfg
:=
policy
.
getWalletOperate
()
.
GetAPI
()
.
GetConfig
()
for
_
,
multiSigaddr
:=
range
multiSigAccs
.
Address
{
req
:=
mtypes
.
ReqMultiSigAccInfo
{
MultiSigAccAddr
:
multiSigaddr
,
}
msg
,
err
:=
operater
.
GetAPI
()
.
Query
(
types
.
ExecName
(
mtypes
.
MultiSigX
),
"MultiSigAccountInfo"
,
&
req
)
msg
,
err
:=
operater
.
GetAPI
()
.
Query
(
cfg
.
ExecName
(
mtypes
.
MultiSigX
),
"MultiSigAccountInfo"
,
&
req
)
if
err
!=
nil
{
bizlog
.
Error
(
"ProceMultiSigAcc"
,
"MultiSigAccountInfo error"
,
err
,
"multiSigaddr"
,
multiSigaddr
)
continue
...
...
plugin/dapp/norm/types/norm.go
View file @
af0be445
...
...
@@ -13,8 +13,8 @@ var NormX = "norm"
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
NormX
))
types
.
RegFork
(
Coins
X
,
InitFork
)
types
.
RegExec
(
Coins
X
,
InitExecutor
)
types
.
RegFork
(
Norm
X
,
InitFork
)
types
.
RegExec
(
Norm
X
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
...
...
plugin/dapp/paracross/executor/action.go
View file @
af0be445
This diff is collapsed.
Click to expand it.
plugin/dapp/paracross/executor/asset.go
View file @
af0be445
...
...
@@ -16,10 +16,11 @@ import (
)
func
(
a
*
action
)
assetTransfer
(
transfer
*
types
.
AssetsTransfer
)
(
*
types
.
Receipt
,
error
)
{
isPara
:=
types
.
IsPara
()
cfg
:=
a
.
api
.
GetConfig
()
isPara
:=
cfg
.
IsPara
()
//主链处理分支
if
!
isPara
{
accDB
,
err
:=
createAccount
(
a
.
db
,
transfer
.
Cointoken
)
accDB
,
err
:=
createAccount
(
cfg
,
a
.
db
,
transfer
.
Cointoken
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"assetTransferToken call account.NewAccountDB failed"
)
}
...
...
@@ -53,10 +54,11 @@ func (a *action) assetTransfer(transfer *types.AssetsTransfer) (*types.Receipt,
}
func
(
a
*
action
)
assetWithdraw
(
withdraw
*
types
.
AssetsWithdraw
,
withdrawTx
*
types
.
Transaction
)
(
*
types
.
Receipt
,
error
)
{
isPara
:=
types
.
IsPara
()
cfg
:=
a
.
api
.
GetConfig
()
isPara
:=
cfg
.
IsPara
()
//主链处理分支
if
!
isPara
{
accDB
,
err
:=
createAccount
(
a
.
db
,
withdraw
.
Cointoken
)
accDB
,
err
:=
createAccount
(
cfg
,
a
.
db
,
withdraw
.
Cointoken
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"assetWithdrawCoins call account.NewAccountDB failed"
)
}
...
...
@@ -85,11 +87,11 @@ func (a *action) assetWithdraw(withdraw *types.AssetsWithdraw, withdrawTx *types
return
assetWithdrawBalance
(
paraAcc
,
a
.
fromaddr
,
withdraw
.
Amount
)
}
func
createAccount
(
db
db
.
KV
,
symbol
string
)
(
*
account
.
DB
,
error
)
{
func
createAccount
(
cfg
*
types
.
Chain33Config
,
db
db
.
KV
,
symbol
string
)
(
*
account
.
DB
,
error
)
{
var
accDB
*
account
.
DB
var
err
error
if
symbol
==
""
{
accDB
=
account
.
NewCoinsAccount
()
accDB
=
account
.
NewCoinsAccount
(
cfg
)
accDB
.
SetDB
(
db
)
}
else
{
accDB
,
err
=
account
.
NewAccountDB
(
"token"
,
symbol
,
db
)
...
...
plugin/dapp/paracross/executor/exec.go
View file @
af0be445
...
...
@@ -62,7 +62,8 @@ func (e *Paracross) Exec_Miner(payload *pt.ParacrossMinerAction, tx *types.Trans
if
index
!=
0
{
return
nil
,
pt
.
ErrParaMinerBaseIndex
}
if
!
types
.
IsPara
()
{
cfg
:=
e
.
GetAPI
()
.
GetConfig
()
if
!
cfg
.
IsPara
()
{
return
nil
,
types
.
ErrNotSupport
}
a
:=
newAction
(
e
,
tx
)
...
...
plugin/dapp/paracross/executor/exec_del_local.go
View file @
af0be445
...
...
@@ -13,6 +13,7 @@ import (
//ExecDelLocal_Commit consensus commit tx del local db process
func
(
e
*
Paracross
)
ExecDelLocal_Commit
(
payload
*
pt
.
ParacrossCommitAction
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
var
set
types
.
LocalDBSet
cfg
:=
e
.
GetAPI
()
.
GetConfig
()
for
_
,
log
:=
range
receiptData
.
Logs
{
if
log
.
Ty
==
pt
.
TyLogParacrossCommit
{
//} || log.Ty == types.TyLogParacrossCommitRecord {
var
g
pt
.
ReceiptParacrossCommit
...
...
@@ -32,7 +33,7 @@ func (e *Paracross) ExecDelLocal_Commit(payload *pt.ParacrossCommitAction, tx *t
key
=
calcLocalHeightKey
(
g
.
Title
,
g
.
Height
)
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
if
!
types
.
IsPara
()
&&
g
.
Height
>
0
{
if
!
cfg
.
IsPara
()
&&
g
.
Height
>
0
{
r
,
err
:=
e
.
saveLocalParaTxs
(
tx
,
true
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,6 +56,7 @@ func (e *Paracross) ExecDelLocal_Commit(payload *pt.ParacrossCommitAction, tx *t
// ExecDelLocal_NodeConfig node config tx delete process
func
(
e
*
Paracross
)
ExecDelLocal_NodeConfig
(
payload
*
pt
.
ParaNodeAddrConfig
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
var
set
types
.
LocalDBSet
cfg
:=
e
.
GetAPI
()
.
GetConfig
()
for
_
,
log
:=
range
receiptData
.
Logs
{
if
log
.
Ty
==
pt
.
TyLogParaNodeConfig
{
var
g
pt
.
ReceiptParaNodeConfig
...
...
@@ -88,7 +90,7 @@ func (e *Paracross) ExecDelLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *
key
=
calcLocalHeightKey
(
g
.
Title
,
g
.
Height
)
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
if
!
types
.
IsPara
()
&&
g
.
Height
>
0
{
if
!
cfg
.
IsPara
()
&&
g
.
Height
>
0
{
r
,
err
:=
e
.
saveLocalParaTxsFork
(
&
g
,
true
)
if
err
!=
nil
{
return
nil
,
err
...
...
plugin/dapp/paracross/executor/exec_local.go
View file @
af0be445
...
...
@@ -18,6 +18,7 @@ import (
//ExecLocal_Commit commit tx local db process
func
(
e
*
Paracross
)
ExecLocal_Commit
(
payload
*
pt
.
ParacrossCommitAction
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
var
set
types
.
LocalDBSet
cfg
:=
e
.
GetAPI
()
.
GetConfig
()
for
_
,
log
:=
range
receiptData
.
Logs
{
if
log
.
Ty
==
pt
.
TyLogParacrossCommit
{
var
g
pt
.
ReceiptParacrossCommit
...
...
@@ -35,7 +36,7 @@ func (e *Paracross) ExecLocal_Commit(payload *pt.ParacrossCommitAction, tx *type
key
=
calcLocalHeightKey
(
g
.
Title
,
g
.
Height
)
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
&
g
)})
if
!
types
.
IsPara
()
&&
g
.
Height
>
0
{
if
!
cfg
.
IsPara
()
&&
g
.
Height
>
0
{
r
,
err
:=
e
.
saveLocalParaTxs
(
tx
,
false
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -58,6 +59,7 @@ func (e *Paracross) ExecLocal_Commit(payload *pt.ParacrossCommitAction, tx *type
//ExecLocal_NodeConfig node config add process
func
(
e
*
Paracross
)
ExecLocal_NodeConfig
(
payload
*
pt
.
ParaNodeAddrConfig
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
var
set
types
.
LocalDBSet
cfg
:=
e
.
GetAPI
()
.
GetConfig
()
for
_
,
log
:=
range
receiptData
.
Logs
{
if
log
.
Ty
==
pt
.
TyLogParaNodeConfig
{
var
g
pt
.
ReceiptParaNodeConfig
...
...
@@ -90,7 +92,7 @@ func (e *Paracross) ExecLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *typ
key
=
calcLocalHeightKey
(
g
.
Title
,
g
.
Height
)
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
&
g
)})
if
!
types
.
IsPara
()
&&
g
.
Height
>
0
{
if
!
cfg
.
IsPara
()
&&
g
.
Height
>
0
{
r
,
err
:=
e
.
saveLocalParaTxsFork
(
&
g
,
false
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -160,14 +162,14 @@ func (e *Paracross) ExecLocal_AssetWithdraw(payload *types.AssetsWithdraw, tx *t
return
nil
,
nil
}
func
setMinerTxResult
(
payload
*
pt
.
ParacrossMinerAction
,
txs
[]
*
types
.
Transaction
,
receipts
[]
*
types
.
ReceiptData
)
error
{
func
setMinerTxResult
(
cfg
*
types
.
Chain33Config
,
payload
*
pt
.
ParacrossMinerAction
,
txs
[]
*
types
.
Transaction
,
receipts
[]
*
types
.
ReceiptData
)
error
{
isCommitTx
:=
make
(
map
[
string
]
bool
)
var
curTxHashs
,
paraTxHashs
,
crossTxHashs
[][]
byte
for
_
,
tx
:=
range
txs
{
hash
:=
tx
.
Hash
()
curTxHashs
=
append
(
curTxHashs
,
hash
)
//对user.p.xx.paracross ,actionTy==commit 的tx不需要再发回主链
if
types
.
IsMyParaExecName
(
string
(
tx
.
Execer
))
&&
bytes
.
HasSuffix
(
tx
.
Execer
,
[]
byte
(
pt
.
ParaX
))
{
if
cfg
.
IsMyParaExecName
(
string
(
tx
.
Execer
))
&&
bytes
.
HasSuffix
(
tx
.
Execer
,
[]
byte
(
pt
.
ParaX
))
{
var
payload
pt
.
ParacrossAction
err
:=
types
.
Decode
(
tx
.
Payload
,
&
payload
)
if
err
!=
nil
{
...
...
@@ -179,11 +181,11 @@ func setMinerTxResult(payload *pt.ParacrossMinerAction, txs []*types.Transaction
}
}
//跨链交易包含了主链交易,需要过滤出来
if
types
.
IsMyParaExecName
(
string
(
tx
.
Execer
))
&&
!
isCommitTx
[
string
(
hash
)]
{
if
cfg
.
IsMyParaExecName
(
string
(
tx
.
Execer
))
&&
!
isCommitTx
[
string
(
hash
)]
{
paraTxHashs
=
append
(
paraTxHashs
,
hash
)
}
}
totalCrossTxHashs
:=
FilterParaMainCrossTxHashes
(
types
.
GetTitle
(),
txs
)
totalCrossTxHashs
:=
FilterParaMainCrossTxHashes
(
cfg
.
GetTitle
(),
txs
)
for
_
,
crossHash
:=
range
totalCrossTxHashs
{
if
!
isCommitTx
[
string
(
crossHash
)]
{
crossTxHashs
=
append
(
crossTxHashs
,
crossHash
)
...
...
@@ -197,14 +199,14 @@ func setMinerTxResult(payload *pt.ParacrossMinerAction, txs []*types.Transaction
return
nil
}
func
setMinerTxResultFork
(
status
*
pt
.
ParacrossNodeStatus
,
txs
[]
*
types
.
Transaction
,
receipts
[]
*
types
.
ReceiptData
)
error
{
func
setMinerTxResultFork
(
cfg
*
types
.
Chain33Config
,
status
*
pt
.
ParacrossNodeStatus
,
txs
[]
*
types
.
Transaction
,
receipts
[]
*
types
.
ReceiptData
)
error
{
isCommitTx
:=
make
(
map
[
string
]
bool
)
var
curTxHashs
[][]
byte
for
_
,
tx
:=
range
txs
{
hash
:=
tx
.
Hash
()
curTxHashs
=
append
(
curTxHashs
,
hash
)
if
types
.
IsMyParaExecName
(
string
(
tx
.
Execer
))
&&
bytes
.
HasSuffix
(
tx
.
Execer
,
[]
byte
(
pt
.
ParaX
))
{
if
cfg
.
IsMyParaExecName
(
string
(
tx
.
Execer
))
&&
bytes
.
HasSuffix
(
tx
.
Execer
,
[]
byte
(
pt
.
ParaX
))
{
var
payload
pt
.
ParacrossAction
err
:=
types
.
Decode
(
tx
.
Payload
,
&
payload
)
if
err
!=
nil
{
...
...
@@ -228,7 +230,7 @@ func setMinerTxResultFork(status *pt.ParacrossNodeStatus, txs []*types.Transacti
status
.
TxResult
=
[]
byte
(
hex
.
EncodeToString
(
util
.
CalcSingleBitMap
(
curTxHashs
,
receipts
)))
//ForkLoopCheckCommitTxDone 后只保留全部txreseult 结果
if
!
pt
.
IsParaForkHeight
(
status
.
MainBlockHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
if
!
pt
.
IsParaForkHeight
(
cfg
,
status
.
MainBlockHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
//跨链tx结果
crossTxHashs
:=
FilterParaCrossTxHashes
(
txs
)
status
.
CrossTxResult
=
[]
byte
(
hex
.
EncodeToString
(
util
.
CalcBitMap
(
crossTxHashs
,
curTxHashs
,
receipts
)))
...
...
@@ -247,15 +249,16 @@ func (e *Paracross) ExecLocal_Miner(payload *pt.ParacrossMinerAction, tx *types.
var
set
types
.
LocalDBSet
txs
:=
e
.
GetTxs
()
cfg
:=
e
.
GetAPI
()
.
GetConfig
()
//removed the 0 vote tx
if
pt
.
IsParaForkHeight
(
payload
.
Status
.
MainBlockHeight
,
pt
.
ForkCommitTx
)
{
err
:=
setMinerTxResultFork
(
payload
.
Status
,
txs
[
1
:
],
e
.
GetReceipt
()[
1
:
])
if
pt
.
IsParaForkHeight
(
cfg
,
payload
.
Status
.
MainBlockHeight
,
pt
.
ForkCommitTx
)
{
err
:=
setMinerTxResultFork
(
cfg
,
payload
.
Status
,
txs
[
1
:
],
e
.
GetReceipt
()[
1
:
])
if
err
!=
nil
{
return
nil
,
err
}
}
else
{
err
:=
setMinerTxResult
(
payload
,
txs
[
1
:
],
e
.
GetReceipt
()[
1
:
])
err
:=
setMinerTxResult
(
cfg
,
payload
,
txs
[
1
:
],
e
.
GetReceipt
()[
1
:
])
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/dapp/paracross/executor/filtertxs.go
View file @
af0be445
...
...
@@ -46,7 +46,7 @@ func checkReceiptExecOk(receipt *types.ReceiptData) bool {
// 1, 主链+平行链 user.p.xx.paracross 交易组 混合跨链资产转移 paracross主链执行成功
// 2, 平行链 user.p.xx.paracross + user.p.xx.other 混合平行链组合 paracross主链执行成功
// 3, 平行链 user.p.xx.other 交易组 混合平行链组合 other主链pack
func
filterParaTxGroup
(
tx
*
types
.
Transaction
,
allTxs
[]
*
types
.
TxDetail
,
index
int
,
blockHeight
,
forkHeight
int64
)
([]
*
types
.
Transaction
,
int
)
{
func
filterParaTxGroup
(
cfg
*
types
.
Chain33Config
,
tx
*
types
.
Transaction
,
allTxs
[]
*
types
.
TxDetail
,
index
int
,
blockHeight
,
forkHeight
int64
)
([]
*
types
.
Transaction
,
int
)
{
var
headIdx
int
for
i
:=
index
;
i
>=
0
;
i
--
{
...
...
@@ -58,7 +58,7 @@ func filterParaTxGroup(tx *types.Transaction, allTxs []*types.TxDetail, index in
endIdx
:=
headIdx
+
int
(
tx
.
GroupCount
)
for
i
:=
headIdx
;
i
<
endIdx
;
i
++
{
if
types
.
IsPara
()
&&
blockHeight
<
forkHeight
{
if
cfg
.
IsPara
()
&&
blockHeight
<
forkHeight
{
if
types
.
IsParaExecName
(
string
(
allTxs
[
i
]
.
Tx
.
Execer
))
{
continue
}
...
...
@@ -77,13 +77,13 @@ func filterParaTxGroup(tx *types.Transaction, allTxs []*types.TxDetail, index in
}
//FilterTxsForPara include some main tx in tx group before ForkParacrossCommitTx
func
FilterTxsForPara
(
main
*
types
.
ParaTxDetail
)
[]
*
types
.
Transaction
{
func
FilterTxsForPara
(
cfg
*
types
.
Chain33Config
,
main
*
types
.
ParaTxDetail
)
[]
*
types
.
Transaction
{
var
txs
[]
*
types
.
Transaction
forkHeight
:=
pt
.
GetDappForkHeight
(
pt
.
ForkCommitTx
)
forkHeight
:=
pt
.
GetDappForkHeight
(
cfg
,
pt
.
ForkCommitTx
)
for
i
:=
0
;
i
<
len
(
main
.
TxDetails
);
i
++
{
tx
:=
main
.
TxDetails
[
i
]
.
Tx
if
tx
.
GroupCount
>=
2
{
mainTxs
,
endIdx
:=
filterParaTxGroup
(
tx
,
main
.
TxDetails
,
i
,
main
.
Header
.
Height
,
forkHeight
)
mainTxs
,
endIdx
:=
filterParaTxGroup
(
cfg
,
tx
,
main
.
TxDetails
,
i
,
main
.
Header
.
Height
,
forkHeight
)
txs
=
append
(
txs
,
mainTxs
...
)
i
=
endIdx
-
1
continue
...
...
plugin/dapp/paracross/executor/query.go
View file @
af0be445
...
...
@@ -94,7 +94,8 @@ func (p *Paracross) Query_GetNodeAddrInfo(in *pt.ReqParacrossNodeInfo) (types.Me
if
err
!=
nil
{
return
nil
,
err
}
if
pt
.
IsParaForkHeight
(
mainHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
cfg
:=
p
.
GetAPI
()
.
GetConfig
()
if
pt
.
IsParaForkHeight
(
cfg
,
mainHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
stat
.
QuitId
=
getParaNodeIDSuffix
(
stat
.
QuitId
)
stat
.
ProposalId
=
getParaNodeIDSuffix
(
stat
.
ProposalId
)
}
...
...
@@ -103,7 +104,8 @@ func (p *Paracross) Query_GetNodeAddrInfo(in *pt.ReqParacrossNodeInfo) (types.Me
func
(
p
*
Paracross
)
getMainHeight
()
(
int64
,
error
)
{
mainHeight
:=
p
.
GetMainHeight
()
if
types
.
IsPara
()
{
cfg
:=
p
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsPara
()
{
block
,
err
:=
p
.
GetAPI
()
.
GetBlocks
(
&
types
.
ReqBlocks
{
Start
:
p
.
GetHeight
(),
End
:
p
.
GetHeight
()})
if
err
!=
nil
||
block
==
nil
||
len
(
block
.
Items
)
==
0
{
return
-
1
,
types
.
ErrBlockExist
...
...
@@ -122,12 +124,13 @@ func (p *Paracross) Query_GetNodeIDInfo(in *pt.ReqParacrossNodeInfo) (types.Mess
if
err
!=
nil
{
return
nil
,
err
}
stat
,
err
:=
getNodeIDWithFork
(
p
.
GetStateDB
(),
in
.
Title
,
mainHeight
,
in
.
Id
)
cfg
:=
p
.
GetAPI
()
.
GetConfig
()
stat
,
err
:=
getNodeIDWithFork
(
cfg
,
p
.
GetStateDB
(),
in
.
Title
,
mainHeight
,
in
.
Id
)
if
err
!=
nil
{
return
nil
,
err
}
if
pt
.
IsParaForkHeight
(
mainHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
if
pt
.
IsParaForkHeight
(
cfg
,
mainHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
stat
.
Id
=
getParaNodeIDSuffix
(
stat
.
Id
)
}
return
stat
,
nil
...
...
@@ -146,7 +149,8 @@ func (p *Paracross) Query_ListNodeStatusInfo(in *pt.ReqParacrossNodeInfo) (types
if
err
!=
nil
{
return
nil
,
err
}
if
!
pt
.
IsParaForkHeight
(
mainHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
cfg
:=
p
.
GetAPI
()
.
GetConfig
()
if
!
pt
.
IsParaForkHeight
(
cfg
,
mainHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
return
resp
,
err
}
addrs
:=
resp
.
(
*
pt
.
RespParacrossNodeAddrs
)
...
...
@@ -169,7 +173,8 @@ func (p *Paracross) Query_GetNodeGroupStatus(in *pt.ReqParacrossNodeInfo) (types
if
err
!=
nil
{
return
nil
,
err
}
if
pt
.
IsParaForkHeight
(
mainHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
cfg
:=
p
.
GetAPI
()
.
GetConfig
()
if
pt
.
IsParaForkHeight
(
cfg
,
mainHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
stat
.
Id
=
getParaNodeIDSuffix
(
stat
.
Id
)
}
return
stat
,
nil
...
...
@@ -188,7 +193,8 @@ func (p *Paracross) Query_ListNodeGroupStatus(in *pt.ReqParacrossNodeInfo) (type
if
err
!=
nil
{
return
nil
,
err
}
if
pt
.
IsParaForkHeight
(
mainHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
cfg
:=
p
.
GetAPI
()
.
GetConfig
()
if
pt
.
IsParaForkHeight
(
cfg
,
mainHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
addrs
:=
resp
.
(
*
pt
.
RespParacrossNodeGroups
)
for
_
,
id
:=
range
addrs
.
Ids
{
id
.
Id
=
getParaNodeIDSuffix
(
id
.
Id
)
...
...
plugin/dapp/paracross/executor/reward.go
View file @
af0be445
...
...
@@ -11,9 +11,10 @@ import (
func
(
a
*
action
)
reward
(
nodeStatus
*
pt
.
ParacrossNodeStatus
,
stat
*
pt
.
ParacrossHeightStatus
)
(
*
types
.
Receipt
,
error
)
{
//获取挖矿相关配置,这里需注意是共识的高度,而不是交易的高度
coinReward
:=
types
.
MGInt
(
"mver.consensus.paracross.coinReward"
,
nodeStatus
.
Height
)
*
types
.
Coin
fundReward
:=
types
.
MGInt
(
"mver.consensus.paracross.coinDevFund"
,
nodeStatus
.
Height
)
*
types
.
Coin
fundAddr
:=
types
.
MGStr
(
"mver.consensus.fundKeyAddr"
,
nodeStatus
.
Height
)
cfg
:=
a
.
api
.
GetConfig
()
coinReward
:=
cfg
.
MGInt
(
"mver.consensus.paracross.coinReward"
,
nodeStatus
.
Height
)
*
types
.
Coin
fundReward
:=
cfg
.
MGInt
(
"mver.consensus.paracross.coinDevFund"
,
nodeStatus
.
Height
)
*
types
.
Coin
fundAddr
:=
cfg
.
MGStr
(
"mver.consensus.fundKeyAddr"
,
nodeStatus
.
Height
)
minerAddrs
:=
getMiners
(
stat
.
Details
,
nodeStatus
.
BlockHash
)
//分配给矿工的单位奖励
...
...
plugin/dapp/paracross/executor/superaccount.go
View file @
af0be445
...
...
@@ -21,10 +21,6 @@ import (
"github.com/pkg/errors"
)
var
(
confManager
=
types
.
ConfSub
(
manager
.
ManageX
)
conf
=
types
.
ConfSub
(
pt
.
ParaX
)
)
func
deepCopy
(
dst
,
src
interface
{})
error
{
var
buf
bytes
.
Buffer
...
...
@@ -58,8 +54,8 @@ func getNodeID(db dbm.KV, id string) (*pt.ParaNodeIdStatus, error) {
}
//分叉之前 id是"mavl-paracros-...0x12342308b"格式,分叉以后只支持输入为去掉了mavl-paracross前缀的交易id,系统会为id加上前缀
func
getNodeIDWithFork
(
db
dbm
.
KV
,
title
string
,
height
int64
,
id
string
)
(
*
pt
.
ParaNodeIdStatus
,
error
)
{
if
pt
.
IsParaForkHeight
(
height
,
pt
.
ForkLoopCheckCommitTxDone
)
{
func
getNodeIDWithFork
(
cfg
*
types
.
Chain33Config
,
db
dbm
.
KV
,
title
string
,
height
int64
,
id
string
)
(
*
pt
.
ParaNodeIdStatus
,
error
)
{
if
pt
.
IsParaForkHeight
(
cfg
,
height
,
pt
.
ForkLoopCheckCommitTxDone
)
{
id
=
calcParaNodeIDKey
(
title
,
id
)
}
return
getNodeID
(
db
,
id
)
...
...
@@ -86,8 +82,8 @@ func getDb(db dbm.KV, key []byte) ([]byte, error) {
}
//分叉之前 id是"mavl-paracros-...0x12342308b"格式,分叉以后只支持输入为去掉了mavl-paracross前缀的交易id,系统会为id加上前缀
func
getNodeGroupID
(
db
dbm
.
KV
,
title
string
,
height
int64
,
id
string
)
(
*
pt
.
ParaNodeGroupStatus
,
error
)
{
if
pt
.
IsParaForkHeight
(
height
,
pt
.
ForkLoopCheckCommitTxDone
)
{
func
getNodeGroupID
(
cfg
*
types
.
Chain33Config
,
db
dbm
.
KV
,
title
string
,
height
int64
,
id
string
)
(
*
pt
.
ParaNodeGroupStatus
,
error
)
{
if
pt
.
IsParaForkHeight
(
cfg
,
height
,
pt
.
ForkLoopCheckCommitTxDone
)
{
id
=
calcParaNodeGroupIDKey
(
title
,
id
)
}
val
,
err
:=
getDb
(
db
,
[]
byte
(
id
))
...
...
@@ -255,7 +251,8 @@ func (a *action) nodeJoin(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
if
!
types
.
IsPara
()
{
cfg
:=
a
.
api
.
GetConfig
()
if
!
cfg
.
IsPara
()
{
r
,
err
:=
a
.
nodeGroupCoinsFrozen
(
a
.
fromaddr
,
config
.
CoinsFrozen
,
1
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -317,7 +314,8 @@ func (a *action) nodeQuit(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
}
func
(
a
*
action
)
nodeCancel
(
config
*
pt
.
ParaNodeAddrConfig
)
(
*
types
.
Receipt
,
error
)
{
stat
,
err
:=
getNodeIDWithFork
(
a
.
db
,
config
.
Title
,
a
.
exec
.
GetMainHeight
(),
config
.
Id
)
cfg
:=
a
.
api
.
GetConfig
()
stat
,
err
:=
getNodeIDWithFork
(
cfg
,
a
.
db
,
config
.
Title
,
a
.
exec
.
GetMainHeight
(),
config
.
Id
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -343,7 +341,8 @@ func (a *action) nodeCancel(config *pt.ParaNodeAddrConfig) (*types.Receipt, erro
}
if
stat
.
Status
==
pt
.
ParacrossNodeJoining
{
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
if
!
types
.
IsPara
()
{
cfg
:=
a
.
api
.
GetConfig
()
if
!
cfg
.
IsPara
()
{
r
,
err
:=
a
.
nodeGroupCoinsActive
(
stat
.
FromAddr
,
stat
.
CoinsFrozen
,
1
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -368,7 +367,8 @@ func (a *action) nodeCancel(config *pt.ParaNodeAddrConfig) (*types.Receipt, erro
}
// IsSuperManager is supper manager or not
func
isSuperManager
(
addr
string
)
bool
{
func
isSuperManager
(
cfg
*
types
.
Chain33Config
,
addr
string
)
bool
{
confManager
:=
types
.
ConfSub
(
cfg
,
manager
.
ManageX
)
for
_
,
m
:=
range
confManager
.
GStrList
(
"superManager"
)
{
if
addr
==
m
{
return
true
...
...
@@ -403,7 +403,8 @@ func (a *action) superManagerVoteProc(title string) error {
if
err
!=
nil
{
return
err
}
cfg
:=
a
.
api
.
GetConfig
()
conf
:=
types
.
ConfSub
(
cfg
,
pt
.
ParaX
)
confStopBlocks
:=
conf
.
GInt
(
"paraConsensusStopBlocks"
)
data
,
err
:=
a
.
exec
.
paracrossGetHeight
(
title
)
if
err
!=
nil
{
...
...
@@ -444,6 +445,7 @@ func updateVotes(stat *pt.ParaNodeIdStatus, nodes map[string]struct{}) {
}
func
(
a
*
action
)
updateNodeAddrStatus
(
stat
*
pt
.
ParaNodeIdStatus
)
(
*
types
.
Receipt
,
error
)
{
cfg
:=
a
.
api
.
GetConfig
()
addrStat
,
err
:=
getNodeAddr
(
a
.
db
,
stat
.
Title
,
stat
.
TargetAddr
)
if
err
!=
nil
{
if
!
isNotFound
(
err
)
{
...
...
@@ -476,7 +478,7 @@ func (a *action) updateNodeAddrStatus(stat *pt.ParaNodeIdStatus) (*types.Receipt
addrStat
.
QuitId
=
stat
.
Id
receipt
:=
makeParaNodeStatusReceipt
(
a
.
fromaddr
,
&
preStat
,
addrStat
)
if
!
types
.
IsPara
()
{
if
!
cfg
.
IsPara
()
{
r
,
err
:=
a
.
nodeGroupCoinsActive
(
proposalStat
.
FromAddr
,
proposalStat
.
CoinsFrozen
,
1
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -494,11 +496,12 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"getNodes for title:%s"
,
config
.
Title
)
}
if
!
validNode
(
a
.
fromaddr
,
nodes
)
&&
!
isSuperManager
(
a
.
fromaddr
)
{
cfg
:=
a
.
api
.
GetConfig
()
if
!
validNode
(
a
.
fromaddr
,
nodes
)
&&
!
isSuperManager
(
cfg
,
a
.
fromaddr
)
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrNodeNotForTheTitle
,
"not validNode:%s"
,
a
.
fromaddr
)
}
stat
,
err
:=
getNodeIDWithFork
(
a
.
db
,
config
.
Title
,
a
.
exec
.
GetMainHeight
(),
config
.
Id
)
stat
,
err
:=
getNodeIDWithFork
(
cfg
,
a
.
db
,
config
.
Title
,
a
.
exec
.
GetMainHeight
(),
config
.
Id
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -541,9 +544,9 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
most
,
vote
:=
getMostVote
(
stat
)
if
!
isCommitDone
(
nodes
,
most
)
{
superManagerPass
:=
false
if
isSuperManager
(
a
.
fromaddr
)
{
if
isSuperManager
(
cfg
,
a
.
fromaddr
)
{
//如果主链执行失败,交易不会过滤到平行链,如果主链成功,平行链直接成功
if
!
types
.
IsPara
()
{
if
!
cfg
.
IsPara
()
{
err
:=
a
.
superManagerVoteProc
(
config
.
Title
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -565,7 +568,7 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
stat
.
Status
=
pt
.
ParacrossNodeClosed
stat
.
Height
=
a
.
height
//active coins
if
!
types
.
IsPara
()
{
if
!
cfg
.
IsPara
()
{
r
,
err
:=
a
.
nodeGroupCoinsActive
(
stat
.
FromAddr
,
stat
.
CoinsFrozen
,
1
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -606,7 +609,7 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
}
receipt
=
mergeReceipt
(
receipt
,
r
)
if
a
.
exec
.
GetMainHeight
()
>
pt
.
GetDappForkHeight
(
pt
.
ForkLoopCheckCommitTxDone
)
{
if
a
.
exec
.
GetMainHeight
()
>
pt
.
GetDappForkHeight
(
cfg
,
pt
.
ForkLoopCheckCommitTxDone
)
{
//node quit后,如果committx满足2/3目标,自动触发commitDone
r
,
err
=
a
.
loopCommitTxDone
(
config
.
Title
)
if
err
!=
nil
{
...
...
@@ -715,6 +718,8 @@ func (a *action) checkNodeGroupExist(title string) error {
func
(
a
*
action
)
nodeGroupCoinsFrozen
(
createAddr
string
,
configCoinsFrozen
int64
,
nodeCounts
int64
)
(
*
types
.
Receipt
,
error
)
{
receipt
:=
&
types
.
Receipt
{}
cfg
:=
a
.
api
.
GetConfig
()
conf
:=
types
.
ConfSub
(
cfg
,
pt
.
ParaX
)
confCoins
:=
conf
.
GInt
(
"nodeGroupFrozenCoins"
)
if
configCoinsFrozen
<
confCoins
{
return
nil
,
pt
.
ErrParaNodeGroupFrozenCoinsNotEnough
...
...
@@ -771,7 +776,8 @@ func (a *action) nodeGroupApply(config *pt.ParaNodeGroupConfig) (*types.Receipt,
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
//main chain
if
!
types
.
IsPara
()
{
cfg
:=
a
.
api
.
GetConfig
()
if
!
cfg
.
IsPara
()
{
r
,
err
:=
a
.
nodeGroupCoinsFrozen
(
a
.
fromaddr
,
config
.
CoinsFrozen
,
int64
(
len
(
addrs
)))
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -812,7 +818,8 @@ func (a *action) nodeGroupModify(config *pt.ParaNodeGroupConfig) (*types.Receipt
}
func
(
a
*
action
)
nodeGroupQuit
(
config
*
pt
.
ParaNodeGroupConfig
)
(
*
types
.
Receipt
,
error
)
{
status
,
err
:=
getNodeGroupID
(
a
.
db
,
config
.
Title
,
a
.
exec
.
GetMainHeight
(),
config
.
Id
)
cfg
:=
a
.
api
.
GetConfig
()
status
,
err
:=
getNodeGroupID
(
cfg
,
a
.
db
,
config
.
Title
,
a
.
exec
.
GetMainHeight
(),
config
.
Id
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -835,7 +842,7 @@ func (a *action) nodeGroupQuit(config *pt.ParaNodeGroupConfig) (*types.Receipt,
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
//main chain
if
!
types
.
IsPara
()
{
if
!
cfg
.
IsPara
()
{
r
,
err
:=
a
.
nodeGroupCoinsActive
(
status
.
FromAddr
,
status
.
CoinsFrozen
,
int64
(
len
(
applyAddrs
)))
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -927,11 +934,12 @@ func (a *action) nodeGroupApproveApply(config *pt.ParaNodeGroupConfig, apply *pt
// NodeGroupApprove super addr approve the node group apply
func
(
a
*
action
)
nodeGroupApprove
(
config
*
pt
.
ParaNodeGroupConfig
)
(
*
types
.
Receipt
,
error
)
{
if
!
isSuperManager
(
a
.
fromaddr
)
{
cfg
:=
a
.
api
.
GetConfig
()
if
!
isSuperManager
(
cfg
,
a
.
fromaddr
)
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrNotAllow
,
"node group approve not super manager:%s"
,
a
.
fromaddr
)
}
id
,
err
:=
getNodeGroupID
(
a
.
db
,
config
.
Title
,
a
.
exec
.
GetMainHeight
(),
config
.
Id
)
id
,
err
:=
getNodeGroupID
(
cfg
,
a
.
db
,
config
.
Title
,
a
.
exec
.
GetMainHeight
(),
config
.
Id
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -992,7 +1000,8 @@ func (a *action) nodeGroupCreate(status *pt.ParaNodeGroupStatus) (*types.Receipt
//NodeGroupConfig support super node group config
func
(
a
*
action
)
NodeGroupConfig
(
config
*
pt
.
ParaNodeGroupConfig
)
(
*
types
.
Receipt
,
error
)
{
if
!
validTitle
(
config
.
Title
)
{
cfg
:=
a
.
api
.
GetConfig
()
if
!
validTitle
(
cfg
,
config
.
Title
)
{
return
nil
,
pt
.
ErrInvalidTitle
}
...
...
@@ -1029,7 +1038,8 @@ func (a *action) NodeGroupConfig(config *pt.ParaNodeGroupConfig) (*types.Receipt
//NodeConfig support super account node config
func
(
a
*
action
)
NodeConfig
(
config
*
pt
.
ParaNodeAddrConfig
)
(
*
types
.
Receipt
,
error
)
{
if
!
validTitle
(
config
.
Title
)
{
cfg
:=
a
.
api
.
GetConfig
()
if
!
validTitle
(
cfg
,
config
.
Title
)
{
return
nil
,
pt
.
ErrInvalidTitle
}
...
...
plugin/dapp/paracross/rpc/rpc.go
View file @
af0be445
...
...
@@ -13,7 +13,8 @@ import (
)
func
(
c
*
channelClient
)
GetTitle
(
ctx
context
.
Context
,
req
*
types
.
ReqString
)
(
*
pt
.
ParacrossConsensusStatus
,
error
)
{
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetTitle"
,
req
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(
cfg
),
"GetTitle"
,
req
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -25,7 +26,7 @@ func (c *channelClient) GetTitle(ctx context.Context, req *types.ReqString) (*pt
if
resp
,
ok
:=
data
.
(
*
pt
.
ParacrossStatus
);
ok
{
// 如果主链上查询平行链的高度,chain height应该是平行链的高度而不是主链高度, 平行链的真实高度需要在平行链侧查询
if
!
types
.
IsPara
()
{
if
!
cfg
.
IsPara
()
{
chainHeight
=
resp
.
Height
}
return
&
pt
.
ParacrossConsensusStatus
{
...
...
@@ -40,9 +41,10 @@ func (c *channelClient) GetTitle(ctx context.Context, req *types.ReqString) (*pt
// GetHeight jrpc get consensus height
func
(
c
*
Jrpc
)
GetHeight
(
req
*
types
.
ReqString
,
result
*
interface
{})
error
{
cfg
:=
c
.
cli
.
GetConfig
()
if
req
==
nil
||
req
.
Data
==
""
{
if
types
.
IsPara
()
{
req
=
&
types
.
ReqString
{
Data
:
types
.
GetTitle
()}
if
cfg
.
IsPara
()
{
req
=
&
types
.
ReqString
{
Data
:
cfg
.
GetTitle
()}
}
else
{
return
types
.
ErrInvalidParam
}
...
...
@@ -58,7 +60,8 @@ func (c *Jrpc) GetHeight(req *types.ReqString, result *interface{}) error {
}
func
(
c
*
channelClient
)
ListTitles
(
ctx
context
.
Context
,
req
*
types
.
ReqNil
)
(
*
pt
.
RespParacrossTitles
,
error
)
{
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"ListTitles"
,
req
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(
cfg
),
"ListTitles"
,
req
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -79,7 +82,8 @@ func (c *Jrpc) ListTitles(req *types.ReqNil, result *interface{}) error {
}
func
(
c
*
channelClient
)
GetTitleHeight
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossTitleHeight
)
(
*
pt
.
ParacrossHeightStatusRsp
,
error
)
{
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetTitleHeight"
,
req
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(
cfg
),
"GetTitleHeight"
,
req
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -103,7 +107,8 @@ func (c *Jrpc) GetTitleHeight(req *pt.ReqParacrossTitleHeight, result *interface
}
func
(
c
*
channelClient
)
GetDoneTitleHeight
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossTitleHeight
)
(
*
pt
.
RespParacrossDone
,
error
)
{
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetDoneTitleHeight"
,
req
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(
cfg
),
"GetDoneTitleHeight"
,
req
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -114,7 +119,8 @@ func (c *channelClient) GetDoneTitleHeight(ctx context.Context, req *pt.ReqParac
}
func
(
c
*
channelClient
)
GetAssetTxResult
(
ctx
context
.
Context
,
req
*
types
.
ReqHash
)
(
*
pt
.
ParacrossAsset
,
error
)
{
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetAssetTxResult"
,
req
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(
cfg
),
"GetAssetTxResult"
,
req
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -185,11 +191,11 @@ func (c *channelClient) GetBlock2MainInfo(ctx context.Context, req *types.ReqBlo
if
err
!=
nil
{
return
nil
,
err
}
cfg
:=
c
.
GetConfig
()
for
_
,
item
:=
range
details
.
Items
{
data
:=
&
pt
.
ParaBlock2MainMap
{
Height
:
item
.
Block
.
Height
,
BlockHash
:
common
.
ToHex
(
item
.
Block
.
Hash
()),
BlockHash
:
common
.
ToHex
(
item
.
Block
.
Hash
(
cfg
)),
MainHeight
:
item
.
Block
.
MainHeight
,
MainHash
:
common
.
ToHex
(
item
.
Block
.
MainHash
),
}
...
...
@@ -216,7 +222,8 @@ func (c *Jrpc) GetBlock2MainInfo(req *types.ReqBlocks, result *interface{}) erro
// GetNodeAddrStatus get super node status
func
(
c
*
channelClient
)
GetNodeAddrStatus
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossNodeInfo
)
(
*
pt
.
ParaNodeAddrIdStatus
,
error
)
{
r
:=
*
req
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetNodeAddrInfo"
,
&
r
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(
cfg
),
"GetNodeAddrInfo"
,
&
r
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -229,7 +236,8 @@ func (c *channelClient) GetNodeAddrStatus(ctx context.Context, req *pt.ReqParacr
// GetNodeIDStatus get super node status
func
(
c
*
channelClient
)
GetNodeIDStatus
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossNodeInfo
)
(
*
pt
.
ParaNodeIdStatus
,
error
)
{
r
:=
*
req
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetNodeIDInfo"
,
&
r
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(
cfg
),
"GetNodeIDInfo"
,
&
r
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -270,7 +278,8 @@ func (c *Jrpc) GetNodeIDStatus(req *pt.ReqParacrossNodeInfo, result *interface{}
//ListNodeStatus list super node by status
func
(
c
*
channelClient
)
ListNodeStatus
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossNodeInfo
)
(
*
pt
.
RespParacrossNodeAddrs
,
error
)
{
r
:=
*
req
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"ListNodeStatusInfo"
,
&
r
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(
cfg
),
"ListNodeStatusInfo"
,
&
r
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -293,7 +302,8 @@ func (c *Jrpc) ListNodeStatus(req *pt.ReqParacrossNodeInfo, result *interface{})
// GetNodeGroupAddrs get super node group addrs
func
(
c
*
channelClient
)
GetNodeGroupAddrs
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossNodeInfo
)
(
*
types
.
ReplyConfig
,
error
)
{
r
:=
*
req
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetNodeGroupAddrs"
,
&
r
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(
cfg
),
"GetNodeGroupAddrs"
,
&
r
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -316,7 +326,8 @@ func (c *Jrpc) GetNodeGroupAddrs(req *pt.ReqParacrossNodeInfo, result *interface
// GetNodeGroupStatus get super node group status
func
(
c
*
channelClient
)
GetNodeGroupStatus
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossNodeInfo
)
(
*
pt
.
ParaNodeGroupStatus
,
error
)
{
r
:=
*
req
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"GetNodeGroupStatus"
,
&
r
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(
cfg
),
"GetNodeGroupStatus"
,
&
r
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -339,7 +350,8 @@ func (c *Jrpc) GetNodeGroupStatus(req *pt.ReqParacrossNodeInfo, result *interfac
//ListNodeGroupStatus list super node group by status
func
(
c
*
channelClient
)
ListNodeGroupStatus
(
ctx
context
.
Context
,
req
*
pt
.
ReqParacrossNodeInfo
)
(
*
pt
.
RespParacrossNodeGroups
,
error
)
{
r
:=
*
req
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(),
"ListNodeGroupStatus"
,
&
r
)
cfg
:=
c
.
GetConfig
()
data
,
err
:=
c
.
Query
(
pt
.
GetExecName
(
cfg
),
"ListNodeGroupStatus"
,
&
r
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/dapp/privacy/wallet/exec.go
View file @
af0be445
...
...
@@ -40,9 +40,10 @@ func (policy *privacyPolicy) On_CreateTransaction(req *privacytypes.ReqCreatePri
return
nil
,
err
}
cfg
:=
policy
.
getWalletOperate
()
.
GetAPI
()
.
GetConfig
()
//为空时增加自动设置
if
req
.
GetAssetExec
()
==
"coins"
&&
req
.
GetTokenname
()
==
""
{
req
.
Tokenname
=
types
.
GetCoinSymbol
()
req
.
Tokenname
=
cfg
.
GetCoinSymbol
()
}
if
req
.
AssetExec
==
""
||
req
.
Tokenname
==
""
{
...
...
plugin/dapp/privacy/wallet/privacy.go
View file @
af0be445
...
...
@@ -526,24 +526,24 @@ func (policy *privacyPolicy) createPublic2PrivacyTx(req *privacytypes.ReqCreateP
Output
:
privacyOutput
,
AssetExec
:
req
.
GetAssetExec
(),
}
cfg
:=
policy
.
getWalletOperate
()
.
GetAPI
()
.
GetConfig
()
action
:=
&
privacytypes
.
PrivacyAction
{
Ty
:
privacytypes
.
ActionPublic2Privacy
,
Value
:
&
privacytypes
.
PrivacyAction_Public2Privacy
{
Public2Privacy
:
value
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
privacytypes
.
PrivacyX
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
privacytypes
.
PrivacyX
)),
Payload
:
types
.
Encode
(
action
),
Nonce
:
policy
.
getWalletOperate
()
.
Nonce
(),
To
:
address
.
ExecAddress
(
types
.
ExecName
(
privacytypes
.
PrivacyX
)),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
privacytypes
.
PrivacyX
)),
}
tx
.
SetExpire
(
time
.
Duration
(
req
.
Expire
))
tx
.
SetExpire
(
cfg
,
time
.
Duration
(
req
.
Expire
))
tx
.
Signature
=
&
types
.
Signature
{
Signature
:
types
.
Encode
(
&
privacytypes
.
PrivacySignatureParam
{
ActionType
:
action
.
Ty
,
}),
}
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
types
.
GInt
(
"MinFee"
))
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
cfg
.
GInt
(
"MinFee"
))
if
err
!=
nil
{
bizlog
.
Error
(
"createPublic2PrivacyTx"
,
"calc fee failed"
,
err
)
return
nil
,
err
...
...
@@ -556,7 +556,8 @@ func (policy *privacyPolicy) createPrivacy2PrivacyTx(req *privacytypes.ReqCreate
//需要燃烧的utxo
var
utxoBurnedAmount
int64
isMainetCoins
:=
!
types
.
IsPara
()
&&
(
req
.
AssetExec
==
"coins"
)
cfg
:=
policy
.
getWalletOperate
()
.
GetAPI
()
.
GetConfig
()
isMainetCoins
:=
!
cfg
.
IsPara
()
&&
(
req
.
AssetExec
==
"coins"
)
if
isMainetCoins
{
utxoBurnedAmount
=
privacytypes
.
PrivacyTxFee
}
...
...
@@ -613,15 +614,15 @@ func (policy *privacyPolicy) createPrivacy2PrivacyTx(req *privacytypes.ReqCreate
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
privacytypes
.
PrivacyX
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
privacytypes
.
PrivacyX
)),
Payload
:
types
.
Encode
(
action
),
Fee
:
privacytypes
.
PrivacyTxFee
,
Nonce
:
policy
.
getWalletOperate
()
.
Nonce
(),
To
:
address
.
ExecAddress
(
types
.
ExecName
(
privacytypes
.
PrivacyX
)),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
privacytypes
.
PrivacyX
)),
}
tx
.
SetExpire
(
time
.
Duration
(
req
.
Expire
))
tx
.
SetExpire
(
cfg
,
time
.
Duration
(
req
.
Expire
))
if
!
isMainetCoins
{
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
types
.
GInt
(
"MinFee"
))
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
cfg
.
GInt
(
"MinFee"
))
if
err
!=
nil
{
bizlog
.
Error
(
"createPrivacy2PrivacyTx"
,
"calc fee failed"
,
err
)
return
nil
,
err
...
...
@@ -645,7 +646,8 @@ func (policy *privacyPolicy) createPrivacy2PublicTx(req *privacytypes.ReqCreateP
//需要燃烧的utxo
//需要燃烧的utxo
var
utxoBurnedAmount
int64
isMainetCoins
:=
!
types
.
IsPara
()
&&
(
req
.
AssetExec
==
"coins"
)
cfg
:=
policy
.
getWalletOperate
()
.
GetAPI
()
.
GetConfig
()
isMainetCoins
:=
!
cfg
.
IsPara
()
&&
(
req
.
AssetExec
==
"coins"
)
if
isMainetCoins
{
utxoBurnedAmount
=
privacytypes
.
PrivacyTxFee
}
...
...
@@ -701,15 +703,15 @@ func (policy *privacyPolicy) createPrivacy2PublicTx(req *privacytypes.ReqCreateP
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
privacytypes
.
PrivacyX
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
privacytypes
.
PrivacyX
)),
Payload
:
types
.
Encode
(
action
),
Fee
:
privacytypes
.
PrivacyTxFee
,
Nonce
:
policy
.
getWalletOperate
()
.
Nonce
(),
To
:
address
.
ExecAddress
(
types
.
ExecName
(
privacytypes
.
PrivacyX
)),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
privacytypes
.
PrivacyX
)),
}
tx
.
SetExpire
(
time
.
Duration
(
req
.
Expire
))
tx
.
SetExpire
(
cfg
,
time
.
Duration
(
req
.
Expire
))
if
!
isMainetCoins
{
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
types
.
GInt
(
"MinFee"
))
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
cfg
.
GInt
(
"MinFee"
))
if
err
!=
nil
{
bizlog
.
Error
(
"createPrivacy2PublicTx"
,
"calc fee failed"
,
err
)
return
nil
,
err
...
...
@@ -812,7 +814,8 @@ func (policy *privacyPolicy) reqUtxosByAddr(addrs []string) {
}
policy
.
store
.
saveREscanUTXOsAddresses
(
storeAddrs
)
reqAddr
:=
address
.
ExecAddress
(
types
.
ExecName
(
privacytypes
.
PrivacyX
))
cfg
:=
policy
.
getWalletOperate
()
.
GetAPI
()
.
GetConfig
()
reqAddr
:=
address
.
ExecAddress
(
cfg
.
ExecName
(
privacytypes
.
PrivacyX
))
var
txInfo
types
.
ReplyTxInfo
i
:=
0
operater
:=
policy
.
getWalletOperate
()
...
...
@@ -836,7 +839,7 @@ func (policy *privacyPolicy) reqUtxosByAddr(addrs []string) {
}
else
{
ReqAddr
.
Height
=
txInfo
.
GetHeight
()
ReqAddr
.
Index
=
txInfo
.
GetIndex
()
if
!
types
.
IsDappFork
(
ReqAddr
.
Height
,
privacytypes
.
PrivacyX
,
"ForkV21Privacy"
)
{
// 小于隐私分叉高度不做扫描
if
!
cfg
.
IsDappFork
(
ReqAddr
.
Height
,
privacytypes
.
PrivacyX
,
"ForkV21Privacy"
)
{
// 小于隐私分叉高度不做扫描
break
}
}
...
...
@@ -947,13 +950,13 @@ func (policy *privacyPolicy) signatureTx(tx *types.Transaction, privacyInput *pr
}
ringSign
.
Items
[
i
]
=
item
}
cfg
:=
policy
.
getWalletOperate
()
.
GetAPI
()
.
GetConfig
()
ringSignData
:=
types
.
Encode
(
ringSign
)
tx
.
Signature
=
&
types
.
Signature
{
Ty
:
privacytypes
.
RingBaseonED25519
,
Signature
:
ringSignData
,
// 这里填的是隐私合约的公钥,让框架保持一致
Pubkey
:
address
.
ExecPubKey
(
types
.
ExecName
(
privacytypes
.
PrivacyX
)),
Pubkey
:
address
.
ExecPubKey
(
cfg
.
ExecName
(
privacytypes
.
PrivacyX
)),
}
return
nil
}
...
...
@@ -1048,6 +1051,7 @@ func (policy *privacyPolicy) addDelPrivacyTxsFromBlock(tx *types.Transaction, in
return
}
cfg
:=
policy
.
getWalletOperate
()
.
GetAPI
()
.
GetConfig
()
txExecRes
:=
block
.
Receipts
[
index
]
.
Ty
var
privateAction
privacytypes
.
PrivacyAction
if
err
:=
types
.
Decode
(
tx
.
GetPayload
(),
&
privateAction
);
err
!=
nil
{
...
...
@@ -1101,7 +1105,7 @@ func (policy *privacyPolicy) addDelPrivacyTxsFromBlock(tx *types.Transaction, in
Owner
:
*
info
.
Addr
,
Height
:
block
.
Block
.
Height
,
Txindex
:
index
,
Blockhash
:
block
.
Block
.
Hash
(),
Blockhash
:
block
.
Block
.
Hash
(
cfg
),
}
utxoGlobalIndex
:=
&
privacytypes
.
UTXOGlobalIndex
{
...
...
plugin/dapp/relay/executor/relay.go
View file @
af0be445
...
...
@@ -15,7 +15,6 @@ import (
var
relaylog
=
log
.
New
(
"module"
,
"execs.relay"
)
var
driverName
=
"relay"
var
subconfig
=
types
.
ConfSub
(
driverName
)
// Init relay register driver
...
...
plugin/dapp/relay/executor/relaydb.go
View file @
af0be445
...
...
@@ -15,6 +15,7 @@ import (
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
ty
"github.com/33cn/plugin/plugin/dapp/relay/types"
"github.com/33cn/chain33/client"
)
const
(
...
...
@@ -90,6 +91,7 @@ type relayDB struct {
height
int64
execAddr
string
btc
*
btcStore
api
client
.
QueueProtocolAPI
}
func
newRelayDB
(
r
*
relay
,
tx
*
types
.
Transaction
)
*
relayDB
{
...
...
@@ -97,7 +99,7 @@ func newRelayDB(r *relay, tx *types.Transaction) *relayDB {
fromAddr
:=
tx
.
From
()
btc
:=
newBtcStore
(
r
.
GetLocalDB
())
return
&
relayDB
{
r
.
GetCoinsAccount
(),
r
.
GetStateDB
(),
hash
,
fromAddr
,
r
.
GetBlockTime
(),
r
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
)),
btc
}
fromAddr
,
r
.
GetBlockTime
(),
r
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
)),
btc
,
r
.
GetAPI
()
}
}
func
(
action
*
relayDB
)
getOrderByID
(
orderID
[]
byte
)
(
*
ty
.
RelayOrder
,
error
)
{
...
...
@@ -676,6 +678,8 @@ func (action *relayDB) saveBtcHeader(headers *ty.BtcHeaders, localDb dbm.KVDB) (
var
preHead
=
&
ty
.
RelayLastRcvBtcHeader
{}
var
receipt
=
&
ty
.
ReceiptRelayRcvBTCHeaders
{}
cfg
:=
action
.
api
.
GetConfig
()
subconfig
:=
types
.
ConfSub
(
cfg
,
driverName
)
if
action
.
fromAddr
!=
subconfig
.
GStr
(
"genesis"
)
{
return
nil
,
types
.
ErrFromAddr
}
...
...
plugin/dapp/relay/rpc/rpc.go
View file @
af0be445
...
...
@@ -11,37 +11,37 @@ import (
ty
"github.com/33cn/plugin/plugin/dapp/relay/types"
)
func
createRawRelayOrderTx
(
parm
*
ty
.
RelayCreate
)
([]
byte
,
error
)
{
func
createRawRelayOrderTx
(
cfg
*
types
.
Chain33Config
,
parm
*
ty
.
RelayCreate
)
([]
byte
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
v
:=
*
parm
return
types
.
CallCreateTx
(
types
.
ExecName
(
ty
.
RelayX
),
"Create"
,
&
v
)
return
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
ty
.
RelayX
),
"Create"
,
&
v
)
}
func
createRawRelayAcceptTx
(
parm
*
ty
.
RelayAccept
)
([]
byte
,
error
)
{
func
createRawRelayAcceptTx
(
cfg
*
types
.
Chain33Config
,
parm
*
ty
.
RelayAccept
)
([]
byte
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
return
types
.
CallCreateTx
(
types
.
ExecName
(
ty
.
RelayX
),
"Accept"
,
parm
)
return
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
ty
.
RelayX
),
"Accept"
,
parm
)
}
func
createRawRelayRevokeTx
(
parm
*
ty
.
RelayRevoke
)
([]
byte
,
error
)
{
func
createRawRelayRevokeTx
(
cfg
*
types
.
Chain33Config
,
parm
*
ty
.
RelayRevoke
)
([]
byte
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
return
types
.
CallCreateTx
(
types
.
ExecName
(
ty
.
RelayX
),
"Revoke"
,
parm
)
return
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
ty
.
RelayX
),
"Revoke"
,
parm
)
}
func
createRawRelayConfirmTx
(
parm
*
ty
.
RelayConfirmTx
)
([]
byte
,
error
)
{
func
createRawRelayConfirmTx
(
cfg
*
types
.
Chain33Config
,
parm
*
ty
.
RelayConfirmTx
)
([]
byte
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
return
types
.
CallCreateTx
(
types
.
ExecName
(
ty
.
RelayX
),
"ConfirmTx"
,
parm
)
return
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
ty
.
RelayX
),
"ConfirmTx"
,
parm
)
}
func
createRawRelaySaveBTCHeadTx
(
parm
*
ty
.
BtcHeader
)
([]
byte
,
error
)
{
func
createRawRelaySaveBTCHeadTx
(
cfg
*
types
.
Chain33Config
,
parm
*
ty
.
BtcHeader
)
([]
byte
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -59,12 +59,13 @@ func createRawRelaySaveBTCHeadTx(parm *ty.BtcHeader) ([]byte, error) {
v
:=
&
ty
.
BtcHeaders
{}
v
.
BtcHeader
=
append
(
v
.
BtcHeader
,
head
)
return
types
.
CallCreateTx
(
types
.
ExecName
(
ty
.
RelayX
),
"BtcHeaders"
,
v
)
return
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
ty
.
RelayX
),
"BtcHeaders"
,
v
)
}
//CreateRawRelayOrderTx jrpc create raw relay order
func
(
c
*
Jrpc
)
CreateRawRelayOrderTx
(
in
*
ty
.
RelayCreate
,
result
*
interface
{})
error
{
reply
,
err
:=
createRawRelayOrderTx
(
in
)
cfg
:=
c
.
cli
.
GetConfig
()
reply
,
err
:=
createRawRelayOrderTx
(
cfg
,
in
)
if
err
!=
nil
{
return
err
}
...
...
@@ -74,7 +75,8 @@ func (c *Jrpc) CreateRawRelayOrderTx(in *ty.RelayCreate, result *interface{}) er
//CreateRawRelayAcceptTx jrpc creat relay accept tx
func
(
c
*
Jrpc
)
CreateRawRelayAcceptTx
(
in
*
ty
.
RelayAccept
,
result
*
interface
{})
error
{
reply
,
err
:=
createRawRelayAcceptTx
(
in
)
cfg
:=
c
.
cli
.
GetConfig
()
reply
,
err
:=
createRawRelayAcceptTx
(
cfg
,
in
)
if
err
!=
nil
{
return
err
}
...
...
@@ -85,7 +87,8 @@ func (c *Jrpc) CreateRawRelayAcceptTx(in *ty.RelayAccept, result *interface{}) e
//CreateRawRelayRevokeTx jrpc create revoke tx
func
(
c
*
Jrpc
)
CreateRawRelayRevokeTx
(
in
*
ty
.
RelayRevoke
,
result
*
interface
{})
error
{
reply
,
err
:=
createRawRelayRevokeTx
(
in
)
cfg
:=
c
.
cli
.
GetConfig
()
reply
,
err
:=
createRawRelayRevokeTx
(
cfg
,
in
)
if
err
!=
nil
{
return
err
}
...
...
@@ -96,7 +99,8 @@ func (c *Jrpc) CreateRawRelayRevokeTx(in *ty.RelayRevoke, result *interface{}) e
//CreateRawRelayConfirmTx jrpc create confirm tx
func
(
c
*
Jrpc
)
CreateRawRelayConfirmTx
(
in
*
ty
.
RelayConfirmTx
,
result
*
interface
{})
error
{
reply
,
err
:=
createRawRelayConfirmTx
(
in
)
cfg
:=
c
.
cli
.
GetConfig
()
reply
,
err
:=
createRawRelayConfirmTx
(
cfg
,
in
)
if
err
!=
nil
{
return
err
}
...
...
@@ -107,7 +111,8 @@ func (c *Jrpc) CreateRawRelayConfirmTx(in *ty.RelayConfirmTx, result *interface{
//CreateRawRelaySaveBTCHeadTx jrpc save btc header
func
(
c
*
Jrpc
)
CreateRawRelaySaveBTCHeadTx
(
in
*
ty
.
BtcHeader
,
result
*
interface
{})
error
{
reply
,
err
:=
createRawRelaySaveBTCHeadTx
(
in
)
cfg
:=
c
.
cli
.
GetConfig
()
reply
,
err
:=
createRawRelaySaveBTCHeadTx
(
cfg
,
in
)
if
err
!=
nil
{
return
err
}
...
...
plugin/dapp/retrieve/executor/exec_del_local.go
View file @
af0be445
...
...
@@ -94,10 +94,10 @@ func (c *Retrieve) ExecDelLocal_Perform(perf *rt.PerformRetrieve, tx *types.Tran
if
err
!=
nil
{
return
set
,
nil
}
if
types
.
IsDappFork
(
c
.
GetHeight
(),
rt
.
RetrieveX
,
rt
.
ForkRetriveAssetX
)
{
cfg
:=
c
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsDappFork
(
c
.
GetHeight
(),
rt
.
RetrieveX
,
rt
.
ForkRetriveAssetX
)
{
if
len
(
perf
.
Assets
)
==
0
{
perf
.
Assets
=
append
(
perf
.
Assets
,
&
rt
.
AssetSymbol
{
Exec
:
"coins"
,
Symbol
:
types
.
GetCoinSymbol
()})
perf
.
Assets
=
append
(
perf
.
Assets
,
&
rt
.
AssetSymbol
{
Exec
:
"coins"
,
Symbol
:
cfg
.
GetCoinSymbol
()})
}
}
for
_
,
asset
:=
range
perf
.
Assets
{
...
...
plugin/dapp/retrieve/executor/exec_local.go
View file @
af0be445
...
...
@@ -102,9 +102,10 @@ func (c *Retrieve) ExecLocal_Perform(perf *rt.PerformRetrieve, tx *types.Transac
if
err
!=
nil
{
return
set
,
nil
}
if
types
.
IsDappFork
(
c
.
GetHeight
(),
rt
.
RetrieveX
,
rt
.
ForkRetriveAssetX
)
{
cfg
:=
c
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsDappFork
(
c
.
GetHeight
(),
rt
.
RetrieveX
,
rt
.
ForkRetriveAssetX
)
{
if
len
(
perf
.
Assets
)
==
0
{
perf
.
Assets
=
append
(
perf
.
Assets
,
&
rt
.
AssetSymbol
{
Exec
:
"coins"
,
Symbol
:
types
.
GetCoinSymbol
()})
perf
.
Assets
=
append
(
perf
.
Assets
,
&
rt
.
AssetSymbol
{
Exec
:
"coins"
,
Symbol
:
cfg
.
GetCoinSymbol
()})
}
}
for
_
,
asset
:=
range
perf
.
Assets
{
...
...
plugin/dapp/retrieve/executor/retrievedb.go
View file @
af0be445
...
...
@@ -15,6 +15,7 @@ import (
//log "github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/system/dapp"
rt
"github.com/33cn/plugin/plugin/dapp/retrieve/types"
"github.com/33cn/chain33/client"
)
const
(
...
...
@@ -99,6 +100,7 @@ type Action struct {
blocktime
int64
height
int64
execaddr
string
api
client
.
QueueProtocolAPI
}
// NewRetrieveAcction gen instance
...
...
@@ -106,7 +108,7 @@ func NewRetrieveAcction(r *Retrieve, tx *types.Transaction) *Action {
hash
:=
tx
.
Hash
()
fromaddr
:=
tx
.
From
()
return
&
Action
{
r
.
GetCoinsAccount
(),
r
.
GetStateDB
(),
hash
,
fromaddr
,
r
.
GetBlockTime
(),
r
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
))}
r
.
GetBlockTime
(),
r
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
))
,
r
.
GetAPI
()
}
}
// RetrieveBackup Action
...
...
@@ -116,7 +118,8 @@ func (action *Action) RetrieveBackup(backupRet *rt.BackupRetrieve) (*types.Recei
var
receipt
*
types
.
Receipt
var
r
*
DB
var
newRetrieve
=
false
if
types
.
IsDappFork
(
action
.
height
,
rt
.
RetrieveX
,
rt
.
ForkRetriveX
)
{
cfg
:=
action
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
action
.
height
,
rt
.
RetrieveX
,
rt
.
ForkRetriveX
)
{
if
err
:=
address
.
CheckAddress
(
backupRet
.
BackupAddress
);
err
!=
nil
{
rlog
.
Debug
(
"retrieve checkaddress"
)
return
nil
,
err
...
...
@@ -208,10 +211,10 @@ func (action *Action) RetrievePerformAssets(perfRet *rt.PerformRetrieve, default
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
var
receipt
*
types
.
Receipt
cfg
:=
action
.
api
.
GetConfig
()
// 兼容原来的找回, 在不指定的情况下,找回主币
if
len
(
perfRet
.
Assets
)
==
0
{
perfRet
.
Assets
=
append
(
perfRet
.
Assets
,
&
rt
.
AssetSymbol
{
Exec
:
"coins"
,
Symbol
:
types
.
GetCoinSymbol
()})
perfRet
.
Assets
=
append
(
perfRet
.
Assets
,
&
rt
.
AssetSymbol
{
Exec
:
"coins"
,
Symbol
:
cfg
.
GetCoinSymbol
()})
//return nil, nil
}
...
...
@@ -248,6 +251,7 @@ func (action *Action) RetrievePerform(perfRet *rt.PerformRetrieve) (*types.Recei
var
index
int
var
related
bool
var
acc
*
types
.
Account
cfg
:=
action
.
api
.
GetConfig
()
retrieve
,
err
:=
readRetrieve
(
action
.
db
,
perfRet
.
BackupAddress
)
if
err
!=
nil
{
...
...
@@ -276,7 +280,7 @@ func (action *Action) RetrievePerform(perfRet *rt.PerformRetrieve) (*types.Recei
return
nil
,
rt
.
ErrRetrievePeriodLimit
}
if
types
.
IsDappFork
(
action
.
height
,
rt
.
RetrieveX
,
rt
.
ForkRetriveAssetX
)
{
if
cfg
.
IsDappFork
(
action
.
height
,
rt
.
RetrieveX
,
rt
.
ForkRetriveAssetX
)
{
return
action
.
RetrievePerformAssets
(
perfRet
,
r
.
RetPara
[
index
]
.
DefaultAddress
)
}
...
...
plugin/dapp/retrieve/rpc/rpc.go
View file @
af0be445
...
...
@@ -16,7 +16,8 @@ func (c *channelClient) Backup(ctx context.Context, v *rt.BackupRetrieve) (*type
Ty
:
rt
.
RetrieveActionBackup
,
Value
:
&
rt
.
RetrieveAction_Backup
{
Backup
:
v
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
rt
.
RetrieveX
),
types
.
Encode
(
backup
))
cfg
:=
c
.
GetConfig
()
tx
,
err
:=
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
rt
.
RetrieveX
),
types
.
Encode
(
backup
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -29,7 +30,8 @@ func (c *channelClient) Prepare(ctx context.Context, v *rt.PrepareRetrieve) (*ty
Ty
:
rt
.
RetrieveActionPrepare
,
Value
:
&
rt
.
RetrieveAction_Prepare
{
Prepare
:
v
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
rt
.
RetrieveX
),
types
.
Encode
(
prepare
))
cfg
:=
c
.
GetConfig
()
tx
,
err
:=
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
rt
.
RetrieveX
),
types
.
Encode
(
prepare
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -44,7 +46,8 @@ func (c *channelClient) Perform(ctx context.Context, v *rt.PerformRetrieve) (*ty
Value
:
&
rt
.
RetrieveAction_Perform
{
Perform
:
v
},
}
payload
:=
types
.
Encode
(
perform
)
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
rt
.
RetrieveX
),
payload
)
cfg
:=
c
.
GetConfig
()
tx
,
err
:=
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
rt
.
RetrieveX
),
payload
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -58,7 +61,8 @@ func (c *channelClient) Cancel(ctx context.Context, v *rt.CancelRetrieve) (*type
Ty
:
rt
.
RetrieveActionCancel
,
Value
:
&
rt
.
RetrieveAction_Cancel
{
Cancel
:
v
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
rt
.
RetrieveX
),
types
.
Encode
(
cancel
))
cfg
:=
c
.
GetConfig
()
tx
,
err
:=
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
rt
.
RetrieveX
),
types
.
Encode
(
cancel
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/dapp/ticket/executor/ticketdb.go
View file @
af0be445
...
...
@@ -21,6 +21,7 @@ import (
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
ty
"github.com/33cn/plugin/plugin/dapp/ticket/types"
"github.com/33cn/chain33/client"
)
var
tlog
=
log
.
New
(
"module"
,
"ticket.db"
)
...
...
@@ -35,16 +36,16 @@ type DB struct {
}
//GetRealPrice 获取真实的价格
func
(
t
*
DB
)
GetRealPrice
()
int64
{
func
(
t
*
DB
)
GetRealPrice
(
cfg
*
types
.
Chain33Config
)
int64
{
if
t
.
GetPrice
()
==
0
{
cfg
:=
ty
.
GetTicketMinerParam
(
types
.
GetFork
(
"ForkChainParamV1"
))
cfg
:=
ty
.
GetTicketMinerParam
(
cfg
,
cfg
.
GetFork
(
"ForkChainParamV1"
))
return
cfg
.
TicketPrice
}
return
t
.
GetPrice
()
}
// NewDB new instance
func
NewDB
(
id
,
minerAddress
,
returnWallet
string
,
blocktime
,
height
,
price
int64
,
isGenesis
bool
)
*
DB
{
func
NewDB
(
cfg
*
types
.
Chain33Config
,
id
,
minerAddress
,
returnWallet
string
,
blocktime
,
height
,
price
int64
,
isGenesis
bool
)
*
DB
{
t
:=
&
DB
{}
t
.
TicketId
=
id
t
.
MinerAddress
=
minerAddress
...
...
@@ -54,7 +55,7 @@ func NewDB(id, minerAddress, returnWallet string, blocktime, height, price int64
t
.
IsGenesis
=
isGenesis
t
.
prevstatus
=
0
//height == 0 的情况下,不去改变 genesis block
if
types
.
IsFork
(
height
,
"ForkChainParamV2"
)
&&
height
>
0
{
if
cfg
.
IsFork
(
height
,
"ForkChainParamV2"
)
&&
height
>
0
{
t
.
Price
=
price
}
return
t
...
...
@@ -126,6 +127,7 @@ type Action struct {
blocktime
int64
height
int64
execaddr
string
api
client
.
QueueProtocolAPI
}
// NewAction new action type
...
...
@@ -133,19 +135,20 @@ func NewAction(t *Ticket, tx *types.Transaction) *Action {
hash
:=
tx
.
Hash
()
fromaddr
:=
tx
.
From
()
return
&
Action
{
t
.
GetCoinsAccount
(),
t
.
GetStateDB
(),
hash
,
fromaddr
,
t
.
GetBlockTime
(),
t
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
))}
t
.
GetBlockTime
(),
t
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
))
,
t
.
GetAPI
()
}
}
// GenesisInit init genesis
func
(
action
*
Action
)
GenesisInit
(
genesis
*
ty
.
TicketGenesis
)
(
*
types
.
Receipt
,
error
)
{
chain33Cfg
:=
action
.
api
.
GetConfig
()
prefix
:=
common
.
ToHex
(
action
.
txhash
)
prefix
=
genesis
.
MinerAddress
+
":"
+
prefix
+
":"
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
cfg
:=
ty
.
GetTicketMinerParam
(
action
.
height
)
cfg
:=
ty
.
GetTicketMinerParam
(
chain33Cfg
,
action
.
height
)
for
i
:=
0
;
i
<
int
(
genesis
.
Count
);
i
++
{
id
:=
prefix
+
fmt
.
Sprintf
(
"%010d"
,
i
)
t
:=
NewDB
(
id
,
genesis
.
MinerAddress
,
genesis
.
ReturnAddress
,
action
.
blocktime
,
action
.
height
,
cfg
.
TicketPrice
,
true
)
t
:=
NewDB
(
chain33Cfg
,
id
,
genesis
.
MinerAddress
,
genesis
.
ReturnAddress
,
action
.
blocktime
,
action
.
height
,
cfg
.
TicketPrice
,
true
)
//冻结子账户资金
receipt
,
err
:=
action
.
coinsAccount
.
ExecFrozen
(
genesis
.
ReturnAddress
,
action
.
execaddr
,
cfg
.
TicketPrice
)
if
err
!=
nil
{
...
...
@@ -225,6 +228,7 @@ func (action *Action) TicketBind(tbind *ty.TicketBind) (*types.Receipt, error) {
// TicketOpen ticket open
func
(
action
*
Action
)
TicketOpen
(
topen
*
ty
.
TicketOpen
)
(
*
types
.
Receipt
,
error
)
{
chain33Cfg
:=
action
.
api
.
GetConfig
()
prefix
:=
common
.
ToHex
(
action
.
txhash
)
prefix
=
topen
.
MinerAddress
+
":"
+
prefix
+
":"
var
logs
[]
*
types
.
ReceiptLog
...
...
@@ -240,17 +244,17 @@ func (action *Action) TicketOpen(topen *ty.TicketOpen) (*types.Receipt, error) {
}
}
//action.fromaddr == topen.ReturnAddress or mineraddr == action.fromaddr
cfg
:=
ty
.
GetTicketMinerParam
(
action
.
height
)
cfg
:=
ty
.
GetTicketMinerParam
(
chain33Cfg
,
action
.
height
)
for
i
:=
0
;
i
<
int
(
topen
.
Count
);
i
++
{
id
:=
prefix
+
fmt
.
Sprintf
(
"%010d"
,
i
)
//add pubHash
if
types
.
IsDappFork
(
action
.
height
,
ty
.
TicketX
,
"ForkTicketId"
)
{
if
chain33Cfg
.
IsDappFork
(
action
.
height
,
ty
.
TicketX
,
"ForkTicketId"
)
{
if
len
(
topen
.
PubHashes
)
==
0
{
return
nil
,
ty
.
ErrOpenTicketPubHash
}
id
=
id
+
":"
+
fmt
.
Sprintf
(
"%x:%d"
,
topen
.
PubHashes
[
i
],
topen
.
RandSeed
)
}
t
:=
NewDB
(
id
,
topen
.
MinerAddress
,
topen
.
ReturnAddress
,
action
.
blocktime
,
action
.
height
,
cfg
.
TicketPrice
,
false
)
t
:=
NewDB
(
chain33Cfg
,
id
,
topen
.
MinerAddress
,
topen
.
ReturnAddress
,
action
.
blocktime
,
action
.
height
,
cfg
.
TicketPrice
,
false
)
//冻结子账户资金
receipt
,
err
:=
action
.
coinsAccount
.
ExecFrozen
(
topen
.
ReturnAddress
,
action
.
execaddr
,
cfg
.
TicketPrice
)
...
...
@@ -296,6 +300,7 @@ func (action *Action) TicketMiner(miner *ty.TicketMiner, index int) (*types.Rece
if
index
!=
0
{
return
nil
,
types
.
ErrCoinBaseIndex
}
chain33Cfg
:=
action
.
api
.
GetConfig
()
ticket
,
err
:=
readTicket
(
action
.
db
,
miner
.
TicketId
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -303,7 +308,7 @@ func (action *Action) TicketMiner(miner *ty.TicketMiner, index int) (*types.Rece
if
ticket
.
Status
!=
1
{
return
nil
,
types
.
ErrCoinBaseTicketStatus
}
cfg
:=
ty
.
GetTicketMinerParam
(
action
.
height
)
cfg
:=
ty
.
GetTicketMinerParam
(
chain33Cfg
,
action
.
height
)
if
!
ticket
.
IsGenesis
{
if
action
.
blocktime
-
ticket
.
GetCreateTime
()
<
cfg
.
TicketFrozenTime
{
return
nil
,
ty
.
ErrTime
...
...
@@ -314,7 +319,7 @@ func (action *Action) TicketMiner(miner *ty.TicketMiner, index int) (*types.Rece
return
nil
,
types
.
ErrFromAddr
}
//check pubHash and privHash
if
!
types
.
IsDappFork
(
action
.
height
,
ty
.
TicketX
,
"ForkTicketId"
)
{
if
!
chain33Cfg
.
IsDappFork
(
action
.
height
,
ty
.
TicketX
,
"ForkTicketId"
)
{
miner
.
PrivHash
=
nil
}
if
len
(
miner
.
PrivHash
)
!=
0
{
...
...
@@ -327,32 +332,32 @@ func (action *Action) TicketMiner(miner *ty.TicketMiner, index int) (*types.Rece
prevstatus
:=
ticket
.
Status
ticket
.
Status
=
2
ticket
.
MinerValue
=
miner
.
Reward
if
types
.
IsFork
(
action
.
height
,
"ForkMinerTime"
)
{
if
chain33Cfg
.
IsFork
(
action
.
height
,
"ForkMinerTime"
)
{
ticket
.
MinerTime
=
action
.
blocktime
}
t
:=
&
DB
{
*
ticket
,
prevstatus
}
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
//user
receipt1
,
err
:=
action
.
coinsAccount
.
ExecDepositFrozen
(
t
.
ReturnAddress
,
action
.
execaddr
,
ticket
.
MinerValue
)
receipt1
,
err
:=
action
.
coinsAccount
.
ExecDepositFrozen
(
chain33Cfg
,
t
.
ReturnAddress
,
action
.
execaddr
,
ticket
.
MinerValue
)
if
err
!=
nil
{
tlog
.
Error
(
"TicketMiner.ExecDepositFrozen user"
,
"addr"
,
t
.
ReturnAddress
,
"execaddr"
,
action
.
execaddr
)
return
nil
,
err
}
//fund
var
receipt2
*
types
.
Receipt
if
types
.
IsFork
(
action
.
height
,
"ForkTicketFundAddrV1"
)
{
if
chain33Cfg
.
IsFork
(
action
.
height
,
"ForkTicketFundAddrV1"
)
{
// issue coins to exec addr
addr
:=
types
.
MGStr
(
"mver.consensus.fundKeyAddr"
,
action
.
height
)
receipt2
,
err
=
action
.
coinsAccount
.
ExecIssueCoins
(
addr
,
cfg
.
CoinDevFund
)
addr
:=
chain33Cfg
.
MGStr
(
"mver.consensus.fundKeyAddr"
,
action
.
height
)
receipt2
,
err
=
action
.
coinsAccount
.
ExecIssueCoins
(
chain33Cfg
,
addr
,
cfg
.
CoinDevFund
)
if
err
!=
nil
{
tlog
.
Error
(
"TicketMiner.ExecDepositFrozen fund to autonomy fund"
,
"addr"
,
addr
,
"error"
,
err
)
return
nil
,
err
}
}
else
{
receipt2
,
err
=
action
.
coinsAccount
.
ExecDepositFrozen
(
types
.
GetFundAddr
(),
action
.
execaddr
,
cfg
.
CoinDevFund
)
receipt2
,
err
=
action
.
coinsAccount
.
ExecDepositFrozen
(
chain33Cfg
,
chain33Cfg
.
GetFundAddr
(),
action
.
execaddr
,
cfg
.
CoinDevFund
)
if
err
!=
nil
{
tlog
.
Error
(
"TicketMiner.ExecDepositFrozen fund"
,
"addr"
,
types
.
GetFundAddr
(),
"execaddr"
,
action
.
execaddr
,
"error"
,
err
)
tlog
.
Error
(
"TicketMiner.ExecDepositFrozen fund"
,
"addr"
,
chain33Cfg
.
GetFundAddr
(),
"execaddr"
,
action
.
execaddr
,
"error"
,
err
)
return
nil
,
err
}
}
...
...
@@ -369,8 +374,9 @@ func (action *Action) TicketMiner(miner *ty.TicketMiner, index int) (*types.Rece
// TicketClose close tick
func
(
action
*
Action
)
TicketClose
(
tclose
*
ty
.
TicketClose
)
(
*
types
.
Receipt
,
error
)
{
chain33Cfg
:=
action
.
api
.
GetConfig
()
tickets
:=
make
([]
*
DB
,
len
(
tclose
.
TicketId
))
cfg
:=
ty
.
GetTicketMinerParam
(
action
.
height
)
cfg
:=
ty
.
GetTicketMinerParam
(
chain33Cfg
,
action
.
height
)
for
i
:=
0
;
i
<
len
(
tclose
.
TicketId
);
i
++
{
ticket
,
err
:=
readTicket
(
action
.
db
,
tclose
.
TicketId
[
i
])
if
err
!=
nil
{
...
...
@@ -409,7 +415,7 @@ func (action *Action) TicketClose(tclose *ty.TicketClose) (*types.Receipt, error
if
t
.
prevstatus
==
1
{
t
.
MinerValue
=
0
}
retValue
:=
t
.
GetRealPrice
()
+
t
.
MinerValue
retValue
:=
t
.
GetRealPrice
(
chain33Cfg
)
+
t
.
MinerValue
receipt1
,
err
:=
action
.
coinsAccount
.
ExecActive
(
t
.
ReturnAddress
,
action
.
execaddr
,
retValue
)
if
err
!=
nil
{
tlog
.
Error
(
"TicketClose.ExecActive user"
,
"addr"
,
t
.
ReturnAddress
,
"execaddr"
,
action
.
execaddr
,
"value"
,
retValue
)
...
...
@@ -421,10 +427,10 @@ func (action *Action) TicketClose(tclose *ty.TicketClose) (*types.Receipt, error
kv
=
append
(
kv
,
receipt1
.
KV
...
)
//如果ticket 已经挖矿成功了,那么要解冻发展基金部分币
if
t
.
prevstatus
==
2
{
if
!
types
.
IsFork
(
action
.
height
,
"ForkTicketFundAddrV1"
)
{
receipt2
,
err
:=
action
.
coinsAccount
.
ExecActive
(
types
.
GetFundAddr
(),
action
.
execaddr
,
cfg
.
CoinDevFund
)
if
!
chain33Cfg
.
IsFork
(
action
.
height
,
"ForkTicketFundAddrV1"
)
{
receipt2
,
err
:=
action
.
coinsAccount
.
ExecActive
(
chain33Cfg
.
GetFundAddr
(),
action
.
execaddr
,
cfg
.
CoinDevFund
)
if
err
!=
nil
{
tlog
.
Error
(
"TicketClose.ExecActive fund"
,
"addr"
,
types
.
GetFundAddr
(),
"execaddr"
,
action
.
execaddr
,
"value"
,
retValue
)
tlog
.
Error
(
"TicketClose.ExecActive fund"
,
"addr"
,
chain33Cfg
.
GetFundAddr
(),
"execaddr"
,
action
.
execaddr
,
"value"
,
retValue
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt2
.
Logs
...
)
...
...
plugin/dapp/ticket/executor/ticketnum.go
View file @
af0be445
...
...
@@ -97,8 +97,9 @@ func (ticket *Ticket) getTxActions(blockHash []byte, blockNum int64) ([]*tickett
tlog
.
Error
(
"getTxActions"
,
"blockHash"
,
blockHash
,
"blockNum"
,
blockNum
,
"err"
,
err
)
return
txActions
,
err
}
cfg
:=
ticket
.
GetAPI
()
.
GetConfig
()
for
_
,
block
:=
range
blockDetails
.
Items
{
tlog
.
Debug
(
"getTxActions"
,
"blockHeight"
,
block
.
Block
.
Height
,
"blockhash"
,
common
.
ToHex
(
block
.
Block
.
Hash
()))
tlog
.
Debug
(
"getTxActions"
,
"blockHeight"
,
block
.
Block
.
Height
,
"blockhash"
,
common
.
ToHex
(
block
.
Block
.
Hash
(
cfg
)))
ticketAction
,
err
:=
ticket
.
getMinerTx
(
block
.
Block
)
if
err
!=
nil
{
return
txActions
,
err
...
...
plugin/dapp/ticket/rpc/rpc.go
View file @
af0be445
...
...
@@ -13,12 +13,12 @@ import (
context
"golang.org/x/net/context"
)
func
bindMiner
(
param
*
ty
.
ReqBindMiner
)
(
*
ty
.
ReplyBindMiner
,
error
)
{
func
bindMiner
(
cfg
*
types
.
Chain33Config
,
param
*
ty
.
ReqBindMiner
)
(
*
ty
.
ReplyBindMiner
,
error
)
{
tBind
:=
&
ty
.
TicketBind
{
MinerAddress
:
param
.
BindAddr
,
ReturnAddress
:
param
.
OriginAddr
,
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
ty
.
TicketX
),
"Tbind"
,
tBind
)
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
ty
.
TicketX
),
"Tbind"
,
tBind
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -32,7 +32,8 @@ func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner
if
err
!=
nil
{
return
nil
,
err
}
if
in
.
Amount
%
ty
.
GetTicketMinerParam
(
header
.
Height
)
.
TicketPrice
!=
0
||
in
.
Amount
<
0
{
cfg
:=
g
.
GetConfig
()
if
in
.
Amount
%
ty
.
GetTicketMinerParam
(
cfg
,
header
.
Height
)
.
TicketPrice
!=
0
||
in
.
Amount
<
0
{
return
nil
,
types
.
ErrAmount
}
err
=
address
.
CheckAddress
(
in
.
BindAddr
)
...
...
@@ -57,7 +58,7 @@ func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner
return
nil
,
types
.
ErrNoBalance
}
}
return
bindMiner
(
in
)
return
bindMiner
(
cfg
,
in
)
}
// SetAutoMining set auto mining
...
...
plugin/dapp/ticket/types/ticket.go
View file @
af0be445
...
...
@@ -146,8 +146,8 @@ type TicketMinerParam struct {
}
// GetTicketMinerParam 获取ticket miner config params
func
GetTicketMinerParam
(
height
int64
)
*
TicketMinerParam
{
conf
:=
types
.
Conf
(
"mver.consensus.ticket"
)
func
GetTicketMinerParam
(
cfg
*
types
.
Chain33Config
,
height
int64
)
*
TicketMinerParam
{
conf
:=
types
.
Conf
(
cfg
,
"mver.consensus.ticket"
)
c
:=
&
TicketMinerParam
{}
c
.
CoinDevFund
=
conf
.
MGInt
(
"coinDevFund"
,
height
)
*
types
.
Coin
c
.
CoinReward
=
conf
.
MGInt
(
"coinReward"
,
height
)
*
types
.
Coin
...
...
plugin/dapp/ticket/wallet/ticket.go
View file @
af0be445
...
...
@@ -402,7 +402,8 @@ func (policy *ticketPolicy) forceCloseTicketList(height int64, priv crypto.PrivK
var
ids
[]
string
var
tl
[]
*
ty
.
Ticket
now
:=
types
.
Now
()
.
Unix
()
cfg
:=
ty
.
GetTicketMinerParam
(
height
)
chain33Cfg
:=
policy
.
walletOperate
.
GetAPI
()
.
GetConfig
()
cfg
:=
ty
.
GetTicketMinerParam
(
chain33Cfg
,
height
)
for
_
,
t
:=
range
tlist
{
if
!
t
.
IsGenesis
{
if
t
.
Status
==
1
&&
now
-
t
.
GetCreateTime
()
<
cfg
.
TicketWithdrawTime
{
...
...
@@ -496,7 +497,8 @@ func (policy *ticketPolicy) closeTicketsByAddr(height int64, priv crypto.PrivKey
var
ids
[]
string
var
tl
[]
*
ty
.
Ticket
now
:=
types
.
Now
()
.
Unix
()
cfg
:=
ty
.
GetTicketMinerParam
(
height
)
chain33Cfg
:=
policy
.
walletOperate
.
GetAPI
()
.
GetConfig
()
cfg
:=
ty
.
GetTicketMinerParam
(
chain33Cfg
,
height
)
for
_
,
t
:=
range
tlist
{
if
!
t
.
IsGenesis
{
if
now
-
t
.
GetCreateTime
()
<
cfg
.
TicketWithdrawTime
{
...
...
@@ -635,7 +637,8 @@ func (policy *ticketPolicy) buyTicketOne(height int64, priv crypto.PrivKey) ([]b
}
//留一个币作为手续费,如果手续费不够了,不能挖矿
//判断手续费是否足够,如果不足要及时补充。
cfg
:=
ty
.
GetTicketMinerParam
(
height
)
chain33Cfg
:=
policy
.
walletOperate
.
GetAPI
()
.
GetConfig
()
cfg
:=
ty
.
GetTicketMinerParam
(
chain33Cfg
,
height
)
fee
:=
types
.
Coin
if
acc1
.
Balance
+
acc2
.
Balance
-
2
*
fee
>=
cfg
.
TicketPrice
{
// 如果可用余额+冻结余额,可以凑成新票,则转币到冻结余额
...
...
@@ -740,7 +743,8 @@ func (policy *ticketPolicy) buyMinerAddrTicketOne(height int64, priv crypto.Priv
}
total
:=
0
var
hashes
[][]
byte
cfg
:=
ty
.
GetTicketMinerParam
(
height
)
chain33Cfg
:=
policy
.
walletOperate
.
GetAPI
()
.
GetConfig
()
cfg
:=
ty
.
GetTicketMinerParam
(
chain33Cfg
,
height
)
for
i
:=
0
;
i
<
len
(
addrs
);
i
++
{
bizlog
.
Info
(
"sourceaddr"
,
"addr"
,
addrs
[
i
])
ok
:=
checkMinerWhiteList
(
addrs
[
i
])
...
...
@@ -830,7 +834,8 @@ func (policy *ticketPolicy) autoMining() {
defer
operater
.
GetWaitGroup
()
.
Done
()
// 只有ticket共识下ticket相关的操作才有效
q
:=
types
.
Conf
(
"config.consensus"
)
cfg
:=
policy
.
walletOperate
.
GetAPI
()
.
GetConfig
()
q
:=
types
.
Conf
(
cfg
,
"config.consensus"
)
if
q
!=
nil
{
cons
:=
q
.
GStr
(
"name"
)
if
strings
.
Compare
(
strings
.
TrimSpace
(
cons
),
ty
.
TicketX
)
!=
0
{
...
...
plugin/dapp/token/executor/exec.go
View file @
af0be445
...
...
@@ -46,7 +46,8 @@ func (t *token) Exec_TokenPreCreate(payload *tokenty.TokenPreCreate, tx *types.T
}
func
(
t
*
token
)
Exec_TokenFinishCreate
(
payload
*
tokenty
.
TokenFinishCreate
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newTokenAction
(
t
,
types
.
MGStr
(
"mver.consensus.fundKeyAddr"
,
t
.
GetHeight
()),
tx
)
cfg
:=
t
.
GetAPI
()
.
GetConfig
()
action
:=
newTokenAction
(
t
,
cfg
.
MGStr
(
"mver.consensus.fundKeyAddr"
,
t
.
GetHeight
()),
tx
)
return
action
.
finishCreate
(
payload
)
}
...
...
plugin/dapp/token/executor/token.go
View file @
af0be445
...
...
@@ -33,7 +33,6 @@ const (
)
var
driverName
=
"token"
var
conf
=
types
.
ConfSub
(
driverName
)
type
subConfig
struct
{
SaveTokenTxList
bool
`json:"saveTokenTxList"`
...
...
plugin/dapp/token/executor/tokendb.go
View file @
af0be445
...
...
@@ -15,13 +15,14 @@ import (
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/token/types"
"github.com/33cn/chain33/client"
)
type
tokenDB
struct
{
token
pty
.
Token
}
func
newTokenDB
(
preCreate
*
pty
.
TokenPreCreate
,
creator
string
,
height
int64
)
*
tokenDB
{
func
newTokenDB
(
cfg
*
types
.
Chain33Config
,
preCreate
*
pty
.
TokenPreCreate
,
creator
string
,
height
int64
)
*
tokenDB
{
t
:=
&
tokenDB
{}
t
.
token
.
Name
=
preCreate
.
GetName
()
t
.
token
.
Symbol
=
preCreate
.
GetSymbol
()
...
...
@@ -32,7 +33,7 @@ func newTokenDB(preCreate *pty.TokenPreCreate, creator string, height int64) *to
t
.
token
.
Owner
=
preCreate
.
GetOwner
()
t
.
token
.
Creator
=
creator
t
.
token
.
Status
=
pty
.
TokenStatusPreCreated
if
types
.
IsDappFork
(
height
,
pty
.
TokenX
,
pty
.
ForkTokenSymbolWithNumberX
)
{
if
cfg
.
IsDappFork
(
height
,
pty
.
TokenX
,
pty
.
ForkTokenSymbolWithNumberX
)
{
t
.
token
.
Category
=
preCreate
.
Category
}
return
t
...
...
@@ -134,17 +135,19 @@ type tokenAction struct {
blocktime
int64
height
int64
execaddr
string
api
client
.
QueueProtocolAPI
}
func
newTokenAction
(
t
*
token
,
toaddr
string
,
tx
*
types
.
Transaction
)
*
tokenAction
{
hash
:=
tx
.
Hash
()
fromaddr
:=
tx
.
From
()
return
&
tokenAction
{
t
.
GetCoinsAccount
(),
t
.
GetStateDB
(),
hash
,
fromaddr
,
toaddr
,
t
.
GetBlockTime
(),
t
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
))}
t
.
GetBlockTime
(),
t
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
))
,
t
.
GetAPI
()
}
}
func
(
action
*
tokenAction
)
preCreate
(
token
*
pty
.
TokenPreCreate
)
(
*
types
.
Receipt
,
error
)
{
tokenlog
.
Debug
(
"preCreate"
)
cfg
:=
action
.
api
.
GetConfig
()
if
token
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -157,18 +160,18 @@ func (action *tokenAction) preCreate(token *pty.TokenPreCreate) (*types.Receipt,
}
else
if
token
.
GetTotal
()
>
types
.
MaxTokenBalance
||
token
.
GetTotal
()
<=
0
{
return
nil
,
pty
.
ErrTokenTotalOverflow
}
if
types
.
IsDappFork
(
action
.
height
,
pty
.
TokenX
,
pty
.
ForkTokenCheckX
)
{
if
cfg
.
IsDappFork
(
action
.
height
,
pty
.
TokenX
,
pty
.
ForkTokenCheckX
)
{
if
err
:=
address
.
CheckAddress
(
token
.
Owner
);
err
!=
nil
{
return
nil
,
err
}
}
if
!
types
.
IsDappFork
(
action
.
height
,
pty
.
TokenX
,
pty
.
ForkTokenSymbolWithNumberX
)
{
if
!
cfg
.
IsDappFork
(
action
.
height
,
pty
.
TokenX
,
pty
.
ForkTokenSymbolWithNumberX
)
{
if
token
.
Category
!=
0
{
return
nil
,
types
.
ErrNotSupport
}
}
if
!
validSymbolWithHeight
([]
byte
(
token
.
GetSymbol
()),
action
.
height
)
{
if
!
validSymbolWithHeight
(
cfg
,
[]
byte
(
token
.
GetSymbol
()),
action
.
height
)
{
tokenlog
.
Error
(
"token precreate "
,
"symbol need be upper"
,
token
.
GetSymbol
())
return
nil
,
pty
.
ErrTokenSymbolUpper
}
...
...
@@ -177,11 +180,11 @@ func (action *tokenAction) preCreate(token *pty.TokenPreCreate) (*types.Receipt,
return
nil
,
pty
.
ErrTokenExist
}
if
checkTokenHasPrecreateWithHeight
(
token
.
GetSymbol
(),
token
.
GetOwner
(),
action
.
db
,
action
.
height
)
{
if
checkTokenHasPrecreateWithHeight
(
cfg
,
token
.
GetSymbol
(),
token
.
GetOwner
(),
action
.
db
,
action
.
height
)
{
return
nil
,
pty
.
ErrTokenHavePrecreated
}
if
types
.
IsDappFork
(
action
.
height
,
pty
.
TokenX
,
pty
.
ForkTokenBlackListX
)
{
if
cfg
.
IsDappFork
(
action
.
height
,
pty
.
TokenX
,
pty
.
ForkTokenBlackListX
)
{
found
,
err
:=
inBlacklist
(
token
.
GetSymbol
(),
blacklist
,
action
.
db
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -194,7 +197,7 @@ func (action *tokenAction) preCreate(token *pty.TokenPreCreate) (*types.Receipt,
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
if
types
.
IsDappFork
(
action
.
height
,
pty
.
TokenX
,
pty
.
ForkTokenPriceX
)
&&
token
.
GetPrice
()
==
0
{
if
cfg
.
IsDappFork
(
action
.
height
,
pty
.
TokenX
,
pty
.
ForkTokenPriceX
)
&&
token
.
GetPrice
()
==
0
{
// pay for create token offline
}
else
{
receipt
,
err
:=
action
.
coinsAccount
.
ExecFrozen
(
action
.
fromaddr
,
action
.
execaddr
,
token
.
GetPrice
())
...
...
@@ -206,10 +209,10 @@ func (action *tokenAction) preCreate(token *pty.TokenPreCreate) (*types.Receipt,
kv
=
append
(
kv
,
receipt
.
KV
...
)
}
tokendb
:=
newTokenDB
(
token
,
action
.
fromaddr
,
action
.
height
)
tokendb
:=
newTokenDB
(
cfg
,
token
,
action
.
fromaddr
,
action
.
height
)
var
statuskey
[]
byte
var
key
[]
byte
if
types
.
IsFork
(
action
.
height
,
"ForkExecKey"
)
{
if
cfg
.
IsFork
(
action
.
height
,
"ForkExecKey"
)
{
statuskey
=
calcTokenStatusNewKeyS
(
tokendb
.
token
.
Symbol
,
tokendb
.
token
.
Owner
,
pty
.
TokenStatusPreCreated
)
key
=
calcTokenAddrNewKeyS
(
tokendb
.
token
.
Symbol
,
tokendb
.
token
.
Owner
)
}
else
{
...
...
@@ -232,6 +235,7 @@ func (action *tokenAction) preCreate(token *pty.TokenPreCreate) (*types.Receipt,
func
(
action
*
tokenAction
)
finishCreate
(
tokenFinish
*
pty
.
TokenFinishCreate
)
(
*
types
.
Receipt
,
error
)
{
tokenlog
.
Debug
(
"finishCreate"
)
cfg
:=
action
.
api
.
GetConfig
()
if
tokenFinish
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -241,7 +245,7 @@ func (action *tokenAction) finishCreate(tokenFinish *pty.TokenFinishCreate) (*ty
}
approverValid
:=
false
conf
:=
types
.
ConfSub
(
cfg
,
driverName
)
for
_
,
approver
:=
range
conf
.
GStrList
(
"tokenApprs"
)
{
if
approver
==
action
.
fromaddr
{
approverValid
=
true
...
...
@@ -257,7 +261,7 @@ func (action *tokenAction) finishCreate(tokenFinish *pty.TokenFinishCreate) (*ty
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
if
types
.
IsDappFork
(
action
.
height
,
pty
.
TokenX
,
"ForkTokenPrice"
)
&&
token
.
GetPrice
()
==
0
{
if
cfg
.
IsDappFork
(
action
.
height
,
pty
.
TokenX
,
"ForkTokenPrice"
)
&&
token
.
GetPrice
()
==
0
{
// pay for create token offline
}
else
{
//将之前冻结的资金转账到fund合约账户中
...
...
@@ -285,7 +289,7 @@ func (action *tokenAction) finishCreate(tokenFinish *pty.TokenFinishCreate) (*ty
token
.
Status
=
pty
.
TokenStatusCreated
tokendb
:=
&
tokenDB
{
*
token
}
var
key
[]
byte
if
types
.
IsFork
(
action
.
height
,
"ForkExecKey"
)
{
if
cfg
.
IsFork
(
action
.
height
,
"ForkExecKey"
)
{
key
=
calcTokenAddrNewKeyS
(
tokendb
.
token
.
Symbol
,
tokendb
.
token
.
Owner
)
}
else
{
key
=
calcTokenAddrKeyS
(
tokendb
.
token
.
Symbol
,
tokendb
.
token
.
Owner
)
...
...
@@ -309,6 +313,7 @@ func (action *tokenAction) revokeCreate(tokenRevoke *pty.TokenRevokeCreate) (*ty
if
tokenRevoke
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
cfg
:=
action
.
api
.
GetConfig
()
token
,
err
:=
getTokenFromDB
(
action
.
db
,
tokenRevoke
.
GetSymbol
(),
tokenRevoke
.
GetOwner
())
if
err
!=
nil
{
tokenlog
.
Error
(
"token revokeCreate "
,
"Can't get token form db for token"
,
tokenRevoke
.
GetSymbol
())
...
...
@@ -330,7 +335,7 @@ func (action *tokenAction) revokeCreate(tokenRevoke *pty.TokenRevokeCreate) (*ty
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
if
types
.
IsDappFork
(
action
.
height
,
pty
.
TokenX
,
pty
.
ForkTokenPriceX
)
&&
token
.
GetPrice
()
==
0
{
if
cfg
.
IsDappFork
(
action
.
height
,
pty
.
TokenX
,
pty
.
ForkTokenPriceX
)
&&
token
.
GetPrice
()
==
0
{
// pay for create token offline
}
else
{
//解锁之前冻结的资金
...
...
@@ -346,7 +351,7 @@ func (action *tokenAction) revokeCreate(tokenRevoke *pty.TokenRevokeCreate) (*ty
token
.
Status
=
pty
.
TokenStatusCreateRevoked
tokendb
:=
&
tokenDB
{
*
token
}
var
key
[]
byte
if
types
.
IsFork
(
action
.
height
,
"ForkExecKey"
)
{
if
cfg
.
IsFork
(
action
.
height
,
"ForkExecKey"
)
{
key
=
calcTokenAddrNewKeyS
(
tokendb
.
token
.
Symbol
,
tokendb
.
token
.
Owner
)
}
else
{
key
=
calcTokenAddrKeyS
(
tokendb
.
token
.
Symbol
,
tokendb
.
token
.
Owner
)
...
...
@@ -375,8 +380,8 @@ func checkTokenHasPrecreate(token, owner string, status int32, db dbm.KV) bool {
return
err
==
nil
}
func
checkTokenHasPrecreateWithHeight
(
token
,
owner
string
,
db
dbm
.
KV
,
height
int64
)
bool
{
if
!
types
.
IsDappFork
(
height
,
pty
.
TokenX
,
pty
.
ForkTokenCheckX
)
{
func
checkTokenHasPrecreateWithHeight
(
cfg
*
types
.
Chain33Config
,
token
,
owner
string
,
db
dbm
.
KV
,
height
int64
)
bool
{
if
!
cfg
.
IsDappFork
(
height
,
pty
.
TokenX
,
pty
.
ForkTokenCheckX
)
{
return
checkTokenHasPrecreate
(
token
,
owner
,
pty
.
TokenStatusPreCreated
,
db
)
}
...
...
@@ -533,10 +538,10 @@ func validSymbolOriginal(cs []byte) bool {
return
upSymbol
==
symbol
}
func
validSymbolWithHeight
(
cs
[]
byte
,
height
int64
)
bool
{
if
types
.
IsDappFork
(
height
,
pty
.
TokenX
,
pty
.
ForkTokenSymbolWithNumberX
)
{
func
validSymbolWithHeight
(
c
fg
*
types
.
Chain33Config
,
c
s
[]
byte
,
height
int64
)
bool
{
if
cfg
.
IsDappFork
(
height
,
pty
.
TokenX
,
pty
.
ForkTokenSymbolWithNumberX
)
{
return
validSymbolForkTokenSymbolWithNumber
(
cs
)
}
else
if
types
.
IsDappFork
(
height
,
pty
.
TokenX
,
pty
.
ForkBadTokenSymbolX
)
{
}
else
if
cfg
.
IsDappFork
(
height
,
pty
.
TokenX
,
pty
.
ForkBadTokenSymbolX
)
{
return
validSymbolForkBadTokenSymbol
(
cs
)
}
return
validSymbolOriginal
(
cs
)
...
...
plugin/dapp/token/executor/transwithdraw.go
View file @
af0be445
...
...
@@ -14,6 +14,7 @@ import (
)
func
(
t
*
token
)
ExecTransWithdraw
(
accountDB
*
account
.
DB
,
tx
*
types
.
Transaction
,
action
*
tokenty
.
TokenAction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
cfg
:=
t
.
GetAPI
()
.
GetConfig
()
if
(
action
.
Ty
==
tokenty
.
ActionTransfer
)
&&
action
.
GetTransfer
()
!=
nil
{
transfer
:=
action
.
GetTransfer
()
from
:=
tx
.
From
()
...
...
@@ -24,7 +25,7 @@ func (t *token) ExecTransWithdraw(accountDB *account.DB, tx *types.Transaction,
return
accountDB
.
Transfer
(
from
,
tx
.
GetRealToAddr
(),
transfer
.
Amount
)
}
else
if
(
action
.
Ty
==
tokenty
.
ActionWithdraw
)
&&
action
.
GetWithdraw
()
!=
nil
{
withdraw
:=
action
.
GetWithdraw
()
if
!
types
.
IsFork
(
t
.
GetHeight
(),
"ForkWithdraw"
)
{
if
!
cfg
.
IsFork
(
t
.
GetHeight
(),
"ForkWithdraw"
)
{
withdraw
.
ExecName
=
""
}
from
:=
tx
.
From
()
...
...
@@ -43,7 +44,7 @@ func (t *token) ExecTransWithdraw(accountDB *account.DB, tx *types.Transaction,
}
return
nil
,
types
.
ErrReRunGenesis
}
else
if
action
.
Ty
==
tokenty
.
TokenActionTransferToExec
&&
action
.
GetTransferToExec
()
!=
nil
{
if
!
types
.
IsFork
(
t
.
GetHeight
(),
"ForkTransferExec"
)
{
if
!
cfg
.
IsFork
(
t
.
GetHeight
(),
"ForkTransferExec"
)
{
return
nil
,
types
.
ErrActionNotSupport
}
transfer
:=
action
.
GetTransferToExec
()
...
...
plugin/dapp/token/rpc/rpc.go
View file @
af0be445
...
...
@@ -21,8 +21,9 @@ func (c *channelClient) getTokenBalance(in *tokenty.ReqTokenBalance) ([]*types.A
if
err
!=
nil
{
return
nil
,
err
}
cfg
:=
c
.
GetConfig
()
switch
in
.
GetExecer
()
{
case
types
.
ExecName
(
tokenty
.
TokenX
)
:
case
cfg
.
ExecName
(
tokenty
.
TokenX
)
:
addrs
:=
in
.
GetAddresses
()
var
queryAddrs
[]
string
queryAddrs
=
append
(
queryAddrs
,
addrs
...
)
...
...
@@ -83,7 +84,8 @@ func (c *Jrpc) CreateRawTokenPreCreateTx(param *tokenty.TokenPreCreate, result *
if
param
==
nil
||
param
.
Symbol
==
""
{
return
types
.
ErrInvalidParam
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
tokenty
.
TokenX
),
"TokenPreCreate"
,
param
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
tokenty
.
TokenX
),
"TokenPreCreate"
,
param
)
if
err
!=
nil
{
return
err
}
...
...
@@ -96,7 +98,8 @@ func (c *Jrpc) CreateRawTokenFinishTx(param *tokenty.TokenFinishCreate, result *
if
param
==
nil
||
param
.
Symbol
==
""
{
return
types
.
ErrInvalidParam
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
tokenty
.
TokenX
),
"TokenFinishCreate"
,
param
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
tokenty
.
TokenX
),
"TokenFinishCreate"
,
param
)
if
err
!=
nil
{
return
err
}
...
...
@@ -109,7 +112,8 @@ func (c *Jrpc) CreateRawTokenRevokeTx(param *tokenty.TokenRevokeCreate, result *
if
param
==
nil
||
param
.
Symbol
==
""
{
return
types
.
ErrInvalidParam
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
tokenty
.
TokenX
),
"TokenRevokeCreate"
,
param
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
tokenty
.
TokenX
),
"TokenRevokeCreate"
,
param
)
if
err
!=
nil
{
return
err
}
...
...
@@ -122,7 +126,8 @@ func (c *Jrpc) CreateRawTokenMintTx(param *tokenty.TokenMint, result *interface{
if
param
==
nil
||
param
.
Symbol
==
""
||
param
.
Amount
<=
0
{
return
types
.
ErrInvalidParam
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
tokenty
.
TokenX
),
"TokenMint"
,
param
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
tokenty
.
TokenX
),
"TokenMint"
,
param
)
if
err
!=
nil
{
return
err
}
...
...
@@ -135,7 +140,8 @@ func (c *Jrpc) CreateRawTokenBurnTx(param *tokenty.TokenBurn, result *interface{
if
param
==
nil
||
param
.
Symbol
==
""
||
param
.
Amount
<=
0
{
return
types
.
ErrInvalidParam
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
tokenty
.
TokenX
),
"TokenBurn"
,
param
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
tokenty
.
TokenX
),
"TokenBurn"
,
param
)
if
err
!=
nil
{
return
err
}
...
...
plugin/dapp/trade/executor/query.go
View file @
af0be445
...
...
@@ -87,24 +87,25 @@ func (t *trade) GetOnesOrderWithStatus(req *pty.ReqAddrAssets) (types.Message, e
return
nil
,
err
}
var
replys
pty
.
ReplyTradeOrders
cfg
:=
t
.
GetAPI
()
.
GetConfig
()
for
_
,
row
:=
range
rows
{
o
,
ok
:=
row
.
Data
.
(
*
pty
.
LocalOrder
)
if
!
ok
{
tradelog
.
Error
(
"GetOnesOrderWithStatus"
,
"err"
,
"bad row type"
)
return
nil
,
types
.
ErrTypeAsset
}
reply
:=
fmtReply
(
o
)
reply
:=
fmtReply
(
cfg
,
o
)
replys
.
Orders
=
append
(
replys
.
Orders
,
reply
)
}
return
&
replys
,
nil
}
func
fmtReply
(
order
*
pty
.
LocalOrder
)
*
pty
.
ReplyTradeOrder
{
func
fmtReply
(
cfg
*
types
.
Chain33Config
,
order
*
pty
.
LocalOrder
)
*
pty
.
ReplyTradeOrder
{
priceExec
:=
order
.
PriceExec
priceSymbol
:=
order
.
PriceSymbol
if
priceExec
==
""
{
priceExec
=
defaultPriceExec
priceSymbol
=
types
.
GetCoinSymbol
()
priceSymbol
=
cfg
.
GetCoinSymbol
()
}
return
&
pty
.
ReplyTradeOrder
{
...
...
@@ -143,7 +144,8 @@ func (t *trade) GetOneOrder(req *pty.ReqAddrAssets) (types.Message, error) {
tradelog
.
Error
(
"query GetData failed"
,
"err"
,
"bad row type"
)
return
nil
,
types
.
ErrTypeAsset
}
reply
:=
fmtReply
(
o
)
cfg
:=
t
.
GetAPI
()
.
GetConfig
()
reply
:=
fmtReply
(
cfg
,
o
)
return
reply
,
nil
}
plugin/dapp/trade/executor/tradedb.go
View file @
af0be445
...
...
@@ -252,30 +252,34 @@ type tradeAction struct {
blocktime
int64
height
int64
execaddr
string
api
client
.
QueueProtocolAPI
}
func
newTradeAction
(
t
*
trade
,
tx
*
types
.
Transaction
)
*
tradeAction
{
hash
:=
hex
.
EncodeToString
(
tx
.
Hash
())
fromaddr
:=
tx
.
From
()
return
&
tradeAction
{
t
.
GetStateDB
(),
hash
,
fromaddr
,
t
.
GetBlockTime
(),
t
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
))}
t
.
GetBlockTime
(),
t
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
))
,
t
.
GetAPI
()
}
}
func
(
action
*
tradeAction
)
tradeSell
(
sell
*
pty
.
TradeForSell
)
(
*
types
.
Receipt
,
error
)
{
if
sell
.
TotalBoardlot
<
0
||
sell
.
PricePerBoardlot
<
0
||
sell
.
MinBoardlot
<
0
||
sell
.
AmountPerBoardlot
<
0
{
return
nil
,
types
.
ErrInvalidParam
}
if
!
checkAsset
(
action
.
height
,
sell
.
AssetExec
,
sell
.
TokenSymbol
)
{
cfg
:=
action
.
api
.
GetConfig
()
if
!
checkAsset
(
cfg
,
action
.
height
,
sell
.
AssetExec
,
sell
.
TokenSymbol
)
{
return
nil
,
types
.
ErrInvalidParam
}
if
!
checkPrice
(
action
.
height
,
sell
.
PriceExec
,
sell
.
PriceExec
)
{
if
!
checkPrice
(
cfg
,
action
.
height
,
sell
.
PriceExec
,
sell
.
PriceExec
)
{
return
nil
,
types
.
ErrInvalidParam
}
if
!
notSameAsset
(
action
.
height
,
sell
.
AssetExec
,
sell
.
TokenSymbol
,
sell
.
PriceExec
,
sell
.
PriceExec
)
{
if
!
notSameAsset
(
cfg
,
action
.
height
,
sell
.
AssetExec
,
sell
.
TokenSymbol
,
sell
.
PriceExec
,
sell
.
PriceExec
)
{
return
nil
,
pty
.
ErrAssetAndPriceSame
}
accDB
,
err
:=
createAccountDB
(
action
.
height
,
action
.
db
,
sell
.
AssetExec
,
sell
.
TokenSymbol
)
accDB
,
err
:=
createAccountDB
(
cfg
,
action
.
height
,
action
.
db
,
sell
.
AssetExec
,
sell
.
TokenSymbol
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -320,7 +324,8 @@ func (action *tradeAction) tradeSell(sell *pty.TradeForSell) (*types.Receipt, er
}
func
(
action
*
tradeAction
)
tradeBuy
(
buyOrder
*
pty
.
TradeForBuy
)
(
*
types
.
Receipt
,
error
)
{
if
types
.
IsDappFork
(
action
.
height
,
pty
.
TradeX
,
pty
.
ForkTradeIDX
)
{
cfg
:=
action
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
action
.
height
,
pty
.
TradeX
,
pty
.
ForkTradeIDX
)
{
buyOrder
.
SellID
=
calcTokenSellID
(
buyOrder
.
SellID
)
}
if
buyOrder
.
BoardlotCnt
<
0
||
!
strings
.
HasPrefix
(
buyOrder
.
SellID
,
sellIDPrefix
)
{
...
...
@@ -347,7 +352,7 @@ func (action *tradeAction) tradeBuy(buyOrder *pty.TradeForBuy) (*types.Receipt,
return
nil
,
pty
.
ErrTCntLessThanMinBoardlot
}
priceAcc
,
err
:=
createPriceDB
(
action
.
height
,
action
.
db
,
sellOrder
.
PriceExec
,
sellOrder
.
PriceSymbol
)
priceAcc
,
err
:=
createPriceDB
(
cfg
,
action
.
height
,
action
.
db
,
sellOrder
.
PriceExec
,
sellOrder
.
PriceSymbol
)
if
err
!=
nil
{
tradelog
.
Error
(
"createPriceDB"
,
"addrFrom"
,
action
.
fromaddr
,
"height"
,
action
.
height
,
"price"
,
sellOrder
.
PriceExec
+
"-"
+
sellOrder
.
PriceSymbol
,
"err"
,
err
)
...
...
@@ -361,7 +366,7 @@ func (action *tradeAction) tradeBuy(buyOrder *pty.TradeForBuy) (*types.Receipt,
return
nil
,
err
}
//然后实现购买token的转移,因为这部分token在之前的卖单生成时已经进行冻结
accDB
,
err
:=
createAccountDB
(
action
.
height
,
action
.
db
,
sellOrder
.
AssetExec
,
sellOrder
.
TokenSymbol
)
accDB
,
err
:=
createAccountDB
(
cfg
,
action
.
height
,
action
.
db
,
sellOrder
.
AssetExec
,
sellOrder
.
TokenSymbol
)
if
err
!=
nil
{
tradelog
.
Error
(
"createAccountDB"
,
"addrFrom"
,
action
.
fromaddr
,
"height"
,
action
.
height
,
"price"
,
sellOrder
.
AssetExec
+
"-"
+
sellOrder
.
TokenSymbol
,
"err"
,
err
)
...
...
@@ -400,7 +405,8 @@ func (action *tradeAction) tradeBuy(buyOrder *pty.TradeForBuy) (*types.Receipt,
}
func
(
action
*
tradeAction
)
tradeRevokeSell
(
revoke
*
pty
.
TradeForRevokeSell
)
(
*
types
.
Receipt
,
error
)
{
if
types
.
IsDappFork
(
action
.
height
,
pty
.
TradeX
,
pty
.
ForkTradeIDX
)
{
cfg
:=
action
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
action
.
height
,
pty
.
TradeX
,
pty
.
ForkTradeIDX
)
{
revoke
.
SellID
=
calcTokenSellID
(
revoke
.
SellID
)
}
if
!
strings
.
HasPrefix
(
revoke
.
SellID
,
sellIDPrefix
)
{
...
...
@@ -424,7 +430,7 @@ func (action *tradeAction) tradeRevokeSell(revoke *pty.TradeForRevokeSell) (*typ
return
nil
,
pty
.
ErrTSellOrderRevoke
}
//然后实现购买token的转移,因为这部分token在之前的卖单生成时已经进行冻结
accDB
,
err
:=
createAccountDB
(
action
.
height
,
action
.
db
,
sellOrder
.
AssetExec
,
sellOrder
.
TokenSymbol
)
accDB
,
err
:=
createAccountDB
(
cfg
,
action
.
height
,
action
.
db
,
sellOrder
.
AssetExec
,
sellOrder
.
TokenSymbol
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -477,17 +483,19 @@ func (action *tradeAction) tradeBuyLimit(buy *pty.TradeForBuyLimit) (*types.Rece
}
}
if
!
checkAsset
(
action
.
height
,
buy
.
AssetExec
,
buy
.
TokenSymbol
)
{
cfg
:=
action
.
api
.
GetConfig
()
if
!
checkAsset
(
cfg
,
action
.
height
,
buy
.
AssetExec
,
buy
.
TokenSymbol
)
{
return
nil
,
types
.
ErrInvalidParam
}
if
!
checkPrice
(
action
.
height
,
buy
.
PriceExec
,
buy
.
PriceExec
)
{
if
!
checkPrice
(
cfg
,
action
.
height
,
buy
.
PriceExec
,
buy
.
PriceExec
)
{
return
nil
,
types
.
ErrInvalidParam
}
if
!
notSameAsset
(
action
.
height
,
buy
.
AssetExec
,
buy
.
TokenSymbol
,
buy
.
PriceExec
,
buy
.
PriceExec
)
{
if
!
notSameAsset
(
cfg
,
action
.
height
,
buy
.
AssetExec
,
buy
.
TokenSymbol
,
buy
.
PriceExec
,
buy
.
PriceExec
)
{
return
nil
,
pty
.
ErrAssetAndPriceSame
}
priceAcc
,
err
:=
createPriceDB
(
action
.
height
,
action
.
db
,
buy
.
PriceExec
,
buy
.
PriceSymbol
)
priceAcc
,
err
:=
createPriceDB
(
cfg
,
action
.
height
,
action
.
db
,
buy
.
PriceExec
,
buy
.
PriceSymbol
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -529,7 +537,8 @@ func (action *tradeAction) tradeBuyLimit(buy *pty.TradeForBuyLimit) (*types.Rece
}
func
(
action
*
tradeAction
)
tradeSellMarket
(
sellOrder
*
pty
.
TradeForSellMarket
)
(
*
types
.
Receipt
,
error
)
{
if
types
.
IsDappFork
(
action
.
height
,
pty
.
TradeX
,
pty
.
ForkTradeIDX
)
{
cfg
:=
action
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
action
.
height
,
pty
.
TradeX
,
pty
.
ForkTradeIDX
)
{
sellOrder
.
BuyID
=
calcTokenBuyID
(
sellOrder
.
BuyID
)
}
if
sellOrder
.
BoardlotCnt
<
0
||
!
strings
.
HasPrefix
(
sellOrder
.
BuyID
,
buyIDPrefix
)
{
...
...
@@ -554,7 +563,7 @@ func (action *tradeAction) tradeSellMarket(sellOrder *pty.TradeForSellMarket) (*
}
// 打token
accDB
,
err
:=
createAccountDB
(
action
.
height
,
action
.
db
,
buyOrder
.
AssetExec
,
buyOrder
.
TokenSymbol
)
accDB
,
err
:=
createAccountDB
(
cfg
,
action
.
height
,
action
.
db
,
buyOrder
.
AssetExec
,
buyOrder
.
TokenSymbol
)
if
err
!=
nil
{
tradelog
.
Error
(
"createAccountDB failed"
,
"err"
,
err
,
"order"
,
buyOrder
)
return
nil
,
err
...
...
@@ -570,7 +579,7 @@ func (action *tradeAction) tradeSellMarket(sellOrder *pty.TradeForSellMarket) (*
}
//首先购买费用的划转
priceAcc
,
err
:=
createPriceDB
(
action
.
height
,
action
.
db
,
buyOrder
.
PriceExec
,
buyOrder
.
PriceSymbol
)
priceAcc
,
err
:=
createPriceDB
(
cfg
,
action
.
height
,
action
.
db
,
buyOrder
.
PriceExec
,
buyOrder
.
PriceSymbol
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -608,7 +617,8 @@ func (action *tradeAction) tradeSellMarket(sellOrder *pty.TradeForSellMarket) (*
}
func
(
action
*
tradeAction
)
tradeRevokeBuyLimit
(
revoke
*
pty
.
TradeForRevokeBuy
)
(
*
types
.
Receipt
,
error
)
{
if
types
.
IsDappFork
(
action
.
height
,
pty
.
TradeX
,
pty
.
ForkTradeIDX
)
{
cfg
:=
action
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
action
.
height
,
pty
.
TradeX
,
pty
.
ForkTradeIDX
)
{
revoke
.
BuyID
=
calcTokenBuyID
(
revoke
.
BuyID
)
}
if
!
strings
.
HasPrefix
(
revoke
.
BuyID
,
buyIDPrefix
)
{
...
...
@@ -630,7 +640,7 @@ func (action *tradeAction) tradeRevokeBuyLimit(revoke *pty.TradeForRevokeBuy) (*
return
nil
,
pty
.
ErrTBuyOrderRevoke
}
priceAcc
,
err
:=
createPriceDB
(
action
.
height
,
action
.
db
,
buyOrder
.
PriceExec
,
buyOrder
.
PriceSymbol
)
priceAcc
,
err
:=
createPriceDB
(
cfg
,
action
.
height
,
action
.
db
,
buyOrder
.
PriceExec
,
buyOrder
.
PriceSymbol
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/dapp/trade/executor/util.go
View file @
af0be445
...
...
@@ -34,8 +34,8 @@ func GetExecSymbol(order *pt.SellOrder) (string, string) {
return
order
.
AssetExec
,
order
.
TokenSymbol
}
func
checkAsset
(
height
int64
,
exec
,
symbol
string
)
bool
{
if
types
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradeAssetX
)
{
func
checkAsset
(
cfg
*
types
.
Chain33Config
,
height
int64
,
exec
,
symbol
string
)
bool
{
if
cfg
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradeAssetX
)
{
if
exec
==
""
||
symbol
==
""
{
return
false
}
...
...
@@ -47,8 +47,8 @@ func checkAsset(height int64, exec, symbol string) bool {
return
true
}
func
checkPrice
(
height
int64
,
exec
,
symbol
string
)
bool
{
if
types
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradePriceX
)
{
func
checkPrice
(
cfg
*
types
.
Chain33Config
,
height
int64
,
exec
,
symbol
string
)
bool
{
if
cfg
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradePriceX
)
{
if
exec
==
""
&&
symbol
!=
""
||
exec
!=
""
&&
symbol
==
""
{
return
false
}
...
...
@@ -60,8 +60,8 @@ func checkPrice(height int64, exec, symbol string) bool {
return
true
}
func
notSameAsset
(
height
int64
,
assetExec
,
assetSymbol
,
priceExec
,
priceSymbol
string
)
bool
{
if
types
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradePriceX
)
{
func
notSameAsset
(
cfg
*
types
.
Chain33Config
,
height
int64
,
assetExec
,
assetSymbol
,
priceExec
,
priceSymbol
string
)
bool
{
if
cfg
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradePriceX
)
{
if
assetExec
==
priceExec
&&
assetSymbol
==
priceSymbol
{
return
false
}
...
...
@@ -69,30 +69,30 @@ func notSameAsset(height int64, assetExec, assetSymbol, priceExec, priceSymbol s
return
true
}
func
createAccountDB
(
height
int64
,
db
db
.
KV
,
exec
,
symbol
string
)
(
*
account
.
DB
,
error
)
{
if
types
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradeFixAssetDBX
)
{
func
createAccountDB
(
cfg
*
types
.
Chain33Config
,
height
int64
,
db
db
.
KV
,
exec
,
symbol
string
)
(
*
account
.
DB
,
error
)
{
if
cfg
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradeFixAssetDBX
)
{
if
exec
==
""
{
exec
=
defaultAssetExec
}
return
account
.
NewAccountDB
(
exec
,
symbol
,
db
)
}
else
if
types
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradeAssetX
)
{
}
else
if
cfg
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradeAssetX
)
{
return
account
.
NewAccountDB
(
exec
,
symbol
,
db
)
}
return
account
.
NewAccountDB
(
defaultAssetExec
,
symbol
,
db
)
}
func
createPriceDB
(
height
int64
,
db
db
.
KV
,
exec
,
symbol
string
)
(
*
account
.
DB
,
error
)
{
if
types
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradePriceX
)
{
func
createPriceDB
(
cfg
*
types
.
Chain33Config
,
height
int64
,
db
db
.
KV
,
exec
,
symbol
string
)
(
*
account
.
DB
,
error
)
{
if
cfg
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradePriceX
)
{
// 为空默认使用 coins
if
exec
==
""
{
acc
:=
account
.
NewCoinsAccount
()
acc
:=
account
.
NewCoinsAccount
(
cfg
)
acc
.
SetDB
(
db
)
return
acc
,
nil
}
return
account
.
NewAccountDB
(
exec
,
symbol
,
db
)
}
acc
:=
account
.
NewCoinsAccount
()
acc
:=
account
.
NewCoinsAccount
(
cfg
)
acc
.
SetDB
(
db
)
return
acc
,
nil
}
plugin/dapp/trade/rpc/rpc.go
View file @
af0be445
...
...
@@ -20,7 +20,8 @@ func (cc *channelClient) CreateRawTradeSellTx(ctx context.Context, in *ptypes.Tr
Ty
:
ptypes
.
TradeSellLimit
,
Value
:
&
ptypes
.
Trade_SellLimit
{
SellLimit
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
sell
))
cfg
:=
cc
.
GetConfig
()
tx
,
err
:=
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
sell
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -37,7 +38,8 @@ func (cc *channelClient) CreateRawTradeBuyTx(ctx context.Context, in *ptypes.Tra
Ty
:
ptypes
.
TradeBuyMarket
,
Value
:
&
ptypes
.
Trade_BuyMarket
{
BuyMarket
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
cfg
:=
cc
.
GetConfig
()
tx
,
err
:=
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -54,7 +56,8 @@ func (cc *channelClient) CreateRawTradeRevokeTx(ctx context.Context, in *ptypes.
Ty
:
ptypes
.
TradeRevokeSell
,
Value
:
&
ptypes
.
Trade_RevokeSell
{
RevokeSell
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
cfg
:=
cc
.
GetConfig
()
tx
,
err
:=
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -71,7 +74,8 @@ func (cc *channelClient) CreateRawTradeBuyLimitTx(ctx context.Context, in *ptype
Ty
:
ptypes
.
TradeBuyLimit
,
Value
:
&
ptypes
.
Trade_BuyLimit
{
BuyLimit
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
cfg
:=
cc
.
GetConfig
()
tx
,
err
:=
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -88,7 +92,8 @@ func (cc *channelClient) CreateRawTradeSellMarketTx(ctx context.Context, in *pty
Ty
:
ptypes
.
TradeSellMarket
,
Value
:
&
ptypes
.
Trade_SellMarket
{
SellMarket
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
cfg
:=
cc
.
GetConfig
()
tx
,
err
:=
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -105,7 +110,8 @@ func (cc *channelClient) CreateRawTradeRevokeBuyTx(ctx context.Context, in *ptyp
Ty
:
ptypes
.
TradeRevokeBuy
,
Value
:
&
ptypes
.
Trade_RevokeBuy
{
RevokeBuy
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
cfg
:=
cc
.
GetConfig
()
tx
,
err
:=
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/dapp/trade/types/trade.go
View file @
af0be445
...
...
@@ -124,6 +124,7 @@ func (t *tradeType) Amount(tx *types.Transaction) (int64, error) {
func
(
t
*
tradeType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
//var tx *types.Transaction
cfg
:=
t
.
GetConfig
()
if
action
==
"TradeSellLimit"
{
var
param
TradeSellTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -131,7 +132,7 @@ func (t *tradeType) CreateTx(action string, message json.RawMessage) (*types.Tra
tlog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawTradeSellTx
(
&
param
)
return
CreateRawTradeSellTx
(
cfg
,
&
param
)
}
else
if
action
==
"TradeBuyMarket"
{
var
param
TradeBuyTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -139,7 +140,7 @@ func (t *tradeType) CreateTx(action string, message json.RawMessage) (*types.Tra
tlog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawTradeBuyTx
(
&
param
)
return
CreateRawTradeBuyTx
(
cfg
,
&
param
)
}
else
if
action
==
"TradeSellRevoke"
{
var
param
TradeRevokeTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -147,7 +148,7 @@ func (t *tradeType) CreateTx(action string, message json.RawMessage) (*types.Tra
tlog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawTradeRevokeTx
(
&
param
)
return
CreateRawTradeRevokeTx
(
cfg
,
&
param
)
}
else
if
action
==
"TradeBuyLimit"
{
var
param
TradeBuyLimitTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -155,7 +156,7 @@ func (t *tradeType) CreateTx(action string, message json.RawMessage) (*types.Tra
tlog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawTradeBuyLimitTx
(
&
param
)
return
CreateRawTradeBuyLimitTx
(
cfg
,
&
param
)
}
else
if
action
==
"TradeSellMarket"
{
var
param
TradeSellMarketTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -163,7 +164,7 @@ func (t *tradeType) CreateTx(action string, message json.RawMessage) (*types.Tra
tlog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawTradeSellMarketTx
(
&
param
)
return
CreateRawTradeSellMarketTx
(
cfg
,
&
param
)
}
else
if
action
==
"TradeRevokeBuy"
{
var
param
TradeRevokeBuyTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -171,14 +172,14 @@ func (t *tradeType) CreateTx(action string, message json.RawMessage) (*types.Tra
tlog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawTradeRevokeBuyTx
(
&
param
)
return
CreateRawTradeRevokeBuyTx
(
cfg
,
&
param
)
}
return
nil
,
types
.
ErrNotSupport
}
//CreateRawTradeSellTx : 创建卖单交易
func
CreateRawTradeSellTx
(
parm
*
TradeSellTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTradeSellTx
(
cfg
*
types
.
Chain33Config
,
parm
*
TradeSellTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -199,11 +200,11 @@ func CreateRawTradeSellTx(parm *TradeSellTx) (*types.Transaction, error) {
Ty
:
TradeSellLimit
,
Value
:
&
Trade_SellLimit
{
v
},
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
sell
))
return
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
TradeX
),
types
.
Encode
(
sell
))
}
//CreateRawTradeBuyTx :创建想指定卖单发起的买单交易
func
CreateRawTradeBuyTx
(
parm
*
TradeBuyTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTradeBuyTx
(
cfg
*
types
.
Chain33Config
,
parm
*
TradeBuyTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -212,11 +213,11 @@ func CreateRawTradeBuyTx(parm *TradeBuyTx) (*types.Transaction, error) {
Ty
:
TradeBuyMarket
,
Value
:
&
Trade_BuyMarket
{
v
},
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
return
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
}
//CreateRawTradeRevokeTx :创建取消卖单的交易
func
CreateRawTradeRevokeTx
(
parm
*
TradeRevokeTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTradeRevokeTx
(
cfg
*
types
.
Chain33Config
,
parm
*
TradeRevokeTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -226,11 +227,11 @@ func CreateRawTradeRevokeTx(parm *TradeRevokeTx) (*types.Transaction, error) {
Ty
:
TradeRevokeSell
,
Value
:
&
Trade_RevokeSell
{
v
},
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
return
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
}
//CreateRawTradeBuyLimitTx :创建买单交易
func
CreateRawTradeBuyLimitTx
(
parm
*
TradeBuyLimitTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTradeBuyLimitTx
(
cfg
*
types
.
Chain33Config
,
parm
*
TradeBuyLimitTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -248,11 +249,11 @@ func CreateRawTradeBuyLimitTx(parm *TradeBuyLimitTx) (*types.Transaction, error)
Ty
:
TradeBuyLimit
,
Value
:
&
Trade_BuyLimit
{
v
},
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buyLimit
))
return
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
TradeX
),
types
.
Encode
(
buyLimit
))
}
//CreateRawTradeSellMarketTx : 创建向指定买单出售token的卖单交易
func
CreateRawTradeSellMarketTx
(
parm
*
TradeSellMarketTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTradeSellMarketTx
(
cfg
*
types
.
Chain33Config
,
parm
*
TradeSellMarketTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -261,11 +262,11 @@ func CreateRawTradeSellMarketTx(parm *TradeSellMarketTx) (*types.Transaction, er
Ty
:
TradeSellMarket
,
Value
:
&
Trade_SellMarket
{
v
},
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
sellMarket
))
return
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
TradeX
),
types
.
Encode
(
sellMarket
))
}
//CreateRawTradeRevokeBuyTx : 取消发起的买单交易
func
CreateRawTradeRevokeBuyTx
(
parm
*
TradeRevokeBuyTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTradeRevokeBuyTx
(
cfg
*
types
.
Chain33Config
,
parm
*
TradeRevokeBuyTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -275,5 +276,5 @@ func CreateRawTradeRevokeBuyTx(parm *TradeRevokeBuyTx) (*types.Transaction, erro
Ty
:
TradeRevokeBuy
,
Value
:
&
Trade_RevokeBuy
{
v
},
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
return
types
.
CreateFormatTx
(
cfg
,
cfg
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
}
plugin/dapp/unfreeze/executor/exec.go
View file @
af0be445
...
...
@@ -48,7 +48,8 @@ func (u *Unfreeze) Exec_Create(payload *pty.UnfreezeCreate, tx *types.Transactio
// Exec_Withdraw 执行冻结合约中提币
func
(
u
*
Unfreeze
)
Exec_Withdraw
(
payload
*
pty
.
UnfreezeWithdraw
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
if
types
.
IsDappFork
(
u
.
GetHeight
(),
pty
.
UnfreezeX
,
pty
.
ForkUnfreezeIDX
)
{
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsDappFork
(
u
.
GetHeight
(),
pty
.
UnfreezeX
,
pty
.
ForkUnfreezeIDX
)
{
payload
.
UnfreezeID
=
unfreezeIDFromHex
(
payload
.
UnfreezeID
)
}
unfreeze
,
err
:=
loadUnfreeze
(
payload
.
UnfreezeID
,
u
.
GetStateDB
())
...
...
@@ -87,7 +88,8 @@ func (u *Unfreeze) Exec_Withdraw(payload *pty.UnfreezeWithdraw, tx *types.Transa
// Exec_Terminate 执行终止冻结合约
func
(
u
*
Unfreeze
)
Exec_Terminate
(
payload
*
pty
.
UnfreezeTerminate
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
if
types
.
IsDappFork
(
u
.
GetHeight
(),
pty
.
UnfreezeX
,
pty
.
ForkUnfreezeIDX
)
{
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsDappFork
(
u
.
GetHeight
(),
pty
.
UnfreezeX
,
pty
.
ForkUnfreezeIDX
)
{
payload
.
UnfreezeID
=
unfreezeIDFromHex
(
payload
.
UnfreezeID
)
}
unfreeze
,
err
:=
loadUnfreeze
(
payload
.
UnfreezeID
,
u
.
GetStateDB
())
...
...
@@ -135,7 +137,8 @@ func (u *Unfreeze) newEntity(payload *pty.UnfreezeCreate, tx *types.Transaction)
if
unfreeze
.
StartTime
==
0
{
unfreeze
.
StartTime
=
u
.
GetBlockTime
()
}
means
,
err
:=
newMeans
(
payload
.
Means
,
u
.
GetHeight
())
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
means
,
err
:=
newMeans
(
cfg
,
payload
.
Means
,
u
.
GetHeight
())
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -178,7 +181,8 @@ func getUnfreezeLog(prev, cur *pty.Unfreeze, ty int32) *types.ReceiptLog {
// 提取解冻币
func
(
u
*
Unfreeze
)
withdraw
(
unfreeze
*
pty
.
Unfreeze
)
(
int64
,
*
types
.
Receipt
,
error
)
{
means
,
err
:=
newMeans
(
unfreeze
.
Means
,
u
.
GetHeight
())
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
means
,
err
:=
newMeans
(
cfg
,
unfreeze
.
Means
,
u
.
GetHeight
())
if
err
!=
nil
{
return
0
,
nil
,
err
...
...
@@ -210,11 +214,12 @@ func (u *Unfreeze) terminator(unfreeze *pty.Unfreeze) (int64, *types.Receipt, er
unfreezeOld
:=
*
unfreeze
var
amount
int64
if
types
.
IsDappFork
(
u
.
GetHeight
(),
pty
.
UnfreezeX
,
"ForkTerminatePart"
)
{
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsDappFork
(
u
.
GetHeight
(),
pty
.
UnfreezeX
,
"ForkTerminatePart"
)
{
if
unfreeze
.
Terminated
{
return
0
,
nil
,
pty
.
ErrTerminated
}
m
,
err
:=
newMeans
(
unfreeze
.
Means
,
u
.
GetHeight
())
m
,
err
:=
newMeans
(
cfg
,
unfreeze
.
Means
,
u
.
GetHeight
())
if
err
!=
nil
{
return
0
,
nil
,
err
}
...
...
plugin/dapp/unfreeze/executor/means.go
View file @
af0be445
...
...
@@ -15,8 +15,8 @@ type Means interface {
calcFrozen
(
unfreeze
*
pty
.
Unfreeze
,
now
int64
)
(
int64
,
error
)
}
func
newMeans
(
means
string
,
height
int64
)
(
Means
,
error
)
{
if
types
.
IsDappFork
(
height
,
pty
.
UnfreezeX
,
"ForkTerminatePart"
)
{
func
newMeans
(
cfg
*
types
.
Chain33Config
,
means
string
,
height
int64
)
(
Means
,
error
)
{
if
cfg
.
IsDappFork
(
height
,
pty
.
UnfreezeX
,
"ForkTerminatePart"
)
{
if
means
==
"FixAmount"
{
return
&
fixAmountV2
{},
nil
}
else
if
means
==
"LeftProportion"
{
...
...
plugin/dapp/unfreeze/executor/query.go
View file @
af0be445
...
...
@@ -15,7 +15,8 @@ import (
// Query_GetUnfreezeWithdraw 查询合约可提币量
func
(
u
*
Unfreeze
)
Query_GetUnfreezeWithdraw
(
in
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
return
QueryWithdraw
(
u
.
GetStateDB
(),
in
.
GetData
())
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
return
QueryWithdraw
(
cfg
,
u
.
GetStateDB
(),
in
.
GetData
())
}
// Query_GetUnfreeze 查询合约状态
...
...
@@ -34,7 +35,7 @@ func (u *Unfreeze) Query_ListUnfreezeByBeneficiary(in *pty.ReqUnfreezes) (types.
}
// QueryWithdraw 查询可提币状态
func
QueryWithdraw
(
stateDB
dbm
.
KV
,
id
string
)
(
types
.
Message
,
error
)
{
func
QueryWithdraw
(
cfg
*
types
.
Chain33Config
,
stateDB
dbm
.
KV
,
id
string
)
(
types
.
Message
,
error
)
{
id
=
unfreezeIDFromHex
(
id
)
unfreeze
,
err
:=
loadUnfreeze
(
id
,
stateDB
)
if
err
!=
nil
{
...
...
@@ -43,7 +44,7 @@ func QueryWithdraw(stateDB dbm.KV, id string) (types.Message, error) {
}
currentTime
:=
time
.
Now
()
.
Unix
()
reply
:=
&
pty
.
ReplyQueryUnfreezeWithdraw
{
UnfreezeID
:
id
}
available
,
err
:=
getWithdrawAvailable
(
unfreeze
,
currentTime
)
available
,
err
:=
getWithdrawAvailable
(
cfg
,
unfreeze
,
currentTime
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -52,8 +53,8 @@ func QueryWithdraw(stateDB dbm.KV, id string) (types.Message, error) {
return
reply
,
nil
}
func
getWithdrawAvailable
(
unfreeze
*
pty
.
Unfreeze
,
calcTime
int64
)
(
int64
,
error
)
{
means
,
err
:=
newMeans
(
unfreeze
.
Means
,
1500000
)
func
getWithdrawAvailable
(
cfg
*
types
.
Chain33Config
,
unfreeze
*
pty
.
Unfreeze
,
calcTime
int64
)
(
int64
,
error
)
{
means
,
err
:=
newMeans
(
cfg
,
unfreeze
.
Means
,
1500000
)
if
err
!=
nil
{
return
0
,
err
}
...
...
plugin/dapp/unfreeze/rpc/rpc.go
View file @
af0be445
...
...
@@ -63,7 +63,8 @@ func (c *Jrpc) CreateRawUnfreezeCreate(param *pty.UnfreezeCreate, result *interf
if
param
==
nil
{
return
types
.
ErrInvalidParam
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
pty
.
UnfreezeX
),
"Create"
,
param
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
pty
.
UnfreezeX
),
"Create"
,
param
)
if
err
!=
nil
{
return
err
}
...
...
@@ -76,7 +77,8 @@ func (c *Jrpc) CreateRawUnfreezeWithdraw(param *pty.UnfreezeWithdraw, result *in
if
param
==
nil
{
return
types
.
ErrInvalidParam
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
pty
.
UnfreezeX
),
"Withdraw"
,
param
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
pty
.
UnfreezeX
),
"Withdraw"
,
param
)
if
err
!=
nil
{
return
err
}
...
...
@@ -89,7 +91,8 @@ func (c *Jrpc) CreateRawUnfreezeTerminate(param *pty.UnfreezeTerminate, result *
if
param
==
nil
{
return
types
.
ErrInvalidParam
}
data
,
err
:=
types
.
CallCreateTx
(
types
.
ExecName
(
pty
.
UnfreezeX
),
"Terminate"
,
param
)
cfg
:=
c
.
cli
.
GetConfig
()
data
,
err
:=
types
.
CallCreateTx
(
cfg
,
cfg
.
ExecName
(
pty
.
UnfreezeX
),
"Terminate"
,
param
)
if
err
!=
nil
{
return
err
}
...
...
plugin/dapp/unfreeze/types/types.go
View file @
af0be445
...
...
@@ -38,8 +38,8 @@ func InitExecutor(cfg *types.Chain33Config) {
}
//getRealExecName
func
getRealExecName
(
paraName
string
)
string
{
return
types
.
ExecName
(
paraName
+
UnfreezeX
)
func
getRealExecName
(
cfg
*
types
.
Chain33Config
,
paraName
string
)
string
{
return
cfg
.
ExecName
(
paraName
+
UnfreezeX
)
}
// NewType 生成新的基础类型
...
...
@@ -117,11 +117,12 @@ func (u *UnfreezeType) CreateTx(action string, message json.RawMessage) (*types.
// RPC_UnfreezeCreateTx 创建冻结合约交易入口
func
(
u
*
UnfreezeType
)
RPC_UnfreezeCreateTx
(
parm
*
UnfreezeCreate
)
(
*
types
.
Transaction
,
error
)
{
return
CreateUnfreezeCreateTx
(
types
.
GetParaName
(),
parm
)
cfg
:=
u
.
GetConfig
()
return
CreateUnfreezeCreateTx
(
cfg
,
cfg
.
GetParaName
(),
parm
)
}
// CreateUnfreezeCreateTx 创建冻结合约交易
func
CreateUnfreezeCreateTx
(
title
string
,
parm
*
UnfreezeCreate
)
(
*
types
.
Transaction
,
error
)
{
func
CreateUnfreezeCreateTx
(
cfg
*
types
.
Chain33Config
,
title
string
,
parm
*
UnfreezeCreate
)
(
*
types
.
Transaction
,
error
)
{
tlog
.
Error
(
"CreateUnfreezeCreateTx"
,
"parm"
,
parm
)
if
parm
==
nil
{
tlog
.
Error
(
"RPC_UnfreezeCreateTx"
,
"parm"
,
parm
)
...
...
@@ -140,22 +141,23 @@ func CreateUnfreezeCreateTx(title string, parm *UnfreezeCreate) (*types.Transact
Value
:
&
UnfreezeAction_Create
{
parm
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
getRealExecName
(
title
)),
Execer
:
[]
byte
(
getRealExecName
(
cfg
,
title
)),
Payload
:
types
.
Encode
(
create
),
Nonce
:
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
.
Int63
(),
To
:
address
.
ExecAddress
(
getRealExecName
(
types
.
GetParaName
())),
To
:
address
.
ExecAddress
(
getRealExecName
(
cfg
,
cfg
.
GetParaName
())),
}
tx
.
SetRealFee
(
types
.
GInt
(
"MinFee"
))
tx
.
SetRealFee
(
cfg
.
GInt
(
"MinFee"
))
return
tx
,
nil
}
// RPC_UnfreezeWithdrawTx 创建提币交易入口
func
(
u
*
UnfreezeType
)
RPC_UnfreezeWithdrawTx
(
parm
*
UnfreezeWithdraw
)
(
*
types
.
Transaction
,
error
)
{
return
CreateUnfreezeWithdrawTx
(
types
.
GetParaName
(),
parm
)
cfg
:=
u
.
GetConfig
()
return
CreateUnfreezeWithdrawTx
(
cfg
,
cfg
.
GetParaName
(),
parm
)
}
// CreateUnfreezeWithdrawTx 创建提币交易
func
CreateUnfreezeWithdrawTx
(
title
string
,
parm
*
UnfreezeWithdraw
)
(
*
types
.
Transaction
,
error
)
{
func
CreateUnfreezeWithdrawTx
(
cfg
*
types
.
Chain33Config
,
title
string
,
parm
*
UnfreezeWithdraw
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
tlog
.
Error
(
"RPC_UnfreezeWithdrawTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -168,22 +170,23 @@ func CreateUnfreezeWithdrawTx(title string, parm *UnfreezeWithdraw) (*types.Tran
Value
:
&
UnfreezeAction_Withdraw
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
getRealExecName
(
title
)),
Execer
:
[]
byte
(
getRealExecName
(
cfg
,
title
)),
Payload
:
types
.
Encode
(
withdraw
),
Nonce
:
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
.
Int63
(),
To
:
address
.
ExecAddress
(
getRealExecName
(
types
.
GetParaName
())),
To
:
address
.
ExecAddress
(
getRealExecName
(
cfg
,
cfg
.
GetParaName
())),
}
tx
.
SetRealFee
(
types
.
GInt
(
"MinFee"
))
tx
.
SetRealFee
(
cfg
.
GInt
(
"MinFee"
))
return
tx
,
nil
}
// RPC_UnfreezeTerminateTx 创建终止冻结合约入口
func
(
u
*
UnfreezeType
)
RPC_UnfreezeTerminateTx
(
parm
*
UnfreezeTerminate
)
(
*
types
.
Transaction
,
error
)
{
return
CreateUnfreezeTerminateTx
(
types
.
GetParaName
(),
parm
)
cfg
:=
u
.
GetConfig
()
return
CreateUnfreezeTerminateTx
(
cfg
,
cfg
.
GetParaName
(),
parm
)
}
// CreateUnfreezeTerminateTx 创建终止冻结合约
func
CreateUnfreezeTerminateTx
(
title
string
,
parm
*
UnfreezeTerminate
)
(
*
types
.
Transaction
,
error
)
{
func
CreateUnfreezeTerminateTx
(
cfg
*
types
.
Chain33Config
,
title
string
,
parm
*
UnfreezeTerminate
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
tlog
.
Error
(
"RPC_UnfreezeTerminateTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -196,12 +199,12 @@ func CreateUnfreezeTerminateTx(title string, parm *UnfreezeTerminate) (*types.Tr
Value
:
&
UnfreezeAction_Terminate
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
getRealExecName
(
title
)),
Execer
:
[]
byte
(
getRealExecName
(
cfg
,
title
)),
Payload
:
types
.
Encode
(
terminate
),
Nonce
:
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
.
Int63
(),
To
:
address
.
ExecAddress
(
getRealExecName
(
types
.
GetParaName
())),
To
:
address
.
ExecAddress
(
getRealExecName
(
cfg
,
cfg
.
GetParaName
())),
}
tx
.
SetRealFee
(
types
.
GInt
(
"MinFee"
))
tx
.
SetRealFee
(
cfg
.
GInt
(
"MinFee"
))
return
tx
,
nil
}
...
...
plugin/dapp/valnode/types/valnode.go
View file @
af0be445
...
...
@@ -25,11 +25,6 @@ func InitExecutor(cfg *types.Chain33Config) {
types
.
RegistorExecutor
(
ValNodeX
,
NewType
(
cfg
))
}
// GetExecName get exec name
func
GetExecName
()
string
{
return
types
.
ExecName
(
ValNodeX
)
}
// ValNodeType stuct
type
ValNodeType
struct
{
types
.
ExecTypeBase
...
...
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