github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/gossip/evmstore/evmpruner/exact.go (about) 1 package evmpruner 2 3 import ( 4 "errors" 5 "io" 6 7 "github.com/syndtr/goleveldb/leveldb/opt" 8 "github.com/unicornultrafoundation/go-helios/u2udb" 9 "github.com/unicornultrafoundation/go-helios/u2udb/leveldb" 10 "github.com/unicornultrafoundation/go-u2u/common" 11 "github.com/unicornultrafoundation/go-u2u/core/rawdb" 12 ) 13 14 type exactSetStore struct { 15 db u2udb.Store 16 } 17 18 func NewLevelDBSet(name string) (*exactSetStore, io.Closer, error) { 19 db, err := leveldb.New(name, 256*opt.MiB, 0, nil, nil) 20 if err != nil { 21 return nil, nil, err 22 } 23 return &exactSetStore{db}, db, nil 24 } 25 26 func (set *exactSetStore) Put(key []byte, _ []byte) error { 27 // If the key length is not 32bytes, ensure it's contract code 28 // entry with new scheme. 29 if len(key) != common.HashLength { 30 isCode, codeKey := rawdb.IsCodeKey(key) 31 if !isCode { 32 return errors.New("invalid entry") 33 } 34 return set.db.Put(codeKey, []byte{}) 35 } 36 return set.db.Put(key, []byte{}) 37 } 38 39 func (set *exactSetStore) Delete(key []byte) error { panic("not supported") } 40 41 func (set *exactSetStore) Contain(key []byte) (bool, error) { 42 return set.db.Has(key) 43 } 44 45 func (set *exactSetStore) Commit(filename, tempname string) error { 46 // No need in manual writing 47 return nil 48 }