github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/swarm/storage/dbapi.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  //
    10  //
    11  //
    12  //
    13  //
    14  //
    15  //
    16  //
    17  //
    18  //
    19  //
    20  //
    21  //
    22  //
    23  //
    24  
    25  package storage
    26  
    27  import "context"
    28  
    29  //
    30  type DBAPI struct {
    31  	db  *LDBStore
    32  	loc *LocalStore
    33  }
    34  
    35  func NewDBAPI(loc *LocalStore) *DBAPI {
    36  	return &DBAPI{loc.DbStore, loc}
    37  }
    38  
    39  //
    40  func (d *DBAPI) Get(ctx context.Context, addr Address) (*Chunk, error) {
    41  	return d.loc.Get(ctx, addr)
    42  }
    43  
    44  //
    45  func (d *DBAPI) CurrentBucketStorageIndex(po uint8) uint64 {
    46  	return d.db.CurrentBucketStorageIndex(po)
    47  }
    48  
    49  //
    50  func (d *DBAPI) Iterator(from uint64, to uint64, po uint8, f func(Address, uint64) bool) error {
    51  	return d.db.SyncIterator(from, to, po, f)
    52  }
    53  
    54  //
    55  func (d *DBAPI) GetOrCreateRequest(ctx context.Context, addr Address) (*Chunk, bool) {
    56  	return d.loc.GetOrCreateRequest(ctx, addr)
    57  }
    58  
    59  //
    60  func (d *DBAPI) Put(ctx context.Context, chunk *Chunk) {
    61  	d.loc.Put(ctx, chunk)
    62  }