"fmt"
"time"
- btmConsensus "github.com/bytom/consensus"
+ "github.com/bytom/consensus"
btmBc "github.com/bytom/protocol/bc"
- btmTypes "github.com/bytom/protocol/bc/types"
+ "github.com/bytom/protocol/bc/types"
"github.com/jinzhu/gorm"
log "github.com/sirupsen/logrus"
+ vaporCfg "github.com/vapor/config"
"github.com/vapor/errors"
"github.com/vapor/federation/common"
"github.com/vapor/federation/config"
"github.com/vapor/protocol/bc"
)
+var fedProg = vaporCfg.FederationProgrom(vaporCfg.CommonConfig)
+
type mainchainKeeper struct {
cfg *config.Chain
db *gorm.DB
return false, err
}
- nextBlock := &btmTypes.Block{}
+ nextBlock := &types.Block{}
if err := nextBlock.UnmarshalText([]byte(nextBlockStr)); err != nil {
return false, errors.New("Unmarshal nextBlock")
}
return true, nil
}
-func (m *mainchainKeeper) tryAttachBlock(chain *orm.Chain, block *btmTypes.Block, txStatus *bc.TransactionStatus) error {
+func (m *mainchainKeeper) tryAttachBlock(chain *orm.Chain, block *types.Block, txStatus *bc.TransactionStatus) error {
blockHash := block.Hash()
log.WithFields(log.Fields{"block_height": block.Height, "block_hash": blockHash.String()}).Info("start to attachBlock")
m.db.Begin()
return m.db.Commit().Error
}
-func (m *mainchainKeeper) processBlock(chain *orm.Chain, block *btmTypes.Block, txStatus *bc.TransactionStatus) error {
+func (m *mainchainKeeper) processBlock(chain *orm.Chain, block *types.Block, txStatus *bc.TransactionStatus) error {
if err := m.processIssuing(block.Transactions); err != nil {
return err
}
return m.processChainInfo(chain, block)
}
-func (m *mainchainKeeper) isDepositTx(tx *btmTypes.Tx) bool {
+func (m *mainchainKeeper) isDepositTx(tx *types.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 {
+func (m *mainchainKeeper) isWithdrawalTx(tx *types.Tx) bool {
for _, input := range tx.Inputs {
if bytes.Equal(input.ControlProgram(), fedProg) {
return true
return false
}
-func (m *mainchainKeeper) processDepositTx(chain *orm.Chain, block *btmTypes.Block, txStatus *bc.TransactionStatus, txIndex uint64, tx *btmTypes.Tx) error {
+func (m *mainchainKeeper) processDepositTx(chain *orm.Chain, block *types.Block, txStatus *bc.TransactionStatus, txIndex uint64, tx *types.Tx) error {
blockHash := block.Hash()
var muxID btmBc.Hash
}
statusFail := txStatus.VerifyStatus[txIndex].StatusFail
- crossChainInputs, err := m.getCrossChainInputs(ormTx.ID, tx, statusFail)
+ crossChainInputs, err := m.getCrossChainReqs(ormTx.ID, tx, statusFail)
if err != nil {
return err
}
return nil
}
-func (m *mainchainKeeper) getCrossChainInputs(crossTransactionID uint64, tx *btmTypes.Tx, statusFail bool) ([]*orm.CrossTransactionReq, error) {
+func (m *mainchainKeeper) getCrossChainReqs(crossTransactionID uint64, tx *types.Tx, statusFail bool) ([]*orm.CrossTransactionReq, error) {
// assume inputs are from an identical owner
script := hex.EncodeToString(tx.Inputs[0].ControlProgram())
inputs := []*orm.CrossTransactionReq{}
continue
}
- if statusFail && *rawOutput.OutputCommitment.AssetAmount.AssetId != *btmConsensus.BTMAssetID {
+ if statusFail && *rawOutput.OutputCommitment.AssetAmount.AssetId != *consensus.BTMAssetID {
continue
}
return inputs, nil
}
-func (m *mainchainKeeper) processWithdrawalTx(chain *orm.Chain, block *btmTypes.Block, txIndex uint64, tx *btmTypes.Tx) error {
+func (m *mainchainKeeper) processWithdrawalTx(chain *orm.Chain, block *types.Block, txIndex uint64, tx *types.Tx) error {
blockHash := block.Hash()
return m.db.Model(&orm.CrossTransaction{}).Where("chain_id != ?", chain.ID).
Where(&orm.CrossTransaction{
}).Error
}
-// TODO: maybe common
-func (m *mainchainKeeper) processChainInfo(chain *orm.Chain, block *btmTypes.Block) error {
+func (m *mainchainKeeper) processChainInfo(chain *orm.Chain, block *types.Block) error {
blockHash := block.Hash()
chain.BlockHash = blockHash.String()
chain.BlockHeight = block.Height
return nil
}
-func (m *mainchainKeeper) processIssuing(txs []*btmTypes.Tx) error {
+func (m *mainchainKeeper) processIssuing(txs []*types.Tx) error {
for _, tx := range txs {
for _, input := range tx.Inputs {
switch inp := input.TypedInput.(type) {
- case *btmTypes.IssuanceInput:
+ case *types.IssuanceInput:
assetID := inp.AssetID()
if _, err := m.getAsset(assetID.String()); err == nil {
continue
return nil
}
-// TODO: maybe common
func (m *mainchainKeeper) getAsset(assetID string) (*orm.Asset, error) {
if asset := m.assetCache.Get(assetID); asset != nil {
return asset, nil