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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.