Commit 2f8b1f10 authored by mdj33's avatar mdj33 Committed by vipwzw

adjust transfer or withdraw by asset Exec

parent 8f380378
...@@ -528,7 +528,7 @@ function para_cross_transfer_from_parachain() { ...@@ -528,7 +528,7 @@ function para_cross_transfer_from_parachain() {
fi fi
echo "========== #1. user.p.game chain transfer to main chain 300 user.p.game.coins.para, remain=700 ===========" echo "========== #1. user.p.game chain transfer to main chain 300 user.p.game.coins.para, remain=700 ==========="
hash=$(${PARA_CLI5} send para cross_transfer -a 300 -s user.p.game.coins.para -d 1 -t 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu -k 0x128de4afa7c061c00d854a1bca51b58e80a2c292583739e5aebf4c0f778959e1) hash=$(${PARA_CLI5} send para cross_transfer -a 300 -e user.p.game.coins -s para -t 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu -k 0x128de4afa7c061c00d854a1bca51b58e80a2c292583739e5aebf4c0f778959e1)
echo "${hash}" echo "${hash}"
query_tx "${PARA_CLI5}" "${hash}" query_tx "${PARA_CLI5}" "${hash}"
check_cross_transfer_game_balance "300.0000" "0.0000" "${hash}" check_cross_transfer_game_balance "300.0000" "0.0000" "${hash}"
...@@ -547,13 +547,13 @@ function para_cross_transfer_from_parachain() { ...@@ -547,13 +547,13 @@ function para_cross_transfer_from_parachain() {
echo "${hash}" echo "${hash}"
query_tx "${CLI}" "${hash}" query_tx "${CLI}" "${hash}"
hash=$(${CLI} --paraName=user.p.para. send para cross_transfer -a 200 -s user.p.game.coins.para -d 0 -t 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu -k 0x128de4afa7c061c00d854a1bca51b58e80a2c292583739e5aebf4c0f778959e1) hash=$(${CLI} --paraName=user.p.para. send para cross_transfer -a 200 -e paracross -s user.p.game.coins.para -t 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu -k 0x128de4afa7c061c00d854a1bca51b58e80a2c292583739e5aebf4c0f778959e1)
echo "${hash}" echo "${hash}"
query_tx "${CLI}" "${hash}" query_tx "${CLI}" "${hash}"
check_cross_transfer_para_balance "100.0000" "200.0000" "${hash}" check_cross_transfer_para_balance "100.0000" "200.0000" "${hash}"
echo "========== #3. withdraw game chain asset to main chain from para chain 50 user.p.game.coins.para,parachain=150,main=150 ====" echo "========== #3. withdraw game chain asset to main chain from para chain 50 user.p.game.coins.para,parachain=150,main=150 ===="
hash=$(${CLI} --paraName=user.p.para. send para cross_transfer -a 50 -s user.p.game.coins.para -d 1 -t 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu -k 0x128de4afa7c061c00d854a1bca51b58e80a2c292583739e5aebf4c0f778959e1) hash=$(${CLI} --paraName=user.p.para. send para cross_transfer -a 50 -e user.p.para.paracross -s paracross.user.p.game.coins.para -t 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu -k 0x128de4afa7c061c00d854a1bca51b58e80a2c292583739e5aebf4c0f778959e1)
echo "${hash}" echo "${hash}"
query_tx "${CLI}" "${hash}" query_tx "${CLI}" "${hash}"
check_cross_transfer_para_balance "100.0000" "150.0000" "${hash}" check_cross_transfer_para_balance "100.0000" "150.0000" "${hash}"
...@@ -569,7 +569,7 @@ function para_cross_transfer_from_parachain() { ...@@ -569,7 +569,7 @@ function para_cross_transfer_from_parachain() {
fi fi
echo "========== #4. withdraw game chain asset to game chain from main chain 50 user.p.game.coins.para,parachain=150,main=100,para=50+700 ======" echo "========== #4. withdraw game chain asset to game chain from main chain 50 user.p.game.coins.para,parachain=150,main=100,para=50+700 ======"
hash=$(${CLI} --paraName=user.p.game. send para cross_transfer -a 50 -s user.p.game.coins.para -d 0 -t 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu -k 0x128de4afa7c061c00d854a1bca51b58e80a2c292583739e5aebf4c0f778959e1) hash=$(${CLI} --paraName=user.p.game. send para cross_transfer -a 50 -e paracross -s user.p.game.coins.para -t 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu -k 0x128de4afa7c061c00d854a1bca51b58e80a2c292583739e5aebf4c0f778959e1)
echo "${hash}" echo "${hash}"
query_tx "${CLI}" "${hash}" query_tx "${CLI}" "${hash}"
check_cross_transfer_game_balance "100.0000" "50.0000" "${hash}" check_cross_transfer_game_balance "100.0000" "50.0000" "${hash}"
...@@ -577,6 +577,7 @@ function para_cross_transfer_from_parachain() { ...@@ -577,6 +577,7 @@ function para_cross_transfer_from_parachain() {
function check_cross_transfer_para_balance() { function check_cross_transfer_para_balance() {
local times=200 local times=200
local hash="$3"
while true; do while true; do
acc=$(${CLI} asset balance -a 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu --asset_exec paracross --asset_symbol user.p.game.coins.para -e paracross | jq -r ".balance") acc=$(${CLI} asset balance -a 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu --asset_exec paracross --asset_symbol user.p.game.coins.para -e paracross | jq -r ".balance")
acc_para=$(${PARA_CLI} asset balance -a 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu --asset_exec paracross --asset_symbol paracross.user.p.game.coins.para -e paracross | jq -r ".balance") acc_para=$(${PARA_CLI} asset balance -a 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu --asset_exec paracross --asset_symbol paracross.user.p.game.coins.para -e paracross | jq -r ".balance")
...@@ -603,6 +604,7 @@ function check_cross_transfer_para_balance() { ...@@ -603,6 +604,7 @@ function check_cross_transfer_para_balance() {
function check_cross_transfer_game_balance() { function check_cross_transfer_game_balance() {
local times=200 local times=200
local hash="$3"
while true; do while true; do
acc=$(${CLI} asset balance -a 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu --asset_exec paracross --asset_symbol user.p.game.coins.para -e paracross | jq -r ".balance") acc=$(${CLI} asset balance -a 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu --asset_exec paracross --asset_symbol user.p.game.coins.para -e paracross | jq -r ".balance")
acc_para=$(${PARA_CLI5} account balance -a 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu -e user.p.game.paracross | jq -r ".balance") acc_para=$(${PARA_CLI5} account balance -a 1BM2xhBk95qoae8zKNDWwAVGgBERhb7DQu -e user.p.game.paracross | jq -r ".balance")
......
...@@ -249,8 +249,11 @@ func CreateRawCrossAssetTransferCmd() *cobra.Command { ...@@ -249,8 +249,11 @@ func CreateRawCrossAssetTransferCmd() *cobra.Command {
} }
func addCreateCrossAssetTransferFlags(cmd *cobra.Command) { func addCreateCrossAssetTransferFlags(cmd *cobra.Command) {
cmd.Flags().Uint32P("type", "d", 0, "transfer type: 0:to paraChain, 1:to mainChain") cmd.Flags().StringP("exec", "e", "", "exec of asset resident")
cmd.MarkFlagRequired("type") cmd.MarkFlagRequired("exec")
cmd.Flags().StringP("symbol", "s", "", "asset symbol like bty")
cmd.MarkFlagRequired("symbol")
cmd.Flags().StringP("to", "t", "", "transfer to account") cmd.Flags().StringP("to", "t", "", "transfer to account")
cmd.MarkFlagRequired("to") cmd.MarkFlagRequired("to")
...@@ -260,11 +263,10 @@ func addCreateCrossAssetTransferFlags(cmd *cobra.Command) { ...@@ -260,11 +263,10 @@ func addCreateCrossAssetTransferFlags(cmd *cobra.Command) {
cmd.Flags().StringP("note", "n", "", "transaction note info") 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) { func createCrossAssetTransfer(cmd *cobra.Command, args []string) {
ty, _ := cmd.Flags().GetUint32("type") ty, _ := cmd.Flags().GetString("exec")
toAddr, _ := cmd.Flags().GetString("to") toAddr, _ := cmd.Flags().GetString("to")
note, _ := cmd.Flags().GetString("note") note, _ := cmd.Flags().GetString("note")
symbol, _ := cmd.Flags().GetString("symbol") symbol, _ := cmd.Flags().GetString("symbol")
...@@ -283,13 +285,8 @@ func createCrossAssetTransfer(cmd *cobra.Command, args []string) { ...@@ -283,13 +285,8 @@ func createCrossAssetTransfer(cmd *cobra.Command, args []string) {
} }
execName := paraName + pt.ParaX 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 var config pt.CrossAssetTransfer
config.Type = ty config.AssetExec = ty
config.AssetSymbol = symbol config.AssetSymbol = symbol
config.ToAddr = toAddr config.ToAddr = toAddr
config.Note = note config.Note = note
......
...@@ -763,7 +763,7 @@ func execCrossTx(a *action, tx *types.TransactionDetail, crossTxHash []byte) (*t ...@@ -763,7 +763,7 @@ func execCrossTx(a *action, tx *types.TransactionDetail, crossTxHash []byte) (*t
clog.Crit("paracross.Commit getCrossAction Tx failed", "error", err, "txHash", common.ToHex(crossTxHash)) clog.Crit("paracross.Commit getCrossAction Tx failed", "error", err, "txHash", common.ToHex(crossTxHash))
return nil, err return nil, err
} }
if act == pt.ParacrossMainWithdraw || act == pt.ParacrossParaTransfer { if act == pt.ParacrossMainAssetWithdraw || act == pt.ParacrossParaAssetTransfer {
receipt, err := a.crossAssetTransfer(payload.GetCrossAssetTransfer(), act, tx.Tx) receipt, err := a.crossAssetTransfer(payload.GetCrossAssetTransfer(), act, tx.Tx)
if err != nil { if err != nil {
clog.Crit("paracross.Commit crossAssetTransfer Tx failed", "error", err, "act", act, "txHash", common.ToHex(crossTxHash)) clog.Crit("paracross.Commit crossAssetTransfer Tx failed", "error", err, "act", act, "txHash", common.ToHex(crossTxHash))
...@@ -808,7 +808,7 @@ func rollbackCrossTx(a *action, tx *types.TransactionDetail, crossTxHash []byte) ...@@ -808,7 +808,7 @@ func rollbackCrossTx(a *action, tx *types.TransactionDetail, crossTxHash []byte)
return nil, err return nil, err
} }
//主链共识后,平行链执行出错的主链资产transfer回滚 //主链共识后,平行链执行出错的主链资产transfer回滚
if act == pt.ParacrossMainTransfer { if act == pt.ParacrossMainAssetTransfer {
receipt, err := a.assetTransferRollback(payload.GetCrossAssetTransfer(), tx.Tx) receipt, err := a.assetTransferRollback(payload.GetCrossAssetTransfer(), tx.Tx)
if err != nil { if err != nil {
clog.Crit("paracross.Commit crossAssetTransfer rbk failed", "error", err, "txHash", common.ToHex(crossTxHash)) clog.Crit("paracross.Commit crossAssetTransfer rbk failed", "error", err, "txHash", common.ToHex(crossTxHash))
...@@ -819,7 +819,7 @@ func rollbackCrossTx(a *action, tx *types.TransactionDetail, crossTxHash []byte) ...@@ -819,7 +819,7 @@ func rollbackCrossTx(a *action, tx *types.TransactionDetail, crossTxHash []byte)
return receipt, nil return receipt, nil
} }
//主链共识后,平行链执行出错的平行链资产withdraw回滚 //主链共识后,平行链执行出错的平行链资产withdraw回滚
if act == pt.ParacrossParaWithdraw { if act == pt.ParacrossParaAssetWithdraw {
receipt, err := a.paraAssetWithdrawRollback(payload.GetCrossAssetTransfer(), tx.Tx) receipt, err := a.paraAssetWithdrawRollback(payload.GetCrossAssetTransfer(), tx.Tx)
if err != nil { if err != nil {
clog.Crit("paracross.Commit rbk paraAssetWithdraw Tx failed", "error", err, "txHash", common.ToHex(crossTxHash)) clog.Crit("paracross.Commit rbk paraAssetWithdraw Tx failed", "error", err, "txHash", common.ToHex(crossTxHash))
...@@ -1066,12 +1066,20 @@ func (a *action) CrossAssetTransfer(transfer *pt.CrossAssetTransfer) (*types.Rec ...@@ -1066,12 +1066,20 @@ func (a *action) CrossAssetTransfer(transfer *pt.CrossAssetTransfer) (*types.Rec
return nil, errors.Wrap(err, "CrossAssetTransfer not Allow") return nil, errors.Wrap(err, "CrossAssetTransfer not Allow")
} }
if len(transfer.AssetExec) == 0 || len(transfer.AssetSymbol) == 0 || transfer.Amount == 0 {
return nil, errors.Wrapf(types.ErrInvalidParam, "CrossAssetTransfer exec=%s, symbol=%s, amount=%d should not be null",
transfer.AssetExec, transfer.AssetSymbol, transfer.Amount)
}
if len(transfer.ToAddr) == 0 {
transfer.ToAddr = a.tx.From()
}
act, err := getCrossAction(transfer, string(a.tx.Execer)) act, err := getCrossAction(transfer, string(a.tx.Execer))
if act == pt.ParacrossNoneTransfer { if act == pt.ParacrossNoneTransfer {
return nil, errors.Wrap(err, "CrossAssetTransfer non action") return nil, errors.Wrap(err, "CrossAssetTransfer non action")
} }
// 需要平行链先执行, 达成共识时,继续执行 // 需要平行链先执行, 达成共识时,继续执行
if !isPara && (act == pt.ParacrossMainWithdraw || act == pt.ParacrossParaTransfer) { if !isPara && (act == pt.ParacrossMainAssetWithdraw || act == pt.ParacrossParaAssetTransfer) {
return nil, nil return nil, nil
} }
receipt, err := a.crossAssetTransfer(transfer, act, a.tx) receipt, err := a.crossAssetTransfer(transfer, act, a.tx)
......
...@@ -45,26 +45,29 @@ asset-transfer 分两种, 主链转出, 主链转入 ...@@ -45,26 +45,29 @@ asset-transfer 分两种, 主链转出, 主链转入
1. 某平行链paracross合约帐号, balance - 1. 某平行链paracross合约帐号, balance -
1. 用户主链paracross合约帐号, balance + 1. 用户主链paracross合约帐号, balance +
cross-transfer 把transfer和withdraw统一为transfer, 通过统一地址符号,内部判断是transfer和withdraw 主链<->平行链双向转移 cross-transfer
统一地址符号:title+执行器+符号 >cross-transfer 把transfer和withdraw都统一为transfer,通过执行器名字内部判断是transfer还是withdraw
1. 主链title缺省为空,类似:coins.bty, token.FZM
1. 平行链符号为: user.p.test.coins.para 或user.p.game.token.FZM *资产 = assetExec + assetSymbol 唯一确定一个资产
1. 主链资产:coins+BTY,token+CCNY
主链转移资产场景: type=0, tx.exec=user.p.test. 1. 平行链资产:user.p.test.coins + FZM,
1. 主链本币转移: symbol:{coins/token}.bty/cny or bty/cny, 1. 其他链转移过来的资产都在paracross执行器下: 主链:paracross + user.p.test.coins.FZM, 平行链: user.p.test.paracross + coins.BTY
平行链资产: paracross-coins.bty 1. 不支持从平行链直接转移到其他平行链,需要先转移到主链,再转移到平行链
2. 主链外币转移: symbol: user.p.para.coins.ccny, 举例:
平行链资产: paracross-paracross.user.p.para.coins.ccny ````
3. 平行链本币提回: symbol: user.p.test.coins.ccny exec symbol tx.title=user.p.test1 tx.title=user.p.test2
平行链资产: paracross账户coins.ccny资产释放 1. 主链上的资产:
平行链转移资产场景:type=1,tx.exec=user.p.test. coins bty transfer transfer
1. 平行链本币转移: symbol:user.p.test.{coins/token}.ccny paracross user.p.test1.coins.fzm withdraw transfer
主链产生资产: paracross-user.p.test.{coins}.ccny
2. 主链外币提取: symbol: user.p.para.coins.ccny 2. 平行链上的资产:
主链恢复外币资产:user.p.test.paracross地址释放user.p.para.coins.ccny user.p.test1.coins fzm transfer NAN
3. 主链本币提取: symbol: coins.bty user.p.test1.paracross coins.bty withdraw NAN
主链恢复本币资产:user.p.test.paracross地址释放coin.bty user.p.test1.paracross paracross.user.p.test2.coins.cny withdraw NAN
其中user.p.test1.paracross.paracross.user.p.test2.coins.cny资产解释:
user.p.test1.paracross.是平行链paracross执行器, paracross.user.p.test2.coins.cny的paracross代表从主链的paracross转移过来的user.p.test2.coins.cny资产
````
交易执行代码分为 三个部分 交易执行代码分为 三个部分
1. 主链 1. 主链
......
This diff is collapsed.
...@@ -16,11 +16,9 @@ import ( ...@@ -16,11 +16,9 @@ import (
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
dbm "github.com/33cn/chain33/common/db" dbm "github.com/33cn/chain33/common/db"
dbmock "github.com/33cn/chain33/common/db/mocks" dbmock "github.com/33cn/chain33/common/db/mocks"
coins "github.com/33cn/chain33/system/dapp/coins/types"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/paracross/testnode" "github.com/33cn/plugin/plugin/dapp/paracross/testnode"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types" pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
token "github.com/33cn/plugin/plugin/dapp/token/types"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
) )
...@@ -341,78 +339,123 @@ func createAssetTransferTokenTx(s suite.Suite, privFrom string, to []byte) (*typ ...@@ -341,78 +339,123 @@ func createAssetTransferTokenTx(s suite.Suite, privFrom string, to []byte) (*typ
func TestGetCrossAction(t *testing.T) { func TestGetCrossAction(t *testing.T) {
txExec := "paracross" txExec := "paracross"
transfer := &pt.CrossAssetTransfer{Type: 0, AssetSymbol: "coin.bty"} transfer := &pt.CrossAssetTransfer{AssetExec: "coins", AssetSymbol: "bty"}
action, err := getCrossAction(transfer, txExec) action, err := getCrossAction(transfer, txExec)
assert.NotNil(t, err) assert.NotNil(t, err)
assert.Equal(t, int64(pt.ParacrossNoneTransfer), action) assert.Equal(t, int64(pt.ParacrossNoneTransfer), action)
txExec = "user.p.para.paracross" txExec = "user.p.para.paracross."
transfer = &pt.CrossAssetTransfer{AssetExec: "user.p.test.coins", AssetSymbol: "bty"}
action, err = getCrossAction(transfer, txExec)
t.Log("ParacrossNoneTransfer e=", err)
assert.NotNil(t, err)
assert.Equal(t, int64(pt.ParacrossNoneTransfer), action)
transfer = &pt.CrossAssetTransfer{AssetExec: "coins", AssetSymbol: "bty"}
action, err = getCrossAction(transfer, txExec) action, err = getCrossAction(transfer, txExec)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, int64(pt.ParacrossMainTransfer), action) assert.Equal(t, int64(pt.ParacrossMainAssetTransfer), action)
transfer = &pt.CrossAssetTransfer{Type: 0, AssetSymbol: "user.p.para.coin.bty"} transfer = &pt.CrossAssetTransfer{AssetExec: "paracross", AssetSymbol: "user.p.para.coins.cbt"}
action, err = getCrossAction(transfer, txExec) action, err = getCrossAction(transfer, txExec)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, int64(pt.ParacrossParaWithdraw), action) assert.Equal(t, int64(pt.ParacrossParaAssetWithdraw), action)
transfer = &pt.CrossAssetTransfer{Type: 0, AssetSymbol: "user.p.test.coin.bty"} transfer = &pt.CrossAssetTransfer{AssetExec: "paracross", AssetSymbol: "user.p.test.coins.cbt"}
action, err = getCrossAction(transfer, txExec) action, err = getCrossAction(transfer, txExec)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, int64(pt.ParacrossMainTransfer), action) assert.Equal(t, int64(pt.ParacrossMainAssetTransfer), action)
transfer = &pt.CrossAssetTransfer{Type: 1, AssetSymbol: "coin.bty"} transfer = &pt.CrossAssetTransfer{AssetExec: "user.p.para.coins", AssetSymbol: "bty"}
action, err = getCrossAction(transfer, txExec) action, err = getCrossAction(transfer, txExec)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, int64(pt.ParacrossMainWithdraw), action) assert.Equal(t, int64(pt.ParacrossParaAssetTransfer), action)
transfer = &pt.CrossAssetTransfer{Type: 1, AssetSymbol: "user.p.para.coin.bty"} transfer = &pt.CrossAssetTransfer{AssetExec: "user.p.para.paracross", AssetSymbol: "coin.bty"}
action, err = getCrossAction(transfer, txExec) action, err = getCrossAction(transfer, txExec)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, int64(pt.ParacrossParaTransfer), action) assert.Equal(t, int64(pt.ParacrossMainAssetWithdraw), action)
transfer = &pt.CrossAssetTransfer{Type: 1, AssetSymbol: "user.p.test.coin.bty"} transfer = &pt.CrossAssetTransfer{AssetExec: "user.p.para.paracross", AssetSymbol: "paracross.user.p.test.coin.bty"}
action, err = getCrossAction(transfer, txExec) action, err = getCrossAction(transfer, txExec)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, int64(pt.ParacrossMainWithdraw), action) assert.Equal(t, int64(pt.ParacrossMainAssetWithdraw), action)
} }
func TestFormatTransfer(t *testing.T) { func TestAmendTransferParam(t *testing.T) {
act := int64(pt.ParacrossMainTransfer) act := int64(pt.ParacrossMainAssetTransfer)
transfer := &pt.CrossAssetTransfer{Type: 0, AssetSymbol: "user.p.coins.bty"} transfer := &pt.CrossAssetTransfer{AssetExec: "coins", AssetSymbol: "bty"}
rst := formatTransfer(transfer, act) rst, err := amendTransferParam(transfer, act)
assert.Equal(t, pt.ParaX, rst.AssetExec) assert.Nil(t, err)
assert.Equal(t, transfer.AssetExec, rst.AssetExec)
act = pt.ParacrossMainWithdraw
transfer = &pt.CrossAssetTransfer{Type: 0, AssetSymbol: "user.p.coins.bty"} transfer = &pt.CrossAssetTransfer{AssetExec: "paracross", AssetSymbol: "user.p.para.coins.bty"}
rst = formatTransfer(transfer, act) rst, err = amendTransferParam(transfer, act)
assert.Equal(t, pt.ParaX, rst.AssetExec) assert.Nil(t, err)
assert.Equal(t, transfer.AssetExec, rst.AssetExec)
act = pt.ParacrossMainTransfer
transfer = &pt.CrossAssetTransfer{Type: 0, AssetSymbol: "coins.bty"} //
rst = formatTransfer(transfer, act) act = int64(pt.ParacrossMainAssetWithdraw)
assert.Equal(t, coins.CoinsX, rst.AssetExec) transfer = &pt.CrossAssetTransfer{AssetExec: "user.p.test.paracross", AssetSymbol: "coins.bty"}
rst, err = amendTransferParam(transfer, act)
act = pt.ParacrossMainWithdraw assert.Nil(t, err)
transfer = &pt.CrossAssetTransfer{Type: 0, AssetSymbol: "coins.bty"} assert.Equal(t, "coins", rst.AssetExec)
rst = formatTransfer(transfer, act)
assert.Equal(t, coins.CoinsX, rst.AssetExec)
act = pt.ParacrossMainTransfer
transfer = &pt.CrossAssetTransfer{Type: 0, AssetSymbol: "fzm"}
rst = formatTransfer(transfer, act)
assert.Equal(t, token.TokenX, rst.AssetExec)
act = pt.ParacrossMainTransfer
transfer = &pt.CrossAssetTransfer{Type: 0, AssetSymbol: ""}
rst = formatTransfer(transfer, act)
assert.Equal(t, coins.CoinsX, rst.AssetExec)
assert.Equal(t, "bty", rst.AssetSymbol) assert.Equal(t, "bty", rst.AssetSymbol)
act = pt.ParacrossParaTransfer act = int64(pt.ParacrossMainAssetWithdraw)
transfer = &pt.CrossAssetTransfer{Type: 0, AssetSymbol: "user.p.coins.para"} transfer = &pt.CrossAssetTransfer{AssetExec: "user.p.test.paracross", AssetSymbol: "paracross.user.p.test.coins.bty"}
rst = formatTransfer(transfer, act) rst, err = amendTransferParam(transfer, act)
assert.Equal(t, coins.CoinsX, rst.AssetExec) assert.Nil(t, err)
assert.Equal(t, "para", rst.AssetSymbol) assert.Equal(t, "paracross", rst.AssetExec)
assert.Equal(t, "user.p.test.coins.bty", rst.AssetSymbol)
act = int64(pt.ParacrossMainAssetWithdraw)
transfer = &pt.CrossAssetTransfer{AssetExec: "user.p.test.paracross", AssetSymbol: "bty"}
rst, err = amendTransferParam(transfer, act)
assert.NotNil(t, err)
//
act = int64(pt.ParacrossParaAssetTransfer)
transfer = &pt.CrossAssetTransfer{AssetExec: "user.p.test.coins", AssetSymbol: "bty"}
rst, err = amendTransferParam(transfer, act)
assert.Nil(t, err)
assert.Equal(t, "coins", rst.AssetExec)
assert.Equal(t, "bty", rst.AssetSymbol)
//
act = int64(pt.ParacrossParaAssetWithdraw)
transfer = &pt.CrossAssetTransfer{AssetExec: "paracross", AssetSymbol: "user.p.test.coins.bty"}
rst, err = amendTransferParam(transfer, act)
assert.Nil(t, err)
assert.Equal(t, "coins", rst.AssetExec)
assert.Equal(t, "bty", rst.AssetSymbol)
act = int64(pt.ParacrossParaAssetWithdraw)
transfer = &pt.CrossAssetTransfer{AssetExec: "paracross", AssetSymbol: "bty"}
rst, err = amendTransferParam(transfer, act)
assert.NotNil(t, err)
//
act = int64(pt.ParacrossMainAssetTransfer)
transfer = &pt.CrossAssetTransfer{AssetExec: "token", AssetSymbol: "coins.bty"}
rst, err = amendTransferParam(transfer, act)
assert.NotNil(t, err)
t.Log("token.coins.bty,err=", err)
transfer = &pt.CrossAssetTransfer{AssetExec: "paracross", AssetSymbol: "bty"}
rst, err = amendTransferParam(transfer, act)
assert.NotNil(t, err)
t.Log("paracross.bty,err=", err)
transfer = &pt.CrossAssetTransfer{AssetExec: "user.p.para.coins", AssetSymbol: "coins.bty"}
rst, err = amendTransferParam(transfer, act)
assert.NotNil(t, err)
t.Log("user.p.para.coins.coins.bty,err=", err)
transfer = &pt.CrossAssetTransfer{AssetExec: "user.p.para.paracross", AssetSymbol: "bty"}
rst, err = amendTransferParam(transfer, act)
assert.NotNil(t, err)
t.Log("user.p.para.paracross.bty,err=", err)
} }
...@@ -177,7 +177,7 @@ func (e *Paracross) ExecLocal_CrossAssetTransfer(payload *pt.CrossAssetTransfer, ...@@ -177,7 +177,7 @@ func (e *Paracross) ExecLocal_CrossAssetTransfer(payload *pt.CrossAssetTransfer,
} }
// 主链转出和平行链提取记录, // 主链转出和平行链提取记录,
// 主链提取和平行链转出在 commit done 时记录 // 主链提取和平行链转出在 commit done 时记录
if !cfg.IsPara() && (act == pt.ParacrossMainWithdraw || act == pt.ParacrossParaTransfer) { if !cfg.IsPara() && (act == pt.ParacrossMainAssetWithdraw || act == pt.ParacrossParaAssetTransfer) {
return nil, nil return nil, nil
} }
asset, err := e.getCrossAssetTransferInfo(payload, tx) asset, err := e.getCrossAssetTransferInfo(payload, tx)
......
...@@ -142,7 +142,7 @@ func (c *Paracross) udpateLocalParaTxs(paraTitle string, paraHeight int64, cross ...@@ -142,7 +142,7 @@ func (c *Paracross) udpateLocalParaTxs(paraTitle string, paraHeight int64, cross
return nil, err return nil, err
} }
//主链共识后,平行链执行出错的主链资产transfer回滚 //主链共识后,平行链执行出错的主链资产transfer回滚
if act == pt.ParacrossMainTransfer || act == pt.ParacrossParaWithdraw { if act == pt.ParacrossMainAssetTransfer || act == pt.ParacrossParaAssetWithdraw {
kv, err := c.updateLocalAssetTransfer(paraTx.Tx, paraHeight, success, isDel) kv, err := c.updateLocalAssetTransfer(paraTx.Tx, paraHeight, success, isDel)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -150,7 +150,7 @@ func (c *Paracross) udpateLocalParaTxs(paraTitle string, paraHeight int64, cross ...@@ -150,7 +150,7 @@ func (c *Paracross) udpateLocalParaTxs(paraTitle string, paraHeight int64, cross
set.KV = append(set.KV, kv) set.KV = append(set.KV, kv)
} }
//主链共识后,平行链执行出错的平行链资产withdraw回滚 //主链共识后,平行链执行出错的平行链资产withdraw回滚
if act == pt.ParacrossMainWithdraw || act == pt.ParacrossParaTransfer { if act == pt.ParacrossMainAssetWithdraw || act == pt.ParacrossParaAssetTransfer {
asset, err := c.getCrossAssetTransferInfo(payload.GetCrossAssetTransfer(), paraTx.Tx) asset, err := c.getCrossAssetTransferInfo(payload.GetCrossAssetTransfer(), paraTx.Tx)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -269,12 +269,12 @@ message ParacrossMinerAction { ...@@ -269,12 +269,12 @@ message ParacrossMinerAction {
} }
message CrossAssetTransfer { message CrossAssetTransfer {
uint32 type = 1; string assetExec = 1;
string assetExec = 2; string assetSymbol = 2;
string assetSymbol = 3; int64 amount = 3;
int64 amount = 4; //default signed addr
string toAddr = 5; string toAddr = 4;
string note = 6; string note = 5;
} }
message ParacrossAction { message ParacrossAction {
......
...@@ -85,10 +85,10 @@ const ( ...@@ -85,10 +85,10 @@ const (
const ( const (
ParacrossNoneTransfer = iota ParacrossNoneTransfer = iota
ParacrossMainTransfer ParacrossMainAssetTransfer
ParacrossMainWithdraw ParacrossMainAssetWithdraw
ParacrossParaTransfer ParacrossParaAssetTransfer
ParacrossParaWithdraw ParacrossParaAssetWithdraw
) )
// status // status
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment