Bitcoin Forum

Bitcoin => Electrum => Topic started by: flatfly on January 19, 2014, 12:56:43 PM



Title: Electrum console scripts - Script #2: List balances
Post by: flatfly on January 19, 2014, 12:56:43 PM
Here's a quick little script to find out what servers have lowest latency for you.

For instance, for users in Europe, the top 2 servers consistently are:

0.015s   electrum.icetwy.re                
0.016s   electrum.cafebitcoin.com
       


Code:
'''
 *   Python 2.x source - By flatfly (GPG ID: 0xF91975FF)
 *
 *   No warranty, explicit or implicit, provided.
'''

import socket, time

best = 5      
ax = getservers().keys()
print 'quicktesting ' + str(len(ax)) + ' servers...'
print '\n\n'
    
for host in ax:

  try:
    s=socket.socket()
    s.settimeout(1)
    t0 = time.time()
    s.connect((host, 50002))
    t1 = time.time()
    delta = t1-t0
    print host.ljust(35) + '{:6.3f}s'.format(delta)
    if delta < best:  
      best = delta
      best_host = host
    s.close()  
  except:
    pass  

print '\n'
print 'lowest latency: '
print best_host.ljust(35) + '{:6.3f}s'.format(best)


Title: Re: Electrum scripts - Script #1: Fastest servers
Post by: doolittle on January 20, 2014, 09:58:40 AM
I am not a python or electrum expert. So to me this script is not easy at all. :(
Can you explain a couple of things? For example:
  • getservers: it is a console-command. getservers(). How can you add another function to it?
  • Keys() is not a console function. Where does it come from?
  • Where are time and socket imported from? Are these standard libraries? Is it possible to add new packages to the standard embedded electrum python interpreter?

As a sidenote: How many servers are there in Europe? Who are the guys running them?


Title: Re: Electrum scripts - Script #1: Fastest servers
Post by: flatfly on January 20, 2014, 06:23:56 PM
I am not a python or electrum expert. So to me this script is not easy at all. :(
Can you explain a couple of things? For example:
  • getservers: it is a console-command. getservers(). How can you add another function to it?
  • Keys() is not a console function. Where does it come from?
  • Where are time and socket imported from? Are these standard libraries? Is it possible to add new packages to the standard embedded electrum python interpreter?

As a sidenote: How many servers are there in Europe? Who are the guys running them?

In a nutshell:
 - the getservers() function returns a dict. keys() is a standard dict method.
 - yes, time and socket are standard libraries.

Sorry for not going into more detail - I have very limited free time these days.
Feel free to google for more information, or wait for others to chime in with more help.


Title: Re: Electrum console scripts - Script #1: Fastest servers
Post by: Abdussamad on January 22, 2014, 04:06:20 AM
Nice! Gotta learn python.


Title: Re: Electrum console scripts - Script #1: Fastest servers
Post by: doolittle on January 22, 2014, 05:23:46 AM
Yes indeed :)


Title: Re: Electrum console scripts - Script #2: List balances
Post by: flatfly on March 17, 2014, 09:55:13 AM
A little one-liner to list your addresses and their balances:

Code:
for x in listaddresses(): print x + '\t' + str(getaddressbalance(x))

Note: Uses the new getaddressbalance feature added in 1.9.8


Title: Re: Electrum console scripts - Script #2: List balances
Post by: RangerK on February 18, 2015, 10:41:57 PM
I would be deeply grateful if someone would offer me a python script for my situation:

I have an electrum wallet with balances on three different private keys.

I'd like to take the balance from just one private key and send it elsewhere.  This is made easier, perhaps, because that entire balance arrived in just one transaction.

Please help?

If it works, I'll offer a small token of gratitude -- 0.02 btc.


Title: Re: Electrum console scripts - Script #2: List balances
Post by: RangerK on February 19, 2015, 07:19:31 AM
I would be deeply grateful if someone would offer me a python script for my situation:

I have an electrum wallet with balances on three different private keys.

I'd like to take the balance from just one private key and send it elsewhere.  This is made easier, perhaps, because that entire balance arrived in just one transaction.

Please help?

If it works, I'll offer a small token of gratitude -- 0.02 btc.
I don't have a python script for that, but there is an easy way to achieve what you want with the Electrum Client.

In your Receive tab, locate the addresses that you don't want to send bitcoins from.  Right-click on each address and select Freeze.  Leaving only the one you want to send from, in the "unfrozen" state.  Send you transaction, like normal.  Electrum will only take from the unfrozen address(es).  If you don't spend all the content of the address, it will return you some change in a new address.  Ensure that you deduct the network transaction fees correctly before sending.  The number should turn red if the total exceed the amount in your address (not enough funds).

When you are done - unfreeze the other addresses.  8)

1AQjoN1Z9JepYUL6XYaTAHtHwPjR8rsiH2
 

Thank you, sir!  Worked like a charm.  What a cool little feature.

Your gratuity has been sent.  I'm also going to PM you a few coupons for block777.com.