Commit graph

753 commits

Author SHA1 Message Date
Josh Rickmar
3c390364d7 Switch some integers from unsigned to signed.
This change switches the time fields (firstSeen/lastSeen) of an
address from uint64 to int64, to be compatible with (time.Time).Unix,
as well as changing the block height fields (firstBlock/lastBlock)
from uint32 to int32, since block height is normally represented
signed.
2013-10-28 09:15:26 -04:00
Josh Rickmar
cafd4666d9 Don't attempt tx resend if unmined in a new block.
Any and all resending should be handled directly by btcd, and btcd
ignores any duplicate transactions when adding to mempool anyways.  A
set of unmined txs is still kept and send to btcd in case of btcd
restarting and losing wallet transactions from its mempool.
2013-10-25 18:59:21 -04:00
Josh Rickmar
2e3f91549c Updates for btcscript api changes. 2013-10-25 15:21:38 -04:00
Josh Rickmar
9e55f32791 Use testnet ports in example conf. 2013-10-24 09:26:06 -04:00
Josh Rickmar
b8d7620ced Fix bug in blockconnected notification handler.
If the new minedtx field cannot by type asserted as a []string, keep
processing the notification instead of printing an error and
returning.
2013-10-23 21:11:04 -04:00
Josh Rickmar
4b7f858bee Close() temp files before renaming them.
Fixes syncing dirty wallet files on Windows.
2013-10-23 18:40:02 -04:00
Josh Rickmar
9983a0a92a (Re)send all unmined txs on btcd connect.
In case of a btcd restart, it is necessary to send unmined
transactions back to btcd so they can be added to the tx mempool.
btcd can make a best-try effort, but It is ultimately btcwallet's
responsibility that transactions appear in blocks even if btcd is
restarted.
2013-10-23 18:32:27 -04:00
Josh Rickmar
adf4970fa4 Keep a pool of unmined transactions, and resend if unmined. 2013-10-23 18:23:20 -04:00
Josh Rickmar
32da412254 Remove debugging line. 2013-10-22 13:37:44 -04:00
John C. Vernaleo
bc498893d6 Move json errors to btcjson and call from there.
ok jrick@
2013-10-22 12:30:42 -04:00
Josh Rickmar
a12eb62b4d Make tests build again. 2013-10-22 10:03:11 -04:00
Josh Rickmar
b1c246c01b Perform smarter UTXO tracking.
This change fixes many issues with the tracking of unspent transaction
outputs.  First, notifications for when UTXOs arse spent are now
requested from btcd, and when spent, will be removed from the
UtxoStore.

Second, when transactions are created, the unconfirmed (not yet in a
block) Utxo (with block height -1 and zeroed block hash) is added to
the wallet's UtxoStore.  Notifications for when this UTXO is spent are
also requested from btcd.  After the tx appears in a block, because
the UTXO has a pkScript to be spent by another owned wallet address, a
notification with the UTXO will be sent to btcwallet.  We already
store the unconfirmed UTXO, so at this point the actual block height
and hash are filled in.

Finally, when calculating the balance, if confirmations is zero,
unconfirmed UTXOs (block height -1) will be included in the balance.
Otherwise, they are ignored.
2013-10-22 09:55:53 -04:00
Josh Rickmar
b3d8f02395 Move defered Unlock() before a possible function return. 2013-10-21 10:32:03 -04:00
Josh Rickmar
1d42efafad Fix erroneous OpenWallet comment.
The notification ID for new transactions to a watched address comment
is unneeded, as OpenWallet does not attempt to track wallets against a
connected btcd instance.  Added an additional comment to the function
noting this.

A log.Debugf was also added so tracked addresses are shown in the
debug output.
2013-10-17 11:19:13 -04:00
Josh Rickmar
44c5d29c3b Use net.JoinHostPort so IPv6 can be handled properly later. 2013-10-16 17:49:35 -04:00
Josh Rickmar
e4c96d01c1 Remove spew.Dump. 2013-10-16 17:38:56 -04:00
Josh Rickmar
310dc010ac Choose correct ports for testnet and mainnet.
This copies the functionality of btcd for choosing the ports for the
HTTP client (for btcd) and server (for frontends).  On testnet, the
following ports are used as default:

 - btcd: 18334
 - frontends: 18332

When running with the (currently disabled) --mainnet flag, btcwallet
will choose the following ports by default:

 - btcd: 8334
 - frontends: 8332

