Commit 08482cde authored by linj's avatar linj

fix create transferToExec

parent 60651391
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
package types package types
import ( import (
fmt "fmt" "encoding/json"
"fmt"
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/log/log15" "github.com/33cn/chain33/common/log/log15"
...@@ -187,34 +188,28 @@ func CreateRawMinerTx(status *ParacrossNodeStatus) (*types.Transaction, error) { ...@@ -187,34 +188,28 @@ func CreateRawMinerTx(status *ParacrossNodeStatus) (*types.Transaction, error) {
} }
// CreateRawTransferTx create paracross asset transfer tx with transfer and withdraw // CreateRawTransferTx create paracross asset transfer tx with transfer and withdraw
func CreateRawTransferTx(param *types.CreateTx) (*types.Transaction, error) { func (p ParacrossType) CreateRawTransferTx(action string, param json.RawMessage) (*types.Transaction, error) {
if !types.IsParaExecName(param.GetExecName()) { tlog.Error("ParacrossType CreateTx failed", "action", action, "msg", string(param))
tlog.Error("CreateRawTransferTx", "exec", param.GetExecName()) tx, err := p.ExecTypeBase.CreateTx(action, param)
return nil, types.ErrInvalidParam if err != nil {
} tlog.Error("ParacrossType CreateTx failed", "err", err, "action", action, "msg", string(param))
return nil, err
transfer := &ParacrossAction{}
if !param.IsWithdraw {
v := &ParacrossAction_Transfer{Transfer: &types.AssetsTransfer{
Amount: param.Amount, Note: param.GetNote(), To: param.GetTo(), Cointoken: param.TokenSymbol}}
transfer.Value = v
transfer.Ty = ParacrossActionTransfer
} else {
v := &ParacrossAction_Withdraw{Withdraw: &types.AssetsWithdraw{
Amount: param.Amount, Note: param.GetNote(), To: param.GetTo(), Cointoken: param.TokenSymbol}}
transfer.Value = v
transfer.Ty = ParacrossActionWithdraw
}
tx := &types.Transaction{
Execer: []byte(param.GetExecName()),
Payload: types.Encode(transfer),
To: address.ExecAddress(param.GetExecName()),
Fee: param.Fee,
} }
var err error if !types.IsPara() {
tx, err = types.FormatTx(param.GetExecName(), tx) var transfer ParacrossAction
err = types.Decode(tx.Payload, &transfer)
if err != nil { if err != nil {
tlog.Error("ParacrossType CreateTx failed", "decode payload err", err, "action", action, "msg", string(param))
return nil, err return nil, err
} }
if action == "Transfer" {
tx.To = transfer.GetTransfer().To
} else if action == "Withdraw" {
tx.To = transfer.GetWithdraw().To
} else if action == "TransferToExec" {
tx.To = transfer.GetTransferToExec().To
}
}
return tx, nil return tx, nil
} }
...@@ -98,15 +98,16 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types. ...@@ -98,15 +98,16 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
} }
return CreateRawAssetTransferTx(&param) return CreateRawAssetTransferTx(&param)
} else if action == "ParacrossTransfer" || action == "ParacrossWithdraw" || action == "ParacrossTransferToExec" { } else if action == "ParacrossTransfer" || action == "Transfer" ||
action == "ParacrossWithdraw" || action == "Withdraw" ||
action == "ParacrossTransferToExec" || action == "TransferToExec" {
var param types.CreateTx var param types.CreateTx
err := json.Unmarshal(message, &param) err := json.Unmarshal(message, &param)
if err != nil { if err != nil {
glog.Error("CreateTx", "Error", err) glog.Error("CreateTx", "Error", err)
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
return CreateRawTransferTx(&param) return p.CreateRawTransferTx(action, message)
} }
return nil, types.ErrNotSupport return nil, types.ErrNotSupport
......
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