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
Show whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
287 additions
and
366 deletions
+287
-366
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
+4
-4
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
+8
-0
paracross.go
plugin/dapp/paracross/types/paracross.go
+41
-13
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
+0
-0
relay.go
plugin/dapp/relay/types/relay.go
+0
-1
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) {
func
Test_genPrivHash
(
t
*
testing
.
T
)
{
c
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
assert
.
NoError
(
t
,
err
)
priv
,
err
:=
c
.
GenKey
()
priv
,
_
:=
c
.
GenKey
()
bt
,
err
:=
genPrivHash
(
priv
,
"AA:BB:CC:DD"
)
assert
.
NotNil
(
t
,
err
)
...
...
plugin/dapp/paracross/commands/paracross.go
View file @
27e5be5f
...
...
@@ -16,6 +16,7 @@ import (
"github.com/spf13/cobra"
)
//ParcCmd paracross cmd register
func
ParcCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"para"
,
...
...
@@ -32,7 +33,7 @@ func ParcCmd() *cobra.Command {
return
cmd
}
// create raw asset transfer tx
//
CreateRawAssetTransferCmd
create raw asset transfer tx
func
CreateRawAssetTransferCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"asset_transfer"
,
...
...
@@ -67,7 +68,7 @@ func createAssetTransfer(cmd *cobra.Command, args []string) {
fmt
.
Println
(
txHex
)
}
// create raw asset withdraw tx
//
CreateRawAssetWithdrawCmd
create raw asset withdraw tx
func
CreateRawAssetWithdrawCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"asset_withdraw"
,
...
...
@@ -139,7 +140,7 @@ func createAssetTx(cmd *cobra.Command, isWithdraw bool) (string, error) {
return
hex
.
EncodeToString
(
txHex
),
nil
}
// create raw transfer tx
//
CreateRawTransferCmd
create raw transfer tx
func
CreateRawTransferCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"transfer"
,
...
...
@@ -174,7 +175,7 @@ func createTransfer(cmd *cobra.Command, args []string) {
fmt
.
Println
(
txHex
)
}
// create raw transfer to exec tx
//
CreateRawTransferToExecCmd
create raw transfer to exec tx
func
CreateRawTransferToExecCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"transfer_exec"
,
...
...
@@ -209,7 +210,7 @@ func createTransferToExec(cmd *cobra.Command, args []string) {
fmt
.
Println
(
txHex
)
}
// create raw withdraw tx
//
CreateRawWithdrawCmd
create raw withdraw tx
func
CreateRawWithdrawCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"withdraw"
,
...
...
plugin/dapp/paracross/executor/account.go
View file @
27e5be5f
...
...
@@ -13,6 +13,7 @@ import (
// 注: 在计算帐号地址时, 平行链paracross合约地址需要带上title前缀,才能表现出和主链一致, 但是现在不带,
//NewParaAccount create new paracross account
// 其中带{}, 都表示变量, 用需要用真实的地址, 符号代替
// 构建主链资产在平行链paracross帐号
// execName: user.p.{guodun}.paracross
...
...
@@ -28,6 +29,7 @@ func NewParaAccount(paraTitle, mainExecName, mainSymbol string, db db.KV) (*acco
return
account
.
NewAccountDB
(
paraExec
,
paraSymbol
,
db
)
}
//NewMainAccount create new Main account
// 以后如果支持从平行链资产转移到主链, 构建平行链资产在主链的paracross帐号
// execName: paracross
// 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) {
log
.
Log
=
types
.
Encode
(
receipt
)
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,7 +30,8 @@ func (a *action) assetTransfer(transfer *types.AssetsTransfer) (*types.Receipt,
clog
.
Debug
(
"paracross.AssetTransfer not isPara"
,
"execer"
,
string
(
a
.
tx
.
Execer
),
"txHash"
,
common
.
Bytes2Hex
(
a
.
tx
.
Hash
()))
return
accDB
.
ExecTransfer
(
a
.
fromaddr
,
toAddr
,
execAddr
,
transfer
.
Amount
)
}
else
{
}
paraTitle
,
err
:=
getTitleFrom
(
a
.
tx
.
Execer
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"assetTransferCoins call getTitleFrom failed"
)
...
...
@@ -47,7 +48,6 @@ func (a *action) assetTransfer(transfer *types.AssetsTransfer) (*types.Receipt,
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
)
{
...
...
@@ -62,7 +62,8 @@ func (a *action) assetWithdraw(withdraw *types.AssetsWithdraw, withdrawTx *types
clog
.
Debug
(
"Paracross.Exec"
,
"AssettWithdraw"
,
withdraw
.
Amount
,
"from"
,
fromAddr
,
"to"
,
withdraw
.
To
,
"exec"
,
execAddr
,
"withdrawTx execor"
,
string
(
withdrawTx
.
Execer
))
return
accDB
.
ExecTransfer
(
fromAddr
,
withdraw
.
To
,
execAddr
,
withdraw
.
Amount
)
}
else
{
}
paraTitle
,
err
:=
getTitleFrom
(
a
.
tx
.
Execer
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"assetWithdrawCoins call getTitleFrom failed"
)
...
...
@@ -79,7 +80,6 @@ func (a *action) assetWithdraw(withdraw *types.AssetsWithdraw, withdrawTx *types
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
)
{
...
...
plugin/dapp/paracross/executor/assettransfer_test.go
View file @
27e5be5f
...
...
@@ -83,13 +83,13 @@ func (suite *AssetTransferTestSuite) SetupTest() {
saveTitle
(
suite
.
stateDB
,
calcTitleKey
(
Title
),
&
titleStatus
)
// setup api
hashes
:=
&
types
.
ReqHashes
{[][]
byte
{
MainBlockHash10
}}
hashes
:=
&
types
.
ReqHashes
{
Hashes
:
[][]
byte
{
MainBlockHash10
}}
suite
.
api
.
On
(
"GetBlockByHashes"
,
hashes
)
.
Return
(
&
types
.
BlockDetails
{
Items
:
[]
*
types
.
BlockDetail
{
blockDetail
},
},
nil
)
suite
.
api
.
On
(
"GetBlockHash"
,
&
types
.
ReqInt
{
MainBlockHeight
})
.
Return
(
&
types
.
ReplyHash
{
MainBlockHash10
},
nil
)
suite
.
api
.
On
(
"GetBlockHash"
,
&
types
.
ReqInt
{
Height
:
MainBlockHeight
})
.
Return
(
&
types
.
ReplyHash
{
Hash
:
MainBlockHash10
},
nil
)
}
func
(
suite
*
AssetTransferTestSuite
)
TestExecTransferNobalance
()
{
...
...
plugin/dapp/paracross/executor/assetwithdraw_test.go
View file @
27e5be5f
...
...
@@ -78,13 +78,13 @@ func (suite *AssetWithdrawTestSuite) SetupTest() {
saveTitle
(
suite
.
stateDB
,
calcTitleKey
(
Title
),
&
titleStatus
)
// setup api
hashes
:=
&
types
.
ReqHashes
{[][]
byte
{
MainBlockHash10
}}
hashes
:=
&
types
.
ReqHashes
{
Hashes
:
[][]
byte
{
MainBlockHash10
}}
suite
.
api
.
On
(
"GetBlockByHashes"
,
hashes
)
.
Return
(
&
types
.
BlockDetails
{
Items
:
[]
*
types
.
BlockDetail
{
blockDetail
},
},
nil
)
suite
.
api
.
On
(
"GetBlockHash"
,
&
types
.
ReqInt
{
MainBlockHeight
})
.
Return
(
&
types
.
ReplyHash
{
MainBlockHash10
},
nil
)
suite
.
api
.
On
(
"GetBlockHash"
,
&
types
.
ReqInt
{
Height
:
MainBlockHeight
})
.
Return
(
&
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
return
db
.
Set
(
key
,
val
)
}
//GetBlock get block detail by block hash
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
{
clog
.
Error
(
"paracross.Commit getBlockHeader"
,
"db"
,
err
,
"commit tx hash"
,
common
.
Bytes2Hex
(
blockHash
))
...
...
@@ -88,8 +89,9 @@ func isNotFound(err error) bool {
return
false
}
//GetTx get tx by tx hash
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
{
clog
.
Error
(
"paracross.Commit GetTx"
,
"db"
,
err
,
"commit tx hash"
,
common
.
Bytes2Hex
(
txHash
))
...
...
plugin/dapp/paracross/executor/exec.go
View file @
27e5be5f
...
...
@@ -11,6 +11,7 @@ import (
"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
)
{
a
:=
newAction
(
e
,
tx
)
receipt
,
err
:=
a
.
Commit
(
payload
)
...
...
@@ -21,6 +22,7 @@ func (e *Paracross) Exec_Commit(payload *pt.ParacrossCommitAction, tx *types.Tra
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
)
{
clog
.
Debug
(
"Paracross.Exec"
,
"transfer"
,
""
)
_
,
err
:=
e
.
checkTxGroup
(
tx
,
index
)
...
...
@@ -37,6 +39,7 @@ func (e *Paracross) Exec_AssetTransfer(payload *types.AssetsTransfer, tx *types.
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
)
{
clog
.
Debug
(
"Paracross.Exec"
,
"withdraw"
,
""
)
_
,
err
:=
e
.
checkTxGroup
(
tx
,
index
)
...
...
@@ -53,6 +56,7 @@ func (e *Paracross) Exec_AssetWithdraw(payload *types.AssetsWithdraw, tx *types.
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
)
{
if
index
!=
0
{
return
nil
,
pt
.
ErrParaMinerBaseIndex
...
...
@@ -64,16 +68,19 @@ func (e *Paracross) Exec_Miner(payload *pt.ParacrossMinerAction, tx *types.Trans
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
)
{
a
:=
newAction
(
e
,
tx
)
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
)
{
a
:=
newAction
(
e
,
tx
)
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
)
{
a
:=
newAction
(
e
,
tx
)
return
a
.
TransferToExec
(
payload
,
tx
,
index
)
...
...
plugin/dapp/paracross/executor/exec_del_local.go
View file @
27e5be5f
...
...
@@ -9,6 +9,7 @@ import (
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
)
{
var
set
types
.
LocalDBSet
for
_
,
log
:=
range
receiptData
.
Logs
{
...
...
@@ -18,17 +19,17 @@ func (e *Paracross) ExecDelLocal_Commit(payload *pt.ParacrossCommitAction, tx *t
var
r
pt
.
ParacrossTx
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
{
var
g
pt
.
ReceiptParacrossDone
types
.
Decode
(
log
.
Log
,
&
g
)
g
.
Height
=
g
.
Height
-
1
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
)
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
)
if
err
!=
nil
{
...
...
@@ -41,12 +42,13 @@ func (e *Paracross) ExecDelLocal_Commit(payload *pt.ParacrossCommitAction, tx *t
var
r
pt
.
ParacrossTx
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
}
//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
)
{
var
set
types
.
LocalDBSet
...
...
@@ -61,29 +63,34 @@ func (e *Paracross) ExecDelLocal_AssetTransfer(payload *types.AssetsTransfer, tx
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
)
{
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
)
{
if
index
!=
0
{
return
nil
,
pt
.
ErrParaMinerBaseIndex
}
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
}
//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
)
{
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
)
{
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
)
{
return
nil
,
nil
}
plugin/dapp/paracross/executor/exec_local.go
View file @
27e5be5f
...
...
@@ -12,6 +12,7 @@ import (
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
)
{
var
set
types
.
LocalDBSet
for
_
,
log
:=
range
receiptData
.
Logs
{
...
...
@@ -21,16 +22,16 @@ func (e *Paracross) ExecLocal_Commit(payload *pt.ParacrossCommitAction, tx *type
var
r
pt
.
ParacrossTx
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
{
var
g
pt
.
ReceiptParacrossDone
types
.
Decode
(
log
.
Log
,
&
g
)
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
)
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
)
if
err
!=
nil
{
...
...
@@ -43,12 +44,13 @@ func (e *Paracross) ExecLocal_Commit(payload *pt.ParacrossCommitAction, tx *type
var
r
pt
.
ParacrossTx
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
}
//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
)
{
var
set
types
.
LocalDBSet
...
...
@@ -63,10 +65,12 @@ func (e *Paracross) ExecLocal_AssetTransfer(payload *types.AssetsTransfer, tx *t
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
)
{
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
)
{
if
index
!=
0
{
return
nil
,
pt
.
ErrParaMinerBaseIndex
...
...
@@ -108,20 +112,23 @@ func (e *Paracross) ExecLocal_Miner(payload *pt.ParacrossMinerAction, tx *types.
payload
.
Status
.
CrossTxResult
=
util
.
CalcSubBitMap
(
mixTxHashs
,
crossTxHashs
,
e
.
GetReceipt
()[
1
:
])
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
pt
.
CalcMinerHeightKey
(
payload
.
Status
.
Title
,
payload
.
Status
.
Height
),
types
.
Encode
(
payload
.
Status
)})
Key
:
pt
.
CalcMinerHeightKey
(
payload
.
Status
.
Title
,
payload
.
Status
.
Height
),
Value
:
types
.
Encode
(
payload
.
Status
)})
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
)
{
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
)
{
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
)
{
return
nil
,
nil
}
plugin/dapp/paracross/executor/paracross.go
View file @
27e5be5f
...
...
@@ -22,6 +22,7 @@ var (
driverName
=
pt
.
ParaX
)
// Paracross exec
type
Paracross
struct
{
drivers
.
DriverBase
}
...
...
@@ -31,11 +32,13 @@ func init() {
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Paracross
{}))
}
//Init paracross exec register
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newParacross
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
setPrefix
()
}
//GetName return paracross name
func
GetName
()
string
{
return
newParacross
()
.
GetName
()
}
...
...
@@ -47,6 +50,7 @@ func newParacross() drivers.Driver {
return
c
}
// GetDriverName return paracross driver name
func
(
c
*
Paracross
)
GetDriverName
()
string
{
return
pt
.
ParaX
}
...
...
@@ -157,11 +161,11 @@ func getCommitHeight(payload []byte) (int64, 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
())
if
isDel
{
c
.
GetLocalDB
()
.
Set
(
key
,
nil
)
return
&
types
.
KeyValue
{
key
,
nil
},
nil
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
},
nil
}
var
payload
pt
.
ParacrossAction
...
...
@@ -200,14 +204,14 @@ func (c *Paracross) initLocalAssetTransfer(tx *types.Transaction, success, isDel
if
err
!=
nil
{
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
)
{
key
:=
calcLocalAssetKey
(
tx
.
Hash
())
if
isDel
{
c
.
GetLocalDB
()
.
Set
(
key
,
nil
)
return
&
types
.
KeyValue
{
key
,
nil
},
nil
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
},
nil
}
var
asset
pt
.
ParacrossAsset
...
...
@@ -254,7 +258,7 @@ func (c *Paracross) initLocalAssetWithdraw(txCommit, tx *types.Transaction, isWi
if
err
!=
nil
{
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
)
{
...
...
@@ -283,9 +287,10 @@ func (c *Paracross) updateLocalAssetTransfer(txCommit, tx *types.Transaction, su
asset
.
Success
=
false
}
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
{
//不允许平行链
if
types
.
IsPara
()
{
...
...
@@ -320,6 +325,7 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error {
return
types
.
ErrNotAllow
}
// Allow add paracross allow rule
func
(
c
*
Paracross
)
Allow
(
tx
*
types
.
Transaction
,
index
int
)
error
{
//默认规则
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 {
item
.
Key
=
key
item
.
Addr
=
addr
item
.
Ty
=
mty
.
ConfigItemArrayConfig
emptyValue
:=
&
types
.
ArrayConfig
{
make
([]
string
,
0
)}
arr
:=
types
.
ConfigItem_Arr
{
emptyValue
}
emptyValue
:=
&
types
.
ArrayConfig
{
Value
:
make
([]
string
,
0
)}
arr
:=
types
.
ConfigItem_Arr
{
Arr
:
emptyValue
}
item
.
Value
=
&
arr
for
i
,
n
:=
range
Nodes
{
if
i
>=
cnt
{
...
...
@@ -132,13 +132,13 @@ func (suite *CommitTestSuite) SetupSuite() {
saveTitle
(
suite
.
stateDB
,
calcTitleKey
(
Title
),
&
titleStatus
)
// setup api
hashes
:=
&
types
.
ReqHashes
{[][]
byte
{
MainBlockHash10
}}
hashes
:=
&
types
.
ReqHashes
{
Hashes
:
[][]
byte
{
MainBlockHash10
}}
suite
.
api
.
On
(
"GetBlockByHashes"
,
hashes
)
.
Return
(
&
types
.
BlockDetails
{
Items
:
[]
*
types
.
BlockDetail
{
blockDetail
},
},
nil
)
suite
.
api
.
On
(
"GetBlockHash"
,
&
types
.
ReqInt
{
MainBlockHeight
})
.
Return
(
&
types
.
ReplyHash
{
MainBlockHash10
},
nil
)
suite
.
api
.
On
(
"GetBlockHash"
,
&
types
.
ReqInt
{
Height
:
MainBlockHeight
})
.
Return
(
&
types
.
ReplyHash
{
Hash
:
MainBlockHash10
},
nil
)
}
func
(
suite
*
CommitTestSuite
)
TestSetup
()
{
...
...
@@ -153,19 +153,19 @@ func (suite *CommitTestSuite) TestSetup() {
func
fillRawCommitTx
(
suite
suite
.
Suite
)
(
*
types
.
Transaction
,
error
)
{
st1
:=
pt
.
ParacrossNodeStatus
{
MainBlockHash10
,
MainBlockHeight
,
Title
,
TitleHeight
,
[]
byte
(
"block-hash-9"
),
[]
byte
(
"block-hash-10"
),
[]
byte
(
"state-hash-9"
),
[]
byte
(
"state-hash-10"
),
10
,
[]
byte
(
"abc"
),
[][]
byte
{},
[]
byte
(
"abc"
),
[][]
byte
{},
MainBlockHash
:
MainBlockHash
10
,
MainBlockHeight
:
MainBlockHeight
,
Title
:
Title
,
Height
:
TitleHeight
,
PreBlockHash
:
[]
byte
(
"block-hash-9"
),
BlockHash
:
[]
byte
(
"block-hash-10"
),
PreStateHash
:
[]
byte
(
"state-hash-9"
),
StateHash
:
[]
byte
(
"state-hash-10"
),
TxCounts
:
10
,
TxResult
:
[]
byte
(
"abc"
),
TxHashs
:
[][]
byte
{},
CrossTxResult
:
[]
byte
(
"abc"
),
CrossTxHashs
:
[][]
byte
{},
}
tx
,
err
:=
pt
.
CreateRawCommitTx4MainChain
(
&
st1
,
pt
.
ParaX
,
0
)
if
err
!=
nil
{
...
...
@@ -370,9 +370,9 @@ type VoteTestSuite struct {
exec
*
Paracross
}
func
(
s
uite
*
VoteTestSuite
)
SetupSuite
()
{
func
(
s
*
VoteTestSuite
)
SetupSuite
()
{
types
.
Init
(
Title
,
nil
)
s
uite
.
exec
=
newParacross
()
.
(
*
Paracross
)
s
.
exec
=
newParacross
()
.
(
*
Paracross
)
}
func
(
s
*
VoteTestSuite
)
TestVoteTx
()
{
...
...
plugin/dapp/paracross/executor/query.go
View file @
27e5be5f
...
...
@@ -11,41 +11,45 @@ import (
"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
{
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
)
{
return
e
.
ParacrossListTitles
()
//Query_ListTitles query paracross titles list
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
{
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
{
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
)
{
ret
,
err
:=
getTitle
(
c
.
GetStateDB
(),
calcTitleKey
(
title
))
func
(
p
*
Paracross
)
p
aracrossGetHeight
(
title
string
)
(
types
.
Message
,
error
)
{
ret
,
err
:=
getTitle
(
p
.
GetStateDB
(),
calcTitleKey
(
title
))
if
err
!=
nil
{
return
nil
,
errors
.
Cause
(
err
)
}
return
ret
,
nil
}
func
(
c
*
Paracross
)
P
aracrossListTitles
()
(
types
.
Message
,
error
)
{
return
listLocalTitles
(
c
.
GetLocalDB
())
func
(
p
*
Paracross
)
p
aracrossListTitles
()
(
types
.
Message
,
error
)
{
return
listLocalTitles
(
p
.
GetLocalDB
())
}
func
listLocalTitles
(
db
dbm
.
KVDB
)
(
types
.
Message
,
error
)
{
...
...
@@ -80,17 +84,17 @@ func loadLocalTitle(db dbm.KV, title string, height int64) (types.Message, error
return
&
resp
,
nil
}
func
(
c
*
Paracross
)
P
aracrossGetTitleHeight
(
title
string
,
height
int64
)
(
types
.
Message
,
error
)
{
return
loadLocalTitle
(
c
.
GetLocalDB
(),
title
,
height
)
func
(
p
*
Paracross
)
p
aracrossGetTitleHeight
(
title
string
,
height
int64
)
(
types
.
Message
,
error
)
{
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
{
return
nil
,
types
.
ErrInvalidParam
}
key
:=
calcLocalAssetKey
(
hash
)
value
,
err
:=
c
.
GetLocalDB
()
.
Get
(
key
)
value
,
err
:=
p
.
GetLocalDB
()
.
Get
(
key
)
if
err
!=
nil
{
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
return
nil
,
types
.
ErrDecode
}
// GetHeight jrpc get consensus height
func
(
c
*
Jrpc
)
GetHeight
(
req
*
types
.
ReqString
,
result
*
interface
{})
error
{
if
req
==
nil
{
return
types
.
ErrInvalidParam
...
...
@@ -42,6 +43,7 @@ func (c *channelClient) ListTitles(ctx context.Context, req *types.ReqNil) (*pt.
return
nil
,
types
.
ErrDecode
}
// ListTitles get paracross consensus titles list
func
(
c
*
Jrpc
)
ListTitles
(
req
*
types
.
ReqNil
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
ListTitles
(
context
.
Background
(),
req
)
*
result
=
data
...
...
@@ -59,6 +61,7 @@ func (c *channelClient) GetTitleHeight(ctx context.Context, req *pt.ReqParacross
return
nil
,
types
.
ErrDecode
}
// GetTitleHeight get consensus title height
func
(
c
*
Jrpc
)
GetTitleHeight
(
req
*
pt
.
ReqParacrossTitleHeight
,
result
*
interface
{})
error
{
if
req
==
nil
{
return
types
.
ErrInvalidParam
...
...
@@ -79,6 +82,7 @@ func (c *channelClient) GetAssetTxResult(ctx context.Context, req *types.ReqHash
return
nil
,
types
.
ErrDecode
}
// GetAssetTxResult get asset tx result
func
(
c
*
Jrpc
)
GetAssetTxResult
(
req
*
types
.
ReqHash
,
result
*
interface
{})
error
{
if
req
==
nil
{
return
types
.
ErrInvalidParam
...
...
plugin/dapp/paracross/rpc/types.go
View file @
27e5be5f
...
...
@@ -9,10 +9,12 @@ import (
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
)
// Jrpc paracross jrpc interface
type
Jrpc
struct
{
cli
*
channelClient
}
// Grpc paracross Grpc interface
type
Grpc
struct
{
*
channelClient
}
...
...
@@ -21,6 +23,7 @@ type channelClient struct {
types
.
ChannelClient
}
// Init paracross rpc register
func
Init
(
name
string
,
s
types
.
RPCServer
)
{
cli
:=
&
channelClient
{}
grpc
:=
&
Grpc
{
channelClient
:
cli
}
...
...
plugin/dapp/paracross/types/errors.go
View file @
27e5be5f
...
...
@@ -7,12 +7,20 @@ package types
import
"errors"
var
(
// ErrInvalidTitle invalid commit msg title
ErrInvalidTitle
=
errors
.
New
(
"ErrInvalidTitle"
)
// 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"
)
// ErrParaMinerBaseIndex miner base index not 0
ErrParaMinerBaseIndex
=
errors
.
New
(
"ErrParaMinerBaseIndex"
)
// ErrParaMinerTxType the 0 tx is not miner tx
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 (
var
tlog
=
log15
.
New
(
"module"
,
ParaX
)
// paracross 执行器的日志类型
const
(
// paracross 执行器的日志类型
// TyLogParacrossCommit commit log key
TyLogParacrossCommit
=
650
// TyLogParacrossCommitDone commit down key
TyLogParacrossCommitDone
=
651
// record 和 commit 不一样, 对应高度完成共识后收到commit 交易
// 这个交易就不参与共识, 只做记录
// TyLogParacrossCommitRecord commit record key
TyLogParacrossCommitRecord
=
652
// TyLogParaAssetTransfer asset transfer log key
TyLogParaAssetTransfer
=
653
// TyLogParaAssetWithdraw asset withdraw log key
TyLogParaAssetWithdraw
=
654
//在平行链上保存节点参与共识的数据
// TyLogParacrossMiner miner log key
TyLogParacrossMiner
=
655
// TyLogParaAssetDeposit asset deposit log key
TyLogParaAssetDeposit
=
656
)
type
P
aracrossCommitTx
struct
{
type
p
aracrossCommitTx
struct
{
Fee
int64
`json:"fee"`
Status
ParacrossNodeStatus
`json:"status"`
}
// action type
const
(
// ParacrossActionCommit paracross consensus commit action
ParacrossActionCommit
=
iota
// ParacrossActionMiner paracross consensus miner action
ParacrossActionMiner
// ParacrossActionTransfer paracross asset transfer action
ParacrossActionTransfer
// ParacrossActionWithdraw paracross asset withdraw action
ParacrossActionWithdraw
// ParacrossActionTransferToExec asset transfer to exec
ParacrossActionTransferToExec
)
const
(
P
araCrossTransferActionTypeStart
=
10000
P
araCrossTransferActionTypeEnd
=
10100
p
araCrossTransferActionTypeStart
=
10000
//p
araCrossTransferActionTypeEnd = 10100
)
const
(
ParacrossActionAssetTransfer
=
iota
+
ParaCrossTransferActionTypeStart
// ParacrossActionAssetTransfer paracross asset transfer key
ParacrossActionAssetTransfer
=
iota
+
paraCrossTransferActionTypeStart
// ParacrossActionAssetWithdraw paracross asset withdraw key
ParacrossActionAssetWithdraw
)
// status
const
(
// ParacrossStatusCommiting commit status
ParacrossStatusCommiting
=
iota
// ParacrossStatusCommitDone commit done status
ParacrossStatusCommitDone
)
var
(
// ParacrossActionCommitStr Commit string
ParacrossActionCommitStr
=
string
(
"Commit"
)
ParacrossTransferPerfix
=
"crossPara."
ParacrossActionAssetTransferStr
=
ParacrossTransferPerfix
+
string
(
"AssetTransfer"
)
ParacrossActionAssetWithdrawStr
=
ParacrossTransferPerfix
+
string
(
"AssetWithdraw"
)
ParacrossActionTransferStr
=
ParacrossTransferPerfix
+
string
(
"Transfer"
)
ParacrossActionTransferToExecStr
=
ParacrossTransferPerfix
+
string
(
"TransferToExec"
)
ParacrossActionWithdrawStr
=
ParacrossTransferPerfix
+
string
(
"Withdraw"
)
paracrossTransferPerfix
=
"crossPara."
// ParacrossActionAssetTransferStr asset transfer key
ParacrossActionAssetTransferStr
=
paracrossTransferPerfix
+
string
(
"AssetTransfer"
)
// ParacrossActionAssetWithdrawStr asset withdraw key
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
{
paraVoteHeightKey
:=
"LODB-paracross-titleVoteHeight-"
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
)
{
return
createRawCommitTx
(
status
,
name
,
fee
)
}
func
CreateRawParacrossCommitTx
(
parm
*
P
aracrossCommitTx
)
(
*
types
.
Transaction
,
error
)
{
func
createRawParacrossCommitTx
(
parm
*
p
aracrossCommitTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
tlog
.
Error
(
"
C
reateRawParacrossCommitTx"
,
"parm"
,
parm
)
tlog
.
Error
(
"
c
reateRawParacrossCommitTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
return
createRawCommitTx
(
&
parm
.
Status
,
types
.
ExecName
(
ParaX
),
parm
.
Fee
)
...
...
@@ -106,6 +131,7 @@ func createRawCommitTx(status *ParacrossNodeStatus, name string, fee int64) (*ty
return
tx
,
nil
}
// CreateRawAssetTransferTx create asset transfer tx
func
CreateRawAssetTransferTx
(
param
*
types
.
CreateTx
)
(
*
types
.
Transaction
,
error
)
{
// 跨链交易需要在主链和平行链上执行, 所以应该可以在主链和平行链上构建
if
!
types
.
IsParaExecName
(
param
.
GetExecName
())
{
...
...
@@ -138,6 +164,7 @@ func CreateRawAssetTransferTx(param *types.CreateTx) (*types.Transaction, error)
return
tx
,
nil
}
// CreateRawMinerTx create miner tx
func
CreateRawMinerTx
(
status
*
ParacrossNodeStatus
)
(
*
types
.
Transaction
,
error
)
{
v
:=
&
ParacrossMinerAction
{
Status
:
status
,
...
...
@@ -159,6 +186,7 @@ func CreateRawMinerTx(status *ParacrossNodeStatus) (*types.Transaction, error) {
return
tx
,
nil
}
// CreateRawTransferTx create paracross asset transfer tx with transfer and withdraw
func
CreateRawTransferTx
(
param
*
types
.
CreateTx
)
(
*
types
.
Transaction
,
error
)
{
if
!
types
.
IsParaExecName
(
param
.
GetExecName
())
{
tlog
.
Error
(
"CreateRawTransferTx"
,
"exec"
,
param
.
GetExecName
())
...
...
plugin/dapp/paracross/types/type.go
View file @
27e5be5f
...
...
@@ -13,6 +13,7 @@ import (
)
var
(
// ParaX paracross exec name
ParaX
=
"paracross"
glog
=
log
.
New
(
"module"
,
ParaX
)
...
...
@@ -30,9 +31,9 @@ var (
// init query rpc
/* TODO-TODO
types.RegisterRPCQueryHandle("ParacrossGetTitle", &ParacrossGetTitle{})
types.RegisterRPCQueryHandle("
ParacrossListTitles", &P
aracrossListTitles{})
types.RegisterRPCQueryHandle("
ParacrossGetTitleHeight", &P
aracrossGetTitleHeight{})
types.RegisterRPCQueryHandle("
ParacrossGetAssetTxResult", &P
aracrossGetAssetTxResult{})
types.RegisterRPCQueryHandle("
paracrossListTitles", &p
aracrossListTitles{})
types.RegisterRPCQueryHandle("
paracrossGetTitleHeight", &p
aracrossGetTitleHeight{})
types.RegisterRPCQueryHandle("
paracrossGetAssetTxResult", &p
aracrossGetAssetTxResult{})
*/
)
...
...
@@ -43,21 +44,25 @@ func init() {
types
.
RegisterDappFork
(
ParaX
,
"Enable"
,
0
)
}
// GetExecName get para exec name
func
GetExecName
()
string
{
return
types
.
ExecName
(
ParaX
)
}
// ParacrossType base paracross type
type
ParacrossType
struct
{
types
.
ExecTypeBase
}
// NewType get paracross type
func
NewType
()
*
ParacrossType
{
c
:=
&
ParacrossType
{}
c
.
SetChild
(
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
{
TyLogParacrossCommit
:
{
reflect
.
TypeOf
(
ReceiptParacrossCommit
{}),
"LogParacrossCommit"
},
TyLogParacrossCommitDone
:
{
reflect
.
TypeOf
(
ReceiptParacrossDone
{}),
"LogParacrossCommitDone"
},
...
...
@@ -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
{
"Commit"
:
ParacrossActionCommit
,
"Miner"
:
ParacrossActionMiner
,
...
...
@@ -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
{}
}
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"
{
var
param
P
aracrossCommitTx
var
param
p
aracrossCommitTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
glog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
C
reateRawParacrossCommitTx
(
&
param
)
return
c
reateRawParacrossCommitTx
(
&
param
)
}
else
if
action
==
"ParacrossAssetTransfer"
||
action
==
"ParacrossAssetWithdraw"
{
var
param
types
.
CreateTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -117,175 +125,3 @@ func (m ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
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 {
db
db
.
DB
}
func
newRelayDB
(
name
string
,
dir
string
,
cache
int32
)
*
relaydDB
{
d
:=
db
.
NewDB
(
name
,
"goleveldb"
,
dir
,
cache
)
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
func
deleteCreateOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
order
*
ty
.
RelayOrder
,
status
int32
)
[]
*
types
.
KeyValue
{
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
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
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
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
key
=
calcAcceptKeyAddr
(
order
,
status
)
if
key
!=
nil
{
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
}
return
kv
...
...
plugin/dapp/relay/executor/relay_test.go
View file @
27e5be5f
...
...
@@ -129,7 +129,7 @@ func (s *suiteRelay) TestExec_1() {
sell
:=
&
ty
.
RelayAction
{
Ty
:
ty
.
RelayActionCreate
,
Value
:
&
ty
.
RelayAction_Create
{
Create
:
order
},
Value
:
&
ty
.
RelayAction_Create
{
Create
:
order
},
}
tx
:=
&
types
.
Transaction
{}
...
...
@@ -140,7 +140,7 @@ func (s *suiteRelay) TestExec_1() {
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
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
()
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
...
...
@@ -172,7 +172,7 @@ func (s *suiteRelay) TestExec_2() {
sell
:=
&
ty
.
RelayAction
{
Ty
:
ty
.
RelayActionAccept
,
Value
:
&
ty
.
RelayAction_Accept
{
Accept
:
order
},
Value
:
&
ty
.
RelayAction_Accept
{
Accept
:
order
},
}
tx
:=
&
types
.
Transaction
{}
...
...
@@ -181,7 +181,7 @@ func (s *suiteRelay) TestExec_2() {
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
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
()
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
s
.
Nil
(
err
)
...
...
@@ -208,7 +208,7 @@ func (s *suiteRelay) TestExec_3() {
}
sell
:=
&
ty
.
RelayAction
{
Ty
:
ty
.
RelayActionConfirmTx
,
Value
:
&
ty
.
RelayAction_ConfirmTx
{
ConfirmTx
:
order
},
Value
:
&
ty
.
RelayAction_ConfirmTx
{
ConfirmTx
:
order
},
}
tx
:=
&
types
.
Transaction
{}
...
...
@@ -217,7 +217,7 @@ func (s *suiteRelay) TestExec_3() {
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
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
()
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
s
.
Nil
(
err
)
...
...
@@ -264,7 +264,7 @@ func (s *suiteRelay) TestExec_4() {
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
()
var
head
=
&
ty
.
BtcHeader
{
Version
:
1
,
...
...
@@ -280,7 +280,7 @@ func (s *suiteRelay) TestExec_4() {
}
sell
:=
&
ty
.
RelayAction
{
Ty
:
ty
.
RelayActionVerifyTx
,
Value
:
&
ty
.
RelayAction_Verify
{
Verify
:
order
},
Value
:
&
ty
.
RelayAction_Verify
{
Verify
:
order
},
}
tx
:=
&
types
.
Transaction
{}
tx
.
To
=
s
.
addrRelay
...
...
@@ -374,7 +374,7 @@ func (s *suiteRelay) TestExec_9_QryStatus5() {
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
()
msg
,
err
:=
s
.
relay
.
Query_GetBTCHeaderCurHeight
(
addrCoins
)
s
.
Nil
(
err
)
...
...
@@ -505,7 +505,7 @@ func (s *suiteBtcHeader) TestSaveBtcHead_1() {
sell
:=
&
ty
.
RelayAction
{
Ty
:
ty
.
RelayActionRcvBTCHeaders
,
Value
:
&
ty
.
RelayAction_BtcHeaders
{
BtcHeaders
:
headers
},
Value
:
&
ty
.
RelayAction_BtcHeaders
{
BtcHeaders
:
headers
},
}
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)
// hash:header
key
=
calcBtcHeaderKeyHash
(
head
.
Hash
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
val
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
val
})
// height:header
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
key
=
calcBtcHeaderKeyHeightList
(
int64
(
head
.
Height
))
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
Height
)})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
Height
)})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
return
kv
,
nil
}
...
...
@@ -108,13 +108,13 @@ func (b *btcStore) saveBlockHead(head *ty.BtcHeader) ([]*types.KeyValue, error)
func
(
b
*
btcStore
)
saveBlockLastHead
(
head
*
ty
.
ReceiptRelayRcvBTCHeaders
)
([]
*
types
.
KeyValue
,
error
)
{
var
kv
[]
*
types
.
KeyValue
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
NewHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
NewHeight
)})
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
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
return
kv
,
nil
}
...
...
@@ -123,14 +123,14 @@ func (b *btcStore) delBlockHead(head *ty.BtcHeader) ([]*types.KeyValue, error) {
var
kv
[]
*
types
.
KeyValue
key
:=
calcBtcHeaderKeyHash
(
head
.
Hash
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
// height:header
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
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
}
...
...
@@ -139,13 +139,13 @@ func (b *btcStore) delBlockLastHead(head *ty.ReceiptRelayRcvBTCHeaders) ([]*type
var
kv
[]
*
types
.
KeyValue
var
key
[]
byte
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
LastHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
LastHeight
)})
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
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
return
kv
,
nil
}
...
...
plugin/dapp/relay/executor/relaybtc_test.go
View file @
27e5be5f
...
...
@@ -34,14 +34,14 @@ func (s *suiteBtcStore) SetupSuite() {
}
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
()
val
,
_
:=
s
.
btc
.
getBtcHeadHeightFromDb
([]
byte
(
"key"
))
s
.
Assert
()
.
Equal
(
val
,
int64
(
10
))
}
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
()
val
,
_
:=
s
.
btc
.
getLastBtcHeadHeight
()
s
.
Assert
()
.
Equal
(
val
,
int64
(
10
))
...
...
@@ -58,7 +58,7 @@ func (s *suiteBtcStore) TestGetBtcHeadByHeight() {
}
func
(
s
*
suiteBtcStore
)
TestGetLastBtcHead
()
{
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
head
:=
&
ty
.
BtcHeader
{}
header
:=
types
.
Encode
(
head
)
...
...
@@ -82,12 +82,12 @@ func (s *suiteBtcStore) TestSaveBlockHead() {
}
val
,
_
:=
proto
.
Marshal
(
head
)
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
))
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
val
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
val
})
key
=
calcBtcHeaderKeyHeightList
(
int64
(
head
.
Height
))
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
Height
)})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
head
.
Height
)})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
res
,
err
:=
s
.
btc
.
saveBlockHead
(
head
)
s
.
Nil
(
err
)
...
...
@@ -104,13 +104,13 @@ func (s *suiteBtcStore) TestSaveBlockLastHead() {
NewBaseHeight
:
150
,
}
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
lastHead
.
NewHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
lastHead
.
NewHeight
)})
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
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
res
,
err
:=
s
.
btc
.
saveBlockLastHead
(
lastHead
)
s
.
Nil
(
err
)
...
...
@@ -131,14 +131,14 @@ func (s *suiteBtcStore) TestDelBlockHead() {
}
key
:=
calcBtcHeaderKeyHash
(
head
.
Hash
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
// height:header
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
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
)
s
.
Nil
(
err
)
...
...
@@ -155,13 +155,13 @@ func (s *suiteBtcStore) TestDelBlockLastHead() {
NewBaseHeight
:
150
,
}
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
lastHead
.
LastHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
lastHead
.
LastHeight
)})
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
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
heightBytes
})
res
,
err
:=
s
.
btc
.
delBlockLastHead
(
lastHead
)
s
.
Nil
(
err
)
...
...
@@ -241,7 +241,7 @@ func (s *suiteBtcStore) TestVerifyBtcTx() {
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
()
var
head
=
&
ty
.
BtcHeader
{
Version
:
1
,
...
...
@@ -290,7 +290,7 @@ func (s *suiteBtcStore) TestGetHeadHeightList() {
heightArry
:=
make
([][]
byte
,
10
)
for
i
:=
0
;
i
<
10
;
i
++
{
height
:=
int64
(
1000
+
i
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
height
})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
height
})
heightArry
[
i
]
=
heightBytes
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 {
func
(
r
*
relayLog
)
getKVSet
()
(
kvSet
[]
*
types
.
KeyValue
)
{
value
:=
types
.
Encode
(
&
r
.
RelayOrder
)
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
!=
""
{
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
...
...
@@ -179,7 +179,7 @@ func (action *relayDB) create(order *ty.RelayCreate) (*types.Receipt, error) {
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayCreate
))
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
{
...
...
@@ -290,7 +290,7 @@ func (action *relayDB) revokeCreate(revoke *ty.RelayRevoke) (*types.Receipt, err
}
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayRevokeCreate
))
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
)
{
...
...
@@ -355,7 +355,7 @@ func (action *relayDB) accept(accept *ty.RelayAccept) (*types.Receipt, error) {
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayAccept
))
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
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayRevokeAccept
))
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
)
{
...
...
@@ -487,7 +487,7 @@ func (action *relayDB) confirmTx(confirm *ty.RelayConfirmTx) (*types.Receipt, er
logs
=
append
(
logs
,
relayLog
.
receiptLog
(
ty
.
TyLogRelayConfirmTx
))
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
}
...
...
@@ -562,7 +562,7 @@ func (action *relayDB) verifyTx(verify *ty.RelayVerify) (*types.Receipt, error)
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receiptTransfer
.
KV
...
)
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
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receiptTransfer
.
KV
...
)
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
value
:=
types
.
Encode
(
head
)
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
++
{
db
.
Set
(
set
[
i
]
.
GetKey
(),
set
[
i
]
.
Value
)
...
...
@@ -714,5 +714,5 @@ func (action *relayDB) saveBtcHeader(headers *ty.BtcHeaders, localDb dbm.KVDB) (
log
.
Log
=
types
.
Encode
(
receipt
)
logs
=
append
(
logs
,
log
)
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() {
value
:=
types
.
Encode
(
&
s
.
log
.
RelayOrder
)
keyID
:=
[]
byte
(
s
.
log
.
Id
)
keyCoinTxHash
:=
[]
byte
(
calcCoinHash
(
s
.
log
.
CoinTxHash
))
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyID
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyCoinTxHash
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyID
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyCoinTxHash
,
Value
:
value
})
for
i
:=
0
;
i
<
len
(
kvSet
);
i
++
{
s
.
db
.
On
(
"Set"
,
kvSet
[
i
]
.
GetKey
(),
kvSet
[
i
]
.
Value
)
.
Return
(
nil
)
.
Once
()
...
...
@@ -61,8 +61,8 @@ func (s *suiteRelayLog) TestGetKVSet() {
value
:=
types
.
Encode
(
&
s
.
log
.
RelayOrder
)
keyID
:=
[]
byte
(
s
.
log
.
Id
)
keyCoinTxHash
:=
[]
byte
(
calcCoinHash
(
s
.
log
.
CoinTxHash
))
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyID
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyCoinTxHash
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyID
,
Value
:
value
})
kvSet
=
append
(
kvSet
,
&
types
.
KeyValue
{
Key
:
keyCoinTxHash
,
Value
:
value
})
rst
:=
s
.
log
.
getKVSet
()
s
.
Assert
()
.
Equal
(
kvSet
,
rst
)
...
...
@@ -176,7 +176,7 @@ func (s *suiteRelayDB) TestRelayCreate_1() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
s
.
Nil
(
err
)
...
...
@@ -208,7 +208,7 @@ func (s *suiteRelayDB) TestRevokeCreate_1aUnlock() {
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
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
()
_
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
...
@@ -229,7 +229,7 @@ func (s *suiteRelayDB) TestRevokeCreate_1bCancel() {
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
...
@@ -309,7 +309,7 @@ func (s *suiteAccept) setupRelayCreate() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
s
.
Nil
(
err
)
...
...
@@ -357,7 +357,7 @@ func (s *suiteAccept) TestRelayAccept() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
accept
(
order
)
s
.
Nil
(
err
)
...
...
@@ -388,7 +388,7 @@ func (s *suiteAccept) TestRevokeAccept_1() {
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
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
()
_
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
...
@@ -409,7 +409,7 @@ func (s *suiteAccept) TestRevokeAccept_2() {
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
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
()
_
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
...
@@ -430,7 +430,7 @@ func (s *suiteAccept) TestRevokeAccept_3() {
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
...
@@ -507,7 +507,7 @@ func (s *suiteConfirm) setupRelayCreate() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
s
.
Nil
(
err
)
...
...
@@ -556,7 +556,7 @@ func (s *suiteConfirm) setupAccept() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
accept
(
order
)
s
.
Nil
(
err
)
...
...
@@ -605,7 +605,7 @@ func (s *suiteConfirm) TestConfirm_2() {
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
confirmTx
(
order
)
s
.
Nil
(
err
)
...
...
@@ -636,7 +636,7 @@ func (s *suiteConfirm) TestRevokeConfirm_1() {
s
.
relay
.
SetEnv
(
40
,
4000
,
1
)
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
()
_
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
...
@@ -657,7 +657,7 @@ func (s *suiteConfirm) TestRevokeConfirm_2() {
s
.
relay
.
SetEnv
(
40
,
4000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
relayRevoke
(
order
)
...
...
@@ -734,7 +734,7 @@ func (s *suiteVerify) setupRelayCreate() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
s
.
Nil
(
err
)
...
...
@@ -765,7 +765,7 @@ func (s *suiteVerify) setupAccept() {
s
.
relay
.
SetEnv
(
20
,
2000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
accept
(
order
)
s
.
Nil
(
err
)
...
...
@@ -796,7 +796,7 @@ func (s *suiteVerify) setupConfirm() {
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
confirmTx
(
order
)
s
.
Nil
(
err
)
...
...
@@ -860,7 +860,7 @@ func (s *suiteVerify) TestVerify() {
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
()
var
head
=
&
ty
.
BtcHeader
{
Version
:
1
,
...
...
@@ -965,7 +965,7 @@ func (s *suiteVerifyCli) setupRelayCreate() {
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
create
(
order
)
s
.
Nil
(
err
)
...
...
@@ -996,7 +996,7 @@ func (s *suiteVerifyCli) setupAccept() {
s
.
relay
.
SetEnv
(
20
,
2000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
accept
(
order
)
s
.
Nil
(
err
)
...
...
@@ -1027,7 +1027,7 @@ func (s *suiteVerifyCli) setupConfirm() {
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
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
()
receipt
,
err
:=
s
.
relayDb
.
confirmTx
(
order
)
s
.
Nil
(
err
)
...
...
plugin/dapp/relay/rpc/rpc.go
View file @
27e5be5f
...
...
@@ -66,7 +66,8 @@ func createRawRelaySaveBTCHeadTx(parm *ty.BtcHeader) ([]byte, error) {
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
)
if
err
!=
nil
{
return
err
...
...
@@ -75,7 +76,8 @@ func (c *jrpc) CreateRawRelayOrderTx(in *ty.RelayCreate, result *interface{}) er
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
)
if
err
!=
nil
{
return
err
...
...
@@ -85,7 +87,8 @@ func (c *jrpc) CreateRawRelayAcceptTx(in *ty.RelayAccept, result *interface{}) e
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
)
if
err
!=
nil
{
return
err
...
...
@@ -95,7 +98,8 @@ func (c *jrpc) CreateRawRelayRevokeTx(in *ty.RelayRevoke, result *interface{}) e
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
)
if
err
!=
nil
{
return
err
...
...
@@ -105,7 +109,8 @@ func (c *jrpc) CreateRawRelayConfirmTx(in *ty.RelayConfirmTx, result *interface{
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
)
if
err
!=
nil
{
return
err
...
...
@@ -114,7 +119,8 @@ func (c *jrpc) CreateRawRelayVerifyBTCTx(in *ty.RelayVerifyCli, result *interfac
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
)
if
err
!=
nil
{
return
err
...
...
plugin/dapp/relay/rpc/rpc_test.go
View file @
27e5be5f
...
...
@@ -16,6 +16,6 @@ func newTestChannelClient() *channelClient {
}
}
func
newTestJrpcClient
()
*
j
rpc
{
return
&
j
rpc
{
cli
:
newTestChannelClient
()}
func
newTestJrpcClient
()
*
J
rpc
{
return
&
J
rpc
{
cli
:
newTestChannelClient
()}
}
plugin/dapp/relay/rpc/types.go
View file @
27e5be5f
...
...
@@ -8,11 +8,13 @@ import (
"github.com/33cn/chain33/rpc/types"
)
type
jrpc
struct
{
// Jrpc relay Jrpc interface
type
Jrpc
struct
{
cli
*
channelClient
}
type
grpc
struct
{
// Grpc relay Grpc interface
type
Grpc
struct
{
*
channelClient
}
...
...
@@ -23,6 +25,6 @@ type channelClient struct {
// Init relay rpc register
func
Init
(
name
string
,
s
types
.
RPCServer
)
{
cli
:=
&
channelClient
{}
grpc
:=
&
g
rpc
{
channelClient
:
cli
}
cli
.
Init
(
name
,
s
,
&
j
rpc
{
cli
:
cli
},
grpc
)
grpc
:=
&
G
rpc
{
channelClient
:
cli
}
cli
.
Init
(
name
,
s
,
&
J
rpc
{
cli
:
cli
},
grpc
)
}
plugin/dapp/relay/types/errors.go
View file @
27e5be5f
plugin/dapp/relay/types/relay.go
View file @
27e5be5f
...
...
@@ -167,7 +167,6 @@ func (r *RelayType) Amount(tx *types.Transaction) (int64, error) {
return
0
,
nil
}
// CreateTx relay create tx TODO 暂时不修改实现, 先完成结构的重构
func
(
r
*
RelayType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
var
tx
*
types
.
Transaction
...
...
plugin/store/mpt/db2/rlp/decode_test.go
View file @
27e5be5f
...
...
@@ -737,7 +737,7 @@ func ExampleDecode_structTagNil() {
Decode
(
bytes
.
NewReader
(
input
),
&
withEmptyOK
)
fmt
.
Printf
(
"with nil tag: String = %v
\n
"
,
withEmptyOK
.
String
)
// ProtoToJ
son
:
// ProtoToJ
SON
:
// normal: String = ""
// 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