Both ports can be overridden no matter the chosen network using the -b
and -p flags.
2013-10-16 17:29:48 -04:00
Josh Rickmar
b5b684127c Remove debugging that slipped in. 2013-10-15 17:06:35 -04:00
Josh Rickmar
2782b7815e Sync wallet files to disk as needed, instead of waiting for a timer.
While fixing this code, the dirty flag was also cleared so that
unneeded syncs wouldn't be needed later.  The dirty flag set and sync
was also added for the 'getnewaddress' handler, as it was previously
missing.
2013-10-15 17:00:42 -04:00
Josh Rickmar
a5c7079fdf Disable --mainnet flag (hardcoded false). 2013-10-15 16:06:13 -04:00
Josh Rickmar
284191ec4b Sync wallet, utxo, and tx files to disk.
This runs a syncer once every minute to write any dirty wallet data
structures out to disk.  As currently implemented, dirty wallets will
be lost if not written before btcwallet closes or crashes.
Deterministic wallet help migitate this issue (as private keys can be
created again as long as a previous wallet file was written) but this
can still be a nuisance as a longer rescan will be required to catch
up to chain.
2013-10-15 15:53:49 -04:00
Josh Rickmar
9b84f87930 Fix issues found by golint. 2013-10-15 10:40:31 -04:00
Josh Rickmar
2541ffae76 Update account UtxoStore after creating transactions.
This removes inputs spent by a transaction from the stored UTXOs.  If
the UtxoStore is modified, all frontends are notified of the new
confirmed and unconfirmed account balances.

More work must be done later to check that the transaction actually
does occur in a later block.  btcd will make a best try effort to
relay the tx to the network, but it is still ultimately btcwallet's
responsibility.  Added a TODO so I remember to do this in the future.
2013-10-15 10:27:54 -04:00
Josh Rickmar
51cb34e50a Add func to remove utxos from a UtxoStore. 2013-10-15 10:05:51 -04:00
Josh Rickmar
154a962173 Use the correct message reply routing for sending transactions. 2013-10-15 09:42:10 -04:00
Josh Rickmar
acbb9076cd Use a generator goroutine and chan to create new JSON IDs 2013-10-14 18:45:48 -04:00
Josh Rickmar
d44159b452 Fix issues found by golint and go vet. 2013-10-14 16:39:15 -04:00
Josh Rickmar
a77fb8f0ae Return used transaction inputs from txToPairs.
These inputs will need to be removed from the stored utxos if the
transaction is sent and accepted in a block.
2013-10-14 16:14:04 -04:00
Josh Rickmar
47c4176b67 Fix sample config file. 2013-10-14 15:32:15 -04:00
Josh Rickmar
eff1407afe go fmt 2013-10-13 19:27:30 -04:00
Josh Rickmar
97a942e499 fix tests 2013-10-13 19:25:47 -04:00
Josh Rickmar
402764e132 Save pkScript of outpoint for txs to a watched address. 2013-10-11 13:01:27 -04:00
Josh Rickmar
42b15ccaa3 small cleanup 2013-10-11 10:53:55 -04:00
Josh Rickmar
50073b32c1 Save correct addresses for new utxos 2013-10-10 18:44:44 -04:00
Josh Rickmar
1ecc74c37d Begin sending notifications based on all accounts.
We need to notify frontends of notifications for every account
(wallet), not just the "current" opened account, since wallet will
need to have multiple wallets open at the same time.  Frontends will
have to filter notifications to show only details of only one account
if they need to display just one account at a time.

As of this commit, account balances and lock state notifications are
using this per-account notification scheme.
2013-10-10 16:20:23 -04:00
Josh Rickmar
94d4bd28ae Hold wallet map lock until wallet has been added (or an error happens) 2013-10-08 19:36:44 -04:00
Josh Rickmar
2e42efef53 fix comment 2013-10-08 19:33:22 -04:00
Josh Rickmar
2a7f09a422 Track new addresses after a getnewaddress command 2013-10-08 19:30:43 -04:00
Josh Rickmar
8163227225 Correctly parse account name for getnewaddress 2013-10-08 19:25:33 -04:00
Josh Rickmar
9cc6600db2 Fixes for api changes 2013-10-08 13:36:39 -04:00
Josh Rickmar
c85a3a29e3 'err != nil' -> 'err == nil', fixes getaddressesbyaccount 2013-10-07 22:22:47 -04:00
Josh Rickmar
f14d2edbff Return errors for getaddressesbyaccount command 2013-10-07 22:17:27 -04:00
Josh Rickmar
7e3edab24b remove debugging that snuck in 2013-10-07 20:33:43 -04:00
Josh Rickmar
c1cf2c59bb Implement settxfee command 2013-10-07 15:14:45 -04:00
Josh Rickmar
b137542c92 unbreak tests 2013-10-07 14:26:29 -04:00
Josh Rickmar
ea9ce4e0b1 Default to testnet.
Use on mainnet is not recommended until extensive testing has been
done, and should be done at your own risk. Run btcwallet with
--mainnet to operate on main Bitcoin network.
2013-10-07 13:25:05 -04:00
Josh Rickmar
3c4ff4b0f4 Add support for running wallet on testnet3.
Websocket connections to btcd will be closed if btcd and btcwallet are
running on different networks.
2013-10-07 13:09:24 -04:00
Josh Rickmar
1d6741eb05 Allocate mutex on stack, spotted by davec. 2013-10-06 11:04:01 -04:00
Josh Rickmar
e081508c9d Reply with errors when parameters are not a []interface{}. 2013-10-04 18:34:53 -04:00
Josh Rickmar
911e9fa5ae Add space to btcd auth string. 2013-10-04 16:40:57 -04:00