github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/store/dbadapter/store.go (about)

     1  package dbadapter
     2  
     3  import (
     4  	"io"
     5  
     6  	dbm "github.com/fibonacci-chain/fbc/libs/tm-db"
     7  
     8  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/cachekv"
     9  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/tracekv"
    10  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/types"
    11  )
    12  
    13  // Wrapper type for dbm.Db with implementation of KVStore
    14  type Store struct {
    15  	dbm.DB
    16  }
    17  
    18  // Get wraps the underlying DB's Get method panicing on error.
    19  func (dsa Store) Get(key []byte) []byte {
    20  	v, err := dsa.DB.Get(key)
    21  	if err != nil {
    22  		panic(err)
    23  	}
    24  
    25  	return v
    26  }
    27  
    28  // Has wraps the underlying DB's Has method panicing on error.
    29  func (dsa Store) Has(key []byte) bool {
    30  	ok, err := dsa.DB.Has(key)
    31  	if err != nil {
    32  		panic(err)
    33  	}
    34  
    35  	return ok
    36  }
    37  
    38  // Set wraps the underlying DB's Set method panicing on error.
    39  func (dsa Store) Set(key, value []byte) {
    40  	if err := dsa.DB.Set(key, value); err != nil {
    41  		panic(err)
    42  	}
    43  }
    44  
    45  // Delete wraps the underlying DB's Delete method panicing on error.
    46  func (dsa Store) Delete(key []byte) {
    47  	if err := dsa.DB.Delete(key); err != nil {
    48  		panic(err)
    49  	}
    50  }
    51  
    52  // Iterator wraps the underlying DB's Iterator method panicing on error.
    53  func (dsa Store) Iterator(start, end []byte) types.Iterator {
    54  	iter, err := dsa.DB.Iterator(start, end)
    55  	if err != nil {
    56  		panic(err)
    57  	}
    58  
    59  	return iter
    60  }
    61  
    62  // ReverseIterator wraps the underlying DB's ReverseIterator method panicing on error.
    63  func (dsa Store) ReverseIterator(start, end []byte) types.Iterator {
    64  	iter, err := dsa.DB.ReverseIterator(start, end)
    65  	if err != nil {
    66  		panic(err)
    67  	}
    68  
    69  	return iter
    70  }
    71  
    72  // GetStoreType returns the type of the store.
    73  func (Store) GetStoreType() types.StoreType {
    74  	return types.StoreTypeDB
    75  }
    76  
    77  // CacheWrap cache wraps the underlying store.
    78  func (dsa Store) CacheWrap() types.CacheWrap {
    79  	return cachekv.NewStore(dsa)
    80  }
    81  
    82  // CacheWrapWithTrace implements KVStore.
    83  func (dsa Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap {
    84  	return cachekv.NewStore(tracekv.NewStore(dsa, w, tc))
    85  }
    86  
    87  // dbm.DB implements KVStore so we can CacheKVStore it.
    88  var _ types.KVStore = Store{}