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 {
CreateRawTransferCmd
(),
CreateRawWithdrawCmd
(),
CreateRawTransferToExecCmd
(),
CreateRawCrossAssetTransferCmd
(),
superNodeCmd
(),
nodeGroupCmd
(),
paraConfigCmd
(),
...
...
@@ -236,6 +237,75 @@ func createWithdraw(cmd *cobra.Command, args []string) {
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
{
cmd
:=
&
cobra
.
Command
{
Use
:
"super_node"
,
...
...
@@ -1015,7 +1085,7 @@ func paraAssetTransfer(cmd *cobra.Command, args []string) {
}
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
var
res
pt
.
ParacrossAsset
Rsp
var
res
pt
.
ParacrossAsset
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
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.
//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
)
if
err
!=
nil
{
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.
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
func
(
e
*
Paracross
)
Exec_Miner
(
payload
*
pt
.
ParacrossMinerAction
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
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
// 主链转出记录,
// 转入在 commit done 时记录, 因为没有日志里没有当时tx信息
r
,
err
:=
e
.
initLocalAssetTransfer
(
tx
,
true
,
true
)
r
,
err
:=
e
.
initLocalAssetTransfer
(
tx
,
true
,
nil
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -159,6 +159,18 @@ func (e *Paracross) ExecDelLocal_AssetWithdraw(payload *types.AssetsWithdraw, tx
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
func
(
e
*
Paracross
)
ExecDelLocal_Miner
(
payload
*
pt
.
ParacrossMinerAction
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
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
// 主链转出记录,
// 转入在 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
{
return
nil
,
err
}
...
...
@@ -162,6 +166,33 @@ func (e *Paracross) ExecLocal_AssetWithdraw(payload *types.AssetsWithdraw, tx *t
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
{
isCommitTx
:=
make
(
map
[
string
]
bool
)
var
curTxHashs
,
paraTxHashs
,
crossTxHashs
[][]
byte
...
...
plugin/dapp/paracross/executor/paracross.go
View file @
bdc1ab9a
...
...
@@ -8,12 +8,12 @@ import (
"bytes"
"encoding/hex"
"github.com/33cn/chain33/common"
log
"github.com/33cn/chain33/common/log/log15"
drivers
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/pkg/errors"
)
var
(
...
...
@@ -135,14 +135,46 @@ func (c *Paracross) udpateLocalParaTxs(paraTitle string, paraHeight int64, cross
hex
.
EncodeToString
(
crossTxHashs
[
i
]))
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
{
kv
,
err
:=
c
.
updateLocalAssetTransfer
(
para
Height
,
paraTx
.
Tx
,
success
,
isDel
)
kv
,
err
:=
c
.
updateLocalAssetTransfer
(
para
Tx
.
Tx
,
paraHeight
,
success
,
isDel
)
if
err
!=
nil
{
return
nil
,
err
}
set
.
KV
=
append
(
set
.
KV
,
kv
)
}
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
{
return
nil
,
err
}
...
...
@@ -153,105 +185,90 @@ func (c *Paracross) udpateLocalParaTxs(paraTitle string, paraHeight int64, cross
return
&
set
,
nil
}
func
(
c
*
Paracross
)
initLocalAssetTransfer
(
tx
*
types
.
Transaction
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
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"
)
}
func
(
c
*
Paracross
)
getAssetTransferInfo
(
tx
*
types
.
Transaction
,
coinToken
string
,
isWithdraw
bool
)
(
*
pt
.
ParacrossAsset
,
error
)
{
exec
:=
"coins"
symbol
:=
types
.
BTY
if
payload
.
GetAssetTransfer
()
.
Coint
oken
!=
""
{
if
coinT
oken
!=
""
{
exec
=
"token"
symbol
=
payload
.
GetAssetTransfer
()
.
Coint
oken
symbol
=
coinT
oken
}
var
asset
pt
.
ParacrossAsset
amount
,
err
:=
tx
.
Amount
()
if
err
!=
nil
{
return
nil
,
err
}
asset
=
pt
.
ParacrossAsset
{
asset
:=
&
pt
.
ParacrossAsset
{
From
:
tx
.
From
(),
To
:
tx
.
To
,
Amount
:
amount
,
IsWithdraw
:
false
,
TxHash
:
tx
.
Hash
(
),
IsWithdraw
:
isWithdraw
,
TxHash
:
common
.
ToHex
(
tx
.
Hash
()
),
Height
:
c
.
GetHeight
(),
Exec
:
exec
,
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
{
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
())
if
isDel
{
c
.
GetLocalDB
()
.
Set
(
key
,
nil
)
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
},
nil
}
var
asset
pt
.
ParacrossAsset
amount
,
err
:=
tx
.
Amount
()
err
:=
c
.
GetLocalDB
()
.
Set
(
key
,
types
.
Encode
(
asset
))
if
err
!=
nil
{
return
nil
,
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
clog
.
Error
(
"para execLocal"
,
"set"
,
hex
.
EncodeToString
(
tx
.
Hash
()),
"failed"
,
err
)
}
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
asset
)},
nil
}
asset
=
pt
.
ParacrossAsset
{
From
:
tx
.
From
(),
To
:
tx
.
To
,
Amount
:
amount
,
IsWithdraw
:
isWithdraw
,
TxHash
:
tx
.
Hash
(),
Height
:
c
.
GetHeight
(),
Exec
:
exec
,
Symbol
:
symbol
,
func
(
c
*
Paracross
)
initLocalAssetTransferDone
(
tx
*
types
.
Transaction
,
asset
*
pt
.
ParacrossAsset
,
paraHeight
int64
,
success
,
isDel
bool
)
(
*
types
.
KeyValue
,
error
)
{
key
:=
calcLocalAssetKey
(
tx
.
Hash
())
if
isDel
{
c
.
GetLocalDB
()
.
Set
(
key
,
nil
)
return
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
},
nil
}
asset
.
ParaHeight
=
paraHeight
asset
.
CommitDoneHeight
=
c
.
GetHeight
()
asset
.
Success
=
success
err
=
c
.
GetLocalDB
()
.
Set
(
key
,
types
.
Encode
(
&
asset
))
err
:=
c
.
GetLocalDB
()
.
Set
(
key
,
types
.
Encode
(
asset
))
if
err
!=
nil
{
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
()))
key
:=
calcLocalAssetKey
(
tx
.
Hash
())
...
...
@@ -317,6 +334,11 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error {
return
nil
}
}
if
cfg
.
IsDappFork
(
c
.
GetHeight
(),
pt
.
ParaX
,
pt
.
ForkParaAssetTransferRbk
)
{
if
payload
.
Ty
==
pt
.
ParacrossActionCrossAssetTransfer
{
return
nil
}
}
}
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
return
nil
,
err
}
rsp
:=
&
pt
.
ParacrossAssetRsp
{
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
return
&
rst
,
nil
}
//Query_GetSelfConsStages get self consensus stages configed
...
...
plugin/dapp/paracross/proto/paracross.proto
View file @
bdc1ab9a
...
...
@@ -268,6 +268,15 @@ message ParacrossMinerAction {
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
{
oneof
value
{
ParacrossCommitAction
commit
=
1
;
...
...
@@ -280,6 +289,7 @@ message ParacrossAction {
ParaNodeAddrConfig
nodeConfig
=
9
;
ParaNodeGroupConfig
nodeGroupConfig
=
10
;
ParaStageConfig
selfStageConfig
=
11
;
CrossAssetTransfer
crossAssetTransfer
=
12
;
}
int32
ty
=
2
;
}
...
...
@@ -359,10 +369,12 @@ message ParacrossAsset {
string
from
=
1
;
string
to
=
2
;
bool
isWithdraw
=
3
;
bytes
txHash
=
4
;
string
txHash
=
4
;
int64
amount
=
5
;
string
exec
=
6
;
string
symbol
=
7
;
//跨链类型 0:to para, 1:to main
uint32
crossType
=
8
;
// 主链部分
int64
height
=
10
;
// 平行链部分
...
...
@@ -371,22 +383,6 @@ message ParacrossAsset {
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
{
int64
height
=
1
;
...
...
plugin/dapp/paracross/types/paracross.go
View file @
bdc1ab9a
...
...
@@ -46,6 +46,8 @@ const (
TyLogParaSelfConsStageConfig
=
665
TyLogParaStageVoteDone
=
666
TyLogParaStageGroupUpdate
=
667
//TyLogParaCrossAssetTransfer 统一的跨链资产转移
TyLogParaCrossAssetTransfer
=
670
)
type
paracrossCommitTx
struct
{
...
...
@@ -73,9 +75,9 @@ const (
)
const
(
// ParacrossActionAssetTransfer paracross asset transfer key
// ParacrossActionAssetTransfer
mainchain
paracross asset transfer key
ParacrossActionAssetTransfer
=
iota
+
paraCrossTransferActionTypeStart
// ParacrossActionAssetWithdraw paracross asset withdraw key
// ParacrossActionAssetWithdraw
mainchain
paracross asset withdraw key
ParacrossActionAssetWithdraw
//ParacrossActionNodeConfig para super node config
ParacrossActionNodeConfig
...
...
@@ -83,6 +85,16 @@ const (
ParacrossActionNodeGroupApply
//ParacrossActionSelfConsensStageConfig apply for self consensus stage config
ParacrossActionSelfStageConfig
// ParacrossActionCrossAssetTransfer crossChain asset transfer key
ParacrossActionCrossAssetTransfer
)
const
(
ParacrossNoneTransfer
=
iota
ParacrossMainTransfer
ParacrossMainWithdraw
ParacrossParaTransfer
ParacrossParaWithdraw
)
// status
...
...
@@ -342,6 +354,21 @@ func (p ParacrossType) CreateRawTransferTx(action string, param json.RawMessage)
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
func
GetDappForkHeight
(
cfg
*
types
.
Chain33Config
,
forkKey
string
)
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 {
TyLogParaAssetWithdraw
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetWithdraw"
},
TyLogParaAssetTransfer
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetTransfer"
},
TyLogParaAssetDeposit
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaAssetDeposit"
},
TyLogParaCrossAssetTransfer
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogParaCrossAssetTransfer"
},
TyLogParacrossMiner
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParacrossMiner
{}),
Name
:
"LogParacrossMiner"
},
TyLogParaNodeConfig
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeConfig
{}),
Name
:
"LogParaNodeConfig"
},
TyLogParaNodeStatusUpdate
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptParaNodeAddrStatUpdate
{}),
Name
:
"LogParaNodeAddrStatUpdate"
},
...
...
@@ -112,16 +113,17 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
// GetTypeMap get action type
func
(
p
*
ParacrossType
)
GetTypeMap
()
map
[
string
]
int32
{
return
map
[
string
]
int32
{
"Commit"
:
ParacrossActionCommit
,
"Miner"
:
ParacrossActionMiner
,
"AssetTransfer"
:
ParacrossActionAssetTransfer
,
"AssetWithdraw"
:
ParacrossActionAssetWithdraw
,
"Transfer"
:
ParacrossActionTransfer
,
"Withdraw"
:
ParacrossActionWithdraw
,
"TransferToExec"
:
ParacrossActionTransferToExec
,
"NodeConfig"
:
ParacrossActionNodeConfig
,
"NodeGroupConfig"
:
ParacrossActionNodeGroupApply
,
"SelfStageConfig"
:
ParacrossActionSelfStageConfig
,
"Commit"
:
ParacrossActionCommit
,
"Miner"
:
ParacrossActionMiner
,
"AssetTransfer"
:
ParacrossActionAssetTransfer
,
"AssetWithdraw"
:
ParacrossActionAssetWithdraw
,
"Transfer"
:
ParacrossActionTransfer
,
"Withdraw"
:
ParacrossActionWithdraw
,
"TransferToExec"
:
ParacrossActionTransferToExec
,
"CrossAssetTransfer"
:
ParacrossActionCrossAssetTransfer
,
"NodeConfig"
:
ParacrossActionNodeConfig
,
"NodeGroupConfig"
:
ParacrossActionNodeGroupApply
,
"SelfStageConfig"
:
ParacrossActionSelfStageConfig
,
}
}
...
...
@@ -156,6 +158,14 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
action
==
"ParacrossTransferToExec"
||
action
==
"TransferToExec"
{
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"
{
var
param
ParaNodeAddrConfig
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