Commit graph

84 commits

Author SHA1 Message Date
Josh Rickmar
49f33eec0f Updates for btcjson type changes.
To increase compatibility with Bitcoin Core Wallet, additional fields
were added to and other fields made optional for the listtransactions
and gettransaction results structs.  For both, fee was changed to be
optional (including the zero value is allowed).
2015-05-06 13:18:13 -04:00
Dave Collins
c820c8a015 Relicense to the btcsuite developers. 2015-05-01 12:20:05 -05:00
Dave Collins
0a13274d5b Update btcjson path import paths to new location. 2015-05-01 00:59:14 -05:00
Josh Rickmar
ec6034e2d9 Modify default account naming policy.
Rather than disallowing the default account to be renamed as was
proposed in #245 (and implemented in #246), the default account name
is no longer considered a reserved name by the address manager.
Instead, it is simply the initial name used for the first initial
account.

A database upgrade removes any additional aliases for the default
account in the database.  This prevents a lookup for some name which
is not an account name from mapping to the default account
unexpectedly (potentially preventing incorrect account usage from the
RPC server due to bad iteraction with default parameters).

All unset account names in a JSON-RPC request are expected to be set
nil by btcjson.  This behavior depends on btcsuite/btcd#399.

Additionally, the manager no longer considers the wildcard * to be a
reserved account name.  Due to poor API decisions, the RPC server
overloads the meaning of account fields to optionally allow referring
to all accounts at a time, or a single account.  This is not a address
manager responsibility, though, as a future cleaner API should not use
multiple differet meanings for the same field across multiple
requests.  Therefore, don't burden down future APIs with this quirk
and prevent incorrect wildcard usage from the RPC server.

Closes #245.
2015-05-01 01:30:20 -04:00
Josh Rickmar
43aef7db3c Convert RPC server to btcjson v2.
Closes #227.
2015-05-01 00:55:12 -04:00
Josh Rickmar
56039deb94 Integrate wtxmgr package. 2015-04-28 17:30:17 -04:00
Javed Khan
48a3b413b4 Move txstore package to legacy directory 2015-04-20 18:20:19 -04:00
Javed Khan
74208f90c1 CurrentAddress: subsequently return new address 2015-04-16 06:34:25 +05:30
Manan Patel
dfe617e05d create wallet package
This a refactor of the btcwallet main package to create a new wallet
package.
The main feature of this package is the integration of all the other
wallet components (waddrmgr, txstore, and chain) and the Wallet type is
'runnable', so it will be continuously updating itself against changes
notified by the remote btcd instance.

It also includes several methods which provide access to information
necessary to run a wallet RPC server.
2015-04-02 11:17:45 -07:00
Josh Rickmar
3dba4ba87d Rename wallet package to keystore.
This package is used solely for the storage of private and public
keys, and the addresses they represent.  Since "wallet" is an
overloaded term and a working wallet requires transaction history as
well, rename this package and its data structures to more clearly
reflect what it is for.
2014-07-08 14:04:31 -05:00
Josh Rickmar
e64d948093 Synchronize locking/unlocking of all keystores.
This change fixes the asynchronous deferred locking that used to be
performed after some timeout after a call to walletpassphrase by
managing the locked state of each account in a new account manager
goroutine.  The timeouts for new unlock requests replace any running
timeouts for older requests, rather than allowing previous timeouts to
expire before the most recent one.

Fixes #105.
2014-07-01 10:09:50 -05:00
Josh Rickmar
99c986e21f Consistantly create empty bytes.Buffers. 2014-06-04 22:23:32 -05:00
Josh Rickmar
0cba485793 Handle unopenable transaction stores.
If the transaction store cannot be opened and read (i.e. the version
is too old to be deserialized), the wallet is marked unsynced and
rewritten, and a new empty transaction store is written over the
previous.
2014-06-03 12:10:42 -05:00
Josh Rickmar
9f7c2d60f7 Do not error opening simnet wallets. 2014-05-30 15:53:19 -05:00
Josh Rickmar
368204a58a Fix rescans across wallet process restarts.
This change immediately writes a new empty transaction store out to
disk if the old one could not be read.  Since old transaction store
versions are not read in at start, and were previously not written out
until new transaction history was received, it was possible that a
full rescan started and finished without ever marking a synced tx
history for the next wallet start.
2014-05-30 15:29:25 -05:00
Josh Rickmar
4495a523d8 Updates for btcutil and btcscript's btcnet conversion. 2014-05-27 17:49:36 -05:00
Josh Rickmar
c3224f4fbc Begin update to use btcnet.Params.
This is an intial pass at converting the btcwallet and deps codebases
to pass a network by their parameters, rather than by a magic number
to identify the network.  The parameters in params.go have been
updated to embed a *btcnet.Params, and all previous uses of cfg.Net()
have been replaced with activeNet.{Params,Net} (where activeNet is
the global var for the active network).

Although dependancy packages have not yet been updated from using
btcwire.BitcoinNet to btcnet.Params, the parameters are now accessible
at all callsites, and individual packages can be updated to use btcnet
without requiring updates in each external btc* package at once.

