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:
parent
c086267521
commit
f36a83b3cc
11 changed files with 51 additions and 51 deletions
10
account.go
10
account.go
|
@ -23,7 +23,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/conformal/btcjson"
|
"github.com/conformal/btcjson"
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwallet/tx"
|
"github.com/conformal/btcwallet/txstore"
|
||||||
"github.com/conformal/btcwallet/wallet"
|
"github.com/conformal/btcwallet/wallet"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -37,7 +37,7 @@ type Account struct {
|
||||||
name string
|
name string
|
||||||
fullRescan bool
|
fullRescan bool
|
||||||
*wallet.Wallet
|
*wallet.Wallet
|
||||||
TxStore *tx.Store
|
TxStore *txstore.Store
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock locks the underlying wallet for an account.
|
// Lock locks the underlying wallet for an account.
|
||||||
|
@ -502,8 +502,8 @@ func (a *Account) RescanActiveJob() (*RescanJob, error) {
|
||||||
func (a *Account) ResendUnminedTxs() {
|
func (a *Account) ResendUnminedTxs() {
|
||||||
txs := a.TxStore.UnminedDebitTxs()
|
txs := a.TxStore.UnminedDebitTxs()
|
||||||
txbuf := new(bytes.Buffer)
|
txbuf := new(bytes.Buffer)
|
||||||
for _, tx_ := range txs {
|
for _, tx := range txs {
|
||||||
tx_.MsgTx().Serialize(txbuf)
|
tx.MsgTx().Serialize(txbuf)
|
||||||
hextx := hex.EncodeToString(txbuf.Bytes())
|
hextx := hex.EncodeToString(txbuf.Bytes())
|
||||||
txsha, err := SendRawTransaction(CurrentServerConn(), hextx)
|
txsha, err := SendRawTransaction(CurrentServerConn(), hextx)
|
||||||
if err != nil {
|
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
|
// ReqSpentUtxoNtfns sends a message to btcd to request updates for when
|
||||||
// a stored UTXO has been spent.
|
// a stored UTXO has been spent.
|
||||||
func ReqSpentUtxoNtfns(credits []*tx.Credit) {
|
func ReqSpentUtxoNtfns(credits []*txstore.Credit) {
|
||||||
ops := make([]*btcwire.OutPoint, 0, len(credits))
|
ops := make([]*btcwire.OutPoint, 0, len(credits))
|
||||||
for _, c := range credits {
|
for _, c := range credits {
|
||||||
op := c.OutPoint()
|
op := c.OutPoint()
|
||||||
|
|
12
acctmgr.go
12
acctmgr.go
|
@ -22,7 +22,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/conformal/btcjson"
|
"github.com/conformal/btcjson"
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwallet/tx"
|
"github.com/conformal/btcwallet/txstore"
|
||||||
"github.com/conformal/btcwallet/wallet"
|
"github.com/conformal/btcwallet/wallet"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"os"
|
"os"
|
||||||
|
@ -178,7 +178,7 @@ func openSavedAccount(name string, cfg *config) (*Account, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
wlt := new(wallet.Wallet)
|
wlt := new(wallet.Wallet)
|
||||||
txs := tx.NewStore()
|
txs := txstore.New()
|
||||||
a := &Account{
|
a := &Account{
|
||||||
name: name,
|
name: name,
|
||||||
Wallet: wlt,
|
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 transaction IDs match, the record in the TxStore is updated with
|
||||||
// the full information about the newly-mined tx, and the TxStore is
|
// the full information about the newly-mined tx, and the TxStore is
|
||||||
// scheduled to be written to disk..
|
// 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() {
|
for _, a := range am.AllAccounts() {
|
||||||
// TODO(jrick): This needs to iterate through each txout's
|
// TODO(jrick): This needs to iterate through each txout's
|
||||||
// addresses and find whether this account's keystore contains
|
// addresses and find whether this account's keystore contains
|
||||||
// any of the addresses this tx sends to.
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -627,7 +627,7 @@ func (am *AccountManager) CreateEncryptedWallet(passphrase []byte) error {
|
||||||
// written immediately to disk.
|
// written immediately to disk.
|
||||||
a := &Account{
|
a := &Account{
|
||||||
Wallet: wlt,
|
Wallet: wlt,
|
||||||
TxStore: tx.NewStore(),
|
TxStore: txstore.New(),
|
||||||
}
|
}
|
||||||
if err := am.RegisterNewAccount(a); err != nil {
|
if err := am.RegisterNewAccount(a); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -773,7 +773,7 @@ func (am *AccountManager) ListSinceBlock(since, curBlockHeight int32,
|
||||||
// GetTransaction.
|
// GetTransaction.
|
||||||
type accountTx struct {
|
type accountTx struct {
|
||||||
Account string
|
Account string
|
||||||
Tx *tx.TxRecord
|
Tx *txstore.TxRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTransaction returns an array of accountTx to fully represent the effect of
|
// GetTransaction returns an array of accountTx to fully represent the effect of
|
||||||
|
|
16
createtx.go
16
createtx.go
|
@ -23,7 +23,7 @@ import (
|
||||||
"github.com/conformal/btcchain"
|
"github.com/conformal/btcchain"
|
||||||
"github.com/conformal/btcscript"
|
"github.com/conformal/btcscript"
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwallet/tx"
|
"github.com/conformal/btcwallet/txstore"
|
||||||
"github.com/conformal/btcwallet/wallet"
|
"github.com/conformal/btcwallet/wallet"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -63,13 +63,13 @@ var TxFeeIncrement = struct {
|
||||||
|
|
||||||
type CreatedTx struct {
|
type CreatedTx struct {
|
||||||
tx *btcutil.Tx
|
tx *btcutil.Tx
|
||||||
inputs []*tx.Credit
|
inputs []*txstore.Credit
|
||||||
changeAddr btcutil.Address
|
changeAddr btcutil.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByAmount defines the methods needed to satisify sort.Interface to
|
// ByAmount defines the methods needed to satisify sort.Interface to
|
||||||
// sort a slice of Utxos by their amount.
|
// sort a slice of Utxos by their amount.
|
||||||
type ByAmount []*tx.Credit
|
type ByAmount []*txstore.Credit
|
||||||
|
|
||||||
func (u ByAmount) Len() int {
|
func (u ByAmount) Len() int {
|
||||||
return len(u)
|
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
|
// is the total number of satoshis which would be spent by the combination
|
||||||
// of all selected previous outputs. err will equal ErrInsufficientFunds if there
|
// of all selected previous outputs. err will equal ErrInsufficientFunds if there
|
||||||
// are not enough unspent outputs to spend amt.
|
// are not enough unspent outputs to spend amt.
|
||||||
func selectInputs(credits []*tx.Credit, amt btcutil.Amount,
|
func selectInputs(credits []*txstore.Credit, amt btcutil.Amount,
|
||||||
minconf int) (selected []*tx.Credit, out btcutil.Amount, err error) {
|
minconf int) (selected []*txstore.Credit, out btcutil.Amount, err error) {
|
||||||
|
|
||||||
bs, err := GetCurBlock()
|
bs, err := GetCurBlock()
|
||||||
if err != nil {
|
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
|
// Create list of eligible unspent previous outputs to use as tx
|
||||||
// inputs, and sort by the amount in reverse order so a minimum number
|
// inputs, and sort by the amount in reverse order so a minimum number
|
||||||
// of inputs is needed.
|
// of inputs is needed.
|
||||||
eligible := make([]*tx.Credit, 0, len(credits))
|
eligible := make([]*txstore.Credit, 0, len(credits))
|
||||||
for _, c := range credits {
|
for _, c := range credits {
|
||||||
if c.Confirmed(minconf, bs.Height) {
|
if c.Confirmed(minconf, bs.Height) {
|
||||||
// Coinbase transactions must have have reached maturity
|
// Coinbase transactions must have have reached maturity
|
||||||
|
@ -195,7 +195,7 @@ func (a *Account) txToPairs(pairs map[string]btcutil.Amount,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var selectedInputs []*tx.Credit
|
var selectedInputs []*txstore.Credit
|
||||||
// These are nil/zeroed until a change address is needed, and reused
|
// These are nil/zeroed until a change address is needed, and reused
|
||||||
// again in case a change utxo has already been chosen.
|
// again in case a change utxo has already been chosen.
|
||||||
var changeAddr btcutil.Address
|
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
|
// allowFree calculates the transaction priority and checks that the
|
||||||
// priority reaches a certain threshhold. If the threshhold is
|
// priority reaches a certain threshhold. If the threshhold is
|
||||||
// reached, a free transaction fee is allowed.
|
// 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 blocksPerDayEstimate = 144
|
||||||
const txSizeEstimate = 250
|
const txSizeEstimate = 250
|
||||||
|
|
||||||
|
|
24
ntfns.go
24
ntfns.go
|
@ -27,13 +27,13 @@ import (
|
||||||
"github.com/conformal/btcjson"
|
"github.com/conformal/btcjson"
|
||||||
"github.com/conformal/btcscript"
|
"github.com/conformal/btcscript"
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwallet/tx"
|
"github.com/conformal/btcwallet/txstore"
|
||||||
"github.com/conformal/btcwallet/wallet"
|
"github.com/conformal/btcwallet/wallet"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"github.com/conformal/btcws"
|
"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 {
|
if block == nil {
|
||||||
return nil, btcutil.TxIndexUnknown, nil
|
return nil, btcutil.TxIndexUnknown, nil
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func parseBlock(block *btcws.BlockDetails) (*tx.Block, int, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, btcutil.TxIndexUnknown, err
|
return nil, btcutil.TxIndexUnknown, err
|
||||||
}
|
}
|
||||||
b := &tx.Block{
|
b := &txstore.Block{
|
||||||
Height: block.Height,
|
Height: block.Height,
|
||||||
Hash: *blksha,
|
Hash: *blksha,
|
||||||
Time: time.Unix(block.Time, 0),
|
Time: time.Unix(block.Time, 0),
|
||||||
|
@ -75,7 +75,7 @@ func NtfnRecvTx(n btcjson.Cmd) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%v handler: bad hexstring: %v", n.Method(), err)
|
return fmt.Errorf("%v handler: bad hexstring: %v", n.Method(), err)
|
||||||
}
|
}
|
||||||
tx_, err := btcutil.NewTxFromBytes(rawTx)
|
tx, err := btcutil.NewTxFromBytes(rawTx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%v handler: bad transaction bytes: %v", n.Method(), err)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("%v handler: bad block: %v", n.Method(), err)
|
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
|
// For transactions originating from this wallet, the sent tx history should
|
||||||
// be recorded before the received history. If wallet created this tx, wait
|
// 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
|
// TODO(jrick) this is wrong due to tx malleability. Cannot safely use the
|
||||||
// txsha as an identifier.
|
// txsha as an identifier.
|
||||||
req := SendTxHistSyncRequest{
|
req := SendTxHistSyncRequest{
|
||||||
txsha: *tx_.Sha(),
|
txsha: *tx.Sha(),
|
||||||
response: make(chan SendTxHistSyncResponse),
|
response: make(chan SendTxHistSyncResponse),
|
||||||
}
|
}
|
||||||
SendTxHistSyncChans.access <- req
|
SendTxHistSyncChans.access <- req
|
||||||
|
@ -101,12 +101,12 @@ func NtfnRecvTx(n btcjson.Cmd) error {
|
||||||
if resp.ok {
|
if resp.ok {
|
||||||
// Wait until send history has been recorded.
|
// Wait until send history has been recorded.
|
||||||
<-resp.c
|
<-resp.c
|
||||||
SendTxHistSyncChans.remove <- *tx_.Sha()
|
SendTxHistSyncChans.remove <- *tx.Sha()
|
||||||
}
|
}
|
||||||
|
|
||||||
// For every output, find all accounts handling that output address (if any)
|
// For every output, find all accounts handling that output address (if any)
|
||||||
// and record the received txout.
|
// and record the received txout.
|
||||||
for outIdx, txout := range tx_.MsgTx().TxOut {
|
for outIdx, txout := range tx.MsgTx().TxOut {
|
||||||
var accounts []*Account
|
var accounts []*Account
|
||||||
_, addrs, _, _ := btcscript.ExtractPkScriptAddrs(txout.PkScript, cfg.Net())
|
_, addrs, _, _ := btcscript.ExtractPkScriptAddrs(txout.PkScript, cfg.Net())
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
|
@ -118,7 +118,7 @@ func NtfnRecvTx(n btcjson.Cmd) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, a := range accounts {
|
for _, a := range accounts {
|
||||||
txr, err := a.TxStore.InsertTx(tx_, block)
|
txr, err := a.TxStore.InsertTx(tx, block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ func NtfnRedeemingTx(n btcjson.Cmd) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%v handler: bad hexstring: %v", n.Method(), err)
|
return fmt.Errorf("%v handler: bad hexstring: %v", n.Method(), err)
|
||||||
}
|
}
|
||||||
tx_, err := btcutil.NewTxFromBytes(rawTx)
|
tx, err := btcutil.NewTxFromBytes(rawTx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%v handler: bad transaction bytes: %v", n.Method(), err)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("%v handler: bad block: %v", n.Method(), err)
|
return fmt.Errorf("%v handler: bad block: %v", n.Method(), err)
|
||||||
}
|
}
|
||||||
tx_.SetIndex(txIdx)
|
tx.SetIndex(txIdx)
|
||||||
return AcctMgr.RecordSpendingTx(tx_, block)
|
return AcctMgr.RecordSpendingTx(tx, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NtfnRescanProgress handles btcd rescanprogress notifications resulting
|
// NtfnRescanProgress handles btcd rescanprogress notifications resulting
|
||||||
|
|
|
@ -28,7 +28,7 @@ import (
|
||||||
"github.com/conformal/btcjson"
|
"github.com/conformal/btcjson"
|
||||||
"github.com/conformal/btcscript"
|
"github.com/conformal/btcscript"
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwallet/tx"
|
"github.com/conformal/btcwallet/txstore"
|
||||||
"github.com/conformal/btcwallet/wallet"
|
"github.com/conformal/btcwallet/wallet"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"github.com/conformal/btcws"
|
"github.com/conformal/btcws"
|
||||||
|
@ -226,7 +226,7 @@ func WalletRequestProcessor() {
|
||||||
err := f(n)
|
err := f(n)
|
||||||
AcctMgr.Release()
|
AcctMgr.Release()
|
||||||
switch err {
|
switch err {
|
||||||
case tx.ErrInconsistentStore:
|
case txstore.ErrInconsistentStore:
|
||||||
// Assume this is a broken btcd reordered
|
// Assume this is a broken btcd reordered
|
||||||
// notifications. Restart the connection
|
// notifications. Restart the connection
|
||||||
// to reload accounts files from their last
|
// to reload accounts files from their last
|
||||||
|
@ -952,7 +952,7 @@ func GetTransaction(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
received := btcutil.Amount(0)
|
received := btcutil.Amount(0)
|
||||||
var debitTx *tx.TxRecord
|
var debitTx *txstore.TxRecord
|
||||||
var debitAccount string
|
var debitAccount string
|
||||||
|
|
||||||
ret := btcjson.GetTransactionResult{
|
ret := btcjson.GetTransactionResult{
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* 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
|
// bitcoin wallet. Its primary purpose is to save transactions with
|
||||||
// outputs spendable with wallet keys and transactions that are signed by
|
// outputs spendable with wallet keys and transactions that are signed by
|
||||||
// wallet keys in memory, handle spend tracking for newly-inserted
|
// wallet keys in memory, handle spend tracking for newly-inserted
|
||||||
|
@ -61,11 +61,11 @@
|
||||||
// Example use:
|
// Example use:
|
||||||
//
|
//
|
||||||
// // Create a new transaction store to hold two transactions.
|
// // Create a new transaction store to hold two transactions.
|
||||||
// s := tx.NewStore()
|
// s := txstore.New()
|
||||||
//
|
//
|
||||||
// // Insert a transaction belonging to some imaginary block at
|
// // Insert a transaction belonging to some imaginary block at
|
||||||
// // height 123.
|
// // height 123.
|
||||||
// b123 := &tx.Block{Height: 123, Time: time.Now()}
|
// b123 := &txstore.Block{Height: 123, Time: time.Now()}
|
||||||
// r1, err := s.InsertTx(txA, b123)
|
// r1, err := s.InsertTx(txA, b123)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// // handle error
|
// // handle error
|
||||||
|
@ -83,14 +83,14 @@
|
||||||
//
|
//
|
||||||
// // Insert a second transaction at some imaginary block height
|
// // Insert a second transaction at some imaginary block height
|
||||||
// // 321.
|
// // 321.
|
||||||
// b321 := &tx.Block{Height: 321, Time: time.Now()}
|
// b321 := &txstore.Block{Height: 321, Time: time.Now()}
|
||||||
// r2, err := s.InsertTx(txB, b321)
|
// r2, err := s.InsertTx(txB, b321)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// // handle error
|
// // handle error
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// // Mark r2 as debiting from record 1's 0th credit.
|
// // 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 {
|
// if err != nil {
|
||||||
// // handle error
|
// // handle error
|
||||||
// }
|
// }
|
||||||
|
@ -99,4 +99,4 @@
|
||||||
// fmt.Println(c1o0.Spent()) // Prints "true"
|
// fmt.Println(c1o0.Spent()) // Prints "true"
|
||||||
// fmt.Println(s.Balance(1, 321)) // Prints "0 BTC"
|
// fmt.Println(s.Balance(1, 321)) // Prints "0 BTC"
|
||||||
// fmt.Println(d2.InputAmount()) // Prints amount of txA output 0.
|
// fmt.Println(d2.InputAmount()) // Prints amount of txA output 0.
|
||||||
package tx
|
package txstore
|
|
@ -4,7 +4,7 @@
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package tx_test
|
package txstore_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
|
@ -14,7 +14,7 @@
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package tx
|
package txstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/conformal/btcchain"
|
"github.com/conformal/btcchain"
|
|
@ -14,7 +14,7 @@
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package tx
|
package txstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -76,7 +76,7 @@ func (s *Store) ReadFrom(r io.Reader) (int64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset store.
|
// Reset store.
|
||||||
*s = *NewStore()
|
*s = *New()
|
||||||
|
|
||||||
// Read block structures. Begin by reading the total number of block
|
// Read block structures. Begin by reading the total number of block
|
||||||
// structures to be read, and then iterate that many times to read
|
// structures to be read, and then iterate that many times to read
|
|
@ -14,7 +14,7 @@
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package tx
|
package txstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -259,8 +259,8 @@ type credit struct {
|
||||||
spentBy *BlockTxKey // nil if unspent
|
spentBy *BlockTxKey // nil if unspent
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStore allocates and initializes a new transaction store.
|
// New allocates and initializes a new transaction store.
|
||||||
func NewStore() *Store {
|
func New() *Store {
|
||||||
return &Store{
|
return &Store{
|
||||||
blockIndexes: map[int32]uint32{},
|
blockIndexes: map[int32]uint32{},
|
||||||
unspent: map[int32]struct{}{},
|
unspent: map[int32]struct{}{},
|
|
@ -12,7 +12,7 @@
|
||||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
package tx_test
|
package txstore_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -21,7 +21,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
. "github.com/conformal/btcwallet/tx"
|
. "github.com/conformal/btcwallet/txstore"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "new store",
|
name: "new store",
|
||||||
f: func(_ *Store) (*Store, error) {
|
f: func(_ *Store) (*Store, error) {
|
||||||
return NewStore(), nil
|
return New(), nil
|
||||||
},
|
},
|
||||||
bal: 0,
|
bal: 0,
|
||||||
unc: 0,
|
unc: 0,
|
||||||
|
@ -547,7 +547,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindingSpentCredits(t *testing.T) {
|
func TestFindingSpentCredits(t *testing.T) {
|
||||||
s := NewStore()
|
s := New()
|
||||||
|
|
||||||
// Insert transaction and credit which will be spent.
|
// Insert transaction and credit which will be spent.
|
||||||
r, err := s.InsertTx(TstRecvTx, TstRecvTxBlockDetails)
|
r, err := s.InsertTx(TstRecvTx, TstRecvTxBlockDetails)
|
Loading…
Add table
Add a link
Reference in a new issue