Commit 5d8d0160 authored by suyanlong's avatar suyanlong

fix paracross exec address bug

parent 453fd14c
......@@ -67,9 +67,10 @@ type Paracross struct {
cancel context.CancelFunc
// 保存区块:(latest_height-6)高度以下的区块
// 分类块中的交易为:已完成、未完成的交易。
notify chan int64 // 高度完成提醒
heightDiff int64 // 高度差
step int64
notify chan int64 // 高度完成提醒
heightDiff int64 // 高度差
step int64
execAddress string
isTest bool
logger hclog.InterceptLogger
......@@ -159,6 +160,15 @@ func (p *Paracross) Initialize(configPath string, ID string, extra []byte) error
p.MinTxFeeRate = chain33Config.Chain33.Fee
p.isTest = chain33Config.Chain33.IsTest
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)
p.logger.Info(config33)
......@@ -450,7 +460,7 @@ func (p *Paracross) lockEvent(lock *types33.AssetsTransfer, tx *types33.Transact
Contract: &types.Contract{
ChainID: cast.ToString(p.chainID),
ExecName: ID,
Address: address.ExecAddress(ID), // 合约地址
Address: p.execAddress, // 合约地址
CallMethod: "AssetTransfer",
},
Payload: &types.MapAssetInfo{
......@@ -477,7 +487,7 @@ func (p *Paracross) lockCrossEvent(lock *paracorssTypes.CrossAssetTransfer, tx *
Contract: &types.Contract{
ChainID: cast.ToString(p.chainID),
ExecName: ID,
Address: address.ExecAddress(ID), // 合约地址
Address: p.execAddress, // 合约地址
CallMethod: "CrossAssetTransfer",
},
Payload: &types.MapAssetInfo{
......@@ -500,7 +510,7 @@ func (p *Paracross) unLockEvent(unlock *types33.AssetsWithdraw, tx *types33.Tran
Contract: &types.Contract{
ChainID: cast.ToString(p.chainID),
ExecName: ID,
Address: address.ExecAddress(ID), // 合约地址
Address: p.execAddress, // 合约地址
CallMethod: "AssetsWithdraw",
},
Payload: &types.MapAssetInfo{
......@@ -702,7 +712,7 @@ func (p *Paracross) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
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,
Amount: event.Payload.BurnAmount,
Fee: p.MinTxFeeRate,
......@@ -740,6 +750,39 @@ func (p *Paracross) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, 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
func (p *Paracross) getNodeStatus(curTxHashs [][]byte, blockDetail *types33.BlockDetail, paraHeight int64) (*paracorssTypes.ParacrossNodeStatus, error) {
// var (
......@@ -828,7 +871,7 @@ func (p *Paracross) CreateRawCommitTx(commit *paracorssTypes.ParacrossCommitActi
}
tx := &types33.Transaction{
Payload: types33.Encode(action),
To: address.ExecAddress(execer),
To: p.execAddress,
Expire: types33.Now().Unix() + int64(120), // 120s
}
return p.FormatTx(tx)
......
......@@ -14,6 +14,7 @@ fee = 100000
#被监听链ID
chain_id = 0
step = 10
symbol = "BTY"
[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