當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Namespace.View方法代碼示例

本文整理匯總了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
}
開發者ID:frankbraun,項目名稱:dcrwallet,代碼行數:36,代碼來源:stake.go

示例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
}
開發者ID:frankbraun,項目名稱:dcrwallet,代碼行數:15,代碼來源:db.go

示例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
}
開發者ID:frankbraun,項目名稱:dcrwallet,代碼行數:20,代碼來源:pool.go


注:本文中的github.com/decred/dcrwallet/walletdb.Namespace.View方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。