While here, the exported API for btcwallet internal library packages
(txstore and wallet) have been updated to pass full network parameters
rather than the btcwire definition of a network.
2014-05-22 21:24:08 -05:00
Josh Rickmar
987dc8f1c4 Updates for btcutil WIF API changes. 2014-05-21 17:50:47 -05:00
Josh Rickmar
14a9653d73 Use btcec consts for serialized pubkey lengths. 2014-05-20 08:12:43 -05:00
Josh Rickmar
c9b476e940 Remove useless if branch. 2014-05-16 22:19:48 -05:00
Owain G. Ainsworth
58ecb31710 wallet: use btcec.PrivKeyFromBytes 2014-05-07 16:08:47 +01:00
David Hill
6b24abfdad Code cleanup.
- Additional error checking
- Use the stack for small data sizes to avoid garbage collection
- Use io.ReadFull vs Read to detect underflows
2014-04-16 17:22:39 -04:00
David Hill
9cfa95d269 gofmt 2014-04-11 14:52:50 -04:00
Owain G. Ainsworth
674e9f2427 Rework wallet apis somewhat.
- Instead of returning a special constructed type whenever queries for an
address.  Return the internal object with an immutable external
interface.

- Make the private key gettable from PubKeyAddress to prevent having to look up
multiple times to get information from the same structure

- Enforce addresses always have public keys.
2014-04-09 22:40:28 +01:00
Josh Rickmar
eb567f2590 Remove some unused vars. 2014-04-07 20:04:39 -05:00
Josh Rickmar
53e4070a5a Support partial syncing of addresses in wallet format.
This change reappropriates the unused `last block` field from Armory's
wallet format to hold the block chain height for a partially synced
address, that is, an address that has been partially synced to
somewhere between its first seen block and the most recently seen
block.  The wallet's SyncHeight method has been updated to return
partial heights as well.

The actual marking of partially unsynced address from a rescan
progress update is not implemented yet.
2014-03-27 13:48:40 -05:00
Jimmy Song
c51cbb3332 Refactor len(w.secret) != 32
Now using w.IsLocked() for all instances of above.
Also changed one other place where the logic had to be reversed
in nextChainedAddress (len(w.secret) == 32 was the condition).
2014-03-20 11:37:54 -05:00
Josh Rickmar
089fa9de18 Rescan and track sync status of imported addresses.
The private key import codepath (called when handling the
importprivkey RPC method) was not triggering rescans for the imported
address.  This change begins a new rescan for each import and adds
additional logic to the wallet file to keep track of unsynced imported
addresses.  After a rescan on an imported address completes, the
address is marked as in sync with the rest of wallet and future
handshake rescans will start from the last seen block, rather than the
import height of the unsynced address.

While here, improve the logging for not just import rescans, but
rescanning on btcd connect (part of the handshake) as well.

Fixes #74.
2014-03-17 13:46:42 -05:00
Owain G. Ainsworth
6a02b61b61 Move walletAddress interface around a bit.
Move the stuff that scripts can't possibly support out of the interface
and move about two type assertions so that everything still works. They
key-using interfaces can be made into a KeyedAddress itnerface if we add
any more.
2014-03-17 14:09:02 +00:00
Owain G. Ainsworth
2ef11ae7f5 Add support for pay-to-script-hash addresses to wallet. 2014-03-17 14:09:02 +00:00
Owain G. Ainsworth
59fb904dc7 Prepare for adding other types of wallet addresses other than pkhash
Add a walletAddress interface to handle the differences betweent he
different types. Stop using btcutil.AddressPubKeyHash everywhere and just use
the standard address.
2014-03-13 19:14:27 +00:00
Owain G. Ainsworth
df31e30839 Make AddressInfo an interface.
Shortly we will add new types of address, so make AddressInfo an
interface, with concrete types providing address-specific information.
Adapt existing code to this new status quo.
2014-03-13 19:14:27 +00:00
Owain G. Ainsworth
34e4c0be35 call addr.lock() instead of handrolling. 2014-03-13 19:14:27 +00:00
Owain G. Ainsworth
d9a3f4324c tyop. 2014-03-13 19:14:26 +00:00
Josh Rickmar
5edd01e8a5 Unmark addresses as requiring private keys next unlock.
The flag marking chained addresses as needing private keys be
generated on the next wallet unlock was not being correctly unset
after creating and encrypting the private key.  After
serializing/deserializing the wallet, on next unlock, recreating
missing private keys would begin too early in the chain and fail due
to trying to encrypt an already encrypted address.

This change correctly unsets the flag and bumps the version so a
special case can be created for ignoring duplicate encryption attempts
when reading an old wallet file.  Tests have also been added to the
chained pubkey test to test for this error case.
2014-02-04 10:37:28 -05:00
Josh Rickmar
03ffa0ccd8 Do not serialize/deserialize armory unique ID.
Closes #70.
2014-02-03 15:11:17 -05:00
Josh Rickmar
b3bb0481b0 Add wallet func to return a change address.
Previous to this commit, all change addresses were indistinguishable
from manually requested addresses.  This adds a new function to return
the new address, setting a new change flag to true, and return the
change status with the AddressInfo.

