OSDN Git Service

move DB interface to dbutils
authorChengcheng Zhang <943420582@qq.com>
Wed, 19 Jun 2019 11:29:14 +0000 (19:29 +0800)
committerChengcheng Zhang <943420582@qq.com>
Wed, 19 Jun 2019 11:29:14 +0000 (19:29 +0800)
23 files changed:
accesstoken/accesstoken.go
account/accounts.go
account/utxo_keeper.go
asset/asset.go
database/dbutils/db_interface.go [new file with mode: 0644]
database/leveldb/db.go
database/leveldb/go_level_db.go
database/leveldb/mem_db.go
database/store.go
database/utxo_view.go
p2p/discover/dht/database.go
p2p/security/blacklist.go
p2p/test_util.go
test/bench_blockchain_test.go
test/chain_test_util.go
test/tx_test_util.go
test/util.go
wallet/annotated.go
wallet/indexer.go
wallet/recovery.go
wallet/utxo.go
wallet/wallet.go
wallet/wallet_test.go

index a2b9d85..3e4e85d 100644 (file)
@@ -11,7 +11,7 @@ import (
        "time"
 
        "github.com/vapor/crypto/sha3pool"
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        "github.com/vapor/errors"
 )
 
@@ -44,11 +44,11 @@ type Token struct {
 
 // CredentialStore store user access credential.
 type CredentialStore struct {
-       DB dbm.DB
+       DB dbutils.DB
 }
 
 // NewStore creates and returns a new Store object.
-func NewStore(db dbm.DB) *CredentialStore {
+func NewStore(db dbutils.DB) *CredentialStore {
        return &CredentialStore{
                DB: db,
        }
index 0526efe..94549f6 100644 (file)
@@ -19,7 +19,7 @@ import (
        "github.com/vapor/crypto"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/crypto/sha3pool"
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        "github.com/vapor/errors"
        "github.com/vapor/protocol"
        "github.com/vapor/protocol/bc"
@@ -103,7 +103,7 @@ type CtrlProgram struct {
 
 // Manager stores accounts and their associated control programs.
 type Manager struct {
-       db         dbm.DB
+       db         dbutils.DB
        chain      *protocol.Chain
        utxoKeeper *utxoKeeper
 
@@ -119,7 +119,7 @@ type Manager struct {
 }
 
 // NewManager creates a new account manager
-func NewManager(walletDB dbm.DB, chain *protocol.Chain) *Manager {
+func NewManager(walletDB dbutils.DB, chain *protocol.Chain) *Manager {
        return &Manager{
                db:          walletDB,
                chain:       chain,
index cd9beea..f331585 100644 (file)
@@ -11,7 +11,7 @@ import (
 
        log "github.com/sirupsen/logrus"
 
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        "github.com/vapor/errors"
        "github.com/vapor/protocol/bc"
 )
@@ -55,7 +55,7 @@ type utxoKeeper struct {
        // `sync/atomic` expects the first word in an allocated struct to be 64-bit
        // aligned on both ARM and x86-32. See https://goo.gl/zW7dgq for more details.
        nextIndex     uint64
-       db            dbm.DB
+       db            dbutils.DB
        mtx           sync.RWMutex
        currentHeight func() uint64
 
@@ -64,7 +64,7 @@ type utxoKeeper struct {
        reservations map[uint64]*reservation
 }
 
-func newUtxoKeeper(f func() uint64, walletdb dbm.DB) *utxoKeeper {
+func newUtxoKeeper(f func() uint64, walletdb dbutils.DB) *utxoKeeper {
        uk := &utxoKeeper{
                db:            walletdb,
                currentHeight: f,
index 12ae60b..2571664 100644 (file)
@@ -9,7 +9,7 @@ import (
        "github.com/golang/groupcache/lru"
 
        "github.com/vapor/consensus"
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        chainjson "github.com/vapor/encoding/json"
        "github.com/vapor/errors"
        "github.com/vapor/protocol"
@@ -70,7 +70,7 @@ var (
 )
 
 //NewRegistry create new registry
-func NewRegistry(db dbm.DB, chain *protocol.Chain) *Registry {
+func NewRegistry(db dbutils.DB, chain *protocol.Chain) *Registry {
        initNativeAsset()
        return &Registry{
                db:         db,
@@ -82,7 +82,7 @@ func NewRegistry(db dbm.DB, chain *protocol.Chain) *Registry {
 
 // Registry tracks and stores all known assets on a blockchain.
 type Registry struct {
-       db    dbm.DB
+       db    dbutils.DB
        chain *protocol.Chain
 
        cacheMu    sync.Mutex
diff --git a/database/dbutils/db_interface.go b/database/dbutils/db_interface.go
new file mode 100644 (file)
index 0000000..40ef295
--- /dev/null
@@ -0,0 +1,34 @@
+package dbutils
+
+type DB interface {
+       Get([]byte) []byte
+       Set([]byte, []byte)
+       SetSync([]byte, []byte)
+       Delete([]byte)
+       DeleteSync([]byte)
+       Close()
+       NewBatch() Batch
+       Iterator() Iterator
+       IteratorPrefix([]byte) Iterator
+
+       // For debugging
+       Print()
+       Stats() map[string]string
+}
+
+type Batch interface {
+       Set(key, value []byte)
+       Delete(key []byte)
+       Write()
+}
+
+type Iterator interface {
+       Next() bool
+
+       Key() []byte
+       Value() []byte
+       Seek([]byte) bool
+
+       Release()
+       Error() error
+}
index 38cab5b..cb4dc68 100644 (file)
@@ -1,41 +1,9 @@
 package db
 
-import . "github.com/tendermint/tmlibs/common"
-
-type DB interface {
-       Get([]byte) []byte
-       Set([]byte, []byte)
-       SetSync([]byte, []byte)
-       Delete([]byte)
-       DeleteSync([]byte)
-       Close()
-       NewBatch() Batch
-       Iterator() Iterator
-       IteratorPrefix([]byte) Iterator
-
-       // For debugging
-       Print()
-       Stats() map[string]string
-}
-
-type Batch interface {
-       Set(key, value []byte)
-       Delete(key []byte)
-       Write()
-}
-
-type Iterator interface {
-       Next() bool
-
-       Key() []byte
-       Value() []byte
-       Seek([]byte) bool
-
-       Release()
-       Error() error
-}
-
-//-----------------------------------------------------------------------------
+import (
+       . "github.com/tendermint/tmlibs/common"
+       "github.com/vapor/database/dbutils"
+)
 
 const (
        LevelDBBackendStr   = "leveldb" // legacy, defaults to goleveldb.
@@ -44,7 +12,7 @@ const (
        MemDBBackendStr     = "memdb"
 )
 
-type dbCreator func(name string, dir string) (DB, error)
+type dbCreator func(name string, dir string) (dbutils.DB, error)
 
 var backends = map[string]dbCreator{}
 
@@ -56,7 +24,7 @@ func registerDBCreator(backend string, creator dbCreator, force bool) {
        backends[backend] = creator
 }
 
-func NewDB(name string, backend string, dir string) DB {
+func NewDB(name string, backend string, dir string) dbutils.DB {
        db, err := backends[backend](name, dir)
        if err != nil {
                PanicSanity(Fmt("Error initializing DB: %v", err))
index e9e8d3d..2d9ecef 100644 (file)
@@ -9,12 +9,13 @@ import (
        "github.com/syndtr/goleveldb/leveldb/iterator"
        "github.com/syndtr/goleveldb/leveldb/opt"
        "github.com/syndtr/goleveldb/leveldb/util"
+       "github.com/vapor/database/dbutils"
 
        . "github.com/tendermint/tmlibs/common"
 )
 
 func init() {
-       dbCreator := func(name string, dir string) (DB, error) {
+       dbCreator := func(name string, dir string) (dbutils.DB, error) {
                return NewGoLevelDB(name, dir)
        }
        registerDBCreator(LevelDBBackendStr, dbCreator, false)
@@ -155,15 +156,15 @@ func (it *goLevelDBIterator) Release() {
        it.source.Release()
 }
 
-func (db *GoLevelDB) Iterator() Iterator {
+func (db *GoLevelDB) Iterator() dbutils.Iterator {
        return &goLevelDBIterator{db.db.NewIterator(nil, nil)}
 }
 
-func (db *GoLevelDB) IteratorPrefix(prefix []byte) Iterator {
+func (db *GoLevelDB) IteratorPrefix(prefix []byte) dbutils.Iterator {
        return &goLevelDBIterator{db.db.NewIterator(util.BytesPrefix(prefix), nil)}
 }
 
-func (db *GoLevelDB) NewBatch() Batch {
+func (db *GoLevelDB) NewBatch() dbutils.Batch {
        batch := new(leveldb.Batch)
        return &goLevelDBBatch{db, batch}
 }
index 62f40fc..d110bbd 100644 (file)
@@ -5,10 +5,12 @@ import (
        "sort"
        "strings"
        "sync"
+
+       "github.com/vapor/database/dbutils"
 )
 
 func init() {
-       registerDBCreator(MemDBBackendStr, func(name string, dir string) (DB, error) {
+       registerDBCreator(MemDBBackendStr, func(name string, dir string) (dbutils.DB, error) {
                return NewMemDB(), nil
        }, false)
 }
@@ -120,11 +122,11 @@ func (it *memDBIterator) Error() error {
        return nil
 }
 
-func (db *MemDB) Iterator() Iterator {
+func (db *MemDB) Iterator() dbutils.Iterator {
        return db.IteratorPrefix([]byte{})
 }
 
-func (db *MemDB) IteratorPrefix(prefix []byte) Iterator {
+func (db *MemDB) IteratorPrefix(prefix []byte) dbutils.Iterator {
        it := newMemDBIterator()
        it.db = db
        it.last = -1
@@ -143,7 +145,7 @@ func (db *MemDB) IteratorPrefix(prefix []byte) Iterator {
        return it
 }
 
-func (db *MemDB) NewBatch() Batch {
+func (db *MemDB) NewBatch() dbutils.Batch {
        return &memDBBatch{db, nil}
 }
 
index 6de274b..5c4f18f 100644 (file)
@@ -9,7 +9,7 @@ import (
        "github.com/golang/protobuf/proto"
        log "github.com/sirupsen/logrus"
 
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        "github.com/vapor/database/storage"
        "github.com/vapor/errors"
        "github.com/vapor/protocol"
@@ -28,7 +28,7 @@ var (
        voteResultPrefix       = []byte("VR:")
 )
 
-func loadBlockStoreStateJSON(db dbm.DB) *protocol.BlockStoreState {
+func loadBlockStoreStateJSON(db dbutils.DB) *protocol.BlockStoreState {
        bytes := db.Get(blockStoreKey)
        if bytes == nil {
                return nil
@@ -45,7 +45,7 @@ func loadBlockStoreStateJSON(db dbm.DB) *protocol.BlockStoreState {
 // It satisfies the interface protocol.Store, and provides additional
 // methods for querying current data.
 type Store struct {
-       db    dbm.DB
+       db    dbutils.DB
        cache cache
 }
 
@@ -71,7 +71,7 @@ func calcVoteResultKey(seq uint64) []byte {
 }
 
 // GetBlockHeader return the block header by given hash and height
-func GetBlockHeader(db dbm.DB, hash *bc.Hash, height uint64) (*types.BlockHeader, error) {
+func GetBlockHeader(db dbutils.DB, hash *bc.Hash, height uint64) (*types.BlockHeader, error) {
        binaryBlockHeader := db.Get(calcBlockHeaderKey(height, hash))
        if binaryBlockHeader == nil {
                return nil, fmt.Errorf("There are no blockHeader with given hash %s", hash.String())
@@ -85,7 +85,7 @@ func GetBlockHeader(db dbm.DB, hash *bc.Hash, height uint64) (*types.BlockHeader
 }
 
 // GetBlockTransactions return the block transactions by given hash
-func GetBlockTransactions(db dbm.DB, hash *bc.Hash) ([]*types.Tx, error) {
+func GetBlockTransactions(db dbutils.DB, hash *bc.Hash) ([]*types.Tx, error) {
        binaryBlockTxs := db.Get(calcBlockTransactionsKey(hash))
        if binaryBlockTxs == nil {
                return nil, fmt.Errorf("There are no block transactions with given hash %s", hash.String())
@@ -99,7 +99,7 @@ func GetBlockTransactions(db dbm.DB, hash *bc.Hash) ([]*types.Tx, error) {
 }
 
 // GetVoteResult return the vote result by given sequence
-func GetVoteResult(db dbm.DB, seq uint64) (*state.VoteResult, error) {
+func GetVoteResult(db dbutils.DB, seq uint64) (*state.VoteResult, error) {
        data := db.Get(calcVoteResultKey(seq))
        if data == nil {
                return nil, protocol.ErrNotFoundVoteResult
@@ -113,7 +113,7 @@ func GetVoteResult(db dbm.DB, seq uint64) (*state.VoteResult, error) {
 }
 
 // NewStore creates and returns a new Store object.
-func NewStore(db dbm.DB) *Store {
+func NewStore(db dbutils.DB) *Store {
        fillBlockHeaderFn := func(hash *bc.Hash, height uint64) (*types.BlockHeader, error) {
                return GetBlockHeader(db, hash, height)
        }
index f05dafd..0708e3c 100644 (file)
@@ -2,7 +2,7 @@ package database
 
 import (
        "github.com/golang/protobuf/proto"
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        "github.com/vapor/database/storage"
        "github.com/vapor/errors"
        "github.com/vapor/protocol/bc"
@@ -15,7 +15,7 @@ func calcUtxoKey(hash *bc.Hash) []byte {
        return []byte(utxoPreFix + hash.String())
 }
 
-func getTransactionsUtxo(db dbm.DB, view *state.UtxoViewpoint, txs []*bc.Tx) error {
+func getTransactionsUtxo(db dbutils.DB, view *state.UtxoViewpoint, txs []*bc.Tx) error {
        for _, tx := range txs {
                for _, prevout := range tx.SpentOutputIDs {
                        if view.HasUtxo(&prevout) {
@@ -58,7 +58,7 @@ func getTransactionsUtxo(db dbm.DB, view *state.UtxoViewpoint, txs []*bc.Tx) err
        return nil
 }
 
-func getUtxo(db dbm.DB, hash *bc.Hash) (*storage.UtxoEntry, error) {
+func getUtxo(db dbutils.DB, hash *bc.Hash) (*storage.UtxoEntry, error) {
        var utxo storage.UtxoEntry
        data := db.Get(calcUtxoKey(hash))
        if data == nil {
@@ -70,7 +70,7 @@ func getUtxo(db dbm.DB, hash *bc.Hash) (*storage.UtxoEntry, error) {
        return &utxo, nil
 }
 
-func saveUtxoView(batch dbm.Batch, view *state.UtxoViewpoint) error {
+func saveUtxoView(batch dbutils.Batch, view *state.UtxoViewpoint) error {
        for key, entry := range view.Entries {
                if (entry.Type == storage.CrosschainUTXOType) && (!entry.Spent) {
                        batch.Delete(calcUtxoKey(&key))
@@ -91,6 +91,6 @@ func saveUtxoView(batch dbm.Batch, view *state.UtxoViewpoint) error {
        return nil
 }
 
-func SaveUtxoView(batch dbm.Batch, view *state.UtxoViewpoint) error {
+func SaveUtxoView(batch dbutils.Batch, view *state.UtxoViewpoint) error {
        return saveUtxoView(batch, view)
 }
index 13dc923..9f416ef 100644 (file)
@@ -16,6 +16,7 @@ import (
        wire "github.com/tendermint/go-wire"
 
        "github.com/vapor/crypto"
+       "github.com/vapor/database/dbutils"
        dbm "github.com/vapor/database/leveldb"
        "github.com/vapor/errors"
 )
@@ -28,7 +29,7 @@ var (
 
 // nodeDB stores all nodes we know about.
 type nodeDB struct {
-       lvl    dbm.DB        // Interface to the database itself
+       lvl    dbutils.DB    // Interface to the database itself
        self   NodeID        // Own node id to prevent adding it into the database
        runner sync.Once     // Ensures we can start at most one expirer
        quit   chan struct{} // Channel to signal the expiring thread to stop
@@ -345,7 +346,7 @@ func (db *nodeDB) updateTopicRegTickets(id NodeID, issued, used uint32) {
 
 // reads the next node record from the iterator, skipping over other
 // database entries.
-func nextNode(it dbm.Iterator) *Node {
+func nextNode(it dbutils.Iterator) *Node {
        var (
                n    = int(0)
                err  = error(nil)
index f8ca05e..5badcbc 100644 (file)
@@ -7,6 +7,7 @@ import (
        "time"
 
        cfg "github.com/vapor/config"
+       "github.com/vapor/database/dbutils"
        dbm "github.com/vapor/database/leveldb"
 )
 
@@ -21,7 +22,7 @@ var (
 
 type Blacklist struct {
        peers map[string]time.Time
-       db    dbm.DB
+       db    dbutils.DB
 
        mtx sync.Mutex
 }
index fa5d631..05fdc31 100644 (file)
@@ -7,7 +7,7 @@ import (
        cmn "github.com/tendermint/tmlibs/common"
 
        cfg "github.com/vapor/config"
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        "github.com/vapor/p2p/connection"
        "github.com/vapor/p2p/discover/dht"
        "github.com/vapor/p2p/signlib"
@@ -88,7 +88,7 @@ func (m *mockDiscv) ReadRandomNodes(buf []*dht.Node) (n int) {
        return 0
 }
 
-func MakeSwitch(cfg *cfg.Config, testdb dbm.DB, privKey signlib.PrivKey, initSwitch func(*Switch) *Switch) *Switch {
+func MakeSwitch(cfg *cfg.Config, testdb dbutils.DB, privKey signlib.PrivKey, initSwitch func(*Switch) *Switch) *Switch {
        // new switch, add reactors
        l, listenAddr := GetListener(cfg.P2P)
        cfg.P2P.LANDiscover = false
index 0d548fe..c6d9898 100644 (file)
@@ -15,6 +15,7 @@ import (
        "github.com/vapor/consensus"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/database"
+       "github.com/vapor/database/dbutils"
        dbm "github.com/vapor/database/leveldb"
        "github.com/vapor/database/storage"
        "github.com/vapor/event"
@@ -97,7 +98,7 @@ func benchInsertChain(b *testing.B, blockTxNumber int, otherAssetNum int, txType
        }
 }
 
-func GenerateChainData(dirPath string, testDB dbm.DB, txNumber, otherAssetNum int, txType string) (*protocol.Chain, []*types.Tx, *protocol.TxPool, error) {
+func GenerateChainData(dirPath string, testDB dbutils.DB, txNumber, otherAssetNum int, txType string) (*protocol.Chain, []*types.Tx, *protocol.TxPool, error) {
        var err error
 
        // generate transactions
@@ -159,7 +160,7 @@ func InsertChain(chain *protocol.Chain, txPool *protocol.TxPool, txs []*types.Tx
                }
        }
 
-       block, err := proposal.NewBlockTemplate(chain, txPool, nil, uint64(time.Now().UnixNano() / 1e6))
+       block, err := proposal.NewBlockTemplate(chain, txPool, nil, uint64(time.Now().UnixNano()/1e6))
        if err != nil {
                return err
        }
@@ -357,7 +358,7 @@ func CreateTxbyNum(txNumber, otherAssetNum int) ([]*types.Tx, error) {
        return txs, nil
 }
 
-func SetUtxoView(db dbm.DB, view *state.UtxoViewpoint) error {
+func SetUtxoView(db dbutils.DB, view *state.UtxoViewpoint) error {
        batch := db.NewBatch()
        if err := database.SaveUtxoView(batch, view); err != nil {
                return err
@@ -367,7 +368,7 @@ func SetUtxoView(db dbm.DB, view *state.UtxoViewpoint) error {
 }
 
 //-------------------------Mock actual transaction----------------------------------
-func MockTxsP2PKH(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
+func MockTxsP2PKH(keyDirPath string, testDB dbutils.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
        accountManager := account.NewManager(testDB, nil)
        hsm, err := pseudohsm.New(keyDirPath)
        if err != nil {
@@ -409,7 +410,7 @@ func MockTxsP2PKH(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int)
        return txs, nil
 }
 
-func MockTxsP2SH(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
+func MockTxsP2SH(keyDirPath string, testDB dbutils.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
        accountManager := account.NewManager(testDB, nil)
        hsm, err := pseudohsm.New(keyDirPath)
        if err != nil {
@@ -456,7 +457,7 @@ func MockTxsP2SH(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int)
        return txs, nil
 }
 
-func MockTxsMultiSign(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
+func MockTxsMultiSign(keyDirPath string, testDB dbutils.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
        accountManager := account.NewManager(testDB, nil)
        hsm, err := pseudohsm.New(keyDirPath)
        if err != nil {
index 9181053..d797ada 100644 (file)
@@ -9,6 +9,7 @@ import (
        "github.com/vapor/blockchain/txbuilder"
        "github.com/vapor/consensus"
        "github.com/vapor/database"
+       "github.com/vapor/database/dbutils"
        dbm "github.com/vapor/database/leveldb"
        "github.com/vapor/database/storage"
        "github.com/vapor/protocol"
@@ -21,7 +22,7 @@ const utxoPrefix = "UT:"
 
 type chainTestContext struct {
        Chain *protocol.Chain
-       DB    dbm.DB
+       DB    dbutils.DB
        Store *database.Store
 }
 
index 11c6313..c80f280 100644 (file)
@@ -14,7 +14,7 @@ import (
        "github.com/vapor/consensus"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/crypto/sha3pool"
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        "github.com/vapor/errors"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
@@ -263,7 +263,7 @@ func CreateSpendInput(tx *types.Tx, outputIndex uint64) (*types.SpendInput, erro
 }
 
 // SignInstructionFor read CtrlProgram from db, construct SignInstruction for SpendInput
-func SignInstructionFor(input *types.SpendInput, db dbm.DB, signer *signers.Signer) (*txbuilder.SigningInstruction, error) {
+func SignInstructionFor(input *types.SpendInput, db dbutils.DB, signer *signers.Signer) (*txbuilder.SigningInstruction, error) {
        cp := account.CtrlProgram{}
        var hash [32]byte
        sha3pool.Sum256(hash[:], input.ControlProgram)
index 54b9b05..b906335 100644 (file)
@@ -11,7 +11,7 @@ import (
        "github.com/vapor/consensus"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/database"
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        "github.com/vapor/event"
        "github.com/vapor/protocol"
        "github.com/vapor/protocol/bc"
@@ -25,7 +25,7 @@ const (
 )
 
 // MockChain mock chain with genesis block
-func MockChain(testDB dbm.DB) (*protocol.Chain, *database.Store, *protocol.TxPool, error) {
+func MockChain(testDB dbutils.DB) (*protocol.Chain, *database.Store, *protocol.TxPool, error) {
        config.CommonConfig = config.DefaultConfig()
        store := database.NewStore(testDB)
        dispatcher := event.NewDispatcher()
index 6604876..9e40286 100644 (file)
@@ -13,7 +13,7 @@ import (
        "github.com/vapor/consensus"
        "github.com/vapor/consensus/segwit"
        "github.com/vapor/crypto/sha3pool"
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
 )
@@ -82,7 +82,7 @@ func (w *Wallet) getAliasDefinition(assetID bc.AssetID) (string, json.RawMessage
 }
 
 // annotateTxs adds account data to transactions
-func annotateTxsAccount(txs []*query.AnnotatedTx, walletDB dbm.DB) {
+func annotateTxsAccount(txs []*query.AnnotatedTx, walletDB dbutils.DB) {
        for i, tx := range txs {
                for j, input := range tx.Inputs {
                        //issue asset tx input SpentOutputID is nil
@@ -107,7 +107,7 @@ func annotateTxsAccount(txs []*query.AnnotatedTx, walletDB dbm.DB) {
        }
 }
 
-func getAccountFromACP(program []byte, walletDB dbm.DB) (*account.Account, error) {
+func getAccountFromACP(program []byte, walletDB dbutils.DB) (*account.Account, error) {
        var hash common.Hash
        accountCP := account.CtrlProgram{}
        localAccount := account.Account{}
index bc61dc3..d4388e9 100644 (file)
@@ -14,7 +14,7 @@ import (
        "github.com/vapor/blockchain/query"
        "github.com/vapor/consensus"
        "github.com/vapor/crypto/sha3pool"
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        chainjson "github.com/vapor/encoding/json"
        "github.com/vapor/errors"
        "github.com/vapor/protocol/bc"
@@ -68,7 +68,7 @@ func parseGlobalTxIdx(globalTxIdx []byte) (*bc.Hash, uint64) {
 }
 
 // deleteTransaction delete transactions when orphan block rollback
-func (w *Wallet) deleteTransactions(batch dbm.Batch, height uint64) {
+func (w *Wallet) deleteTransactions(batch dbutils.Batch, height uint64) {
        tmpTx := query.AnnotatedTx{}
        txIter := w.DB.IteratorPrefix(calcDeleteKey(height))
        defer txIter.Release()
@@ -84,7 +84,7 @@ func (w *Wallet) deleteTransactions(batch dbm.Batch, height uint64) {
 // saveExternalAssetDefinition save external and local assets definition,
 // when query ,query local first and if have no then query external
 // details see getAliasDefinition
-func saveExternalAssetDefinition(b *types.Block, walletDB dbm.DB) {
+func saveExternalAssetDefinition(b *types.Block, walletDB dbutils.DB) {
        storeBatch := walletDB.NewBatch()
        defer storeBatch.Write()
 
@@ -120,7 +120,7 @@ type TxSummary struct {
 }
 
 // indexTransactions saves all annotated transactions to the database.
-func (w *Wallet) indexTransactions(batch dbm.Batch, b *types.Block, txStatus *bc.TransactionStatus) error {
+func (w *Wallet) indexTransactions(batch dbutils.Batch, b *types.Block, txStatus *bc.TransactionStatus) error {
        annotatedTxs := w.filterAccountTxs(b, txStatus)
        saveExternalAssetDefinition(b, w.DB)
        annotateTxsAccount(annotatedTxs, w.DB)
index 2933ad6..cdc8990 100644 (file)
@@ -12,7 +12,7 @@ import (
        "github.com/vapor/blockchain/signers"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/crypto/sha3pool"
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        "github.com/vapor/errors"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
@@ -170,7 +170,7 @@ func (rs *recoveryState) stateForScope(account *account.Account) {
 type recoveryManager struct {
        mu sync.Mutex
 
-       db         dbm.DB
+       db         dbutils.DB
        accountMgr *account.Manager
 
        locked int32
@@ -187,7 +187,7 @@ type recoveryManager struct {
 }
 
 // newRecoveryManager create recovery manger.
-func newRecoveryManager(db dbm.DB, accountMgr *account.Manager) *recoveryManager {
+func newRecoveryManager(db dbutils.DB, accountMgr *account.Manager) *recoveryManager {
        return &recoveryManager{
                db:         db,
                accountMgr: accountMgr,
index 1e60a34..a70017f 100644 (file)
@@ -9,7 +9,7 @@ import (
        "github.com/vapor/consensus"
        "github.com/vapor/consensus/segwit"
        "github.com/vapor/crypto/sha3pool"
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        "github.com/vapor/errors"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
@@ -48,7 +48,7 @@ func (w *Wallet) GetAccountUtxos(accountID string, id string, unconfirmed, isSma
        return accountUtxos
 }
 
-func (w *Wallet) attachUtxos(batch dbm.Batch, b *types.Block, txStatus *bc.TransactionStatus) {
+func (w *Wallet) attachUtxos(batch dbutils.Batch, b *types.Block, txStatus *bc.TransactionStatus) {
        for txIndex, tx := range b.Transactions {
                statusFail, err := txStatus.GetStatus(txIndex)
                if err != nil {
@@ -75,7 +75,7 @@ func (w *Wallet) attachUtxos(batch dbm.Batch, b *types.Block, txStatus *bc.Trans
        }
 }
 
-func (w *Wallet) detachUtxos(batch dbm.Batch, b *types.Block, txStatus *bc.TransactionStatus) {
+func (w *Wallet) detachUtxos(batch dbutils.Batch, b *types.Block, txStatus *bc.TransactionStatus) {
        for txIndex := len(b.Transactions) - 1; txIndex >= 0; txIndex-- {
                tx := b.Transactions[txIndex]
                for j := range tx.Outputs {
@@ -151,7 +151,7 @@ func (w *Wallet) filterAccountUtxo(utxos []*account.UTXO) []*account.UTXO {
        return result
 }
 
-func batchSaveUtxos(utxos []*account.UTXO, batch dbm.Batch) error {
+func batchSaveUtxos(utxos []*account.UTXO, batch dbutils.Batch) error {
        for _, utxo := range utxos {
                data, err := json.Marshal(utxo)
                if err != nil {
index 92a24b9..515316c 100644 (file)
@@ -9,7 +9,7 @@ import (
        "github.com/vapor/account"
        "github.com/vapor/asset"
        "github.com/vapor/blockchain/pseudohsm"
-       dbm "github.com/vapor/database/leveldb"
+       "github.com/vapor/database/dbutils"
        "github.com/vapor/errors"
        "github.com/vapor/event"
        "github.com/vapor/protocol"
@@ -42,7 +42,7 @@ type StatusInfo struct {
 
 //Wallet is related to storing account unspent outputs
 type Wallet struct {
-       DB              dbm.DB
+       DB              dbutils.DB
        rw              sync.RWMutex
        status          StatusInfo
        TxIndexFlag     bool
@@ -58,7 +58,7 @@ type Wallet struct {
 }
 
 //NewWallet return a new wallet instance
-func NewWallet(walletDB dbm.DB, account *account.Manager, asset *asset.Registry, hsm *pseudohsm.HSM, chain *protocol.Chain, dispatcher *event.Dispatcher, txIndexFlag bool) (*Wallet, error) {
+func NewWallet(walletDB dbutils.DB, account *account.Manager, asset *asset.Registry, hsm *pseudohsm.HSM, chain *protocol.Chain, dispatcher *event.Dispatcher, txIndexFlag bool) (*Wallet, error) {
        w := &Wallet{
                DB:              walletDB,
                AccountMgr:      account,
@@ -156,7 +156,7 @@ func (w *Wallet) loadWalletInfo() error {
        return w.AttachBlock(block)
 }
 
-func (w *Wallet) commitWalletInfo(batch dbm.Batch) error {
+func (w *Wallet) commitWalletInfo(batch dbutils.Batch) error {
        rawWallet, err := json.Marshal(w.status)
        if err != nil {
                log.WithFields(log.Fields{"module": logModule, "err": err}).Error("save wallet info")
index 823eab9..cca6971 100644 (file)
@@ -17,6 +17,7 @@ import (
        "github.com/vapor/consensus"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/database"
+       "github.com/vapor/database/dbutils"
        dbm "github.com/vapor/database/leveldb"
        "github.com/vapor/event"
        "github.com/vapor/protocol"
@@ -378,7 +379,7 @@ func mockTxData(utxos []*account.UTXO, testAccount *account.Account) (*txbuilder
        return tplBuilder.Build()
 }
 
-func mockWallet(walletDB dbm.DB, account *account.Manager, asset *asset.Registry, chain *protocol.Chain, dispatcher *event.Dispatcher, txIndexFlag bool) *Wallet {
+func mockWallet(walletDB dbutils.DB, account *account.Manager, asset *asset.Registry, chain *protocol.Chain, dispatcher *event.Dispatcher, txIndexFlag bool) *Wallet {
        wallet := &Wallet{
                DB:              walletDB,
                AccountMgr:      account,