Ejemplo n.º 1
0
// 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
}
Ejemplo n.º 2
0
// 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
}
Ejemplo n.º 3
0
// 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
}