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
60252d13
Commit
60252d13
authored
Nov 26, 2018
by
harrylee2015
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master' into game
parents
e56fb37a
0ac1f080
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
230 additions
and
196 deletions
+230
-196
exec_local.go
plugin/dapp/cert/executor/exec_local.go
+12
-3
query.go
plugin/dapp/game/executor/query.go
+1
-1
exec_del_local.go
plugin/dapp/hashlock/executor/exec_del_local.go
+12
-3
exec_local.go
plugin/dapp/hashlock/executor/exec_local.go
+12
-3
ticket.go
plugin/dapp/ticket/wallet/ticket.go
+8
-1
exec_test.go
plugin/dapp/trade/executor/exec_test.go
+20
-20
kv.go
plugin/dapp/trade/executor/kv.go
+20
-20
trade_test.go
plugin/dapp/trade/executor/trade_test.go
+42
-42
tradedb.go
plugin/dapp/trade/executor/tradedb.go
+98
-98
rpc.go
plugin/dapp/trade/rpc/rpc.go
+5
-5
No files found.
plugin/dapp/cert/executor/exec_local.go
100644 → 100755
View file @
60252d13
...
...
@@ -17,11 +17,14 @@ func calcCertHeightKey(height int64) []byte {
}
// ExecLocal_New 启用证书交易执行
func
(
c
*
Cert
)
ExecLocal_New
(
payload
*
ct
.
CertNew
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
c
*
Cert
)
ExecLocal_New
(
payload
*
ct
.
CertNew
,
tx
*
types
.
Transaction
,
receiptData
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
!
authority
.
IsAuthEnable
{
clog
.
Error
(
"Authority is not available. Please check the authority config or authority initialize error logs."
)
return
nil
,
ct
.
ErrInitializeAuthority
}
if
receiptData
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
var
set
types
.
LocalDBSet
historityCertdata
:=
&
types
.
HistoryCertStore
{}
...
...
@@ -46,11 +49,14 @@ func (c *Cert) ExecLocal_New(payload *ct.CertNew, tx *types.Transaction, receipt
}
// ExecLocal_Update 更新证书交易执行
func
(
c
*
Cert
)
ExecLocal_Update
(
payload
*
ct
.
CertUpdate
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
c
*
Cert
)
ExecLocal_Update
(
payload
*
ct
.
CertUpdate
,
tx
*
types
.
Transaction
,
receiptData
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
!
authority
.
IsAuthEnable
{
clog
.
Error
(
"Authority is not available. Please check the authority config or authority initialize error logs."
)
return
nil
,
ct
.
ErrInitializeAuthority
}
if
receiptData
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
var
set
types
.
LocalDBSet
// 写入上一纪录的next-height
...
...
@@ -76,11 +82,14 @@ func (c *Cert) ExecLocal_Update(payload *ct.CertUpdate, tx *types.Transaction, r
}
// ExecLocal_Normal 非证书变更交易执行
func
(
c
*
Cert
)
ExecLocal_Normal
(
payload
*
ct
.
CertNormal
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
c
*
Cert
)
ExecLocal_Normal
(
payload
*
ct
.
CertNormal
,
tx
*
types
.
Transaction
,
receiptData
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
!
authority
.
IsAuthEnable
{
clog
.
Error
(
"Authority is not available. Please check the authority config or authority initialize error logs."
)
return
nil
,
ct
.
ErrInitializeAuthority
}
if
receiptData
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
var
set
types
.
LocalDBSet
return
&
set
,
nil
...
...
plugin/dapp/game/executor/query.go
View file @
60252d13
...
...
@@ -30,5 +30,5 @@ func (g *Game) Query_QueryGameById(in *gt.QueryGameInfo) (types.Message, error)
if
err
!=
nil
{
return
nil
,
err
}
return
&
gt
.
ReplyGame
{
game
},
nil
return
&
gt
.
ReplyGame
{
Game
:
game
},
nil
}
plugin/dapp/hashlock/executor/exec_del_local.go
View file @
60252d13
...
...
@@ -11,7 +11,10 @@ import (
)
// ExecDelLocal_Hlock Action
func
(
h
*
Hashlock
)
ExecDelLocal_Hlock
(
hlock
*
pty
.
HashlockLock
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
h
*
Hashlock
)
ExecDelLocal_Hlock
(
hlock
*
pty
.
HashlockLock
,
tx
*
types
.
Transaction
,
receipt
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
info
:=
pty
.
Hashlockquery
{
Time
:
hlock
.
Time
,
Status
:
hashlockLocked
,
Amount
:
hlock
.
Amount
,
CreateTime
:
h
.
GetBlockTime
(),
CurrentTime
:
0
}
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
hlock
.
Hash
,
info
)
if
err
!=
nil
{
...
...
@@ -21,7 +24,10 @@ func (h *Hashlock) ExecDelLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transac
}
// ExecDelLocal_Hsend Action
func
(
h
*
Hashlock
)
ExecDelLocal_Hsend
(
hsend
*
pty
.
HashlockSend
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
h
*
Hashlock
)
ExecDelLocal_Hsend
(
hsend
*
pty
.
HashlockSend
,
tx
*
types
.
Transaction
,
receipt
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
info
:=
pty
.
Hashlockquery
{
Time
:
0
,
Status
:
hashlockSent
,
Amount
:
0
,
CreateTime
:
0
,
CurrentTime
:
0
}
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hsend
.
Secret
),
info
)
if
err
!=
nil
{
...
...
@@ -31,7 +37,10 @@ func (h *Hashlock) ExecDelLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transac
}
// ExecDelLocal_Hunlock Action
func
(
h
*
Hashlock
)
ExecDelLocal_Hunlock
(
hunlock
*
pty
.
HashlockUnlock
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
h
*
Hashlock
)
ExecDelLocal_Hunlock
(
hunlock
*
pty
.
HashlockUnlock
,
tx
*
types
.
Transaction
,
receipt
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
info
:=
pty
.
Hashlockquery
{
Time
:
0
,
Status
:
hashlockUnlocked
,
Amount
:
0
,
CreateTime
:
0
,
CurrentTime
:
0
}
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hunlock
.
Secret
),
info
)
if
err
!=
nil
{
...
...
plugin/dapp/hashlock/executor/exec_local.go
View file @
60252d13
...
...
@@ -11,7 +11,10 @@ import (
)
// ExecLocal_Hlock Action
func
(
h
*
Hashlock
)
ExecLocal_Hlock
(
hlock
*
pty
.
HashlockLock
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
h
*
Hashlock
)
ExecLocal_Hlock
(
hlock
*
pty
.
HashlockLock
,
tx
*
types
.
Transaction
,
receipt
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
info
:=
pty
.
Hashlockquery
{
Time
:
hlock
.
Time
,
Status
:
hashlockLocked
,
Amount
:
hlock
.
Amount
,
CreateTime
:
h
.
GetBlockTime
(),
CurrentTime
:
0
}
clog
.
Error
(
"ExecLocal"
,
"info"
,
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
hlock
.
Hash
,
info
)
...
...
@@ -22,7 +25,10 @@ func (h *Hashlock) ExecLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transactio
}
// ExecLocal_Hsend Action
func
(
h
*
Hashlock
)
ExecLocal_Hsend
(
hsend
*
pty
.
HashlockSend
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
h
*
Hashlock
)
ExecLocal_Hsend
(
hsend
*
pty
.
HashlockSend
,
tx
*
types
.
Transaction
,
receipt
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
info
:=
pty
.
Hashlockquery
{
Time
:
0
,
Status
:
hashlockSent
,
Amount
:
0
,
CreateTime
:
0
,
CurrentTime
:
0
}
clog
.
Error
(
"ExecLocal"
,
"info"
,
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hsend
.
Secret
),
info
)
...
...
@@ -33,7 +39,10 @@ func (h *Hashlock) ExecLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transactio
}
// ExecLocal_Hunlock Action
func
(
h
*
Hashlock
)
ExecLocal_Hunlock
(
hunlock
*
pty
.
HashlockUnlock
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
h
*
Hashlock
)
ExecLocal_Hunlock
(
hunlock
*
pty
.
HashlockUnlock
,
tx
*
types
.
Transaction
,
receipt
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
info
:=
pty
.
Hashlockquery
{
Time
:
0
,
Status
:
hashlockUnlocked
,
Amount
:
0
,
CreateTime
:
0
,
CurrentTime
:
0
}
clog
.
Error
(
"ExecLocal"
,
"info"
,
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hunlock
.
Secret
),
info
)
...
...
plugin/dapp/ticket/wallet/ticket.go
View file @
60252d13
...
...
@@ -5,6 +5,7 @@
package
wallet
import
(
"encoding/hex"
"fmt"
"sync"
"sync/atomic"
...
...
@@ -611,17 +612,20 @@ func (policy *ticketPolicy) buyTicket(height int64) ([][]byte, int, error) {
}
count
:=
0
var
hashes
[][]
byte
bizlog
.
Debug
(
"ticketPolicy buyTicket begin"
)
for
_
,
priv
:=
range
privs
{
hash
,
n
,
err
:=
policy
.
buyTicketOne
(
height
,
priv
)
if
err
!=
nil
{
bizlog
.
Error
(
"buyTicketOne"
,
"err"
,
err
)
bizlog
.
Error
(
"
ticketPolicy buyTicket
buyTicketOne"
,
"err"
,
err
)
continue
}
count
+=
n
if
hash
!=
nil
{
hashes
=
append
(
hashes
,
hash
)
}
bizlog
.
Debug
(
"ticketPolicy buyTicket"
,
"Address"
,
address
.
PubKeyToAddress
(
priv
.
PubKey
()
.
Bytes
())
.
String
(),
"txhash"
,
hex
.
EncodeToString
(
hash
),
"n"
,
n
)
}
bizlog
.
Debug
(
"ticketPolicy buyTicket end"
)
return
hashes
,
count
,
nil
}
...
...
@@ -705,6 +709,7 @@ func (policy *ticketPolicy) buyMinerAddrTicket(height int64) ([][]byte, int, err
}
count
:=
0
var
hashes
[][]
byte
bizlog
.
Debug
(
"ticketPolicy buyMinerAddrTicket begin"
)
for
_
,
priv
:=
range
privs
{
hashlist
,
n
,
err
:=
policy
.
buyMinerAddrTicketOne
(
height
,
priv
)
if
err
!=
nil
{
...
...
@@ -717,7 +722,9 @@ func (policy *ticketPolicy) buyMinerAddrTicket(height int64) ([][]byte, int, err
if
hashlist
!=
nil
{
hashes
=
append
(
hashes
,
hashlist
...
)
}
bizlog
.
Debug
(
"ticketPolicy buyMinerAddrTicket"
,
"Address"
,
address
.
PubKeyToAddress
(
priv
.
PubKey
()
.
Bytes
())
.
String
(),
"n"
,
n
)
}
bizlog
.
Debug
(
"ticketPolicy buyMinerAddrTicket end"
)
return
hashes
,
count
,
nil
}
...
...
plugin/dapp/trade/executor/exec_test.go
View file @
60252d13
...
...
@@ -88,13 +88,13 @@ func TestTrade_Exec_SellLimit(t *testing.T) {
driver
.
SetStateDB
(
stateDB
)
sell
:=
&
pty
.
TradeSellTx
{
Symbol
,
sellArgs
.
amount
,
sellArgs
.
min
,
sellArgs
.
price
,
sellArgs
.
total
,
0
,
AssetExecToken
,
TokenSymbol
:
Symbol
,
AmountPerBoardlot
:
sellArgs
.
amount
,
MinBoardlot
:
sellArgs
.
min
,
PricePerBoardlot
:
sellArgs
.
price
,
TotalBoardlot
:
sellArgs
.
total
,
Fee
:
0
,
AssetExec
:
AssetExec
Token
,
}
tx
,
_
:=
pty
.
CreateRawTradeSellTx
(
sell
)
tx
,
_
=
signTx
(
tx
,
PrivKeyA
)
...
...
@@ -125,9 +125,9 @@ func TestTrade_Exec_SellLimit(t *testing.T) {
assert
.
Equal
(
t
,
string
(
Nodes
[
0
]),
sellOrder
.
Address
)
buy
:=
&
pty
.
TradeBuyTx
{
sellOrder
.
SellID
,
buyArgs
.
total
,
0
,
SellID
:
sellOrder
.
SellID
,
BoardlotCnt
:
buyArgs
.
total
,
Fee
:
0
,
}
tx
,
_
=
pty
.
CreateRawTradeBuyTx
(
buy
)
tx
,
_
=
signTx
(
tx
,
PrivKeyB
)
...
...
@@ -197,13 +197,13 @@ func TestTrade_Exec_BuyLimit(t *testing.T) {
driver
.
SetStateDB
(
stateDB
)
buy
:=
&
pty
.
TradeBuyLimitTx
{
Symbol
,
buyArgs
.
amount
,
buyArgs
.
min
,
buyArgs
.
price
,
buyArgs
.
total
,
0
,
AssetExecPara
,
TokenSymbol
:
Symbol
,
AmountPerBoardlot
:
buyArgs
.
amount
,
MinBoardlot
:
buyArgs
.
min
,
PricePerBoardlot
:
buyArgs
.
price
,
TotalBoardlot
:
buyArgs
.
total
,
Fee
:
0
,
AssetExec
:
AssetExec
Para
,
}
tx
,
_
:=
pty
.
CreateRawTradeBuyLimitTx
(
buy
)
tx
,
_
=
signTx
(
tx
,
PrivKeyB
)
...
...
@@ -234,9 +234,9 @@ func TestTrade_Exec_BuyLimit(t *testing.T) {
assert
.
Equal
(
t
,
string
(
Nodes
[
1
]),
buyLimitOrder
.
Address
)
sell
:=
&
pty
.
TradeSellMarketTx
{
buyLimitOrder
.
BuyID
,
sellArgs
.
total
,
0
,
BuyID
:
buyLimitOrder
.
BuyID
,
BoardlotCnt
:
sellArgs
.
total
,
Fee
:
0
,
}
tx
,
_
=
pty
.
CreateRawTradeSellMarketTx
(
sell
)
tx
,
_
=
signTx
(
tx
,
PrivKeyA
)
...
...
plugin/dapp/trade/executor/kv.go
View file @
60252d13
...
...
@@ -158,13 +158,13 @@ func genBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBase
keyID
:=
receipt
.
TxHash
newkey
:=
calcTokenBuyOrderKey
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
,
height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyToken
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
priceBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
PricePerBoardlot
,
64
)
if
err
!=
nil
{
...
...
@@ -180,11 +180,11 @@ func genBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBase
newkey
=
calcTokensBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
price
,
receipt
.
Owner
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
receipt
.
Owner
,
st
,
ty
,
height
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
...
...
@@ -195,13 +195,13 @@ func genSellMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptSellBa
keyID
:=
receipt
.
TxHash
newkey
:=
calcTokenSellOrderKey
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
,
height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyStatus
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyToken
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
priceBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
PricePerBoardlot
,
64
)
if
err
!=
nil
{
...
...
@@ -217,11 +217,11 @@ func genSellMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptSellBa
newkey
=
calcTokensSellOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
price
,
receipt
.
Owner
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
receipt
.
Owner
,
st
,
ty
,
height
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
...
...
@@ -235,42 +235,42 @@ func calcPriceOfToken(priceBoardlot, AmountPerBoardlot int64) int64 {
func
genBuyLimitOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
buyOrder
*
pty
.
BuyLimitOrder
,
status
int32
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
newkey
:=
calcTokenBuyOrderKey
(
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
status
,
buyOrder
.
BuyID
,
buyOrder
.
Height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyStatus
(
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
status
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyToken
(
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
status
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcTokensBuyOrderKeyStatus
(
buyOrder
.
TokenSymbol
,
status
,
calcPriceOfToken
(
buyOrder
.
PricePerBoardlot
,
buyOrder
.
AmountPerBoardlot
),
buyOrder
.
Address
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
buyOrder
.
Address
,
st
,
ty
,
buyOrder
.
Height
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
func
genSellOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
sellorder
*
pty
.
SellOrder
,
status
int32
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
newkey
:=
calcTokenSellOrderKey
(
sellorder
.
TokenSymbol
,
sellorder
.
Address
,
status
,
sellorder
.
SellID
,
sellorder
.
Height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyStatus
(
sellorder
.
TokenSymbol
,
sellorder
.
Address
,
status
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyToken
(
sellorder
.
TokenSymbol
,
sellorder
.
Address
,
status
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcTokensSellOrderKeyStatus
(
sellorder
.
TokenSymbol
,
status
,
calcPriceOfToken
(
sellorder
.
PricePerBoardlot
,
sellorder
.
AmountPerBoardlot
),
sellorder
.
Address
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
sellorder
.
Address
,
st
,
ty
,
sellorder
.
Height
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
plugin/dapp/trade/executor/trade_test.go
View file @
60252d13
...
...
@@ -15,54 +15,54 @@ import (
var
(
sellorderOnsale
=
pty
.
SellOrder
{
"Tokensymbol"
,
"Address"
,
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
2
,
// Minboardlot int64 `protobuf:"varint,4,opt,name=minboardlot" json:"minboardlot,omitempty"`
1
*
1e8
,
//Priceperboardlot int64 `protobuf:"varint,5,opt,name=priceperboardlot" json:"priceperboardlot,omitempty"`
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
pty
.
TradeOrderStatusOnSale
,
//Status int32 `protobuf:"varint,12,opt,name=status" json:"status,omitempty"`
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
"token"
,
TokenSymbol
:
"Tokensymbol"
,
Address
:
"Address"
,
AmountPerBoardlot
:
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
MinBoardlot
:
2
,
// Minboardlot int64 `protobuf:"varint,4,opt,name=minboardlot" json:"minboardlot,omitempty"`
PricePerBoardlot
:
1
*
1e8
,
//Priceperboardlot int64 `protobuf:"varint,5,opt,name=priceperboardlot" json:"priceperboardlot,omitempty"`
TotalBoardlot
:
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
SoldBoardlot
:
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
Starttime
:
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
Stoptime
:
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
Crowdfund
:
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
SellID
:
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
Status
:
pty
.
TradeOrderStatusOnSale
,
//Status int32 `protobuf:"varint,12,opt,name=status" json:"status,omitempty"`
Height
:
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
AssetExec
:
"token"
,
}
sellorderSoldOut
=
pty
.
SellOrder
{
"Tokensymbol"
,
"Address"
,
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
2
,
// Minboardlot int64 `protobuf:"varint,4,opt,name=minboardlot" json:"minboardlot,omitempty"`
1
*
1e8
,
//Priceperboardlot int64 `protobuf:"varint,5,opt,name=priceperboardlot" json:"priceperboardlot,omitempty"`
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
pty
.
TradeOrderStatusSoldOut
,
//Status int32 `protobuf:"varint,12,opt,name=status" json:"status,omitempty"`
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
"token"
,
TokenSymbol
:
"Tokensymbol"
,
Address
:
"Address"
,
AmountPerBoardlot
:
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
MinBoardlot
:
2
,
// Minboardlot int64 `protobuf:"varint,4,opt,name=minboardlot" json:"minboardlot,omitempty"`
PricePerBoardlot
:
1
*
1e8
,
//Priceperboardlot int64 `protobuf:"varint,5,opt,name=priceperboardlot" json:"priceperboardlot,omitempty"`
TotalBoardlot
:
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
SoldBoardlot
:
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
Starttime
:
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
Stoptime
:
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
Crowdfund
:
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
SellID
:
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
Status
:
pty
.
TradeOrderStatusSoldOut
,
//Status int32 `protobuf:"varint,12,opt,name=status" json:"status,omitempty"`
Height
:
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
AssetExec
:
"token"
,
}
sellorderRevoked
=
pty
.
SellOrder
{
"Tokensymbol"
,
"Address"
,
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
2
,
// Minboardlot int64 `protobuf:"varint,4,opt,name=minboardlot" json:"minboardlot,omitempty"`
1
*
1e8
,
//Priceperboardlot int64 `protobuf:"varint,5,opt,name=priceperboardlot" json:"priceperboardlot,omitempty"`
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
pty
.
TradeOrderStatusRevoked
,
//Status int32 `protobuf:"varint,12,opt,name=status" json:"status,omitempty"`
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
"token"
,
TokenSymbol
:
"Tokensymbol"
,
Address
:
"Address"
,
AmountPerBoardlot
:
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
MinBoardlot
:
2
,
// Minboardlot int64 `protobuf:"varint,4,opt,name=minboardlot" json:"minboardlot,omitempty"`
PricePerBoardlot
:
1
*
1e8
,
//Priceperboardlot int64 `protobuf:"varint,5,opt,name=priceperboardlot" json:"priceperboardlot,omitempty"`
TotalBoardlot
:
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
SoldBoardlot
:
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
Starttime
:
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
Stoptime
:
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
Crowdfund
:
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
SellID
:
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
Status
:
pty
.
TradeOrderStatusRevoked
,
//Status int32 `protobuf:"varint,12,opt,name=status" json:"status,omitempty"`
Height
:
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
AssetExec
:
"token"
,
}
)
...
...
plugin/dapp/trade/executor/tradedb.go
View file @
60252d13
This diff is collapsed.
Click to expand it.
plugin/dapp/trade/rpc/rpc.go
View file @
60252d13
...
...
@@ -35,7 +35,7 @@ func (cc *channelClient) CreateRawTradeBuyTx(ctx context.Context, in *ptypes.Tra
}
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeBuyMarket
,
Value
:
&
ptypes
.
Trade_BuyMarket
{
in
},
Value
:
&
ptypes
.
Trade_BuyMarket
{
BuyMarket
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
...
...
@@ -52,7 +52,7 @@ func (cc *channelClient) CreateRawTradeRevokeTx(ctx context.Context, in *ptypes.
}
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeRevokeSell
,
Value
:
&
ptypes
.
Trade_RevokeSell
{
in
},
Value
:
&
ptypes
.
Trade_RevokeSell
{
RevokeSell
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
...
...
@@ -69,7 +69,7 @@ func (cc *channelClient) CreateRawTradeBuyLimitTx(ctx context.Context, in *ptype
}
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeBuyLimit
,
Value
:
&
ptypes
.
Trade_BuyLimit
{
in
},
Value
:
&
ptypes
.
Trade_BuyLimit
{
BuyLimit
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
...
...
@@ -86,7 +86,7 @@ func (cc *channelClient) CreateRawTradeSellMarketTx(ctx context.Context, in *pty
}
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeSellMarket
,
Value
:
&
ptypes
.
Trade_SellMarket
{
in
},
Value
:
&
ptypes
.
Trade_SellMarket
{
SellMarket
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
...
...
@@ -103,7 +103,7 @@ func (cc *channelClient) CreateRawTradeRevokeBuyTx(ctx context.Context, in *ptyp
}
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeRevokeBuy
,
Value
:
&
ptypes
.
Trade_RevokeBuy
{
in
},
Value
:
&
ptypes
.
Trade_RevokeBuy
{
RevokeBuy
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
...
...
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