Commit graph

54 commits

Author SHA1 Message Date
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
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
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
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
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
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
adf4970fa4 Keep a pool of unmined transactions, and resend if unmined. 2013-10-23 18:23:20 -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
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
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
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
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
f14d2edbff Return errors for getaddressesbyaccount command 2013-10-07 22:17:27 -04:00
Josh Rickmar
c1cf2c59bb Implement settxfee command 2013-10-07 15:14:45 -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
e081508c9d Reply with errors when parameters are not a []interface{}. 2013-10-04 18:34:53 -04:00
Josh Rickmar
4857572e59 Send raw transactions off to btcd. 2013-10-04 15:02:17 -04:00
Josh Rickmar
63686347c6 Create transactions using saved utxo data.
This is a big change that also many general fixes to problems found
when creating transactions.  In particular the Utxo and Tx formats and
serialization functions were updated with additional information that
would be necessary for rolling back old utxo and tx data data after
btcd chain switches.  This change also implements the json methods
'sendfrom' and 'sendmany' to create a new transaction based on a
frontend request.

Transactions are currently not sent to btcd since the tx relay code is
not finished yet, so a temporary error is returned back to frontends
who try to send new transactions.
2013-10-01 14:26:27 -04:00
Josh Rickmar
24d6168709 Reply with correct account balance for getbalance requests. 2013-09-05 15:31:39 -04:00
Josh Rickmar
2789502ec9 Begin tracking newly created wallets against btcd. 2013-09-05 12:50:39 -04:00
Josh Rickmar
28c679ee82 Reply with nil result if wallet creation succeeded. 2013-09-03 12:16:02 -04:00
Josh Rickmar
e3416add35 Implement 'getbalance' replier (currently replies with 0). 2013-09-03 11:00:01 -04:00
Josh Rickmar
1918bd3698 Do not fail if default wallet does not exist.
We must instead wait for the user to explicitly generate their own
wallet for an account name.  This is because all btcwallet wallets
must be encrypted, and the passphrase must be known at time of wallet
generation.
2013-09-03 10:21:14 -04:00
Josh Rickmar
1c1ab52ef7 Implement new JSON extension 'createencryptedwallet'. 2013-09-03 09:49:16 -04:00
Josh Rickmar
9eae969230 Implement new wallet and chained address creation. 2013-09-03 00:10:32 -04:00
Josh Rickmar
e80d089a15 Implement io.ReaderFrom and io.WriterTo tx/utxo types.
These are currently untested.
2013-08-23 14:28:07 -04:00
Josh Rickmar
39259bee37 Notify frontends when wallet is locked or unlocked. 2013-08-22 12:00:37 -04:00
Josh Rickmar
eec4c64ac6 And another one. 2013-08-21 15:28:15 -04:00
Josh Rickmar
4f4807a003 Fix logic error: err != nil -> err == nil 2013-08-21 15:26:00 -04:00
Josh Rickmar
cc13f2eed5 Implement JSON extension walletislocked 2013-08-21 14:46:20 -04:00
Josh Rickmar
b0f6a70d40 Use ReplySuccess() to send successful JSON replies 2013-08-21 13:43:05 -04:00
Josh Rickmar
8f38a43964 Send JSON reply after successfully decrypting wallet 2013-08-21 13:29:36 -04:00