Commit graph

1126 commits

Author SHA1 Message Date
Josh Rickmar
30db3490c0 Use btcws for parsing btcd notifications. 2013-11-08 12:45:18 -05:00
Josh Rickmar
cdd9bea5db Log sent tx ids to debug.
While here, add createdTx to unmined pool for 'sendfrom' commands as
well, instead of just 'sendmany'.
2013-11-07 15:29:17 -05:00
Josh Rickmar
3cd9a96dc7 Unlock mutex before function return. 2013-11-06 14:12:52 -05:00
Josh Rickmar
85219a70d3 Update for new btcd notifications.
This removes the enforced check for the spent field for tx-to-me
notifications, as this is no longer sent, and should be calculated by
wallet (not done yet).  Additionally, the full CreatedTx information
is saved with the unmined tx map, so when a tx is mined, information
about which inputs and ouputs it creates that are relevant to the
wallet can be used.
2013-11-06 14:05:14 -05:00
Josh Rickmar
f809638c72 Write dirty wallet to disk if a change address is added. 2013-11-06 12:52:01 -05:00
Josh Rickmar
e65206f752 Begin using btcws.
This change begins using the btcws package for marshaling custom
commands used for websocket connections to btcd.
2013-11-06 11:23:30 -05:00
Josh Rickmar
f3408bad91 Add support for compressed pubkeys (used by default).
Wallets that include compressed pubkeys are no longer compatible with
armory, however, imported wallets from armory (using uncompressed
pubkeys) are still valid.
2013-11-05 11:08:02 -05:00
Josh Rickmar
18fb993d0b Implement address rescanning.
When a wallet is opened, a rescan request will be sent to btcd with
all active addresses from the wallet, to rescan from the last synced
block (now saved to the wallet file) and the current best block.

As multi-account support is further explored, rescan requests should
be batched together to send a single request for all addresses from
all wallets.

This change introduces several changes to the wallet, tx, and utxo
files.  Wallet files are still compatible, however, a rescan will try
to start at the genesis block since no correct "last synced to" or
"created at block X" was saved.  The tx and utxo files, however, are
not compatible and should be deleted (or an error will occur on read).
If any errors occur opening the utxo file, a rescan will start
beginning at the creation block saved in the wallet.
2013-11-01 10:06:38 -04:00
David Hill
de76220c6b Just exit if we cannot start the listener 2013-10-29 23:53:20 -04:00
Josh Rickmar
9094bcde02 Remove unused const. 2013-10-29 11:02:30 -04:00
Josh Rickmar
91b4a5711c Fix logger formatting.
This change copies the behavior of btcd for using seelog for logging,
including making timestamps human readable, and setting the default
logging level to info.

Fixes #8.
2013-10-29 10:38:51 -04:00
Josh Rickmar
68cbb4192c Notify all frontends of new accounts.
When a new account (wallet) is created with the createencryptedwallet
JSON method, all frontends, including the one requesting the wallet,
must be notified of this new account and its balance (probably zero).

This removes the need for frontends to poll and check for any new
accounts.
2013-10-29 09:35:19 -04:00
Josh Rickmar
b2263ba6f5 Notify connecting frontends of btcd connect state.
This change automatically sends the btcdconnected notification for all
frontends as they connect to btcwallet.  The old btcdconnected command
has been removed, as it is no longer needed for clients to explicitly
request this information any longer.
2013-10-29 09:19:11 -04:00
Josh Rickmar
0e26aa7452 Update Windows Getting Started instructions.
To start btcd and btcwallet with all the right settings for testnet,
the Btcd Suite batch file should be run from the start menu rather
than btcd and btcwallet individually.  Update the README to reflect
that.
2013-10-29 09:03:10 -04:00
Josh Rickmar
540cbb0930 Greatly simplify design.
This change removes a lot of unnecessary and complicated locking (if
serializing requests is needed in the future, a goroutine will be used
instead) and also shifts the heavy lifting from frontends to btcwallet
itself to handle any notifications when they can be properly handled.
Although it's still legal to, frontends no longer need to explicitly
request account balances as these are calculated and sent as an async
notification on frontend connect, and these notifications will only
occur if btcd is currently connected.  Likewise, when btcd connects,
all frontends are immediately notified of all notifications that
require btcd information, such as the current block height for
calculating account balances.
2013-10-29 02:43:03 -04:00
Josh Rickmar
f6af03bf98 Set a default fee of 0.0001 BTC. 2013-10-29 02:17:49 -04:00
Josh Rickmar
bff2c850d5 stupid markdown parser is stupid. 2013-10-28 20:29:53 -04:00
Josh Rickmar
be95e8a050 Fix formatting issues. 2013-10-28 20:16:50 -04:00
Josh Rickmar
5ac395714a Modify README.md to reflect recent changes. 2013-10-28 20:05:31 -04:00
Josh Rickmar
aad61db6d0 Fix some remaining issues with reported balances.
CalculateBalance now works correctly: if confirmations is 0, all UTXOs
will be used for the balance.  Otherwise, unconfirmed UTXOs will be
exclused.  1 confirmation will allow the UTXO height and current block
height to be equal.  Even though the difference is zero, the
transaction including the UTXO has been mined into one block.

This change also remove extraneous account balance notifications for
connected and disconnected blocks.
2013-10-28 17:42:19 -04:00
Josh Rickmar
b34563bbd9 Request updates for new change addresses.
When sending a new transaction, the change address must receive the
same updates as explicitly-generated addresses.  Without this
notification, the unconfirmed UTXO will never become confirmed as the
notification will never be received.

This fixes the issue where change UTXOs never move from "Unconfirmed"
to "Balance" in btcgui.
2013-10-28 14:13:20 -04:00
Josh Rickmar
dea80bae9b Use bitcoin-qt balance/unconfirmed nomenclature.
bitcoin-qt uses "Balance" to mean all spendable outputs that have been
mined into a block, while "Unconfirmed" only refers to outputs that
have not yet been mined into a block.  This change copies that
behavior, instead of the previous required 6 blocks to be confirmed.
2013-10-28 14:10:37 -04:00
Josh Rickmar
851a9d6e41 Simplify txToPairs function signature.
This moves the non-error return values for txToPairs into a new
struct, createdTx, and adds an additional value for the payment
address string.
2013-10-28 11:24:50 -04:00
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