本文整理匯總了Golang中github.com/btcsuite/btcwallet/walletdb.Bucket類的典型用法代碼示例。如果您正苦於以下問題:Golang Bucket類的具體用法?Golang Bucket怎麽用?Golang Bucket使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Bucket類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: fetchOpenChannel
// fetchOpenChannel
func fetchOpenChannel(bucket walletdb.Bucket, nodeID [32]byte,
addrmgr *waddrmgr.Manager) (*OpenChannel, error) {
// Grab the bucket dedicated to storing data related to this particular
// node.
nodeBucket := bucket.Bucket(nodeID[:])
if nodeBucket == nil {
return nil, fmt.Errorf("channel bucket for node does not exist")
}
serializedChannel := nodeBucket.Get(activeChanKey)
if serializedChannel == nil {
// TODO(roasbeef): make proper in error.go
return nil, fmt.Errorf("node has no open channels")
}
// Decode the serialized channel state, using the addrmgr to decrypt
// sensitive information.
channel := &OpenChannel{}
reader := bytes.NewReader(serializedChannel)
if err := channel.Decode(reader, addrmgr); err != nil {
return nil, err
}
return channel, nil
}
示例2: rangeUnminedTransactions
// rangeUnminedTransactions executes the function f with TxDetails for every
// unmined transaction. f is not executed if no unmined transactions exist.
// Error returns from f (if any) are propigated to the caller. Returns true
// (signaling breaking out of a RangeTransactions) iff f executes and returns
// true.
func (s *Store) rangeUnminedTransactions(ns walletdb.Bucket, f func([]TxDetails) (bool, error)) (bool, error) {
var details []TxDetails
err := ns.Bucket(bucketUnmined).ForEach(func(k, v []byte) error {
if len(k) < 32 {
str := fmt.Sprintf("%s: short key (expected %d "+
"bytes, read %d)", bucketUnmined, 32, len(k))
return storeError(ErrData, str, nil)
}
var txHash wire.ShaHash
copy(txHash[:], k)
detail, err := s.unminedTxDetails(ns, &txHash, v)
if err != nil {
return err
}
// Because the key was created while foreach-ing over the
// bucket, it should be impossible for unminedTxDetails to ever
// successfully return a nil details struct.
details = append(details, *detail)
return nil
})
if err == nil && len(details) > 0 {
return f(details)
}
return false, err
}
示例3: putRawUnmined
func putRawUnmined(ns walletdb.Bucket, k, v []byte) error {
err := ns.Bucket(bucketUnmined).Put(k, v)
if err != nil {
str := "failed to put unmined record"
return storeError(ErrDatabase, str, err)
}
return nil
}
示例4: putRawCredit
func putRawCredit(ns walletdb.Bucket, k, v []byte) error {
err := ns.Bucket(bucketCredits).Put(k, v)
if err != nil {
str := "failed to put credit"
return storeError(ErrDatabase, str, err)
}
return nil
}
示例5: fetchTxRecord
func fetchTxRecord(ns walletdb.Bucket, txHash *wire.ShaHash, block *Block) (*TxRecord, error) {
k := keyTxRecord(txHash, block)
v := ns.Bucket(bucketTxRecords).Get(k)
rec := new(TxRecord)
err := readRawTxRecord(txHash, v, rec)
return rec, err
}
示例6: putRawTxRecord
func putRawTxRecord(ns walletdb.Bucket, k, v []byte) error {
err := ns.Bucket(bucketTxRecords).Put(k, v)
if err != nil {
str := fmt.Sprintf("%s: put failed", bucketTxRecords)
return storeError(ErrDatabase, str, err)
}
return nil
}
示例7: deleteRawUnmined
func deleteRawUnmined(ns walletdb.Bucket, k []byte) error {
err := ns.Bucket(bucketUnmined).Delete(k)
if err != nil {
str := "failed to delete unmined record"
return storeError(ErrDatabase, str, err)
}
return nil
}
示例8: deleteRawDebit
func deleteRawDebit(ns walletdb.Bucket, k []byte) error {
err := ns.Bucket(bucketDebits).Delete(k)
if err != nil {
str := "failed to delete debit"
return storeError(ErrDatabase, str, err)
}
return nil
}
示例9: putRawBlockRecord
func putRawBlockRecord(ns walletdb.Bucket, k, v []byte) error {
err := ns.Bucket(bucketBlocks).Put(k, v)
if err != nil {
str := "failed to store block"
return storeError(ErrDatabase, str, err)
}
return nil
}
示例10: putRawUnspent
func putRawUnspent(ns walletdb.Bucket, k, v []byte) error {
err := ns.Bucket(bucketUnspent).Put(k, v)
if err != nil {
str := "cannot put unspent"
return storeError(ErrDatabase, str, err)
}
return nil
}
示例11: fetchMinedBalance
func fetchMinedBalance(ns walletdb.Bucket) (btcutil.Amount, error) {
v := ns.Get(rootMinedBalance)
if len(v) != 8 {
str := fmt.Sprintf("balance: short read (expected 8 bytes, "+
"read %v)", len(v))
return 0, storeError(ErrData, str, nil)
}
return btcutil.Amount(byteOrder.Uint64(v)), nil
}
示例12: fetchBlockTime
func fetchBlockTime(ns walletdb.Bucket, height int32) (time.Time, error) {
k := keyBlockRecord(height)
v := ns.Bucket(bucketBlocks).Get(k)
if len(v) < 44 {
str := fmt.Sprintf("%s: short read (expected %d bytes, read %d)",
bucketBlocks, 44, len(v))
return time.Time{}, storeError(ErrData, str, nil)
}
return time.Unix(int64(byteOrder.Uint64(v[32:40])), 0), nil
}
示例13: testDeleteValues
// testDeleteValues removes all of the provided key/value pairs from the
// provided bucket.
func testDeleteValues(tc *testContext, bucket walletdb.Bucket, values map[string]string) bool {
for k := range values {
if err := bucket.Delete([]byte(k)); err != nil {
tc.t.Errorf("Delete: unexpected error: %v", err)
return false
}
}
return true
}
示例14: putUnspent
func putUnspent(ns walletdb.Bucket, outPoint *wire.OutPoint, block *Block) error {
k := canonicalOutPoint(&outPoint.Hash, outPoint.Index)
v := valueUnspent(block)
err := ns.Bucket(bucketUnspent).Put(k, v)
if err != nil {
str := "cannot put unspent"
return storeError(ErrDatabase, str, err)
}
return nil
}
示例15: putMinedBalance
func putMinedBalance(ns walletdb.Bucket, amt btcutil.Amount) error {
v := make([]byte, 8)
byteOrder.PutUint64(v, uint64(amt))
err := ns.Put(rootMinedBalance, v)
if err != nil {
str := "failed to put balance"
return storeError(ErrDatabase, str, err)
}
return nil
}