github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/store/mainchain/storages/light_ledger.go (about)

     1  package storages
     2  
     3  import (
     4  	"github.com/sixexorg/magnetic-ring/common"
     5  	"github.com/sixexorg/magnetic-ring/core/mainchain/types"
     6  	"github.com/sixexorg/magnetic-ring/store/mainchain/states"
     7  )
     8  
     9  type LightLedger struct {
    10  	ledger *LedgerStoreImp
    11  }
    12  
    13  func GetLightLedger() *LightLedger {
    14  	ledger := GetLedgerStore()
    15  	return &LightLedger{ledger: ledger}
    16  }
    17  
    18  func (this *LightLedger) ContainBlock(blockHash common.Hash) (bool, error) {
    19  	return this.ledger.blockStore.ContainBlock(blockHash)
    20  
    21  }
    22  func (this *LightLedger) GetBlockByHash(blockHash common.Hash) (*types.Block, error) {
    23  	block, err := this.ledger.GetBlockByHash(blockHash)
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  	return block, nil
    28  }
    29  func (this *LightLedger) GetBlockHashByHeight(height uint64) (common.Hash, error) {
    30  	blockHash, err := this.ledger.GetBlockHashByHeight(height)
    31  	if err != nil {
    32  		return common.Hash{}, err
    33  	}
    34  	return blockHash, err
    35  }
    36  func (this *LightLedger) GetBlockByHeight(height uint64) (*types.Block, error) {
    37  	return this.ledger.GetBlockByHeight(height)
    38  }
    39  
    40  func (this *LightLedger) GetCurrentHeaderHeight() uint64 {
    41  	return this.ledger.GetCurrentHeaderHeight()
    42  }
    43  
    44  func (this *LightLedger) GetCurrentHeaderHash() common.Hash {
    45  	return this.ledger.GetCurrentHeaderHash()
    46  }
    47  
    48  //GetCurrentBlock return the current block height, and block hash.
    49  //Current block means the latest block in store.
    50  func (this *LightLedger) GetCurrentBlock() (uint64, common.Hash) {
    51  	return this.ledger.GetCurrentBlock()
    52  }
    53  
    54  //GetCurrentBlockHash return the current block hash
    55  func (this *LightLedger) GetCurrentBlockHash() common.Hash {
    56  	return this.ledger.GetCurrentBlockHash()
    57  }
    58  
    59  //GetCurrentBlockHeight return the current block height
    60  func (this *LightLedger) GetCurrentBlockHeight() uint64 {
    61  	return this.ledger.GetCurrentBlockHeight()
    62  }
    63  
    64  func (this *LightLedger) GetAccountByHeight(height uint64, account common.Address) (*states.AccountState, error) {
    65  	return this.ledger.GetAccountByHeight(height, account)
    66  }
    67  func (this *LightLedger) GetLeagueByHeight(height uint64, leagueId common.Address) (*states.LeagueState, error) {
    68  	return this.ledger.GetLeagueByHeight(height, leagueId)
    69  }
    70  
    71  /*func (this *LightLedger) GetMetaData(leagueId common.Address) (rate uint32, creator common.Address, minBox uint64, err error) {
    72  	return this.ledger.GetMetaData(leagueId)
    73  }*/
    74  func (this *LightLedger) GetLeagueMemberByHeight(height uint64, leagueId, account common.Address) (*states.LeagueMember, error) {
    75  	return this.ledger.GetLeagueMemberByHeight(height, leagueId, account)
    76  
    77  }
    78  
    79  func (this *LightLedger) GetTxByHash(txHash common.Hash) (*types.Transaction, uint64, error) {
    80  	return this.ledger.GetTxByHash(txHash)
    81  }
    82  
    83  func (this *LightLedger) GetHeaderByHash(blockHash common.Hash) (*types.Header, error) {
    84  	return this.ledger.GetHeaderByHash(blockHash)
    85  }
    86  
    87  func (this *LightLedger) GetTxByLeagueId(leagueId common.Address) (*types.Transaction, uint64, error) {
    88  	return this.ledger.GetTxByLeagueId(leagueId)
    89  }