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
27e5be5f
Commit
27e5be5f
authored
Nov 23, 2018
by
mdj33
Committed by
vipwzw
Nov 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct paracross plugin lint error
parent
7f73d32d
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
345 additions
and
424 deletions
+345
-424
ticket_test.go
plugin/consensus/ticket/ticket_test.go
+1
-1
paracross.go
plugin/dapp/paracross/commands/paracross.go
+6
-5
account.go
plugin/dapp/paracross/executor/account.go
+2
-0
action.go
plugin/dapp/paracross/executor/action.go
+1
-1
asset.go
plugin/dapp/paracross/executor/asset.go
+32
-32
assettransfer_test.go
plugin/dapp/paracross/executor/assettransfer_test.go
+3
-3
assetwithdraw_test.go
plugin/dapp/paracross/executor/assetwithdraw_test.go
+3
-3
db.go
plugin/dapp/paracross/executor/db.go
+4
-2
exec.go
plugin/dapp/paracross/executor/exec.go
+7
-0
exec_del_local.go
plugin/dapp/paracross/executor/exec_del_local.go
+12
-5
exec_local.go
plugin/dapp/paracross/executor/exec_local.go
+13
-6
paracross.go
plugin/dapp/paracross/executor/paracross.go
+12
-6
paracross_test.go
plugin/dapp/paracross/executor/paracross_test.go
+20
-20
query.go
plugin/dapp/paracross/executor/query.go
+20
-16
rpc.go
plugin/dapp/paracross/rpc/rpc.go
+4
-0
types.go
plugin/dapp/paracross/rpc/types.go
+3
-0
errors.go
plugin/dapp/paracross/types/errors.go
+15
-7
paracross.go
plugin/dapp/paracross/types/paracross.go
+46
-18
type.go
plugin/dapp/paracross/types/type.go
+17
-181
db.go
plugin/dapp/relay/cmd/relayd/relayd/db.go
+0
-1
relay.go
plugin/dapp/relay/executor/relay.go
+5
-5
relay_test.go
plugin/dapp/relay/executor/relay_test.go
+10
-10
relaybtc.go
plugin/dapp/relay/executor/relaybtc.go
+15
-15
relaybtc_test.go
plugin/dapp/relay/executor/relaybtc_test.go
+20
-20
relaydb.go
plugin/dapp/relay/executor/relaydb.go
+11
-11
relaydb_test.go
plugin/dapp/relay/executor/relaydb_test.go
+24
-24
rpc.go
plugin/dapp/relay/rpc/rpc.go
+12
-6
rpc_test.go
plugin/dapp/relay/rpc/rpc_test.go
+2
-2
types.go
plugin/dapp/relay/rpc/types.go
+6
-4
errors.go
plugin/dapp/relay/types/errors.go
+16
-16
relay.go
plugin/dapp/relay/types/relay.go
+2
-3
decode_test.go
plugin/store/mpt/db2/rlp/decode_test.go
+1
-1
No files found.
plugin/consensus/ticket/ticket_test.go
View file @
27e5be5f
...
@@ -55,7 +55,7 @@ func TestProcEvent(t *testing.T) {
...
@@ -55,7 +55,7 @@ func TestProcEvent(t *testing.T) {
func
Test_genPrivHash
(
t
*
testing
.
T
)
{
func
Test_genPrivHash
(
t
*
testing
.
T
)
{
c
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
c
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
priv
,
err
:=
c
.
GenKey
()
priv
,
_
:=
c
.
GenKey
()
bt
,
err
:=
genPrivHash
(
priv
,
"AA:BB:CC:DD"
)
bt
,
err
:=
genPrivHash
(
priv
,
"AA:BB:CC:DD"
)
assert
.
NotNil
(
t
,
err
)
assert
.
NotNil
(
t
,
err
)
...
...
plugin/dapp/paracross/commands/paracross.go
View file @
27e5be5f
...
@@ -16,6 +16,7 @@ import (
...
@@ -16,6 +16,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra"
)
)
//ParcCmd paracross cmd register
func
ParcCmd
()
*
cobra
.
Command
{
func
ParcCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"para"
,
Use
:
"para"
,
...
@@ -32,7 +33,7 @@ func ParcCmd() *cobra.Command {
...
@@ -32,7 +33,7 @@ func ParcCmd() *cobra.Command {
return
cmd
return
cmd
}
}
// create raw asset transfer tx
//
CreateRawAssetTransferCmd
create raw asset transfer tx
func
CreateRawAssetTransferCmd
()
*
cobra
.
Command
{
func
CreateRawAssetTransferCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"asset_transfer"
,
Use
:
"asset_transfer"
,
...
@@ -67,7 +68,7 @@ func createAssetTransfer(cmd *cobra.Command, args []string) {
...
@@ -67,7 +68,7 @@ func createAssetTransfer(cmd *cobra.Command, args []string) {
fmt
.
Println
(
txHex
)
fmt
.
Println
(
txHex
)
}
}
// create raw asset withdraw tx
//
CreateRawAssetWithdrawCmd
create raw asset withdraw tx
func
CreateRawAssetWithdrawCmd
()
*
cobra
.
Command
{
func
CreateRawAssetWithdrawCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"asset_withdraw"
,
Use
:
"asset_withdraw"
,
...
@@ -139,7 +140,7 @@ func createAssetTx(cmd *cobra.Command, isWithdraw bool) (string, error) {
...
@@ -139,7 +140,7 @@ func createAssetTx(cmd *cobra.Command, isWithdraw bool) (string, error) {
return
hex
.
EncodeToString
(
txHex
),
nil
return
hex
.
EncodeToString
(
txHex
),
nil
}
}
// create raw transfer tx
//
CreateRawTransferCmd
create raw transfer tx
func
CreateRawTransferCmd
()
*
cobra
.
Command
{
func
CreateRawTransferCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"transfer"
,
Use
:
"transfer"
,
...
@@ -174,7 +175,7 @@ func createTransfer(cmd *cobra.Command, args []string) {
...
@@ -174,7 +175,7 @@ func createTransfer(cmd *cobra.Command, args []string) {
fmt
.
Println
(
txHex
)
fmt
.
Println
(
txHex
)
}
}
// create raw transfer to exec tx
//
CreateRawTransferToExecCmd
create raw transfer to exec tx
func
CreateRawTransferToExecCmd
()
*
cobra
.
Command
{
func
CreateRawTransferToExecCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"transfer_exec"
,
Use
:
"transfer_exec"
,
...
@@ -209,7 +210,7 @@ func createTransferToExec(cmd *cobra.Command, args []string) {
...
@@ -209,7 +210,7 @@ func createTransferToExec(cmd *cobra.Command, args []string) {
fmt
.
Println
(
txHex
)
fmt
.
Println
(
txHex
)
}
}
// create raw withdraw tx
//
CreateRawWithdrawCmd
create raw withdraw tx
func
CreateRawWithdrawCmd
()
*
cobra
.
Command
{
func
CreateRawWithdrawCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"withdraw"
,
Use
:
"withdraw"
,
...
...
plugin/dapp/paracross/executor/account.go
View file @
27e5be5f
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
// 注: 在计算帐号地址时, 平行链paracross合约地址需要带上title前缀,才能表现出和主链一致, 但是现在不带,
// 注: 在计算帐号地址时, 平行链paracross合约地址需要带上title前缀,才能表现出和主链一致, 但是现在不带,
//NewParaAccount create new paracross account
// 其中带{}, 都表示变量, 用需要用真实的地址, 符号代替
// 其中带{}, 都表示变量, 用需要用真实的地址, 符号代替
// 构建主链资产在平行链paracross帐号
// 构建主链资产在平行链paracross帐号
// execName: user.p.{guodun}.paracross
// execName: user.p.{guodun}.paracross
...
@@ -28,6 +29,7 @@ func NewParaAccount(paraTitle, mainExecName, mainSymbol string, db db.KV) (*acco
...
@@ -28,6 +29,7 @@ func NewParaAccount(paraTitle, mainExecName, mainSymbol string, db db.KV) (*acco
return
account
.
NewAccountDB
(
paraExec
,
paraSymbol
,
db
)
return
account
.
NewAccountDB
(
paraExec
,
paraSymbol
,
db
)
}
}
//NewMainAccount create new Main account
// 以后如果支持从平行链资产转移到主链, 构建平行链资产在主链的paracross帐号
// 以后如果支持从平行链资产转移到主链, 构建平行链资产在主链的paracross帐号
// execName: paracross
// execName: paracross
// symbol: user.p.{guodun}.coins.{guodun} user.p.{guodun}.token.{TEST}
// symbol: user.p.{guodun}.coins.{guodun} user.p.{guodun}.token.{TEST}
...
...
plugin/dapp/paracross/executor/action.go
View file @
27e5be5f
...
@@ -448,7 +448,7 @@ func (a *action) Miner(miner *pt.ParacrossMinerAction) (*types.Receipt, error) {
...
@@ -448,7 +448,7 @@ func (a *action) Miner(miner *pt.ParacrossMinerAction) (*types.Receipt, error) {
log
.
Log
=
types
.
Encode
(
receipt
)
log
.
Log
=
types
.
Encode
(
receipt
)
logs
=
append
(
logs
,
log
)
logs
=
append
(
logs
,
log
)
return
&
types
.
Receipt
{
types
.
ExecOk
,
nil
,
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
nil
,
Logs
:
logs
},
nil
}
}
...
...
plugin/dapp/paracross/executor/asset.go
View file @
27e5be5f
...
@@ -30,24 +30,24 @@ func (a *action) assetTransfer(transfer *types.AssetsTransfer) (*types.Receipt,
...
@@ -30,24 +30,24 @@ func (a *action) assetTransfer(transfer *types.AssetsTransfer) (*types.Receipt,
clog
.
Debug
(
"paracross.AssetTransfer not isPara"
,
"execer"
,
string
(
a
.
tx
.
Execer
),
clog
.
Debug
(
"paracross.AssetTransfer not isPara"
,
"execer"
,
string
(
a
.
tx
.
Execer
),
"txHash"
,
common
.
Bytes2Hex
(
a
.
tx
.
Hash
()))
"txHash"
,
common
.
Bytes2Hex
(
a
.
tx
.
Hash
()))
return
accDB
.
ExecTransfer
(
a
.
fromaddr
,
toAddr
,
execAddr
,
transfer
.
Amount
)
return
accDB
.
ExecTransfer
(
a
.
fromaddr
,
toAddr
,
execAddr
,
transfer
.
Amount
)
}
paraTitle
,
err
:=
getTitleFrom
(
a
.
tx
.
Execer
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"assetTransferCoins call getTitleFrom failed"
)
}
var
paraAcc
*
account
.
DB
if
transfer
.
Cointoken
==
""
{
paraAcc
,
err
=
NewParaAccount
(
string
(
paraTitle
),
"coins"
,
"bty"
,
a
.
db
)
}
else
{
}
else
{
paraTitle
,
err
:=
getTitleFrom
(
a
.
tx
.
Execer
)
paraAcc
,
err
=
NewParaAccount
(
string
(
paraTitle
),
"token"
,
transfer
.
Cointoken
,
a
.
db
)
if
err
!=
nil
{
}
return
nil
,
errors
.
Wrap
(
err
,
"assetTransferCoins call getTitleFrom failed"
)
if
err
!=
nil
{
}
return
nil
,
errors
.
Wrap
(
err
,
"assetTransferCoins call NewParaAccount failed"
)
var
paraAcc
*
account
.
DB
if
transfer
.
Cointoken
==
""
{
paraAcc
,
err
=
NewParaAccount
(
string
(
paraTitle
),
"coins"
,
"bty"
,
a
.
db
)
}
else
{
paraAcc
,
err
=
NewParaAccount
(
string
(
paraTitle
),
"token"
,
transfer
.
Cointoken
,
a
.
db
)
}
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"assetTransferCoins call NewParaAccount failed"
)
}
clog
.
Debug
(
"paracross.AssetTransfer isPara"
,
"execer"
,
string
(
a
.
tx
.
Execer
),
"txHash"
,
common
.
Bytes2Hex
(
a
.
tx
.
Hash
()))
return
assetDepositBalance
(
paraAcc
,
transfer
.
To
,
transfer
.
Amount
)
}
}
clog
.
Debug
(
"paracross.AssetTransfer isPara"
,
"execer"
,
string
(
a
.
tx
.
Execer
),
"txHash"
,
common
.
Bytes2Hex
(
a
.
tx
.
Hash
()))
return
assetDepositBalance
(
paraAcc
,
transfer
.
To
,
transfer
.
Amount
)
}
}
func
(
a
*
action
)
assetWithdraw
(
withdraw
*
types
.
AssetsWithdraw
,
withdrawTx
*
types
.
Transaction
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
assetWithdraw
(
withdraw
*
types
.
AssetsWithdraw
,
withdrawTx
*
types
.
Transaction
)
(
*
types
.
Receipt
,
error
)
{
...
@@ -62,24 +62,24 @@ func (a *action) assetWithdraw(withdraw *types.AssetsWithdraw, withdrawTx *types
...
@@ -62,24 +62,24 @@ func (a *action) assetWithdraw(withdraw *types.AssetsWithdraw, withdrawTx *types
clog
.
Debug
(
"Paracross.Exec"
,
"AssettWithdraw"
,
withdraw
.
Amount
,
"from"
,
fromAddr
,
clog
.
Debug
(
"Paracross.Exec"
,
"AssettWithdraw"
,
withdraw
.
Amount
,
"from"
,
fromAddr
,
"to"
,
withdraw
.
To
,
"exec"
,
execAddr
,
"withdrawTx execor"
,
string
(
withdrawTx
.
Execer
))
"to"
,
withdraw
.
To
,
"exec"
,
execAddr
,
"withdrawTx execor"
,
string
(
withdrawTx
.
Execer
))
return
accDB
.
ExecTransfer
(
fromAddr
,
withdraw
.
To
,
execAddr
,
withdraw
.
Amount
)
return
accDB
.
ExecTransfer
(
fromAddr
,
withdraw
.
To
,
execAddr
,
withdraw
.
Amount
)
}
paraTitle
,
err
:=
getTitleFrom
(
a
.
tx
.
Execer
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"assetWithdrawCoins call getTitleFrom failed"
)
}
var
paraAcc
*
account
.
DB
if
withdraw
.
Cointoken
==
""
{
paraAcc
,
err
=
NewParaAccount
(
string
(
paraTitle
),
"coins"
,
"bty"
,
a
.
db
)
}
else
{
}
else
{
paraTitle
,
err
:=
getTitleFrom
(
a
.
tx
.
Execer
)
paraAcc
,
err
=
NewParaAccount
(
string
(
paraTitle
),
"token"
,
withdraw
.
Cointoken
,
a
.
db
)
if
err
!=
nil
{
}
return
nil
,
errors
.
Wrap
(
err
,
"assetWithdrawCoins call getTitleFrom failed"
)
if
err
!=
nil
{
}
return
nil
,
errors
.
Wrap
(
err
,
"assetWithdrawCoins call NewParaAccount failed"
)
var
paraAcc
*
account
.
DB
if
withdraw
.
Cointoken
==
""
{
paraAcc
,
err
=
NewParaAccount
(
string
(
paraTitle
),
"coins"
,
"bty"
,
a
.
db
)
}
else
{
paraAcc
,
err
=
NewParaAccount
(
string
(
paraTitle
),
"token"
,
withdraw
.
Cointoken
,
a
.
db
)
}
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"assetWithdrawCoins call NewParaAccount failed"
)
}
clog
.
Debug
(
"paracross.assetWithdrawCoins isPara"
,
"execer"
,
string
(
a
.
tx
.
Execer
),
"txHash"
,
common
.
Bytes2Hex
(
a
.
tx
.
Hash
()))
return
assetWithdrawBalance
(
paraAcc
,
a
.
fromaddr
,
withdraw
.
Amount
)
}
}
clog
.
Debug
(
"paracross.assetWithdrawCoins isPara"
,
"execer"
,
string
(
a
.
tx
.
Execer
),
"txHash"
,
common
.
Bytes2Hex
(
a
.
tx
.
Hash
()))
return
assetWithdrawBalance
(
paraAcc
,
a
.
fromaddr
,
withdraw
.
Amount
)
}
}
func
createAccount
(
db
db
.
KV
,
symbol
string
)
(
*
account
.
DB
,
error
)
{
func
createAccount
(
db
db
.
KV
,
symbol
string
)
(
*
account
.
DB
,
error
)
{
...
...
plugin/dapp/paracross/executor/assettransfer_test.go
View file @
27e5be5f
...
@@ -83,13 +83,13 @@ func (suite *AssetTransferTestSuite) SetupTest() {
...
@@ -83,13 +83,13 @@ func (suite *AssetTransferTestSuite) SetupTest() {
saveTitle
(
suite
.
stateDB
,
calcTitleKey
(
Title
),
&
titleStatus
)
saveTitle
(
suite
.
stateDB
,
calcTitleKey
(
Title
),
&
titleStatus
)
// setup api
// setup api
hashes
:=
&
types
.
ReqHashes
{[][]
byte
{
MainBlockHash10
}}
hashes
:=
&
types
.
ReqHashes
{
Hashes
:
[][]
byte
{
MainBlockHash10
}}
suite
.
api
.
On
(
"GetBlockByHashes"
,
hashes
)
.
Return
(
suite
.
api
.
On
(
"GetBlockByHashes"
,
hashes
)
.
Return
(
&
types
.
BlockDetails
{
&
types
.
BlockDetails
{
Items
:
[]
*
types
.
BlockDetail
{
blockDetail
},
Items
:
[]
*
types
.
BlockDetail
{
blockDetail
},
},
nil
)
},
nil
)
suite
.
api
.
On
(
"GetBlockHash"
,
&
types
.
ReqInt
{
MainBlockHeight
})
.
Return
(
suite
.
api
.
On
(
"GetBlockHash"
,
&
types
.
ReqInt
{
Height
:
MainBlockHeight
})
.
Return
(
&
types
.
ReplyHash
{
MainBlockHash10
},
nil
)
&
types
.
ReplyHash
{
Hash
:
MainBlockHash10
},
nil
)
}
}
func
(
suite
*
AssetTransferTestSuite
)
TestExecTransferNobalance
()
{
func
(
suite
*
AssetTransferTestSuite
)
TestExecTransferNobalance
()
{
...
...
plugin/dapp/paracross/executor/assetwithdraw_test.go
View file @
27e5be5f
...
@@ -78,13 +78,13 @@ func (suite *AssetWithdrawTestSuite) SetupTest() {
...
@@ -78,13 +78,13 @@ func (suite *AssetWithdrawTestSuite) SetupTest() {
saveTitle
(
suite
.
stateDB
,
calcTitleKey
(
Title
),
&
titleStatus
)
saveTitle
(
suite
.
stateDB
,
calcTitleKey
(
Title
),
&
titleStatus
)
// setup api
// setup api
hashes
:=
&
types
.
ReqHashes
{[][]
byte
{
MainBlockHash10
}}
hashes
:=
&
types
.
ReqHashes
{
Hashes
:
[][]
byte
{
MainBlockHash10
}}
suite
.
api
.
On
(
"GetBlockByHashes"
,
hashes
)
.
Return
(
suite
.
api
.
On
(
"GetBlockByHashes"
,
hashes
)
.
Return
(
&
types
.
BlockDetails
{
&
types
.
BlockDetails
{
Items
:
[]
*
types
.
BlockDetail
{
blockDetail
},
Items
:
[]
*
types
.
BlockDetail
{
blockDetail
},
},
nil
)
},
nil
)
suite
.
api
.
On
(
"GetBlockHash"
,
&
types
.
ReqInt
{
MainBlockHeight
})
.
Return
(
suite
.
api
.
On
(
"GetBlockHash"
,
&
types
.
ReqInt
{
Height
:
MainBlockHeight
})
.
Return
(
&
types
.
ReplyHash
{
MainBlockHash10
},
nil
)
&
types
.
ReplyHash
{
Hash
:
MainBlockHash10
},
nil
)
}
}
// 主链先不执行
// 主链先不执行
...
...
plugin/dapp/paracross/executor/db.go
View file @
27e5be5f
...
@@ -53,8 +53,9 @@ func saveTitleHeight(db dbm.KV, key []byte, heightStatus types.Message /* height
...
@@ -53,8 +53,9 @@ func saveTitleHeight(db dbm.KV, key []byte, heightStatus types.Message /* height
return
db
.
Set
(
key
,
val
)
return
db
.
Set
(
key
,
val
)
}
}
//GetBlock get block detail by block hash
func
GetBlock
(
api
client
.
QueueProtocolAPI
,
blockHash
[]
byte
)
(
*
types
.
BlockDetail
,
error
)
{
func
GetBlock
(
api
client
.
QueueProtocolAPI
,
blockHash
[]
byte
)
(
*
types
.
BlockDetail
,
error
)
{
blockDetails
,
err
:=
api
.
GetBlockByHashes
(
&
types
.
ReqHashes
{[][]
byte
{
blockHash
}})
blockDetails
,
err
:=
api
.
GetBlockByHashes
(
&
types
.
ReqHashes
{
Hashes
:
[][]
byte
{
blockHash
}})
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"paracross.Commit getBlockHeader"
,
"db"
,
err
,
clog
.
Error
(
"paracross.Commit getBlockHeader"
,
"db"
,
err
,
"commit tx hash"
,
common
.
Bytes2Hex
(
blockHash
))
"commit tx hash"
,
common
.
Bytes2Hex
(
blockHash
))
...
@@ -88,8 +89,9 @@ func isNotFound(err error) bool {
...
@@ -88,8 +89,9 @@ func isNotFound(err error) bool {
return
false
return
false
}
}
//GetTx get tx by tx hash
func
GetTx
(
api
client
.
QueueProtocolAPI
,
txHash
[]
byte
)
(
*
types
.
TransactionDetail
,
error
)
{
func
GetTx
(
api
client
.
QueueProtocolAPI
,
txHash
[]
byte
)
(
*
types
.
TransactionDetail
,
error
)
{
txs
,
err
:=
api
.
GetTransactionByHash
(
&
types
.
ReqHashes
{[][]
byte
{
txHash
}})
txs
,
err
:=
api
.
GetTransactionByHash
(
&
types
.
ReqHashes
{
Hashes
:
[][]
byte
{
txHash
}})
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"paracross.Commit GetTx"
,
"db"
,
err
,
clog
.
Error
(
"paracross.Commit GetTx"
,
"db"
,
err
,
"commit tx hash"
,
common
.
Bytes2Hex
(
txHash
))
"commit tx hash"
,
common
.
Bytes2Hex
(
txHash
))
...
...
plugin/dapp/paracross/executor/exec.go
View file @
27e5be5f
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"github.com/pkg/errors"
"github.com/pkg/errors"
)
)
//Exec_Commit consensus commit tx exec process
func
(
e
*
Paracross
)
Exec_Commit
(
payload
*
pt
.
ParacrossCommitAction
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
e
*
Paracross
)
Exec_Commit
(
payload
*
pt
.
ParacrossCommitAction
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
a
:=
newAction
(
e
,
tx
)
a
:=
newAction
(
e
,
tx
)
receipt
,
err
:=
a
.
Commit
(
payload
)
receipt
,
err
:=
a
.
Commit
(
payload
)
...
@@ -21,6 +22,7 @@ func (e *Paracross) Exec_Commit(payload *pt.ParacrossCommitAction, tx *types.Tra
...
@@ -21,6 +22,7 @@ func (e *Paracross) Exec_Commit(payload *pt.ParacrossCommitAction, tx *types.Tra
return
receipt
,
nil
return
receipt
,
nil
}
}
//Exec_AssetTransfer asset transfer exec process
func
(
e
*
Paracross
)
Exec_AssetTransfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
e
*
Paracross
)
Exec_AssetTransfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
clog
.
Debug
(
"Paracross.Exec"
,
"transfer"
,
""
)
clog
.
Debug
(
"Paracross.Exec"
,
"transfer"
,
""
)
_
,
err
:=
e
.
checkTxGroup
(
tx
,
index
)
_
,
err
:=
e
.
checkTxGroup
(
tx
,
index
)
...
@@ -37,6 +39,7 @@ func (e *Paracross) Exec_AssetTransfer(payload *types.AssetsTransfer, tx *types.
...
@@ -37,6 +39,7 @@ func (e *Paracross) Exec_AssetTransfer(payload *types.AssetsTransfer, tx *types.
return
receipt
,
nil
return
receipt
,
nil
}
}
//Exec_AssetWithdraw asset withdraw exec process
func
(
e
*
Paracross
)
Exec_AssetWithdraw
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
e
*
Paracross
)
Exec_AssetWithdraw
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
clog
.
Debug
(
"Paracross.Exec"
,
"withdraw"
,
""
)
clog
.
Debug
(
"Paracross.Exec"
,
"withdraw"
,
""
)
_
,
err
:=
e
.
checkTxGroup
(
tx
,
index
)
_
,
err
:=
e
.
checkTxGroup
(
tx
,
index
)
...
@@ -53,6 +56,7 @@ func (e *Paracross) Exec_AssetWithdraw(payload *types.AssetsWithdraw, tx *types.
...
@@ -53,6 +56,7 @@ func (e *Paracross) Exec_AssetWithdraw(payload *types.AssetsWithdraw, tx *types.
return
receipt
,
nil
return
receipt
,
nil
}
}
//Exec_Miner miner tx exec process
func
(
e
*
Paracross
)
Exec_Miner
(
payload
*
pt
.
ParacrossMinerAction
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
e
*
Paracross
)
Exec_Miner
(
payload
*
pt
.
ParacrossMinerAction
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
if
index
!=
0
{
if
index
!=
0
{
return
nil
,
pt
.
ErrParaMinerBaseIndex
return
nil
,
pt
.
ErrParaMinerBaseIndex
...
@@ -64,16 +68,19 @@ func (e *Paracross) Exec_Miner(payload *pt.ParacrossMinerAction, tx *types.Trans
...
@@ -64,16 +68,19 @@ func (e *Paracross) Exec_Miner(payload *pt.ParacrossMinerAction, tx *types.Trans
return
a
.
Miner
(
payload
)
return
a
.
Miner
(
payload
)
}
}
//Exec_Transfer exec asset transfer process
func
(
e
*
Paracross
)
Exec_Transfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
e
*
Paracross
)
Exec_Transfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
a
:=
newAction
(
e
,
tx
)
a
:=
newAction
(
e
,
tx
)
return
a
.
Transfer
(
payload
,
tx
,
index
)
return
a
.
Transfer
(
payload
,
tx
,
index
)
}
}
//Exec_Withdraw exec asset withdraw
func
(
e
*
Paracross
)
Exec_Withdraw
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
e
*
Paracross
)
Exec_Withdraw
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
a
:=
newAction
(
e
,
tx
)
a
:=
newAction
(
e
,
tx
)
return
a
.
Withdraw
(
payload
,
tx
,
index
)
return
a
.
Withdraw
(
payload
,
tx
,
index
)
}
}
//Exec_TransferToExec exec transfer asset
func
(
e
*
Paracross
)
Exec_TransferToExec
(
payload
*
types
.
AssetsTransferToExec
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
e
*
Paracross
)
Exec_TransferToExec
(
payload
*
types
.
AssetsTransferToExec
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
a
:=
newAction
(
e
,
tx
)
a
:=
newAction
(
e
,
tx
)
return
a
.
TransferToExec
(
payload
,
tx
,
index
)
return
a
.
TransferToExec
(
payload
,
tx
,
index
)
...
...
plugin/dapp/paracross/executor/exec_del_local.go
View file @
27e5be5f
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
)
)
//ExecDelLocal_Commit consensus commit tx del local db process
func
(
e
*
Paracross
)
ExecDelLocal_Commit
(
payload
*
pt
.
ParacrossCommitAction
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecDelLocal_Commit
(
payload
*
pt
.
ParacrossCommitAction
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
var
set
types
.
LocalDBSet
var
set
types
.
LocalDBSet
for
_
,
log
:=
range
receiptData
.
Logs
{
for
_
,
log
:=
range
receiptData
.
Logs
{
...
@@ -18,17 +19,17 @@ func (e *Paracross) ExecDelLocal_Commit(payload *pt.ParacrossCommitAction, tx *t
...
@@ -18,17 +19,17 @@ func (e *Paracross) ExecDelLocal_Commit(payload *pt.ParacrossCommitAction, tx *t
var
r
pt
.
ParacrossTx
var
r
pt
.
ParacrossTx
r
.
TxHash
=
string
(
tx
.
Hash
())
r
.
TxHash
=
string
(
tx
.
Hash
())
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
calcLocalTxKey
(
g
.
Status
.
Title
,
g
.
Status
.
Height
,
tx
.
From
()),
nil
})
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
calcLocalTxKey
(
g
.
Status
.
Title
,
g
.
Status
.
Height
,
tx
.
From
()),
Value
:
nil
})
}
else
if
log
.
Ty
==
pt
.
TyLogParacrossCommitDone
{
}
else
if
log
.
Ty
==
pt
.
TyLogParacrossCommitDone
{
var
g
pt
.
ReceiptParacrossDone
var
g
pt
.
ReceiptParacrossDone
types
.
Decode
(
log
.
Log
,
&
g
)
types
.
Decode
(
log
.
Log
,
&
g
)
g
.
Height
=
g
.
Height
-
1
g
.
Height
=
g
.
Height
-
1
key
:=
calcLocalTitleKey
(
g
.
Title
)
key
:=
calcLocalTitleKey
(
g
.
Title
)
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
key
,
types
.
Encode
(
&
g
)})
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
&
g
)})
key
=
calcLocalHeightKey
(
g
.
Title
,
g
.
Height
)
key
=
calcLocalHeightKey
(
g
.
Title
,
g
.
Height
)
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
key
,
nil
})
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
r
,
err
:=
e
.
saveLocalParaTxs
(
tx
,
true
)
r
,
err
:=
e
.
saveLocalParaTxs
(
tx
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -41,12 +42,13 @@ func (e *Paracross) ExecDelLocal_Commit(payload *pt.ParacrossCommitAction, tx *t
...
@@ -41,12 +42,13 @@ func (e *Paracross) ExecDelLocal_Commit(payload *pt.ParacrossCommitAction, tx *t
var
r
pt
.
ParacrossTx
var
r
pt
.
ParacrossTx
r
.
TxHash
=
string
(
tx
.
Hash
())
r
.
TxHash
=
string
(
tx
.
Hash
())
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
calcLocalTxKey
(
g
.
Status
.
Title
,
g
.
Status
.
Height
,
tx
.
From
()),
nil
})
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
calcLocalTxKey
(
g
.
Status
.
Title
,
g
.
Status
.
Height
,
tx
.
From
()),
Value
:
nil
})
}
}
}
}
return
&
set
,
nil
return
&
set
,
nil
}
}
//ExecDelLocal_AssetTransfer asset transfer del local db process
func
(
e
*
Paracross
)
ExecDelLocal_AssetTransfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecDelLocal_AssetTransfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
var
set
types
.
LocalDBSet
var
set
types
.
LocalDBSet
...
@@ -61,29 +63,34 @@ func (e *Paracross) ExecDelLocal_AssetTransfer(payload *types.AssetsTransfer, tx
...
@@ -61,29 +63,34 @@ func (e *Paracross) ExecDelLocal_AssetTransfer(payload *types.AssetsTransfer, tx
return
&
set
,
nil
return
&
set
,
nil
}
}
//ExecDelLocal_AssetWithdraw asset withdraw local db process
func
(
e
*
Paracross
)
ExecDelLocal_AssetWithdraw
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecDelLocal_AssetWithdraw
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
nil
,
nil
return
nil
,
nil
}
}
//ExecDelLocal_Miner miner tx del local db process
func
(
e
*
Paracross
)
ExecDelLocal_Miner
(
payload
*
pt
.
ParacrossMinerAction
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecDelLocal_Miner
(
payload
*
pt
.
ParacrossMinerAction
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
index
!=
0
{
if
index
!=
0
{
return
nil
,
pt
.
ErrParaMinerBaseIndex
return
nil
,
pt
.
ErrParaMinerBaseIndex
}
}
var
set
types
.
LocalDBSet
var
set
types
.
LocalDBSet
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
pt
.
CalcMinerHeightKey
(
payload
.
Status
.
Title
,
payload
.
Status
.
Height
),
nil
})
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
pt
.
CalcMinerHeightKey
(
payload
.
Status
.
Title
,
payload
.
Status
.
Height
),
Value
:
nil
})
return
&
set
,
nil
return
&
set
,
nil
}
}
//ExecDelLocal_Transfer asset transfer del local process
func
(
e
*
Paracross
)
ExecDelLocal_Transfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecDelLocal_Transfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
nil
,
nil
return
nil
,
nil
}
}
//ExecDelLocal_Withdraw asset withdraw del local db process
func
(
e
*
Paracross
)
ExecDelLocal_Withdraw
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecDelLocal_Withdraw
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
nil
,
nil
return
nil
,
nil
}
}
//ExecDelLocal_TransferToExec asset transfer to exec del local db process
func
(
e
*
Paracross
)
ExecDelLocal_TransferToExec
(
payload
*
types
.
AssetsTransferToExec
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecDelLocal_TransferToExec
(
payload
*
types
.
AssetsTransferToExec
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
nil
,
nil
return
nil
,
nil
}
}
plugin/dapp/paracross/executor/exec_local.go
View file @
27e5be5f
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
)
)
//ExecLocal_Commit commit tx local db process
func
(
e
*
Paracross
)
ExecLocal_Commit
(
payload
*
pt
.
ParacrossCommitAction
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecLocal_Commit
(
payload
*
pt
.
ParacrossCommitAction
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
var
set
types
.
LocalDBSet
var
set
types
.
LocalDBSet
for
_
,
log
:=
range
receiptData
.
Logs
{
for
_
,
log
:=
range
receiptData
.
Logs
{
...
@@ -21,16 +22,16 @@ func (e *Paracross) ExecLocal_Commit(payload *pt.ParacrossCommitAction, tx *type
...
@@ -21,16 +22,16 @@ func (e *Paracross) ExecLocal_Commit(payload *pt.ParacrossCommitAction, tx *type
var
r
pt
.
ParacrossTx
var
r
pt
.
ParacrossTx
r
.
TxHash
=
string
(
tx
.
Hash
())
r
.
TxHash
=
string
(
tx
.
Hash
())
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
calcLocalTxKey
(
g
.
Status
.
Title
,
g
.
Status
.
Height
,
tx
.
From
()),
types
.
Encode
(
&
r
)})
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
calcLocalTxKey
(
g
.
Status
.
Title
,
g
.
Status
.
Height
,
tx
.
From
()),
Value
:
types
.
Encode
(
&
r
)})
}
else
if
log
.
Ty
==
pt
.
TyLogParacrossCommitDone
{
}
else
if
log
.
Ty
==
pt
.
TyLogParacrossCommitDone
{
var
g
pt
.
ReceiptParacrossDone
var
g
pt
.
ReceiptParacrossDone
types
.
Decode
(
log
.
Log
,
&
g
)
types
.
Decode
(
log
.
Log
,
&
g
)
key
:=
calcLocalTitleKey
(
g
.
Title
)
key
:=
calcLocalTitleKey
(
g
.
Title
)
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
key
,
types
.
Encode
(
&
g
)})
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
&
g
)})
key
=
calcLocalHeightKey
(
g
.
Title
,
g
.
Height
)
key
=
calcLocalHeightKey
(
g
.
Title
,
g
.
Height
)
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
key
,
types
.
Encode
(
&
g
)})
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
&
g
)})
r
,
err
:=
e
.
saveLocalParaTxs
(
tx
,
false
)
r
,
err
:=
e
.
saveLocalParaTxs
(
tx
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -43,12 +44,13 @@ func (e *Paracross) ExecLocal_Commit(payload *pt.ParacrossCommitAction, tx *type
...
@@ -43,12 +44,13 @@ func (e *Paracross) ExecLocal_Commit(payload *pt.ParacrossCommitAction, tx *type
var
r
pt
.
ParacrossTx
var
r
pt
.
ParacrossTx
r
.
TxHash
=
string
(
tx
.
Hash
())
r
.
TxHash
=
string
(
tx
.
Hash
())
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
calcLocalTxKey
(
g
.
Status
.
Title
,
g
.
Status
.
Height
,
tx
.
From
()),
types
.
Encode
(
&
r
)})
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
calcLocalTxKey
(
g
.
Status
.
Title
,
g
.
Status
.
Height
,
tx
.
From
()),
Value
:
types
.
Encode
(
&
r
)})
}
}
}
}
return
&
set
,
nil
return
&
set
,
nil
}
}
//ExecLocal_AssetTransfer asset transfer local proc
func
(
e
*
Paracross
)
ExecLocal_AssetTransfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecLocal_AssetTransfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
var
set
types
.
LocalDBSet
var
set
types
.
LocalDBSet
...
@@ -63,10 +65,12 @@ func (e *Paracross) ExecLocal_AssetTransfer(payload *types.AssetsTransfer, tx *t
...
@@ -63,10 +65,12 @@ func (e *Paracross) ExecLocal_AssetTransfer(payload *types.AssetsTransfer, tx *t
return
&
set
,
nil
return
&
set
,
nil
}
}
//ExecLocal_AssetWithdraw asset withdraw process
func
(
e
*
Paracross
)
ExecLocal_AssetWithdraw
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecLocal_AssetWithdraw
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
nil
,
nil
return
nil
,
nil
}
}
//ExecLocal_Miner miner tx local db process
func
(
e
*
Paracross
)
ExecLocal_Miner
(
payload
*
pt
.
ParacrossMinerAction
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecLocal_Miner
(
payload
*
pt
.
ParacrossMinerAction
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
index
!=
0
{
if
index
!=
0
{
return
nil
,
pt
.
ErrParaMinerBaseIndex
return
nil
,
pt
.
ErrParaMinerBaseIndex
...
@@ -108,20 +112,23 @@ func (e *Paracross) ExecLocal_Miner(payload *pt.ParacrossMinerAction, tx *types.
...
@@ -108,20 +112,23 @@ func (e *Paracross) ExecLocal_Miner(payload *pt.ParacrossMinerAction, tx *types.
payload
.
Status
.
CrossTxResult
=
util
.
CalcSubBitMap
(
mixTxHashs
,
crossTxHashs
,
e
.
GetReceipt
()[
1
:
])
payload
.
Status
.
CrossTxResult
=
util
.
CalcSubBitMap
(
mixTxHashs
,
crossTxHashs
,
e
.
GetReceipt
()[
1
:
])
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
pt
.
CalcMinerHeightKey
(
payload
.
Status
.
Title
,
payload
.
Status
.
Height
),
Key
:
pt
.
CalcMinerHeightKey
(
payload
.
Status
.
Title
,
payload
.
Status
.
Height
),
types
.
Encode
(
payload
.
Status
)})
Value
:
types
.
Encode
(
payload
.
Status
)})
return
&
set
,
nil
return
&
set
,
nil
}
}
// ExecLocal_Transfer asset transfer local db process
func
(
e
*
Paracross
)
ExecLocal_Transfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecLocal_Transfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
nil
,
nil
return
nil
,
nil
}
}
//ExecLocal_Withdraw asset withdraw local db process
func
(
e
*
Paracross
)
ExecLocal_Withdraw
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecLocal_Withdraw
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
nil
,
nil
return
nil
,
nil
}
}
//ExecLocal_TransferToExec transfer asset to exec local db process
func
(
e
*
Paracross
)
ExecLocal_TransferToExec
(
payload
*
types
.
AssetsTransferToExec
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
ExecLocal_TransferToExec
(
payload
*
types
.
AssetsTransferToExec
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
nil
,
nil
return
nil
,
nil
}
}
plugin/dapp/paracross/executor/paracross.go
View file @
27e5be5f
...
@@ -22,6 +22,7 @@ var (
...
@@ -22,6 +22,7 @@ var (
driverName
=
pt
.
ParaX
driverName
=
pt
.
ParaX
)
)
// Paracross exec
type
Paracross
struct
{
type
Paracross
struct
{
drivers
.
DriverBase
drivers
.
DriverBase
}
}
...
@@ -31,11 +32,13 @@ func init() {
...
@@ -31,11 +32,13 @@ func init() {
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Paracross
{}))
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Paracross
{}))
}
}
//Init paracross exec register
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newParacross
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
Register
(
GetName
(),
newParacross
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
setPrefix
()
setPrefix
()
}
}
//GetName return paracross name
func
GetName
()
string
{
func
GetName
()
string
{
return
newParacross
()
.
GetName
()
return
newParacross
()
.
GetName
()
}
}
...
@@ -47,6 +50,7 @@ func newParacross() drivers.Driver {
...
@@ -47,6 +50,7 @@ func newParacross() drivers.Driver {
return
c
return
c
}
}
// GetDriverName return paracross driver name
func
(
c
*
Paracross
)
GetDriverName
()
string
{
func
(
c
*
Paracross
)
GetDriverName
()
string
{
return
pt
.
ParaX
return
pt
.
ParaX
}
}
...
@@ -157,11 +161,11 @@ func getCommitHeight(payload []byte) (int64, error) {
...
@@ -157,11 +161,11 @@ func getCommitHeight(payload []byte) (int64, error) {
}
}
func
(
c
*
Paracross
)
initLocalAssetTransfer
(
tx
*
types
.
Transaction
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
error
)
{
func
(
c
*
Paracross
)
initLocalAssetTransfer
(
tx
*
types
.
Transaction
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
error
)
{
clog
.
Debug
(
"para execLocal"
,
"tx hash"
,
common
.
Bytes2Hex
(
tx
.
Hash
()),
"action name"
,
log
.
Lazy
{
tx
.
ActionName
})
clog
.
Debug
(
"para execLocal"
,
"tx hash"
,
common
.
Bytes2Hex
(
tx
.
Hash
()),
"action name"
,
log
.
Lazy
{
Fn
:
tx
.
ActionName
})
key
:=
calcLocalAssetKey
(
tx
.
Hash
())
key
:=
calcLocalAssetKey
(
tx
.
Hash
())
if
isDel
{
if
isDel
{
c
.
GetLocalDB
()
.
Set
(
key
,
nil
)
c
.
GetLocalDB
()
.
Set
(
key
,
nil
)
return
&
types
.
KeyValue
{
key
,
nil
},
nil
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
},
nil
}
}
var
payload
pt
.
ParacrossAction
var
payload
pt
.
ParacrossAction
...
@@ -200,14 +204,14 @@ func (c *Paracross) initLocalAssetTransfer(tx *types.Transaction, success, isDel
...
@@ -200,14 +204,14 @@ func (c *Paracross) initLocalAssetTransfer(tx *types.Transaction, success, isDel
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"para execLocal"
,
"set"
,
common
.
Bytes2Hex
(
tx
.
Hash
()),
"failed"
,
err
)
clog
.
Error
(
"para execLocal"
,
"set"
,
common
.
Bytes2Hex
(
tx
.
Hash
()),
"failed"
,
err
)
}
}
return
&
types
.
KeyValue
{
key
,
types
.
Encode
(
&
asset
)},
nil
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
&
asset
)},
nil
}
}
func
(
c
*
Paracross
)
initLocalAssetWithdraw
(
txCommit
,
tx
*
types
.
Transaction
,
isWithdraw
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
error
)
{
func
(
c
*
Paracross
)
initLocalAssetWithdraw
(
txCommit
,
tx
*
types
.
Transaction
,
isWithdraw
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
error
)
{
key
:=
calcLocalAssetKey
(
tx
.
Hash
())
key
:=
calcLocalAssetKey
(
tx
.
Hash
())
if
isDel
{
if
isDel
{
c
.
GetLocalDB
()
.
Set
(
key
,
nil
)
c
.
GetLocalDB
()
.
Set
(
key
,
nil
)
return
&
types
.
KeyValue
{
key
,
nil
},
nil
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
},
nil
}
}
var
asset
pt
.
ParacrossAsset
var
asset
pt
.
ParacrossAsset
...
@@ -254,7 +258,7 @@ func (c *Paracross) initLocalAssetWithdraw(txCommit, tx *types.Transaction, isWi
...
@@ -254,7 +258,7 @@ func (c *Paracross) initLocalAssetWithdraw(txCommit, tx *types.Transaction, isWi
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"para execLocal"
,
"set"
,
""
,
"failed"
,
err
)
clog
.
Error
(
"para execLocal"
,
"set"
,
""
,
"failed"
,
err
)
}
}
return
&
types
.
KeyValue
{
key
,
types
.
Encode
(
&
asset
)},
nil
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
&
asset
)},
nil
}
}
func
(
c
*
Paracross
)
updateLocalAssetTransfer
(
txCommit
,
tx
*
types
.
Transaction
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
error
)
{
func
(
c
*
Paracross
)
updateLocalAssetTransfer
(
txCommit
,
tx
*
types
.
Transaction
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
error
)
{
...
@@ -283,9 +287,10 @@ func (c *Paracross) updateLocalAssetTransfer(txCommit, tx *types.Transaction, su
...
@@ -283,9 +287,10 @@ func (c *Paracross) updateLocalAssetTransfer(txCommit, tx *types.Transaction, su
asset
.
Success
=
false
asset
.
Success
=
false
}
}
c
.
GetLocalDB
()
.
Set
(
key
,
types
.
Encode
(
&
asset
))
c
.
GetLocalDB
()
.
Set
(
key
,
types
.
Encode
(
&
asset
))
return
&
types
.
KeyValue
{
key
,
types
.
Encode
(
&
asset
)},
nil
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
&
asset
)},
nil
}
}
//IsFriend call exec is same seariase exec
func
(
c
*
Paracross
)
IsFriend
(
myexec
,
writekey
[]
byte
,
tx
*
types
.
Transaction
)
bool
{
func
(
c
*
Paracross
)
IsFriend
(
myexec
,
writekey
[]
byte
,
tx
*
types
.
Transaction
)
bool
{
//不允许平行链
//不允许平行链
if
types
.
IsPara
()
{
if
types
.
IsPara
()
{
...
@@ -320,6 +325,7 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error {
...
@@ -320,6 +325,7 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error {
return
types
.
ErrNotAllow
return
types
.
ErrNotAllow
}
}
// Allow add paracross allow rule
func
(
c
*
Paracross
)
Allow
(
tx
*
types
.
Transaction
,
index
int
)
error
{
func
(
c
*
Paracross
)
Allow
(
tx
*
types
.
Transaction
,
index
int
)
error
{
//默认规则
//默认规则
err
:=
c
.
DriverBase
.
Allow
(
tx
,
index
)
err
:=
c
.
DriverBase
.
Allow
(
tx
,
index
)
...
...
plugin/dapp/paracross/executor/paracross_test.go
View file @
27e5be5f
...
@@ -73,8 +73,8 @@ func makeNodeInfo(key, addr string, cnt int) *types.ConfigItem {
...
@@ -73,8 +73,8 @@ func makeNodeInfo(key, addr string, cnt int) *types.ConfigItem {
item
.
Key
=
key
item
.
Key
=
key
item
.
Addr
=
addr
item
.
Addr
=
addr
item
.
Ty
=
mty
.
ConfigItemArrayConfig
item
.
Ty
=
mty
.
ConfigItemArrayConfig
emptyValue
:=
&
types
.
ArrayConfig
{
make
([]
string
,
0
)}
emptyValue
:=
&
types
.
ArrayConfig
{
Value
:
make
([]
string
,
0
)}
arr
:=
types
.
ConfigItem_Arr
{
emptyValue
}
arr
:=
types
.
ConfigItem_Arr
{
Arr
:
emptyValue
}
item
.
Value
=
&
arr
item
.
Value
=
&
arr
for
i
,
n
:=
range
Nodes
{
for
i
,
n
:=
range
Nodes
{
if
i
>=
cnt
{
if
i
>=
cnt
{
...
@@ -132,13 +132,13 @@ func (suite *CommitTestSuite) SetupSuite() {
...
@@ -132,13 +132,13 @@ func (suite *CommitTestSuite) SetupSuite() {
saveTitle
(
suite
.
stateDB
,
calcTitleKey
(
Title
),
&
titleStatus
)
saveTitle
(
suite
.
stateDB
,
calcTitleKey
(
Title
),
&
titleStatus
)
// setup api
// setup api
hashes
:=
&
types
.
ReqHashes
{[][]
byte
{
MainBlockHash10
}}
hashes
:=
&
types
.
ReqHashes
{
Hashes
:
[][]
byte
{
MainBlockHash10
}}
suite
.
api
.
On
(
"GetBlockByHashes"
,
hashes
)
.
Return
(
suite
.
api
.
On
(
"GetBlockByHashes"
,
hashes
)
.
Return
(
&
types
.
BlockDetails
{
&
types
.
BlockDetails
{
Items
:
[]
*
types
.
BlockDetail
{
blockDetail
},
Items
:
[]
*
types
.
BlockDetail
{
blockDetail
},
},
nil
)
},
nil
)
suite
.
api
.
On
(
"GetBlockHash"
,
&
types
.
ReqInt
{
MainBlockHeight
})
.
Return
(
suite
.
api
.
On
(
"GetBlockHash"
,
&
types
.
ReqInt
{
Height
:
MainBlockHeight
})
.
Return
(
&
types
.
ReplyHash
{
MainBlockHash10
},
nil
)
&
types
.
ReplyHash
{
Hash
:
MainBlockHash10
},
nil
)
}
}
func
(
suite
*
CommitTestSuite
)
TestSetup
()
{
func
(
suite
*
CommitTestSuite
)
TestSetup
()
{
...
@@ -153,19 +153,19 @@ func (suite *CommitTestSuite) TestSetup() {
...
@@ -153,19 +153,19 @@ func (suite *CommitTestSuite) TestSetup() {
func
fillRawCommitTx
(
suite
suite
.
Suite
)
(
*
types
.
Transaction
,
error
)
{
func
fillRawCommitTx
(
suite
suite
.
Suite
)
(
*
types
.
Transaction
,
error
)
{
st1
:=
pt
.
ParacrossNodeStatus
{
st1
:=
pt
.
ParacrossNodeStatus
{
MainBlockHash10
,
MainBlockHash
:
MainBlockHash
10
,
MainBlockHeight
,
MainBlockHeight
:
MainBlockHeight
,
Title
,
Title
:
Title
,
TitleHeight
,
Height
:
TitleHeight
,
[]
byte
(
"block-hash-9"
),
PreBlockHash
:
[]
byte
(
"block-hash-9"
),
[]
byte
(
"block-hash-10"
),
BlockHash
:
[]
byte
(
"block-hash-10"
),
[]
byte
(
"state-hash-9"
),
PreStateHash
:
[]
byte
(
"state-hash-9"
),
[]
byte
(
"state-hash-10"
),
StateHash
:
[]
byte
(
"state-hash-10"
),
10
,
TxCounts
:
10
,
[]
byte
(
"abc"
),
TxResult
:
[]
byte
(
"abc"
),
[][]
byte
{},
TxHashs
:
[][]
byte
{},
[]
byte
(
"abc"
),
CrossTxResult
:
[]
byte
(
"abc"
),
[][]
byte
{},
CrossTxHashs
:
[][]
byte
{},
}
}
tx
,
err
:=
pt
.
CreateRawCommitTx4MainChain
(
&
st1
,
pt
.
ParaX
,
0
)
tx
,
err
:=
pt
.
CreateRawCommitTx4MainChain
(
&
st1
,
pt
.
ParaX
,
0
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -370,9 +370,9 @@ type VoteTestSuite struct {
...
@@ -370,9 +370,9 @@ type VoteTestSuite struct {
exec
*
Paracross
exec
*
Paracross
}
}
func
(
s
uite
*
VoteTestSuite
)
SetupSuite
()
{
func
(
s
*
VoteTestSuite
)
SetupSuite
()
{
types
.
Init
(
Title
,
nil
)
types
.
Init
(
Title
,
nil
)
s
uite
.
exec
=
newParacross
()
.
(
*
Paracross
)
s
.
exec
=
newParacross
()
.
(
*
Paracross
)
}
}
func
(
s
*
VoteTestSuite
)
TestVoteTx
()
{
func
(
s
*
VoteTestSuite
)
TestVoteTx
()
{
...
...
plugin/dapp/paracross/executor/query.go
View file @
27e5be5f
...
@@ -11,41 +11,45 @@ import (
...
@@ -11,41 +11,45 @@ import (
"github.com/pkg/errors"
"github.com/pkg/errors"
)
)
func
(
e
*
Paracross
)
Query_GetTitle
(
in
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
// Query_GetTitle query paracross title
func
(
p
*
Paracross
)
Query_GetTitle
(
in
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
if
in
==
nil
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
return
e
.
P
aracrossGetHeight
(
in
.
GetData
())
return
p
.
p
aracrossGetHeight
(
in
.
GetData
())
}
}
func
(
e
*
Paracross
)
Query_ListTitles
(
in
*
types
.
ReqNil
)
(
types
.
Message
,
error
)
{
//Query_ListTitles query paracross titles list
return
e
.
ParacrossListTitles
()
func
(
p
*
Paracross
)
Query_ListTitles
(
in
*
types
.
ReqNil
)
(
types
.
Message
,
error
)
{
return
p
.
paracrossListTitles
()
}
}
func
(
e
*
Paracross
)
Query_GetTitleHeight
(
in
*
pt
.
ReqParacrossTitleHeight
)
(
types
.
Message
,
error
)
{
// Query_GetTitleHeight query title height
func
(
p
*
Paracross
)
Query_GetTitleHeight
(
in
*
pt
.
ReqParacrossTitleHeight
)
(
types
.
Message
,
error
)
{
if
in
==
nil
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
return
e
.
P
aracrossGetTitleHeight
(
in
.
Title
,
in
.
Height
)
return
p
.
p
aracrossGetTitleHeight
(
in
.
Title
,
in
.
Height
)
}
}
func
(
e
*
Paracross
)
Query_GetAssetTxResult
(
in
*
types
.
ReqHash
)
(
types
.
Message
,
error
)
{
// Query_GetAssetTxResult query get asset tx reseult
func
(
p
*
Paracross
)
Query_GetAssetTxResult
(
in
*
types
.
ReqHash
)
(
types
.
Message
,
error
)
{
if
in
==
nil
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
return
e
.
P
aracrossGetAssetTxResult
(
in
.
Hash
)
return
p
.
p
aracrossGetAssetTxResult
(
in
.
Hash
)
}
}
func
(
c
*
Paracross
)
P
aracrossGetHeight
(
title
string
)
(
types
.
Message
,
error
)
{
func
(
p
*
Paracross
)
p
aracrossGetHeight
(
title
string
)
(
types
.
Message
,
error
)
{
ret
,
err
:=
getTitle
(
c
.
GetStateDB
(),
calcTitleKey
(
title
))
ret
,
err
:=
getTitle
(
p
.
GetStateDB
(),
calcTitleKey
(
title
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Cause
(
err
)
return
nil
,
errors
.
Cause
(
err
)
}
}
return
ret
,
nil
return
ret
,
nil
}
}
func
(
c
*
Paracross
)
P
aracrossListTitles
()
(
types
.
Message
,
error
)
{
func
(
p
*
Paracross
)
p
aracrossListTitles
()
(
types
.
Message
,
error
)
{
return
listLocalTitles
(
c
.
GetLocalDB
())
return
listLocalTitles
(
p
.
GetLocalDB
())
}
}
func
listLocalTitles
(
db
dbm
.
KVDB
)
(
types
.
Message
,
error
)
{
func
listLocalTitles
(
db
dbm
.
KVDB
)
(
types
.
Message
,
error
)
{
...
@@ -80,17 +84,17 @@ func loadLocalTitle(db dbm.KV, title string, height int64) (types.Message, error
...
@@ -80,17 +84,17 @@ func loadLocalTitle(db dbm.KV, title string, height int64) (types.Message, error
return
&
resp
,
nil
return
&
resp
,
nil
}
}
func
(
c
*
Paracross
)
P
aracrossGetTitleHeight
(
title
string
,
height
int64
)
(
types
.
Message
,
error
)
{
func
(
p
*
Paracross
)
p
aracrossGetTitleHeight
(
title
string
,
height
int64
)
(
types
.
Message
,
error
)
{
return
loadLocalTitle
(
c
.
GetLocalDB
(),
title
,
height
)
return
loadLocalTitle
(
p
.
GetLocalDB
(),
title
,
height
)
}
}
func
(
c
*
Paracross
)
P
aracrossGetAssetTxResult
(
hash
[]
byte
)
(
types
.
Message
,
error
)
{
func
(
p
*
Paracross
)
p
aracrossGetAssetTxResult
(
hash
[]
byte
)
(
types
.
Message
,
error
)
{
if
len
(
hash
)
==
0
{
if
len
(
hash
)
==
0
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
key
:=
calcLocalAssetKey
(
hash
)
key
:=
calcLocalAssetKey
(
hash
)
value
,
err
:=
c
.
GetLocalDB
()
.
Get
(
key
)
value
,
err
:=
p
.
GetLocalDB
()
.
Get
(
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
plugin/dapp/paracross/rpc/rpc.go
View file @
27e5be5f
...
@@ -22,6 +22,7 @@ func (c *channelClient) GetTitle(ctx context.Context, req *types.ReqString) (*pt
...
@@ -22,6 +22,7 @@ func (c *channelClient) GetTitle(ctx context.Context, req *types.ReqString) (*pt
return
nil
,
types
.
ErrDecode
return
nil
,
types
.
ErrDecode
}
}
// GetHeight jrpc get consensus height
func
(
c
*
Jrpc
)
GetHeight
(
req
*
types
.
ReqString
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
GetHeight
(
req
*
types
.
ReqString
,
result
*
interface
{})
error
{
if
req
==
nil
{
if
req
==
nil
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
...
@@ -42,6 +43,7 @@ func (c *channelClient) ListTitles(ctx context.Context, req *types.ReqNil) (*pt.
...
@@ -42,6 +43,7 @@ func (c *channelClient) ListTitles(ctx context.Context, req *types.ReqNil) (*pt.
return
nil
,
types
.
ErrDecode
return
nil
,
types
.
ErrDecode
}
}
// ListTitles get paracross consensus titles list
func
(
c
*
Jrpc
)
ListTitles
(
req
*
types
.
ReqNil
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
ListTitles
(
req
*
types
.
ReqNil
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
ListTitles
(
context
.
Background
(),
req
)
data
,
err
:=
c
.
cli
.
ListTitles
(
context
.
Background
(),
req
)
*
result
=
data
*
result
=
data
...
@@ -59,6 +61,7 @@ func (c *channelClient) GetTitleHeight(ctx context.Context, req *pt.ReqParacross
...
@@ -59,6 +61,7 @@ func (c *channelClient) GetTitleHeight(ctx context.Context, req *pt.ReqParacross
return
nil
,
types
.
ErrDecode
return
nil
,
types
.
ErrDecode
}
}
// GetTitleHeight get consensus title height
func
(
c
*
Jrpc
)
GetTitleHeight
(
req
*
pt
.
ReqParacrossTitleHeight
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
GetTitleHeight
(
req
*
pt
.
ReqParacrossTitleHeight
,
result
*
interface
{})
error
{
if
req
==
nil
{
if
req
==
nil
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
...
@@ -79,6 +82,7 @@ func (c *channelClient) GetAssetTxResult(ctx context.Context, req *types.ReqHash
...
@@ -79,6 +82,7 @@ func (c *channelClient) GetAssetTxResult(ctx context.Context, req *types.ReqHash
return
nil
,
types
.
ErrDecode
return
nil
,
types
.
ErrDecode
}
}
// GetAssetTxResult get asset tx result
func
(
c
*
Jrpc
)
GetAssetTxResult
(
req
*
types
.
ReqHash
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
GetAssetTxResult
(
req
*
types
.
ReqHash
,
result
*
interface
{})
error
{
if
req
==
nil
{
if
req
==
nil
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
...
...
plugin/dapp/paracross/rpc/types.go
View file @
27e5be5f
...
@@ -9,10 +9,12 @@ import (
...
@@ -9,10 +9,12 @@ import (
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
)
)
// Jrpc paracross jrpc interface
type
Jrpc
struct
{
type
Jrpc
struct
{
cli
*
channelClient
cli
*
channelClient
}
}
// Grpc paracross Grpc interface
type
Grpc
struct
{
type
Grpc
struct
{
*
channelClient
*
channelClient
}
}
...
@@ -21,6 +23,7 @@ type channelClient struct {
...
@@ -21,6 +23,7 @@ type channelClient struct {
types
.
ChannelClient
types
.
ChannelClient
}
}
// Init paracross rpc register
func
Init
(
name
string
,
s
types
.
RPCServer
)
{
func
Init
(
name
string
,
s
types
.
RPCServer
)
{
cli
:=
&
channelClient
{}
cli
:=
&
channelClient
{}
grpc
:=
&
Grpc
{
channelClient
:
cli
}
grpc
:=
&
Grpc
{
channelClient
:
cli
}
...
...
plugin/dapp/paracross/types/errors.go
View file @
27e5be5f
...
@@ -7,12 +7,20 @@ package types
...
@@ -7,12 +7,20 @@ package types
import
"errors"
import
"errors"
var
(
var
(
ErrInvalidTitle
=
errors
.
New
(
"ErrInvalidTitle"
)
// ErrInvalidTitle invalid commit msg title
ErrTitleNotExist
=
errors
.
New
(
"ErrTitleNotExist"
)
ErrInvalidTitle
=
errors
.
New
(
"ErrInvalidTitle"
)
ErrNodeNotForTheTitle
=
errors
.
New
(
"ErrNodeNotForTheTitle"
)
// ErrTitleNotExist commit msg title not exist
ErrTitleNotExist
=
errors
.
New
(
"ErrTitleNotExist"
)
// ErrNodeNotForTheTitle the node not match with title
ErrNodeNotForTheTitle
=
errors
.
New
(
"ErrNodeNotForTheTitle"
)
// ErrParaBlockHashNoMatch block hash not match with before
ErrParaBlockHashNoMatch
=
errors
.
New
(
"ErrParaBlockHashNoMatch"
)
ErrParaBlockHashNoMatch
=
errors
.
New
(
"ErrParaBlockHashNoMatch"
)
ErrParaMinerBaseIndex
=
errors
.
New
(
"ErrParaMinerBaseIndex"
)
// ErrParaMinerBaseIndex miner base index not 0
ErrParaMinerTxType
=
errors
.
New
(
"ErrParaMinerTxType"
)
ErrParaMinerBaseIndex
=
errors
.
New
(
"ErrParaMinerBaseIndex"
)
ErrParaEmptyMinerTx
=
errors
.
New
(
"ErrParaEmptyMinerTx"
)
// ErrParaMinerTxType the 0 tx is not miner tx
ErrParaMinerExecErr
=
errors
.
New
(
"ErrParaMinerExecErr"
)
ErrParaMinerTxType
=
errors
.
New
(
"ErrParaMinerTxType"
)
// ErrParaEmptyMinerTx block no miner tx
ErrParaEmptyMinerTx
=
errors
.
New
(
"ErrParaEmptyMinerTx"
)
// ErrParaMinerExecErr miner tx exec error
ErrParaMinerExecErr
=
errors
.
New
(
"ErrParaMinerExecErr"
)
)
)
plugin/dapp/paracross/types/paracross.go
View file @
27e5be5f
...
@@ -14,72 +14,97 @@ import (
...
@@ -14,72 +14,97 @@ import (
var
tlog
=
log15
.
New
(
"module"
,
ParaX
)
var
tlog
=
log15
.
New
(
"module"
,
ParaX
)
// paracross 执行器的日志类型
const
(
const
(
// paracross 执行器的日志类型
TyLogParacrossCommit
=
650
// TyLogParacrossCommit commit log key
TyLogParacrossCommit
=
650
// TyLogParacrossCommitDone commit down key
TyLogParacrossCommitDone
=
651
TyLogParacrossCommitDone
=
651
// record 和 commit 不一样, 对应高度完成共识后收到commit 交易
// record 和 commit 不一样, 对应高度完成共识后收到commit 交易
// 这个交易就不参与共识, 只做记录
// 这个交易就不参与共识, 只做记录
// TyLogParacrossCommitRecord commit record key
TyLogParacrossCommitRecord
=
652
TyLogParacrossCommitRecord
=
652
TyLogParaAssetTransfer
=
653
// TyLogParaAssetTransfer asset transfer log key
TyLogParaAssetWithdraw
=
654
TyLogParaAssetTransfer
=
653
// TyLogParaAssetWithdraw asset withdraw log key
TyLogParaAssetWithdraw
=
654
//在平行链上保存节点参与共识的数据
//在平行链上保存节点参与共识的数据
TyLogParacrossMiner
=
655
// TyLogParacrossMiner miner log key
TyLogParacrossMiner
=
655
// TyLogParaAssetDeposit asset deposit log key
TyLogParaAssetDeposit
=
656
TyLogParaAssetDeposit
=
656
)
)
type
P
aracrossCommitTx
struct
{
type
p
aracrossCommitTx
struct
{
Fee
int64
`json:"fee"`
Fee
int64
`json:"fee"`
Status
ParacrossNodeStatus
`json:"status"`
Status
ParacrossNodeStatus
`json:"status"`
}
}
// action type
// action type
const
(
const
(
// ParacrossActionCommit paracross consensus commit action
ParacrossActionCommit
=
iota
ParacrossActionCommit
=
iota
// ParacrossActionMiner paracross consensus miner action
ParacrossActionMiner
ParacrossActionMiner
// ParacrossActionTransfer paracross asset transfer action
ParacrossActionTransfer
ParacrossActionTransfer
// ParacrossActionWithdraw paracross asset withdraw action
ParacrossActionWithdraw
ParacrossActionWithdraw
// ParacrossActionTransferToExec asset transfer to exec
ParacrossActionTransferToExec
ParacrossActionTransferToExec
)
)
const
(
const
(
P
araCrossTransferActionTypeStart
=
10000
p
araCrossTransferActionTypeStart
=
10000
P
araCrossTransferActionTypeEnd
=
10100
//p
araCrossTransferActionTypeEnd = 10100
)
)
const
(
const
(
ParacrossActionAssetTransfer
=
iota
+
ParaCrossTransferActionTypeStart
// ParacrossActionAssetTransfer paracross asset transfer key
ParacrossActionAssetTransfer
=
iota
+
paraCrossTransferActionTypeStart
// ParacrossActionAssetWithdraw paracross asset withdraw key
ParacrossActionAssetWithdraw
ParacrossActionAssetWithdraw
)
)
// status
// status
const
(
const
(
// ParacrossStatusCommiting commit status
ParacrossStatusCommiting
=
iota
ParacrossStatusCommiting
=
iota
// ParacrossStatusCommitDone commit done status
ParacrossStatusCommitDone
ParacrossStatusCommitDone
)
)
var
(
var
(
ParacrossActionCommitStr
=
string
(
"Commit"
)
// ParacrossActionCommitStr Commit string
ParacrossTransferPerfix
=
"crossPara."
ParacrossActionCommitStr
=
string
(
"Commit"
)
ParacrossActionAssetTransferStr
=
ParacrossTransferPerfix
+
string
(
"AssetTransfer"
)
paracrossTransferPerfix
=
"crossPara."
ParacrossActionAssetWithdrawStr
=
ParacrossTransferPerfix
+
string
(
"AssetWithdraw"
)
// ParacrossActionAssetTransferStr asset transfer key
ParacrossActionTransferStr
=
ParacrossTransferPerfix
+
string
(
"Transfer"
)
ParacrossActionAssetTransferStr
=
paracrossTransferPerfix
+
string
(
"AssetTransfer"
)
ParacrossActionTransferToExecStr
=
ParacrossTransferPerfix
+
string
(
"TransferToExec"
)
// ParacrossActionAssetWithdrawStr asset withdraw key
ParacrossActionWithdrawStr
=
ParacrossTransferPerfix
+
string
(
"Withdraw"
)
ParacrossActionAssetWithdrawStr
=
paracrossTransferPerfix
+
string
(
"AssetWithdraw"
)
// ParacrossActionTransferStr trasfer key
ParacrossActionTransferStr
=
paracrossTransferPerfix
+
string
(
"Transfer"
)
// ParacrossActionTransferToExecStr transfer to exec key
ParacrossActionTransferToExecStr
=
paracrossTransferPerfix
+
string
(
"TransferToExec"
)
// ParacrossActionWithdrawStr withdraw key
ParacrossActionWithdrawStr
=
paracrossTransferPerfix
+
string
(
"Withdraw"
)
)
)
// CalcMinerHeightKey get miner key
func
CalcMinerHeightKey
(
title
string
,
height
int64
)
[]
byte
{
func
CalcMinerHeightKey
(
title
string
,
height
int64
)
[]
byte
{
paraVoteHeightKey
:=
"LODB-paracross-titleVoteHeight-"
paraVoteHeightKey
:=
"LODB-paracross-titleVoteHeight-"
return
[]
byte
(
fmt
.
Sprintf
(
paraVoteHeightKey
+
"%s-%012d"
,
title
,
height
))
return
[]
byte
(
fmt
.
Sprintf
(
paraVoteHeightKey
+
"%s-%012d"
,
title
,
height
))
}
}
// CreateRawCommitTx4MainChain create commit tx to main chain
func
CreateRawCommitTx4MainChain
(
status
*
ParacrossNodeStatus
,
name
string
,
fee
int64
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawCommitTx4MainChain
(
status
*
ParacrossNodeStatus
,
name
string
,
fee
int64
)
(
*
types
.
Transaction
,
error
)
{
return
createRawCommitTx
(
status
,
name
,
fee
)
return
createRawCommitTx
(
status
,
name
,
fee
)
}
}
func
CreateRawParacrossCommitTx
(
parm
*
P
aracrossCommitTx
)
(
*
types
.
Transaction
,
error
)
{
func
createRawParacrossCommitTx
(
parm
*
p
aracrossCommitTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
if
parm
==
nil
{
tlog
.
Error
(
"
C
reateRawParacrossCommitTx"
,
"parm"
,
parm
)
tlog
.
Error
(
"
c
reateRawParacrossCommitTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
return
createRawCommitTx
(
&
parm
.
Status
,
types
.
ExecName
(
ParaX
),
parm
.
Fee
)
return
createRawCommitTx
(
&
parm
.
Status
,
types
.
ExecName
(
ParaX
),
parm
.
Fee
)
...
@@ -106,6 +131,7 @@ func createRawCommitTx(status *ParacrossNodeStatus, name string, fee int64) (*ty
...
@@ -106,6 +131,7 @@ func createRawCommitTx(status *ParacrossNodeStatus, name string, fee int64) (*ty
return
tx
,
nil
return
tx
,
nil
}
}
// CreateRawAssetTransferTx create asset transfer tx
func
CreateRawAssetTransferTx
(
param
*
types
.
CreateTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawAssetTransferTx
(
param
*
types
.
CreateTx
)
(
*
types
.
Transaction
,
error
)
{
// 跨链交易需要在主链和平行链上执行, 所以应该可以在主链和平行链上构建
// 跨链交易需要在主链和平行链上执行, 所以应该可以在主链和平行链上构建
if
!
types
.
IsParaExecName
(
param
.
GetExecName
())
{
if
!
types
.
IsParaExecName
(
param
.
GetExecName
())
{
...
@@ -138,6 +164,7 @@ func CreateRawAssetTransferTx(param *types.CreateTx) (*types.Transaction, error)
...
@@ -138,6 +164,7 @@ func CreateRawAssetTransferTx(param *types.CreateTx) (*types.Transaction, error)
return
tx
,
nil
return
tx
,
nil
}
}
// CreateRawMinerTx create miner tx
func
CreateRawMinerTx
(
status
*
ParacrossNodeStatus
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawMinerTx
(
status
*
ParacrossNodeStatus
)
(
*
types
.
Transaction
,
error
)
{
v
:=
&
ParacrossMinerAction
{
v
:=
&
ParacrossMinerAction
{
Status
:
status
,
Status
:
status
,
...
@@ -159,6 +186,7 @@ func CreateRawMinerTx(status *ParacrossNodeStatus) (*types.Transaction, error) {
...
@@ -159,6 +186,7 @@ func CreateRawMinerTx(status *ParacrossNodeStatus) (*types.Transaction, error) {
return
tx
,
nil
return
tx
,
nil
}
}
// CreateRawTransferTx create paracross asset transfer tx with transfer and withdraw
func
CreateRawTransferTx
(
param
*
types
.
CreateTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTransferTx
(
param
*
types
.
CreateTx
)
(
*
types
.
Transaction
,
error
)
{
if
!
types
.
IsParaExecName
(
param
.
GetExecName
())
{
if
!
types
.
IsParaExecName
(
param
.
GetExecName
())
{
tlog
.
Error
(
"CreateRawTransferTx"
,
"exec"
,
param
.
GetExecName
())
tlog
.
Error
(
"CreateRawTransferTx"
,
"exec"
,
param
.
GetExecName
())
...
...
plugin/dapp/paracross/types/type.go
View file @
27e5be5f
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
)
)
var
(
var
(
// ParaX paracross exec name
ParaX
=
"paracross"
ParaX
=
"paracross"
glog
=
log
.
New
(
"module"
,
ParaX
)
glog
=
log
.
New
(
"module"
,
ParaX
)
...
@@ -30,9 +31,9 @@ var (
...
@@ -30,9 +31,9 @@ var (
// init query rpc
// init query rpc
/* TODO-TODO
/* TODO-TODO
types.RegisterRPCQueryHandle("ParacrossGetTitle", &ParacrossGetTitle{})
types.RegisterRPCQueryHandle("ParacrossGetTitle", &ParacrossGetTitle{})
types.RegisterRPCQueryHandle("
ParacrossListTitles", &P
aracrossListTitles{})
types.RegisterRPCQueryHandle("
paracrossListTitles", &p
aracrossListTitles{})
types.RegisterRPCQueryHandle("
ParacrossGetTitleHeight", &P
aracrossGetTitleHeight{})
types.RegisterRPCQueryHandle("
paracrossGetTitleHeight", &p
aracrossGetTitleHeight{})
types.RegisterRPCQueryHandle("
ParacrossGetAssetTxResult", &P
aracrossGetAssetTxResult{})
types.RegisterRPCQueryHandle("
paracrossGetAssetTxResult", &p
aracrossGetAssetTxResult{})
*/
*/
)
)
...
@@ -43,21 +44,25 @@ func init() {
...
@@ -43,21 +44,25 @@ func init() {
types
.
RegisterDappFork
(
ParaX
,
"Enable"
,
0
)
types
.
RegisterDappFork
(
ParaX
,
"Enable"
,
0
)
}
}
// GetExecName get para exec name
func
GetExecName
()
string
{
func
GetExecName
()
string
{
return
types
.
ExecName
(
ParaX
)
return
types
.
ExecName
(
ParaX
)
}
}
// ParacrossType base paracross type
type
ParacrossType
struct
{
type
ParacrossType
struct
{
types
.
ExecTypeBase
types
.
ExecTypeBase
}
}
// NewType get paracross type
func
NewType
()
*
ParacrossType
{
func
NewType
()
*
ParacrossType
{
c
:=
&
ParacrossType
{}
c
:=
&
ParacrossType
{}
c
.
SetChild
(
c
)
c
.
SetChild
(
c
)
return
c
return
c
}
}
func
(
at
*
ParacrossType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
// GetLogMap get receipt log map
func
(
p
*
ParacrossType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
return
map
[
int64
]
*
types
.
LogInfo
{
return
map
[
int64
]
*
types
.
LogInfo
{
TyLogParacrossCommit
:
{
reflect
.
TypeOf
(
ReceiptParacrossCommit
{}),
"LogParacrossCommit"
},
TyLogParacrossCommit
:
{
reflect
.
TypeOf
(
ReceiptParacrossCommit
{}),
"LogParacrossCommit"
},
TyLogParacrossCommitDone
:
{
reflect
.
TypeOf
(
ReceiptParacrossDone
{}),
"LogParacrossCommitDone"
},
TyLogParacrossCommitDone
:
{
reflect
.
TypeOf
(
ReceiptParacrossDone
{}),
"LogParacrossCommitDone"
},
...
@@ -69,7 +74,8 @@ func (at *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
...
@@ -69,7 +74,8 @@ func (at *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
}
}
}
}
func
(
t
*
ParacrossType
)
GetTypeMap
()
map
[
string
]
int32
{
// GetTypeMap get action type
func
(
p
*
ParacrossType
)
GetTypeMap
()
map
[
string
]
int32
{
return
map
[
string
]
int32
{
return
map
[
string
]
int32
{
"Commit"
:
ParacrossActionCommit
,
"Commit"
:
ParacrossActionCommit
,
"Miner"
:
ParacrossActionMiner
,
"Miner"
:
ParacrossActionMiner
,
...
@@ -81,20 +87,22 @@ func (t *ParacrossType) GetTypeMap() map[string]int32 {
...
@@ -81,20 +87,22 @@ func (t *ParacrossType) GetTypeMap() map[string]int32 {
}
}
}
}
func
(
b
*
ParacrossType
)
GetPayload
()
types
.
Message
{
// GetPayload paracross get action payload
func
(
p
*
ParacrossType
)
GetPayload
()
types
.
Message
{
return
&
ParacrossAction
{}
return
&
ParacrossAction
{}
}
}
func
(
m
ParacrossType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
// CreateTx paracross create tx by different action
func
(
p
ParacrossType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
if
action
==
"ParacrossCommit"
{
if
action
==
"ParacrossCommit"
{
var
param
P
aracrossCommitTx
var
param
p
aracrossCommitTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
glog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
return
C
reateRawParacrossCommitTx
(
&
param
)
return
c
reateRawParacrossCommitTx
(
&
param
)
}
else
if
action
==
"ParacrossAssetTransfer"
||
action
==
"ParacrossAssetWithdraw"
{
}
else
if
action
==
"ParacrossAssetTransfer"
||
action
==
"ParacrossAssetWithdraw"
{
var
param
types
.
CreateTx
var
param
types
.
CreateTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
@@ -117,175 +125,3 @@ func (m ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
...
@@ -117,175 +125,3 @@ func (m ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
return
nil
,
types
.
ErrNotSupport
return
nil
,
types
.
ErrNotSupport
}
}
type
ParacrossCommitLog
struct
{
}
func
(
l
ParacrossCommitLog
)
Name
()
string
{
return
"LogParacrossCommit"
}
func
(
l
ParacrossCommitLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptParacrossCommit
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
err
}
type
ParacrossDoneLog
struct
{
}
func
(
l
ParacrossDoneLog
)
Name
()
string
{
return
"LogParacrossDone"
}
func
(
l
ParacrossDoneLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptParacrossDone
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
err
}
type
ParacrossCommitRecordLog
struct
{
}
func
(
l
ParacrossCommitRecordLog
)
Name
()
string
{
return
"LogParacrossCommitRecord"
}
func
(
l
ParacrossCommitRecordLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptParacrossRecord
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
err
}
type
ParacrossAssetWithdrawLog
struct
{
}
func
(
l
ParacrossAssetWithdrawLog
)
Name
()
string
{
return
"LogParacrossAssetWithdraw"
}
func
(
l
ParacrossAssetWithdrawLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
types
.
ReceiptAccountTransfer
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
err
}
type
ParacrossAssetTransferLog
struct
{
}
func
(
l
ParacrossAssetTransferLog
)
Name
()
string
{
return
"LogParacrossAssetTransfer"
}
func
(
l
ParacrossAssetTransferLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
types
.
ReceiptAccountTransfer
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
err
}
type
ParacrossMinerLog
struct
{
}
func
(
l
ParacrossMinerLog
)
Name
()
string
{
return
"LogParaMiner"
}
func
(
l
ParacrossMinerLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptParacrossMiner
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
err
}
type
ParacrossAssetDepositLog
struct
{
}
func
(
l
ParacrossAssetDepositLog
)
Name
()
string
{
return
"LogParacrossAssetDeposit"
}
func
(
l
ParacrossAssetDepositLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
types
.
ReceiptAccountTransfer
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
nil
}
type
ParacrossGetTitle
struct
{
}
func
(
t
*
ParacrossGetTitle
)
JsonToProto
(
message
json
.
RawMessage
)
([]
byte
,
error
)
{
var
req
types
.
ReqString
err
:=
json
.
Unmarshal
(
message
,
&
req
)
if
err
!=
nil
{
return
nil
,
err
}
return
types
.
Encode
(
&
req
),
nil
}
func
(
t
*
ParacrossGetTitle
)
ProtoToJson
(
reply
*
types
.
Message
)
(
interface
{},
error
)
{
return
reply
,
nil
}
type
ParacrossListTitles
struct
{
}
func
(
t
*
ParacrossListTitles
)
JsonToProto
(
message
json
.
RawMessage
)
([]
byte
,
error
)
{
var
req
types
.
ReqNil
return
types
.
Encode
(
&
req
),
nil
}
func
(
t
*
ParacrossListTitles
)
ProtoToJson
(
reply
*
types
.
Message
)
(
interface
{},
error
)
{
return
reply
,
nil
}
type
ParacrossGetTitleHeight
struct
{
}
func
(
t
*
ParacrossGetTitleHeight
)
JsonToProto
(
message
json
.
RawMessage
)
([]
byte
,
error
)
{
var
req
ReqParacrossTitleHeight
err
:=
json
.
Unmarshal
(
message
,
&
req
)
if
err
!=
nil
{
return
nil
,
err
}
return
types
.
Encode
(
&
req
),
nil
}
func
(
t
*
ParacrossGetTitleHeight
)
ProtoToJson
(
reply
*
types
.
Message
)
(
interface
{},
error
)
{
return
reply
,
nil
}
type
ParacrossGetAssetTxResult
struct
{
}
func
(
t
*
ParacrossGetAssetTxResult
)
JsonToProto
(
message
json
.
RawMessage
)
([]
byte
,
error
)
{
var
req
types
.
ReqHash
err
:=
json
.
Unmarshal
(
message
,
&
req
)
if
err
!=
nil
{
return
nil
,
err
}
return
types
.
Encode
(
&
req
),
nil
}
func
(
t
*
ParacrossGetAssetTxResult
)
ProtoToJson
(
reply
*
types
.
Message
)
(
interface
{},
error
)
{
return
reply
,
nil
}
plugin/dapp/relay/cmd/relayd/relayd/db.go
View file @
27e5be5f
...
@@ -26,7 +26,6 @@ type relaydDB struct {
...
@@ -26,7 +26,6 @@ type relaydDB struct {
db
db
.
DB
db
db
.
DB
}
}
func
newRelayDB
(
name
string
,
dir
string
,
cache
int32
)
*
relaydDB
{
func
newRelayDB
(
name
string
,
dir
string
,
cache
int32
)
*
relaydDB
{
d
:=
db
.
NewDB
(
name
,
"goleveldb"
,
dir
,
cache
)
d
:=
db
.
NewDB
(
name
,
"goleveldb"
,
dir
,
cache
)
return
&
relaydDB
{
d
}
return
&
relaydDB
{
d
}
...
...
plugin/dapp/relay/executor/relay.go
View file @
27e5be5f
...
@@ -225,20 +225,20 @@ func getCreateOrderKeyValue(kv []*types.KeyValue, order *ty.RelayOrder, status i
...
@@ -225,20 +225,20 @@ func getCreateOrderKeyValue(kv []*types.KeyValue, order *ty.RelayOrder, status i
func
deleteCreateOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
order
*
ty
.
RelayOrder
,
status
int32
)
[]
*
types
.
KeyValue
{
func
deleteCreateOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
order
*
ty
.
RelayOrder
,
status
int32
)
[]
*
types
.
KeyValue
{
key
:=
calcOrderKeyStatus
(
order
,
status
)
key
:=
calcOrderKeyStatus
(
order
,
status
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
key
=
calcOrderKeyCoin
(
order
,
status
)
key
=
calcOrderKeyCoin
(
order
,
status
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
key
=
calcOrderKeyAddrStatus
(
order
,
status
)
key
=
calcOrderKeyAddrStatus
(
order
,
status
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
key
=
calcOrderKeyAddrCoin
(
order
,
status
)
key
=
calcOrderKeyAddrCoin
(
order
,
status
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
key
=
calcAcceptKeyAddr
(
order
,
status
)
key
=
calcAcceptKeyAddr
(
order
,
status
)
if
key
!=
nil
{
if
key
!=
nil
{
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
}
}
return
kv
return
kv
...
...
plugin/dapp/relay/executor/relay_test.go
View file @
27e5be5f
...
@@ -129,7 +129,7 @@ func (s *suiteRelay) TestExec_1() {
...
@@ -129,7 +129,7 @@ func (s *suiteRelay) TestExec_1() {
sell
:=
&
ty
.
RelayAction
{
sell
:=
&
ty
.
RelayAction
{
Ty
:
ty
.
RelayActionCreate
,
Ty
:
ty
.
RelayActionCreate
,
Value
:
&
ty
.
RelayAction_Create
{
Create
:
order
},
Value
:
&
ty
.
RelayAction_Create
{
Create
:
order
},
}
}
tx
:=
&
types
.
Transaction
{}
tx
:=
&
types
.
Transaction
{}
...
@@ -140,7 +140,7 @@ func (s *suiteRelay) TestExec_1() {
...
@@ -140,7 +140,7 @@ func (s *suiteRelay) TestExec_1() {
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
...
@@ -172,7 +172,7 @@ func (s *suiteRelay) TestExec_2() {
...
@@ -172,7 +172,7 @@ func (s *suiteRelay) TestExec_2() {
sell
:=
&
ty
.
RelayAction
{
sell
:=
&
ty
.
RelayAction
{
Ty
:
ty
.
RelayActionAccept
,
Ty
:
ty
.
RelayActionAccept
,
Value
:
&
ty
.
RelayAction_Accept
{
Accept
:
order
},
Value
:
&
ty
.
RelayAction_Accept
{
Accept
:
order
},
}
}
tx
:=
&
types
.
Transaction
{}
tx
:=
&
types
.
Transaction
{}
...
@@ -181,7 +181,7 @@ func (s *suiteRelay) TestExec_2() {
...
@@ -181,7 +181,7 @@ func (s *suiteRelay) TestExec_2() {
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
s
.
relay
.
SetEnv
(
20
,
2000
,
1
)
s
.
relay
.
SetEnv
(
20
,
2000
,
1
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -208,7 +208,7 @@ func (s *suiteRelay) TestExec_3() {
...
@@ -208,7 +208,7 @@ func (s *suiteRelay) TestExec_3() {
}
}
sell
:=
&
ty
.
RelayAction
{
sell
:=
&
ty
.
RelayAction
{
Ty
:
ty
.
RelayActionConfirmTx
,
Ty
:
ty
.
RelayActionConfirmTx
,
Value
:
&
ty
.
RelayAction_ConfirmTx
{
ConfirmTx
:
order
},
Value
:
&
ty
.
RelayAction_ConfirmTx
{
ConfirmTx
:
order
},
}
}
tx
:=
&
types
.
Transaction
{}
tx
:=
&
types
.
Transaction
{}
...
@@ -217,7 +217,7 @@ func (s *suiteRelay) TestExec_3() {
...
@@ -217,7 +217,7 @@ func (s *suiteRelay) TestExec_3() {
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -264,7 +264,7 @@ func (s *suiteRelay) TestExec_4() {
...
@@ -264,7 +264,7 @@ func (s *suiteRelay) TestExec_4() {
Hash
:
"6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4"
,
Hash
:
"6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4"
,
}
}
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
1006
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
1006
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
var
head
=
&
ty
.
BtcHeader
{
var
head
=
&
ty
.
BtcHeader
{
Version
:
1
,
Version
:
1
,
...
@@ -280,7 +280,7 @@ func (s *suiteRelay) TestExec_4() {
...
@@ -280,7 +280,7 @@ func (s *suiteRelay) TestExec_4() {
}
}
sell
:=
&
ty
.
RelayAction
{
sell
:=
&
ty
.
RelayAction
{
Ty
:
ty
.
RelayActionVerifyTx
,
Ty
:
ty
.
RelayActionVerifyTx
,
Value
:
&
ty
.
RelayAction_Verify
{
Verify
:
order
},
Value
:
&
ty
.
RelayAction_Verify
{
Verify
:
order
},
}
}
tx
:=
&
types
.
Transaction
{}
tx
:=
&
types
.
Transaction
{}
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
...
@@ -374,7 +374,7 @@ func (s *suiteRelay) TestExec_9_QryStatus5() {
...
@@ -374,7 +374,7 @@ func (s *suiteRelay) TestExec_9_QryStatus5() {
BaseHeight
:
10
,
BaseHeight
:
10
,
}
}
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Twice
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Twice
()
msg
,
err
:=
s
.
relay
.
Query_GetBTCHeaderCurHeight
(
addrCoins
)
msg
,
err
:=
s
.
relay
.
Query_GetBTCHeaderCurHeight
(
addrCoins
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -505,7 +505,7 @@ func (s *suiteBtcHeader) TestSaveBtcHead_1() {
...
@@ -505,7 +505,7 @@ func (s *suiteBtcHeader) TestSaveBtcHead_1() {
sell
:=
&
ty
.
RelayAction
{
sell
:=
&
ty
.
RelayAction
{
Ty
:
ty
.
RelayActionRcvBTCHeaders
,
Ty
:
ty
.
RelayActionRcvBTCHeaders
,
Value
:
&
ty
.
RelayAction_BtcHeaders
{
BtcHeaders
:
headers
},
Value
:
&
ty
.
RelayAction_BtcHeaders
{
BtcHeaders
:
headers
},
}
}
tx
:=
&
types
.
Transaction
{}
tx
:=
&
types
.
Transaction
{}
...
...
plugin/dapp/relay/executor/relaybtc.go
View file @
27e5be5f
...
@@ -92,15 +92,15 @@ func (b *btcStore) saveBlockHead(head *ty.BtcHeader) ([]*types.KeyValue, error)
...
@@ -92,15 +92,15 @@ func (b *btcStore) saveBlockHead(head *ty.BtcHeader) ([]*types.KeyValue, error)
// hash:header
// hash:header
key
=
calcBtcHeaderKeyHash
(
head
.
Hash
)
key
=
calcBtcHeaderKeyHash
(
head
.
Hash
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
val
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
val
})
// height:header
// height:header
key
=
calcBtcHeaderKeyHeight
(
int64
(
head
.
Height
))
key
=
calcBtcHeaderKeyHeight
(
int64
(
head
.
Height
))
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
val
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
val
})
// prefix-height:height
// prefix-height:height
key
=
calcBtcHeaderKeyHeightList
(
int64
(
head
.
Height
))
key
=
calcBtcHeaderKeyHeightList
(
int64
(
head
.
Height
))
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
Height
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
Height
)})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
return
kv
,
nil
return
kv
,
nil
}
}
...
@@ -108,13 +108,13 @@ func (b *btcStore) saveBlockHead(head *ty.BtcHeader) ([]*types.KeyValue, error)
...
@@ -108,13 +108,13 @@ func (b *btcStore) saveBlockHead(head *ty.BtcHeader) ([]*types.KeyValue, error)
func
(
b
*
btcStore
)
saveBlockLastHead
(
head
*
ty
.
ReceiptRelayRcvBTCHeaders
)
([]
*
types
.
KeyValue
,
error
)
{
func
(
b
*
btcStore
)
saveBlockLastHead
(
head
*
ty
.
ReceiptRelayRcvBTCHeaders
)
([]
*
types
.
KeyValue
,
error
)
{
var
kv
[]
*
types
.
KeyValue
var
kv
[]
*
types
.
KeyValue
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
NewHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
NewHeight
)})
key
:=
relayBTCHeaderLastHeight
key
:=
relayBTCHeaderLastHeight
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
heightBytes
=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
NewBaseHeight
)})
heightBytes
=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
NewBaseHeight
)})
key
=
relayBTCHeaderBaseHeight
key
=
relayBTCHeaderBaseHeight
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
return
kv
,
nil
return
kv
,
nil
}
}
...
@@ -123,14 +123,14 @@ func (b *btcStore) delBlockHead(head *ty.BtcHeader) ([]*types.KeyValue, error) {
...
@@ -123,14 +123,14 @@ func (b *btcStore) delBlockHead(head *ty.BtcHeader) ([]*types.KeyValue, error) {
var
kv
[]
*
types
.
KeyValue
var
kv
[]
*
types
.
KeyValue
key
:=
calcBtcHeaderKeyHash
(
head
.
Hash
)
key
:=
calcBtcHeaderKeyHash
(
head
.
Hash
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
// height:header
// height:header
key
=
calcBtcHeaderKeyHeight
(
int64
(
head
.
Height
))
key
=
calcBtcHeaderKeyHeight
(
int64
(
head
.
Height
))
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
// prefix-height:height
// prefix-height:height
key
=
calcBtcHeaderKeyHeightList
(
int64
(
head
.
Height
))
key
=
calcBtcHeaderKeyHeightList
(
int64
(
head
.
Height
))
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
return
kv
,
nil
return
kv
,
nil
}
}
...
@@ -139,13 +139,13 @@ func (b *btcStore) delBlockLastHead(head *ty.ReceiptRelayRcvBTCHeaders) ([]*type
...
@@ -139,13 +139,13 @@ func (b *btcStore) delBlockLastHead(head *ty.ReceiptRelayRcvBTCHeaders) ([]*type
var
kv
[]
*
types
.
KeyValue
var
kv
[]
*
types
.
KeyValue
var
key
[]
byte
var
key
[]
byte
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
LastHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
LastHeight
)})
key
=
relayBTCHeaderLastHeight
key
=
relayBTCHeaderLastHeight
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
heightBytes
=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
LastBaseHeight
)})
heightBytes
=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
LastBaseHeight
)})
key
=
relayBTCHeaderBaseHeight
key
=
relayBTCHeaderBaseHeight
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
return
kv
,
nil
return
kv
,
nil
}
}
...
...
plugin/dapp/relay/executor/relaybtc_test.go
View file @
27e5be5f
...
@@ -34,14 +34,14 @@ func (s *suiteBtcStore) SetupSuite() {
...
@@ -34,14 +34,14 @@ func (s *suiteBtcStore) SetupSuite() {
}
}
func
(
s
*
suiteBtcStore
)
TestGetBtcHeadHeightFromDb
()
{
func
(
s
*
suiteBtcStore
)
TestGetBtcHeadHeightFromDb
()
{
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
val
,
_
:=
s
.
btc
.
getBtcHeadHeightFromDb
([]
byte
(
"key"
))
val
,
_
:=
s
.
btc
.
getBtcHeadHeightFromDb
([]
byte
(
"key"
))
s
.
Assert
()
.
Equal
(
val
,
int64
(
10
))
s
.
Assert
()
.
Equal
(
val
,
int64
(
10
))
}
}
func
(
s
*
suiteBtcStore
)
TestGetLastBtcHeadHeight
()
{
func
(
s
*
suiteBtcStore
)
TestGetLastBtcHeadHeight
()
{
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
val
,
_
:=
s
.
btc
.
getLastBtcHeadHeight
()
val
,
_
:=
s
.
btc
.
getLastBtcHeadHeight
()
s
.
Assert
()
.
Equal
(
val
,
int64
(
10
))
s
.
Assert
()
.
Equal
(
val
,
int64
(
10
))
...
@@ -58,7 +58,7 @@ func (s *suiteBtcStore) TestGetBtcHeadByHeight() {
...
@@ -58,7 +58,7 @@ func (s *suiteBtcStore) TestGetBtcHeadByHeight() {
}
}
func
(
s
*
suiteBtcStore
)
TestGetLastBtcHead
()
{
func
(
s
*
suiteBtcStore
)
TestGetLastBtcHead
()
{
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
head
:=
&
ty
.
BtcHeader
{}
head
:=
&
ty
.
BtcHeader
{}
header
:=
types
.
Encode
(
head
)
header
:=
types
.
Encode
(
head
)
...
@@ -82,12 +82,12 @@ func (s *suiteBtcStore) TestSaveBlockHead() {
...
@@ -82,12 +82,12 @@ func (s *suiteBtcStore) TestSaveBlockHead() {
}
}
val
,
_
:=
proto
.
Marshal
(
head
)
val
,
_
:=
proto
.
Marshal
(
head
)
key
:=
calcBtcHeaderKeyHash
(
head
.
Hash
)
key
:=
calcBtcHeaderKeyHash
(
head
.
Hash
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
val
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
val
})
key
=
calcBtcHeaderKeyHeight
(
int64
(
head
.
Height
))
key
=
calcBtcHeaderKeyHeight
(
int64
(
head
.
Height
))
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
val
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
val
})
key
=
calcBtcHeaderKeyHeightList
(
int64
(
head
.
Height
))
key
=
calcBtcHeaderKeyHeightList
(
int64
(
head
.
Height
))
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
Height
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
Height
)})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
res
,
err
:=
s
.
btc
.
saveBlockHead
(
head
)
res
,
err
:=
s
.
btc
.
saveBlockHead
(
head
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -104,13 +104,13 @@ func (s *suiteBtcStore) TestSaveBlockLastHead() {
...
@@ -104,13 +104,13 @@ func (s *suiteBtcStore) TestSaveBlockLastHead() {
NewBaseHeight
:
150
,
NewBaseHeight
:
150
,
}
}
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
lastHead
.
NewHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
lastHead
.
NewHeight
)})
key
:=
relayBTCHeaderLastHeight
key
:=
relayBTCHeaderLastHeight
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
heightBytes
=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
lastHead
.
NewBaseHeight
)})
heightBytes
=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
lastHead
.
NewBaseHeight
)})
key
=
relayBTCHeaderBaseHeight
key
=
relayBTCHeaderBaseHeight
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
res
,
err
:=
s
.
btc
.
saveBlockLastHead
(
lastHead
)
res
,
err
:=
s
.
btc
.
saveBlockLastHead
(
lastHead
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -131,14 +131,14 @@ func (s *suiteBtcStore) TestDelBlockHead() {
...
@@ -131,14 +131,14 @@ func (s *suiteBtcStore) TestDelBlockHead() {
}
}
key
:=
calcBtcHeaderKeyHash
(
head
.
Hash
)
key
:=
calcBtcHeaderKeyHash
(
head
.
Hash
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
// height:header
// height:header
key
=
calcBtcHeaderKeyHeight
(
int64
(
head
.
Height
))
key
=
calcBtcHeaderKeyHeight
(
int64
(
head
.
Height
))
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
// prefix-height:height
// prefix-height:height
key
=
calcBtcHeaderKeyHeightList
(
int64
(
head
.
Height
))
key
=
calcBtcHeaderKeyHeightList
(
int64
(
head
.
Height
))
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
res
,
err
:=
s
.
btc
.
delBlockHead
(
head
)
res
,
err
:=
s
.
btc
.
delBlockHead
(
head
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -155,13 +155,13 @@ func (s *suiteBtcStore) TestDelBlockLastHead() {
...
@@ -155,13 +155,13 @@ func (s *suiteBtcStore) TestDelBlockLastHead() {
NewBaseHeight
:
150
,
NewBaseHeight
:
150
,
}
}
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
lastHead
.
LastHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
lastHead
.
LastHeight
)})
key
:=
relayBTCHeaderLastHeight
key
:=
relayBTCHeaderLastHeight
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
heightBytes
=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
lastHead
.
LastBaseHeight
)})
heightBytes
=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
lastHead
.
LastBaseHeight
)})
key
=
relayBTCHeaderBaseHeight
key
=
relayBTCHeaderBaseHeight
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
res
,
err
:=
s
.
btc
.
delBlockLastHead
(
lastHead
)
res
,
err
:=
s
.
btc
.
delBlockLastHead
(
lastHead
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -241,7 +241,7 @@ func (s *suiteBtcStore) TestVerifyBtcTx() {
...
@@ -241,7 +241,7 @@ func (s *suiteBtcStore) TestVerifyBtcTx() {
Spv
:
spv
,
Spv
:
spv
,
}
}
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
1006
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
1006
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
var
head
=
&
ty
.
BtcHeader
{
var
head
=
&
ty
.
BtcHeader
{
Version
:
1
,
Version
:
1
,
...
@@ -290,7 +290,7 @@ func (s *suiteBtcStore) TestGetHeadHeightList() {
...
@@ -290,7 +290,7 @@ func (s *suiteBtcStore) TestGetHeadHeightList() {
heightArry
:=
make
([][]
byte
,
10
)
heightArry
:=
make
([][]
byte
,
10
)
for
i
:=
0
;
i
<
10
;
i
++
{
for
i
:=
0
;
i
<
10
;
i
++
{
height
:=
int64
(
1000
+
i
)
height
:=
int64
(
1000
+
i
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
height
})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
height
})
heightArry
[
i
]
=
heightBytes
heightArry
[
i
]
=
heightBytes
replay
.
Heights
=
append
(
replay
.
Heights
,
height
)
replay
.
Heights
=
append
(
replay
.
Heights
,
height
)
}
}
...
...
plugin/dapp/relay/executor/relaydb.go
View file @
27e5be5f
...
@@ -43,11 +43,11 @@ func (r *relayLog) save(db dbm.KV) []*types.KeyValue {
...
@@ -43,11 +43,11 @@ func (r *relayLog) save(db dbm.KV) []*types.KeyValue {
func
(
r
*
relayLog
)
getKVSet
()
(
kvSet
[]
*
types
.
KeyValue
)
{
func
(
r
*
relayLog
)
getKVSet
()
(
kvSet
[]
*
types
.
KeyValue
)
{
value
:=
types
.
Encode
(
&
r
.
RelayOrder
)
value
:=
types
.
Encode
(
&
r
.
RelayOrder
)
key
:=
[]
byte
(
r
.
Id
)
key
:=
[]
byte
(
r
.
Id
)
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
value
})
if
r
.
CoinTxHash
!=
""
{
if
r
.
CoinTxHash
!=
""
{
key
=
[]
byte
(
calcCoinHash
(
r
.
CoinTxHash
))
key
=
[]
byte
(
calcCoinHash
(
r
.
CoinTxHash
))
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
value
})
}
}
return
kvSet
return
kvSet
...
@@ -179,7 +179,7 @@ func (action *relayDB) create(order *ty.RelayCreate) (*types.Receipt, error) {
...
@@ -179,7 +179,7 @@ func (action *relayDB) create(order *ty.RelayCreate) (*types.Receipt, error) {
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayCreate
))
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayCreate
))
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
}
}
func
(
action
*
relayDB
)
checkRevokeOrder
(
order
*
ty
.
RelayOrder
)
error
{
func
(
action
*
relayDB
)
checkRevokeOrder
(
order
*
ty
.
RelayOrder
)
error
{
...
@@ -290,7 +290,7 @@ func (action *relayDB) revokeCreate(revoke *ty.RelayRevoke) (*types.Receipt, err
...
@@ -290,7 +290,7 @@ func (action *relayDB) revokeCreate(revoke *ty.RelayRevoke) (*types.Receipt, err
}
}
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayRevokeCreate
))
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayRevokeCreate
))
kv
=
append
(
kv
,
orderKV
...
)
kv
=
append
(
kv
,
orderKV
...
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
}
func
(
action
*
relayDB
)
accept
(
accept
*
ty
.
RelayAccept
)
(
*
types
.
Receipt
,
error
)
{
func
(
action
*
relayDB
)
accept
(
accept
*
ty
.
RelayAccept
)
(
*
types
.
Receipt
,
error
)
{
...
@@ -355,7 +355,7 @@ func (action *relayDB) accept(accept *ty.RelayAccept) (*types.Receipt, error) {
...
@@ -355,7 +355,7 @@ func (action *relayDB) accept(accept *ty.RelayAccept) (*types.Receipt, error) {
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayAccept
))
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayAccept
))
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
}
}
...
@@ -429,7 +429,7 @@ func (action *relayDB) revokeAccept(revoke *ty.RelayRevoke) (*types.Receipt, err
...
@@ -429,7 +429,7 @@ func (action *relayDB) revokeAccept(revoke *ty.RelayRevoke) (*types.Receipt, err
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayRevokeAccept
))
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayRevokeAccept
))
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
}
}
func
(
action
*
relayDB
)
confirmTx
(
confirm
*
ty
.
RelayConfirmTx
)
(
*
types
.
Receipt
,
error
)
{
func
(
action
*
relayDB
)
confirmTx
(
confirm
*
ty
.
RelayConfirmTx
)
(
*
types
.
Receipt
,
error
)
{
...
@@ -487,7 +487,7 @@ func (action *relayDB) confirmTx(confirm *ty.RelayConfirmTx) (*types.Receipt, er
...
@@ -487,7 +487,7 @@ func (action *relayDB) confirmTx(confirm *ty.RelayConfirmTx) (*types.Receipt, er
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayConfirmTx
))
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayConfirmTx
))
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
return
receipt
,
nil
}
}
...
@@ -562,7 +562,7 @@ func (action *relayDB) verifyTx(verify *ty.RelayVerify) (*types.Receipt, error)
...
@@ -562,7 +562,7 @@ func (action *relayDB) verifyTx(verify *ty.RelayVerify) (*types.Receipt, error)
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receiptTransfer
.
KV
...
)
kv
=
append
(
kv
,
receiptTransfer
.
KV
...
)
kv
=
append
(
kv
,
orderKV
...
)
kv
=
append
(
kv
,
orderKV
...
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
}
...
@@ -637,7 +637,7 @@ func (action *relayDB) verifyCmdTx(verify *ty.RelayVerifyCli) (*types.Receipt, e
...
@@ -637,7 +637,7 @@ func (action *relayDB) verifyCmdTx(verify *ty.RelayVerifyCli) (*types.Receipt, e
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receiptTransfer
.
KV
...
)
kv
=
append
(
kv
,
receiptTransfer
.
KV
...
)
kv
=
append
(
kv
,
orderKV
...
)
kv
=
append
(
kv
,
orderKV
...
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
}
...
@@ -648,7 +648,7 @@ func saveBtcLastHead(db dbm.KV, head *ty.RelayLastRcvBtcHeader) (set []*types.Ke
...
@@ -648,7 +648,7 @@ func saveBtcLastHead(db dbm.KV, head *ty.RelayLastRcvBtcHeader) (set []*types.Ke
value
:=
types
.
Encode
(
head
)
value
:=
types
.
Encode
(
head
)
key
:=
[]
byte
(
btcLastHead
)
key
:=
[]
byte
(
btcLastHead
)
set
=
append
(
set
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
value
})
set
=
append
(
set
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
value
})
for
i
:=
0
;
i
<
len
(
set
);
i
++
{
for
i
:=
0
;
i
<
len
(
set
);
i
++
{
db
.
Set
(
set
[
i
]
.
GetKey
(),
set
[
i
]
.
Value
)
db
.
Set
(
set
[
i
]
.
GetKey
(),
set
[
i
]
.
Value
)
...
@@ -714,5 +714,5 @@ func (action *relayDB) saveBtcHeader(headers *ty.BtcHeaders, localDb dbm.KVDB) (
...
@@ -714,5 +714,5 @@ func (action *relayDB) saveBtcHeader(headers *ty.BtcHeaders, localDb dbm.KVDB) (
log
.
Log
=
types
.
Encode
(
receipt
)
log
.
Log
=
types
.
Encode
(
receipt
)
logs
=
append
(
logs
,
log
)
logs
=
append
(
logs
,
log
)
kv
=
saveBtcLastHead
(
action
.
db
,
preHead
)
kv
=
saveBtcLastHead
(
action
.
db
,
preHead
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
}
plugin/dapp/relay/executor/relaydb_test.go
View file @
27e5be5f
...
@@ -45,8 +45,8 @@ func (s *suiteRelayLog) TestSave() {
...
@@ -45,8 +45,8 @@ func (s *suiteRelayLog) TestSave() {
value
:=
types
.
Encode
(
&
s
.
log
.
RelayOrder
)
value
:=
types
.
Encode
(
&
s
.
log
.
RelayOrder
)
keyID
:=
[]
byte
(
s
.
log
.
Id
)
keyID
:=
[]
byte
(
s
.
log
.
Id
)
keyCoinTxHash
:=
[]
byte
(
calcCoinHash
(
s
.
log
.
CoinTxHash
))
keyCoinTxHash
:=
[]
byte
(
calcCoinHash
(
s
.
log
.
CoinTxHash
))
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyID
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyID
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyCoinTxHash
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyCoinTxHash
,
Value
:
value
})
for
i
:=
0
;
i
<
len
(
kvSet
);
i
++
{
for
i
:=
0
;
i
<
len
(
kvSet
);
i
++
{
s
.
db
.
On
(
"Set"
,
kvSet
[
i
]
.
GetKey
(),
kvSet
[
i
]
.
Value
)
.
Return
(
nil
)
.
Once
()
s
.
db
.
On
(
"Set"
,
kvSet
[
i
]
.
GetKey
(),
kvSet
[
i
]
.
Value
)
.
Return
(
nil
)
.
Once
()
...
@@ -61,8 +61,8 @@ func (s *suiteRelayLog) TestGetKVSet() {
...
@@ -61,8 +61,8 @@ func (s *suiteRelayLog) TestGetKVSet() {
value
:=
types
.
Encode
(
&
s
.
log
.
RelayOrder
)
value
:=
types
.
Encode
(
&
s
.
log
.
RelayOrder
)
keyID
:=
[]
byte
(
s
.
log
.
Id
)
keyID
:=
[]
byte
(
s
.
log
.
Id
)
keyCoinTxHash
:=
[]
byte
(
calcCoinHash
(
s
.
log
.
CoinTxHash
))
keyCoinTxHash
:=
[]
byte
(
calcCoinHash
(
s
.
log
.
CoinTxHash
))
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyID
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyID
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyCoinTxHash
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyCoinTxHash
,
Value
:
value
})
rst
:=
s
.
log
.
getKVSet
()
rst
:=
s
.
log
.
getKVSet
()
s
.
Assert
()
.
Equal
(
kvSet
,
rst
)
s
.
Assert
()
.
Equal
(
kvSet
,
rst
)
...
@@ -176,7 +176,7 @@ func (s *suiteRelayDB) TestRelayCreate_1() {
...
@@ -176,7 +176,7 @@ func (s *suiteRelayDB) TestRelayCreate_1() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -208,7 +208,7 @@ func (s *suiteRelayDB) TestRevokeCreate_1aUnlock() {
...
@@ -208,7 +208,7 @@ func (s *suiteRelayDB) TestRevokeCreate_1aUnlock() {
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
_
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
_
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
@@ -229,7 +229,7 @@ func (s *suiteRelayDB) TestRevokeCreate_1bCancel() {
...
@@ -229,7 +229,7 @@ func (s *suiteRelayDB) TestRevokeCreate_1bCancel() {
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
receipt
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
@@ -309,7 +309,7 @@ func (s *suiteAccept) setupRelayCreate() {
...
@@ -309,7 +309,7 @@ func (s *suiteAccept) setupRelayCreate() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -357,7 +357,7 @@ func (s *suiteAccept) TestRelayAccept() {
...
@@ -357,7 +357,7 @@ func (s *suiteAccept) TestRelayAccept() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
accept
(
order
)
receipt
,
err
:=
s
.
relayDb
.
accept
(
order
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -388,7 +388,7 @@ func (s *suiteAccept) TestRevokeAccept_1() {
...
@@ -388,7 +388,7 @@ func (s *suiteAccept) TestRevokeAccept_1() {
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
22
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
22
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
_
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
_
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
@@ -409,7 +409,7 @@ func (s *suiteAccept) TestRevokeAccept_2() {
...
@@ -409,7 +409,7 @@ func (s *suiteAccept) TestRevokeAccept_2() {
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
+
lockBtcHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
+
lockBtcHeight
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
_
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
_
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
@@ -430,7 +430,7 @@ func (s *suiteAccept) TestRevokeAccept_3() {
...
@@ -430,7 +430,7 @@ func (s *suiteAccept) TestRevokeAccept_3() {
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
+
lockBtcHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
+
lockBtcHeight
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
receipt
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
@@ -507,7 +507,7 @@ func (s *suiteConfirm) setupRelayCreate() {
...
@@ -507,7 +507,7 @@ func (s *suiteConfirm) setupRelayCreate() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -556,7 +556,7 @@ func (s *suiteConfirm) setupAccept() {
...
@@ -556,7 +556,7 @@ func (s *suiteConfirm) setupAccept() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
accept
(
order
)
receipt
,
err
:=
s
.
relayDb
.
accept
(
order
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -605,7 +605,7 @@ func (s *suiteConfirm) TestConfirm_2() {
...
@@ -605,7 +605,7 @@ func (s *suiteConfirm) TestConfirm_2() {
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
confirmTx
(
order
)
receipt
,
err
:=
s
.
relayDb
.
confirmTx
(
order
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -636,7 +636,7 @@ func (s *suiteConfirm) TestRevokeConfirm_1() {
...
@@ -636,7 +636,7 @@ func (s *suiteConfirm) TestRevokeConfirm_1() {
s
.
relay
.
SetEnv
(
40
,
4000
,
1
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
+
lockBtcHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
+
lockBtcHeight
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
_
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
_
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
@@ -657,7 +657,7 @@ func (s *suiteConfirm) TestRevokeConfirm_2() {
...
@@ -657,7 +657,7 @@ func (s *suiteConfirm) TestRevokeConfirm_2() {
s
.
relay
.
SetEnv
(
40
,
4000
,
1
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
+
4
*
lockBtcHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
+
4
*
lockBtcHeight
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
receipt
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
@@ -734,7 +734,7 @@ func (s *suiteVerify) setupRelayCreate() {
...
@@ -734,7 +734,7 @@ func (s *suiteVerify) setupRelayCreate() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -765,7 +765,7 @@ func (s *suiteVerify) setupAccept() {
...
@@ -765,7 +765,7 @@ func (s *suiteVerify) setupAccept() {
s
.
relay
.
SetEnv
(
20
,
2000
,
1
)
s
.
relay
.
SetEnv
(
20
,
2000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
accept
(
order
)
receipt
,
err
:=
s
.
relayDb
.
accept
(
order
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -796,7 +796,7 @@ func (s *suiteVerify) setupConfirm() {
...
@@ -796,7 +796,7 @@ func (s *suiteVerify) setupConfirm() {
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
confirmTx
(
order
)
receipt
,
err
:=
s
.
relayDb
.
confirmTx
(
order
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -860,7 +860,7 @@ func (s *suiteVerify) TestVerify() {
...
@@ -860,7 +860,7 @@ func (s *suiteVerify) TestVerify() {
Hash
:
"6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4"
,
Hash
:
"6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4"
,
}
}
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
1006
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
1006
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
var
head
=
&
ty
.
BtcHeader
{
var
head
=
&
ty
.
BtcHeader
{
Version
:
1
,
Version
:
1
,
...
@@ -965,7 +965,7 @@ func (s *suiteVerifyCli) setupRelayCreate() {
...
@@ -965,7 +965,7 @@ func (s *suiteVerifyCli) setupRelayCreate() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -996,7 +996,7 @@ func (s *suiteVerifyCli) setupAccept() {
...
@@ -996,7 +996,7 @@ func (s *suiteVerifyCli) setupAccept() {
s
.
relay
.
SetEnv
(
20
,
2000
,
1
)
s
.
relay
.
SetEnv
(
20
,
2000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
accept
(
order
)
receipt
,
err
:=
s
.
relayDb
.
accept
(
order
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -1027,7 +1027,7 @@ func (s *suiteVerifyCli) setupConfirm() {
...
@@ -1027,7 +1027,7 @@ func (s *suiteVerifyCli) setupConfirm() {
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relayDb
.
confirmTx
(
order
)
receipt
,
err
:=
s
.
relayDb
.
confirmTx
(
order
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
...
plugin/dapp/relay/rpc/rpc.go
View file @
27e5be5f
...
@@ -66,7 +66,8 @@ func createRawRelaySaveBTCHeadTx(parm *ty.BtcHeader) ([]byte, error) {
...
@@ -66,7 +66,8 @@ func createRawRelaySaveBTCHeadTx(parm *ty.BtcHeader) ([]byte, error) {
return
types
.
CallCreateTx
(
types
.
ExecName
(
ty
.
RelayX
),
"BtcHeaders"
,
v
)
return
types
.
CallCreateTx
(
types
.
ExecName
(
ty
.
RelayX
),
"BtcHeaders"
,
v
)
}
}
func
(
c
*
jrpc
)
CreateRawRelayOrderTx
(
in
*
ty
.
RelayCreate
,
result
*
interface
{})
error
{
//CreateRawRelayOrderTx jrpc create raw relay order
func
(
c
*
Jrpc
)
CreateRawRelayOrderTx
(
in
*
ty
.
RelayCreate
,
result
*
interface
{})
error
{
reply
,
err
:=
createRawRelayOrderTx
(
in
)
reply
,
err
:=
createRawRelayOrderTx
(
in
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -75,7 +76,8 @@ func (c *jrpc) CreateRawRelayOrderTx(in *ty.RelayCreate, result *interface{}) er
...
@@ -75,7 +76,8 @@ func (c *jrpc) CreateRawRelayOrderTx(in *ty.RelayCreate, result *interface{}) er
return
nil
return
nil
}
}
func
(
c
*
jrpc
)
CreateRawRelayAcceptTx
(
in
*
ty
.
RelayAccept
,
result
*
interface
{})
error
{
//CreateRawRelayAcceptTx jrpc creat relay accept tx
func
(
c
*
Jrpc
)
CreateRawRelayAcceptTx
(
in
*
ty
.
RelayAccept
,
result
*
interface
{})
error
{
reply
,
err
:=
createRawRelayAcceptTx
(
in
)
reply
,
err
:=
createRawRelayAcceptTx
(
in
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -85,7 +87,8 @@ func (c *jrpc) CreateRawRelayAcceptTx(in *ty.RelayAccept, result *interface{}) e
...
@@ -85,7 +87,8 @@ func (c *jrpc) CreateRawRelayAcceptTx(in *ty.RelayAccept, result *interface{}) e
return
nil
return
nil
}
}
func
(
c
*
jrpc
)
CreateRawRelayRevokeTx
(
in
*
ty
.
RelayRevoke
,
result
*
interface
{})
error
{
//CreateRawRelayRevokeTx jrpc create revoke tx
func
(
c
*
Jrpc
)
CreateRawRelayRevokeTx
(
in
*
ty
.
RelayRevoke
,
result
*
interface
{})
error
{
reply
,
err
:=
createRawRelayRevokeTx
(
in
)
reply
,
err
:=
createRawRelayRevokeTx
(
in
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -95,7 +98,8 @@ func (c *jrpc) CreateRawRelayRevokeTx(in *ty.RelayRevoke, result *interface{}) e
...
@@ -95,7 +98,8 @@ func (c *jrpc) CreateRawRelayRevokeTx(in *ty.RelayRevoke, result *interface{}) e
return
nil
return
nil
}
}
func
(
c
*
jrpc
)
CreateRawRelayConfirmTx
(
in
*
ty
.
RelayConfirmTx
,
result
*
interface
{})
error
{
//CreateRawRelayConfirmTx jrpc create confirm tx
func
(
c
*
Jrpc
)
CreateRawRelayConfirmTx
(
in
*
ty
.
RelayConfirmTx
,
result
*
interface
{})
error
{
reply
,
err
:=
createRawRelayConfirmTx
(
in
)
reply
,
err
:=
createRawRelayConfirmTx
(
in
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -105,7 +109,8 @@ func (c *jrpc) CreateRawRelayConfirmTx(in *ty.RelayConfirmTx, result *interface{
...
@@ -105,7 +109,8 @@ func (c *jrpc) CreateRawRelayConfirmTx(in *ty.RelayConfirmTx, result *interface{
return
nil
return
nil
}
}
func
(
c
*
jrpc
)
CreateRawRelayVerifyBTCTx
(
in
*
ty
.
RelayVerifyCli
,
result
*
interface
{})
error
{
//CreateRawRelayVerifyBTCTx jrpc create veirfy btc tx
func
(
c
*
Jrpc
)
CreateRawRelayVerifyBTCTx
(
in
*
ty
.
RelayVerifyCli
,
result
*
interface
{})
error
{
reply
,
err
:=
createRawRelayVerifyBTCTx
(
in
)
reply
,
err
:=
createRawRelayVerifyBTCTx
(
in
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -114,7 +119,8 @@ func (c *jrpc) CreateRawRelayVerifyBTCTx(in *ty.RelayVerifyCli, result *interfac
...
@@ -114,7 +119,8 @@ func (c *jrpc) CreateRawRelayVerifyBTCTx(in *ty.RelayVerifyCli, result *interfac
return
nil
return
nil
}
}
func
(
c
*
jrpc
)
CreateRawRelaySaveBTCHeadTx
(
in
*
ty
.
BtcHeader
,
result
*
interface
{})
error
{
//CreateRawRelaySaveBTCHeadTx jrpc save btc header
func
(
c
*
Jrpc
)
CreateRawRelaySaveBTCHeadTx
(
in
*
ty
.
BtcHeader
,
result
*
interface
{})
error
{
reply
,
err
:=
createRawRelaySaveBTCHeadTx
(
in
)
reply
,
err
:=
createRawRelaySaveBTCHeadTx
(
in
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
plugin/dapp/relay/rpc/rpc_test.go
View file @
27e5be5f
...
@@ -16,6 +16,6 @@ func newTestChannelClient() *channelClient {
...
@@ -16,6 +16,6 @@ func newTestChannelClient() *channelClient {
}
}
}
}
func
newTestJrpcClient
()
*
j
rpc
{
func
newTestJrpcClient
()
*
J
rpc
{
return
&
j
rpc
{
cli
:
newTestChannelClient
()}
return
&
J
rpc
{
cli
:
newTestChannelClient
()}
}
}
plugin/dapp/relay/rpc/types.go
View file @
27e5be5f
...
@@ -8,11 +8,13 @@ import (
...
@@ -8,11 +8,13 @@ import (
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/rpc/types"
)
)
type
jrpc
struct
{
// Jrpc relay Jrpc interface
type
Jrpc
struct
{
cli
*
channelClient
cli
*
channelClient
}
}
type
grpc
struct
{
// Grpc relay Grpc interface
type
Grpc
struct
{
*
channelClient
*
channelClient
}
}
...
@@ -23,6 +25,6 @@ type channelClient struct {
...
@@ -23,6 +25,6 @@ type channelClient struct {
// Init relay rpc register
// Init relay rpc register
func
Init
(
name
string
,
s
types
.
RPCServer
)
{
func
Init
(
name
string
,
s
types
.
RPCServer
)
{
cli
:=
&
channelClient
{}
cli
:=
&
channelClient
{}
grpc
:=
&
g
rpc
{
channelClient
:
cli
}
grpc
:=
&
G
rpc
{
channelClient
:
cli
}
cli
.
Init
(
name
,
s
,
&
j
rpc
{
cli
:
cli
},
grpc
)
cli
.
Init
(
name
,
s
,
&
J
rpc
{
cli
:
cli
},
grpc
)
}
}
plugin/dapp/relay/types/errors.go
View file @
27e5be5f
...
@@ -8,39 +8,39 @@ import "errors"
...
@@ -8,39 +8,39 @@ import "errors"
var
(
var
(
// ErrRelayOrderNotExist relay order not exist
// ErrRelayOrderNotExist relay order not exist
ErrRelayOrderNotExist
=
errors
.
New
(
"ErrRelayOrderNotExist"
)
ErrRelayOrderNotExist
=
errors
.
New
(
"ErrRelayOrderNotExist"
)
// ErrRelayOrderOnSell relay order on sell status
// ErrRelayOrderOnSell relay order on sell status
ErrRelayOrderOnSell
=
errors
.
New
(
"ErrRelayOrderOnSell"
)
ErrRelayOrderOnSell
=
errors
.
New
(
"ErrRelayOrderOnSell"
)
// ErrRelayOrderStatusErr relay order status err
// ErrRelayOrderStatusErr relay order status err
ErrRelayOrderStatusErr
=
errors
.
New
(
"ErrRelayOrderStatusErr"
)
ErrRelayOrderStatusErr
=
errors
.
New
(
"ErrRelayOrderStatusErr"
)
// ErrRelayOrderParamErr relay order parameter err
// ErrRelayOrderParamErr relay order parameter err
ErrRelayOrderParamErr
=
errors
.
New
(
"ErrRelayOrderParamErr"
)
ErrRelayOrderParamErr
=
errors
.
New
(
"ErrRelayOrderParamErr"
)
// ErrRelayOrderSoldout order has been sold
// ErrRelayOrderSoldout order has been sold
ErrRelayOrderSoldout
=
errors
.
New
(
"ErrRelayOrderSoldout"
)
ErrRelayOrderSoldout
=
errors
.
New
(
"ErrRelayOrderSoldout"
)
// ErrRelayOrderRevoked order revoked
// ErrRelayOrderRevoked order revoked
ErrRelayOrderRevoked
=
errors
.
New
(
"ErrRelayOrderRevoked"
)
ErrRelayOrderRevoked
=
errors
.
New
(
"ErrRelayOrderRevoked"
)
// ErrRelayOrderConfirming order is confirming, not time out
// ErrRelayOrderConfirming order is confirming, not time out
ErrRelayOrderConfirming
=
errors
.
New
(
"ErrRelayOrderConfirming"
)
ErrRelayOrderConfirming
=
errors
.
New
(
"ErrRelayOrderConfirming"
)
// ErrRelayOrderFinished order has finished
// ErrRelayOrderFinished order has finished
ErrRelayOrderFinished
=
errors
.
New
(
"ErrRelayOrderFinished"
)
ErrRelayOrderFinished
=
errors
.
New
(
"ErrRelayOrderFinished"
)
// ErrRelayReturnAddr relay order return addr error
// ErrRelayReturnAddr relay order return addr error
ErrRelayReturnAddr
=
errors
.
New
(
"ErrRelayReturnAddr"
)
ErrRelayReturnAddr
=
errors
.
New
(
"ErrRelayReturnAddr"
)
// ErrRelayVerify order is verifying
// ErrRelayVerify order is verifying
ErrRelayVerify
=
errors
.
New
(
"ErrRelayVerify"
)
ErrRelayVerify
=
errors
.
New
(
"ErrRelayVerify"
)
// ErrRelayVerifyAddrNotFound order verify addr not found
// ErrRelayVerifyAddrNotFound order verify addr not found
ErrRelayVerifyAddrNotFound
=
errors
.
New
(
"ErrRelayVerifyAddrNotFound"
)
ErrRelayVerifyAddrNotFound
=
errors
.
New
(
"ErrRelayVerifyAddrNotFound"
)
// ErrRelayWaitBlocksErr order wait block not enough
// ErrRelayWaitBlocksErr order wait block not enough
ErrRelayWaitBlocksErr
=
errors
.
New
(
"ErrRelayWaitBlocks"
)
ErrRelayWaitBlocksErr
=
errors
.
New
(
"ErrRelayWaitBlocks"
)
// ErrRelayCoinTxHashUsed order confirm tx has been used
// ErrRelayCoinTxHashUsed order confirm tx has been used
ErrRelayCoinTxHashUsed
=
errors
.
New
(
"ErrRelayCoinTxHashUsed"
)
ErrRelayCoinTxHashUsed
=
errors
.
New
(
"ErrRelayCoinTxHashUsed"
)
// ErrRelayBtcTxTimeErr btc tx time not reasonable
// ErrRelayBtcTxTimeErr btc tx time not reasonable
ErrRelayBtcTxTimeErr
=
errors
.
New
(
"ErrRelayBtcTxTimeErr"
)
ErrRelayBtcTxTimeErr
=
errors
.
New
(
"ErrRelayBtcTxTimeErr"
)
// ErrRelayBtcHeadSequenceErr btc header sequence not continuous
// ErrRelayBtcHeadSequenceErr btc header sequence not continuous
ErrRelayBtcHeadSequenceErr
=
errors
.
New
(
"ErrRelayBtcHeadSequenceErr"
)
ErrRelayBtcHeadSequenceErr
=
errors
.
New
(
"ErrRelayBtcHeadSequenceErr"
)
// ErrRelayBtcHeadHashErr btc header hash not correct
// ErrRelayBtcHeadHashErr btc header hash not correct
ErrRelayBtcHeadHashErr
=
errors
.
New
(
"ErrRelayBtcHeadHashErr"
)
ErrRelayBtcHeadHashErr
=
errors
.
New
(
"ErrRelayBtcHeadHashErr"
)
// ErrRelayBtcHeadBitsErr rcv btc header bit not correct
// ErrRelayBtcHeadBitsErr rcv btc header bit not correct
ErrRelayBtcHeadBitsErr
=
errors
.
New
(
"ErrRelayBtcHeadBitsErr"
)
ErrRelayBtcHeadBitsErr
=
errors
.
New
(
"ErrRelayBtcHeadBitsErr"
)
// ErrRelayBtcHeadNewBitsErr calc btc header new bits error
// ErrRelayBtcHeadNewBitsErr calc btc header new bits error
ErrRelayBtcHeadNewBitsErr
=
errors
.
New
(
"ErrRelayBtcHeadNewBitsErr"
)
ErrRelayBtcHeadNewBitsErr
=
errors
.
New
(
"ErrRelayBtcHeadNewBitsErr"
)
)
)
plugin/dapp/relay/types/relay.go
View file @
27e5be5f
...
@@ -37,7 +37,7 @@ const (
...
@@ -37,7 +37,7 @@ const (
const
(
const
(
// RelayOrderBuy define relay buy order
// RelayOrderBuy define relay buy order
RelayOrderBuy
=
iota
RelayOrderBuy
=
iota
// RelayOrderSell define relay sell order
// RelayOrderSell define relay sell order
RelayOrderSell
RelayOrderSell
)
)
...
@@ -98,7 +98,7 @@ func (r *RelayType) GetLogMap() map[int64]*types.LogInfo {
...
@@ -98,7 +98,7 @@ func (r *RelayType) GetLogMap() map[int64]*types.LogInfo {
const
(
const
(
// RelayActionCreate relay create order action
// RelayActionCreate relay create order action
RelayActionCreate
=
iota
RelayActionCreate
=
iota
// RelayActionAccept accept order action
// RelayActionAccept accept order action
RelayActionAccept
RelayActionAccept
// RelayActionRevoke revoke order action
// RelayActionRevoke revoke order action
...
@@ -167,7 +167,6 @@ func (r *RelayType) Amount(tx *types.Transaction) (int64, error) {
...
@@ -167,7 +167,6 @@ func (r *RelayType) Amount(tx *types.Transaction) (int64, error) {
return
0
,
nil
return
0
,
nil
}
}
// CreateTx relay create tx TODO 暂时不修改实现, 先完成结构的重构
// CreateTx relay create tx TODO 暂时不修改实现, 先完成结构的重构
func
(
r
*
RelayType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
func
(
r
*
RelayType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
var
tx
*
types
.
Transaction
var
tx
*
types
.
Transaction
...
...
plugin/store/mpt/db2/rlp/decode_test.go
View file @
27e5be5f
...
@@ -737,7 +737,7 @@ func ExampleDecode_structTagNil() {
...
@@ -737,7 +737,7 @@ func ExampleDecode_structTagNil() {
Decode
(
bytes
.
NewReader
(
input
),
&
withEmptyOK
)
Decode
(
bytes
.
NewReader
(
input
),
&
withEmptyOK
)
fmt
.
Printf
(
"with nil tag: String = %v
\n
"
,
withEmptyOK
.
String
)
fmt
.
Printf
(
"with nil tag: String = %v
\n
"
,
withEmptyOK
.
String
)
// ProtoToJ
son
:
// ProtoToJ
SON
:
// normal: String = ""
// normal: String = ""
// with nil tag: String = <nil>
// with nil tag: String = <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