本文整理匯總了Golang中github.com/decred/dcrwallet/walletdb.Namespace.View方法的典型用法代碼示例。如果您正苦於以下問題:Golang Namespace.View方法的具體用法?Golang Namespace.View怎麽用?Golang Namespace.View使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/decred/dcrwallet/walletdb.Namespace
的用法示例。
在下文中一共展示了Namespace.View方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: loadOwnedSStxs
// loadManager returns a new stake manager that results from loading it from
// the passed opened database. The public passphrase is required to decrypt the
// public keys.
func (s *StakeStore) loadOwnedSStxs(namespace walletdb.Namespace) error {
// Regenerate the list of tickets.
// Perform all database lookups in a read-only view.
ticketList := make(map[chainhash.Hash]struct{})
err := namespace.View(func(tx walletdb.Tx) error {
var errForEach error
// Open the sstx records database.
bucket := tx.RootBucket().Bucket(sstxRecordsBucketName)
// Store each key sequentially.
errForEach = bucket.ForEach(func(k []byte, v []byte) error {
var errNewHash error
var hash *chainhash.Hash
hash, errNewHash = chainhash.NewHash(k)
if errNewHash != nil {
return errNewHash
}
ticketList[*hash] = struct{}{}
return nil
})
return errForEach
})
if err != nil {
return err
}
s.ownedSStxs = ticketList
return nil
}
示例2: stakeStoreExists
// stakeStoreExists returns whether or not the stake store has already
// been created in the given database namespace.
func stakeStoreExists(namespace walletdb.Namespace) (bool, error) {
var exists bool
err := namespace.View(func(tx walletdb.Tx) error {
mainBucket := tx.RootBucket().Bucket(mainBucketName)
exists = mainBucket != nil
return nil
})
if err != nil {
str := fmt.Sprintf("failed to obtain database view: %v", err)
return false, stakeStoreError(ErrDatabase, str, err)
}
return exists, nil
}
示例3: Load
// Load fetches the entry in the database with the given ID and returns the Pool
// representing it.
func Load(namespace walletdb.Namespace, m *waddrmgr.Manager, poolID []byte) (*Pool, error) {
err := namespace.View(
func(tx walletdb.Tx) error {
if exists := existsPool(tx, poolID); !exists {
str := fmt.Sprintf("unable to find voting pool %v in db", poolID)
return newError(ErrPoolNotExists, str, nil)
}
return nil
})
if err != nil {
return nil, err
}
p := newPool(namespace, m, poolID)
if err = p.LoadAllSeries(); err != nil {
return nil, err
}
return p, nil
}