Commit graph

130 commits

Author SHA1 Message Date
Josh Rickmar
c97e0d5fc6 Detect reorgs after btcd disconnect/reconnect.
This change saves (at most) the last 20 block hashes to disk.  Upon
btcd connect, in the handshake, btcwallet checks whether btcd's best
chain still contains these blocks, starting from the most recently
added block and continuing until the earliest saved.  If any blocks
are missing, Tx history and UTXOs from any blocks no longer in the
chain are removed, and a rescan is started from after the best block
still in the main chain.

If all previous block hashes are exhausted (either due to a large
reorg, or because not enough blocks have been seen), a full rescan is
triggered (full meaning from the earliest block that matters to this
wallet) since the last synced up to point is no longer available.

The previous 20 seen block hashes are saved to the wallet file, which
required bumping the file version.  Older wallets written with lesser
versions will use the previous reading function, making this change
backwards compatible.
2013-12-09 15:19:20 -05:00
Josh Rickmar
378af40329 Remove some fmt.Printf debugging. 2013-12-03 12:45:27 -05:00
Josh Rickmar
c54af23849 Perform signature verifiction when generating addresses.
This change adds an additional check when creating a new wallet or
extending the keypool.  All public and private keypairs are parsed
from their serialized forms, and an ecdsa signature is created and
verified using the keypairs.  If the verifiction fails at any point,
the wallet creation or keypool extension is aborted to prevent any
errors where an address is returned to a user, but any funds send to
that address are unspendable due to a mismatched keypair.
2013-12-03 12:37:18 -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
bec16828c5 Ignore zeros when generating wallet name. 2013-11-22 14:47:43 -05:00
Josh Rickmar
a05e9b7a3e Make tests pass again. 2013-11-22 11:40:24 -05:00
Josh Rickmar
38ed238a7f Refill keypool if empty and wallet is unlocked. 2013-11-22 11:34:40 -05:00
Josh Rickmar
3143ec328e Correctly serialize pubkeys for imported keys. 2013-11-20 10:47:44 -05:00
Josh Rickmar
455a376df8 Add hex string of pubkey to AddressInfo. 2013-11-20 10:17:49 -05:00
Josh Rickmar
1ff67707e4 Fix issues found by golint. 2013-11-19 20:46:16 -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
David Hill
37109bfe0d update tests to use the new Account type and catch rand.Read errors 2013-11-15 12:03:52 -05:00
David Hill
fcc4871351 check rand.Read for errors 2013-11-15 11:59:37 -05:00
Josh Rickmar
c138a663e1 Return errors if rand.Read fails. 2013-11-13 17:25:50 -05:00
Josh Rickmar
e9b7fd2fcf Huge cleanup for decreased eye bleeding. 2013-11-11 15:30:50 -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
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
50073b32c1 Save correct addresses for new utxos 2013-10-10 18:44:44 -04:00
Josh Rickmar
9cc6600db2 Fixes for api changes 2013-10-08 13:36:39 -04:00
Josh Rickmar
c85a3a29e3 'err != nil' -> 'err == nil', fixes getaddressesbyaccount 2013-10-07 22:22:47 -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
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
85425c2c80 Abstract out wallet tracking function.
This will soon be used to also implement tracking of utxo and txs for
address in this wallet.
2013-09-03 17:16:07 -04:00
Josh Rickmar
b495842b0e Set defualt highestUsed chained address to -1 (root). 2013-09-03 16:35:07 -04:00
Josh Rickmar
9eae969230 Implement new wallet and chained address creation. 2013-09-03 00:10:32 -04:00
Josh Rickmar
cc13f2eed5 Implement JSON extension walletislocked 2013-08-21 14:46:20 -04:00
Josh Rickmar
92a79baeff Implement (*Wallet).Lock() and reply with correct JSON 2013-08-21 13:25:22 -04:00
Josh Rickmar
a56e4e89d2 Initial commit. 2013-08-21 10:37:30 -04:00