Commit Graph

2267 Commits

Author SHA1 Message Date
ThomasV d367930113 amount is in satoshis 2015-06-08 13:20:42 +02:00
ThomasV 9bd94e5062 refactor payment requests 2015-06-08 12:51:45 +02:00
ThomasV 572a463806 reason->memo 2015-06-08 08:06:38 +02:00
ThomasV 3bb00f0006 store json record requests 2015-06-07 21:52:23 +02:00
ThomasV bf755f8ac0 jsonrpc interface 2015-06-07 19:11:54 +02:00
ThomasV 48e53498db improve requests 2015-06-07 18:44:33 +02:00
Neil Booth 98bea614d8 Implement BIP-LI01.
No more need to randomly place change.
2015-06-06 22:25:40 +09:00
ThomasV 0b874b2bb0 Readding pending_transactions_for_notifications, needed by the gui. 2015-06-05 08:56:55 +02:00
Neil Booth a2445aa27d Remove unused vars and imports. 2015-06-05 11:54:00 +09:00
Neil Booth 2f2e468d0a SocketPipe shouldn't close the socket.
This is a layering violation - the SocketPipe doesn't own
the socket and provides no other way to close the socket, leading
to unnecessary complexity like that in interface.py.

I looked at deamon.py and NetworkProxy - the two other users,
and they don't close the sockets explicitly, just let them be
garbage collected.
2015-06-04 16:30:59 +09:00
ThomasV 90d7179d73 Merge pull request #1276 from kyuupichan/need_interface
Need an interface to process a request.
2015-06-04 05:57:04 +02:00
Neil Booth caebdd0819 Need an interface to process a request.
Occasionally triggered with a race at start up, typically from
the verifier requesting a merkle root.
2015-06-04 11:22:57 +09:00
ThomasV fc23b0f490 fix #1274 2015-06-03 14:18:49 +02:00
ThomasV ec795ba3c0 fix var name 2015-06-03 11:39:44 +02:00
ThomasV ab60da89ac Add a help group for config variables. Change name of ssl variables 2015-06-03 11:34:52 +02:00
ThomasV 34360bddfb add missing definition of COIN 2015-06-03 10:25:21 +02:00
ThomasV 0ddd94b5b3 remove forgotten debugging statement 2015-06-03 10:03:55 +02:00
ThomasV ca62df89d4 fix: set_config 2015-06-03 10:02:12 +02:00
ThomasV d85a11173d verify: return earlier if request is empty 2015-06-03 09:34:35 +02:00
ThomasV cbeeedcca2 Add note for commands that are not SPV; fix format_request parameter 2015-06-03 09:12:38 +02:00
ThomasV fb6a74e034 fix typo 2015-06-02 16:49:21 +02:00
ThomasV 3188ff05a3 fix is_watching_only 2015-06-02 16:41:32 +02:00
ThomasV b832a5cea4 Merge pull request #1272 from kyuupichan/if-socket
Fix couple of minor socket issues
2015-06-02 16:28:42 +02:00
ThomasV 088d8e8415 show request status 2015-06-02 11:36:06 +02:00
Neil Booth ab2f80c3e0 Fix couple of minor socket issues
Set timeout and socket options on all simple sockets.  At present
some code paths can miss it, such as when the SSL certificate is
CA-signed.

Add a missing check for failure.
2015-06-02 18:13:36 +09:00
ThomasV e4946cf26e setconfig: return False on error 2015-06-02 11:05:21 +02:00
ThomasV 31c4849566 url_rewrite 2015-06-02 10:41:36 +02:00
ThomasV b83b7fa5c8 cmd line: format payment requests 2015-06-02 10:25:39 +02:00
ThomasV 2727df962e requests: store path not url 2015-06-02 09:56:10 +02:00
ThomasV b9e4825422 fix request_dir variable 2015-06-02 09:37:54 +02:00
ThomasV 514ea6aa8c doc for addrequest 2015-06-02 09:31:24 +02:00
ThomasV d41785c783 save payment requests in requests_dir 2015-06-02 09:18:39 +02:00
Neil Booth d16714a1db Make the blockchain class not a thread
Remove interface communication out of blockchain.py
into network.py.  network.py handles protocol requests
for headers and chunks.  blockchain.py continues to
handle their analysis and verification.

