Commit 5d8d0160 authored by suyanlong's avatar suyanlong

fix paracross exec address bug

parent 453fd14c
...@@ -70,6 +70,7 @@ type Paracross struct { ...@@ -70,6 +70,7 @@ type Paracross struct {
notify chan int64 // 高度完成提醒 notify chan int64 // 高度完成提醒
heightDiff int64 // 高度差 heightDiff int64 // 高度差
step int64 step int64
execAddress string
isTest bool isTest bool
logger hclog.InterceptLogger logger hclog.InterceptLogger
...@@ -159,6 +160,15 @@ func (p *Paracross) Initialize(configPath string, ID string, extra []byte) error ...@@ -159,6 +160,15 @@ func (p *Paracross) Initialize(configPath string, ID string, extra []byte) error
p.MinTxFeeRate = chain33Config.Chain33.Fee p.MinTxFeeRate = chain33Config.Chain33.Fee
p.isTest = chain33Config.Chain33.IsTest p.isTest = chain33Config.Chain33.IsTest
p.paraHeight = atomic.NewUint64(0) p.paraHeight = atomic.NewUint64(0)
if strings.ToUpper(chain33Config.Chain33.Symbol) == "YCC" {
execAddress, err := address.GetExecAddress(ID, 2)
if err != nil {
return errors.Wrap(err, "execAddress")
}
p.execAddress = execAddress
} else {
p.execAddress = address.ExecAddress(ID)
}
config33 = fmt.Sprintf(config33, p.title, chain33Config.Chain33.Addr) config33 = fmt.Sprintf(config33, p.title, chain33Config.Chain33.Addr)
p.logger.Info(config33) p.logger.Info(config33)
...@@ -450,7 +460,7 @@ func (p *Paracross) lockEvent(lock *types33.AssetsTransfer, tx *types33.Transact ...@@ -450,7 +460,7 @@ func (p *Paracross) lockEvent(lock *types33.AssetsTransfer, tx *types33.Transact
Contract: &types.Contract{ Contract: &types.Contract{
ChainID: cast.ToString(p.chainID), ChainID: cast.ToString(p.chainID),
ExecName: ID, ExecName: ID,
Address: address.ExecAddress(ID), // 合约地址 Address: p.execAddress, // 合约地址
CallMethod: "AssetTransfer", CallMethod: "AssetTransfer",
}, },
Payload: &types.MapAssetInfo{ Payload: &types.MapAssetInfo{
...@@ -477,7 +487,7 @@ func (p *Paracross) lockCrossEvent(lock *paracorssTypes.CrossAssetTransfer, tx * ...@@ -477,7 +487,7 @@ func (p *Paracross) lockCrossEvent(lock *paracorssTypes.CrossAssetTransfer, tx *
Contract: &types.Contract{ Contract: &types.Contract{
ChainID: cast.ToString(p.chainID), ChainID: cast.ToString(p.chainID),
ExecName: ID, ExecName: ID,
Address: address.ExecAddress(ID), // 合约地址 Address: p.execAddress, // 合约地址
CallMethod: "CrossAssetTransfer", CallMethod: "CrossAssetTransfer",
}, },
Payload: &types.MapAssetInfo{ Payload: &types.MapAssetInfo{
...@@ -500,7 +510,7 @@ func (p *Paracross) unLockEvent(unlock *types33.AssetsWithdraw, tx *types33.Tran ...@@ -500,7 +510,7 @@ func (p *Paracross) unLockEvent(unlock *types33.AssetsWithdraw, tx *types33.Tran
Contract: &types.Contract{ Contract: &types.Contract{
ChainID: cast.ToString(p.chainID), ChainID: cast.ToString(p.chainID),
ExecName: ID, ExecName: ID,
Address: address.ExecAddress(ID), // 合约地址 Address: p.execAddress, // 合约地址
CallMethod: "AssetsWithdraw", CallMethod: "AssetsWithdraw",
}, },
Payload: &types.MapAssetInfo{ Payload: &types.MapAssetInfo{
...@@ -702,7 +712,7 @@ func (p *Paracross) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { ...@@ -702,7 +712,7 @@ func (p *Paracross) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
if event.Payload.EventType == types.EventType_Burn { if event.Payload.EventType == types.EventType_Burn {
// 用户在联盟链一侧发起销毁。 // 用户在联盟链一侧发起销毁。
// 第一次提交。 // 第一次提交。
tx, err := paracorssTypes.CreateRawAssetTransferTxExt(p.chainID, p.MinTxFeeRate, &types33.CreateTx{ tx, err := p.CreateRawAssetTransferTxExt(p.chainID, p.MinTxFeeRate, &types33.CreateTx{
To: event.Payload.BurnAddress, To: event.Payload.BurnAddress,
Amount: event.Payload.BurnAmount, Amount: event.Payload.BurnAmount,
Fee: p.MinTxFeeRate, Fee: p.MinTxFeeRate,
...@@ -740,6 +750,39 @@ func (p *Paracross) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { ...@@ -740,6 +750,39 @@ func (p *Paracross) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
return nil, errors.New("ibtp error") return nil, errors.New("ibtp error")
} }
func (p *Paracross) CreateRawAssetTransferTxExt(chainID int32, minFee int64, param *types33.CreateTx) (*types33.Transaction, error) {
// 跨链交易需要在主链和平行链上执行, 所以应该可以在主链和平行链上构建
if !types33.IsParaExecName(param.GetExecName()) {
return nil, types33.ErrInvalidParam
}
transfer := &paracorssTypes.ParacrossAction{}
if !param.IsWithdraw {
v := &paracorssTypes.ParacrossAction_AssetTransfer{AssetTransfer: &types33.AssetsTransfer{
Amount: param.Amount, Note: param.GetNote(), To: param.GetTo(), Cointoken: param.TokenSymbol,
}}
transfer.Value = v
transfer.Ty = paracorssTypes.ParacrossActionAssetTransfer
} else {
v := &paracorssTypes.ParacrossAction_AssetWithdraw{AssetWithdraw: &types33.AssetsWithdraw{
Amount: param.Amount, Note: param.GetNote(), To: param.GetTo(), Cointoken: param.TokenSymbol, ExecName: param.ExecName,
}}
transfer.Value = v
transfer.Ty = paracorssTypes.ParacrossActionAssetWithdraw
}
rawtx := &types33.Transaction{
Execer: []byte(param.GetExecName()),
Payload: types33.Encode(transfer),
To: p.execAddress,
Fee: param.Fee,
}
tx, err := types33.FormatTxExt(chainID, true, minFee, param.GetExecName(), rawtx)
if err != nil {
return nil, err
}
return tx, nil
}
// 模拟status // 模拟status
func (p *Paracross) getNodeStatus(curTxHashs [][]byte, blockDetail *types33.BlockDetail, paraHeight int64) (*paracorssTypes.ParacrossNodeStatus, error) { func (p *Paracross) getNodeStatus(curTxHashs [][]byte, blockDetail *types33.BlockDetail, paraHeight int64) (*paracorssTypes.ParacrossNodeStatus, error) {
// var ( // var (
...@@ -828,7 +871,7 @@ func (p *Paracross) CreateRawCommitTx(commit *paracorssTypes.ParacrossCommitActi ...@@ -828,7 +871,7 @@ func (p *Paracross) CreateRawCommitTx(commit *paracorssTypes.ParacrossCommitActi
} }
tx := &types33.Transaction{ tx := &types33.Transaction{
Payload: types33.Encode(action), Payload: types33.Encode(action),
To: address.ExecAddress(execer), To: p.execAddress,
Expire: types33.Now().Unix() + int64(120), // 120s Expire: types33.Now().Unix() + int64(120), // 120s
} }
return p.FormatTx(tx) return p.FormatTx(tx)
......
...@@ -14,6 +14,7 @@ fee = 100000 ...@@ -14,6 +14,7 @@ fee = 100000
#被监听链ID #被监听链ID
chain_id = 0 chain_id = 0
step = 10 step = 10
symbol = "BTY"
[log] [log]
#日志级别 #日志级别
......
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