当前位置: 首页>>代码示例>>Golang>>正文


Golang walletdb.Tx类代码示例

本文整理汇总了Golang中github.com/decred/dcrwallet/walletdb.Tx的典型用法代码示例。如果您正苦于以下问题:Golang Tx类的具体用法?Golang Tx怎么用?Golang Tx使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Tx类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: updateSSRtxRecord

// updateSSRtxRecord updates an SSRtx record in the SSRtx records bucket.
func updateSSRtxRecord(tx walletdb.Tx, hash *chainhash.Hash,
	record *ssrtxRecord) error {
	// Fetch the current content of the key.
	// Possible buggy behaviour: If deserialization fails,
	// we won't detect it here. We assume we're throwing
	// ErrSSRtxsNotFound.
	oldRecords, _ := fetchSSRtxRecords(tx, hash)

	// Don't reinsert records we already have.
	if ssrtxRecordExistsInRecords(record, oldRecords) {
		return nil
	}

	bucket := tx.RootBucket().Bucket(ssrtxRecordsBucketName)

	var records []*ssrtxRecord
	// Either create a slice if currently nothing exists for this
	// key in the db, or append the entry to the slice.
	if oldRecords == nil {
		records = make([]*ssrtxRecord, 1)
		records[0] = record
	} else {
		records = append(oldRecords, record)
	}

	// Write the serialized SSRtxs keyed by the sstx hash.
	serializedSSRtxsRecords := serializeSSRtxRecords(records)

	err := bucket.Put(hash.Bytes(), serializedSSRtxsRecords)
	if err != nil {
		str := fmt.Sprintf("failed to store ssrtx records '%s'", hash)
		return stakeStoreError(ErrDatabase, str, err)
	}
	return nil
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:36,代码来源:db.go

示例2: getMaxUsedIdx

// getMaxUsedIdx returns the highest used index from the used addresses bucket
// of the given pool, series and branch.
func getMaxUsedIdx(tx walletdb.Tx, poolID []byte, seriesID uint32, branch Branch) (Index, error) {
	maxIdx := Index(0)
	usedAddrs := tx.RootBucket().Bucket(poolID).Bucket(usedAddrsBucketName)
	bucket := usedAddrs.Bucket(getUsedAddrBucketID(seriesID, branch))
	if bucket == nil {
		return maxIdx, nil
	}
	// FIXME: This is far from optimal and should be optimized either by storing
	// a separate key in the DB with the highest used idx for every
	// series/branch or perhaps by doing a large gap linear forward search +
	// binary backwards search (e.g. check for 1000000, 2000000, ....  until it
	// doesn't exist, and then use a binary search to find the max using the
	// discovered bounds).
	err := bucket.ForEach(
		func(k, v []byte) error {
			idx := Index(bytesToUint32(k))
			if idx > maxIdx {
				maxIdx = idx
			}
			return nil
		})
	if err != nil {
		return Index(0), newError(ErrDatabase, "failed to get highest idx of used addresses", err)
	}
	return maxIdx, nil
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:28,代码来源:db.go

示例3: putMeta

// putMeta
func putMeta(tx walletdb.Tx, key []byte, n int32) error {
	bucket := tx.RootBucket().Bucket(metaBucketName)
	err := bucket.Put(key, uint32ToBytes(uint32(n)))
	if err != nil {
		str := fmt.Sprintf("failed to store meta key '%s'", key)
		return stakeStoreError(ErrDatabase, str, err)
	}
	return nil
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:10,代码来源:db.go

示例4: getUsedAddrHash

// getUsedAddrHash returns the addr hash with the given index from the used
// addresses bucket of the given pool, series and branch.
func getUsedAddrHash(tx walletdb.Tx, poolID []byte, seriesID uint32, branch Branch,
	index Index) []byte {

	usedAddrs := tx.RootBucket().Bucket(poolID).Bucket(usedAddrsBucketName)
	bucket := usedAddrs.Bucket(getUsedAddrBucketID(seriesID, branch))
	if bucket == nil {
		return nil
	}
	return bucket.Get(uint32ToBytes(uint32(index)))
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:12,代码来源:db.go

示例5: putUsedAddrHash

// putUsedAddrHash adds an entry (key==index, value==encryptedHash) to the used
// addresses bucket of the given pool, series and branch.
func putUsedAddrHash(tx walletdb.Tx, poolID []byte, seriesID uint32, branch Branch,
	index Index, encryptedHash []byte) error {

	usedAddrs := tx.RootBucket().Bucket(poolID).Bucket(usedAddrsBucketName)
	bucket, err := usedAddrs.CreateBucketIfNotExists(getUsedAddrBucketID(seriesID, branch))
	if err != nil {
		return newError(ErrDatabase, "failed to store used address hash", err)
	}
	return bucket.Put(uint32ToBytes(uint32(index)), encryptedHash)
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:12,代码来源:db.go

示例6: fetchSStxRecord

// fetchSStxRecord retrieves a tx record from the sstx records bucket
// with the given hash.
func fetchSStxRecord(tx walletdb.Tx, hash *chainhash.Hash) (*sstxRecord, error) {
	bucket := tx.RootBucket().Bucket(sstxRecordsBucketName)

	key := hash.Bytes()
	val := bucket.Get(key)
	if val == nil {
		str := fmt.Sprintf("missing sstx record for hash '%s'", hash.String())
		return nil, stakeStoreError(ErrSStxNotFound, str, nil)
	}

	return deserializeSStxRecord(val)
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:14,代码来源:db.go

示例7: fetchMeta

// fetchMeta
func fetchMeta(tx walletdb.Tx, key []byte) (int32, error) {
	bucket := tx.RootBucket().Bucket(metaBucketName)

	val := bucket.Get(key)
	// Return 0 if the metadata is uninitialized
	if val == nil {
		return 0, nil
	}
	if val == nil {
		str := fmt.Sprintf("meta key not found %s", key)
		return 0, stakeStoreError(ErrDatabase, str, nil)
	}

	return int32(byteOrder.Uint32(val)), nil
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:16,代码来源:db.go

示例8: updateSStxRecord

// updateSStxRecord updates a sstx record in the sstx records bucket.
func updateSStxRecord(tx walletdb.Tx, record *sstxRecord) error {
	bucket := tx.RootBucket().Bucket(sstxRecordsBucketName)

	// Write the serialized txrecord keyed by the tx hash.
	serializedSStxRecord, err := serializeSStxRecord(record)
	if err != nil {
		str := fmt.Sprintf("failed to serialize sstxrecord '%s'", record.tx.Sha())
		return stakeStoreError(ErrDatabase, str, err)
	}
	err = bucket.Put(record.tx.Sha().Bytes(), serializedSStxRecord)
	if err != nil {
		str := fmt.Sprintf("failed to store sstxrecord '%s'", record.tx.Sha())
		return stakeStoreError(ErrDatabase, str, err)
	}
	return nil
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:17,代码来源:db.go

示例9: putSeriesRow

// putSeriesRow stores the given series row inside a voting pool bucket named
// after poolID. The voting pool bucket does not need to be created
// beforehand.
func putSeriesRow(tx walletdb.Tx, poolID []byte, ID uint32, row *dbSeriesRow) error {
	bucket, err := tx.RootBucket().CreateBucketIfNotExists(poolID)
	if err != nil {
		str := fmt.Sprintf("cannot create bucket %v", poolID)
		return newError(ErrDatabase, str, err)
	}
	bucket = bucket.Bucket(seriesBucketName)
	serialized, err := serializeSeriesRow(row)
	if err != nil {
		return err
	}
	err = bucket.Put(uint32ToBytes(ID), serialized)
	if err != nil {
		str := fmt.Sprintf("cannot put series %v into bucket %v", serialized, poolID)
		return newError(ErrDatabase, str, err)
	}
	return nil
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:21,代码来源:db.go

示例10: loadAllSeries

// loadAllSeries returns a map of all the series stored inside a voting pool
// bucket, keyed by id.
func loadAllSeries(tx walletdb.Tx, poolID []byte) (map[uint32]*dbSeriesRow, error) {
	bucket := tx.RootBucket().Bucket(poolID).Bucket(seriesBucketName)
	allSeries := make(map[uint32]*dbSeriesRow)
	err := bucket.ForEach(
		func(k, v []byte) error {
			seriesID := bytesToUint32(k)
			series, err := deserializeSeriesRow(v)
			if err != nil {
				return err
			}
			allSeries[seriesID] = series
			return nil
		})
	if err != nil {
		return nil, err
	}
	return allSeries, nil
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:20,代码来源:db.go

示例11: putPool

// putPool stores a voting pool in the database, creating a bucket named
// after the voting pool id and two other buckets inside it to store series and
// used addresses for that pool.
func putPool(tx walletdb.Tx, poolID []byte) error {
	poolBucket, err := tx.RootBucket().CreateBucket(poolID)
	if err != nil {
		return newError(ErrDatabase, fmt.Sprintf("cannot create pool %v", poolID), err)
	}
	_, err = poolBucket.CreateBucket(seriesBucketName)
	if err != nil {
		return newError(ErrDatabase, fmt.Sprintf("cannot create series bucket for pool %v",
			poolID), err)
	}
	_, err = poolBucket.CreateBucket(usedAddrsBucketName)
	if err != nil {
		return newError(ErrDatabase, fmt.Sprintf("cannot create used addrs bucket for pool %v",
			poolID), err)
	}
	_, err = poolBucket.CreateBucket(withdrawalsBucketName)
	if err != nil {
		return newError(
			ErrDatabase, fmt.Sprintf("cannot create withdrawals bucket for pool %v", poolID), err)
	}
	return nil
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:25,代码来源:db.go

示例12: getWithdrawal

func getWithdrawal(tx walletdb.Tx, poolID []byte, roundID uint32) []byte {
	bucket := tx.RootBucket().Bucket(poolID)
	return bucket.Get(uint32ToBytes(roundID))
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:4,代码来源:db.go

示例13: putWithdrawal

func putWithdrawal(tx walletdb.Tx, poolID []byte, roundID uint32, serialized []byte) error {
	bucket := tx.RootBucket().Bucket(poolID)
	return bucket.Put(uint32ToBytes(roundID), serialized)
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:4,代码来源:db.go

示例14: existsPool

// existsPool checks the existence of a bucket named after the given
// voting pool id.
func existsPool(tx walletdb.Tx, poolID []byte) bool {
	bucket := tx.RootBucket().Bucket(poolID)
	return bucket != nil
}
开发者ID:frankbraun,项目名称:dcrwallet,代码行数:6,代码来源:db.go


注:本文中的github.com/decred/dcrwallet/walletdb.Tx类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。