If an interface provides a header chain that doesn't
connect, it is dismissed, as per a previous TODO comment.

This removes a thread and another source of timeouts.
I see no performance issues with this when truncating the
blockchain.

Rename 'result' to 'header' for clarity.
2015-06-01 20:53:42 +09:00
ThomasV 832369d7c4 Merge pull request #1270 from kyuupichan/if-tristate
Make interface status tri-state.
2015-06-01 13:09:40 +02:00
ThomasV 0938299e9b move payment requests logic to wallet, add basic commands 2015-06-01 13:02:09 +02:00
Neil Booth 76355e66c8 Make interface status tri-state.
This allows us to distinguish between connecting and connected
state in interface.py (used to be done in network.py but that
had other issues).

This means we don't switch to a connecting server, and get_interfaces()
does not report connecting ones.
2015-06-01 18:22:03 +09:00
Neil Booth 03e53a5e01 Create a constant for 100000000 and use it
Use same name as is in bitcoind.
Note that one of the constants in text.py had the wrong number
of zeroes previously...
2015-06-01 14:53:36 +09:00
ThomasV 4d9be9a6d2 commands: use decorator to register commands 2015-06-01 06:10:06 +02:00
ThomasV 7e20901e3b read command defaults 2015-06-01 00:17:50 +02:00
ThomasV c3f82fd69c fix cmd descriptions 2015-05-31 23:23:13 +02:00
ThomasV f8eb68458d use docstrings 2015-05-31 23:17:44 +02:00
ThomasV ddd6a58cc7 commands: extract params and options from arguments 2015-05-31 22:42:34 +02:00
ThomasV 1d5c6bdc2d deserialized option for mktx 2015-05-31 18:21:14 +02:00
ThomasV 4042ac69ec fix varname 2015-05-31 18:03:58 +02:00
ThomasV 9c76a0232e distinction between 'destination' and 'address' 2015-05-31 18:02:09 +02:00
ThomasV 200563c4e9 fix sweep fee 2015-05-31 17:49:59 +02:00
ThomasV c4d822b0cf add 'unsigned' option 2015-05-31 17:38:57 +02:00
ThomasV ee20910c65 fix signtransaction flags 2015-05-31 17:21:02 +02:00
ThomasV a3cd33fe03 add option to disable dnssec 2015-05-31 16:43:27 +02:00
ThomasV 9be94c74d2 add getalias command 2015-05-31 15:06:52 +02:00
ThomasV 8513dd2c63 fix cmd names 2015-05-31 15:00:56 +02:00
ThomasV c006678289 fix indent 2015-05-31 15:00:43 +02:00
ThomasV 5a76a0fc95 hook openalias plugin to command line interface 2015-05-31 14:42:16 +02:00
ThomasV ee5f499fc1 use contacts in command line 2015-05-31 14:10:52 +02:00
ThomasV 5cd3bfedb6 always pass coins to wallet.make_unsigned_transactions. fix \! shortcut in commands 2015-05-31 11:31:41 +02:00
ThomasV 0531f00c80 support for \! shortcut in command line 2015-05-31 10:40:12 +02:00
ThomasV 0caa29784c separate param_descriptions and improve help messages 2015-05-31 10:03:53 +02:00
ThomasV cc610d352f merge signtxwithwallet and signtxwithkey 2015-05-31 09:28:47 +02:00
ThomasV 1d5f04c588 fix function name 2015-05-31 08:49:47 +02:00
ThomasV 53a3f00389 add --deserialize option to gettransaction 2015-05-31 08:20:09 +02:00
ThomasV 9acc0e4ed0 minor formatting 2015-05-31 08:06:20 +02:00
ThomasV 2167b9e93d Merge pull request #1264 from kyuupichan/unify_interfaces
Remove pending_servers, self.interfaces is now the complete set of
2015-05-31 08:02:47 +02:00
ThomasV bd6bfcea0e Merge pull request #1267 from kyuupichan/spendable_coins
get_spendable_coins and frozen addrs
2015-05-31 07:53:43 +02:00
Neil Booth 320f9a3790 get_spendable_coins and frozen addrs
Two callers of get_spendable_coins were removing frozen addrs
before calling.  Put that functionality in the function.
We shouldn't be able to send_from a frozen address.  This was
possible in the current release because logic assumed a two-element
tuple was returned when it is now three-element.  Fix that too.

