2015-12-01 19:44:58 +01:00
|
|
|
// Copyright (c) 2014 The btcsuite developers
|
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
2014-06-13 19:14:44 +02:00
|
|
|
|
|
|
|
package votingpool
|
|
|
|
|
|
|
|
import (
|
2014-11-04 18:22:13 +01:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
2015-01-15 17:48:58 +01:00
|
|
|
"github.com/btcsuite/btcutil/hdkeychain"
|
2015-01-17 07:25:53 +01:00
|
|
|
"github.com/btcsuite/btcwallet/waddrmgr"
|
|
|
|
"github.com/btcsuite/btcwallet/walletdb"
|
2014-06-13 19:14:44 +02:00
|
|
|
)
|
|
|
|
|
2014-11-04 18:22:13 +01:00
|
|
|
var TstLastErr = lastErr
|
|
|
|
|
|
|
|
const TstEligibleInputMinConfirmations = eligibleInputMinConfirmations
|
|
|
|
|
2014-06-13 19:14:44 +02:00
|
|
|
// TstPutSeries transparently wraps the voting pool putSeries method.
|
|
|
|
func (vp *Pool) TstPutSeries(version, seriesID, reqSigs uint32, inRawPubKeys []string) error {
|
|
|
|
return vp.putSeries(version, seriesID, reqSigs, inRawPubKeys)
|
|
|
|
}
|
|
|
|
|
|
|
|
var TstBranchOrder = branchOrder
|
|
|
|
|
|
|
|
// TstExistsSeries checks whether a series is stored in the database.
|
|
|
|
func (vp *Pool) TstExistsSeries(seriesID uint32) (bool, error) {
|
2014-11-04 18:22:13 +01:00
|
|
|
var exists bool
|
|
|
|
err := vp.namespace.View(
|
|
|
|
func(tx walletdb.Tx) error {
|
|
|
|
poolBucket := tx.RootBucket().Bucket(vp.ID)
|
|
|
|
if poolBucket == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
bucket := poolBucket.Bucket(seriesBucketName)
|
|
|
|
if bucket == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
exists = bucket.Get(uint32ToBytes(seriesID)) != nil
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return exists, nil
|
2014-06-13 19:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TstNamespace exposes the Pool's namespace as it's needed in some tests.
|
|
|
|
func (vp *Pool) TstNamespace() walletdb.Namespace {
|
|
|
|
return vp.namespace
|
|
|
|
}
|
|
|
|
|
|
|
|
// TstGetRawPublicKeys gets a series public keys in string format.
|
|
|
|
func (s *SeriesData) TstGetRawPublicKeys() []string {
|
|
|
|
rawKeys := make([]string, len(s.publicKeys))
|
|
|
|
for i, key := range s.publicKeys {
|
|
|
|
rawKeys[i] = key.String()
|
|
|
|
}
|
|
|
|
return rawKeys
|
|
|
|
}
|
|
|
|
|
|
|
|
// TstGetRawPrivateKeys gets a series private keys in string format.
|
|
|
|
func (s *SeriesData) TstGetRawPrivateKeys() []string {
|
|
|
|
rawKeys := make([]string, len(s.privateKeys))
|
|
|
|
for i, key := range s.privateKeys {
|
|
|
|
if key != nil {
|
|
|
|
rawKeys[i] = key.String()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rawKeys
|
|
|
|
}
|
|
|
|
|
|
|
|
// TstGetReqSigs expose the series reqSigs attribute.
|
|
|
|
func (s *SeriesData) TstGetReqSigs() uint32 {
|
|
|
|
return s.reqSigs
|
|
|
|
}
|
|
|
|
|
|
|
|
// TstEmptySeriesLookup empties the voting pool seriesLookup attribute.
|
|
|
|
func (vp *Pool) TstEmptySeriesLookup() {
|
|
|
|
vp.seriesLookup = make(map[uint32]*SeriesData)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TstDecryptExtendedKey expose the decryptExtendedKey method.
|
|
|
|
func (vp *Pool) TstDecryptExtendedKey(keyType waddrmgr.CryptoKeyType, encrypted []byte) (*hdkeychain.ExtendedKey, error) {
|
|
|
|
return vp.decryptExtendedKey(keyType, encrypted)
|
|
|
|
}
|
|
|
|
|
2015-02-23 17:07:12 +01:00
|
|
|
// TstGetMsgTx returns a copy of the withdrawal transaction with the given
|
|
|
|
// ntxid.
|
2014-11-04 18:22:13 +01:00
|
|
|
func (s *WithdrawalStatus) TstGetMsgTx(ntxid Ntxid) *wire.MsgTx {
|
2015-02-23 17:07:12 +01:00
|
|
|
return s.transactions[ntxid].MsgTx.Copy()
|
2014-06-13 19:14:44 +02:00
|
|
|
}
|