X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=federation%2Fsynchron%2Fmainchain_keeper.go;h=3b4da044be1ee292180b99f98f07505ed311ced7;hp=b7770371076beceb522cd68ca2f46a736eded3f5;hb=a177b8b4f2828248c5bf34561b877c2578b77dd1;hpb=feed757163f1e2a5d1d6194b5f0323cd60cf0a81 diff --git a/federation/synchron/mainchain_keeper.go b/federation/synchron/mainchain_keeper.go index b7770371..3b4da044 100644 --- a/federation/synchron/mainchain_keeper.go +++ b/federation/synchron/mainchain_keeper.go @@ -7,12 +7,14 @@ import ( "fmt" "time" - "github.com/bytom/consensus" + btmConsensus "github.com/bytom/consensus" btmBc "github.com/bytom/protocol/bc" "github.com/bytom/protocol/bc/types" "github.com/jinzhu/gorm" log "github.com/sirupsen/logrus" + vaporConsensus "github.com/vapor/consensus" + "github.com/vapor/consensus/segwit" "github.com/vapor/errors" "github.com/vapor/federation/common" "github.com/vapor/federation/config" @@ -21,6 +23,7 @@ import ( "github.com/vapor/federation/service" "github.com/vapor/federation/util" "github.com/vapor/protocol/bc" + "github.com/vapor/wallet" ) type mainchainKeeper struct { @@ -207,8 +210,23 @@ func (m *mainchainKeeper) processDepositTx(chain *orm.Chain, block *types.Block, } func (m *mainchainKeeper) getCrossChainReqs(crossTransactionID uint64, tx *types.Tx, statusFail bool) ([]*orm.CrossTransactionReq, error) { + var fromAddress, toAddress string // assume inputs are from an identical owner - script := hex.EncodeToString(tx.Inputs[0].ControlProgram()) + prog := tx.Inputs[0].ControlProgram() + script := hex.EncodeToString(prog) + switch { + case segwit.IsP2WPKHScript(prog): + if pubHash, err := segwit.GetHashFromStandardProg(prog); err == nil { + fromAddress = wallet.BuildP2PKHAddress(pubHash, &vaporConsensus.MainNetParams) + toAddress = wallet.BuildP2PKHAddress(pubHash, &vaporConsensus.VaporNetParams) + } + case segwit.IsP2WSHScript(prog): + if scriptHash, err := segwit.GetHashFromStandardProg(prog); err == nil { + fromAddress = wallet.BuildP2SHAddress(scriptHash, &vaporConsensus.MainNetParams) + toAddress = wallet.BuildP2SHAddress(scriptHash, &vaporConsensus.VaporNetParams) + } + } + reqs := []*orm.CrossTransactionReq{} for i, rawOutput := range tx.Outputs { // check valid deposit @@ -216,7 +234,7 @@ func (m *mainchainKeeper) getCrossChainReqs(crossTransactionID uint64, tx *types continue } - if statusFail && *rawOutput.OutputCommitment.AssetAmount.AssetId != *consensus.BTMAssetID { + if statusFail && *rawOutput.OutputCommitment.AssetAmount.AssetId != *btmConsensus.BTMAssetID { continue } @@ -231,6 +249,8 @@ func (m *mainchainKeeper) getCrossChainReqs(crossTransactionID uint64, tx *types AssetID: asset.ID, AssetAmount: rawOutput.OutputCommitment.AssetAmount.Amount, Script: script, + FromAddress: fromAddress, + ToAddress: toAddress, } reqs = append(reqs, req) }