Command line options listunspent and createrawtransaction currently
ignore frozen addresses.  I'm not sure that's right but I've preserved
that behaviour.

With this patch only the wallet class refers to self.frozen_addresses;
other clients use is_frozen() now.
2015-05-31 14:07:50 +09:00
ThomasV 00ded10810 fix: freeze does not need password 2015-05-31 06:45:51 +02:00
Neil Booth 0f29984f07 Speed up freezing and unfreezing of many addresses
Speedup mainly from writing to storage only once.
Make frozen_addresses a set in memory, as sets give cleaner
code and are more efficient.

Minor change in behaviour: command line freezing used to return
False if the address isn't in the wallet OR the address was already
frozen.  Now it returns more like a success code: it returns False
only if the address isn't in the wallet regardless of frozen state.
Similarly for unfreezing.
2015-05-31 11:54:21 +09:00
ThomasV d6f4b57d64 help function for python console 2015-05-30 19:13:28 +02:00
ThomasV 92a158b910 proper handling of arg_types. add more options for listaddresses 2015-05-30 18:49:58 +02:00
ThomasV 2ab9272f52 fix positional arguments 2015-05-30 16:14:56 +02:00
ThomasV 966bb3c15f separate help and description for commands 2015-05-30 14:07:48 +02:00
ThomasV 0ad73b0899 better help 2015-05-30 13:38:05 +02:00
ThomasV d2f3e3f349 fix cmdline listcontacts 2015-05-30 12:35:58 +02:00
Neil Booth 2b66f0d459 Remove pending_servers, self.interfaces is now the complete set of
interfaces we have created.

Existing code has the concept of pending servers, where a connection
thread is started but has not sent a connection notification, and
and interfaces which have received the notification.

This separation caused a couple of minor bugs, and given the cleaner
semantics of unifying the two I don't think the separation is beneficial.
The bugs:

1) When stopping the network, we only stopped the connected interface
threads, not the pending ones.  This would leave Python hanging
on exit if we don't make them daemon threads.

2) start_interface() did not check pending servers before starting
a new thread.  Some of its callers did, but not all, so it was
possible to initiate two threads to one server and "lose" one thread.

