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
52f1e829
Commit
52f1e829
authored
Feb 06, 2020
by
mdj33
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
relay multi coins support
parent
98d25c0a
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
145 additions
and
173 deletions
+145
-173
build.sh
plugin/dapp/relay/cmd/build.sh
+8
-8
testcase.sh
plugin/dapp/relay/cmd/build/testcase.sh
+0
-0
relayd.toml
plugin/dapp/relay/cmd/relayd/relayd.toml
+2
-2
relayd.go
plugin/dapp/relay/cmd/relayd/relayd/relayd.go
+1
-1
relay.go
plugin/dapp/relay/commands/relay.go
+13
-13
types.go
plugin/dapp/relay/commands/types.go
+3
-1
kv.go
plugin/dapp/relay/executor/kv.go
+13
-5
relay.go
plugin/dapp/relay/executor/relay.go
+5
-1
relay_test.go
plugin/dapp/relay/executor/relay_test.go
+11
-11
relaybtc.go
plugin/dapp/relay/executor/relaybtc.go
+2
-2
relaybtc_test.go
plugin/dapp/relay/executor/relaybtc_test.go
+2
-2
relaydb.go
plugin/dapp/relay/executor/relaydb.go
+0
-0
relaydb_test.go
plugin/dapp/relay/executor/relaydb_test.go
+55
-97
relay.proto
plugin/dapp/relay/proto/relay.proto
+29
-23
relay.go
plugin/dapp/relay/types/relay.go
+1
-7
No files found.
plugin/dapp/relay/cmd/build.sh
View file @
52f1e829
...
@@ -4,14 +4,14 @@ strpwd=$(pwd)
...
@@ -4,14 +4,14 @@ strpwd=$(pwd)
strcmd
=
${
strpwd
##*dapp/
}
strcmd
=
${
strpwd
##*dapp/
}
strapp
=
${
strcmd
%/cmd*
}
strapp
=
${
strcmd
%/cmd*
}
#
OUT_DIR="${1}/$strapp"
OUT_DIR
=
"
${
1
}
/
$strapp
"
#
SRC_RELAYD=github.com/33cn/plugin/plugin/dapp/relay/cmd/relayd
SRC_RELAYD
=
github.com/33cn/plugin/plugin/dapp/relay/cmd/relayd
#
FLAG=$2
FLAG
=
$2
#
#
#
shellcheck disable=SC2086,1072
# shellcheck disable=SC2086,1072
#
go build -i ${FLAG} -v -o "${OUT_DIR}/relayd" "${SRC_RELAYD}"
go build
-i
${
FLAG
}
-v
-o
"
${
OUT_DIR
}
/relayd"
"
${
SRC_RELAYD
}
"
#
cp ./relayd/relayd.toml "${OUT_DIR}/relayd.toml"
cp
./relayd/relayd.toml
"
${
OUT_DIR
}
/relayd.toml"
#
cp ./build/* "${OUT_DIR}"
cp
./build/
*
"
${
OUT_DIR
}
"
OUT_TESTDIR
=
"
${
1
}
/dapptest/
$strapp
"
OUT_TESTDIR
=
"
${
1
}
/dapptest/
$strapp
"
mkdir
-p
"
${
OUT_TESTDIR
}
"
mkdir
-p
"
${
OUT_TESTDIR
}
"
...
...
plugin/dapp/relay/cmd/build/testcase.sh
View file @
52f1e829
This diff is collapsed.
Click to expand it.
plugin/dapp/relay/cmd/relayd/relayd.toml
View file @
52f1e829
...
@@ -10,8 +10,8 @@ syncSetup = 100
...
@@ -10,8 +10,8 @@ syncSetup = 100
syncSetupCount
=
10
syncSetupCount
=
10
[auth]
[auth]
# test private key
# test private key
1G5Cjy8LuQex2fuYv3gzb7B8MxAnxLEqt3
privateKey
=
"
4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01
"
privateKey
=
"
22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962
"
publicKey
=
""
publicKey
=
""
address
=
""
address
=
""
...
...
plugin/dapp/relay/cmd/relayd/relayd/relayd.go
View file @
52f1e829
...
@@ -344,7 +344,7 @@ func (r *Relayd) dealOrder() {
...
@@ -344,7 +344,7 @@ func (r *Relayd) dealOrder() {
for
_
,
value
:=
range
result
.
GetOrders
()
{
for
_
,
value
:=
range
result
.
GetOrders
()
{
// TODO save db ???
// TODO save db ???
tx
,
err
:=
r
.
btcClient
.
GetTransaction
(
value
.
Coin
TxHash
)
tx
,
err
:=
r
.
btcClient
.
GetTransaction
(
value
.
X
TxHash
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"dealOrder"
,
"dealOrder GetTransaction error: "
,
err
)
log
.
Error
(
"dealOrder"
,
"dealOrder GetTransaction error: "
,
err
)
continue
continue
...
...
plugin/dapp/relay/commands/relay.go
View file @
52f1e829
...
@@ -302,12 +302,12 @@ func parseRelayOrders(res ty.ReplyRelayOrders) {
...
@@ -302,12 +302,12 @@ func parseRelayOrders(res ty.ReplyRelayOrders) {
show
.
OrderID
=
order
.
Id
show
.
OrderID
=
order
.
Id
show
.
Status
=
order
.
Status
.
String
()
show
.
Status
=
order
.
Status
.
String
()
show
.
Creator
=
order
.
CreaterAddr
show
.
Creator
=
order
.
CreaterAddr
show
.
CoinOperation
=
ty
.
RelayOrderOperation
[
order
.
CoinOperation
]
show
.
CoinOperation
=
order
.
Operation
show
.
Amount
=
strconv
.
FormatFloat
(
float64
(
order
.
Amount
)
/
float64
(
types
.
Coin
),
'f'
,
4
,
64
)
show
.
Amount
=
strconv
.
FormatFloat
(
float64
(
order
.
LocalCoin
Amount
)
/
float64
(
types
.
Coin
),
'f'
,
4
,
64
)
show
.
Coin
=
order
.
Coin
show
.
Coin
=
order
.
X
Coin
show
.
CoinAddr
=
order
.
Coin
Addr
show
.
CoinAddr
=
order
.
X
Addr
show
.
CoinAmount
=
strconv
.
FormatFloat
(
float64
(
order
.
Coin
Amount
)
/
float64
(
types
.
Coin
),
'f'
,
4
,
64
)
show
.
CoinAmount
=
strconv
.
FormatFloat
(
float64
(
order
.
X
Amount
)
/
float64
(
types
.
Coin
),
'f'
,
4
,
64
)
show
.
CoinWaits
=
order
.
Coin
Waits
show
.
CoinWaits
=
order
.
XBlock
Waits
show
.
CreateTime
=
order
.
CreateTime
show
.
CreateTime
=
order
.
CreateTime
show
.
AcceptAddr
=
order
.
AcceptAddr
show
.
AcceptAddr
=
order
.
AcceptAddr
show
.
AcceptTime
=
order
.
AcceptTime
show
.
AcceptTime
=
order
.
AcceptTime
...
@@ -389,11 +389,11 @@ func relayOrder(cmd *cobra.Command, args []string) {
...
@@ -389,11 +389,11 @@ func relayOrder(cmd *cobra.Command, args []string) {
params
:=
&
ty
.
RelayCreate
{
params
:=
&
ty
.
RelayCreate
{
Operation
:
oper
,
Operation
:
oper
,
Amount
:
coinUInt64
*
1e4
,
XAmount
:
coinUInt64
*
1e4
,
Coin
:
coin
,
XCoin
:
coin
,
Addr
:
coinaddr
,
XAddr
:
coinaddr
,
CoinWaits
:
coinwait
,
XBlockWaits
:
coinwait
,
Bty
Amount
:
btyUInt64
*
1e4
,
LocalCoin
Amount
:
btyUInt64
*
1e4
,
}
}
var
res
string
var
res
string
...
@@ -435,8 +435,8 @@ func relayAccept(cmd *cobra.Command, args []string) {
...
@@ -435,8 +435,8 @@ func relayAccept(cmd *cobra.Command, args []string) {
params
:=
&
ty
.
RelayAccept
{
params
:=
&
ty
.
RelayAccept
{
OrderId
:
orderID
,
OrderId
:
orderID
,
CoinAddr
:
coinaddr
,
XAddr
:
coinaddr
,
Coin
Waits
:
coinwait
,
XBlock
Waits
:
coinwait
,
}
}
var
res
string
var
res
string
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"relay.CreateRawRelayAcceptTx"
,
params
,
&
res
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"relay.CreateRawRelayAcceptTx"
,
params
,
&
res
)
...
...
plugin/dapp/relay/commands/types.go
View file @
52f1e829
...
@@ -9,7 +9,7 @@ type relayOrder2Show struct {
...
@@ -9,7 +9,7 @@ type relayOrder2Show struct {
Status
string
`json:"status"`
Status
string
`json:"status"`
Creator
string
`json:"address"`
Creator
string
`json:"address"`
Amount
string
`json:"amount"`
Amount
string
`json:"amount"`
CoinOperation
string
`json:"coinoperation"`
CoinOperation
uint32
`json:"coinoperation"`
Coin
string
`json:"coin"`
Coin
string
`json:"coin"`
CoinAmount
string
`json:"coinamount"`
CoinAmount
string
`json:"coinamount"`
CoinAddr
string
`json:"coinaddr"`
CoinAddr
string
`json:"coinaddr"`
...
@@ -21,4 +21,6 @@ type relayOrder2Show struct {
...
@@ -21,4 +21,6 @@ type relayOrder2Show struct {
FinishTime
int64
`json:"finishtime"`
FinishTime
int64
`json:"finishtime"`
FinishTxHash
string
`json:"finishtxhash"`
FinishTxHash
string
`json:"finishtxhash"`
Height
int64
`json:"height"`
Height
int64
`json:"height"`
LocalCoinExec
string
`json:"localCoinExec"`
LocalCoinSym
string
`json:"localCoinSym"`
}
}
plugin/dapp/relay/executor/kv.go
View file @
52f1e829
...
@@ -7,6 +7,8 @@ package executor
...
@@ -7,6 +7,8 @@ package executor
import
(
import
(
"fmt"
"fmt"
"strings"
ty
"github.com/33cn/plugin/plugin/dapp/relay/types"
ty
"github.com/33cn/plugin/plugin/dapp/relay/types"
)
)
...
@@ -46,25 +48,25 @@ func calcBtcHeaderKeyHeightList(height int64) []byte {
...
@@ -46,25 +48,25 @@ func calcBtcHeaderKeyHeightList(height int64) []byte {
func
calcOrderKeyStatus
(
order
*
ty
.
RelayOrder
,
status
int32
)
[]
byte
{
func
calcOrderKeyStatus
(
order
*
ty
.
RelayOrder
,
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
relayOrderSCAIH
+
"%d:%s:%s:%s:%d"
,
key
:=
fmt
.
Sprintf
(
relayOrderSCAIH
+
"%d:%s:%s:%s:%d"
,
status
,
order
.
Coin
,
order
.
CreaterAddr
,
order
.
Id
,
order
.
Height
)
status
,
order
.
X
Coin
,
order
.
CreaterAddr
,
order
.
Id
,
order
.
Height
)
return
[]
byte
(
key
)
return
[]
byte
(
key
)
}
}
func
calcOrderKeyCoin
(
order
*
ty
.
RelayOrder
,
status
int32
)
[]
byte
{
func
calcOrderKeyCoin
(
order
*
ty
.
RelayOrder
,
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
relayOrderCSAIH
+
"%s:%d:%s:%s:%d"
,
key
:=
fmt
.
Sprintf
(
relayOrderCSAIH
+
"%s:%d:%s:%s:%d"
,
order
.
Coin
,
status
,
order
.
CreaterAddr
,
order
.
Id
,
order
.
Height
)
order
.
X
Coin
,
status
,
order
.
CreaterAddr
,
order
.
Id
,
order
.
Height
)
return
[]
byte
(
key
)
return
[]
byte
(
key
)
}
}
func
calcOrderKeyAddrStatus
(
order
*
ty
.
RelayOrder
,
status
int32
)
[]
byte
{
func
calcOrderKeyAddrStatus
(
order
*
ty
.
RelayOrder
,
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
relayOrderASCIH
+
"%s:%d:%s:%s:%d"
,
key
:=
fmt
.
Sprintf
(
relayOrderASCIH
+
"%s:%d:%s:%s:%d"
,
order
.
CreaterAddr
,
status
,
order
.
Coin
,
order
.
Id
,
order
.
Height
)
order
.
CreaterAddr
,
status
,
order
.
X
Coin
,
order
.
Id
,
order
.
Height
)
return
[]
byte
(
key
)
return
[]
byte
(
key
)
}
}
func
calcOrderKeyAddrCoin
(
order
*
ty
.
RelayOrder
,
status
int32
)
[]
byte
{
func
calcOrderKeyAddrCoin
(
order
*
ty
.
RelayOrder
,
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
relayOrderACSIH
+
"%s:%s:%d:%s:%d"
,
key
:=
fmt
.
Sprintf
(
relayOrderACSIH
+
"%s:%s:%d:%s:%d"
,
order
.
CreaterAddr
,
order
.
Coin
,
status
,
order
.
Id
,
order
.
Height
)
order
.
CreaterAddr
,
order
.
X
Coin
,
status
,
order
.
Id
,
order
.
Height
)
return
[]
byte
(
key
)
return
[]
byte
(
key
)
}
}
...
@@ -90,7 +92,7 @@ func calcOrderPrefixAddr(addr string) []byte {
...
@@ -90,7 +92,7 @@ func calcOrderPrefixAddr(addr string) []byte {
func
calcAcceptKeyAddr
(
order
*
ty
.
RelayOrder
,
status
int32
)
[]
byte
{
func
calcAcceptKeyAddr
(
order
*
ty
.
RelayOrder
,
status
int32
)
[]
byte
{
if
order
.
AcceptAddr
!=
""
{
if
order
.
AcceptAddr
!=
""
{
return
[]
byte
(
fmt
.
Sprintf
(
relayBuyOrderACSIH
+
"%s:%s:%d:%s:%d"
,
return
[]
byte
(
fmt
.
Sprintf
(
relayBuyOrderACSIH
+
"%s:%s:%d:%s:%d"
,
order
.
AcceptAddr
,
order
.
Coin
,
status
,
order
.
Id
,
order
.
Height
))
order
.
AcceptAddr
,
order
.
X
Coin
,
status
,
order
.
Id
,
order
.
Height
))
}
}
return
nil
return
nil
...
@@ -111,3 +113,9 @@ func calcRelayOrderID(hash string) string {
...
@@ -111,3 +113,9 @@ func calcRelayOrderID(hash string) string {
func
calcCoinHash
(
hash
string
)
string
{
func
calcCoinHash
(
hash
string
)
string
{
return
coinHashPrefix
+
hash
return
coinHashPrefix
+
hash
}
}
func
getRealTxHashID
(
id
string
)
string
{
ids
:=
strings
.
Split
(
id
,
"-"
)
return
ids
[
len
(
ids
)
-
1
]
}
plugin/dapp/relay/executor/relay.go
View file @
52f1e829
...
@@ -133,6 +133,10 @@ func (r *relay) getRelayOrderReply(OrderIDs [][]byte) (types.Message, error) {
...
@@ -133,6 +133,10 @@ func (r *relay) getRelayOrderReply(OrderIDs [][]byte) (types.Message, error) {
orderIDGot
[
string
(
orderID
)]
=
true
orderIDGot
[
string
(
orderID
)]
=
true
}
}
}
}
//get remove mavl-xx- prefix
for
_
,
order
:=
range
reply
.
Relayorders
{
order
.
Id
=
getRealTxHashID
(
order
.
Id
)
}
return
&
reply
,
nil
return
&
reply
,
nil
}
}
...
@@ -142,7 +146,7 @@ func insertOrderDescending(toBeInserted *ty.RelayOrder, orders []*ty.RelayOrder)
...
@@ -142,7 +146,7 @@ func insertOrderDescending(toBeInserted *ty.RelayOrder, orders []*ty.RelayOrder)
}
else
{
}
else
{
index
:=
len
(
orders
)
index
:=
len
(
orders
)
for
i
,
element
:=
range
orders
{
for
i
,
element
:=
range
orders
{
if
toBeInserted
.
Amount
>=
element
.
Amount
{
if
toBeInserted
.
LocalCoinAmount
>=
element
.
LocalCoin
Amount
{
index
=
i
index
=
i
break
break
}
}
...
...
plugin/dapp/relay/executor/relay_test.go
View file @
52f1e829
...
@@ -124,10 +124,10 @@ func (s *suiteRelay) testExecDelLocal(tx *types.Transaction, receipt *types.Rece
...
@@ -124,10 +124,10 @@ func (s *suiteRelay) testExecDelLocal(tx *types.Transaction, receipt *types.Rece
func
(
s
*
suiteRelay
)
TestExec_1
()
{
func
(
s
*
suiteRelay
)
TestExec_1
()
{
order
:=
&
ty
.
RelayCreate
{
order
:=
&
ty
.
RelayCreate
{
Operation
:
ty
.
RelayOrderSell
,
Operation
:
ty
.
RelayOrderSell
,
Coin
:
"BTC"
,
XCoin
:
"BTC"
,
Amount
:
0.299
*
1e8
,
XAmount
:
0.299
*
1e8
,
Addr
:
addrBtc
,
XAddr
:
addrBtc
,
Bty
Amount
:
200
*
1e8
,
LocalCoin
Amount
:
200
*
1e8
,
}
}
sell
:=
&
ty
.
RelayAction
{
sell
:=
&
ty
.
RelayAction
{
...
@@ -156,8 +156,8 @@ func (s *suiteRelay) TestExec_1() {
...
@@ -156,8 +156,8 @@ func (s *suiteRelay) TestExec_1() {
var
log
ty
.
ReceiptRelayLog
var
log
ty
.
ReceiptRelayLog
types
.
Decode
(
receipt
.
Logs
[
len
(
receipt
.
Logs
)
-
1
]
.
Log
,
&
log
)
types
.
Decode
(
receipt
.
Logs
[
len
(
receipt
.
Logs
)
-
1
]
.
Log
,
&
log
)
s
.
Equal
(
"200.0000"
,
log
.
Tx
Amount
)
s
.
Equal
(
"200.0000"
,
log
.
LocalCoin
Amount
)
s
.
Equal
(
uint64
(
10
),
log
.
Coin
Height
)
s
.
Equal
(
uint64
(
10
),
log
.
X
Height
)
s
.
orderID
=
log
.
OrderId
s
.
orderID
=
log
.
OrderId
...
@@ -170,7 +170,7 @@ func (s *suiteRelay) TestExec_1() {
...
@@ -170,7 +170,7 @@ func (s *suiteRelay) TestExec_1() {
func
(
s
*
suiteRelay
)
TestExec_2
()
{
func
(
s
*
suiteRelay
)
TestExec_2
()
{
order
:=
&
ty
.
RelayAccept
{
order
:=
&
ty
.
RelayAccept
{
OrderId
:
s
.
orderID
,
OrderId
:
s
.
orderID
,
CoinAddr
:
addrBtc
,
XAddr
:
addrBtc
,
}
}
sell
:=
&
ty
.
RelayAction
{
sell
:=
&
ty
.
RelayAction
{
...
@@ -197,8 +197,8 @@ func (s *suiteRelay) TestExec_2() {
...
@@ -197,8 +197,8 @@ func (s *suiteRelay) TestExec_2() {
var
log
ty
.
ReceiptRelayLog
var
log
ty
.
ReceiptRelayLog
types
.
Decode
(
receipt
.
Logs
[
len
(
receipt
.
Logs
)
-
1
]
.
Log
,
&
log
)
types
.
Decode
(
receipt
.
Logs
[
len
(
receipt
.
Logs
)
-
1
]
.
Log
,
&
log
)
s
.
Equal
(
"200.0000"
,
log
.
Tx
Amount
)
s
.
Equal
(
"200.0000"
,
log
.
LocalCoin
Amount
)
s
.
Equal
(
uint64
(
20
),
log
.
Coin
Height
)
s
.
Equal
(
uint64
(
20
),
log
.
X
Height
)
s
.
Equal
(
ty
.
RelayOrderStatus_locking
.
String
(),
log
.
CurStatus
)
s
.
Equal
(
ty
.
RelayOrderStatus_locking
.
String
(),
log
.
CurStatus
)
}
}
...
@@ -233,8 +233,8 @@ func (s *suiteRelay) TestExec_3() {
...
@@ -233,8 +233,8 @@ func (s *suiteRelay) TestExec_3() {
var
log
ty
.
ReceiptRelayLog
var
log
ty
.
ReceiptRelayLog
types
.
Decode
(
receipt
.
Logs
[
len
(
receipt
.
Logs
)
-
1
]
.
Log
,
&
log
)
types
.
Decode
(
receipt
.
Logs
[
len
(
receipt
.
Logs
)
-
1
]
.
Log
,
&
log
)
s
.
Equal
(
"200.0000"
,
log
.
Tx
Amount
)
s
.
Equal
(
"200.0000"
,
log
.
LocalCoin
Amount
)
s
.
Equal
(
uint64
(
30
),
log
.
Coin
Height
)
s
.
Equal
(
uint64
(
30
),
log
.
X
Height
)
s
.
Equal
(
ty
.
RelayOrderStatus_confirming
.
String
(),
log
.
CurStatus
)
s
.
Equal
(
ty
.
RelayOrderStatus_confirming
.
String
(),
log
.
CurStatus
)
}
}
...
...
plugin/dapp/relay/executor/relaybtc.go
View file @
52f1e829
...
@@ -197,7 +197,7 @@ func (b *btcStore) getMerkleRootFromHeader(blockhash string) (string, error) {
...
@@ -197,7 +197,7 @@ func (b *btcStore) getMerkleRootFromHeader(blockhash string) (string, error) {
func
(
b
*
btcStore
)
verifyBtcTx
(
verify
*
ty
.
RelayVerify
,
order
*
ty
.
RelayOrder
)
error
{
func
(
b
*
btcStore
)
verifyBtcTx
(
verify
*
ty
.
RelayVerify
,
order
*
ty
.
RelayOrder
)
error
{
var
foundtx
bool
var
foundtx
bool
for
_
,
outtx
:=
range
verify
.
GetTx
()
.
GetVout
()
{
for
_
,
outtx
:=
range
verify
.
GetTx
()
.
GetVout
()
{
if
outtx
.
Address
==
order
.
CoinAddr
&&
outtx
.
Value
>=
order
.
Coin
Amount
{
if
outtx
.
Address
==
order
.
XAddr
&&
outtx
.
Value
>=
order
.
X
Amount
{
foundtx
=
true
foundtx
=
true
}
}
}
}
...
@@ -220,7 +220,7 @@ func (b *btcStore) verifyBtcTx(verify *ty.RelayVerify, order *ty.RelayOrder) err
...
@@ -220,7 +220,7 @@ func (b *btcStore) verifyBtcTx(verify *ty.RelayVerify, order *ty.RelayOrder) err
return
err
return
err
}
}
if
verify
.
Tx
.
BlockHeight
+
uint64
(
order
.
Coin
Waits
)
>
uint64
(
height
)
{
if
verify
.
Tx
.
BlockHeight
+
uint64
(
order
.
XBlock
Waits
)
>
uint64
(
height
)
{
return
ty
.
ErrRelayWaitBlocksErr
return
ty
.
ErrRelayWaitBlocksErr
}
}
...
...
plugin/dapp/relay/executor/relaybtc_test.go
View file @
52f1e829
...
@@ -197,8 +197,8 @@ func (s *suiteBtcStore) TestGetMerkleRootFromHeader() {
...
@@ -197,8 +197,8 @@ func (s *suiteBtcStore) TestGetMerkleRootFromHeader() {
func
(
s
*
suiteBtcStore
)
TestVerifyBtcTx
()
{
func
(
s
*
suiteBtcStore
)
TestVerifyBtcTx
()
{
order
:=
&
ty
.
RelayOrder
{
order
:=
&
ty
.
RelayOrder
{
CoinAddr
:
"1Am9UTGfdnxabvcywYG2hvzr6qK8T3oUZT"
,
XAddr
:
"1Am9UTGfdnxabvcywYG2hvzr6qK8T3oUZT"
,
CoinAmount
:
29900000
,
XAmount
:
29900000
,
AcceptTime
:
100
,
AcceptTime
:
100
,
ConfirmTime
:
200
,
ConfirmTime
:
200
,
}
}
...
...
plugin/dapp/relay/executor/relaydb.go
View file @
52f1e829
This diff is collapsed.
Click to expand it.
plugin/dapp/relay/executor/relaydb_test.go
View file @
52f1e829
This diff is collapsed.
Click to expand it.
plugin/dapp/relay/proto/relay.proto
View file @
52f1e829
...
@@ -28,13 +28,13 @@ message RelayOrder {
...
@@ -28,13 +28,13 @@ message RelayOrder {
string
id
=
1
;
string
id
=
1
;
RelayOrderStatus
status
=
2
;
RelayOrderStatus
status
=
2
;
RelayOrderStatus
preStatus
=
3
;
RelayOrderStatus
preStatus
=
3
;
uint64
amount
=
4
;
uint64
localCoinAmount
=
4
;
string
createrAddr
=
5
;
string
createrAddr
=
5
;
uint32
coinOperation
=
6
;
uint32
operation
=
6
;
string
c
oin
=
7
;
string
xC
oin
=
7
;
uint64
coinAmount
=
8
;
uint64
xAmount
=
8
;
string
coinAddr
=
9
;
string
xAddr
=
9
;
string
coinTxHash
=
10
;
string
xTxHash
=
10
;
int64
createTime
=
11
;
int64
createTime
=
11
;
string
acceptAddr
=
12
;
string
acceptAddr
=
12
;
int64
acceptTime
=
13
;
int64
acceptTime
=
13
;
...
@@ -42,23 +42,27 @@ message RelayOrder {
...
@@ -42,23 +42,27 @@ message RelayOrder {
int64
finishTime
=
15
;
int64
finishTime
=
15
;
string
finishTxHash
=
16
;
string
finishTxHash
=
16
;
int64
height
=
17
;
int64
height
=
17
;
uint64
coinHeight
=
18
;
uint64
XHeight
=
18
;
uint32
coinWaits
=
19
;
uint32
xBlockWaits
=
19
;
string
localCoinSymbol
=
20
;
string
localCoinExec
=
21
;
}
}
message
RelayCreate
{
message
RelayCreate
{
uint32
operation
=
1
;
// 0: buy, 1: sell
uint32
operation
=
1
;
// 0: buy, 1: sell
string
coin
=
2
;
// outside coin BTC, ETH...
string
xCoin
=
2
;
// outside cross coin BTC, ETH...
uint64
amount
=
3
;
uint64
xAmount
=
3
;
string
addr
=
4
;
string
xAddr
=
4
;
uint64
btyAmount
=
5
;
uint64
localCoinAmount
=
5
;
uint32
coinWaits
=
6
;
// the coin blocks to wait
uint32
xBlockWaits
=
6
;
// the coin blocks to wait
string
localCoinSymbol
=
7
;
string
localCoinExec
=
8
;
}
}
message
RelayAccept
{
message
RelayAccept
{
string
orderId
=
1
;
string
orderId
=
1
;
string
coinAddr
=
2
;
// for sell coin case needed
string
xAddr
=
2
;
// for sell coin case needed
uint32
coinWaits
=
3
;
uint32
xBlockWaits
=
3
;
}
}
message
RelayRevoke
{
message
RelayRevoke
{
...
@@ -154,21 +158,23 @@ message ReceiptRelayLog {
...
@@ -154,21 +158,23 @@ message ReceiptRelayLog {
string
orderId
=
1
;
string
orderId
=
1
;
string
curStatus
=
2
;
string
curStatus
=
2
;
string
preStatus
=
3
;
string
preStatus
=
3
;
string
tx
Amount
=
4
;
string
localCoin
Amount
=
4
;
string
createrAddr
=
5
;
string
createrAddr
=
5
;
string
coinOperation
=
6
;
uint32
coinOperation
=
6
;
string
coin
=
7
;
string
xCoin
=
7
;
string
coinAmount
=
8
;
string
xAmount
=
8
;
string
coinAddr
=
9
;
string
xAddr
=
9
;
string
coinTxHash
=
10
;
string
xTxHash
=
10
;
int64
createTime
=
11
;
int64
createTime
=
11
;
string
acceptAddr
=
12
;
string
acceptAddr
=
12
;
int64
acceptTime
=
13
;
int64
acceptTime
=
13
;
int64
confirmTime
=
14
;
int64
confirmTime
=
14
;
int64
finishTime
=
15
;
int64
finishTime
=
15
;
string
finishTxHash
=
16
;
string
finishTxHash
=
16
;
uint64
coinHeight
=
17
;
uint64
xHeight
=
17
;
uint32
coinWaits
=
18
;
uint32
xBlockWaits
=
18
;
string
localCoinSymbol
=
19
;
string
localCoinExec
=
20
;
}
}
message
ReqRelayAddrCoins
{
message
ReqRelayAddrCoins
{
...
...
plugin/dapp/relay/types/relay.go
View file @
52f1e829
...
@@ -42,12 +42,6 @@ const (
...
@@ -42,12 +42,6 @@ const (
RelayOrderSell
RelayOrderSell
)
)
// RelayOrderOperation buy or sell operation
var
RelayOrderOperation
=
map
[
uint32
]
string
{
RelayOrderBuy
:
"buy"
,
RelayOrderSell
:
"sell"
,
}
const
(
const
(
// RelayUnlock revoke order
// RelayUnlock revoke order
RelayUnlock
=
iota
RelayUnlock
=
iota
...
@@ -171,7 +165,7 @@ func (r *RelayType) Amount(tx *types.Transaction) (int64, error) {
...
@@ -171,7 +165,7 @@ func (r *RelayType) Amount(tx *types.Transaction) (int64, error) {
}
}
relay
:=
data
.
(
*
RelayAction
)
relay
:=
data
.
(
*
RelayAction
)
if
RelayActionCreate
==
relay
.
Ty
&&
relay
.
GetCreate
()
!=
nil
{
if
RelayActionCreate
==
relay
.
Ty
&&
relay
.
GetCreate
()
!=
nil
{
return
int64
(
relay
.
GetCreate
()
.
Bty
Amount
),
nil
return
int64
(
relay
.
GetCreate
()
.
LocalCoin
Amount
),
nil
}
}
return
0
,
nil
return
0
,
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