Commit graph

80 commits

Author SHA1 Message Date
Josh Rickmar
fa699ef4a5 Add getaccount RPC command. 2013-12-30 16:31:33 -05:00
Josh Rickmar
920ff10155 Add getunconfirmedbalance websocket RPC extension. 2013-12-30 15:11:41 -05:00
Josh Rickmar
8be51e37cf Add handlers to unimplemented RPC requests.
Fixes #29.
2013-12-30 12:44:51 -05:00
Josh Rickmar
5bf8f89e4b Add listaddresstransactions extension.
Fixes #27.
2013-12-30 11:10:06 -05:00
Josh Rickmar
614ed93a1d Support mempool transaction notifications. 2013-12-20 12:48:47 -05:00
Josh Rickmar
75d3a77106 Fix build for new btcws notifications. 2013-12-13 11:00:31 -05:00
Josh Rickmar
d4e756bc23 Add getaddressbalance websocket extension request. 2013-12-10 16:15:25 -05:00
Josh Rickmar
48a685e85e Calculate the minimum tx fee when creating transactions. 2013-12-04 12:13:40 -05:00
Josh Rickmar
af1438eecd Add frontend support for displaying txs.
This change adds a new websocket extension command,
listalltransaction, which works just like listtransactions except it
does not take the count or from optional args, and will return an
array of all transaction details.  Notifications for newly-added
transactions are now sent to frontends as well, using the newtx
notification.

No support for updating tx details or removing failed txs is
implemented yet, and will be when cleanly failing a tx send is
implemented later.
2013-12-02 17:34:36 -05:00
Josh Rickmar
3c528f81ec New Account and AccountStore API.
This change better organizes account handling by creating a new
AccountStore type and accountstore global variable, with receiver
funcs for all operations that require all accounts.  More Account
funcs are also added to clean up account handling in the RPC code.

Intial work on this done by dhill.
2013-12-02 14:56:06 -05:00
Josh Rickmar
2dd3fd0a21 Fix build. 2013-11-27 16:07:00 -05:00
Josh Rickmar
0056958dfa More verbose tx handling. 2013-11-27 14:50:43 -05:00
Josh Rickmar
413f23ea18 Add support for listtransactions RPC request.
This change adds support for the listtransactions RPC command.  To
properly reply to this command, additonal information about received
transactions was added, and is now saved in an account's tx.bin file.
Additionally, when sending a transaction, a *tx.SendTx is now saved to
the Tx store, and is included in listtransactions replies under the
"send" category.

WARNING: All account's tx.bin and utxo.bin files should be removed
before running with this change, or else the files may not be read
correctly.  Removing tx.bin is not an issue as it was not being used
before, and was being saved with incorrect data.  Removing utxo.bin is
not an issue as it will just trigger a rescan on next start.  File
format versions are now included in both files, so automatic updates
from previous file formats will be possible with future changes.

Fixes #12.
2013-11-26 16:22:15 -05:00
Josh Rickmar
38ed238a7f Refill keypool if empty and wallet is unlocked. 2013-11-22 11:34:40 -05:00
Josh Rickmar
57802d8daf Rename some Account variables. 2013-11-21 11:23:50 -05:00
Josh Rickmar
649112b764 Reply with errors if the expected account does not exist.
This fixes the cases for the walletlock and walletpassphase requests
to return an appropiate error to the frontend when the default account
does not exist.
2013-11-21 11:06:46 -05:00
Josh Rickmar
47b5e17917 Return from dumpwallet handler after replying with an error. 2013-11-21 10:40:09 -05:00
Josh Rickmar
908b419443 Fix a typo. 2013-11-21 10:34:51 -05:00
Josh Rickmar
7e0a24950a Disable dumpwallet RPC handler that snuck in.
We do not support this yet, and need to match bitcoin'd behavior
before the function is added back to the RPC handler map.
2013-11-19 20:44:37 -05:00
Josh Rickmar
00fe439670 Add private key import and export support.
This adds the necessary bits for handling importing addresses for the
wallet file format, as well as implementing the importprivkey and
dumpprivkey RPC requests.

Initial code by dhill.
2013-11-19 20:18:11 -05:00
Josh Rickmar
28087af90b Add handling for standard bitcoind-style RPC.
With the exception of the createencryptedwallet extension (which is
required to make a wallet), all websocket-specific handlers are now
only available from a websocket connection, and standard RPC requests
are handled with a normal HTTP request and reply.

As an added bonus, listening on IPv6 now works.
2013-11-18 15:51:50 -05:00
Josh Rickmar
ef49eca365 more wallet -> account renames 2013-11-15 11:44:24 -05:00
David Hill
9c827a824f Rename BtcWallet to Account and put it in its own file. 2013-11-14 12:15:16 -05:00
Josh Rickmar
503f591e88 Process tx notifications before new blocks.
This change modifies the order in which transaction to watched
addresses are processed and when frontend notifications occur.  Due to
btcd notifying all transactions before sending the blockconnected
notification, the UTXO and transaction stores can be modified without
sending any frontend notifications, and then a single frontend
notification is sent when the blockconnected notification arrives.

The order in which each file is synced to disk was also changed to
write out the UTXO and transaction stores before writing the wallet.
This is to prevent a race where wallet closes after writing the dirty
wallet, but before the dirty UTXO store is written.  In this
situation, newly added UTXOs will be missed and not found again on the
next wallet open during the rescan.  Writing the wallet (which holds
the synced-to-block information) last prevents this.

An issue where the unconfirmed change UTXO created from a new
transaction never being properly notified to frontends is fixed now as
well.
2013-11-12 14:53:38 -05:00
Josh Rickmar
b7aec7f7a1 Type assert GetNewAddressCmd correctly. 2013-11-12 12:40:20 -05:00
Josh Rickmar
be26855266 Clean up replying to frontend commands.
This change moves the handlers to a map (instead of falling through a
switch statement), and updates each handler to use a btcjson.Cmd
instead of passing parameters in a btcjson.Message manually.

Plenty of comments were also added, which should also make the code
much more understandable.
2013-11-12 12:01:32 -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
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