Apart form fixing the above two issues, unification causes one more
change in semantics: we are now willing to switch to a connection
that is pending (we don't switch to failed interfaces). I don't
think that is a problem: if it times out we'll just switch
again when we receive the disconnect notification, and previously the
fact that an interface was in the interaces dictionary wasn't a
guarantee the connection was good anyway: we might not have processed
a pending disconnection notification.
2015-05-30 17:42:11 +09:00
Neil Booth 4eaff5678d Avoid change address reuse if possible
As discussed on #electrum yesterday.
Increase change gap limit to 6.
Choose the next unused change address, if any, otherwise pick
one at random from the gap limit.
2015-05-30 17:07:29 +09:00
ThomasV 48f98f75db improve help messages 2015-05-30 09:43:42 +02:00
ThomasV bf1aa6263c add description to command parameters 2015-05-30 09:36:54 +02:00
ThomasV 5dd535f915 move global options to parent, to avoid order-sensitive parsing 2015-05-30 07:58:47 +02:00
ThomasV 701527df20 fix -P option 2015-05-30 06:56:45 +02:00
ThomasV 6201133c48 fix #1263 2015-05-30 06:38:46 +02:00
ThomasV a0c7219db0 rm debugging print 2015-05-29 19:30:00 +02:00
ThomasV 2e67ca43e8 use csv instead of mkmanytx 2015-05-29 19:26:06 +02:00
ThomasV 3ddbbc1008 Parse arguments with argparse.
Move parser to commands.py
2015-05-29 19:24:50 +02:00
ThomasV 3195b94f28 Merge pull request #1257 from kyuupichan/update_fee
Fix calls to update_fee
2015-05-28 19:34:04 +02:00
ThomasV a3dd51f476 rm failing test 2015-05-28 15:43:50 +02:00
ThomasV 9dc8393cf6 move import test to wallet.py 2015-05-28 15:39:26 +02:00
ThomasV 3fdfd23ca9 add check in importprivkey 2015-05-28 15:27:22 +02:00
Neil Booth 05cb9975cb Fix calls to update_fee
Fees should be recalculated when send_from changes.
Fees should be recalculated when editing fee preference, but
only save to storage when leaving the fee per kb widget.
No need to emit a textEdited signal; the widget does that already
(with the effect that we used to call update_fee() twice).
2015-05-28 15:52:31 +09:00
ThomasV dd8493f97e make coin selection a bit faster 2015-05-27 11:07:57 +02:00
ThomasV 65e7dca3de Merge pull request #1249 from kyuupichan/stale_interfaces2
Common stale interface testing and switching
2015-05-27 10:42:59 +02:00
ThomasV 8e6e4f1b92 Merge pull request #1255 from kyuupichan/amountedit2
Fix nasty bug in amount editors
2015-05-27 10:19:07 +02:00
Neil Booth e5d243e08c Fix nasty bug in amount editors
str() can convert amounts to scientific notation
2015-05-27 17:14:40 +09:00
Neil Booth 45a8740755 Common stale interface testing and switching
Three places used to test for lagging and switch.  Commonize the
code.  We test for lagging before autoconnect so lagging
diagnostics are output if not auto-connect.

Lagging diagnotics moved to server_is_lagging().
2015-05-27 00:42:43 +09:00
ThomasV ae957f3736 make_transaction: remove unneeded inputs 2015-05-26 09:09:07 +02:00
ThomasV 7becb28ec8 Merge pull request #1246 from kyuupichan/bug_fix
e20dfc unintentionally inverted portable condition
2015-05-25 13:28:42 +02:00
Neil Booth e63ac88c77 e20dfc unintentionally inverted portable condition
This wasn't noticed because the test was also broken.
2015-05-25 16:59:16 +09:00
Neil Booth 39fe24b4d3 Rename auto_cycle to auto_connect in config
User config is updated if appropriate.
Add tests behaviour is as expected.
Just the one rename-it reference to auto_cycle remains.
2015-05-25 16:18:52 +09:00
ThomasV d5f6651237 follow up e20dfcd3eb 2015-05-25 08:47:25 +02:00
Neil Booth e20dfcd3eb Fix SimpleConfig
SimpleConfig claims to handle configuration options in priority
command line, user config, system config, which makes sense.
In fact it appears it used priority command line, system config,
user config.
Also, from the priority ordering, it would seem correct that a
value should be unmodifiable if and only if it's set on the command
line.  Previously anything in the system config would be unmodifiable.

This patch fixes these and cleans the code up a bit.  I noticed this
whilst attempting to unify the 'auto_cycle' setting.

Fixup tests accordingly.
2015-05-25 15:16:19 +09:00
Neil Booth 4f6d2f3d32 Put getting of auto_cycle into one place.
Default to False consistently; this may change the behaviour of
network.py's get_parameters().
2015-05-25 14:09:43 +09:00
ThomasV 778297697a lazy plugin constructor 2015-05-24 20:37:05 +02:00
ThomasV 71046371ec Merge pull request #1242 from kyuupichan/pick_random_server
Clean up pick_random_server() and filter_protocol() and their
2015-05-24 16:43:17 +02:00
ThomasV 117b809bab fix issue #1238 2015-05-24 16:14:56 +02:00
Neil Booth 01d8f79a75 Clean up pick_random_server() and filter_protocol() and their
call sites.

Remove unused imports and redundant random pick of server
2015-05-24 21:07:35 +09:00
ThomasV 48ad7c36a8 show plugin dependencies 2015-05-24 10:06:53 +02:00
ThomasV d40c12c949 check gui when loading plugins 2015-05-24 09:26:28 +02:00
Neil Booth 89c1a1a0ab Improve logic in network.py's set_parameters()
1) For new proxy or protocol, restart the network and default to
   the requested server.
2) Otherwise if we aren't using the requested server, switch to it
3) Otherwise choose a random server if the requested server is
   stale and auto_connect is True

