github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/swarm/storage/dbapi.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 12:09:49</date>
    10  //</624342680737943552>
    11  
    12  //
    13  //
    14  //
    15  //
    16  //
    17  //
    18  //
    19  //
    20  //
    21  //
    22  //
    23  //
    24  //
    25  //
    26  //
    27  
    28  package storage
    29  
    30  import "context"
    31  
    32  //
    33  type DBAPI struct {
    34  	db  *LDBStore
    35  	loc *LocalStore
    36  }
    37  
    38  func NewDBAPI(loc *LocalStore) *DBAPI {
    39  	return &DBAPI{loc.DbStore, loc}
    40  }
    41  
    42  //
    43  func (d *DBAPI) Get(ctx context.Context, addr Address) (*Chunk, error) {
    44  	return d.loc.Get(ctx, addr)
    45  }
    46  
    47  //
    48  func (d *DBAPI) CurrentBucketStorageIndex(po uint8) uint64 {
    49  	return d.db.CurrentBucketStorageIndex(po)
    50  }
    51  
    52  //
    53  func (d *DBAPI) Iterator(from uint64, to uint64, po uint8, f func(Address, uint64) bool) error {
    54  	return d.db.SyncIterator(from, to, po, f)
    55  }
    56  
    57  //
    58  func (d *DBAPI) GetOrCreateRequest(ctx context.Context, addr Address) (*Chunk, bool) {
    59  	return d.loc.GetOrCreateRequest(ctx, addr)
    60  }
    61  
    62  //
    63  func (d *DBAPI) Put(ctx context.Context, chunk *Chunk) {
    64  	d.loc.Put(ctx, chunk)
    65  }
    66