Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
100bcc22
Commit
100bcc22
authored
Aug 18, 2021
by
mdj33
Committed by
vipwzw
Aug 26, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coin precision support configure
parent
45329fb6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
36 changed files
with
420 additions
and
261 deletions
+420
-261
paracommitmsg.go
plugin/consensus/para/paracommitmsg.go
+3
-3
proposal_project.go
plugin/dapp/autonomy/commands/proposal_project.go
+2
-1
proposal_rule.go
plugin/dapp/autonomy/commands/proposal_rule.go
+2
-1
ruleaction.go
plugin/dapp/autonomy/executor/ruleaction.go
+11
-10
ruleaction_test.go
plugin/dapp/autonomy/executor/ruleaction_test.go
+12
-12
blackwhite.go
plugin/dapp/blackwhite/commands/blackwhite.go
+19
-4
action.go
plugin/dapp/blackwhite/executor/action.go
+28
-14
collateralizedb.go
plugin/dapp/collateralize/executor/collateralizedb.go
+3
-3
evm.go
plugin/dapp/evm/commands/evm.go
+16
-7
exchange.go
plugin/dapp/exchange/executor/exchange.go
+3
-2
exchange_test.go
plugin/dapp/exchange/executor/exchange_test.go
+3
-3
exchangedb.go
plugin/dapp/exchange/executor/exchangedb.go
+22
-20
exchange_test.go
plugin/dapp/exchange/test/exchange_test.go
+2
-2
hashlock.go
plugin/dapp/hashlock/commands/hashlock.go
+49
-24
issuancedb.go
plugin/dapp/issuance/executor/issuancedb.go
+3
-3
lotterydb.go
plugin/dapp/lottery/executor/lotterydb.go
+7
-7
multisig.go
plugin/dapp/multisig/commands/multisig.go
+10
-9
account.go
plugin/dapp/paracross/executor/account.go
+4
-4
game.go
plugin/dapp/pokerbull/cmd/game.go
+22
-10
pokerbulldb.go
plugin/dapp/pokerbull/executor/pokerbulldb.go
+2
-1
query.go
plugin/dapp/pokerbull/executor/query.go
+2
-2
privacy.go
plugin/dapp/privacy/commands/privacy.go
+0
-0
privacy.go
plugin/dapp/privacy/executor/privacy.go
+3
-2
rpc.go
plugin/dapp/privacy/rpc/rpc.go
+2
-1
privacybizpolicy.go
plugin/dapp/privacy/wallet/privacybizpolicy.go
+1
-1
privacystore.go
plugin/dapp/privacy/wallet/privacystore.go
+7
-7
privacystore_test.go
plugin/dapp/privacy/wallet/privacystore_test.go
+1
-1
relay.go
plugin/dapp/relay/commands/relay.go
+5
-4
relaydb.go
plugin/dapp/relay/executor/relaydb.go
+11
-12
retrieve.go
plugin/dapp/retrieve/cmd/retrieve.go
+56
-28
rpc.go
plugin/dapp/ticket/rpc/rpc.go
+1
-1
token.go
plugin/dapp/token/commands/token.go
+63
-20
trade.go
plugin/dapp/trade/commands/trade.go
+11
-10
local_order.go
plugin/dapp/trade/executor/local_order.go
+13
-10
tradedb.go
plugin/dapp/trade/executor/tradedb.go
+20
-21
types.go
plugin/dapp/trade/rpc/types.go
+1
-1
No files found.
plugin/consensus/para/paracommitmsg.go
View file @
100bcc22
...
@@ -408,8 +408,8 @@ func (client *commitMsgClient) isSync() bool {
...
@@ -408,8 +408,8 @@ func (client *commitMsgClient) isSync() bool {
func
(
client
*
commitMsgClient
)
getSendingTx
(
startHeight
,
endHeight
int64
)
(
*
types
.
Transaction
,
int64
)
{
func
(
client
*
commitMsgClient
)
getSendingTx
(
startHeight
,
endHeight
int64
)
(
*
types
.
Transaction
,
int64
)
{
count
:=
endHeight
-
startHeight
count
:=
endHeight
-
startHeight
if
count
>
types
.
TxGroupMaxCount
{
if
count
>
int64
(
types
.
MaxTxGroupSize
)
{
count
=
types
.
TxGroupMaxCount
count
=
int64
(
types
.
MaxTxGroupSize
)
}
}
status
,
err
:=
client
.
getNodeStatus
(
startHeight
+
1
,
startHeight
+
count
)
status
,
err
:=
client
.
getNodeStatus
(
startHeight
+
1
,
startHeight
+
count
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -706,7 +706,7 @@ func (client *commitMsgClient) getNodeStatus(start, end int64) ([]*pt.ParacrossN
...
@@ -706,7 +706,7 @@ func (client *commitMsgClient) getNodeStatus(start, end int64) ([]*pt.ParacrossN
//2,如果20个块都是 commit tx的空块,20个块打包一次发送,尽量减少commit tx造成的空块
//2,如果20个块都是 commit tx的空块,20个块打包一次发送,尽量减少commit tx造成的空块
//3,如果形如xxoxx的块排列,x代表commit空块,o代表实际的块,即只要不全部是commit块,也要全部打包一起发出去
//3,如果形如xxoxx的块排列,x代表commit空块,o代表实际的块,即只要不全部是commit块,也要全部打包一起发出去
//如果=0 意味着全部是paracross commit tx,延迟发送
//如果=0 意味着全部是paracross commit tx,延迟发送
if
needSentTxs
==
0
&&
len
(
ret
)
<
types
.
TxGroupMaxCount
{
if
needSentTxs
==
0
&&
len
(
ret
)
<
int
(
types
.
MaxTxGroupSize
)
{
plog
.
Debug
(
"para commitmsg all self-consensus commit tx,send delay"
,
"start"
,
start
,
"end"
,
end
)
plog
.
Debug
(
"para commitmsg all self-consensus commit tx,send delay"
,
"start"
,
start
,
"end"
,
end
)
return
nil
,
nil
return
nil
,
nil
}
}
...
...
plugin/dapp/autonomy/commands/proposal_project.go
View file @
100bcc22
...
@@ -7,9 +7,10 @@ package commands
...
@@ -7,9 +7,10 @@ package commands
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"os"
commandtypes
"github.com/33cn/chain33/system/dapp/commands/types"
commandtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
"github.com/pkg/errors"
"os"
"strings"
"strings"
...
...
plugin/dapp/autonomy/commands/proposal_rule.go
View file @
100bcc22
...
@@ -7,9 +7,10 @@ package commands
...
@@ -7,9 +7,10 @@ package commands
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"github.com/pkg/errors"
"os"
"os"
"github.com/pkg/errors"
"strings"
"strings"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
...
...
plugin/dapp/autonomy/executor/ruleaction.go
View file @
100bcc22
...
@@ -26,17 +26,18 @@ const (
...
@@ -26,17 +26,18 @@ const (
minPublicPeriod
int32
=
17280
*
7
minPublicPeriod
int32
=
17280
*
7
// 最大公示周期
// 最大公示周期
maxPublicPeriod
int32
=
17280
*
14
maxPublicPeriod
int32
=
17280
*
14
// 最小重大项目阈值
// 最小重大项目阈值
(coin)
minLargeProjectAmount
=
types
.
Coin
*
100
*
10000
minLargeProjectAmount
=
100
*
10000
// 最大重大项目阈值
// 最大重大项目阈值
(coin)
maxLargeProjectAmount
=
types
.
Coin
*
300
*
10000
maxLargeProjectAmount
=
300
*
10000
// 最小提案金
// 最小提案金
(coin)
minProposalAmount
=
types
.
Coin
*
20
minProposalAmount
=
20
// 最大提案金
// 最大提案金
(coin)
maxProposalAmount
=
types
.
Coin
*
2000
maxProposalAmount
=
2000
)
)
func
(
a
*
action
)
propRule
(
prob
*
auty
.
ProposalRule
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
propRule
(
prob
*
auty
.
ProposalRule
)
(
*
types
.
Receipt
,
error
)
{
cfg
:=
a
.
api
.
GetConfig
()
//如果全小于等于0,则说明该提案规则参数不正确
//如果全小于等于0,则说明该提案规则参数不正确
if
prob
.
RuleCfg
==
nil
||
prob
.
RuleCfg
.
BoardApproveRatio
<=
0
&&
prob
.
RuleCfg
.
PubOpposeRatio
<=
0
&&
if
prob
.
RuleCfg
==
nil
||
prob
.
RuleCfg
.
BoardApproveRatio
<=
0
&&
prob
.
RuleCfg
.
PubOpposeRatio
<=
0
&&
prob
.
RuleCfg
.
ProposalAmount
<=
0
&&
prob
.
RuleCfg
.
LargeProjectAmount
<=
0
&&
prob
.
RuleCfg
.
PublicPeriod
<=
0
{
prob
.
RuleCfg
.
ProposalAmount
<=
0
&&
prob
.
RuleCfg
.
LargeProjectAmount
<=
0
&&
prob
.
RuleCfg
.
PublicPeriod
<=
0
{
...
@@ -46,8 +47,8 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) {
...
@@ -46,8 +47,8 @@ func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) {
if
(
prob
.
RuleCfg
.
BoardApproveRatio
>
0
&&
(
prob
.
RuleCfg
.
BoardApproveRatio
>
maxBoardApproveRatio
||
prob
.
RuleCfg
.
BoardApproveRatio
<
minBoardApproveRatio
))
||
if
(
prob
.
RuleCfg
.
BoardApproveRatio
>
0
&&
(
prob
.
RuleCfg
.
BoardApproveRatio
>
maxBoardApproveRatio
||
prob
.
RuleCfg
.
BoardApproveRatio
<
minBoardApproveRatio
))
||
(
prob
.
RuleCfg
.
PubOpposeRatio
>
0
&&
(
prob
.
RuleCfg
.
PubOpposeRatio
>
maxPubOpposeRatio
||
prob
.
RuleCfg
.
PubOpposeRatio
<
minPubOpposeRatio
))
||
(
prob
.
RuleCfg
.
PubOpposeRatio
>
0
&&
(
prob
.
RuleCfg
.
PubOpposeRatio
>
maxPubOpposeRatio
||
prob
.
RuleCfg
.
PubOpposeRatio
<
minPubOpposeRatio
))
||
(
prob
.
RuleCfg
.
PublicPeriod
>
0
&&
(
prob
.
RuleCfg
.
PublicPeriod
>
maxPublicPeriod
||
prob
.
RuleCfg
.
PublicPeriod
<
minPublicPeriod
))
||
(
prob
.
RuleCfg
.
PublicPeriod
>
0
&&
(
prob
.
RuleCfg
.
PublicPeriod
>
maxPublicPeriod
||
prob
.
RuleCfg
.
PublicPeriod
<
minPublicPeriod
))
||
(
prob
.
RuleCfg
.
LargeProjectAmount
>
0
&&
(
prob
.
RuleCfg
.
LargeProjectAmount
>
maxLargeProjectAmount
||
prob
.
RuleCfg
.
LargeProjectAmount
<
minLargeProjectAmount
))
||
(
prob
.
RuleCfg
.
LargeProjectAmount
>
0
&&
(
prob
.
RuleCfg
.
LargeProjectAmount
>
maxLargeProjectAmount
*
cfg
.
GetCoinPrecision
()
||
prob
.
RuleCfg
.
LargeProjectAmount
<
minLargeProjectAmount
*
cfg
.
GetCoinPrecision
()
))
||
(
prob
.
RuleCfg
.
ProposalAmount
>
0
&&
(
prob
.
RuleCfg
.
ProposalAmount
>
maxProposalAmount
||
prob
.
RuleCfg
.
ProposalAmount
<
minProposalAmount
))
{
(
prob
.
RuleCfg
.
ProposalAmount
>
0
&&
(
prob
.
RuleCfg
.
ProposalAmount
>
maxProposalAmount
*
cfg
.
GetCoinPrecision
()
||
prob
.
RuleCfg
.
ProposalAmount
<
minProposalAmount
*
cfg
.
GetCoinPrecision
()
))
{
alog
.
Error
(
"propRule RuleCfg invaild"
,
"ruleCfg"
,
prob
.
RuleCfg
)
alog
.
Error
(
"propRule RuleCfg invaild"
,
"ruleCfg"
,
prob
.
RuleCfg
)
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
...
...
plugin/dapp/autonomy/executor/ruleaction_test.go
View file @
100bcc22
...
@@ -22,8 +22,8 @@ import (
...
@@ -22,8 +22,8 @@ import (
const
(
const
(
testBoardApproveRatio
int32
=
60
testBoardApproveRatio
int32
=
60
testPubOpposeRatio
int32
=
35
testPubOpposeRatio
int32
=
35
testProposalAmount
=
minProposalAmount
*
2
testProposalAmount
=
minProposalAmount
*
types
.
DefaultCoinPrecision
*
2
testLargeProjectAmount
=
minLargeProjectAmount
*
2
testLargeProjectAmount
=
minLargeProjectAmount
*
2
*
types
.
DefaultCoinPrecision
testPublicPeriod
=
minPublicPeriod
testPublicPeriod
=
minPublicPeriod
)
)
...
@@ -39,8 +39,8 @@ func TestPropRule(t *testing.T) {
...
@@ -39,8 +39,8 @@ func TestPropRule(t *testing.T) {
RuleCfg
:
&
auty
.
RuleConfig
{
RuleCfg
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
maxBoardApproveRatio
,
BoardApproveRatio
:
maxBoardApproveRatio
,
PubOpposeRatio
:
maxPubOpposeRatio
,
PubOpposeRatio
:
maxPubOpposeRatio
,
ProposalAmount
:
maxProposalAmount
,
ProposalAmount
:
maxProposalAmount
*
types
.
DefaultCoinPrecision
,
LargeProjectAmount
:
maxLargeProjectAmount
,
LargeProjectAmount
:
maxLargeProjectAmount
*
types
.
DefaultCoinPrecision
,
PublicPeriod
:
maxPublicPeriod
,
PublicPeriod
:
maxPublicPeriod
,
},
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
...
@@ -50,8 +50,8 @@ func TestPropRule(t *testing.T) {
...
@@ -50,8 +50,8 @@ func TestPropRule(t *testing.T) {
RuleCfg
:
&
auty
.
RuleConfig
{
RuleCfg
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
minBoardApproveRatio
,
BoardApproveRatio
:
minBoardApproveRatio
,
PubOpposeRatio
:
minPubOpposeRatio
,
PubOpposeRatio
:
minPubOpposeRatio
,
ProposalAmount
:
minProposalAmount
,
ProposalAmount
:
minProposalAmount
*
types
.
DefaultCoinPrecision
,
LargeProjectAmount
:
minLargeProjectAmount
,
LargeProjectAmount
:
minLargeProjectAmount
*
types
.
DefaultCoinPrecision
,
PublicPeriod
:
minPublicPeriod
,
PublicPeriod
:
minPublicPeriod
,
},
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
...
@@ -61,8 +61,8 @@ func TestPropRule(t *testing.T) {
...
@@ -61,8 +61,8 @@ func TestPropRule(t *testing.T) {
RuleCfg
:
&
auty
.
RuleConfig
{
RuleCfg
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
minBoardApproveRatio
-
1
,
BoardApproveRatio
:
minBoardApproveRatio
-
1
,
PubOpposeRatio
:
minPubOpposeRatio
-
1
,
PubOpposeRatio
:
minPubOpposeRatio
-
1
,
ProposalAmount
:
minProposalAmount
-
1
,
ProposalAmount
:
minProposalAmount
*
types
.
DefaultCoinPrecision
-
1
,
LargeProjectAmount
:
minLargeProjectAmount
-
1
,
LargeProjectAmount
:
minLargeProjectAmount
*
types
.
DefaultCoinPrecision
-
1
,
PublicPeriod
:
minPublicPeriod
-
1
,
PublicPeriod
:
minPublicPeriod
-
1
,
},
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
...
@@ -72,8 +72,8 @@ func TestPropRule(t *testing.T) {
...
@@ -72,8 +72,8 @@ func TestPropRule(t *testing.T) {
RuleCfg
:
&
auty
.
RuleConfig
{
RuleCfg
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
maxBoardApproveRatio
+
1
,
BoardApproveRatio
:
maxBoardApproveRatio
+
1
,
PubOpposeRatio
:
maxPubOpposeRatio
+
1
,
PubOpposeRatio
:
maxPubOpposeRatio
+
1
,
ProposalAmount
:
maxProposalAmount
+
1
,
ProposalAmount
:
maxProposalAmount
*
types
.
DefaultCoinPrecision
+
1
,
LargeProjectAmount
:
maxLargeProjectAmount
+
1
,
LargeProjectAmount
:
maxLargeProjectAmount
*
types
.
DefaultCoinPrecision
+
1
,
PublicPeriod
:
maxPublicPeriod
+
1
,
PublicPeriod
:
maxPublicPeriod
+
1
,
},
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
...
@@ -83,8 +83,8 @@ func TestPropRule(t *testing.T) {
...
@@ -83,8 +83,8 @@ func TestPropRule(t *testing.T) {
RuleCfg
:
&
auty
.
RuleConfig
{
RuleCfg
:
&
auty
.
RuleConfig
{
BoardApproveRatio
:
1
,
BoardApproveRatio
:
1
,
PubOpposeRatio
:
minPubOpposeRatio
+
1
,
PubOpposeRatio
:
minPubOpposeRatio
+
1
,
ProposalAmount
:
minProposalAmount
+
1
,
ProposalAmount
:
minProposalAmount
*
types
.
DefaultCoinPrecision
+
1
,
LargeProjectAmount
:
minLargeProjectAmount
+
1
,
LargeProjectAmount
:
minLargeProjectAmount
*
types
.
DefaultCoinPrecision
+
1
,
PublicPeriod
:
minPublicPeriod
+
1
,
PublicPeriod
:
minPublicPeriod
+
1
,
},
},
StartBlockHeight
:
env
.
blockHeight
+
5
,
StartBlockHeight
:
env
.
blockHeight
+
5
,
...
...
plugin/dapp/blackwhite/commands/blackwhite.go
View file @
100bcc22
...
@@ -5,9 +5,14 @@
...
@@ -5,9 +5,14 @@
package
commands
package
commands
import
(
import
(
"fmt"
"os"
"strconv"
"strconv"
"strings"
"strings"
cmdtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
rpctypes
"github.com/33cn/chain33/rpc/types"
...
@@ -66,15 +71,20 @@ func blackwhiteCreate(cmd *cobra.Command, args []string) {
...
@@ -66,15 +71,20 @@ func blackwhiteCreate(cmd *cobra.Command, args []string) {
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
feeInt64
:=
int64
(
fee
*
1e4
)
feeInt64
:=
int64
(
fee
*
1e4
)
amountInt64
:=
int64
(
amount
)
if
timeout
==
0
{
if
timeout
==
0
{
timeout
=
10
timeout
=
10
}
}
timeout
=
60
*
timeout
timeout
=
60
*
timeout
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
params
:=
&
gt
.
BlackwhiteCreateTxReq
{
params
:=
&
gt
.
BlackwhiteCreateTxReq
{
PlayAmount
:
amountInt64
*
types
.
Coi
n
,
PlayAmount
:
int64
(
amount
)
*
cfg
.
CoinPrecisio
n
,
PlayerCount
:
int32
(
playerCount
),
PlayerCount
:
int32
(
playerCount
),
Timeout
:
timeout
,
Timeout
:
timeout
,
GameName
:
gameName
,
GameName
:
gameName
,
...
@@ -121,6 +131,11 @@ func blackwhitePlay(cmd *cobra.Command, args []string) {
...
@@ -121,6 +131,11 @@ func blackwhitePlay(cmd *cobra.Command, args []string) {
secret
,
_
:=
cmd
.
Flags
()
.
GetString
(
"secret"
)
secret
,
_
:=
cmd
.
Flags
()
.
GetString
(
"secret"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
blacks
:=
strings
.
Split
(
isBlackStr
,
"-"
)
blacks
:=
strings
.
Split
(
isBlackStr
,
"-"
)
var
hashValues
[][]
byte
var
hashValues
[][]
byte
...
@@ -134,10 +149,10 @@ func blackwhitePlay(cmd *cobra.Command, args []string) {
...
@@ -134,10 +149,10 @@ func blackwhitePlay(cmd *cobra.Command, args []string) {
}
}
feeInt64
:=
int64
(
fee
*
1e4
)
feeInt64
:=
int64
(
fee
*
1e4
)
amountInt64
:=
int64
(
amount
)
params
:=
&
gt
.
BlackwhitePlayTxReq
{
params
:=
&
gt
.
BlackwhitePlayTxReq
{
GameID
:
gameID
,
GameID
:
gameID
,
Amount
:
amountInt64
*
types
.
Coi
n
,
Amount
:
int64
(
amount
)
*
cfg
.
CoinPrecisio
n
,
HashValues
:
hashValues
,
HashValues
:
hashValues
,
Fee
:
feeInt64
,
Fee
:
feeInt64
,
}
}
...
...
plugin/dapp/blackwhite/executor/action.go
View file @
100bcc22
...
@@ -7,6 +7,8 @@ package executor
...
@@ -7,6 +7,8 @@ package executor
import
(
import
(
"math"
"math"
"github.com/pkg/errors"
"bytes"
"bytes"
"strconv"
"strconv"
...
@@ -20,14 +22,14 @@ import (
...
@@ -20,14 +22,14 @@ import (
)
)
const
(
const
(
maxAmount
int64
=
100
*
types
.
Coin
maxAmount
int64
=
100
minAmount
int64
=
1
*
types
.
Coin
minAmount
int64
=
1
minPlayerCount
int32
=
3
minPlayerCount
int32
=
3
maxPlayerCount
int32
=
100000
maxPlayerCount
int32
=
100000
lockAmount
int64
=
types
.
Coin
/
100
//创建者锁定金额
lockAmount
int64
=
100
//创建者锁定金额 types.coins/lockAmount
showTimeout
int64
=
60
*
5
// 公布密钥超时时间
showTimeout
int64
=
60
*
5
// 公布密钥超时时间
maxPlayTimeout
int64
=
60
*
60
*
24
// 创建交易之后最大超时时间
maxPlayTimeout
int64
=
60
*
60
*
24
// 创建交易之后最大超时时间
minPlayTimeout
int64
=
60
*
10
// 创建交易之后最小超时时间
minPlayTimeout
int64
=
60
*
10
// 创建交易之后最小超时时间
white
=
"0"
white
=
"0"
black
=
"1"
black
=
"1"
...
@@ -65,7 +67,8 @@ func newAction(t *Blackwhite, tx *types.Transaction, index int32) *action {
...
@@ -65,7 +67,8 @@ func newAction(t *Blackwhite, tx *types.Transaction, index int32) *action {
}
}
func
(
a
*
action
)
Create
(
create
*
gt
.
BlackwhiteCreate
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
Create
(
create
*
gt
.
BlackwhiteCreate
)
(
*
types
.
Receipt
,
error
)
{
if
create
.
PlayAmount
<
minAmount
||
create
.
PlayAmount
>
maxAmount
{
cfg
:=
a
.
api
.
GetConfig
()
if
create
.
PlayAmount
<
minAmount
*
cfg
.
GetCoinPrecision
()
||
create
.
PlayAmount
>
maxAmount
*
cfg
.
GetCoinPrecision
()
{
return
nil
,
types
.
ErrAmount
return
nil
,
types
.
ErrAmount
}
}
if
create
.
PlayerCount
<
minPlayerCount
||
create
.
PlayerCount
>
maxPlayerCount
{
if
create
.
PlayerCount
<
minPlayerCount
||
create
.
PlayerCount
>
maxPlayerCount
{
...
@@ -75,9 +78,13 @@ func (a *action) Create(create *gt.BlackwhiteCreate) (*types.Receipt, error) {
...
@@ -75,9 +78,13 @@ func (a *action) Create(create *gt.BlackwhiteCreate) (*types.Receipt, error) {
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
receipt
,
err
:=
a
.
coinsAccount
.
ExecFrozen
(
a
.
fromaddr
,
a
.
execaddr
,
lockAmount
)
if
cfg
.
GetCoinPrecision
()
<
lockAmount
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"coinPrecison=%d < lockAmount=100"
,
cfg
.
GetCoinPrecision
())
}
receipt
,
err
:=
a
.
coinsAccount
.
ExecFrozen
(
a
.
fromaddr
,
a
.
execaddr
,
cfg
.
GetCoinPrecision
()
/
lockAmount
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"blackwhite create "
,
"addr"
,
a
.
fromaddr
,
"execaddr"
,
a
.
execaddr
,
"ExecFrozen amount"
,
lockAmount
)
clog
.
Error
(
"blackwhite create "
,
"addr"
,
a
.
fromaddr
,
"execaddr"
,
a
.
execaddr
,
"ExecFrozen amount"
,
cfg
.
GetCoinPrecision
()
/
lockAmount
)
return
nil
,
err
return
nil
,
err
}
}
...
@@ -296,6 +303,7 @@ func (a *action) TimeoutDone(done *gt.BlackwhiteTimeoutDone) (*types.Receipt, er
...
@@ -296,6 +303,7 @@ func (a *action) TimeoutDone(done *gt.BlackwhiteTimeoutDone) (*types.Receipt, er
var
logs
[]
*
types
.
ReceiptLog
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
var
kv
[]
*
types
.
KeyValue
cfg
:=
a
.
api
.
GetConfig
()
// 检查当前状态
// 检查当前状态
if
gt
.
BlackwhiteStatusPlay
==
round
.
Status
{
if
gt
.
BlackwhiteStatusPlay
==
round
.
Status
{
if
a
.
blocktime
>=
round
.
Timeout
+
round
.
CreateTime
{
if
a
.
blocktime
>=
round
.
Timeout
+
round
.
CreateTime
{
...
@@ -317,13 +325,16 @@ func (a *action) TimeoutDone(done *gt.BlackwhiteTimeoutDone) (*types.Receipt, er
...
@@ -317,13 +325,16 @@ func (a *action) TimeoutDone(done *gt.BlackwhiteTimeoutDone) (*types.Receipt, er
logs
=
append
(
logs
,
receipt
.
Logs
...
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
}
}
if
cfg
.
GetCoinPrecision
()
<
lockAmount
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"coinPrecison=%d < lockAmount=100"
,
cfg
.
GetCoinPrecision
())
}
// 将创建游戏者解冻
// 将创建游戏者解冻
receipt
,
err
:=
a
.
coinsAccount
.
ExecActive
(
round
.
CreateAddr
,
a
.
execaddr
,
lockAmount
)
receipt
,
err
:=
a
.
coinsAccount
.
ExecActive
(
round
.
CreateAddr
,
a
.
execaddr
,
cfg
.
GetCoinPrecision
()
/
lockAmount
)
if
err
!=
nil
{
if
err
!=
nil
{
for
_
,
addrR
:=
range
round
.
AddrResult
{
for
_
,
addrR
:=
range
round
.
AddrResult
{
a
.
coinsAccount
.
ExecFrozen
(
addrR
.
Addr
,
a
.
execaddr
,
addrR
.
Amount
)
a
.
coinsAccount
.
ExecFrozen
(
addrR
.
Addr
,
a
.
execaddr
,
addrR
.
Amount
)
}
}
clog
.
Error
(
"blackwhite timeout done"
,
"addr"
,
round
.
CreateAddr
,
"execaddr"
,
a
.
execaddr
,
"execActive create lockAmount"
,
lockAmount
,
"err"
,
err
)
clog
.
Error
(
"blackwhite timeout done"
,
"addr"
,
round
.
CreateAddr
,
"execaddr"
,
a
.
execaddr
,
"execActive create lockAmount"
,
cfg
.
GetCoinPrecision
()
/
lockAmount
,
"err"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
...
@@ -364,7 +375,6 @@ func (a *action) TimeoutDone(done *gt.BlackwhiteTimeoutDone) (*types.Receipt, er
...
@@ -364,7 +375,6 @@ func (a *action) TimeoutDone(done *gt.BlackwhiteTimeoutDone) (*types.Receipt, er
key1
:=
calcMavlRoundKey
(
round
.
GameID
)
key1
:=
calcMavlRoundKey
(
round
.
GameID
)
value1
:=
types
.
Encode
(
&
round
)
value1
:=
types
.
Encode
(
&
round
)
cfg
:=
a
.
api
.
GetConfig
()
if
cfg
.
IsDappFork
(
a
.
height
,
gt
.
BlackwhiteX
,
"ForkBlackWhiteV2"
)
{
if
cfg
.
IsDappFork
(
a
.
height
,
gt
.
BlackwhiteX
,
"ForkBlackWhiteV2"
)
{
//将当前游戏状态保存,便于同一区块中游戏参数的累加
//将当前游戏状态保存,便于同一区块中游戏参数的累加
a
.
db
.
Set
(
key1
,
value1
)
a
.
db
.
Set
(
key1
,
value1
)
...
@@ -492,8 +502,12 @@ func (a *action) StatTransfer(round *gt.BlackwhiteRound) (*types.Receipt, error)
...
@@ -492,8 +502,12 @@ func (a *action) StatTransfer(round *gt.BlackwhiteRound) (*types.Receipt, error)
round
.
Winner
=
append
(
round
.
Winner
,
winer
.
addr
)
round
.
Winner
=
append
(
round
.
Winner
,
winer
.
addr
)
}
}
cfg
:=
a
.
api
.
GetConfig
()
if
cfg
.
GetCoinPrecision
()
<
lockAmount
{
return
nil
,
errors
.
Wrapf
(
types
.
ErrInvalidParam
,
"coinPrecison=%d < lockAmount=100"
,
cfg
.
GetCoinPrecision
())
}
// 将创建游戏者解冻
// 将创建游戏者解冻
receipt
,
err
:=
a
.
coinsAccount
.
ExecActive
(
round
.
CreateAddr
,
a
.
execaddr
,
lockAmount
)
receipt
,
err
:=
a
.
coinsAccount
.
ExecActive
(
round
.
CreateAddr
,
a
.
execaddr
,
cfg
.
GetCoinPrecision
()
/
lockAmount
)
if
err
!=
nil
{
if
err
!=
nil
{
// rollback
// rollback
if
len
(
winers
)
==
0
{
if
len
(
winers
)
==
0
{
...
@@ -512,7 +526,7 @@ func (a *action) StatTransfer(round *gt.BlackwhiteRound) (*types.Receipt, error)
...
@@ -512,7 +526,7 @@ func (a *action) StatTransfer(round *gt.BlackwhiteRound) (*types.Receipt, error)
a
.
coinsAccount
.
ExecFrozen
(
loser
.
addr
,
a
.
execaddr
,
loser
.
amount
)
a
.
coinsAccount
.
ExecFrozen
(
loser
.
addr
,
a
.
execaddr
,
loser
.
amount
)
}
}
}
}
clog
.
Error
(
"StatTransfer ExecActive create ExecFrozen "
,
"addr"
,
round
.
CreateAddr
,
"execaddr"
,
a
.
execaddr
,
"amount"
,
lockAmount
)
clog
.
Error
(
"StatTransfer ExecActive create ExecFrozen "
,
"addr"
,
round
.
CreateAddr
,
"execaddr"
,
a
.
execaddr
,
"amount"
,
cfg
.
GetCoinPrecision
()
/
lockAmount
)
return
nil
,
err
return
nil
,
err
}
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
...
...
plugin/dapp/collateralize/executor/collateralizedb.go
View file @
100bcc22
...
@@ -27,8 +27,7 @@ const (
...
@@ -27,8 +27,7 @@ const (
//setting
//setting
const
(
const
(
Coin
=
types
.
Coin
// 1e8
DefaultDebtCeiling
=
10000
// 默认借贷限额
DefaultDebtCeiling
=
10000
*
Coin
// 默认借贷限额
DefaultLiquidationRatio
=
0.4
*
1e4
// 默认质押比
DefaultLiquidationRatio
=
0.4
*
1e4
// 默认质押比
DefaultStabilityFeeRation
=
0.08
*
1e4
// 默认稳定费
DefaultStabilityFeeRation
=
0.08
*
1e4
// 默认稳定费
DefaultPeriod
=
3600
*
24
*
365
// 默认合约限期
DefaultPeriod
=
3600
*
24
*
365
// 默认合约限期
...
@@ -255,9 +254,10 @@ func (action *Action) CollateralizeManage(manage *pty.CollateralizeManage) (*typ
...
@@ -255,9 +254,10 @@ func (action *Action) CollateralizeManage(manage *pty.CollateralizeManage) (*typ
}
}
manConfig
,
_
:=
getCollateralizeConfig
(
action
.
db
)
manConfig
,
_
:=
getCollateralizeConfig
(
action
.
db
)
cfg
:=
action
.
Collateralize
.
GetAPI
()
.
GetConfig
()
if
manConfig
==
nil
{
if
manConfig
==
nil
{
manConfig
=
&
pty
.
CollateralizeManage
{
manConfig
=
&
pty
.
CollateralizeManage
{
DebtCeiling
:
DefaultDebtCeiling
,
DebtCeiling
:
DefaultDebtCeiling
*
cfg
.
GetCoinPrecision
()
,
LiquidationRatio
:
DefaultLiquidationRatio
,
LiquidationRatio
:
DefaultLiquidationRatio
,
StabilityFeeRatio
:
DefaultStabilityFeeRation
,
StabilityFeeRatio
:
DefaultStabilityFeeRation
,
Period
:
DefaultPeriod
,
Period
:
DefaultPeriod
,
...
...
plugin/dapp/evm/commands/evm.go
View file @
100bcc22
...
@@ -12,8 +12,10 @@ import (
...
@@ -12,8 +12,10 @@ import (
"os"
"os"
"time"
"time"
cmdtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
"encoding/json"
"encoding/json"
"strconv"
"strings"
"strings"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
...
@@ -154,6 +156,12 @@ func evmBalance(cmd *cobra.Command, args []string) {
...
@@ -154,6 +156,12 @@ func evmBalance(cmd *cobra.Command, args []string) {
return
return
}
}
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
var
addrs
[]
string
var
addrs
[]
string
addrs
=
append
(
addrs
,
addr
)
addrs
=
append
(
addrs
,
addr
)
params
:=
types
.
ReqBalance
{
params
:=
types
.
ReqBalance
{
...
@@ -163,8 +171,8 @@ func evmBalance(cmd *cobra.Command, args []string) {
...
@@ -163,8 +171,8 @@ func evmBalance(cmd *cobra.Command, args []string) {
}
}
var
res
[]
*
rpctypes
.
Account
var
res
[]
*
rpctypes
.
Account
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.GetBalance"
,
params
,
&
res
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.GetBalance"
,
params
,
&
res
)
ctx
.
SetResultCb
(
parseGetBalanceRes
)
ctx
.
SetResultCb
Ext
(
parseGetBalanceRes
)
ctx
.
Run
(
)
ctx
.
Run
Ext
(
cfg
)
}
}
// AccountResult 账户余额查询出来之后进行单位转换
// AccountResult 账户余额查询出来之后进行单位转换
...
@@ -179,10 +187,11 @@ type AccountResult struct {
...
@@ -179,10 +187,11 @@ type AccountResult struct {
Addr
string
`json:"addr,omitempty"`
Addr
string
`json:"addr,omitempty"`
}
}
func
parseGetBalanceRes
(
arg
interface
{})
(
interface
{},
error
)
{
func
parseGetBalanceRes
(
arg
...
interface
{})
(
interface
{},
error
)
{
res
:=
*
arg
.
(
*
[]
*
rpctypes
.
Account
)
res
:=
*
arg
[
0
]
.
(
*
[]
*
rpctypes
.
Account
)
balanceResult
:=
strconv
.
FormatFloat
(
float64
(
res
[
0
]
.
Balance
)
/
float64
(
types
.
Coin
),
'f'
,
4
,
64
)
cfg
:=
arg
[
1
]
.
(
*
rpctypes
.
ChainConfigInfo
)
frozenResult
:=
strconv
.
FormatFloat
(
float64
(
res
[
0
]
.
Frozen
)
/
float64
(
types
.
Coin
),
'f'
,
4
,
64
)
balanceResult
:=
types
.
FormatAmount2FloatDisplay
(
res
[
0
]
.
Balance
,
cfg
.
CoinPrecision
,
true
)
frozenResult
:=
types
.
FormatAmount2FloatDisplay
(
res
[
0
]
.
Frozen
,
cfg
.
CoinPrecision
,
true
)
result
:=
&
AccountResult
{
result
:=
&
AccountResult
{
Addr
:
res
[
0
]
.
Addr
,
Addr
:
res
[
0
]
.
Addr
,
Currency
:
res
[
0
]
.
Currency
,
Currency
:
res
[
0
]
.
Currency
,
...
...
plugin/dapp/exchange/executor/exchange.go
View file @
100bcc22
...
@@ -58,6 +58,7 @@ func (e *exchange) CheckTx(tx *types.Transaction, index int) error {
...
@@ -58,6 +58,7 @@ func (e *exchange) CheckTx(tx *types.Transaction, index int) error {
//发送交易的时候就检查payload,做严格的参数检查
//发送交易的时候就检查payload,做严格的参数检查
var
exchange
exchangetypes
.
ExchangeAction
var
exchange
exchangetypes
.
ExchangeAction
types
.
Decode
(
tx
.
GetPayload
(),
&
exchange
)
types
.
Decode
(
tx
.
GetPayload
(),
&
exchange
)
cfg
:=
e
.
GetAPI
()
.
GetConfig
()
if
exchange
.
Ty
==
exchangetypes
.
TyLimitOrderAction
{
if
exchange
.
Ty
==
exchangetypes
.
TyLimitOrderAction
{
limitOrder
:=
exchange
.
GetLimitOrder
()
limitOrder
:=
exchange
.
GetLimitOrder
()
left
:=
limitOrder
.
GetLeftAsset
()
left
:=
limitOrder
.
GetLeftAsset
()
...
@@ -65,13 +66,13 @@ func (e *exchange) CheckTx(tx *types.Transaction, index int) error {
...
@@ -65,13 +66,13 @@ func (e *exchange) CheckTx(tx *types.Transaction, index int) error {
price
:=
limitOrder
.
GetPrice
()
price
:=
limitOrder
.
GetPrice
()
amount
:=
limitOrder
.
GetAmount
()
amount
:=
limitOrder
.
GetAmount
()
op
:=
limitOrder
.
GetOp
()
op
:=
limitOrder
.
GetOp
()
if
!
CheckExchangeAsset
(
e
.
GetAPI
()
.
GetConfig
()
.
GetCoinExec
(),
left
,
right
)
{
if
!
CheckExchangeAsset
(
cfg
.
GetCoinExec
(),
left
,
right
)
{
return
exchangetypes
.
ErrAsset
return
exchangetypes
.
ErrAsset
}
}
if
!
CheckPrice
(
price
)
{
if
!
CheckPrice
(
price
)
{
return
exchangetypes
.
ErrAssetPrice
return
exchangetypes
.
ErrAssetPrice
}
}
if
!
CheckAmount
(
amount
)
{
if
!
CheckAmount
(
amount
,
cfg
.
GetCoinPrecision
()
)
{
return
exchangetypes
.
ErrAssetAmount
return
exchangetypes
.
ErrAssetAmount
}
}
if
!
CheckOp
(
op
)
{
if
!
CheckOp
(
op
)
{
...
...
plugin/dapp/exchange/executor/exchange_test.go
View file @
100bcc22
...
@@ -895,7 +895,7 @@ func TestKV(t *testing.T) {
...
@@ -895,7 +895,7 @@ func TestKV(t *testing.T) {
}
}
func
TestSafeMul
(
t
*
testing
.
T
)
{
func
TestSafeMul
(
t
*
testing
.
T
)
{
t
.
Log
(
SafeMul
(
1e8
,
1e7
))
t
.
Log
(
SafeMul
(
1e8
,
1e7
,
types
.
DefaultCoinPrecision
))
t
.
Log
(
SafeMul
(
1e10
,
1e16
))
t
.
Log
(
SafeMul
(
1e10
,
1e16
,
types
.
DefaultCoinPrecision
))
t
.
Log
(
SafeMul
(
1e7
,
1e6
))
t
.
Log
(
SafeMul
(
1e7
,
1e6
,
types
.
DefaultCoinPrecision
))
}
}
plugin/dapp/exchange/executor/exchangedb.go
View file @
100bcc22
...
@@ -55,9 +55,9 @@ func (a *Action) OpSwap(op int32) int32 {
...
@@ -55,9 +55,9 @@ func (a *Action) OpSwap(op int32) int32 {
}
}
//CalcActualCost 计算实际花费
//CalcActualCost 计算实际花费
func
CalcActualCost
(
op
int32
,
amount
int64
,
price
int64
)
int64
{
func
CalcActualCost
(
op
int32
,
amount
int64
,
price
,
coinPrecision
int64
)
int64
{
if
op
==
et
.
OpBuy
{
if
op
==
et
.
OpBuy
{
return
SafeMul
(
amount
,
price
)
return
SafeMul
(
amount
,
price
,
coinPrecision
)
}
}
return
amount
return
amount
}
}
...
@@ -83,9 +83,9 @@ func CheckCount(count int32) bool {
...
@@ -83,9 +83,9 @@ func CheckCount(count int32) bool {
return
count
<=
20
&&
count
>=
0
return
count
<=
20
&&
count
>=
0
}
}
//CheckAmount 最小交易
1e8
//CheckAmount 最小交易
1coin
func
CheckAmount
(
amount
int64
)
bool
{
func
CheckAmount
(
amount
,
coinPrecision
int64
)
bool
{
if
amount
<
types
.
Coi
n
||
amount
>=
types
.
MaxCoin
{
if
amount
<
coinPrecisio
n
||
amount
>=
types
.
MaxCoin
{
return
false
return
false
}
}
return
true
return
true
...
@@ -124,10 +124,11 @@ func (a *Action) LimitOrder(payload *et.LimitOrder) (*types.Receipt, error) {
...
@@ -124,10 +124,11 @@ func (a *Action) LimitOrder(payload *et.LimitOrder) (*types.Receipt, error) {
rightAsset
:=
payload
.
GetRightAsset
()
rightAsset
:=
payload
.
GetRightAsset
()
//TODO 参数要合法,必须有严格的校验,后面统一加入到checkTx里面
//TODO 参数要合法,必须有严格的校验,后面统一加入到checkTx里面
//coins执行器下面只有bty
//coins执行器下面只有bty
if
!
CheckExchangeAsset
(
a
.
api
.
GetConfig
()
.
GetCoinExec
(),
leftAsset
,
rightAsset
)
{
cfg
:=
a
.
api
.
GetConfig
()
if
!
CheckExchangeAsset
(
cfg
.
GetCoinExec
(),
leftAsset
,
rightAsset
)
{
return
nil
,
et
.
ErrAsset
return
nil
,
et
.
ErrAsset
}
}
if
!
CheckAmount
(
payload
.
GetAmount
())
{
if
!
CheckAmount
(
payload
.
GetAmount
()
,
cfg
.
GetCoinPrecision
()
)
{
return
nil
,
et
.
ErrAssetAmount
return
nil
,
et
.
ErrAssetAmount
}
}
if
!
CheckPrice
(
payload
.
GetPrice
())
{
if
!
CheckPrice
(
payload
.
GetPrice
())
{
...
@@ -137,7 +138,6 @@ func (a *Action) LimitOrder(payload *et.LimitOrder) (*types.Receipt, error) {
...
@@ -137,7 +138,6 @@ func (a *Action) LimitOrder(payload *et.LimitOrder) (*types.Receipt, error) {
return
nil
,
et
.
ErrAssetOp
return
nil
,
et
.
ErrAssetOp
}
}
//TODO 这里symbol
//TODO 这里symbol
cfg
:=
a
.
api
.
GetConfig
()
leftAssetDB
,
err
:=
account
.
NewAccountDB
(
cfg
,
leftAsset
.
GetExecer
(),
leftAsset
.
GetSymbol
(),
a
.
statedb
)
leftAssetDB
,
err
:=
account
.
NewAccountDB
(
cfg
,
leftAsset
.
GetExecer
(),
leftAsset
.
GetSymbol
(),
a
.
statedb
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -148,7 +148,7 @@ func (a *Action) LimitOrder(payload *et.LimitOrder) (*types.Receipt, error) {
...
@@ -148,7 +148,7 @@ func (a *Action) LimitOrder(payload *et.LimitOrder) (*types.Receipt, error) {
}
}
//先检查账户余额
//先检查账户余额
if
payload
.
GetOp
()
==
et
.
OpBuy
{
if
payload
.
GetOp
()
==
et
.
OpBuy
{
amount
:=
SafeMul
(
payload
.
GetAmount
(),
payload
.
GetPrice
())
amount
:=
SafeMul
(
payload
.
GetAmount
(),
payload
.
GetPrice
()
,
cfg
.
GetCoinPrecision
()
)
rightAccount
:=
rightAssetDB
.
LoadExecAccount
(
a
.
fromaddr
,
a
.
execaddr
)
rightAccount
:=
rightAssetDB
.
LoadExecAccount
(
a
.
fromaddr
,
a
.
execaddr
)
if
rightAccount
.
Balance
<
amount
{
if
rightAccount
.
Balance
<
amount
{
elog
.
Error
(
"limit check right balance"
,
"addr"
,
a
.
fromaddr
,
"avail"
,
rightAccount
.
Balance
,
"need"
,
amount
)
elog
.
Error
(
"limit check right balance"
,
"addr"
,
a
.
fromaddr
,
"avail"
,
rightAccount
.
Balance
,
"need"
,
amount
)
...
@@ -197,7 +197,7 @@ func (a *Action) RevokeOrder(payload *et.RevokeOrder) (*types.Receipt, error) {
...
@@ -197,7 +197,7 @@ func (a *Action) RevokeOrder(payload *et.RevokeOrder) (*types.Receipt, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
amount
:=
CalcActualCost
(
et
.
OpBuy
,
balance
,
price
)
amount
:=
CalcActualCost
(
et
.
OpBuy
,
balance
,
price
,
cfg
.
GetCoinPrecision
()
)
rightAccount
:=
rightAssetDB
.
LoadExecAccount
(
a
.
fromaddr
,
a
.
execaddr
)
rightAccount
:=
rightAssetDB
.
LoadExecAccount
(
a
.
fromaddr
,
a
.
execaddr
)
if
rightAccount
.
Frozen
<
amount
{
if
rightAccount
.
Frozen
<
amount
{
elog
.
Error
(
"revoke check right frozen"
,
"addr"
,
a
.
fromaddr
,
"avail"
,
rightAccount
.
Frozen
,
"amount"
,
amount
)
elog
.
Error
(
"revoke check right frozen"
,
"addr"
,
a
.
fromaddr
,
"avail"
,
rightAccount
.
Frozen
,
"amount"
,
amount
)
...
@@ -216,7 +216,7 @@ func (a *Action) RevokeOrder(payload *et.RevokeOrder) (*types.Receipt, error) {
...
@@ -216,7 +216,7 @@ func (a *Action) RevokeOrder(payload *et.RevokeOrder) (*types.Receipt, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
amount
:=
CalcActualCost
(
et
.
OpSell
,
balance
,
price
)
amount
:=
CalcActualCost
(
et
.
OpSell
,
balance
,
price
,
cfg
.
GetCoinPrecision
()
)
leftAccount
:=
leftAssetDB
.
LoadExecAccount
(
a
.
fromaddr
,
a
.
execaddr
)
leftAccount
:=
leftAssetDB
.
LoadExecAccount
(
a
.
fromaddr
,
a
.
execaddr
)
if
leftAccount
.
Frozen
<
amount
{
if
leftAccount
.
Frozen
<
amount
{
elog
.
Error
(
"revoke check left frozen"
,
"addr"
,
a
.
fromaddr
,
"avail"
,
leftAccount
.
Frozen
,
"amount"
,
amount
)
elog
.
Error
(
"revoke check left frozen"
,
"addr"
,
a
.
fromaddr
,
"avail"
,
leftAccount
.
Frozen
,
"amount"
,
amount
)
...
@@ -259,6 +259,7 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
...
@@ -259,6 +259,7 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
var
priceKey
string
var
priceKey
string
var
count
int
var
count
int
cfg
:=
a
.
api
.
GetConfig
()
or
:=
&
et
.
Order
{
or
:=
&
et
.
Order
{
OrderID
:
a
.
GetIndex
(),
OrderID
:
a
.
GetIndex
(),
Value
:
&
et
.
Order_LimitOrder
{
LimitOrder
:
payload
},
Value
:
&
et
.
Order_LimitOrder
{
LimitOrder
:
payload
},
...
@@ -355,7 +356,7 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
...
@@ -355,7 +356,7 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
//未完成的订单需要冻结剩余未成交的资金
//未完成的订单需要冻结剩余未成交的资金
if
payload
.
Op
==
et
.
OpBuy
{
if
payload
.
Op
==
et
.
OpBuy
{
amount
:=
CalcActualCost
(
et
.
OpBuy
,
or
.
Balance
,
payload
.
Price
)
amount
:=
CalcActualCost
(
et
.
OpBuy
,
or
.
Balance
,
payload
.
Price
,
cfg
.
GetCoinPrecision
()
)
receipt
,
err
:=
rightAccountDB
.
ExecFrozen
(
a
.
fromaddr
,
a
.
execaddr
,
amount
)
receipt
,
err
:=
rightAccountDB
.
ExecFrozen
(
a
.
fromaddr
,
a
.
execaddr
,
amount
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"LimitOrder.ExecFrozen"
,
"addr"
,
a
.
fromaddr
,
"amount"
,
amount
,
"err"
,
err
.
Error
())
elog
.
Error
(
"LimitOrder.ExecFrozen"
,
"addr"
,
a
.
fromaddr
,
"amount"
,
amount
,
"err"
,
err
.
Error
())
...
@@ -365,7 +366,7 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
...
@@ -365,7 +366,7 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
}
}
if
payload
.
Op
==
et
.
OpSell
{
if
payload
.
Op
==
et
.
OpSell
{
amount
:=
CalcActualCost
(
et
.
OpSell
,
or
.
Balance
,
payload
.
Price
)
amount
:=
CalcActualCost
(
et
.
OpSell
,
or
.
Balance
,
payload
.
Price
,
cfg
.
GetCoinPrecision
()
)
receipt
,
err
:=
leftAccountDB
.
ExecFrozen
(
a
.
fromaddr
,
a
.
execaddr
,
amount
)
receipt
,
err
:=
leftAccountDB
.
ExecFrozen
(
a
.
fromaddr
,
a
.
execaddr
,
amount
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"LimitOrder.ExecFrozen"
,
"addr"
,
a
.
fromaddr
,
"amount"
,
amount
,
"err"
,
err
.
Error
())
elog
.
Error
(
"LimitOrder.ExecFrozen"
,
"addr"
,
a
.
fromaddr
,
"amount"
,
amount
,
"err"
,
err
.
Error
())
...
@@ -398,9 +399,10 @@ func (a *Action) matchModel(leftAccountDB, rightAccountDB *account.DB, payload *
...
@@ -398,9 +399,10 @@ func (a *Action) matchModel(leftAccountDB, rightAccountDB *account.DB, payload *
elog
.
Info
(
"try match"
,
"activeId"
,
or
.
OrderID
,
"passiveId"
,
matchorder
.
OrderID
,
"activeAddr"
,
or
.
Addr
,
"passiveAddr"
,
elog
.
Info
(
"try match"
,
"activeId"
,
or
.
OrderID
,
"passiveId"
,
matchorder
.
OrderID
,
"activeAddr"
,
or
.
Addr
,
"passiveAddr"
,
matchorder
.
Addr
,
"amount"
,
matched
,
"price"
,
payload
.
Price
)
matchorder
.
Addr
,
"amount"
,
matched
,
"price"
,
payload
.
Price
)
cfg
:=
a
.
api
.
GetConfig
()
if
payload
.
Op
==
et
.
OpSell
{
if
payload
.
Op
==
et
.
OpSell
{
//转移冻结资产
//转移冻结资产
amount
:=
CalcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matched
,
payload
.
Price
)
amount
:=
CalcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matched
,
payload
.
Price
,
cfg
.
GetCoinPrecision
()
)
receipt
,
err
:=
rightAccountDB
.
ExecTransferFrozen
(
matchorder
.
Addr
,
a
.
fromaddr
,
a
.
execaddr
,
amount
)
receipt
,
err
:=
rightAccountDB
.
ExecTransferFrozen
(
matchorder
.
Addr
,
a
.
fromaddr
,
a
.
execaddr
,
amount
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"matchModel.ExecTransferFrozen"
,
"from"
,
matchorder
.
Addr
,
"to"
,
a
.
fromaddr
,
"amount"
,
amount
,
"err"
,
err
)
elog
.
Error
(
"matchModel.ExecTransferFrozen"
,
"from"
,
matchorder
.
Addr
,
"to"
,
a
.
fromaddr
,
"amount"
,
amount
,
"err"
,
err
)
...
@@ -410,7 +412,7 @@ func (a *Action) matchModel(leftAccountDB, rightAccountDB *account.DB, payload *
...
@@ -410,7 +412,7 @@ func (a *Action) matchModel(leftAccountDB, rightAccountDB *account.DB, payload *
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
//解冻多余资金
//解冻多余资金
if
payload
.
Price
<
matchorder
.
GetLimitOrder
()
.
Price
{
if
payload
.
Price
<
matchorder
.
GetLimitOrder
()
.
Price
{
amount
:=
CalcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matched
,
matchorder
.
GetLimitOrder
()
.
Price
-
payload
.
Price
)
amount
:=
CalcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matched
,
matchorder
.
GetLimitOrder
()
.
Price
-
payload
.
Price
,
cfg
.
GetCoinPrecision
()
)
receipt
,
err
:=
rightAccountDB
.
ExecActive
(
matchorder
.
Addr
,
a
.
execaddr
,
amount
)
receipt
,
err
:=
rightAccountDB
.
ExecActive
(
matchorder
.
Addr
,
a
.
execaddr
,
amount
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"matchModel.ExecActive"
,
"addr"
,
matchorder
.
Addr
,
"amount"
,
amount
,
"err"
,
err
.
Error
())
elog
.
Error
(
"matchModel.ExecActive"
,
"addr"
,
matchorder
.
Addr
,
"amount"
,
amount
,
"err"
,
err
.
Error
())
...
@@ -420,7 +422,7 @@ func (a *Action) matchModel(leftAccountDB, rightAccountDB *account.DB, payload *
...
@@ -420,7 +422,7 @@ func (a *Action) matchModel(leftAccountDB, rightAccountDB *account.DB, payload *
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
}
}
//将达成交易的相应资产结算
//将达成交易的相应资产结算
amount
=
CalcActualCost
(
payload
.
Op
,
matched
,
payload
.
Price
)
amount
=
CalcActualCost
(
payload
.
Op
,
matched
,
payload
.
Price
,
cfg
.
GetCoinPrecision
()
)
receipt
,
err
=
leftAccountDB
.
ExecTransfer
(
a
.
fromaddr
,
matchorder
.
Addr
,
a
.
execaddr
,
amount
)
receipt
,
err
=
leftAccountDB
.
ExecTransfer
(
a
.
fromaddr
,
matchorder
.
Addr
,
a
.
execaddr
,
amount
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"matchModel.ExecTransfer"
,
"from"
,
a
.
fromaddr
,
"to"
,
matchorder
.
Addr
,
"amount"
,
amount
,
"err"
,
err
.
Error
())
elog
.
Error
(
"matchModel.ExecTransfer"
,
"from"
,
a
.
fromaddr
,
"to"
,
matchorder
.
Addr
,
"amount"
,
amount
,
"err"
,
err
.
Error
())
...
@@ -436,7 +438,7 @@ func (a *Action) matchModel(leftAccountDB, rightAccountDB *account.DB, payload *
...
@@ -436,7 +438,7 @@ func (a *Action) matchModel(leftAccountDB, rightAccountDB *account.DB, payload *
}
}
if
payload
.
Op
==
et
.
OpBuy
{
if
payload
.
Op
==
et
.
OpBuy
{
//转移冻结资产
//转移冻结资产
amount
:=
CalcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matched
,
matchorder
.
GetLimitOrder
()
.
Price
)
amount
:=
CalcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matched
,
matchorder
.
GetLimitOrder
()
.
Price
,
cfg
.
GetCoinPrecision
()
)
receipt
,
err
:=
leftAccountDB
.
ExecTransferFrozen
(
matchorder
.
Addr
,
a
.
fromaddr
,
a
.
execaddr
,
amount
)
receipt
,
err
:=
leftAccountDB
.
ExecTransferFrozen
(
matchorder
.
Addr
,
a
.
fromaddr
,
a
.
execaddr
,
amount
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"matchModel.ExecTransferFrozen2"
,
"from"
,
matchorder
.
Addr
,
"to"
,
a
.
fromaddr
,
"amount"
,
amount
,
"err"
,
err
.
Error
())
elog
.
Error
(
"matchModel.ExecTransferFrozen2"
,
"from"
,
matchorder
.
Addr
,
"to"
,
a
.
fromaddr
,
"amount"
,
amount
,
"err"
,
err
.
Error
())
...
@@ -445,7 +447,7 @@ func (a *Action) matchModel(leftAccountDB, rightAccountDB *account.DB, payload *
...
@@ -445,7 +447,7 @@ func (a *Action) matchModel(leftAccountDB, rightAccountDB *account.DB, payload *
logs
=
append
(
logs
,
receipt
.
Logs
...
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
//将达成交易的相应资产结算
//将达成交易的相应资产结算
amount
=
CalcActualCost
(
payload
.
Op
,
matched
,
matchorder
.
GetLimitOrder
()
.
Price
)
amount
=
CalcActualCost
(
payload
.
Op
,
matched
,
matchorder
.
GetLimitOrder
()
.
Price
,
cfg
.
GetCoinPrecision
()
)
receipt
,
err
=
rightAccountDB
.
ExecTransfer
(
a
.
fromaddr
,
matchorder
.
Addr
,
a
.
execaddr
,
amount
)
receipt
,
err
=
rightAccountDB
.
ExecTransfer
(
a
.
fromaddr
,
matchorder
.
Addr
,
a
.
execaddr
,
amount
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"matchModel.ExecTransfer2"
,
"from"
,
a
.
fromaddr
,
"to"
,
matchorder
.
Addr
,
"amount"
,
amount
,
"err"
,
err
.
Error
())
elog
.
Error
(
"matchModel.ExecTransfer2"
,
"from"
,
a
.
fromaddr
,
"to"
,
matchorder
.
Addr
,
"amount"
,
amount
,
"err"
,
err
.
Error
())
...
@@ -681,9 +683,9 @@ func queryMarketDepth(localdb dbm.KV, left, right *et.Asset, op int32, price int
...
@@ -681,9 +683,9 @@ func queryMarketDepth(localdb dbm.KV, left, right *et.Asset, op int32, price int
}
}
//SafeMul math库中的安全大数乘法,防溢出
//SafeMul math库中的安全大数乘法,防溢出
func
SafeMul
(
x
,
y
int64
)
int64
{
func
SafeMul
(
x
,
y
,
coinPrecision
int64
)
int64
{
res
:=
big
.
NewInt
(
0
)
.
Mul
(
big
.
NewInt
(
x
),
big
.
NewInt
(
y
))
res
:=
big
.
NewInt
(
0
)
.
Mul
(
big
.
NewInt
(
x
),
big
.
NewInt
(
y
))
res
=
big
.
NewInt
(
0
)
.
Div
(
res
,
big
.
NewInt
(
types
.
Coi
n
))
res
=
big
.
NewInt
(
0
)
.
Div
(
res
,
big
.
NewInt
(
coinPrecisio
n
))
return
res
.
Int64
()
return
res
.
Int64
()
}
}
...
...
plugin/dapp/exchange/test/exchange_test.go
View file @
100bcc22
...
@@ -269,7 +269,7 @@ func testPlaceLimitOrder(t *testing.T, req *et.LimitOrder, addr string, privkey
...
@@ -269,7 +269,7 @@ func testPlaceLimitOrder(t *testing.T, req *et.LimitOrder, addr string, privkey
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
t
.
Log
(
tokenAfter
)
t
.
Log
(
tokenAfter
)
cost
:=
executor
.
CalcActualCost
(
req
.
Op
,
req
.
Amount
,
req
.
Price
)
cost
:=
executor
.
CalcActualCost
(
req
.
Op
,
req
.
Amount
,
req
.
Price
,
types
.
DefaultCoinPrecision
)
t
.
Log
(
req
.
Amount
,
req
.
Price
,
cost
)
t
.
Log
(
req
.
Amount
,
req
.
Price
,
cost
)
// bty/ccny
// bty/ccny
if
req
.
Op
==
et
.
OpBuy
{
if
req
.
Op
==
et
.
OpBuy
{
...
@@ -315,7 +315,7 @@ func testRevokeLimitOrder(t *testing.T, orderID int64, addr string, privkey stri
...
@@ -315,7 +315,7 @@ func testRevokeLimitOrder(t *testing.T, orderID int64, addr string, privkey stri
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
t
.
Log
(
tokenAfter
)
t
.
Log
(
tokenAfter
)
cost
:=
executor
.
CalcActualCost
(
lo
.
Op
,
order
.
Balance
,
lo
.
Price
)
cost
:=
executor
.
CalcActualCost
(
lo
.
Op
,
order
.
Balance
,
lo
.
Price
,
types
.
DefaultCoinPrecision
)
// bty/ccny
// bty/ccny
if
lo
.
Op
==
et
.
OpBuy
{
if
lo
.
Op
==
et
.
OpBuy
{
// bty
// bty
...
...
plugin/dapp/hashlock/commands/hashlock.go
View file @
100bcc22
...
@@ -7,6 +7,10 @@ package commands
...
@@ -7,6 +7,10 @@ package commands
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"os"
cmdtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
"github.com/33cn/chain33/rpc/jsonclient"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
rpctypes
"github.com/33cn/chain33/rpc/types"
...
@@ -59,9 +63,6 @@ func addHashlockLockCmdFlags(cmd *cobra.Command) {
...
@@ -59,9 +63,6 @@ func addHashlockLockCmdFlags(cmd *cobra.Command) {
}
}
func
hashlockLockCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
hashlockLockCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
secret
,
_
:=
cmd
.
Flags
()
.
GetString
(
"secret"
)
secret
,
_
:=
cmd
.
Flags
()
.
GetString
(
"secret"
)
toAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"to"
)
toAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"to"
)
...
@@ -69,18 +70,31 @@ func hashlockLockCmd(cmd *cobra.Command, args []string) {
...
@@ -69,18 +70,31 @@ func hashlockLockCmd(cmd *cobra.Command, args []string) {
delay
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"delay"
)
delay
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"delay"
)
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
defaultFee
:=
float64
(
cfg
.
GetMinTxFeeRate
())
/
float64
(
types
.
Coin
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
if
err
!=
nil
{
if
fee
<
defaultFee
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
fee
=
defaultFee
return
}
}
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
if
delay
<
60
{
if
delay
<
60
{
fmt
.
Println
(
"delay period changed to 60"
)
fmt
.
Println
(
"delay period changed to 60"
)
delay
=
60
delay
=
60
}
}
amountInt64
:=
int64
(
amount
*
types
.
InputPrecision
)
*
types
.
Multiple1E4
amountInt64
,
err
:=
types
.
FormatFloatDisplay2Value
(
amount
,
cfg
.
CoinPrecision
)
feeInt64
:=
int64
(
fee
*
types
.
InputPrecision
)
*
types
.
Multiple1E4
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"FormatFloatDisplay2Value.amount"
))
return
}
feeInt64
,
err
:=
types
.
FormatFloatDisplay2Value
(
fee
,
cfg
.
CoinPrecision
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"FormatFloatDisplay2Value.fee"
))
return
}
if
feeInt64
<
cfg
.
MinTxFeeRate
{
feeInt64
=
cfg
.
MinTxFeeRate
}
params
:=
pty
.
HashlockLockTx
{
params
:=
pty
.
HashlockLockTx
{
Secret
:
secret
,
Secret
:
secret
,
Amount
:
amountInt64
,
Amount
:
amountInt64
,
...
@@ -123,19 +137,25 @@ func addHashlockCmdFlags(cmd *cobra.Command) {
...
@@ -123,19 +137,25 @@ func addHashlockCmdFlags(cmd *cobra.Command) {
}
}
func
hashlockUnlockCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
hashlockUnlockCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
secret
,
_
:=
cmd
.
Flags
()
.
GetString
(
"secret"
)
secret
,
_
:=
cmd
.
Flags
()
.
GetString
(
"secret"
)
defaultFee
:=
float64
(
cfg
.
GetMinTxFeeRate
())
/
float64
(
types
.
Coin
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
if
fee
<
defaultFee
{
feeInt64
,
err
:=
types
.
FormatFloatDisplay2Value
(
fee
,
cfg
.
CoinPrecision
)
fee
=
defaultFee
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"FormatFloatDisplay2Value.fee"
))
return
}
if
feeInt64
<
cfg
.
MinTxFeeRate
{
feeInt64
=
cfg
.
MinTxFeeRate
}
}
feeInt64
:=
int64
(
fee
*
types
.
InputPrecision
)
*
types
.
Multiple1E4
params
:=
pty
.
HashlockUnlockTx
{
params
:=
pty
.
HashlockUnlockTx
{
Secret
:
secret
,
Secret
:
secret
,
Fee
:
feeInt64
,
Fee
:
feeInt64
,
...
@@ -166,19 +186,24 @@ func HashlockSendCmd() *cobra.Command {
...
@@ -166,19 +186,24 @@ func HashlockSendCmd() *cobra.Command {
}
}
func
hashlockSendCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
hashlockSendCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
secret
,
_
:=
cmd
.
Flags
()
.
GetString
(
"secret"
)
secret
,
_
:=
cmd
.
Flags
()
.
GetString
(
"secret"
)
defaultFee
:=
float64
(
cfg
.
GetMinTxFeeRate
())
/
float64
(
types
.
Coin
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
if
err
!=
nil
{
if
fee
<
defaultFee
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
fee
=
defaultFee
return
}
}
feeInt64
:=
int64
(
fee
*
types
.
InputPrecision
)
*
types
.
Multiple1E4
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
feeInt64
,
err
:=
types
.
FormatFloatDisplay2Value
(
fee
,
cfg
.
CoinPrecision
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"FormatFloatDisplay2Value.fee"
))
return
}
if
feeInt64
<
cfg
.
MinTxFeeRate
{
feeInt64
=
cfg
.
MinTxFeeRate
}
params
:=
pty
.
HashlockSendTx
{
params
:=
pty
.
HashlockSendTx
{
Secret
:
secret
,
Secret
:
secret
,
Fee
:
feeInt64
,
Fee
:
feeInt64
,
...
...
plugin/dapp/issuance/executor/issuancedb.go
View file @
100bcc22
...
@@ -25,8 +25,7 @@ const (
...
@@ -25,8 +25,7 @@ const (
//setting
//setting
const
(
const
(
Coin
=
types
.
Coin
// 1e8
DefaultDebtCeiling
=
100000
// 默认借贷限额
DefaultDebtCeiling
=
100000
*
Coin
// 默认借贷限额
DefaultLiquidationRatio
=
0.25
*
1e4
// 默认质押比
DefaultLiquidationRatio
=
0.25
*
1e4
// 默认质押比
DefaultPeriod
=
3600
*
24
*
365
// 默认合约限期
DefaultPeriod
=
3600
*
24
*
365
// 默认合约限期
PriceWarningRate
=
1.3
*
1e4
// 价格提前预警率
PriceWarningRate
=
1.3
*
1e4
// 价格提前预警率
...
@@ -355,6 +354,7 @@ func (action *Action) IssuanceCreate(create *pty.IssuanceCreate) (*types.Receipt
...
@@ -355,6 +354,7 @@ func (action *Action) IssuanceCreate(create *pty.IssuanceCreate) (*types.Receipt
var
kv
[]
*
types
.
KeyValue
var
kv
[]
*
types
.
KeyValue
var
receipt
*
types
.
Receipt
var
receipt
*
types
.
Receipt
cfg
:=
action
.
Issuance
.
GetAPI
()
.
GetConfig
()
// 是否配置管理用户
// 是否配置管理用户
if
!
isRightAddr
(
pty
.
FundKey
,
action
.
fromaddr
,
action
.
db
)
{
if
!
isRightAddr
(
pty
.
FundKey
,
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"IssuanceCreate"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to create"
)
clog
.
Error
(
"IssuanceCreate"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to create"
)
...
@@ -405,7 +405,7 @@ func (action *Action) IssuanceCreate(create *pty.IssuanceCreate) (*types.Receipt
...
@@ -405,7 +405,7 @@ func (action *Action) IssuanceCreate(create *pty.IssuanceCreate) (*types.Receipt
if
create
.
DebtCeiling
!=
0
{
if
create
.
DebtCeiling
!=
0
{
issu
.
DebtCeiling
=
create
.
DebtCeiling
issu
.
DebtCeiling
=
create
.
DebtCeiling
}
else
{
}
else
{
issu
.
DebtCeiling
=
DefaultDebtCeiling
issu
.
DebtCeiling
=
DefaultDebtCeiling
*
cfg
.
GetCoinPrecision
()
}
}
if
create
.
Period
!=
0
{
if
create
.
Period
!=
0
{
issu
.
Period
=
create
.
Period
issu
.
Period
=
create
.
Period
...
...
plugin/dapp/lottery/executor/lotterydb.go
View file @
100bcc22
...
@@ -50,7 +50,6 @@ const (
...
@@ -50,7 +50,6 @@ const (
const
(
const
(
luckyNumMol
=
100000
luckyNumMol
=
100000
decimal
=
types
.
Coin
//1e8
blockNum
=
5
blockNum
=
5
)
)
...
@@ -358,7 +357,7 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
...
@@ -358,7 +357,7 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
Once ExecTransfer succeed, ExecFrozen succeed, no roolback needed
Once ExecTransfer succeed, ExecFrozen succeed, no roolback needed
**********/
**********/
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransfer
(
action
.
fromaddr
,
lott
.
CreateAddr
,
action
.
execaddr
,
buy
.
GetAmount
()
*
decimal
)
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransfer
(
action
.
fromaddr
,
lott
.
CreateAddr
,
action
.
execaddr
,
buy
.
GetAmount
()
*
cfg
.
GetCoinPrecision
()
)
if
err
!=
nil
{
if
err
!=
nil
{
llog
.
Error
(
"LotteryBuy.ExecTransfer"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
buy
.
GetAmount
())
llog
.
Error
(
"LotteryBuy.ExecTransfer"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
buy
.
GetAmount
())
return
nil
,
err
return
nil
,
err
...
@@ -366,7 +365,7 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
...
@@ -366,7 +365,7 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
logs
=
append
(
logs
,
receipt
.
Logs
...
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
receipt
,
err
=
action
.
coinsAccount
.
ExecFrozen
(
lott
.
CreateAddr
,
action
.
execaddr
,
buy
.
GetAmount
()
*
decimal
)
receipt
,
err
=
action
.
coinsAccount
.
ExecFrozen
(
lott
.
CreateAddr
,
action
.
execaddr
,
buy
.
GetAmount
()
*
cfg
.
GetCoinPrecision
()
)
if
err
!=
nil
{
if
err
!=
nil
{
llog
.
Error
(
"LotteryBuy.Frozen"
,
"addr"
,
lott
.
CreateAddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
buy
.
GetAmount
())
llog
.
Error
(
"LotteryBuy.Frozen"
,
"addr"
,
lott
.
CreateAddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
buy
.
GetAmount
())
...
@@ -503,16 +502,17 @@ func (action *Action) LotteryClose(draw *pty.LotteryClose) (*types.Receipt, erro
...
@@ -503,16 +502,17 @@ func (action *Action) LotteryClose(draw *pty.LotteryClose) (*types.Receipt, erro
}
}
llog
.
Debug
(
"LotteryClose"
,
"totalReturn"
,
totalReturn
)
llog
.
Debug
(
"LotteryClose"
,
"totalReturn"
,
totalReturn
)
cfg
:=
action
.
api
.
GetConfig
()
if
totalReturn
>
0
{
if
totalReturn
>
0
{
if
!
action
.
CheckExecAccount
(
lott
.
CreateAddr
,
decimal
*
totalReturn
,
true
)
{
if
!
action
.
CheckExecAccount
(
lott
.
CreateAddr
,
cfg
.
GetCoinPrecision
()
*
totalReturn
,
true
)
{
return
nil
,
pty
.
ErrLotteryFundNotEnough
return
nil
,
pty
.
ErrLotteryFundNotEnough
}
}
for
_
,
recs
:=
range
lott
.
PurRecords
{
for
_
,
recs
:=
range
lott
.
PurRecords
{
if
recs
.
AmountOneRound
>
0
{
if
recs
.
AmountOneRound
>
0
{
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransferFrozen
(
lott
.
CreateAddr
,
recs
.
Addr
,
action
.
execaddr
,
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransferFrozen
(
lott
.
CreateAddr
,
recs
.
Addr
,
action
.
execaddr
,
decimal
*
recs
.
AmountOneRound
)
cfg
.
GetCoinPrecision
()
*
recs
.
AmountOneRound
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -621,11 +621,11 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp
...
@@ -621,11 +621,11 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp
}
}
llog
.
Debug
(
"checkDraw"
,
"lenofupdate"
,
len
(
updateInfo
.
BuyInfo
),
"update"
,
updateInfo
.
BuyInfo
)
llog
.
Debug
(
"checkDraw"
,
"lenofupdate"
,
len
(
updateInfo
.
BuyInfo
),
"update"
,
updateInfo
.
BuyInfo
)
var
factor
=
decimal
var
factor
=
action
.
api
.
GetConfig
()
.
GetCoinPrecision
()
if
totalFund
>
0
{
if
totalFund
>
0
{
if
totalFund
>
lott
.
GetFund
()
/
2
{
if
totalFund
>
lott
.
GetFund
()
/
2
{
llog
.
Debug
(
"checkDraw ajust fund"
,
"lott.Fund"
,
lott
.
Fund
,
"totalFund"
,
totalFund
)
llog
.
Debug
(
"checkDraw ajust fund"
,
"lott.Fund"
,
lott
.
Fund
,
"totalFund"
,
totalFund
)
factor
=
decimal
*
(
lott
.
GetFund
())
/
2
/
(
totalFund
)
factor
=
action
.
api
.
GetConfig
()
.
GetCoinPrecision
()
*
(
lott
.
GetFund
())
/
2
/
(
totalFund
)
lott
.
Fund
=
lott
.
Fund
/
2
lott
.
Fund
=
lott
.
Fund
/
2
}
else
{
}
else
{
lott
.
Fund
-=
totalFund
lott
.
Fund
-=
totalFund
...
...
plugin/dapp/multisig/commands/multisig.go
View file @
100bcc22
...
@@ -6,14 +6,15 @@ package commands
...
@@ -6,14 +6,15 @@ package commands
import
(
import
(
"fmt"
"fmt"
commandtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
"math"
"math"
"os"
"os"
"strconv"
"strconv"
"strings"
"strings"
"time"
"time"
commandtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
"github.com/33cn/chain33/rpc/jsonclient"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
...
@@ -706,8 +707,8 @@ func parseAccInfo(view ...interface{}) (interface{}, error) {
...
@@ -706,8 +707,8 @@ func parseAccInfo(view ...interface{}) (interface{}, error) {
var
dailyLimitResults
[]
*
mty
.
DailyLimitResult
var
dailyLimitResults
[]
*
mty
.
DailyLimitResult
for
_
,
dailyLimit
:=
range
res
.
DailyLimits
{
for
_
,
dailyLimit
:=
range
res
.
DailyLimits
{
dailyLimt
:=
types
.
GetFormatFloat
(
int64
(
dailyLimit
.
DailyLimit
),
cfg
.
CoinPrecision
,
true
)
dailyLimt
:=
types
.
FormatAmount2FloatDisplay
(
int64
(
dailyLimit
.
DailyLimit
),
cfg
.
CoinPrecision
,
true
)
spentToday
:=
types
.
GetFormatFloat
(
int64
(
dailyLimit
.
SpentToday
),
cfg
.
CoinPrecision
,
true
)
spentToday
:=
types
.
FormatAmount2FloatDisplay
(
int64
(
dailyLimit
.
SpentToday
),
cfg
.
CoinPrecision
,
true
)
dailyLimitResult
:=
&
mty
.
DailyLimitResult
{
dailyLimitResult
:=
&
mty
.
DailyLimitResult
{
Symbol
:
dailyLimit
.
Symbol
,
Symbol
:
dailyLimit
.
Symbol
,
Execer
:
dailyLimit
.
Execer
,
Execer
:
dailyLimit
.
Execer
,
...
@@ -984,7 +985,7 @@ func parseUnSpentToday(view ...interface{}) (interface{}, error) {
...
@@ -984,7 +985,7 @@ func parseUnSpentToday(view ...interface{}) (interface{}, error) {
var
result
[]
*
mty
.
UnSpentAssetsResult
var
result
[]
*
mty
.
UnSpentAssetsResult
for
_
,
unSpentAssets
:=
range
res
.
UnSpentAssets
{
for
_
,
unSpentAssets
:=
range
res
.
UnSpentAssets
{
amountResult
:=
types
.
GetFormatFloat
(
int64
(
unSpentAssets
.
Amount
),
cfg
.
CoinPrecision
,
true
)
amountResult
:=
types
.
FormatAmount2FloatDisplay
(
int64
(
unSpentAssets
.
Amount
),
cfg
.
CoinPrecision
,
true
)
unSpentAssetsResult
:=
&
mty
.
UnSpentAssetsResult
{
unSpentAssetsResult
:=
&
mty
.
UnSpentAssetsResult
{
Execer
:
unSpentAssets
.
Assets
.
Execer
,
Execer
:
unSpentAssets
.
Assets
.
Execer
,
Symbol
:
unSpentAssets
.
Assets
.
Symbol
,
Symbol
:
unSpentAssets
.
Assets
.
Symbol
,
...
@@ -1052,7 +1053,7 @@ func getMultiSigAccAssets(cmd *cobra.Command, args []string) {
...
@@ -1052,7 +1053,7 @@ func getMultiSigAccAssets(cmd *cobra.Command, args []string) {
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
rep
=
&
mty
.
ReplyAccAssets
{}
rep
=
&
mty
.
ReplyAccAssets
{}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
rep
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
rep
)
ctx
.
Run
Ext
(
parseAccAssets
)
ctx
.
SetResultCb
Ext
(
parseAccAssets
)
ctx
.
RunExt
(
cfg
)
ctx
.
RunExt
(
cfg
)
}
}
...
@@ -1062,9 +1063,9 @@ func parseAccAssets(view ...interface{}) (interface{}, error) {
...
@@ -1062,9 +1063,9 @@ func parseAccAssets(view ...interface{}) (interface{}, error) {
var
result
[]
*
mty
.
AccAssetsResult
var
result
[]
*
mty
.
AccAssetsResult
for
_
,
accAssets
:=
range
res
.
AccAssets
{
for
_
,
accAssets
:=
range
res
.
AccAssets
{
balanceResult
:=
types
.
GetFormatFloat
(
accAssets
.
Account
.
Balance
,
cfg
.
CoinPrecision
,
true
)
balanceResult
:=
types
.
FormatAmount2FloatDisplay
(
accAssets
.
Account
.
Balance
,
cfg
.
CoinPrecision
,
true
)
frozenResult
:=
types
.
GetFormatFloat
(
accAssets
.
Account
.
Frozen
,
cfg
.
CoinPrecision
,
true
)
frozenResult
:=
types
.
FormatAmount2FloatDisplay
(
accAssets
.
Account
.
Frozen
,
cfg
.
CoinPrecision
,
true
)
receiverResult
:=
types
.
GetFormatFloat
(
accAssets
.
RecvAmount
,
cfg
.
CoinPrecision
,
true
)
receiverResult
:=
types
.
FormatAmount2FloatDisplay
(
accAssets
.
RecvAmount
,
cfg
.
CoinPrecision
,
true
)
accAssetsResult
:=
&
mty
.
AccAssetsResult
{
accAssetsResult
:=
&
mty
.
AccAssetsResult
{
Execer
:
accAssets
.
Assets
.
Execer
,
Execer
:
accAssets
.
Assets
.
Execer
,
...
...
plugin/dapp/paracross/executor/account.go
View file @
100bcc22
...
@@ -41,8 +41,8 @@ func NewMainAccount(cfg *types.Chain33Config, paraTitle, paraExecName, paraSymbo
...
@@ -41,8 +41,8 @@ func NewMainAccount(cfg *types.Chain33Config, paraTitle, paraExecName, paraSymbo
}
}
func
assetDepositBalance
(
acc
*
account
.
DB
,
addr
string
,
amount
int64
)
(
*
types
.
Receipt
,
error
)
{
func
assetDepositBalance
(
acc
*
account
.
DB
,
addr
string
,
amount
int64
)
(
*
types
.
Receipt
,
error
)
{
if
!
types
.
CheckAmount
(
amount
)
{
if
err
:=
acc
.
CheckAmount
(
amount
);
err
!=
nil
{
return
nil
,
types
.
ErrAmount
return
nil
,
err
}
}
acc1
:=
acc
.
LoadAccount
(
addr
)
acc1
:=
acc
.
LoadAccount
(
addr
)
copyacc
:=
*
acc1
copyacc
:=
*
acc1
...
@@ -66,8 +66,8 @@ func assetDepositBalance(acc *account.DB, addr string, amount int64) (*types.Rec
...
@@ -66,8 +66,8 @@ func assetDepositBalance(acc *account.DB, addr string, amount int64) (*types.Rec
}
}
func
assetWithdrawBalance
(
acc
*
account
.
DB
,
addr
string
,
amount
int64
)
(
*
types
.
Receipt
,
error
)
{
func
assetWithdrawBalance
(
acc
*
account
.
DB
,
addr
string
,
amount
int64
)
(
*
types
.
Receipt
,
error
)
{
if
!
types
.
CheckAmount
(
amount
)
{
if
err
:=
acc
.
CheckAmount
(
amount
);
err
!=
nil
{
return
nil
,
types
.
ErrAmount
return
nil
,
err
}
}
acc1
:=
acc
.
LoadAccount
(
addr
)
acc1
:=
acc
.
LoadAccount
(
addr
)
if
acc1
.
Balance
-
amount
<
0
{
if
acc1
.
Balance
-
amount
<
0
{
...
...
plugin/dapp/pokerbull/cmd/game.go
View file @
100bcc22
...
@@ -6,8 +6,12 @@ package cmd
...
@@ -6,8 +6,12 @@ package cmd
import
(
import
(
"fmt"
"fmt"
"os"
"strconv"
"strconv"
cmdtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
...
@@ -54,17 +58,21 @@ func addPokerbullStartFlags(cmd *cobra.Command) {
...
@@ -54,17 +58,21 @@ func addPokerbullStartFlags(cmd *cobra.Command) {
}
}
func
pokerbullStart
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
pokerbullStart
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
value
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"value"
)
value
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"value"
)
playerCount
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"playerCount"
)
playerCount
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"playerCount"
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
params
:=
&
rpctypes
.
CreateTxIn
{
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
PokerBullX
),
Execer
:
types
.
GetExecName
(
pkt
.
PokerBullX
,
paraName
),
ActionName
:
pkt
.
CreateStartTx
,
ActionName
:
pkt
.
CreateStartTx
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
value
\"
:%d,
\"
playerNum
\"
:%d}"
,
int64
(
value
)
*
types
.
Coi
n
,
int32
(
playerCount
))),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
value
\"
:%d,
\"
playerNum
\"
:%d}"
,
int64
(
value
)
*
cfg
.
CoinPrecisio
n
,
int32
(
playerCount
))),
}
}
var
res
string
var
res
string
...
@@ -163,25 +171,29 @@ func addPokerbullPlayFlags(cmd *cobra.Command) {
...
@@ -163,25 +171,29 @@ func addPokerbullPlayFlags(cmd *cobra.Command) {
}
}
func
pokerbullPlay
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
pokerbullPlay
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
gameID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"gameID"
)
gameID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"gameID"
)
round
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"round"
)
round
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"round"
)
value
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"value"
)
value
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"value"
)
address
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"address"
)
address
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"address"
)
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
payload
:=
&
pkt
.
PBGamePlay
{
payload
:=
&
pkt
.
PBGamePlay
{
GameId
:
gameID
,
GameId
:
gameID
,
Value
:
int64
(
value
)
*
types
.
Coi
n
,
Value
:
int64
(
value
)
*
cfg
.
CoinPrecisio
n
,
Round
:
int32
(
round
),
Round
:
int32
(
round
),
}
}
payload
.
Address
=
make
([]
string
,
len
(
address
))
payload
.
Address
=
make
([]
string
,
len
(
address
))
copy
(
payload
.
Address
,
address
)
copy
(
payload
.
Address
,
address
)
params
:=
&
rpctypes
.
CreateTxIn
{
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
PokerBullX
),
Execer
:
types
.
GetExecName
(
pkt
.
PokerBullX
,
paraName
),
ActionName
:
pkt
.
CreatePlayTx
,
ActionName
:
pkt
.
CreatePlayTx
,
Payload
:
types
.
MustPBToJSON
(
payload
),
Payload
:
types
.
MustPBToJSON
(
payload
),
}
}
...
...
plugin/dapp/pokerbull/executor/pokerbulldb.go
View file @
100bcc22
...
@@ -6,10 +6,11 @@ package executor
...
@@ -6,10 +6,11 @@ package executor
import
(
import
(
"fmt"
"fmt"
"github.com/33cn/chain33/client"
"sort"
"sort"
"strconv"
"strconv"
"github.com/33cn/chain33/client"
"strings"
"strings"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/account"
...
...
plugin/dapp/pokerbull/executor/query.go
View file @
100bcc22
...
@@ -76,7 +76,7 @@ func (g *PokerBull) Query_QueryGameByRound(in *pkt.QueryPBGameByRound) (types.Me
...
@@ -76,7 +76,7 @@ func (g *PokerBull) Query_QueryGameByRound(in *pkt.QueryPBGameByRound) (types.Me
}
}
cfg
:=
g
.
GetAPI
()
.
GetConfig
()
cfg
:=
g
.
GetAPI
()
.
GetConfig
()
winnerReturn
:=
int64
((
pkt
.
DeveloperFee
+
pkt
.
PlatformFee
)
*
float64
(
cfg
.
GetCoinPrecision
()))
winnerReturn
:=
int64
((
1
-
(
pkt
.
DeveloperFee
+
pkt
.
PlatformFee
)
)
*
float64
(
cfg
.
GetCoinPrecision
()))
gameInfo
:=
&
pkt
.
ReplyPBGameByRound
{
gameInfo
:=
&
pkt
.
ReplyPBGameByRound
{
GameId
:
game
.
GameId
,
GameId
:
game
.
GameId
,
Status
:
game
.
Status
,
Status
:
game
.
Status
,
...
@@ -84,7 +84,7 @@ func (g *PokerBull) Query_QueryGameByRound(in *pkt.QueryPBGameByRound) (types.Me
...
@@ -84,7 +84,7 @@ func (g *PokerBull) Query_QueryGameByRound(in *pkt.QueryPBGameByRound) (types.Me
IsWaiting
:
game
.
IsWaiting
,
IsWaiting
:
game
.
IsWaiting
,
Value
:
game
.
Value
,
Value
:
game
.
Value
,
Players
:
roundPlayers
,
Players
:
roundPlayers
,
Return
:
(
game
.
Value
/
cfg
.
GetCoinPrecision
())
*
(
cfg
.
GetCoinPrecision
()
-
winnerReturn
)
,
Return
:
(
game
.
Value
/
cfg
.
GetCoinPrecision
())
*
winnerReturn
,
}
}
return
gameInfo
,
nil
return
gameInfo
,
nil
...
...
plugin/dapp/privacy/commands/privacy.go
View file @
100bcc22
This diff is collapsed.
Click to expand it.
plugin/dapp/privacy/executor/privacy.go
View file @
100bcc22
...
@@ -236,6 +236,7 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
...
@@ -236,6 +236,7 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
return
pty
.
ErrRingSign
return
pty
.
ErrRingSign
}
}
cfg
:=
p
.
GetAPI
()
.
GetConfig
()
totalInput
:=
int64
(
0
)
totalInput
:=
int64
(
0
)
keyinput
:=
input
.
GetKeyinput
()
keyinput
:=
input
.
GetKeyinput
()
keyImages
:=
make
([][]
byte
,
len
(
keyinput
))
keyImages
:=
make
([][]
byte
,
len
(
keyinput
))
...
@@ -253,7 +254,7 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
...
@@ -253,7 +254,7 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
if
!
res
{
if
!
res
{
if
errIndex
>=
0
&&
errIndex
<
int32
(
len
(
keyinput
))
{
if
errIndex
>=
0
&&
errIndex
<
int32
(
len
(
keyinput
))
{
input
:=
keyinput
[
errIndex
]
input
:=
keyinput
[
errIndex
]
privacylog
.
Error
(
"PrivacyTrading CheckTx"
,
"txhash"
,
txhashstr
,
"UTXO spent already errindex"
,
errIndex
,
"utxo amout"
,
input
.
Amount
/
types
.
Coin
,
"utxo keyimage"
,
common
.
ToHex
(
input
.
KeyImage
))
privacylog
.
Error
(
"PrivacyTrading CheckTx"
,
"txhash"
,
txhashstr
,
"UTXO spent already errindex"
,
errIndex
,
"utxo amout"
,
input
.
Amount
/
cfg
.
GetCoinPrecision
()
,
"utxo keyimage"
,
common
.
ToHex
(
input
.
KeyImage
))
}
}
privacylog
.
Error
(
"PrivacyTrading CheckTx"
,
"txhash"
,
txhashstr
,
"err"
,
"checkUTXOValid failed "
)
privacylog
.
Error
(
"PrivacyTrading CheckTx"
,
"txhash"
,
txhashstr
,
"err"
,
"checkUTXOValid failed "
)
return
pty
.
ErrDoubleSpendOccur
return
pty
.
ErrDoubleSpendOccur
...
@@ -269,7 +270,7 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
...
@@ -269,7 +270,7 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
}
}
//只有主链coins隐私转账才收取特殊交易费, assertExec空情况适配老版本
//只有主链coins隐私转账才收取特殊交易费, assertExec空情况适配老版本
cfg
:=
p
.
GetAPI
()
.
GetConfig
()
if
!
cfg
.
IsPara
()
&&
(
assertExec
==
""
||
assertExec
==
cfg
.
GetCoinExec
())
{
if
!
cfg
.
IsPara
()
&&
(
assertExec
==
""
||
assertExec
==
cfg
.
GetCoinExec
())
{
totalOutput
:=
int64
(
0
)
totalOutput
:=
int64
(
0
)
...
...
plugin/dapp/privacy/rpc/rpc.go
View file @
100bcc22
...
@@ -95,7 +95,8 @@ func (c *Jrpc) GetPrivacyTxByAddr(in *pty.ReqPrivacyTransactionList, result *int
...
@@ -95,7 +95,8 @@ func (c *Jrpc) GetPrivacyTxByAddr(in *pty.ReqPrivacyTransactionList, result *int
return
err
return
err
}
}
var
txdetails
rpctypes
.
WalletTxDetails
var
txdetails
rpctypes
.
WalletTxDetails
err
=
rpctypes
.
ConvertWalletTxDetailToJSON
(
reply
.
(
*
types
.
WalletTxDetails
),
&
txdetails
,
c
.
cli
.
GetConfig
()
.
GetCoinExec
())
cfg
:=
c
.
cli
.
GetConfig
()
err
=
rpctypes
.
ConvertWalletTxDetailToJSON
(
reply
.
(
*
types
.
WalletTxDetails
),
&
txdetails
,
cfg
.
GetCoinExec
(),
cfg
.
GetCoinPrecision
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
plugin/dapp/privacy/wallet/privacybizpolicy.go
View file @
100bcc22
...
@@ -61,7 +61,7 @@ func (policy *privacyPolicy) getWalletOperate() wcom.WalletOperate {
...
@@ -61,7 +61,7 @@ func (policy *privacyPolicy) getWalletOperate() wcom.WalletOperate {
// Init 初始化处理
// Init 初始化处理
func
(
policy
*
privacyPolicy
)
Init
(
walletOperate
wcom
.
WalletOperate
,
sub
[]
byte
)
{
func
(
policy
*
privacyPolicy
)
Init
(
walletOperate
wcom
.
WalletOperate
,
sub
[]
byte
)
{
policy
.
setWalletOperate
(
walletOperate
)
policy
.
setWalletOperate
(
walletOperate
)
policy
.
store
=
newStore
(
walletOperate
.
GetDBStore
(),
walletOperate
.
GetAPI
()
.
GetConfig
()
.
GetCoinExec
()
)
policy
.
store
=
newStore
(
walletOperate
.
GetDBStore
(),
walletOperate
.
GetAPI
()
.
GetConfig
())
// 启动定时检查超期FTXO的协程
// 启动定时检查超期FTXO的协程
walletOperate
.
GetWaitGroup
()
.
Add
(
1
)
walletOperate
.
GetWaitGroup
()
.
Add
(
1
)
go
policy
.
checkWalletStoreData
()
go
policy
.
checkWalletStoreData
()
...
...
plugin/dapp/privacy/wallet/privacystore.go
View file @
100bcc22
...
@@ -23,13 +23,13 @@ const (
...
@@ -23,13 +23,13 @@ const (
PRIVACYDBVERSION
int64
=
1
PRIVACYDBVERSION
int64
=
1
)
)
func
newStore
(
db
db
.
DB
,
c
oinsExec
strin
g
)
*
privacyStore
{
func
newStore
(
db
db
.
DB
,
c
fg
*
types
.
Chain33Confi
g
)
*
privacyStore
{
return
&
privacyStore
{
Store
:
wcom
.
NewStore
(
db
),
coinsExec
:
coinsExec
}
return
&
privacyStore
{
Store
:
wcom
.
NewStore
(
db
),
Chain33Config
:
cfg
}
}
}
// privacyStore 隐私交易数据库存储操作类
// privacyStore 隐私交易数据库存储操作类
type
privacyStore
struct
{
type
privacyStore
struct
{
coinsExec
strin
g
*
types
.
Chain33Confi
g
*
wcom
.
Store
*
wcom
.
Store
}
}
...
@@ -257,7 +257,7 @@ func (store *privacyStore) getWalletPrivacyTxDetails(param *privacytypes.ReqPriv
...
@@ -257,7 +257,7 @@ func (store *privacyStore) getWalletPrivacyTxDetails(param *privacytypes.ReqPriv
return
nil
,
types
.
ErrUnmarshal
return
nil
,
types
.
ErrUnmarshal
}
}
txDetail
.
Txhash
=
txDetail
.
GetTx
()
.
Hash
()
txDetail
.
Txhash
=
txDetail
.
GetTx
()
.
Hash
()
if
txDetail
.
GetTx
()
.
IsWithdraw
(
store
.
coinsExec
)
{
if
txDetail
.
GetTx
()
.
IsWithdraw
(
store
.
Chain33Config
.
GetCoinExec
()
)
{
//swap from and to
//swap from and to
txDetail
.
Fromaddr
,
txDetail
.
Tx
.
To
=
txDetail
.
Tx
.
To
,
txDetail
.
Fromaddr
txDetail
.
Fromaddr
,
txDetail
.
Tx
.
To
=
txDetail
.
Tx
.
To
,
txDetail
.
Fromaddr
}
}
...
@@ -556,7 +556,7 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti
...
@@ -556,7 +556,7 @@ func (store *privacyStore) selectCurrentWalletPrivacyTx(txDetal *types.Transacti
}
}
if
assetExec
==
""
{
if
assetExec
==
""
{
assetExec
=
store
.
coinsExec
assetExec
=
store
.
Chain33Config
.
GetCoinExec
()
}
}
//处理output
//处理output
...
@@ -659,7 +659,7 @@ func (store *privacyStore) setUTXO(utxoInfo *privacytypes.PrivacyDBStore, txHash
...
@@ -659,7 +659,7 @@ func (store *privacyStore) setUTXO(utxoInfo *privacytypes.PrivacyDBStore, txHash
}
}
outIndex
:=
int
(
utxoInfo
.
OutIndex
)
outIndex
:=
int
(
utxoInfo
.
OutIndex
)
utxoKey
:=
calcUTXOKey
(
txHash
,
outIndex
)
utxoKey
:=
calcUTXOKey
(
txHash
,
outIndex
)
bizlog
.
Debug
(
"setUTXO"
,
"addr"
,
utxoInfo
.
Owner
,
"tx with hash"
,
txHash
,
"amount:"
,
utxoInfo
.
Amount
/
types
.
Coin
)
bizlog
.
Debug
(
"setUTXO"
,
"addr"
,
utxoInfo
.
Owner
,
"tx with hash"
,
txHash
,
"amount:"
,
utxoInfo
.
Amount
/
store
.
GetCoinPrecision
()
)
newbatch
.
Set
(
calcUTXOKey4TokenAddr
(
utxoInfo
.
AssetExec
,
utxoInfo
.
Tokenname
,
utxoInfo
.
Owner
,
txHash
,
outIndex
),
utxoKey
)
newbatch
.
Set
(
calcUTXOKey4TokenAddr
(
utxoInfo
.
AssetExec
,
utxoInfo
.
Tokenname
,
utxoInfo
.
Owner
,
txHash
,
outIndex
),
utxoKey
)
newbatch
.
Set
(
utxoKey
,
privacyStorebyte
)
newbatch
.
Set
(
utxoKey
,
privacyStorebyte
)
return
nil
return
nil
...
@@ -854,7 +854,7 @@ func (store *privacyStore) moveFTXO2UTXO(key1 []byte, newbatch db.Batch) {
...
@@ -854,7 +854,7 @@ func (store *privacyStore) moveFTXO2UTXO(key1 []byte, newbatch db.Batch) {
outindex
:=
int
(
ftxo
.
UtxoBasic
.
UtxoGlobalIndex
.
Outindex
)
outindex
:=
int
(
ftxo
.
UtxoBasic
.
UtxoGlobalIndex
.
Outindex
)
key
:=
calcUTXOKey4TokenAddr
(
ftxosInOneTx
.
AssetExec
,
ftxosInOneTx
.
Tokenname
,
ftxosInOneTx
.
Sender
,
utxohash
,
outindex
)
key
:=
calcUTXOKey4TokenAddr
(
ftxosInOneTx
.
AssetExec
,
ftxosInOneTx
.
Tokenname
,
ftxosInOneTx
.
Sender
,
utxohash
,
outindex
)
value
:=
calcUTXOKey
(
utxohash
,
int
(
ftxo
.
UtxoBasic
.
UtxoGlobalIndex
.
Outindex
))
value
:=
calcUTXOKey
(
utxohash
,
int
(
ftxo
.
UtxoBasic
.
UtxoGlobalIndex
.
Outindex
))
bizlog
.
Debug
(
"moveFTXO2UTXO"
,
"addr"
,
ftxosInOneTx
.
Sender
,
"tx with hash"
,
utxohash
,
"amount"
,
ftxo
.
Amount
/
types
.
Coin
)
bizlog
.
Debug
(
"moveFTXO2UTXO"
,
"addr"
,
ftxosInOneTx
.
Sender
,
"tx with hash"
,
utxohash
,
"amount"
,
ftxo
.
Amount
/
store
.
GetCoinPrecision
()
)
newbatch
.
Set
(
key
,
value
)
newbatch
.
Set
(
key
,
value
)
}
}
bizlog
.
Debug
(
"moveFTXO2UTXO"
,
"addr"
,
ftxosInOneTx
.
Sender
,
"tx with hash"
,
ftxosInOneTx
.
Txhash
)
bizlog
.
Debug
(
"moveFTXO2UTXO"
,
"addr"
,
ftxosInOneTx
.
Sender
,
"tx with hash"
,
ftxosInOneTx
.
Txhash
)
...
...
plugin/dapp/privacy/wallet/privacystore_test.go
View file @
100bcc22
...
@@ -27,7 +27,7 @@ func createStore(t *testing.T) *privacyStore {
...
@@ -27,7 +27,7 @@ func createStore(t *testing.T) *privacyStore {
util
.
ResetDatadir
(
mcfg
,
"$TEMP/"
)
util
.
ResetDatadir
(
mcfg
,
"$TEMP/"
)
cfgWallet
:=
mcfg
.
Wallet
cfgWallet
:=
mcfg
.
Wallet
walletStoreDB
:=
dbm
.
NewDB
(
"wallet"
,
cfgWallet
.
Driver
,
cfgWallet
.
DbPath
,
cfgWallet
.
DbCache
)
walletStoreDB
:=
dbm
.
NewDB
(
"wallet"
,
cfgWallet
.
Driver
,
cfgWallet
.
DbPath
,
cfgWallet
.
DbCache
)
store
:=
newStore
(
walletStoreDB
,
"coins"
)
store
:=
newStore
(
walletStoreDB
,
cfg
)
assert
.
NotNil
(
t
,
store
)
assert
.
NotNil
(
t
,
store
)
return
store
return
store
}
}
...
...
plugin/dapp/relay/commands/relay.go
View file @
100bcc22
...
@@ -7,11 +7,12 @@ package commands
...
@@ -7,11 +7,12 @@ package commands
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
commandtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
"os"
"os"
"strings"
"strings"
commandtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
"github.com/33cn/chain33/rpc/jsonclient"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
...
@@ -318,10 +319,10 @@ func parseRelayOrders(res ty.ReplyRelayOrders, coinPrecision int64) {
...
@@ -318,10 +319,10 @@ func parseRelayOrders(res ty.ReplyRelayOrders, coinPrecision int64) {
show
.
Status
=
order
.
Status
.
String
()
show
.
Status
=
order
.
Status
.
String
()
show
.
Creator
=
order
.
CreaterAddr
show
.
Creator
=
order
.
CreaterAddr
show
.
CoinOperation
=
order
.
Operation
show
.
CoinOperation
=
order
.
Operation
show
.
Amount
=
types
.
GetFormatFloat
(
int64
(
order
.
LocalCoinAmount
),
coinPrecision
,
true
)
show
.
Amount
=
types
.
FormatAmount2FloatDisplay
(
int64
(
order
.
LocalCoinAmount
),
coinPrecision
,
true
)
show
.
Coin
=
order
.
XCoin
show
.
Coin
=
order
.
XCoin
show
.
CoinAddr
=
order
.
XAddr
show
.
CoinAddr
=
order
.
XAddr
show
.
CoinAmount
=
types
.
GetFormatFloat
(
int64
(
order
.
XAmount
),
coinPrecision
,
true
)
show
.
CoinAmount
=
types
.
FormatAmount2FloatDisplay
(
int64
(
order
.
XAmount
),
coinPrecision
,
true
)
show
.
CoinWaits
=
order
.
XBlockWaits
show
.
CoinWaits
=
order
.
XBlockWaits
show
.
CreateTime
=
order
.
CreateTime
show
.
CreateTime
=
order
.
CreateTime
show
.
AcceptAddr
=
order
.
AcceptAddr
show
.
AcceptAddr
=
order
.
AcceptAddr
...
...
plugin/dapp/relay/executor/relaydb.go
View file @
100bcc22
...
@@ -7,8 +7,6 @@ package executor
...
@@ -7,8 +7,6 @@ package executor
import
(
import
(
"time"
"time"
"strconv"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
...
@@ -28,10 +26,11 @@ const (
...
@@ -28,10 +26,11 @@ const (
type
relayLog
struct
{
type
relayLog
struct
{
ty
.
RelayOrder
ty
.
RelayOrder
*
types
.
Chain33Config
}
}
func
newRelayLog
(
order
*
ty
.
RelayOrder
)
*
relayLog
{
func
newRelayLog
(
order
*
ty
.
RelayOrder
,
cfg
*
types
.
Chain33Config
)
*
relayLog
{
return
&
relayLog
{
*
order
}
return
&
relayLog
{
RelayOrder
:
*
order
,
Chain33Config
:
cfg
}
}
}
func
(
r
*
relayLog
)
save
(
db
dbm
.
KV
)
[]
*
types
.
KeyValue
{
func
(
r
*
relayLog
)
save
(
db
dbm
.
KV
)
[]
*
types
.
KeyValue
{
...
@@ -65,10 +64,10 @@ func (r *relayLog) receiptLog(relayLogType int32) *types.ReceiptLog {
...
@@ -65,10 +64,10 @@ func (r *relayLog) receiptLog(relayLogType int32) *types.ReceiptLog {
CurStatus
:
r
.
Status
.
String
(),
CurStatus
:
r
.
Status
.
String
(),
PreStatus
:
r
.
PreStatus
.
String
(),
PreStatus
:
r
.
PreStatus
.
String
(),
CreaterAddr
:
r
.
CreaterAddr
,
CreaterAddr
:
r
.
CreaterAddr
,
LocalCoinAmount
:
strconv
.
FormatFloat
(
float64
(
r
.
LocalCoinAmount
)
/
float64
(
types
.
Coin
),
'f'
,
4
,
64
),
LocalCoinAmount
:
types
.
FormatAmount2FloatDisplay
(
int64
(
r
.
LocalCoinAmount
),
r
.
GetCoinPrecision
(),
true
),
CoinOperation
:
r
.
Operation
,
CoinOperation
:
r
.
Operation
,
XCoin
:
r
.
XCoin
,
XCoin
:
r
.
XCoin
,
XAmount
:
strconv
.
FormatFloat
(
float64
(
r
.
XAmount
)
/
float64
(
types
.
Coin
),
'f'
,
4
,
64
),
XAmount
:
types
.
FormatAmount2FloatDisplay
(
int64
(
r
.
XAmount
),
r
.
GetCoinPrecision
(),
true
),
XAddr
:
r
.
XAddr
,
XAddr
:
r
.
XAddr
,
XTxHash
:
r
.
XTxHash
,
XTxHash
:
r
.
XTxHash
,
XBlockWaits
:
r
.
XBlockWaits
,
XBlockWaits
:
r
.
XBlockWaits
,
...
@@ -200,7 +199,7 @@ func (action *relayDB) create(order *ty.RelayCreate) (*types.Receipt, error) {
...
@@ -200,7 +199,7 @@ func (action *relayDB) create(order *ty.RelayCreate) (*types.Receipt, error) {
logs
=
append
(
logs
,
receipt
.
Logs
...
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
relayLog
:=
newRelayLog
(
uOrder
)
relayLog
:=
newRelayLog
(
uOrder
,
action
.
api
.
GetConfig
()
)
sellOrderKV
:=
relayLog
.
save
(
action
.
db
)
sellOrderKV
:=
relayLog
.
save
(
action
.
db
)
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayCreate
))
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayCreate
))
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
...
@@ -305,7 +304,7 @@ func (action *relayDB) revokeCreate(revoke *ty.RelayRevoke) (*types.Receipt, err
...
@@ -305,7 +304,7 @@ func (action *relayDB) revokeCreate(revoke *ty.RelayRevoke) (*types.Receipt, err
order
.
Status
=
ty
.
RelayOrderStatus_canceled
order
.
Status
=
ty
.
RelayOrderStatus_canceled
}
}
relayLog
:=
newRelayLog
(
order
)
relayLog
:=
newRelayLog
(
order
,
action
.
api
.
GetConfig
()
)
orderKV
:=
relayLog
.
save
(
action
.
db
)
orderKV
:=
relayLog
.
save
(
action
.
db
)
var
logs
[]
*
types
.
ReceiptLog
var
logs
[]
*
types
.
ReceiptLog
...
@@ -382,7 +381,7 @@ func (action *relayDB) accept(accept *ty.RelayAccept) (*types.Receipt, error) {
...
@@ -382,7 +381,7 @@ func (action *relayDB) accept(accept *ty.RelayAccept) (*types.Receipt, error) {
logs
=
append
(
logs
,
receipt
.
Logs
...
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
relayLog
:=
newRelayLog
(
order
)
relayLog
:=
newRelayLog
(
order
,
action
.
api
.
GetConfig
()
)
sellOrderKV
:=
relayLog
.
save
(
action
.
db
)
sellOrderKV
:=
relayLog
.
save
(
action
.
db
)
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayAccept
))
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayAccept
))
...
@@ -461,7 +460,7 @@ func (action *relayDB) revokeAccept(revoke *ty.RelayRevoke) (*types.Receipt, err
...
@@ -461,7 +460,7 @@ func (action *relayDB) revokeAccept(revoke *ty.RelayRevoke) (*types.Receipt, err
logs
=
append
(
logs
,
receiptTransfer
.
Logs
...
)
logs
=
append
(
logs
,
receiptTransfer
.
Logs
...
)
kv
=
append
(
kv
,
receiptTransfer
.
KV
...
)
kv
=
append
(
kv
,
receiptTransfer
.
KV
...
)
}
}
relayLog
:=
newRelayLog
(
order
)
relayLog
:=
newRelayLog
(
order
,
action
.
api
.
GetConfig
()
)
sellOrderKV
:=
relayLog
.
save
(
action
.
db
)
sellOrderKV
:=
relayLog
.
save
(
action
.
db
)
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayRevokeAccept
))
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayRevokeAccept
))
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
...
@@ -518,7 +517,7 @@ func (action *relayDB) confirmTx(confirm *ty.RelayConfirmTx) (*types.Receipt, er
...
@@ -518,7 +517,7 @@ func (action *relayDB) confirmTx(confirm *ty.RelayConfirmTx) (*types.Receipt, er
var
logs
[]
*
types
.
ReceiptLog
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
var
kv
[]
*
types
.
KeyValue
relayLog
:=
newRelayLog
(
order
)
relayLog
:=
newRelayLog
(
order
,
action
.
api
.
GetConfig
()
)
sellOrderKV
:=
relayLog
.
save
(
action
.
db
)
sellOrderKV
:=
relayLog
.
save
(
action
.
db
)
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayConfirmTx
))
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayConfirmTx
))
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
...
@@ -591,7 +590,7 @@ func (action *relayDB) verifyTx(verify *ty.RelayVerify) (*types.Receipt, error)
...
@@ -591,7 +590,7 @@ func (action *relayDB) verifyTx(verify *ty.RelayVerify) (*types.Receipt, error)
order
.
FinishTime
=
action
.
blockTime
order
.
FinishTime
=
action
.
blockTime
order
.
FinishTxHash
=
common
.
ToHex
(
action
.
txHash
)
order
.
FinishTxHash
=
common
.
ToHex
(
action
.
txHash
)
relayLog
:=
newRelayLog
(
order
)
relayLog
:=
newRelayLog
(
order
,
action
.
api
.
GetConfig
()
)
orderKV
:=
relayLog
.
save
(
action
.
db
)
orderKV
:=
relayLog
.
save
(
action
.
db
)
var
logs
[]
*
types
.
ReceiptLog
var
logs
[]
*
types
.
ReceiptLog
...
...
plugin/dapp/retrieve/cmd/retrieve.go
View file @
100bcc22
...
@@ -6,6 +6,10 @@ package cmd
...
@@ -6,6 +6,10 @@ package cmd
import
(
import
(
"fmt"
"fmt"
"os"
cmdtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
rpctypes
"github.com/33cn/chain33/rpc/types"
...
@@ -64,25 +68,31 @@ func addBakupCmdFlags(cmd *cobra.Command) {
...
@@ -64,25 +68,31 @@ func addBakupCmdFlags(cmd *cobra.Command) {
}
}
func
backupCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
backupCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
backup
,
_
:=
cmd
.
Flags
()
.
GetString
(
"backup"
)
backup
,
_
:=
cmd
.
Flags
()
.
GetString
(
"backup"
)
defaultAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"default"
)
defaultAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"default"
)
delay
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"delay"
)
delay
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"delay"
)
defaultFee
:=
float64
(
cfg
.
GetMinTxFeeRate
())
/
float64
(
types
.
Coin
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
if
fee
<
defaultFee
{
feeInt64
,
err
:=
types
.
FormatFloatDisplay2Value
(
fee
,
cfg
.
CoinPrecision
)
fee
=
defaultFee
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"FormatFloatDisplay2Value.fee"
))
return
}
if
feeInt64
<
cfg
.
MinTxFeeRate
{
feeInt64
=
cfg
.
MinTxFeeRate
}
}
if
delay
<
60
{
if
delay
<
60
{
fmt
.
Println
(
"delay period changed to 60"
)
fmt
.
Println
(
"delay period changed to 60"
)
delay
=
60
delay
=
60
}
}
feeInt64
:=
int64
(
fee
*
types
.
InputPrecision
)
*
types
.
Multiple1E4
params
:=
rpc
.
RetrieveBackupTx
{
params
:=
rpc
.
RetrieveBackupTx
{
BackupAddr
:
backup
,
BackupAddr
:
backup
,
DefaultAddr
:
defaultAddr
,
DefaultAddr
:
defaultAddr
,
...
@@ -126,20 +136,26 @@ func addPerformCmdFlags(cmd *cobra.Command) {
...
@@ -126,20 +136,26 @@ func addPerformCmdFlags(cmd *cobra.Command) {
}
}
func
prepareCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
prepareCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
backup
,
_
:=
cmd
.
Flags
()
.
GetString
(
"backup"
)
backup
,
_
:=
cmd
.
Flags
()
.
GetString
(
"backup"
)
defaultAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"default"
)
defaultAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"default"
)
defaultFee
:=
float64
(
cfg
.
GetMinTxFeeRate
())
/
float64
(
types
.
Coin
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
if
fee
<
defaultFee
{
feeInt64
,
err
:=
types
.
FormatFloatDisplay2Value
(
fee
,
cfg
.
CoinPrecision
)
fee
=
defaultFee
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"FormatFloatDisplay2Value.fee"
))
return
}
if
feeInt64
<
cfg
.
MinTxFeeRate
{
feeInt64
=
cfg
.
MinTxFeeRate
}
}
feeInt64
:=
int64
(
fee
*
types
.
InputPrecision
)
*
types
.
Multiple1E4
params
:=
rpc
.
RetrievePrepareTx
{
params
:=
rpc
.
RetrievePrepareTx
{
BackupAddr
:
backup
,
BackupAddr
:
backup
,
DefaultAddr
:
defaultAddr
,
DefaultAddr
:
defaultAddr
,
...
@@ -161,23 +177,29 @@ func PerformCmd() *cobra.Command {
...
@@ -161,23 +177,29 @@ func PerformCmd() *cobra.Command {
}
}
func
performCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
performCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
backup
,
_
:=
cmd
.
Flags
()
.
GetString
(
"backup"
)
backup
,
_
:=
cmd
.
Flags
()
.
GetString
(
"backup"
)
defaultAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"default"
)
defaultAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"default"
)
defaultFee
:=
float64
(
cfg
.
GetMinTxFeeRate
())
/
float64
(
types
.
Coin
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
if
fee
<
defaultFee
{
feeInt64
,
err
:=
types
.
FormatFloatDisplay2Value
(
fee
,
cfg
.
CoinPrecision
)
fee
=
defaultFee
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"FormatFloatDisplay2Value.fee"
))
return
}
if
feeInt64
<
cfg
.
MinTxFeeRate
{
feeInt64
=
cfg
.
MinTxFeeRate
}
}
execs
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"exec"
)
execs
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"exec"
)
symbols
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"symbol"
)
symbols
,
_
:=
cmd
.
Flags
()
.
GetStringArray
(
"symbol"
)
feeInt64
:=
int64
(
fee
*
types
.
InputPrecision
)
*
types
.
Multiple1E4
params
:=
rpc
.
RetrievePerformTx
{
params
:=
rpc
.
RetrievePerformTx
{
BackupAddr
:
backup
,
BackupAddr
:
backup
,
DefaultAddr
:
defaultAddr
,
DefaultAddr
:
defaultAddr
,
...
@@ -208,20 +230,26 @@ func CancelCmd() *cobra.Command {
...
@@ -208,20 +230,26 @@ func CancelCmd() *cobra.Command {
}
}
func
cancelCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
cancelCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
backup
,
_
:=
cmd
.
Flags
()
.
GetString
(
"backup"
)
backup
,
_
:=
cmd
.
Flags
()
.
GetString
(
"backup"
)
defaultAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"default"
)
defaultAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"default"
)
defaultFee
:=
float64
(
cfg
.
GetMinTxFeeRate
())
/
float64
(
types
.
Coin
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
if
fee
<
defaultFee
{
feeInt64
,
err
:=
types
.
FormatFloatDisplay2Value
(
fee
,
cfg
.
CoinPrecision
)
fee
=
defaultFee
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"FormatFloatDisplay2Value.fee"
))
return
}
if
feeInt64
<
cfg
.
MinTxFeeRate
{
feeInt64
=
cfg
.
MinTxFeeRate
}
}
feeInt64
:=
int64
(
fee
*
types
.
InputPrecision
)
*
types
.
Multiple1E4
params
:=
rpc
.
RetrieveCancelTx
{
params
:=
rpc
.
RetrieveCancelTx
{
BackupAddr
:
backup
,
BackupAddr
:
backup
,
DefaultAddr
:
defaultAddr
,
DefaultAddr
:
defaultAddr
,
...
...
plugin/dapp/ticket/rpc/rpc.go
View file @
100bcc22
...
@@ -61,7 +61,7 @@ func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner
...
@@ -61,7 +61,7 @@ func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner
if
len
(
balances
)
==
0
{
if
len
(
balances
)
==
0
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
if
balances
[
0
]
.
Balance
<
in
.
Amount
+
2
*
types
.
Coin
{
if
balances
[
0
]
.
Balance
<
in
.
Amount
+
2
*
cfg
.
GetCoinPrecision
()
{
return
nil
,
types
.
ErrNoBalance
return
nil
,
types
.
ErrNoBalance
}
}
}
}
...
...
plugin/dapp/token/commands/token.go
View file @
100bcc22
...
@@ -8,9 +8,11 @@ import (
...
@@ -8,9 +8,11 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"os"
"os"
"strconv"
"strings"
"strings"
cmdtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
"github.com/33cn/chain33/rpc/jsonclient"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/system/dapp/commands"
"github.com/33cn/chain33/system/dapp/commands"
...
@@ -146,6 +148,13 @@ func GetTokensPreCreatedCmd() *cobra.Command {
...
@@ -146,6 +148,13 @@ func GetTokensPreCreatedCmd() *cobra.Command {
func
getPreCreatedTokens
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
getPreCreatedTokens
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
var
reqtokens
tokenty
.
ReqTokens
var
reqtokens
tokenty
.
ReqTokens
reqtokens
.
Status
=
tokenty
.
TokenStatusPreCreated
reqtokens
.
Status
=
tokenty
.
TokenStatusPreCreated
reqtokens
.
QueryAll
=
true
reqtokens
.
QueryAll
=
true
...
@@ -166,8 +175,8 @@ func getPreCreatedTokens(cmd *cobra.Command, args []string) {
...
@@ -166,8 +175,8 @@ func getPreCreatedTokens(cmd *cobra.Command, args []string) {
}
}
for
_
,
preCreatedToken
:=
range
res
.
Tokens
{
for
_
,
preCreatedToken
:=
range
res
.
Tokens
{
preCreatedToken
.
Price
=
preCreatedToken
.
Price
/
types
.
Coi
n
preCreatedToken
.
Price
=
preCreatedToken
.
Price
/
cfg
.
CoinPrecisio
n
preCreatedToken
.
Total
=
preCreatedToken
.
Total
/
types
.
TokenPrecision
preCreatedToken
.
Total
=
preCreatedToken
.
Total
/
cfg
.
TokenPrecision
data
,
err
:=
json
.
MarshalIndent
(
preCreatedToken
,
""
,
" "
)
data
,
err
:=
json
.
MarshalIndent
(
preCreatedToken
,
""
,
" "
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -192,6 +201,13 @@ func GetTokensCreatedCmd() *cobra.Command {
...
@@ -192,6 +201,13 @@ func GetTokensCreatedCmd() *cobra.Command {
func
getFinishCreatedTokens
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
getFinishCreatedTokens
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
var
reqtokens
tokenty
.
ReqTokens
var
reqtokens
tokenty
.
ReqTokens
reqtokens
.
Status
=
tokenty
.
TokenStatusCreated
reqtokens
.
Status
=
tokenty
.
TokenStatusCreated
reqtokens
.
QueryAll
=
true
reqtokens
.
QueryAll
=
true
...
@@ -212,8 +228,8 @@ func getFinishCreatedTokens(cmd *cobra.Command, args []string) {
...
@@ -212,8 +228,8 @@ func getFinishCreatedTokens(cmd *cobra.Command, args []string) {
}
}
for
_
,
createdToken
:=
range
res
.
Tokens
{
for
_
,
createdToken
:=
range
res
.
Tokens
{
createdToken
.
Price
=
createdToken
.
Price
/
types
.
Coi
n
createdToken
.
Price
=
createdToken
.
Price
/
cfg
.
CoinPrecisio
n
createdToken
.
Total
=
createdToken
.
Total
/
types
.
TokenPrecision
createdToken
.
Total
=
createdToken
.
Total
/
cfg
.
TokenPrecision
//fmt.Printf("---The %dth Finish Created token is below--------------------\n", i)
//fmt.Printf("---The %dth Finish Created token is below--------------------\n", i)
data
,
err
:=
json
.
MarshalIndent
(
createdToken
,
""
,
" "
)
data
,
err
:=
json
.
MarshalIndent
(
createdToken
,
""
,
" "
)
...
@@ -250,6 +266,13 @@ func tokenAssets(cmd *cobra.Command, args []string) {
...
@@ -250,6 +266,13 @@ func tokenAssets(cmd *cobra.Command, args []string) {
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
addr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
addr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
execer
,
_
:=
cmd
.
Flags
()
.
GetString
(
"exec"
)
execer
,
_
:=
cmd
.
Flags
()
.
GetString
(
"exec"
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
execer
=
getRealExecName
(
paraName
,
execer
)
execer
=
getRealExecName
(
paraName
,
execer
)
req
:=
tokenty
.
ReqAccountTokenAssets
{
req
:=
tokenty
.
ReqAccountTokenAssets
{
Address
:
addr
,
Address
:
addr
,
...
@@ -262,16 +285,18 @@ func tokenAssets(cmd *cobra.Command, args []string) {
...
@@ -262,16 +285,18 @@ func tokenAssets(cmd *cobra.Command, args []string) {
var
res
tokenty
.
ReplyAccountTokenAssets
var
res
tokenty
.
ReplyAccountTokenAssets
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
SetResultCb
(
parseTokenAssetsRes
)
ctx
.
SetResultCb
Ext
(
parseTokenAssetsRes
)
ctx
.
Run
(
)
ctx
.
Run
Ext
(
cfg
)
}
}
func
parseTokenAssetsRes
(
arg
interface
{})
(
interface
{},
error
)
{
func
parseTokenAssetsRes
(
arg
...
interface
{})
(
interface
{},
error
)
{
res
:=
arg
.
(
*
tokenty
.
ReplyAccountTokenAssets
)
res
:=
arg
[
0
]
.
(
*
tokenty
.
ReplyAccountTokenAssets
)
cfg
:=
arg
[
1
]
.
(
*
rpctypes
.
ChainConfigInfo
)
var
result
[]
*
tokenty
.
TokenAccountResult
var
result
[]
*
tokenty
.
TokenAccountResult
for
_
,
ta
:=
range
res
.
TokenAssets
{
for
_
,
ta
:=
range
res
.
TokenAssets
{
balanceResult
:=
strconv
.
FormatFloat
(
float64
(
ta
.
Account
.
Balance
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
4
,
64
)
balanceResult
:=
types
.
FormatAmount2FloatDisplay
(
ta
.
Account
.
Balance
,
cfg
.
TokenPrecision
,
true
)
frozenResult
:=
strconv
.
FormatFloat
(
float64
(
ta
.
Account
.
Frozen
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
4
,
64
)
frozenResult
:=
types
.
FormatAmount2FloatDisplay
(
ta
.
Account
.
Frozen
,
cfg
.
TokenPrecision
,
true
)
tokenAccount
:=
&
tokenty
.
TokenAccountResult
{
tokenAccount
:=
&
tokenty
.
TokenAccountResult
{
Token
:
ta
.
Symbol
,
Token
:
ta
.
Symbol
,
Addr
:
ta
.
Account
.
Addr
,
Addr
:
ta
.
Account
.
Addr
,
...
@@ -312,6 +337,12 @@ func tokenBalance(cmd *cobra.Command, args []string) {
...
@@ -312,6 +337,12 @@ func tokenBalance(cmd *cobra.Command, args []string) {
token
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
token
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
execer
,
_
:=
cmd
.
Flags
()
.
GetString
(
"exec"
)
execer
,
_
:=
cmd
.
Flags
()
.
GetString
(
"exec"
)
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
execer
=
getRealExecName
(
paraName
,
execer
)
execer
=
getRealExecName
(
paraName
,
execer
)
addresses
:=
strings
.
Split
(
addr
,
" "
)
addresses
:=
strings
.
Split
(
addr
,
" "
)
params
:=
tokenty
.
ReqTokenBalance
{
params
:=
tokenty
.
ReqTokenBalance
{
...
@@ -321,16 +352,18 @@ func tokenBalance(cmd *cobra.Command, args []string) {
...
@@ -321,16 +352,18 @@ func tokenBalance(cmd *cobra.Command, args []string) {
}
}
var
res
[]
*
rpctypes
.
Account
var
res
[]
*
rpctypes
.
Account
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"token.GetTokenBalance"
,
params
,
&
res
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"token.GetTokenBalance"
,
params
,
&
res
)
ctx
.
SetResultCb
(
parseTokenBalanceRes
)
ctx
.
SetResultCb
Ext
(
parseTokenBalanceRes
)
ctx
.
Run
(
)
ctx
.
Run
Ext
(
cfg
)
}
}
func
parseTokenBalanceRes
(
arg
interface
{})
(
interface
{},
error
)
{
func
parseTokenBalanceRes
(
arg
...
interface
{})
(
interface
{},
error
)
{
res
:=
arg
.
(
*
[]
*
rpctypes
.
Account
)
res
:=
arg
[
0
]
.
(
*
[]
*
rpctypes
.
Account
)
cfg
:=
arg
[
1
]
.
(
*
rpctypes
.
ChainConfigInfo
)
var
result
[]
*
tokenty
.
TokenAccountResult
var
result
[]
*
tokenty
.
TokenAccountResult
for
_
,
one
:=
range
*
res
{
for
_
,
one
:=
range
*
res
{
balanceResult
:=
strconv
.
FormatFloat
(
float64
(
one
.
Balance
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
4
,
64
)
balanceResult
:=
types
.
FormatAmount2FloatDisplay
(
one
.
Balance
,
cfg
.
TokenPrecision
,
true
)
frozenResult
:=
strconv
.
FormatFloat
(
float64
(
one
.
Frozen
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
4
,
64
)
frozenResult
:=
types
.
FormatAmount2FloatDisplay
(
one
.
Frozen
,
cfg
.
TokenPrecision
,
true
)
tokenAccount
:=
&
tokenty
.
TokenAccountResult
{
tokenAccount
:=
&
tokenty
.
TokenAccountResult
{
Token
:
tokenSymbol
,
Token
:
tokenSymbol
,
Addr
:
one
.
Addr
,
Addr
:
one
.
Addr
,
...
@@ -388,14 +421,24 @@ func tokenPrecreated(cmd *cobra.Command, args []string) {
...
@@ -388,14 +421,24 @@ func tokenPrecreated(cmd *cobra.Command, args []string) {
total
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"total"
)
total
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"total"
)
category
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"category"
)
category
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"category"
)
priceInt64
:=
int64
((
price
+
0.000001
)
*
1e4
)
cfg
,
err
:=
cmdtypes
.
GetChainConfig
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"GetChainConfig"
))
return
}
priceInt64
,
err
:=
types
.
FormatFloatDisplay2Value
(
price
,
cfg
.
CoinPrecision
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"FormatFloatDisplay2Value"
))
return
}
params
:=
&
tokenty
.
TokenPreCreate
{
params
:=
&
tokenty
.
TokenPreCreate
{
Price
:
priceInt64
*
1e4
,
Price
:
priceInt64
,
Name
:
name
,
Name
:
name
,
Symbol
:
symbol
,
Symbol
:
symbol
,
Introduction
:
introduction
,
Introduction
:
introduction
,
Owner
:
ownerAddr
,
Owner
:
ownerAddr
,
Total
:
total
*
types
.
TokenPrecision
,
Total
:
total
*
cfg
.
TokenPrecision
,
Category
:
category
,
Category
:
category
,
}
}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"token.CreateRawTokenPreCreateTx"
,
params
,
nil
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"token.CreateRawTokenPreCreateTx"
,
params
,
nil
)
...
...
plugin/dapp/trade/commands/trade.go
View file @
100bcc22
...
@@ -6,11 +6,12 @@ package commands
...
@@ -6,11 +6,12 @@ package commands
import
(
import
(
"fmt"
"fmt"
commandtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
"os"
"os"
"strings"
"strings"
commandtypes
"github.com/33cn/chain33/system/dapp/commands/types"
"github.com/pkg/errors"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
...
@@ -220,8 +221,8 @@ func parseSellOrders(arg ...interface{}) (interface{}, error) {
...
@@ -220,8 +221,8 @@ func parseSellOrders(arg ...interface{}) (interface{}, error) {
TotalBoardlot
:
o
.
TotalBoardlot
,
TotalBoardlot
:
o
.
TotalBoardlot
,
TradedBoardlot
:
o
.
TradedBoardlot
,
TradedBoardlot
:
o
.
TradedBoardlot
,
}
}
order
.
AmountPerBoardlot
=
types
.
GetFormatFloat
(
o
.
AmountPerBoardlot
,
cfg
.
CoinPrecision
,
true
)
order
.
AmountPerBoardlot
=
types
.
FormatAmount2FloatDisplay
(
o
.
AmountPerBoardlot
,
cfg
.
CoinPrecision
,
true
)
order
.
PricePerBoardlot
=
types
.
GetFormatFloat
(
o
.
PricePerBoardlot
,
cfg
.
CoinPrecision
,
true
)
order
.
PricePerBoardlot
=
types
.
FormatAmount2FloatDisplay
(
o
.
PricePerBoardlot
,
cfg
.
CoinPrecision
,
true
)
result
.
SellOrders
=
append
(
result
.
SellOrders
,
order
)
result
.
SellOrders
=
append
(
result
.
SellOrders
,
order
)
}
}
return
result
,
nil
return
result
,
nil
...
@@ -392,8 +393,8 @@ func parseBuyOrders(arg ...interface{}) (interface{}, error) {
...
@@ -392,8 +393,8 @@ func parseBuyOrders(arg ...interface{}) (interface{}, error) {
TotalBoardlot
:
o
.
TotalBoardlot
,
TotalBoardlot
:
o
.
TotalBoardlot
,
TradedBoardlot
:
o
.
TradedBoardlot
,
TradedBoardlot
:
o
.
TradedBoardlot
,
}
}
order
.
AmountPerBoardlot
=
types
.
GetFormatFloat
(
o
.
AmountPerBoardlot
,
cfg
.
CoinPrecision
,
true
)
order
.
AmountPerBoardlot
=
types
.
FormatAmount2FloatDisplay
(
o
.
AmountPerBoardlot
,
cfg
.
CoinPrecision
,
true
)
order
.
PricePerBoardlot
=
types
.
GetFormatFloat
(
o
.
PricePerBoardlot
,
cfg
.
CoinPrecision
,
true
)
order
.
PricePerBoardlot
=
types
.
FormatAmount2FloatDisplay
(
o
.
PricePerBoardlot
,
cfg
.
CoinPrecision
,
true
)
result
.
BuyOrders
=
append
(
result
.
BuyOrders
,
order
)
result
.
BuyOrders
=
append
(
result
.
BuyOrders
,
order
)
}
}
return
result
,
nil
return
result
,
nil
...
@@ -472,8 +473,8 @@ func parseTradeOrders(arg ...interface{}) (interface{}, error) {
...
@@ -472,8 +473,8 @@ func parseTradeOrders(arg ...interface{}) (interface{}, error) {
TotalBoardlot
:
o
.
TotalBoardlot
,
TotalBoardlot
:
o
.
TotalBoardlot
,
TradedBoardlot
:
o
.
TradedBoardlot
,
TradedBoardlot
:
o
.
TradedBoardlot
,
}
}
order
.
AmountPerBoardlot
=
types
.
GetFormatFloat
(
o
.
AmountPerBoardlot
,
cfg
.
CoinPrecision
,
true
)
order
.
AmountPerBoardlot
=
types
.
FormatAmount2FloatDisplay
(
o
.
AmountPerBoardlot
,
cfg
.
CoinPrecision
,
true
)
order
.
PricePerBoardlot
=
types
.
GetFormatFloat
(
o
.
PricePerBoardlot
,
cfg
.
CoinPrecision
,
true
)
order
.
PricePerBoardlot
=
types
.
FormatAmount2FloatDisplay
(
o
.
PricePerBoardlot
,
cfg
.
CoinPrecision
,
true
)
result
.
Orders
=
append
(
result
.
Orders
,
order
)
result
.
Orders
=
append
(
result
.
Orders
,
order
)
}
}
return
result
,
nil
return
result
,
nil
...
@@ -744,9 +745,9 @@ func buyRevoke(cmd *cobra.Command, args []string) {
...
@@ -744,9 +745,9 @@ func buyRevoke(cmd *cobra.Command, args []string) {
return
return
}
}
feeInt64
,
err
:=
types
.
TransferFloat
(
fee
,
cfg
.
CoinPrecision
)
feeInt64
,
err
:=
types
.
FormatFloatDisplay2Value
(
fee
,
cfg
.
CoinPrecision
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"
TransferFloat
"
))
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
Wrapf
(
err
,
"
FormatFloatDisplay2Value
"
))
return
return
}
}
params
:=
&
pty
.
TradeRevokeBuyTx
{
params
:=
&
pty
.
TradeRevokeBuyTx
{
...
...
plugin/dapp/trade/executor/local_order.go
View file @
100bcc22
...
@@ -254,32 +254,33 @@ func (t *trade) rollBackSellLimit(tx *types.Transaction, sell *pty.ReceiptSellBa
...
@@ -254,32 +254,33 @@ func (t *trade) rollBackSellLimit(tx *types.Transaction, sell *pty.ReceiptSellBa
return
order
return
order
}
}
func
parseOrderAmountFloat
(
s
string
)
int64
{
func
parseOrderAmountFloat
(
s
string
,
tokenPrecision
int64
)
int64
{
x
,
err
:=
strconv
.
ParseFloat
(
s
,
64
)
x
,
err
:=
strconv
.
ParseFloat
(
s
,
64
)
if
err
!=
nil
{
if
err
!=
nil
{
tradelog
.
Error
(
"parseOrderAmountFloat"
,
"decode receipt"
,
err
)
tradelog
.
Error
(
"parseOrderAmountFloat"
,
"decode receipt"
,
err
)
return
0
return
0
}
}
return
int64
(
x
*
float64
(
t
ypes
.
T
okenPrecision
))
return
int64
(
x
*
float64
(
tokenPrecision
))
}
}
func
parseOrderPriceFloat
(
s
string
)
int64
{
func
parseOrderPriceFloat
(
s
string
,
coinPrecision
int64
)
int64
{
x
,
err
:=
strconv
.
ParseFloat
(
s
,
64
)
x
,
err
:=
strconv
.
ParseFloat
(
s
,
64
)
if
err
!=
nil
{
if
err
!=
nil
{
tradelog
.
Error
(
"parseOrderPriceFloat"
,
"decode receipt"
,
err
)
tradelog
.
Error
(
"parseOrderPriceFloat"
,
"decode receipt"
,
err
)
return
0
return
0
}
}
return
int64
(
x
*
float64
(
types
.
Coi
n
))
return
int64
(
x
*
float64
(
coinPrecisio
n
))
}
}
func
(
t
*
trade
)
genSellMarket
(
tx
*
types
.
Transaction
,
sell
*
pty
.
ReceiptSellBase
,
txIndex
string
)
*
pty
.
LocalOrder
{
func
(
t
*
trade
)
genSellMarket
(
tx
*
types
.
Transaction
,
sell
*
pty
.
ReceiptSellBase
,
txIndex
string
)
*
pty
.
LocalOrder
{
cfg
:=
t
.
GetAPI
()
.
GetConfig
()
order
:=
&
pty
.
LocalOrder
{
order
:=
&
pty
.
LocalOrder
{
AssetSymbol
:
sell
.
TokenSymbol
,
AssetSymbol
:
sell
.
TokenSymbol
,
TxIndex
:
txIndex
,
TxIndex
:
txIndex
,
Owner
:
sell
.
Owner
,
Owner
:
sell
.
Owner
,
AmountPerBoardlot
:
parseOrderAmountFloat
(
sell
.
AmountPerBoardlot
),
AmountPerBoardlot
:
parseOrderAmountFloat
(
sell
.
AmountPerBoardlot
,
cfg
.
GetTokenPrecision
()
),
MinBoardlot
:
sell
.
MinBoardlot
,
MinBoardlot
:
sell
.
MinBoardlot
,
PricePerBoardlot
:
parseOrderPriceFloat
(
sell
.
PricePerBoardlot
),
PricePerBoardlot
:
parseOrderPriceFloat
(
sell
.
PricePerBoardlot
,
cfg
.
GetCoinPrecision
()
),
TotalBoardlot
:
sell
.
TotalBoardlot
,
TotalBoardlot
:
sell
.
TotalBoardlot
,
TradedBoardlot
:
sell
.
SoldBoardlot
,
TradedBoardlot
:
sell
.
SoldBoardlot
,
BuyID
:
sell
.
BuyID
,
BuyID
:
sell
.
BuyID
,
...
@@ -300,13 +301,14 @@ func (t *trade) genSellMarket(tx *types.Transaction, sell *pty.ReceiptSellBase,
...
@@ -300,13 +301,14 @@ func (t *trade) genSellMarket(tx *types.Transaction, sell *pty.ReceiptSellBase,
}
}
func
(
t
*
trade
)
genBuyLimit
(
tx
*
types
.
Transaction
,
buy
*
pty
.
ReceiptBuyBase
,
txIndex
string
)
*
pty
.
LocalOrder
{
func
(
t
*
trade
)
genBuyLimit
(
tx
*
types
.
Transaction
,
buy
*
pty
.
ReceiptBuyBase
,
txIndex
string
)
*
pty
.
LocalOrder
{
cfg
:=
t
.
GetAPI
()
.
GetConfig
()
order
:=
&
pty
.
LocalOrder
{
order
:=
&
pty
.
LocalOrder
{
AssetSymbol
:
buy
.
TokenSymbol
,
AssetSymbol
:
buy
.
TokenSymbol
,
TxIndex
:
txIndex
,
TxIndex
:
txIndex
,
Owner
:
buy
.
Owner
,
Owner
:
buy
.
Owner
,
AmountPerBoardlot
:
parseOrderAmountFloat
(
buy
.
AmountPerBoardlot
),
AmountPerBoardlot
:
parseOrderAmountFloat
(
buy
.
AmountPerBoardlot
,
cfg
.
GetTokenPrecision
()
),
MinBoardlot
:
buy
.
MinBoardlot
,
MinBoardlot
:
buy
.
MinBoardlot
,
PricePerBoardlot
:
parseOrderPriceFloat
(
buy
.
PricePerBoardlot
),
PricePerBoardlot
:
parseOrderPriceFloat
(
buy
.
PricePerBoardlot
,
cfg
.
GetCoinPrecision
()
),
TotalBoardlot
:
buy
.
TotalBoardlot
,
TotalBoardlot
:
buy
.
TotalBoardlot
,
TradedBoardlot
:
buy
.
BoughtBoardlot
,
TradedBoardlot
:
buy
.
BoughtBoardlot
,
BuyID
:
buy
.
BuyID
,
BuyID
:
buy
.
BuyID
,
...
@@ -374,13 +376,14 @@ func (t *trade) rollbackBuyLimit(tx *types.Transaction, buy *pty.ReceiptBuyBase,
...
@@ -374,13 +376,14 @@ func (t *trade) rollbackBuyLimit(tx *types.Transaction, buy *pty.ReceiptBuyBase,
}
}
func
(
t
*
trade
)
genBuyMarket
(
tx
*
types
.
Transaction
,
buy
*
pty
.
ReceiptBuyBase
,
txIndex
string
)
*
pty
.
LocalOrder
{
func
(
t
*
trade
)
genBuyMarket
(
tx
*
types
.
Transaction
,
buy
*
pty
.
ReceiptBuyBase
,
txIndex
string
)
*
pty
.
LocalOrder
{
cfg
:=
t
.
GetAPI
()
.
GetConfig
()
order
:=
&
pty
.
LocalOrder
{
order
:=
&
pty
.
LocalOrder
{
AssetSymbol
:
buy
.
TokenSymbol
,
AssetSymbol
:
buy
.
TokenSymbol
,
TxIndex
:
txIndex
,
TxIndex
:
txIndex
,
Owner
:
buy
.
Owner
,
Owner
:
buy
.
Owner
,
AmountPerBoardlot
:
parseOrderAmountFloat
(
buy
.
AmountPerBoardlot
),
AmountPerBoardlot
:
parseOrderAmountFloat
(
buy
.
AmountPerBoardlot
,
cfg
.
GetTokenPrecision
()
),
MinBoardlot
:
buy
.
MinBoardlot
,
MinBoardlot
:
buy
.
MinBoardlot
,
PricePerBoardlot
:
parseOrderPriceFloat
(
buy
.
PricePerBoardlot
),
PricePerBoardlot
:
parseOrderPriceFloat
(
buy
.
PricePerBoardlot
,
cfg
.
GetCoinPrecision
()
),
TotalBoardlot
:
buy
.
TotalBoardlot
,
TotalBoardlot
:
buy
.
TotalBoardlot
,
TradedBoardlot
:
buy
.
BoughtBoardlot
,
TradedBoardlot
:
buy
.
BoughtBoardlot
,
BuyID
:
calcTokenBuyID
(
hex
.
EncodeToString
(
tx
.
Hash
())),
BuyID
:
calcTokenBuyID
(
hex
.
EncodeToString
(
tx
.
Hash
())),
...
...
plugin/dapp/trade/executor/tradedb.go
View file @
100bcc22
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
"encoding/hex"
"encoding/hex"
"errors"
"errors"
"fmt"
"fmt"
"strconv"
"strings"
"strings"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/client"
...
@@ -39,15 +38,15 @@ func (selldb *sellDB) save(db dbm.KV) []*types.KeyValue {
...
@@ -39,15 +38,15 @@ func (selldb *sellDB) save(db dbm.KV) []*types.KeyValue {
return
set
return
set
}
}
func
(
selldb
*
sellDB
)
getSellLogs
(
tradeType
int32
,
txhash
string
)
*
types
.
ReceiptLog
{
func
(
selldb
*
sellDB
)
getSellLogs
(
tradeType
int32
,
txhash
string
,
cfg
*
types
.
Chain33Config
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
tradeType
log
.
Ty
=
tradeType
base
:=
&
pty
.
ReceiptSellBase
{
base
:=
&
pty
.
ReceiptSellBase
{
TokenSymbol
:
selldb
.
TokenSymbol
,
TokenSymbol
:
selldb
.
TokenSymbol
,
Owner
:
selldb
.
Address
,
Owner
:
selldb
.
Address
,
AmountPerBoardlot
:
strconv
.
FormatFloat
(
float64
(
selldb
.
AmountPerBoardlot
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
8
,
64
),
AmountPerBoardlot
:
types
.
FormatAmount2FixPrecisionDisplay
(
selldb
.
AmountPerBoardlot
,
cfg
.
GetTokenPrecision
()
),
MinBoardlot
:
selldb
.
MinBoardlot
,
MinBoardlot
:
selldb
.
MinBoardlot
,
PricePerBoardlot
:
strconv
.
FormatFloat
(
float64
(
selldb
.
PricePerBoardlot
)
/
float64
(
types
.
Coin
),
'f'
,
8
,
64
),
PricePerBoardlot
:
types
.
FormatAmount2FixPrecisionDisplay
(
selldb
.
PricePerBoardlot
,
cfg
.
GetCoinPrecision
()
),
TotalBoardlot
:
selldb
.
TotalBoardlot
,
TotalBoardlot
:
selldb
.
TotalBoardlot
,
SoldBoardlot
:
selldb
.
SoldBoardlot
,
SoldBoardlot
:
selldb
.
SoldBoardlot
,
Starttime
:
selldb
.
Starttime
,
Starttime
:
selldb
.
Starttime
,
...
@@ -74,15 +73,15 @@ func (selldb *sellDB) getSellLogs(tradeType int32, txhash string) *types.Receipt
...
@@ -74,15 +73,15 @@ func (selldb *sellDB) getSellLogs(tradeType int32, txhash string) *types.Receipt
return
log
return
log
}
}
func
(
selldb
*
sellDB
)
getBuyLogs
(
buyerAddr
string
,
boardlotcnt
int64
,
txhash
string
)
*
types
.
ReceiptLog
{
func
(
selldb
*
sellDB
)
getBuyLogs
(
buyerAddr
string
,
boardlotcnt
int64
,
txhash
string
,
cfg
*
types
.
Chain33Config
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogTradeBuyMarket
log
.
Ty
=
pty
.
TyLogTradeBuyMarket
base
:=
&
pty
.
ReceiptBuyBase
{
base
:=
&
pty
.
ReceiptBuyBase
{
TokenSymbol
:
selldb
.
TokenSymbol
,
TokenSymbol
:
selldb
.
TokenSymbol
,
Owner
:
buyerAddr
,
Owner
:
buyerAddr
,
AmountPerBoardlot
:
strconv
.
FormatFloat
(
float64
(
selldb
.
AmountPerBoardlot
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
8
,
64
),
AmountPerBoardlot
:
types
.
FormatAmount2FixPrecisionDisplay
(
selldb
.
AmountPerBoardlot
,
cfg
.
GetTokenPrecision
()
),
MinBoardlot
:
selldb
.
MinBoardlot
,
MinBoardlot
:
selldb
.
MinBoardlot
,
PricePerBoardlot
:
strconv
.
FormatFloat
(
float64
(
selldb
.
PricePerBoardlot
)
/
float64
(
types
.
Coin
),
'f'
,
8
,
64
),
PricePerBoardlot
:
types
.
FormatAmount2FixPrecisionDisplay
(
selldb
.
PricePerBoardlot
,
cfg
.
GetCoinPrecision
()
),
TotalBoardlot
:
boardlotcnt
,
TotalBoardlot
:
boardlotcnt
,
BoughtBoardlot
:
boardlotcnt
,
BoughtBoardlot
:
boardlotcnt
,
BuyID
:
""
,
BuyID
:
""
,
...
@@ -147,15 +146,15 @@ func (buydb *buyDB) getKVSet() (kvset []*types.KeyValue) {
...
@@ -147,15 +146,15 @@ func (buydb *buyDB) getKVSet() (kvset []*types.KeyValue) {
return
kvset
return
kvset
}
}
func
(
buydb
*
buyDB
)
getBuyLogs
(
tradeType
int32
,
txhash
string
)
*
types
.
ReceiptLog
{
func
(
buydb
*
buyDB
)
getBuyLogs
(
tradeType
int32
,
txhash
string
,
cfg
*
types
.
Chain33Config
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
tradeType
log
.
Ty
=
tradeType
base
:=
&
pty
.
ReceiptBuyBase
{
base
:=
&
pty
.
ReceiptBuyBase
{
TokenSymbol
:
buydb
.
TokenSymbol
,
TokenSymbol
:
buydb
.
TokenSymbol
,
Owner
:
buydb
.
Address
,
Owner
:
buydb
.
Address
,
AmountPerBoardlot
:
strconv
.
FormatFloat
(
float64
(
buydb
.
AmountPerBoardlot
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
8
,
64
),
AmountPerBoardlot
:
types
.
FormatAmount2FixPrecisionDisplay
(
buydb
.
AmountPerBoardlot
,
cfg
.
GetTokenPrecision
()
),
MinBoardlot
:
buydb
.
MinBoardlot
,
MinBoardlot
:
buydb
.
MinBoardlot
,
PricePerBoardlot
:
strconv
.
FormatFloat
(
float64
(
buydb
.
PricePerBoardlot
)
/
float64
(
types
.
Coin
),
'f'
,
8
,
64
),
PricePerBoardlot
:
types
.
FormatAmount2FixPrecisionDisplay
(
buydb
.
PricePerBoardlot
,
cfg
.
GetCoinPrecision
()
),
TotalBoardlot
:
buydb
.
TotalBoardlot
,
TotalBoardlot
:
buydb
.
TotalBoardlot
,
BoughtBoardlot
:
buydb
.
BoughtBoardlot
,
BoughtBoardlot
:
buydb
.
BoughtBoardlot
,
BuyID
:
buydb
.
BuyID
,
BuyID
:
buydb
.
BuyID
,
...
@@ -194,15 +193,15 @@ func getBuyOrderFromID(buyID []byte, db dbm.KV) (*pty.BuyLimitOrder, error) {
...
@@ -194,15 +193,15 @@ func getBuyOrderFromID(buyID []byte, db dbm.KV) (*pty.BuyLimitOrder, error) {
return
&
buy
,
nil
return
&
buy
,
nil
}
}
func
(
buydb
*
buyDB
)
getSellLogs
(
sellerAddr
string
,
sellID
string
,
boardlotCnt
int64
,
txhash
string
)
*
types
.
ReceiptLog
{
func
(
buydb
*
buyDB
)
getSellLogs
(
sellerAddr
string
,
sellID
string
,
boardlotCnt
int64
,
txhash
string
,
cfg
*
types
.
Chain33Config
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogTradeSellMarket
log
.
Ty
=
pty
.
TyLogTradeSellMarket
base
:=
&
pty
.
ReceiptSellBase
{
base
:=
&
pty
.
ReceiptSellBase
{
TokenSymbol
:
buydb
.
TokenSymbol
,
TokenSymbol
:
buydb
.
TokenSymbol
,
Owner
:
sellerAddr
,
Owner
:
sellerAddr
,
AmountPerBoardlot
:
strconv
.
FormatFloat
(
float64
(
buydb
.
AmountPerBoardlot
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
8
,
64
),
AmountPerBoardlot
:
types
.
FormatAmount2FixPrecisionDisplay
(
buydb
.
AmountPerBoardlot
,
cfg
.
GetTokenPrecision
()
),
MinBoardlot
:
buydb
.
MinBoardlot
,
MinBoardlot
:
buydb
.
MinBoardlot
,
PricePerBoardlot
:
strconv
.
FormatFloat
(
float64
(
buydb
.
PricePerBoardlot
)
/
float64
(
types
.
Coin
),
'f'
,
8
,
64
),
PricePerBoardlot
:
types
.
FormatAmount2FixPrecisionDisplay
(
buydb
.
PricePerBoardlot
,
cfg
.
GetCoinPrecision
()
),
TotalBoardlot
:
boardlotCnt
,
TotalBoardlot
:
boardlotCnt
,
SoldBoardlot
:
boardlotCnt
,
SoldBoardlot
:
boardlotCnt
,
Starttime
:
0
,
Starttime
:
0
,
...
@@ -292,7 +291,7 @@ func (action *tradeAction) tradeSell(sell *pty.TradeForSell) (*types.Receipt, er
...
@@ -292,7 +291,7 @@ func (action *tradeAction) tradeSell(sell *pty.TradeForSell) (*types.Receipt, er
tokendb
:=
newSellDB
(
sellOrder
)
tokendb
:=
newSellDB
(
sellOrder
)
sellOrderKV
:=
tokendb
.
save
(
action
.
db
)
sellOrderKV
:=
tokendb
.
save
(
action
.
db
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
logs
=
append
(
logs
,
tokendb
.
getSellLogs
(
pty
.
TyLogTradeSellLimit
,
action
.
txhash
))
logs
=
append
(
logs
,
tokendb
.
getSellLogs
(
pty
.
TyLogTradeSellLimit
,
action
.
txhash
,
cfg
))
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
...
@@ -373,8 +372,8 @@ func (action *tradeAction) tradeBuy(buyOrder *pty.TradeForBuy) (*types.Receipt,
...
@@ -373,8 +372,8 @@ func (action *tradeAction) tradeBuy(buyOrder *pty.TradeForBuy) (*types.Receipt,
logs
=
append
(
logs
,
receiptFromAcc
.
Logs
...
)
logs
=
append
(
logs
,
receiptFromAcc
.
Logs
...
)
logs
=
append
(
logs
,
receiptFromExecAcc
.
Logs
...
)
logs
=
append
(
logs
,
receiptFromExecAcc
.
Logs
...
)
logs
=
append
(
logs
,
sellTokendb
.
getSellLogs
(
pty
.
TyLogTradeSellLimit
,
action
.
txhash
))
logs
=
append
(
logs
,
sellTokendb
.
getSellLogs
(
pty
.
TyLogTradeSellLimit
,
action
.
txhash
,
cfg
))
logs
=
append
(
logs
,
sellTokendb
.
getBuyLogs
(
action
.
fromaddr
,
buyOrder
.
BoardlotCnt
,
action
.
txhash
))
logs
=
append
(
logs
,
sellTokendb
.
getBuyLogs
(
action
.
fromaddr
,
buyOrder
.
BoardlotCnt
,
action
.
txhash
,
cfg
))
kv
=
append
(
kv
,
receiptFromAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
...
@@ -425,7 +424,7 @@ func (action *tradeAction) tradeRevokeSell(revoke *pty.TradeForRevokeSell) (*typ
...
@@ -425,7 +424,7 @@ func (action *tradeAction) tradeRevokeSell(revoke *pty.TradeForRevokeSell) (*typ
sellOrderKV
:=
tokendb
.
save
(
action
.
db
)
sellOrderKV
:=
tokendb
.
save
(
action
.
db
)
logs
=
append
(
logs
,
receiptFromExecAcc
.
Logs
...
)
logs
=
append
(
logs
,
receiptFromExecAcc
.
Logs
...
)
logs
=
append
(
logs
,
tokendb
.
getSellLogs
(
pty
.
TyLogTradeSellRevoke
,
action
.
txhash
))
logs
=
append
(
logs
,
tokendb
.
getSellLogs
(
pty
.
TyLogTradeSellRevoke
,
action
.
txhash
,
cfg
))
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
...
@@ -505,7 +504,7 @@ func (action *tradeAction) tradeBuyLimit(buy *pty.TradeForBuyLimit) (*types.Rece
...
@@ -505,7 +504,7 @@ func (action *tradeAction) tradeBuyLimit(buy *pty.TradeForBuyLimit) (*types.Rece
tokendb
:=
newBuyDB
(
buyOrder
)
tokendb
:=
newBuyDB
(
buyOrder
)
buyOrderKV
:=
tokendb
.
save
(
action
.
db
)
buyOrderKV
:=
tokendb
.
save
(
action
.
db
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
logs
=
append
(
logs
,
tokendb
.
getBuyLogs
(
pty
.
TyLogTradeBuyLimit
,
action
.
txhash
))
logs
=
append
(
logs
,
tokendb
.
getBuyLogs
(
pty
.
TyLogTradeBuyLimit
,
action
.
txhash
,
cfg
))
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
buyOrderKV
...
)
kv
=
append
(
kv
,
buyOrderKV
...
)
...
@@ -585,8 +584,8 @@ func (action *tradeAction) tradeSellMarket(sellOrder *pty.TradeForSellMarket) (*
...
@@ -585,8 +584,8 @@ func (action *tradeAction) tradeSellMarket(sellOrder *pty.TradeForSellMarket) (*
logs
=
append
(
logs
,
receiptFromAcc
.
Logs
...
)
logs
=
append
(
logs
,
receiptFromAcc
.
Logs
...
)
logs
=
append
(
logs
,
receiptFromExecAcc
.
Logs
...
)
logs
=
append
(
logs
,
receiptFromExecAcc
.
Logs
...
)
logs
=
append
(
logs
,
buyTokendb
.
getBuyLogs
(
pty
.
TyLogTradeBuyLimit
,
action
.
txhash
))
logs
=
append
(
logs
,
buyTokendb
.
getBuyLogs
(
pty
.
TyLogTradeBuyLimit
,
action
.
txhash
,
cfg
))
logs
=
append
(
logs
,
buyTokendb
.
getSellLogs
(
action
.
fromaddr
,
action
.
txhash
,
sellOrder
.
BoardlotCnt
,
action
.
txhash
))
logs
=
append
(
logs
,
buyTokendb
.
getSellLogs
(
action
.
fromaddr
,
action
.
txhash
,
sellOrder
.
BoardlotCnt
,
action
.
txhash
,
cfg
))
kv
=
append
(
kv
,
receiptFromAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
...
@@ -637,7 +636,7 @@ func (action *tradeAction) tradeRevokeBuyLimit(revoke *pty.TradeForRevokeBuy) (*
...
@@ -637,7 +636,7 @@ func (action *tradeAction) tradeRevokeBuyLimit(revoke *pty.TradeForRevokeBuy) (*
sellOrderKV
:=
tokendb
.
save
(
action
.
db
)
sellOrderKV
:=
tokendb
.
save
(
action
.
db
)
logs
=
append
(
logs
,
receiptFromExecAcc
.
Logs
...
)
logs
=
append
(
logs
,
receiptFromExecAcc
.
Logs
...
)
logs
=
append
(
logs
,
tokendb
.
getBuyLogs
(
pty
.
TyLogTradeBuyRevoke
,
action
.
txhash
))
logs
=
append
(
logs
,
tokendb
.
getBuyLogs
(
pty
.
TyLogTradeBuyRevoke
,
action
.
txhash
,
cfg
))
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
...
...
plugin/dapp/trade/rpc/types.go
View file @
100bcc22
...
@@ -43,7 +43,7 @@ func (jrpc *Jrpc) GetLastMemPool(in types.ReqNil, result *interface{}) error {
...
@@ -43,7 +43,7 @@ func (jrpc *Jrpc) GetLastMemPool(in types.ReqNil, result *interface{}) error {
var
txlist
rpctypes
.
ReplyTxList
var
txlist
rpctypes
.
ReplyTxList
txs
:=
reply
.
GetTxs
()
txs
:=
reply
.
GetTxs
()
for
_
,
tx
:=
range
txs
{
for
_
,
tx
:=
range
txs
{
tran
,
err
:=
rpctypes
.
DecodeTx
(
tx
)
tran
,
err
:=
rpctypes
.
DecodeTx
(
tx
,
jrpc
.
cli
.
GetConfig
()
.
GetCoinPrecision
()
)
if
err
!=
nil
{
if
err
!=
nil
{
continue
continue
}
}
...
...
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