As switch_to_interface() now has another user, move the logic
there whereby we close the old interface in order to terminate
subscriptions, in order to have it in one place.
2015-05-23 23:33:17 +09:00
ThomasV 8f98ea4aca make plugins available without the GUI 2015-05-23 10:38:19 +02:00
ThomasV 89c277de9d fix pruning error in #1223 2015-05-23 08:45:27 +02:00
ThomasV 0fbbeb16be Merge pull request #1232 from kyuupichan/switch-or-start
switch_to_interface() to start interface if not connected
2015-05-23 07:30:00 +02:00
ThomasV 4aaa9e24f2 Merge pull request #1234 from kyuupichan/storage-tmpfile
Prevent race with two electrum instances on same wallet.
2015-05-23 07:22:12 +02:00
Neil Booth 77490e4764 Flush wallet storage once for a sequence of puts.
This speeds up save_transactions by 2 to 3 times for me.
2015-05-23 10:52:10 +09:00
Neil Booth 33a8348d48 Prevent race with two electrum instances on same wallet.
Whilst it's not a good idea to have two electrum instances
open on the same wallet, we should avoid throwing an
exception.  Also note how the old code's handling of the
exception (caused by both renaming the file almost at the
same time, rather than a non-POSIX system not supporting
the atomic rename) can lead to the wallet file being lost
enirely because os.remove(self.path) succeeds and the
rename of the temporary no-longer-existing file then fails.
2015-05-23 10:24:10 +09:00
ThomasV b029589fc1 fix issue #1233 2015-05-22 20:47:51 +02:00
Neil Booth 2f34f3db21 Only start if not already in pending_servers
This was only in one call site previously, not both.
2015-05-22 16:29:56 +09:00
Neil Booth 31ffd4b381 switch_to_interface() to start interface if not connected
Two places currently have switch-to-or-start-interface logic.
Put that common logic into switch_to_interface().
2015-05-22 16:24:58 +09:00
Neil Booth 346e38674b Absorb add_interface and remove_interface
They are now only called from the same place; it's simpler
and clearer to put them inline.
2015-05-22 15:26:17 +09:00
ThomasV 0b201d98ab Merge pull request #1230 from kyuupichan/switch-random-if
Remove interfaces in one place only
2015-05-22 08:13:14 +02:00
ThomasV e13e42a00c Merge pull request #1229 from kyuupichan/uri-format
Plain number formatting for URIs.
2015-05-22 08:12:09 +02:00
Neil Booth 274965468e Remove interfaces in one place only
switch_to_random_interface used to do is_connected()
checks and remove interfaces when switching.  This
is redundant: interfaces are only added to self.interfaces
once in is_connected() state from process_if_notification().
When they are disconnected, a notification is also received
and process_if_notification() performs the removal.  Furthermore,
two other callers of switch_to_interface do not do explicit
is_connected() checks before calling it.
2015-05-22 15:01:11 +09:00
Neil Booth d09d5e5dac Plain number formatting for URIs. 2015-05-22 14:32:47 +09:00
Neil Booth 4873c455b9 Add documentation string. Fix uninitialized f error.
Traceback (most recent call last):
      File "src/electrum/lib/network.py", line 411, in process_request
        out['result'] = f(*params)
    UnboundLocalError: local variable 'f' referenced before assignment
    [Network] network error local variable 'f' referenced before assignment
2015-05-22 14:14:06 +09:00
Neil Booth 05dd310431 Set 'connecting' status in one place.
Also means when switching to an already connected server our
status doesn't quickly change to connecting and back again.
2015-05-22 14:05:58 +09:00
Neil Booth 86626d8080 Consistency in handling of self.interface
switch_to_interface() becomes the common place where
self.interface is set; therefore self.interface is not None
precisely when self.default_server is connected.  Previously some
places required it to be connected and some didn't.  Also an
interface change now sends the 'updated' notification
consistently - previously some did and some didn't.

Have network_start() call start_interfaces() - this also means
network restarts now do this.

Fix apparent off-by-one in start_interfaces()
2015-05-22 09:13:09 +09:00
Neil Booth c918e74039 Put common network start and stop code in one place.
Prefer to use safer self.is_connected() as it checks interface
is not None.

Using common code gives small observable changes in behaviour:

 - slightly different print_error() messages
 - network restarts now enter status 'connecting' which they
   didn't before, which seems correct
 - status 'connecting' is done with set_status() rather than
   simply assigning the status, which seems more correct.  Now
   that the response_queue is available in the constructor this
   works; it used to fail with 'response_queue is not defined'
