github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/gossip/eth_state_adapter.go (about)

     1  package gossip
     2  
     3  import (
     4  	"github.com/unicornultrafoundation/go-u2u/common"
     5  	"github.com/unicornultrafoundation/go-u2u/core/state"
     6  	"github.com/unicornultrafoundation/go-u2u/core/state/snapshot"
     7  )
     8  
     9  // ethBlockChain wraps store to implement eth/protocols/snap.BlockChain interface.
    10  type ethBlockChain struct {
    11  	store *Store
    12  }
    13  
    14  func newEthBlockChain(s *Store) (*ethBlockChain, error) {
    15  	bc := &ethBlockChain{
    16  		store: s,
    17  	}
    18  
    19  	return bc, nil
    20  }
    21  
    22  // StateCache returns the caching database underpinning the blockchain instance.
    23  func (bc *ethBlockChain) StateCache() state.Database {
    24  	return bc.store.LastKvdbEvmSnapshot().EvmState
    25  }
    26  
    27  // ContractCode retrieves a blob of data associated with a contract hash
    28  // either from ephemeral in-memory cache, or from persistent storage.
    29  func (bc *ethBlockChain) ContractCode(hash common.Hash) ([]byte, error) {
    30  	return bc.store.LastKvdbEvmSnapshot().EvmState.ContractCode(common.Hash{}, hash)
    31  }
    32  
    33  // Snapshots returns the blockchain snapshot tree to paused it during sync.
    34  func (bc *ethBlockChain) Snapshots() *snapshot.Tree {
    35  	return bc.store.LastKvdbEvmSnapshot().Snapshots()
    36  }