OSDN Git Service

Use nil better to len for goleveldb.Get return
authoricodezjb <icodezjb@163.com>
Fri, 27 Oct 2017 02:40:33 +0000 (10:40 +0800)
committericodezjb <icodezjb@163.com>
Fri, 27 Oct 2017 02:40:33 +0000 (10:40 +0800)
blockchain/account/accounts.go
blockchain/account/indexer.go
blockchain/account/reserve.go
blockchain/asset/asset.go
blockchain/pin/pin.go
blockchain/txdb/snapshot.go
blockchain/txdb/store.go

index 8541db1..9ba6a56 100644 (file)
@@ -91,7 +91,7 @@ type Account struct {
 
 // Create creates a new Account.
 func (m *Manager) Create(ctx context.Context, xpubs []chainkd.XPub, quorum int, alias string, tags map[string]interface{}, clientToken string) (*Account, error) {
-       if ret := m.db.Get(json.RawMessage("ali" + alias)); len(ret) != 0 {
+       if ret := m.db.Get(json.RawMessage("ali" + alias)); ret != nil {
                return nil, errors.New(fmt.Sprintf("alias:%s already exists", alias))
        }
 
@@ -140,7 +140,7 @@ func (m *Manager) UpdateTags(ctx context.Context, id, alias *string, tags map[st
        }
 
        bytes := m.db.Get(key_id)
-       if len(bytes) == 0 {
+       if bytes == nil {
                return errors.New("no exit this account")
        }
 
@@ -214,7 +214,7 @@ func (m *Manager) findByID(ctx context.Context, id string) (*signers.Signer, err
        }
 
        bytes := m.db.Get(json.RawMessage(id))
-       if len(bytes) == 0 {
+       if bytes == nil {
                return nil, errors.New("not find this account.")
        }
 
index 5867690..35869d1 100644 (file)
@@ -200,7 +200,7 @@ func (m *Manager) loadAccountInfo(ctx context.Context, outs []*rawOutput) []*acc
        for s := range outsByScript {
                sha3pool.Sum256(b32[:], []byte(s))
                bytes := m.db.Get(json.RawMessage("acp" + string(b32[:])))
-               if len(bytes) == 0 {
+               if bytes == nil {
                        continue
                }
 
@@ -211,7 +211,7 @@ func (m *Manager) loadAccountInfo(ctx context.Context, outs []*rawOutput) []*acc
 
                //filte the accounts which exists in accountdb with wallet enabled
                isExist := m.db.Get(json.RawMessage(cp.AccountID))
-               if len(isExist) == 0 {
+               if isExist == nil {
                        continue
                }
 
index 55e91fc..35d447f 100644 (file)
@@ -448,7 +448,7 @@ func findSpecificUTXO(ctx context.Context, db dbm.DB, outHash bc.Hash) (*utxo, e
        b32 := new([4][32]byte)
 
        accUTXOValue := db.Get(json.RawMessage("acu" + string(outHash.Bytes())))
-       if len(accUTXOValue) != 0 {
+       if accUTXOValue != nil {
                err := json.Unmarshal(accUTXOValue, &au)
                if err != nil {
                        return nil, errors.Wrap(err)
index 3d430dd..49df5a7 100644 (file)
@@ -226,7 +226,7 @@ func (reg *Registry) findByID(ctx context.Context, id bc.AssetID) (*Asset, error
        }
 
        bytes := reg.db.Get([]byte(id.String()))
-       if len(bytes) == 0 {
+       if bytes == nil {
                return nil, errors.New("no exit this asset.")
        }
        var asset Asset
index a987612..f2a4f4b 100644 (file)
@@ -235,7 +235,7 @@ func (p *pin) complete(ctx context.Context, height uint64) error {
        )
 
        bytes := p.db.Get(json.RawMessage("blp" + p.name))
-       if len(bytes) != 0 {
+       if bytes != nil {
                err = json.Unmarshal(bytes, &block_processor)
                if err == nil && block_processor.Height >= max {
                        goto Noupdate
index 3a1cfdf..ae85259 100644 (file)
@@ -71,7 +71,7 @@ func (bsj SnapshotHeightJSON) Save(db dbm.DB) {
 
 func LoadSnapshotHeightJSON(db dbm.DB) SnapshotHeightJSON {
        bytes := db.Get(latestSnapshotHeight)
-       if len(bytes) == 0 {
+       if bytes == nil {
                return SnapshotHeightJSON{
                        Height: 0,
                }
@@ -120,7 +120,7 @@ func storeStateSnapshot(ctx context.Context, db dbm.DB, snapshot *state.Snapshot
 func getStateSnapshot(ctx context.Context, db dbm.DB) (*state.Snapshot, uint64, error) {
        height := LoadSnapshotHeightJSON(db).Height
        data := db.Get(calcSnapshotKey(height))
-       if len(data) == 0 {
+       if data == nil {
                return nil, height, errors.New("no this snapshot.")
        }
 
@@ -135,7 +135,7 @@ func getStateSnapshot(ctx context.Context, db dbm.DB) (*state.Snapshot, uint64,
 // provided height.
 func getRawSnapshot(ctx context.Context, db dbm.DB, height uint64) (data []byte, err error) {
        bytez := db.Get(calcSnapshotKey(height))
-       if len(bytez) == 0 {
+       if bytez == nil {
                return nil, errors.New("no this height snapshot.")
        }
        return bytez, nil
index e3d00e8..007b824 100644 (file)
@@ -34,7 +34,7 @@ func calcBlockKey(height uint64) []byte {
 func LoadBlock(db dbm.DB, height uint64) *legacy.Block {
        var block *legacy.Block = &legacy.Block{}
        bytez := db.Get(calcBlockKey(height))
-       if len(bytez) == 0 {
+       if bytez == nil {
                return nil
        }
 
@@ -58,7 +58,7 @@ func (bsj BlockStoreStateJSON) Save(db dbm.DB) {
 
 func LoadBlockStoreStateJSON(db dbm.DB) BlockStoreStateJSON {
        bytes := db.Get(blockStoreKey)
-       if len(bytes) == 0 {
+       if bytes == nil {
                return BlockStoreStateJSON{
                        Height: 0,
                }
@@ -101,7 +101,7 @@ func (s *Store) GetBlock(height uint64) (*legacy.Block, error) {
 
 func (s *Store) GetRawBlock(height uint64) ([]byte, error) {
        bytez := s.db.Get(calcBlockKey(height))
-       if len(bytez) == 0 {
+       if bytez == nil {
                return nil, errors.New("querying blocks from the db null")
        }
        return bytez, nil