2015-05-22 07:52:59 +09:00
ThomasV 8620019f92 Merge pull request #1222 from kyuupichan/if_notification
Put interface notification handling in its own function.
2015-05-21 15:05:07 +02:00
ThomasV 5bd22d2378 follow-up to bd781d600b8ce2bc9dcebebbdb0fb60ad2fb892e: use pipe 2015-05-21 12:50:26 +02:00
Neil Booth c9a30eb5f2 Put interface notification handling in its own function. 2015-05-21 17:45:37 +09:00
Neil Booth bd781d600b Have queues passed to the network constructor.
This is somewhat cleaner as the proxy's pipe and network setup
was awkwardly interleaved.  It also means network's constructor
is free to use both; currently some code is working around the
fact that the response queue doesn't exist in the constructor.
2015-05-21 12:49:39 +09:00
ThomasV 7b27f01e07 call fsync before rename 2015-05-19 11:56:33 +02:00
ThomasV 5c73bc5bc7 interface: init ping_time with 0 so that the client sends version message 2015-05-19 11:28:30 +02:00
ThomasV 2104e96a66 network: use get_nowait on one of the two queues 2015-05-19 10:22:25 +02:00
Neil Booth 63733ccd2a No need for thread to handle requests
Handle requests in the main loop.
Remove unused lock.
interface.py was reworked and send_request() no longer throws.
2015-05-19 14:29:10 +09:00
ThomasV a0e9046c2c prepare for 2.2 release 2015-05-17 09:17:52 +02:00
ThomasV e33bc2473b network: don't store unanswered request if result is in cache 2015-05-17 09:00:36 +02:00
ThomasV 6d0bc5d9b3 fix: nodes retry 2015-05-17 08:41:01 +02:00
ThomasV 44f06de796 network: when interface is disconnected, clear cache and resend unanswered requests 2015-05-15 14:47:59 +02:00
mikeland86 0ec62c8f36 Fix createrawtransaction and missing deserialize()
Found these issues while trying to create, sign, and broadcast a raw transaction. 

* createrawtransaction was using old signature for Transaction constructor
* Signwithwallet and decoderawtransaction need to call deserialize on tx before they can access inputs and outputs. (Maybe adding getInputs() and getOutputs() which deserializes if needed might be nicer)
2015-05-13 14:57:34 +02:00
ThomasV 5fa2a48343 add getmerkle command 2015-05-12 12:30:26 +02:00
ThomasV 81be685644 remove tests broken after WalletStorage update 2015-05-11 11:59:39 +02:00
ThomasV 7e9153aaa4 test if labels exist before loop. don't raise if a label cannot be converted 2015-05-11 11:55:26 +02:00
Azelphur fe5be618db Convert old latin1 labels, Raise exception if json conversion fails.
A couple of changes
1) Old electrum wallets seemed to save labels in latin1, when you call json.dumps on line 83/84 it fails silently, which causes the label import to fail. Whenever electrum saves, it then overwrites your default wallet with no labels - essentially deleting all your labels. The solution to this is iterating over all the labels for old wallets decoding anything that fails to unicode() as latin1, and then unicoding it :)

2) Failing to import data and then deleting it is bad. So I'm raising an exception to avoid data being lost.
2015-05-10 20:28:42 +01:00
ThomasV 59a9e4f710 fix new_wallet and seed language 2015-05-10 08:31:31 +02:00
ThomasV a1d1999545 move interfaces maintenance to its own function 2015-05-08 20:13:18 +02:00
ThomasV f2c2f9d738 network: fix confusion between addresses and cached responses 2015-05-08 17:59:33 +02:00
ThomasV 2a92a310ba typo 2015-05-08 17:47:04 +02:00
ThomasV 8c07bdc3bc do not timeout if interface is receiving data 2015-05-08 17:45:59 +02:00
ThomasV 233fd8ed77 revert 175bfae9e6. store last known height in wallet instead 2015-05-08 13:43:42 +02:00
ThomasV 1d517abf39 restore network_proxy.get_local_height 2015-05-08 11:12:19 +02:00
ThomasV c2a4252065 do not pass config to storage. request height from network_proxy if connected 2015-05-08 10:58:54 +02:00
Neil Booth 13b9b577a4 Don't use self.network to get the local height.
This restores a working offline mode.
2015-05-08 14:45:23 +09:00