This is needed as part of resolving #41 (getrawchangeaddress).
2014-02-03 10:21:47 -05:00
Josh Rickmar
6ad3f8786e Implement walletpassphrasechange RPC call.
Closes #62.
2014-01-27 14:14:54 -05:00
Josh Rickmar
3f6133e44b Add func to return passphrase of an unlocked wallet.
This function will be used to create new encrypted wallets with the
same passhprase as existing account wallets.
2014-01-24 12:31:08 -05:00
Josh Rickmar
e8c8823bfe Fix a bookkeeping error on watching wallet exports.
The exported watching wallet would include all imported addresses'
chain indexes added to the chain index map.  Imported addresses are
special as they do not belong to the address chain, and this would
cause issues when serializing the wallet.
2014-01-21 17:05:54 -05:00
Josh Rickmar
04b51ee426 Add func to get next n active addresses.
This adds a new function, ExtendActiveAddresses, to extend the number
of active addresses, generated by the address chain, by any arbitrary
positive number.  This will be used for recovering wallet addresses
from a wallet backup, as well as getting the next as many addresses as
required to keep a watching wallet in sync with an original wallet
with the private keys, or sync an original wallet with new addresses
generated by the watching wallet.
2014-01-21 11:23:09 -05:00
Josh Rickmar
effd810e54 Add function+tests for exporting a watching wallet.
This change introduces a new function to export a wallet in memory to
a watching wallet.  Watching wallets allow to watch for balance
changes and transactions to wallet addresses while only storing the
public parts of a wallet (no private keys).  New addresses created by
the watching wallet will use pubkey address chaining and will allow to
receive funds to an indefinite number of new addresses, and create the
private keys for said addresses from the non-watching wallet later.

The actual exporting of a watching wallet to a file (triggered by an
RPC request) is not yet implemented.

While here, fix an issue found by new test code for the chained
address code which incorrectly set the starting index of addresses in
the chain needing private keys to be created.
2014-01-20 16:02:44 -05:00
Josh Rickmar
80b16790bc Remove unused (and commented-out) function. 2014-01-17 10:33:29 -05:00
Josh Rickmar
54355f16e7 Return meaningful errors for locked wallets.
This change adds a check for a valid (32-byte length) secret before
attempting to encrypt or decrypt any addresses.  If the check fails, a
meaningful error (ErrWalletLocked) is returned to the caller, rather
than an error out of the aes package.
2014-01-17 10:29:44 -05:00
Josh Rickmar
97e1442e8d Remove exported Version func from wallet package.
This function was not implemented (returning zero values) and all
versioning is handled internally by the wallet's ReadFrom and WriteTo
functions.  If the read wallet does not match the latest file version,
it is read in the old format, but always written back with the new
format.
2014-01-17 09:43:23 -05:00
Josh Rickmar
82f2067ac4 Remove unnecessary mutex around wallet secret.
The wallet package was using a sync.Mutex around the saved decryption
key (kept in memory for an unlocked wallet).  As the wallet package is
designed to use no internal locking, and correct synchronization is
provided by the importers of the package, this mutex has been removed.
2014-01-17 09:35:52 -05:00
Josh Rickmar
311d6176a8 Generate new addresses from pubkeys if keypool is depleted.
This change uses the ChainedPubKey function to create addresses from
the previous address's public key and the wallet chaincode, without
the need for the private key, if the keypool has been depleted and the
wallet is locked.  This is done since the next chained private key is
unsolvable without a locked wallet.

If a wallet contains any of these chained addresses with missing
private keys, the private keys are created during the next wallet
unlock, using ChainedPrivKey.
2014-01-16 19:37:34 -05:00
Josh Rickmar
ea54b638f3 Add ChainedPubKey function and tests.
This change adds a function to generate the next public key of the
address chain from the previous public key and chaincode, without
needing the previous address's private key.  This will be used to
allow generating new addresses with an unlocked wallet, where the
private keys are created on the next unlock.

Tests have been added to verify that the chained private and private
keys match each other (using both chaining functions) as well as an
expected value in the test case. ECDSA signature creation and
verifiction is also performed using the generated keypairs to verify
the next keypair is valid.
2014-01-16 11:50:08 -05:00
Josh Rickmar
3dc9b175d0 Use correct hash algorithm for chained addresses.
btcwallet originally correctly copied the behavior of armory when
chaining new private keys off the previous private key, but this
regressed in commit e8265eca41 with a
switch from double sha256 to a single sha256.

This change reverts the behavior (using the clearly-named function
btcwire.DoubleSha256) to match armory's and old btcwallet's address
chaining algorithm.

If you have flipped the switch to use btcwallet on mainnet, any newly
generated addresses created for the keypool after Jan 6, 2014 (the
date the regression was committed) should be backed up with
dumpprivkey (using btcctl) and a new wallet backup should be made of
your current wallet file (~/.btcwallet/mainnet/wallet.bin on unix) to
avoid the possibility of losing any real money.
2014-01-15 18:25:19 -05:00
Josh Rickmar
f0c649b7ac Make maximum keypool size a config option. 2014-01-15 17:29:01 -05:00