From ba0ecea6018c29e64bf23cffa2a7392825e1aa20 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Thu, 13 Jun 2019 14:13:22 +0800 Subject: [PATCH] fix --- federation/synchron/common.go | 25 ++-------------------- federation/synchron/mainchain_keeper.go | 37 ++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/federation/synchron/common.go b/federation/synchron/common.go index 546ca8cd..0bfc2365 100644 --- a/federation/synchron/common.go +++ b/federation/synchron/common.go @@ -1,33 +1,12 @@ package synchron import ( - "bytes" - - btmTypes "github.com/bytom/protocol/bc/types" - vaporCfg "github.com/vapor/config" "github.com/vapor/errors" ) var ( + fedProg = vaporCfg.FederationProgrom(vaporCfg.CommonConfig) + ErrInconsistentDB = errors.New("inconsistent db status") ) - -func isDepositFromMainchain(tx *btmTypes.Tx) bool { - fedProg := vaporCfg.FederationProgrom(vaporCfg.CommonConfig) - for _, output := range tx.Outputs { - if bytes.Equal(output.OutputCommitment.ControlProgram, fedProg) { - return true - } - } - return false -} - -// func isWithdrawalToMainchain(tx *btmTypes.Tx) bool { -// for _, input := range tx.Inputs { -// if bytes.Equal(input.ControlProgram(), fedProg) { -// return true -// } -// } -// return false -// } diff --git a/federation/synchron/mainchain_keeper.go b/federation/synchron/mainchain_keeper.go index c847b395..5d46c77b 100644 --- a/federation/synchron/mainchain_keeper.go +++ b/federation/synchron/mainchain_keeper.go @@ -1,6 +1,7 @@ package synchron import ( + "bytes" "encoding/hex" "time" @@ -109,19 +110,45 @@ func (m *mainchainKeeper) processBlock(chain *orm.Chain, block *btmTypes.Block) } for i, tx := range block.Transactions { - if isDepositFromMainchain(tx) { - if err := m.processDepositFromMainchain(uint64(i), tx); err != nil { + if m.isDepositTx(tx) { + if err := m.processDepositTx(uint64(i), tx); err != nil { + return err + } + } + + if m.isWithdrawalTx(tx) { + if err := m.processWithdrawalTx(uint64(i), tx); err != nil { return err } } - // if isWithdrawalToMainchain(tx) { - // } } return m.processChainInfo(chain, block) } -func (m *mainchainKeeper) processDepositFromMainchain(txIndex uint64, tx *btmTypes.Tx) error { +func (m *mainchainKeeper) isDepositTx(tx *btmTypes.Tx) bool { + for _, output := range tx.Outputs { + if bytes.Equal(output.OutputCommitment.ControlProgram, fedProg) { + return true + } + } + return false +} + +func (m *mainchainKeeper) isWithdrawalTx(tx *btmTypes.Tx) bool { + for _, input := range tx.Inputs { + if bytes.Equal(input.ControlProgram(), fedProg) { + return true + } + } + return false +} + +func (m *mainchainKeeper) processDepositTx(txIndex uint64, tx *btmTypes.Tx) error { + return nil +} + +func (m *mainchainKeeper) processWithdrawalTx(txIndex uint64, tx *btmTypes.Tx) error { return nil } -- 2.11.0