Rename tx package to txstore.

Prodded by @davecgh, and I had this change in the back of my head for
a while now anyways.
This commit is contained in:
Josh Rickmar 2014-05-08 14:48:42 -05:00
parent c086267521
commit f36a83b3cc
11 changed files with 51 additions and 51 deletions

View file

@ -23,7 +23,7 @@ import (
"fmt"
"github.com/conformal/btcjson"
"github.com/conformal/btcutil"
"github.com/conformal/btcwallet/tx"
"github.com/conformal/btcwallet/txstore"
"github.com/conformal/btcwallet/wallet"
"github.com/conformal/btcwire"
"path/filepath"
@ -37,7 +37,7 @@ type Account struct {
name string
fullRescan bool
*wallet.Wallet
TxStore *tx.Store
TxStore *txstore.Store
}
// Lock locks the underlying wallet for an account.
@ -502,8 +502,8 @@ func (a *Account) RescanActiveJob() (*RescanJob, error) {
func (a *Account) ResendUnminedTxs() {
txs := a.TxStore.UnminedDebitTxs()
txbuf := new(bytes.Buffer)
for _, tx_ := range txs {
tx_.MsgTx().Serialize(txbuf)
for _, tx := range txs {
tx.MsgTx().Serialize(txbuf)
hextx := hex.EncodeToString(txbuf.Bytes())
txsha, err := SendRawTransaction(CurrentServerConn(), hextx)
if err != nil {
@ -651,7 +651,7 @@ func (a *Account) ReqNewTxsForAddress(addr btcutil.Address) {
// ReqSpentUtxoNtfns sends a message to btcd to request updates for when
// a stored UTXO has been spent.
func ReqSpentUtxoNtfns(credits []*tx.Credit) {
func ReqSpentUtxoNtfns(credits []*txstore.Credit) {
ops := make([]*btcwire.OutPoint, 0, len(credits))
for _, c := range credits {
op := c.OutPoint()

View file

@ -22,7 +22,7 @@ import (
"fmt"
"github.com/conformal/btcjson"
"github.com/conformal/btcutil"
"github.com/conformal/btcwallet/tx"
"github.com/conformal/btcwallet/txstore"
"github.com/conformal/btcwallet/wallet"
"github.com/conformal/btcwire"
"os"
@ -178,7 +178,7 @@ func openSavedAccount(name string, cfg *config) (*Account, error) {
}
wlt := new(wallet.Wallet)
txs := tx.NewStore()
txs := txstore.New()
a := &Account{
name: name,
Wallet: wlt,
@ -573,12 +573,12 @@ func (am *AccountManager) BlockNotify(bs *wallet.BlockStamp) {
// the transaction IDs match, the record in the TxStore is updated with
// the full information about the newly-mined tx, and the TxStore is
// scheduled to be written to disk..
func (am *AccountManager) RecordSpendingTx(tx_ *btcutil.Tx, block *tx.Block) error {
func (am *AccountManager) RecordSpendingTx(tx *btcutil.Tx, block *txstore.Block) error {
for _, a := range am.AllAccounts() {
// TODO(jrick): This needs to iterate through each txout's
// addresses and find whether this account's keystore contains
// any of the addresses this tx sends to.
txr, err := a.TxStore.InsertTx(tx_, block)
txr, err := a.TxStore.InsertTx(tx, block)
if err != nil {
return err
}
@ -627,7 +627,7 @@ func (am *AccountManager) CreateEncryptedWallet(passphrase []byte) error {
// written immediately to disk.
a := &Account{
Wallet: wlt,
TxStore: tx.NewStore(),
TxStore: txstore.New(),
}
if err := am.RegisterNewAccount(a); err != nil {
return err
@ -773,7 +773,7 @@ func (am *AccountManager) ListSinceBlock(since, curBlockHeight int32,
// GetTransaction.
type accountTx struct {
Account string
Tx *tx.TxRecord
Tx *txstore.TxRecord
}
// GetTransaction returns an array of accountTx to fully represent the effect of

View file

@ -23,7 +23,7 @@ import (
"github.com/conformal/btcchain"
"github.com/conformal/btcscript"
"github.com/conformal/btcutil"
"github.com/conformal/btcwallet/tx"
"github.com/conformal/btcwallet/txstore"
"github.com/conformal/btcwallet/wallet"
"github.com/conformal/btcwire"
"sort"
@ -63,13 +63,13 @@ var TxFeeIncrement = struct {
type CreatedTx struct {
tx *btcutil.Tx
inputs []*tx.Credit
inputs []*txstore.Credit
changeAddr btcutil.Address
}
// ByAmount defines the methods needed to satisify sort.Interface to
// sort a slice of Utxos by their amount.
type ByAmount []*tx.Credit
type ByAmount []*txstore.Credit
func (u ByAmount) Len() int {
return len(u)
@ -89,8 +89,8 @@ func (u ByAmount) Swap(i, j int) {
// is the total number of satoshis which would be spent by the combination
// of all selected previous outputs. err will equal ErrInsufficientFunds if there
// are not enough unspent outputs to spend amt.
func selectInputs(credits []*tx.Credit, amt btcutil.Amount,
minconf int) (selected []*tx.Credit, out btcutil.Amount, err error) {
func selectInputs(credits []*txstore.Credit, amt btcutil.Amount,
minconf int) (selected []*txstore.Credit, out btcutil.Amount, err error) {
bs, err := GetCurBlock()
if err != nil {
@ -100,7 +100,7 @@ func selectInputs(credits []*tx.Credit, amt btcutil.Amount,
// Create list of eligible unspent previous outputs to use as tx
// inputs, and sort by the amount in reverse order so a minimum number
// of inputs is needed.
eligible := make([]*tx.Credit, 0, len(credits))
eligible := make([]*txstore.Credit, 0, len(credits))
for _, c := range credits {
if c.Confirmed(minconf, bs.Height) {
// Coinbase transactions must have have reached maturity
@ -195,7 +195,7 @@ func (a *Account) txToPairs(pairs map[string]btcutil.Amount,
return nil, err
}
var selectedInputs []*tx.Credit
var selectedInputs []*txstore.Credit
// These are nil/zeroed until a change address is needed, and reused
// again in case a change utxo has already been chosen.
var changeAddr btcutil.Address
@ -352,7 +352,7 @@ func minimumFee(tx *btcwire.MsgTx, allowFree bool) btcutil.Amount {
// allowFree calculates the transaction priority and checks that the
// priority reaches a certain threshhold. If the threshhold is
// reached, a free transaction fee is allowed.
func allowFree(curHeight int32, txouts []*tx.Credit, txSize int) bool {
func allowFree(curHeight int32, txouts []*txstore.Credit, txSize int) bool {
const blocksPerDayEstimate = 144
const txSizeEstimate = 250

View file

@ -27,13 +27,13 @@ import (
"github.com/conformal/btcjson"
"github.com/conformal/btcscript"
"github.com/conformal/btcutil"
"github.com/conformal/btcwallet/tx"
"github.com/conformal/btcwallet/txstore"
"github.com/conformal/btcwallet/wallet"
"github.com/conformal/btcwire"
"github.com/conformal/btcws"
)
func parseBlock(block *btcws.BlockDetails) (*tx.Block, int, error) {
func parseBlock(block *btcws.BlockDetails) (*txstore.Block, int, error) {
if block == nil {
return nil, btcutil.TxIndexUnknown, nil
}
@ -41,7 +41,7 @@ func parseBlock(block *btcws.BlockDetails) (*tx.Block, int, error) {
if err != nil {
return nil, btcutil.TxIndexUnknown, err
}
b := &tx.Block{
b := &txstore.Block{
Height: block.Height,
Hash: *blksha,
Time: time.Unix(block.Time, 0),
@ -75,7 +75,7 @@ func NtfnRecvTx(n btcjson.Cmd) error {
if err != nil {
return fmt.Errorf("%v handler: bad hexstring: %v", n.Method(), err)
}
tx_, err := btcutil.NewTxFromBytes(rawTx)
tx, err := btcutil.NewTxFromBytes(rawTx)
if err != nil {
return fmt.Errorf("%v handler: bad transaction bytes: %v", n.Method(), err)
}
@ -84,7 +84,7 @@ func NtfnRecvTx(n btcjson.Cmd) error {
if err != nil {
return fmt.Errorf("%v handler: bad block: %v", n.Method(), err)
}
tx_.SetIndex(txIdx)
tx.SetIndex(txIdx)
// For transactions originating from this wallet, the sent tx history should
// be recorded before the received history. If wallet created this tx, wait
@ -93,7 +93,7 @@ func NtfnRecvTx(n btcjson.Cmd) error {
// TODO(jrick) this is wrong due to tx malleability. Cannot safely use the
// txsha as an identifier.
req := SendTxHistSyncRequest{
txsha: *tx_.Sha(),
txsha: *tx.Sha(),
response: make(chan SendTxHistSyncResponse),
}
SendTxHistSyncChans.access <- req
@ -101,12 +101,12 @@ func NtfnRecvTx(n btcjson.Cmd) error {
if resp.ok {
// Wait until send history has been recorded.
<-resp.c
SendTxHistSyncChans.remove <- *tx_.Sha()
SendTxHistSyncChans.remove <- *tx.Sha()
}
// For every output, find all accounts handling that output address (if any)
// and record the received txout.
for outIdx, txout := range tx_.MsgTx().TxOut {
for outIdx, txout := range tx.MsgTx().TxOut {
var accounts []*Account
_, addrs, _, _ := btcscript.ExtractPkScriptAddrs(txout.PkScript, cfg.Net())
for _, addr := range addrs {
@ -118,7 +118,7 @@ func NtfnRecvTx(n btcjson.Cmd) error {
}
for _, a := range accounts {
txr, err := a.TxStore.InsertTx(tx_, block)
txr, err := a.TxStore.InsertTx(tx, block)
if err != nil {
return err
}
@ -246,7 +246,7 @@ func NtfnRedeemingTx(n btcjson.Cmd) error {
if err != nil {
return fmt.Errorf("%v handler: bad hexstring: %v", n.Method(), err)
}
tx_, err := btcutil.NewTxFromBytes(rawTx)
tx, err := btcutil.NewTxFromBytes(rawTx)
if err != nil {
return fmt.Errorf("%v handler: bad transaction bytes: %v", n.Method(), err)
}
@ -255,8 +255,8 @@ func NtfnRedeemingTx(n btcjson.Cmd) error {
if err != nil {
return fmt.Errorf("%v handler: bad block: %v", n.Method(), err)
}
tx_.SetIndex(txIdx)
return AcctMgr.RecordSpendingTx(tx_, block)
tx.SetIndex(txIdx)
return AcctMgr.RecordSpendingTx(tx, block)
}
// NtfnRescanProgress handles btcd rescanprogress notifications resulting

View file

@ -28,7 +28,7 @@ import (
"github.com/conformal/btcjson"
"github.com/conformal/btcscript"
"github.com/conformal/btcutil"
"github.com/conformal/btcwallet/tx"
"github.com/conformal/btcwallet/txstore"
"github.com/conformal/btcwallet/wallet"
"github.com/conformal/btcwire"
"github.com/conformal/btcws"
@ -226,7 +226,7 @@ func WalletRequestProcessor() {
err := f(n)
AcctMgr.Release()
switch err {
case tx.ErrInconsistentStore:
case txstore.ErrInconsistentStore:
// Assume this is a broken btcd reordered
// notifications. Restart the connection
// to reload accounts files from their last
@ -952,7 +952,7 @@ func GetTransaction(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
}
received := btcutil.Amount(0)
var debitTx *tx.TxRecord
var debitTx *txstore.TxRecord
var debitAccount string
ret := btcjson.GetTransactionResult{

View file

@ -14,7 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
// Package tx provides an implementation of a transaction store for a
// Package txstore provides an implementation of a transaction store for a
// bitcoin wallet. Its primary purpose is to save transactions with
// outputs spendable with wallet keys and transactions that are signed by
// wallet keys in memory, handle spend tracking for newly-inserted
@ -61,11 +61,11 @@
// Example use:
//
// // Create a new transaction store to hold two transactions.
// s := tx.NewStore()
// s := txstore.New()
//
// // Insert a transaction belonging to some imaginary block at
// // height 123.
// b123 := &tx.Block{Height: 123, Time: time.Now()}
// b123 := &txstore.Block{Height: 123, Time: time.Now()}
// r1, err := s.InsertTx(txA, b123)
// if err != nil {
// // handle error
@ -83,14 +83,14 @@
//
// // Insert a second transaction at some imaginary block height
// // 321.
// b321 := &tx.Block{Height: 321, Time: time.Now()}
// b321 := &txstore.Block{Height: 321, Time: time.Now()}
// r2, err := s.InsertTx(txB, b321)
// if err != nil {
// // handle error
// }
//
// // Mark r2 as debiting from record 1's 0th credit.
// d2, err := r2.AddDebits([]*tx.Credit{c1o0})
// d2, err := r2.AddDebits([]*txstore.Credit{c1o0})
// if err != nil {
// // handle error
// }
@ -99,4 +99,4 @@
// fmt.Println(c1o0.Spent()) // Prints "true"
// fmt.Println(s.Balance(1, 321)) // Prints "0 BTC"
// fmt.Println(d2.InputAmount()) // Prints amount of txA output 0.
package tx
package txstore

View file

@ -4,7 +4,7 @@
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package tx_test
package txstore_test
import (
"io"

View file

@ -14,7 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package tx
package txstore
import (
"github.com/conformal/btcchain"

View file

@ -14,7 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package tx
package txstore
import (
"bytes"
@ -76,7 +76,7 @@ func (s *Store) ReadFrom(r io.Reader) (int64, error) {
}
// Reset store.
*s = *NewStore()
*s = *New()
// Read block structures. Begin by reading the total number of block
// structures to be read, and then iterate that many times to read

View file

@ -14,7 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package tx
package txstore
import (
"errors"
@ -259,8 +259,8 @@ type credit struct {
spentBy *BlockTxKey // nil if unspent
}
// NewStore allocates and initializes a new transaction store.
func NewStore() *Store {
// New allocates and initializes a new transaction store.
func New() *Store {
return &Store{
blockIndexes: map[int32]uint32{},
unspent: map[int32]struct{}{},

View file

@ -12,7 +12,7 @@
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package tx_test
package txstore_test
import (
"bytes"
@ -21,7 +21,7 @@ import (
"time"
"github.com/conformal/btcutil"
. "github.com/conformal/btcwallet/tx"
. "github.com/conformal/btcwallet/txstore"
"github.com/conformal/btcwire"
)
@ -87,7 +87,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
{
name: "new store",
f: func(_ *Store) (*Store, error) {
return NewStore(), nil
return New(), nil
},
bal: 0,
unc: 0,
@ -547,7 +547,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
}
func TestFindingSpentCredits(t *testing.T) {
s := NewStore()
s := New()
// Insert transaction and credit which will be spent.
r, err := s.InsertTx(TstRecvTx, TstRecvTxBlockDetails)