Commit graph

58 commits

Author SHA1 Message Date
Josh Rickmar
4bdb88f4bc Log authentication failures to info debug level. 2013-12-05 10:04:35 -05:00
Josh Rickmar
ce23523ed7 Introduce new account file structure.
This changes the locations that account files (wallet.bin, utxo.bin,
and tx.bin) are searched for when opening or disk syncing accounts.
Previously, files were saved in the following layout:

  ~/.btcwallet/
    - btcwallet/
      - wallet.bin
      - tx.bin
      - utxo.bin
    - btcwallet-AccountA/
      - wallet.bin
      - tx.bin
      - utxo.bin

This format had two issues.  First, each account would require its own
directory, causing a scalability issue on unix (and perhaps other)
platforms.  Second, there was no distinction between testnet and
mainnet wallets, and if mainnet support was enabled, btcwallet would
attempt to open accounts with testnet wallets.

Instead, the following file structure is now used:

  ~/.btcwallet/
    - testnet/
      - wallet.bin
      - tx.bin
      - utxo.bin
      - AccountA-wallet.bin
      - AccountA-tx.bin
      - AccountA-utxo.bin

This solves both of the previously-mentioned issues by requiring only
two subdirectories (one each for the testnet and mainnet bitcoin
networks), and by separating the locations to open and save testnet
and mainnet account files.

At startup, a check for the old account file structure is performed.
If found, files are moved to the new locations, and the old account
directories are removed.  Account files are moved to the testnet
directory, as only testnet support is currently enabled.

The version has been bumped to 0.1.1 to reflect this change.

Fixes #16.
2013-12-04 20:25:13 -05:00
Josh Rickmar
3b04e3a4bc Use TLS+auth for frontend connections.
This change is mostly a copy paste job from the TLS listeners and
autogenerated cert code from btcd.
2013-12-03 10:52:09 -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
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
a246fc91d6 Update for new btcws TxMinedNtfn API. 2013-11-25 12:54:49 -05:00
Josh Rickmar
74d7178aa8 Set TLS1.2 as the minimum acceptable TLS version. 2013-11-21 16:41:15 -05:00
Josh Rickmar
21faab5e3e Simplify BtcdHandler. 2013-11-21 15:49:07 -05:00
Josh Rickmar
935335f1a5 Pass handsake errors to caller. 2013-11-21 15:01:51 -05:00
Josh Rickmar
828544cb2f Fix some races found by -race. 2013-11-21 14:41:05 -05:00
Josh Rickmar
e1ce9843bf Add missing mutex unlock if an error is hit.
Spotted by dhill.
2013-11-21 10:48:35 -05:00
David Hill
89e3054bc5 socks5/tor proxy support 2013-11-19 20:54:48 -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
0bd877237f Add missing space for basic HTTP auth header. 2013-11-19 18:25:42 -05:00
Josh Rickmar
5dbf69d23e Enable TLS support for btcd websocket connections.
This adds an additional config option, -cafile, to specify the root
certificates checked when verifying a btcd TLC connection.  btcd will
now automatically generate certs in
~/.btcd/data/{main,test}net/rpc.cert, and this file should be copied
to ~/.btcwallet/cert.pem.

The -btcdport option is also gone now, and replaced with -connect (or
-c), to specify both the hostname/ip and port of the server running
btcd.
2013-11-19 12:21:54 -05:00
Josh Rickmar
474106a757 Sending and receving from chans on the same goroutine is a bad idea. 2013-11-18 16:37:28 -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
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
30db3490c0 Use btcws for parsing btcd notifications. 2013-11-08 12:45:18 -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
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
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
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
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
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
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
44c5d29c3b Use net.JoinHostPort so IPv6 can be handled properly later. 2013-10-16 17:49:35 -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
9b84f87930 Fix issues found by golint. 2013-10-15 10:40:31 -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
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
7e3edab24b remove debugging that snuck in 2013-10-07 20:33:43 -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
911e9fa5ae Add space to btcd auth string. 2013-10-04 16:40:57 -04:00
Josh Rickmar
8e9e6f6229 Handle basic auth for dialing btcd websocket connections. 2013-10-03 09:11:35 -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
290fdb5427 Read btcd:blockconnected hash string from correct map. 2013-09-05 12:58:19 -04:00
Josh Rickmar
2789502ec9 Begin tracking newly created wallets against btcd. 2013-09-05 12:50:39 -04:00
Josh Rickmar
ed98256553 Track opened wallets after establishing btcd connection. 2013-09-05 11:51:33 -04:00
Josh Rickmar
019df772b1 Use a single handler (per wallet) for all tx notifications. 2013-09-05 11:19:48 -04:00
Josh Rickmar
6e20de7c4a Interpret btcd:blockconnected hash as string.
btcd was changed to send the block hash for new block notifications as
a big endian string, so type assert as a string and convert to a
btcwire.ShaHash.
2013-09-04 20:38:57 -04:00
Josh Rickmar
419ceb55c6 Implement Utxo notification handler to add to utxo store. 2013-09-04 09:54:06 -04:00