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
bdc1ab9a
Commit
bdc1ab9a
authored
Jan 09, 2020
by
mdj33
Committed by
vipwzw
Feb 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cross asset transfer
parent
bb9f022e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
279 additions
and
117 deletions
+279
-117
paracross.go
plugin/dapp/paracross/commands/paracross.go
+71
-1
action.go
plugin/dapp/paracross/executor/action.go
+0
-0
asset.go
plugin/dapp/paracross/executor/asset.go
+0
-0
exec.go
plugin/dapp/paracross/executor/exec.go
+16
-1
exec_del_local.go
plugin/dapp/paracross/executor/exec_del_local.go
+13
-1
exec_local.go
plugin/dapp/paracross/executor/exec_local.go
+32
-1
paracross.go
plugin/dapp/paracross/executor/paracross.go
+84
-62
query.go
plugin/dapp/paracross/executor/query.go
+1
-22
paracross.proto
plugin/dapp/paracross/proto/paracross.proto
+13
-17
paracross.go
plugin/dapp/paracross/types/paracross.go
+29
-2
type.go
plugin/dapp/paracross/types/type.go
+20
-10
No files found.
plugin/dapp/paracross/commands/paracross.go
View file @
bdc1ab9a
...
@@ -32,6 +32,7 @@ func ParcCmd() *cobra.Command {
...
@@ -32,6 +32,7 @@ func ParcCmd() *cobra.Command {
CreateRawTransferCmd
(),
CreateRawTransferCmd
(),
CreateRawWithdrawCmd
(),
CreateRawWithdrawCmd
(),
CreateRawTransferToExecCmd
(),
CreateRawTransferToExecCmd
(),
CreateRawCrossAssetTransferCmd
(),
superNodeCmd
(),
superNodeCmd
(),
nodeGroupCmd
(),
nodeGroupCmd
(),
paraConfigCmd
(),
paraConfigCmd
(),
...
@@ -236,6 +237,75 @@ func createWithdraw(cmd *cobra.Command, args []string) {
...
@@ -236,6 +237,75 @@ func createWithdraw(cmd *cobra.Command, args []string) {
commands
.
CreateAssetWithdraw
(
cmd
,
args
,
pt
.
ParaX
)
commands
.
CreateAssetWithdraw
(
cmd
,
args
,
pt
.
ParaX
)
}
}
// CreateRawCrossAssetTransferCmd create raw cross asset transfer tx
func
CreateRawCrossAssetTransferCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"cross_transfer"
,
Short
:
"Create a cross asset transfer transaction"
,
Run
:
createCrossAssetTransfer
,
}
addCreateCrossAssetTransferFlags
(
cmd
)
return
cmd
}
func
addCreateCrossAssetTransferFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uint32P
(
"type"
,
"d"
,
0
,
"transfer type: 0:to paraChain, 1:to mainChain"
)
cmd
.
MarkFlagRequired
(
"type"
)
cmd
.
Flags
()
.
StringP
(
"to"
,
"t"
,
""
,
"transfer to account"
)
cmd
.
MarkFlagRequired
(
"to"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0
,
"transaction amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"transaction note info"
)
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
""
,
"default for bty, parachain symbol like user.p.xx.bty"
)
}
func
createCrossAssetTransfer
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
ty
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"type"
)
toAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"to"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
symbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
if
amount
<
0
{
fmt
.
Fprintln
(
os
.
Stderr
,
"amount < 0"
)
return
}
amountInt64
:=
int64
(
math
.
Trunc
((
amount
+
0.0000001
)
*
1e4
))
*
1e4
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
if
!
strings
.
HasPrefix
(
paraName
,
"user.p"
)
{
fmt
.
Fprintln
(
os
.
Stderr
,
"paraName is not right, paraName format like `user.p.guodun.`"
)
return
}
execName
:=
paraName
+
pt
.
ParaX
if
ty
>
0
&&
symbol
==
""
{
fmt
.
Fprintln
(
os
.
Stderr
,
"transfer to main chain, symbol should not be null"
)
return
}
var
config
pt
.
CrossAssetTransfer
config
.
Type
=
ty
config
.
AssetSymbol
=
symbol
config
.
ToAddr
=
toAddr
config
.
Note
=
note
config
.
Amount
=
amountInt64
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
execName
,
ActionName
:
"CrossAssetTransfer"
,
Payload
:
types
.
MustPBToJSON
(
&
config
),
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
nil
)
ctx
.
RunWithoutMarshal
()
}
func
superNodeCmd
()
*
cobra
.
Command
{
func
superNodeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"super_node"
,
Use
:
"super_node"
,
...
@@ -1015,7 +1085,7 @@ func paraAssetTransfer(cmd *cobra.Command, args []string) {
...
@@ -1015,7 +1085,7 @@ func paraAssetTransfer(cmd *cobra.Command, args []string) {
}
}
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
var
res
pt
.
ParacrossAsset
Rsp
var
res
pt
.
ParacrossAsset
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
ctx
.
Run
()
}
}
...
...
plugin/dapp/paracross/executor/action.go
View file @
bdc1ab9a
This diff is collapsed.
Click to expand it.
plugin/dapp/paracross/executor/asset.go
View file @
bdc1ab9a
This diff is collapsed.
Click to expand it.
plugin/dapp/paracross/executor/exec.go
View file @
bdc1ab9a
...
@@ -42,7 +42,6 @@ func (e *Paracross) Exec_AssetTransfer(payload *types.AssetsTransfer, tx *types.
...
@@ -42,7 +42,6 @@ func (e *Paracross) Exec_AssetTransfer(payload *types.AssetsTransfer, tx *types.
//Exec_AssetWithdraw asset withdraw exec process
//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"
,
""
)
_
,
err
:=
e
.
checkTxGroup
(
tx
,
index
)
_
,
err
:=
e
.
checkTxGroup
(
tx
,
index
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"ParacrossActionAssetWithdraw"
,
"get tx group failed"
,
err
,
"hash"
,
hex
.
EncodeToString
(
tx
.
Hash
()))
clog
.
Error
(
"ParacrossActionAssetWithdraw"
,
"get tx group failed"
,
err
,
"hash"
,
hex
.
EncodeToString
(
tx
.
Hash
()))
...
@@ -57,6 +56,22 @@ func (e *Paracross) Exec_AssetWithdraw(payload *types.AssetsWithdraw, tx *types.
...
@@ -57,6 +56,22 @@ func (e *Paracross) Exec_AssetWithdraw(payload *types.AssetsWithdraw, tx *types.
return
receipt
,
nil
return
receipt
,
nil
}
}
//Exec_ParaAssetTransfer parallel chain asset transfer exec process
func
(
e
*
Paracross
)
Exec_CrossAssetTransfer
(
payload
*
pt
.
CrossAssetTransfer
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
_
,
err
:=
e
.
checkTxGroup
(
tx
,
index
)
if
err
!=
nil
{
clog
.
Error
(
"ParacrossActionCrossAssetTransfer"
,
"get tx group failed"
,
err
,
"hash"
,
hex
.
EncodeToString
(
tx
.
Hash
()))
return
nil
,
err
}
a
:=
newAction
(
e
,
tx
)
receipt
,
err
:=
a
.
CrossAssetTransfer
(
payload
)
if
err
!=
nil
{
clog
.
Error
(
"Paracross CrossAssetTransfer failed"
,
"error"
,
err
,
"hash"
,
hex
.
EncodeToString
(
tx
.
Hash
()))
return
nil
,
errors
.
Cause
(
err
)
}
return
receipt
,
nil
}
//Exec_Miner miner tx exec process
//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
{
...
...
plugin/dapp/paracross/executor/exec_del_local.go
View file @
bdc1ab9a
...
@@ -145,7 +145,7 @@ func (e *Paracross) ExecDelLocal_AssetTransfer(payload *types.AssetsTransfer, tx
...
@@ -145,7 +145,7 @@ func (e *Paracross) ExecDelLocal_AssetTransfer(payload *types.AssetsTransfer, tx
// 主链转出记录,
// 主链转出记录,
// 转入在 commit done 时记录, 因为没有日志里没有当时tx信息
// 转入在 commit done 时记录, 因为没有日志里没有当时tx信息
r
,
err
:=
e
.
initLocalAssetTransfer
(
tx
,
true
,
true
)
r
,
err
:=
e
.
initLocalAssetTransfer
(
tx
,
true
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -159,6 +159,18 @@ func (e *Paracross) ExecDelLocal_AssetWithdraw(payload *types.AssetsWithdraw, tx
...
@@ -159,6 +159,18 @@ func (e *Paracross) ExecDelLocal_AssetWithdraw(payload *types.AssetsWithdraw, tx
return
nil
,
nil
return
nil
,
nil
}
}
//ExecDelLocal_AssetTransfer asset transfer del local db process
func
(
e
*
Paracross
)
ExecDelLocal_CrossAssetTransfer
(
payload
*
pt
.
CrossAssetTransfer
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
var
set
types
.
LocalDBSet
r
,
err
:=
e
.
initLocalAssetTransfer
(
tx
,
true
,
nil
)
if
err
!=
nil
{
return
nil
,
err
}
set
.
KV
=
append
(
set
.
KV
,
r
)
return
&
set
,
nil
}
//ExecDelLocal_Miner miner tx del local db process
//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
{
...
...
plugin/dapp/paracross/executor/exec_local.go
View file @
bdc1ab9a
...
@@ -148,7 +148,11 @@ func (e *Paracross) ExecLocal_AssetTransfer(payload *types.AssetsTransfer, tx *t
...
@@ -148,7 +148,11 @@ func (e *Paracross) ExecLocal_AssetTransfer(payload *types.AssetsTransfer, tx *t
// 主链转出记录,
// 主链转出记录,
// 转入在 commit done 时记录, 因为没有日志里没有当时tx信息
// 转入在 commit done 时记录, 因为没有日志里没有当时tx信息
r
,
err
:=
e
.
initLocalAssetTransfer
(
tx
,
true
,
false
)
asset
,
err
:=
e
.
getAssetTransferInfo
(
tx
,
payload
.
Cointoken
,
false
)
if
err
!=
nil
{
return
nil
,
err
}
r
,
err
:=
e
.
initLocalAssetTransfer
(
tx
,
false
,
asset
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -162,6 +166,33 @@ func (e *Paracross) ExecLocal_AssetWithdraw(payload *types.AssetsWithdraw, tx *t
...
@@ -162,6 +166,33 @@ func (e *Paracross) ExecLocal_AssetWithdraw(payload *types.AssetsWithdraw, tx *t
return
nil
,
nil
return
nil
,
nil
}
}
//ExecLocal_AssetTransfer asset transfer local proc
func
(
e
*
Paracross
)
ExecLocal_CrossAssetTransfer
(
payload
*
pt
.
CrossAssetTransfer
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
var
set
types
.
LocalDBSet
cfg
:=
e
.
GetAPI
()
.
GetConfig
()
act
,
err
:=
getCrossAction
(
payload
,
string
(
tx
.
Execer
))
if
err
!=
nil
{
clog
.
Crit
(
"local CrossAssetTransfer getCrossAction failed"
,
"error"
,
err
)
return
nil
,
err
}
// 主链转出和平行链提取记录,
// 主链提取和平行链转出在 commit done 时记录
if
!
cfg
.
IsPara
()
&&
(
act
==
pt
.
ParacrossMainWithdraw
||
act
==
pt
.
ParacrossParaTransfer
)
{
return
nil
,
nil
}
asset
,
err
:=
e
.
getCrossAssetTransferInfo
(
payload
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
r
,
err
:=
e
.
initLocalAssetTransfer
(
tx
,
false
,
asset
)
if
err
!=
nil
{
return
nil
,
err
}
set
.
KV
=
append
(
set
.
KV
,
r
)
return
&
set
,
nil
}
func
setMinerTxResult
(
cfg
*
types
.
Chain33Config
,
payload
*
pt
.
ParacrossMinerAction
,
txs
[]
*
types
.
Transaction
,
receipts
[]
*
types
.
ReceiptData
)
error
{
func
setMinerTxResult
(
cfg
*
types
.
Chain33Config
,
payload
*
pt
.
ParacrossMinerAction
,
txs
[]
*
types
.
Transaction
,
receipts
[]
*
types
.
ReceiptData
)
error
{
isCommitTx
:=
make
(
map
[
string
]
bool
)
isCommitTx
:=
make
(
map
[
string
]
bool
)
var
curTxHashs
,
paraTxHashs
,
crossTxHashs
[][]
byte
var
curTxHashs
,
paraTxHashs
,
crossTxHashs
[][]
byte
...
...
plugin/dapp/paracross/executor/paracross.go
View file @
bdc1ab9a
...
@@ -8,12 +8,12 @@ import (
...
@@ -8,12 +8,12 @@ import (
"bytes"
"bytes"
"encoding/hex"
"encoding/hex"
"github.com/33cn/chain33/common"
log
"github.com/33cn/chain33/common/log/log15"
log
"github.com/33cn/chain33/common/log/log15"
drivers
"github.com/33cn/chain33/system/dapp"
drivers
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
"github.com/33cn/chain33/util"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/pkg/errors"
)
)
var
(
var
(
...
@@ -135,14 +135,46 @@ func (c *Paracross) udpateLocalParaTxs(paraTitle string, paraHeight int64, cross
...
@@ -135,14 +135,46 @@ func (c *Paracross) udpateLocalParaTxs(paraTitle string, paraHeight int64, cross
hex
.
EncodeToString
(
crossTxHashs
[
i
]))
hex
.
EncodeToString
(
crossTxHashs
[
i
]))
return
nil
,
err
return
nil
,
err
}
}
if
payload
.
Ty
==
pt
.
ParacrossActionCrossAssetTransfer
{
act
,
err
:=
getCrossAction
(
payload
.
GetCrossAssetTransfer
(),
string
(
paraTx
.
Tx
.
Execer
))
if
err
!=
nil
{
clog
.
Crit
(
"udpateLocalParaTxs getCrossAction failed"
,
"error"
,
err
)
return
nil
,
err
}
//主链共识后,平行链执行出错的主链资产transfer回滚
if
act
==
pt
.
ParacrossMainTransfer
||
act
==
pt
.
ParacrossParaWithdraw
{
kv
,
err
:=
c
.
updateLocalAssetTransfer
(
paraTx
.
Tx
,
paraHeight
,
success
,
isDel
)
if
err
!=
nil
{
return
nil
,
err
}
set
.
KV
=
append
(
set
.
KV
,
kv
)
}
//主链共识后,平行链执行出错的平行链资产withdraw回滚
if
act
==
pt
.
ParacrossMainWithdraw
||
act
==
pt
.
ParacrossParaTransfer
{
asset
,
err
:=
c
.
getCrossAssetTransferInfo
(
payload
.
GetCrossAssetTransfer
(),
paraTx
.
Tx
)
if
err
!=
nil
{
return
nil
,
err
}
kv
,
err
:=
c
.
initLocalAssetTransferDone
(
paraTx
.
Tx
,
asset
,
paraHeight
,
success
,
isDel
)
if
err
!=
nil
{
return
nil
,
err
}
set
.
KV
=
append
(
set
.
KV
,
kv
)
}
}
if
payload
.
Ty
==
pt
.
ParacrossActionAssetTransfer
{
if
payload
.
Ty
==
pt
.
ParacrossActionAssetTransfer
{
kv
,
err
:=
c
.
updateLocalAssetTransfer
(
para
Height
,
paraTx
.
Tx
,
success
,
isDel
)
kv
,
err
:=
c
.
updateLocalAssetTransfer
(
para
Tx
.
Tx
,
paraHeight
,
success
,
isDel
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
set
.
KV
=
append
(
set
.
KV
,
kv
)
set
.
KV
=
append
(
set
.
KV
,
kv
)
}
else
if
payload
.
Ty
==
pt
.
ParacrossActionAssetWithdraw
{
}
else
if
payload
.
Ty
==
pt
.
ParacrossActionAssetWithdraw
{
kv
,
err
:=
c
.
initLocalAssetWithdraw
(
paraHeight
,
paraTx
.
Tx
,
true
,
success
,
isDel
)
asset
,
err
:=
c
.
getAssetTransferInfo
(
paraTx
.
Tx
,
payload
.
GetAssetWithdraw
()
.
Cointoken
,
true
)
if
err
!=
nil
{
return
nil
,
err
}
kv
,
err
:=
c
.
initLocalAssetTransferDone
(
paraTx
.
Tx
,
asset
,
paraHeight
,
success
,
isDel
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -153,105 +185,90 @@ func (c *Paracross) udpateLocalParaTxs(paraTitle string, paraHeight int64, cross
...
@@ -153,105 +185,90 @@ func (c *Paracross) udpateLocalParaTxs(paraTitle string, paraHeight int64, cross
return
&
set
,
nil
return
&
set
,
nil
}
}
func
(
c
*
Paracross
)
initLocalAssetTransfer
(
tx
*
types
.
Transaction
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
error
)
{
func
(
c
*
Paracross
)
getAssetTransferInfo
(
tx
*
types
.
Transaction
,
coinToken
string
,
isWithdraw
bool
)
(
*
pt
.
ParacrossAsset
,
error
)
{
clog
.
Debug
(
"para execLocal"
,
"tx hash"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"action name"
,
log
.
Lazy
{
Fn
:
tx
.
ActionName
})
key
:=
calcLocalAssetKey
(
tx
.
Hash
())
if
isDel
{
c
.
GetLocalDB
()
.
Set
(
key
,
nil
)
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
},
nil
}
var
payload
pt
.
ParacrossAction
err
:=
types
.
Decode
(
tx
.
Payload
,
&
payload
)
if
err
!=
nil
{
return
nil
,
err
}
if
payload
.
GetAssetTransfer
()
==
nil
{
return
nil
,
errors
.
New
(
"GetAssetTransfer is nil"
)
}
exec
:=
"coins"
exec
:=
"coins"
symbol
:=
types
.
BTY
symbol
:=
types
.
BTY
if
payload
.
GetAssetTransfer
()
.
Coint
oken
!=
""
{
if
coinT
oken
!=
""
{
exec
=
"token"
exec
=
"token"
symbol
=
payload
.
GetAssetTransfer
()
.
Coint
oken
symbol
=
coinT
oken
}
}
var
asset
pt
.
ParacrossAsset
amount
,
err
:=
tx
.
Amount
()
amount
,
err
:=
tx
.
Amount
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
asset
=
pt
.
ParacrossAsset
{
asset
:=
&
pt
.
ParacrossAsset
{
From
:
tx
.
From
(),
From
:
tx
.
From
(),
To
:
tx
.
To
,
To
:
tx
.
To
,
Amount
:
amount
,
Amount
:
amount
,
IsWithdraw
:
false
,
IsWithdraw
:
isWithdraw
,
TxHash
:
tx
.
Hash
(
),
TxHash
:
common
.
ToHex
(
tx
.
Hash
()
),
Height
:
c
.
GetHeight
(),
Height
:
c
.
GetHeight
(),
Exec
:
exec
,
Exec
:
exec
,
Symbol
:
symbol
,
Symbol
:
symbol
,
}
}
return
asset
,
nil
}
err
=
c
.
GetLocalDB
()
.
Set
(
key
,
types
.
Encode
(
&
asset
))
func
(
c
*
Paracross
)
getCrossAssetTransferInfo
(
payload
*
pt
.
CrossAssetTransfer
,
tx
*
types
.
Transaction
)
(
*
pt
.
ParacrossAsset
,
error
)
{
exec
:=
payload
.
AssetExec
symbol
:=
payload
.
AssetSymbol
if
payload
.
AssetSymbol
==
""
{
symbol
=
types
.
BTY
exec
=
"coins"
}
amount
,
err
:=
tx
.
Amount
()
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"para execLocal"
,
"set"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"failed"
,
err
)
return
nil
,
err
}
}
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
&
asset
)},
nil
asset
:=
&
pt
.
ParacrossAsset
{
From
:
tx
.
From
(),
To
:
tx
.
To
,
Amount
:
amount
,
TxHash
:
common
.
ToHex
(
tx
.
Hash
()),
Height
:
c
.
GetHeight
(),
Exec
:
exec
,
Symbol
:
symbol
,
}
return
asset
,
nil
}
}
func
(
c
*
Paracross
)
initLocalAssetWithdraw
(
paraHeight
int64
,
tx
*
types
.
Transaction
,
isWithdraw
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
error
)
{
func
(
c
*
Paracross
)
initLocalAssetTransfer
(
tx
*
types
.
Transaction
,
isDel
bool
,
asset
*
pt
.
ParacrossAsset
)
(
*
types
.
KeyValue
,
error
)
{
clog
.
Debug
(
"para execLocal"
,
"tx hash"
,
hex
.
EncodeToString
(
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
:
key
,
Value
:
nil
},
nil
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
},
nil
}
}
var
asset
pt
.
ParacrossAsset
err
:=
c
.
GetLocalDB
()
.
Set
(
key
,
types
.
Encode
(
asset
))
amount
,
err
:=
tx
.
Amount
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
clog
.
Error
(
"para execLocal"
,
"set"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"failed"
,
err
)
}
asset
.
ParaHeight
=
paraHeight
var
payload
pt
.
ParacrossAction
err
=
types
.
Decode
(
tx
.
Payload
,
&
payload
)
if
err
!=
nil
{
return
nil
,
err
}
if
payload
.
GetAssetWithdraw
()
==
nil
{
return
nil
,
errors
.
New
(
"GetAssetWithdraw is nil"
)
}
exec
:=
"coins"
symbol
:=
types
.
BTY
if
payload
.
GetAssetWithdraw
()
.
Cointoken
!=
""
{
exec
=
"token"
symbol
=
payload
.
GetAssetWithdraw
()
.
Cointoken
}
}
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
asset
)},
nil
}
asset
=
pt
.
ParacrossAsset
{
func
(
c
*
Paracross
)
initLocalAssetTransferDone
(
tx
*
types
.
Transaction
,
asset
*
pt
.
ParacrossAsset
,
paraHeight
int64
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
error
)
{
From
:
tx
.
From
(),
key
:=
calcLocalAssetKey
(
tx
.
Hash
())
To
:
tx
.
To
,
if
isDel
{
Amount
:
amount
,
c
.
GetLocalDB
()
.
Set
(
key
,
nil
)
IsWithdraw
:
isWithdraw
,
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
},
nil
TxHash
:
tx
.
Hash
(),
Height
:
c
.
GetHeight
(),
Exec
:
exec
,
Symbol
:
symbol
,
}
}
asset
.
ParaHeight
=
paraHeight
asset
.
CommitDoneHeight
=
c
.
GetHeight
()
asset
.
CommitDoneHeight
=
c
.
GetHeight
()
asset
.
Success
=
success
asset
.
Success
=
success
err
=
c
.
GetLocalDB
()
.
Set
(
key
,
types
.
Encode
(
&
asset
))
err
:=
c
.
GetLocalDB
()
.
Set
(
key
,
types
.
Encode
(
asset
))
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"para execLocal"
,
"set"
,
""
,
"failed"
,
err
)
clog
.
Error
(
"para execLocal"
,
"set"
,
""
,
"failed"
,
err
)
}
}
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
&
asset
)},
nil
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
asset
)},
nil
}
}
func
(
c
*
Paracross
)
updateLocalAssetTransfer
(
paraHeight
int64
,
tx
*
types
.
Transaction
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
error
)
{
func
(
c
*
Paracross
)
updateLocalAssetTransfer
(
tx
*
types
.
Transaction
,
paraHeight
int64
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
error
)
{
clog
.
Debug
(
"para execLocal"
,
"tx hash"
,
hex
.
EncodeToString
(
tx
.
Hash
()))
clog
.
Debug
(
"para execLocal"
,
"tx hash"
,
hex
.
EncodeToString
(
tx
.
Hash
()))
key
:=
calcLocalAssetKey
(
tx
.
Hash
())
key
:=
calcLocalAssetKey
(
tx
.
Hash
())
...
@@ -317,6 +334,11 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error {
...
@@ -317,6 +334,11 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error {
return
nil
return
nil
}
}
}
}
if
cfg
.
IsDappFork
(
c
.
GetHeight
(),
pt
.
ParaX
,
pt
.
ForkParaAssetTransferRbk
)
{
if
payload
.
Ty
==
pt
.
ParacrossActionCrossAssetTransfer
{
return
nil
}
}
}
}
return
types
.
ErrNotAllow
return
types
.
ErrNotAllow
}
}
...
...
plugin/dapp/paracross/executor/query.go
View file @
bdc1ab9a
...
@@ -441,28 +441,7 @@ func (p *Paracross) paracrossGetAssetTxResult(hash []byte) (types.Message, error
...
@@ -441,28 +441,7 @@ func (p *Paracross) paracrossGetAssetTxResult(hash []byte) (types.Message, error
return
nil
,
err
return
nil
,
err
}
}
rsp
:=
&
pt
.
ParacrossAssetRsp
{
return
&
rst
,
nil
From
:
rst
.
From
,
To
:
rst
.
To
,
Amount
:
rst
.
Amount
,
Exec
:
rst
.
Exec
,
Symbol
:
rst
.
Symbol
,
Height
:
rst
.
Height
,
CommitDoneHeight
:
rst
.
CommitDoneHeight
,
ParaHeight
:
rst
.
ParaHeight
,
}
rsp
.
TxHash
=
common
.
ToHex
(
rst
.
TxHash
)
rsp
.
IsWithdraw
=
"false"
if
rst
.
IsWithdraw
{
rsp
.
IsWithdraw
=
"true"
}
rsp
.
Success
=
"false"
if
rst
.
Success
{
rsp
.
Success
=
"true"
}
return
rsp
,
nil
}
}
//Query_GetSelfConsStages get self consensus stages configed
//Query_GetSelfConsStages get self consensus stages configed
...
...
plugin/dapp/paracross/proto/paracross.proto
View file @
bdc1ab9a
...
@@ -268,6 +268,15 @@ message ParacrossMinerAction {
...
@@ -268,6 +268,15 @@ message ParacrossMinerAction {
bool
isSelfConsensus
=
2
;
bool
isSelfConsensus
=
2
;
}
}
message
CrossAssetTransfer
{
uint32
type
=
1
;
string
assetExec
=
2
;
string
assetSymbol
=
3
;
int64
amount
=
4
;
string
toAddr
=
5
;
string
note
=
6
;
}
message
ParacrossAction
{
message
ParacrossAction
{
oneof
value
{
oneof
value
{
ParacrossCommitAction
commit
=
1
;
ParacrossCommitAction
commit
=
1
;
...
@@ -280,6 +289,7 @@ message ParacrossAction {
...
@@ -280,6 +289,7 @@ message ParacrossAction {
ParaNodeAddrConfig
nodeConfig
=
9
;
ParaNodeAddrConfig
nodeConfig
=
9
;
ParaNodeGroupConfig
nodeGroupConfig
=
10
;
ParaNodeGroupConfig
nodeGroupConfig
=
10
;
ParaStageConfig
selfStageConfig
=
11
;
ParaStageConfig
selfStageConfig
=
11
;
CrossAssetTransfer
crossAssetTransfer
=
12
;
}
}
int32
ty
=
2
;
int32
ty
=
2
;
}
}
...
@@ -359,10 +369,12 @@ message ParacrossAsset {
...
@@ -359,10 +369,12 @@ message ParacrossAsset {
string
from
=
1
;
string
from
=
1
;
string
to
=
2
;
string
to
=
2
;
bool
isWithdraw
=
3
;
bool
isWithdraw
=
3
;
bytes
txHash
=
4
;
string
txHash
=
4
;
int64
amount
=
5
;
int64
amount
=
5
;
string
exec
=
6
;
string
exec
=
6
;
string
symbol
=
7
;
string
symbol
=
7
;
//跨链类型 0:to para, 1:to main
uint32
crossType
=
8
;
// 主链部分
// 主链部分
int64
height
=
10
;
int64
height
=
10
;
// 平行链部分
// 平行链部分
...
@@ -371,22 +383,6 @@ message ParacrossAsset {
...
@@ -371,22 +383,6 @@ message ParacrossAsset {
bool
success
=
23
;
bool
success
=
23
;
}
}
message
ParacrossAssetRsp
{
// input
string
from
=
1
;
string
to
=
2
;
string
isWithdraw
=
3
;
string
txHash
=
4
;
int64
amount
=
5
;
string
exec
=
6
;
string
symbol
=
7
;
// 主链部分
int64
height
=
10
;
// 平行链部分
int64
commitDoneHeight
=
21
;
int64
paraHeight
=
22
;
string
success
=
23
;
}
message
ParaLocalDbBlock
{
message
ParaLocalDbBlock
{
int64
height
=
1
;
int64
height
=
1
;
...
...
plugin/dapp/paracross/types/paracross.go
View file @
bdc1ab9a
...
@@ -46,6 +46,8 @@ const (
...
@@ -46,6 +46,8 @@ const (
TyLogParaSelfConsStageConfig
=
665
TyLogParaSelfConsStageConfig
=
665
TyLogParaStageVoteDone
=
666
TyLogParaStageVoteDone
=
666
TyLogParaStageGroupUpdate
=
667
TyLogParaStageGroupUpdate
=
667
//TyLogParaCrossAssetTransfer 统一的跨链资产转移
TyLogParaCrossAssetTransfer
=
670
)
)
type
paracrossCommitTx
struct
{
type
paracrossCommitTx
struct
{
...
@@ -73,9 +75,9 @@ const (
...
@@ -73,9 +75,9 @@ const (
)
)
const
(
const
(
// ParacrossActionAssetTransfer paracross asset transfer key
// ParacrossActionAssetTransfer
mainchain
paracross asset transfer key
ParacrossActionAssetTransfer
=
iota
+
paraCrossTransferActionTypeStart
ParacrossActionAssetTransfer
=
iota
+
paraCrossTransferActionTypeStart
// ParacrossActionAssetWithdraw paracross asset withdraw key
// ParacrossActionAssetWithdraw
mainchain
paracross asset withdraw key
ParacrossActionAssetWithdraw
ParacrossActionAssetWithdraw
//ParacrossActionNodeConfig para super node config
//ParacrossActionNodeConfig para super node config
ParacrossActionNodeConfig
ParacrossActionNodeConfig
...
@@ -83,6 +85,16 @@ const (
...
@@ -83,6 +85,16 @@ const (
ParacrossActionNodeGroupApply
ParacrossActionNodeGroupApply
//ParacrossActionSelfConsensStageConfig apply for self consensus stage config
//ParacrossActionSelfConsensStageConfig apply for self consensus stage config
ParacrossActionSelfStageConfig
ParacrossActionSelfStageConfig
// ParacrossActionCrossAssetTransfer crossChain asset transfer key
ParacrossActionCrossAssetTransfer
)
const
(
ParacrossNoneTransfer
=
iota
ParacrossMainTransfer
ParacrossMainWithdraw
ParacrossParaTransfer
ParacrossParaWithdraw
)
)
// status
// status
...
@@ -342,6 +354,21 @@ func (p ParacrossType) CreateRawTransferTx(action string, param json.RawMessage)
...
@@ -342,6 +354,21 @@ func (p ParacrossType) CreateRawTransferTx(action string, param json.RawMessage)
return
tx
,
nil
return
tx
,
nil
}
}
//CreateRawCrossAssetTransferTx create raw cross asset transfer tx
func
CreateRawCrossAssetTransferTx
(
apply
*
CrossAssetTransfer
)
(
*
types
.
Transaction
,
error
)
{
action
:=
&
ParacrossAction
{
Ty
:
ParacrossActionCrossAssetTransfer
,
Value
:
&
ParacrossAction_CrossAssetTransfer
{
apply
},
}
tx
:=
&
types
.
Transaction
{
Payload
:
types
.
Encode
(
action
),
}
return
tx
,
nil
}
//GetDappForkHeight get paracross dapp fork height
//GetDappForkHeight get paracross dapp fork height
func
GetDappForkHeight
(
cfg
*
types
.
Chain33Config
,
forkKey
string
)
int64
{
func
GetDappForkHeight
(
cfg
*
types
.
Chain33Config
,
forkKey
string
)
int64
{
var
forkHeight
int64
var
forkHeight
int64
...
...
plugin/dapp/paracross/types/type.go
View file @
bdc1ab9a
...
@@ -96,6 +96,7 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
...
@@ -96,6 +96,7 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
TyLogParaAssetWithdraw
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetWithdraw"
},
TyLogParaAssetWithdraw
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetWithdraw"
},
TyLogParaAssetTransfer
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetTransfer"
},
TyLogParaAssetTransfer
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetTransfer"
},
TyLogParaAssetDeposit
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetDeposit"
},
TyLogParaAssetDeposit
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetDeposit"
},
TyLogParaCrossAssetTransfer
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaCrossAssetTransfer"
},
TyLogParacrossMiner
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParacrossMiner
{}),
Name
:
"LogParacrossMiner"
},
TyLogParacrossMiner
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParacrossMiner
{}),
Name
:
"LogParacrossMiner"
},
TyLogParaNodeConfig
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeConfig
{}),
Name
:
"LogParaNodeConfig"
},
TyLogParaNodeConfig
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeConfig
{}),
Name
:
"LogParaNodeConfig"
},
TyLogParaNodeStatusUpdate
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeAddrStatUpdate
{}),
Name
:
"LogParaNodeAddrStatUpdate"
},
TyLogParaNodeStatusUpdate
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeAddrStatUpdate
{}),
Name
:
"LogParaNodeAddrStatUpdate"
},
...
@@ -112,16 +113,17 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
...
@@ -112,16 +113,17 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
// GetTypeMap get action type
// GetTypeMap get action type
func
(
p
*
ParacrossType
)
GetTypeMap
()
map
[
string
]
int32
{
func
(
p
*
ParacrossType
)
GetTypeMap
()
map
[
string
]
int32
{
return
map
[
string
]
int32
{
return
map
[
string
]
int32
{
"Commit"
:
ParacrossActionCommit
,
"Commit"
:
ParacrossActionCommit
,
"Miner"
:
ParacrossActionMiner
,
"Miner"
:
ParacrossActionMiner
,
"AssetTransfer"
:
ParacrossActionAssetTransfer
,
"AssetTransfer"
:
ParacrossActionAssetTransfer
,
"AssetWithdraw"
:
ParacrossActionAssetWithdraw
,
"AssetWithdraw"
:
ParacrossActionAssetWithdraw
,
"Transfer"
:
ParacrossActionTransfer
,
"Transfer"
:
ParacrossActionTransfer
,
"Withdraw"
:
ParacrossActionWithdraw
,
"Withdraw"
:
ParacrossActionWithdraw
,
"TransferToExec"
:
ParacrossActionTransferToExec
,
"TransferToExec"
:
ParacrossActionTransferToExec
,
"NodeConfig"
:
ParacrossActionNodeConfig
,
"CrossAssetTransfer"
:
ParacrossActionCrossAssetTransfer
,
"NodeGroupConfig"
:
ParacrossActionNodeGroupApply
,
"NodeConfig"
:
ParacrossActionNodeConfig
,
"SelfStageConfig"
:
ParacrossActionSelfStageConfig
,
"NodeGroupConfig"
:
ParacrossActionNodeGroupApply
,
"SelfStageConfig"
:
ParacrossActionSelfStageConfig
,
}
}
}
}
...
@@ -156,6 +158,14 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
...
@@ -156,6 +158,14 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
action
==
"ParacrossTransferToExec"
||
action
==
"TransferToExec"
{
action
==
"ParacrossTransferToExec"
||
action
==
"TransferToExec"
{
return
p
.
CreateRawTransferTx
(
action
,
message
)
return
p
.
CreateRawTransferTx
(
action
,
message
)
}
else
if
action
==
"CrossAssetTransfer"
{
var
param
CrossAssetTransfer
err
:=
types
.
JSONToPB
(
message
,
&
param
)
if
err
!=
nil
{
glog
.
Error
(
"CreateTx.CrossAssetTransfer"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawCrossAssetTransferTx
(
&
param
)
}
else
if
action
==
"NodeConfig"
{
}
else
if
action
==
"NodeConfig"
{
var
param
ParaNodeAddrConfig
var
param
ParaNodeAddrConfig
err
:=
types
.
JSONToPB
(
message
,
&
param
)
err
:=
types
.
JSONToPB
(
message
,
&
param
)
...
...
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