github.com/aswedchain/aswed@v1.0.1/consensus/congress/interactive.go (about)

     1  package congress
     2  
     3  import (
     4  	"github.com/aswedchain/aswed/common"
     5  	"github.com/aswedchain/aswed/consensus"
     6  	"github.com/aswedchain/aswed/core/types"
     7  )
     8  
     9  type chainContext struct {
    10  	chainReader consensus.ChainHeaderReader
    11  	engine      consensus.Engine
    12  }
    13  
    14  func newChainContext(chainReader consensus.ChainHeaderReader, engine consensus.Engine) *chainContext {
    15  	return &chainContext{
    16  		chainReader: chainReader,
    17  		engine:      engine,
    18  	}
    19  }
    20  
    21  // Engine retrieves the chain's consensus engine.
    22  func (cc *chainContext) Engine() consensus.Engine {
    23  	return cc.engine
    24  }
    25  
    26  // GetHeader returns the hash corresponding to their hash.
    27  func (cc *chainContext) GetHeader(hash common.Hash, number uint64) *types.Header {
    28  	return cc.chainReader.GetHeader(hash, number)
    29  }
    30  
    31  // minimalChainContext provides a `core.ChainContext` implementation without really functioned `GetHeader` method,
    32  // it's used to execute those contracts which do no includes `BLOCKHASH` opcode.
    33  // The purpose is to reduce dependencies between different packages.
    34  type minimalChainContext struct {
    35  	engine consensus.Engine
    36  }
    37  
    38  func newMinimalChainContext(engine consensus.Engine) *minimalChainContext {
    39  	return &minimalChainContext{
    40  		engine: engine,
    41  	}
    42  }
    43  
    44  // Engine retrieves the chain's consensus engine.
    45  func (cc *minimalChainContext) Engine() consensus.Engine {
    46  	return cc.engine
    47  }
    48  
    49  func (cc *minimalChainContext) GetHeader(hash common.Hash, number uint64) *types.Header {
    50  	return nil
    51  }