electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit ed256e064a89df23c9455daae7c83150ac824b12
parent 4d9be9a6d2920d660779a30aad1f9f4b4b100e1a
Author: ThomasV <electrumdev@gmail.com>
Date:   Mon,  1 Jun 2015 09:36:48 +0200

Merge pull request #1269 from kyuupichan/COIN

Create a constant for 100000000 and use it
Diffstat:
Mgui/android.py | 14+++++++-------
Mgui/gtk.py | 14+++++++-------
Mgui/qt/lite_window.py | 2+-
Mgui/qt/main_window.py | 4++--
Mgui/stdio.py | 12++++++------
Mgui/text.py | 15+++++++--------
Mlib/bitcoin.py | 1+
Mlib/commands.py | 22+++++++++++-----------
Mlib/util.py | 2+-
Mplugins/exchange_rate.py | 15++++++++-------
10 files changed, 51 insertions(+), 50 deletions(-)

diff --git a/gui/android.py b/gui/android.py @@ -23,7 +23,7 @@ from __future__ import absolute_import import android from electrum import SimpleConfig, Wallet, WalletStorage, format_satoshis -from electrum.bitcoin import is_address +from electrum.bitcoin import is_address, COIN from electrum import util from decimal import Decimal import datetime, re @@ -585,7 +585,7 @@ def payto_loop(): continue try: - amount = int( 100000000 * Decimal(amount) ) + amount = int(COIN * Decimal(amount)) except Exception: modal_dialog('Error','Invalid amount') continue @@ -608,7 +608,7 @@ def payto_loop(): if re.match('^bitcoin:', data): payto, amount, label, message, _ = util.parse_URI(data) if amount: - amount = str(amount/100000000) + amount = str(amount / COIN) droid.fullSetProperty("recipient", "text", payto) droid.fullSetProperty("amount", "text", amount) droid.fullSetProperty("message", "text", message) @@ -662,7 +662,7 @@ def receive_loop(): elif event["name"]=="amount": amount = modal_input('Amount', 'Amount you want to receive (in BTC). ', format_satoshis(receive_amount) if receive_amount else None, "numberDecimal") if amount is not None: - receive_amount = int(100000000 * Decimal(amount)) if amount else None + receive_amount = int(COIN * Decimal(amount)) if amount else None out = 'receive' elif event["name"]=="message": @@ -770,7 +770,7 @@ def settings_loop(): def set_listview(): host, port, p, proxy_config, auto_connect = network.get_parameters() - fee = str( Decimal( wallet.fee_per_kb)/100000000 ) + fee = str(Decimal(wallet.fee_per_kb) / COIN) is_encrypted = 'yes' if wallet.use_encryption else 'no' protocol = protocol_name(p) droid.fullShow(settings_layout) @@ -818,10 +818,10 @@ def settings_loop(): elif pos == "3": #fee fee = modal_input('Transaction fee', 'The fee will be this amount multiplied by the number of inputs in your transaction. ', - str(Decimal(wallet.fee_per_kb)/100000000 ), "numberDecimal") + str(Decimal(wallet.fee_per_kb) / COIN), "numberDecimal") if fee: try: - fee = int( 100000000 * Decimal(fee) ) + fee = int(COIN * Decimal(fee)) except Exception: modal_dialog('error','invalid fee value') wallet.set_fee(fee) diff --git a/gui/gtk.py b/gui/gtk.py @@ -25,7 +25,7 @@ gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk, GObject, cairo from decimal import Decimal from electrum.util import print_error, InvalidPassword -from electrum.bitcoin import is_valid +from electrum.bitcoin import is_valid, COIN from electrum.wallet import NotEnoughFunds from electrum import WalletStorage, Wallet @@ -48,7 +48,7 @@ def numbify(entry, is_int = False): s = s.replace('.','') s = s[:p] + '.' + s[p:p+8] try: - amount = int( Decimal(s) * 100000000 ) + amount = int(Decimal(s) * COIN) except Exception: amount = None else: @@ -164,7 +164,7 @@ def run_settings_dialog(self): fee_label.set_size_request(150,10) fee_label.show() fee.pack_start(fee_label,False, False, 10) - fee_entry.set_text( str( Decimal(self.wallet.fee_per_kb) /100000000 ) ) + fee_entry.set_text(str(Decimal(self.wallet.fee_per_kb) / COIN)) fee_entry.connect('changed', numbify, False) fee_entry.show() fee.pack_start(fee_entry,False,False, 10) @@ -196,7 +196,7 @@ def run_settings_dialog(self): return try: - fee = int( 100000000 * Decimal(fee) ) + fee = int(COIN * Decimal(fee)) except Exception: show_message("error") return @@ -698,7 +698,7 @@ class ElectrumWindow: if not self.funds_error: if not is_fee: fee = tx.get_fee() - fee_entry.set_text( str( Decimal( fee ) / 100000000 ) ) + fee_entry.set_text(str(Decimal(fee) / COIN)) self.fee_box.show() amount_entry.modify_text(Gtk.StateType.NORMAL, Gdk.color_parse("#000000")) fee_entry.modify_text(Gtk.StateType.NORMAL, Gdk.color_parse("#000000")) @@ -791,12 +791,12 @@ class ElectrumWindow: return try: - amount = int( Decimal(amount_entry.get_text()) * 100000000 ) + amount = int(Decimal(amount_entry.get_text()) * COIN) except Exception: self.show_message( "invalid amount") return try: - fee = int( Decimal(fee_entry.get_text()) * 100000000 ) + fee = int(Decimal(fee_entry.get_text()) * COIN) except Exception: self.show_message( "invalid fee") return diff --git a/gui/qt/lite_window.py b/gui/qt/lite_window.py @@ -36,7 +36,7 @@ import shutil from util import * -bitcoin = lambda v: v * 100000000 +bitcoin = lambda v: v * COIN def IconButton(filename, parent=None): pixmap = QPixmap(filename) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -30,7 +30,7 @@ from PyQt4.QtGui import * from PyQt4.QtCore import * import PyQt4.QtCore as QtCore -from electrum.bitcoin import MIN_RELAY_TX_FEE, is_valid +from electrum.bitcoin import MIN_RELAY_TX_FEE, COIN, is_valid from electrum.plugins import run_hook import icons_rc @@ -1092,7 +1092,7 @@ class ElectrumWindow(QMainWindow): return amount = sum(map(lambda x:x[2], outputs)) - confirm_amount = self.config.get('confirm_amount', 100000000) + confirm_amount = self.config.get('confirm_amount', COIN) if amount >= confirm_amount: o = '\n'.join(map(lambda x:x[1], outputs)) if not self.question(_("send %(amount)s to %(address)s?")%{ 'amount' : self.format_amount(amount) + ' '+ self.base_unit(), 'address' : o}): diff --git a/gui/stdio.py b/gui/stdio.py @@ -3,7 +3,7 @@ _ = lambda x:x #from i18n import _ from electrum.wallet import WalletStorage, Wallet from electrum.util import format_satoshis, set_verbosity, StoreDict -from electrum.bitcoin import is_valid +from electrum.bitcoin import is_valid, COIN from electrum.network import filter_protocol import sys, getpass, datetime @@ -125,11 +125,11 @@ class ElectrumGui: msg = _( "Synchronizing..." ) else: c, u, x = self.wallet.get_balance() - msg = _("Balance")+": %f "%(Decimal(c) / 100000000) + msg = _("Balance")+": %f "%(Decimal(c) / COIN) if u: - msg += " [%f unconfirmed]"%(Decimal(u) / 100000000) + msg += " [%f unconfirmed]"%(Decimal(u) / COIN) if x: - msg += " [%f unmatured]"%(Decimal(x) / 100000000) + msg += " [%f unmatured]"%(Decimal(x) / COIN) else: msg = _( "Not connected" ) @@ -178,12 +178,12 @@ class ElectrumGui: print(_('Invalid Bitcoin address')) return try: - amount = int( Decimal( self.str_amount) * 100000000 ) + amount = int(Decimal(self.str_amount) * COIN) except Exception: print(_('Invalid Amount')) return try: - fee = int( Decimal( self.str_fee) * 100000000 ) + fee = int(Decimal(self.str_fee) * COIN) except Exception: print(_('Invalid Fee')) return diff --git a/gui/text.py b/gui/text.py @@ -1,10 +1,9 @@ import curses, datetime, locale from decimal import Decimal _ = lambda x:x -#from i18n import _ from electrum.util import format_satoshis, set_verbosity from electrum.util import StoreDict -from electrum.bitcoin import is_valid +from electrum.bitcoin import is_valid, COIN from electrum import Wallet, WalletStorage @@ -133,11 +132,11 @@ class ElectrumGui: msg = _("Synchronizing...") else: c, u, x = self.wallet.get_balance() - msg = _("Balance")+": %f "%(Decimal(c) / 100000000) + msg = _("Balance")+": %f "%(Decimal(c) / COIN) if u: - msg += " [%f unconfirmed]"%(Decimal(u) / 100000000) + msg += " [%f unconfirmed]"%(Decimal(u) / COIN) if x: - msg += " [%f unmatured]"%(Decimal(x) / 100000000) + msg += " [%f unmatured]"%(Decimal(x) / COIN) else: msg = _("Not connected") @@ -297,12 +296,12 @@ class ElectrumGui: self.show_message(_('Invalid Bitcoin address')) return try: - amount = int( Decimal( self.str_amount) * 100000000 ) + amount = int(Decimal(self.str_amount) * COIN) except Exception: self.show_message(_('Invalid Amount')) return try: - fee = int( Decimal( self.str_fee) * 100000000 ) + fee = int(Decimal(self.str_fee) * COIN) except Exception: self.show_message(_('Invalid Fee')) return @@ -388,7 +387,7 @@ class ElectrumGui: if out.get('Default GUI'): self.config.set_key('gui', out['Default GUI'], True) if out.get('Default fee'): - fee = int ( Decimal( out['Default fee']) *10000000 ) + fee = int(Decimal(out['Default fee']) * COIN) self.config.set_key('fee_per_kb', fee, True) diff --git a/lib/bitcoin.py b/lib/bitcoin.py @@ -35,6 +35,7 @@ DUST_THRESHOLD = 546 MIN_RELAY_TX_FEE = 1000 RECOMMENDED_FEE = 50000 COINBASE_MATURITY = 100 +COIN = 100000000 # AES encryption EncodeAES = lambda secret, s: base64.b64encode(aes.encryptData(secret,s)) diff --git a/lib/commands.py b/lib/commands.py @@ -29,7 +29,7 @@ from decimal import Decimal import util from util import print_msg, format_satoshis, print_stderr import bitcoin -from bitcoin import is_address, hash_160_to_bc_address, hash_160 +from bitcoin import is_address, hash_160_to_bc_address, hash_160, COIN from transaction import Transaction @@ -148,7 +148,7 @@ class Commands: def listunspent(self): """List unspent outputs. Returns the list of unspent transaction outputs in your wallet.""" l = copy.deepcopy(self.wallet.get_spendable_coins(exclude_frozen = False)) - for i in l: i["value"] = str(Decimal(i["value"])/100000000) + for i in l: i["value"] = str(Decimal(i["value"])/COIN) return l @command('n') @@ -178,7 +178,7 @@ class Commands: break else: raise BaseException('Transaction output not in wallet', prevout_hash+":%d"%prevout_n) - outputs = map(lambda x: ('address', x[0], int(1e8*x[1])), outputs.items()) + outputs = map(lambda x: ('address', x[0], int(COIN*x[1])), outputs.items()) tx = Transaction.from_io(tx_inputs, outputs) if not unsigned: self.wallet.sign_transaction(tx, self.password) @@ -260,19 +260,19 @@ class Commands: c, u, x = self.wallet.get_balance() else: c, u, x = self.wallet.get_account_balance(account) - out = {"confirmed": str(Decimal(c)/100000000)} + out = {"confirmed": str(Decimal(c)/COIN)} if u: - out["unconfirmed"] = str(Decimal(u)/100000000) + out["unconfirmed"] = str(Decimal(u)/COIN) if x: - out["unmatured"] = str(Decimal(x)/100000000) + out["unmatured"] = str(Decimal(x)/COIN) return out @command('n') def getaddressbalance(self, address): """Return the balance of an address""" out = self.network.synchronous_get([('blockchain.address.get_balance', [address])])[0] - out["confirmed"] = str(Decimal(out["confirmed"])/100000000) - out["unconfirmed"] = str(Decimal(out["unconfirmed"])/100000000) + out["confirmed"] = str(Decimal(out["confirmed"])/COIN) + out["unconfirmed"] = str(Decimal(out["unconfirmed"])/COIN) return out @command('n') @@ -332,7 +332,7 @@ class Commands: dest = resolver(destination) if tx_fee is None: tx_fee = 0.0001 - fee = int(Decimal(tx_fee)*100000000) + fee = int(Decimal(tx_fee)*COIN) return Transaction.sweep([privkey], self.network, dest, fee) @command('wp') @@ -350,7 +350,7 @@ class Commands: resolver = lambda x: None if x is None else self.contacts.resolve(x, nocheck)['address'] change_addr = resolver(change_addr) domain = None if domain is None else map(resolver, domain) - fee = None if fee is None else int(100000000*Decimal(fee)) + fee = None if fee is None else int(COIN*Decimal(fee)) final_outputs = [] for address, amount in outputs: address = resolver(address) @@ -367,7 +367,7 @@ class Commands: fee = self.wallet.estimated_fee(dummy_tx) amount -= fee else: - amount = int(100000000*Decimal(amount)) + amount = int(COIN*Decimal(amount)) final_outputs.append(('address', address, amount)) coins = self.wallet.get_spendable_coins(domain) diff --git a/lib/util.py b/lib/util.py @@ -254,7 +254,7 @@ def parse_URI(uri): k = int(m.group(2)) - 8 amount = Decimal(m.group(1)) * pow( Decimal(10) , k) else: - amount = Decimal(am) * 100000000 + amount = Decimal(am) * COIN if 'message' in pq: message = pq['message'][0].decode('utf8') if 'label' in pq: diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py @@ -11,6 +11,7 @@ import re from ssl import SSLError from decimal import Decimal +from electrum.bitcoin import COIN from electrum.plugins import BasePlugin, hook from electrum.i18n import _ from electrum_gui.qt.util import * @@ -220,7 +221,7 @@ class Plugin(BasePlugin): @hook def get_fiat_balance_text(self, btc_balance, r): # return balance as: 1.23 USD - r[0] = self.create_fiat_balance_text(Decimal(btc_balance) / 100000000) + r[0] = self.create_fiat_balance_text(Decimal(btc_balance) / COIN) def get_fiat_price_text(self, r): # return BTC price as: 123.45 USD @@ -240,7 +241,7 @@ class Plugin(BasePlugin): price_text = "1 BTC~%s"%quote fiat_currency = quote[-3:] btc_price = self.btc_rate - fiat_balance = Decimal(btc_price) * (Decimal(btc_balance)/100000000) + fiat_balance = Decimal(btc_price) * Decimal(btc_balance) / COIN balance_text = "(%.2f %s)" % (fiat_balance,fiat_currency) text = " " + balance_text + " " + price_text + " " r2[0] = text @@ -338,20 +339,20 @@ class Plugin(BasePlugin): tx_info = {'timestamp':int(time.time()), 'value': v} pass tx_time = int(tx_info['timestamp']) - tx_value = Decimal(str(tx_info['value'])) / 100000000 + tx_value = Decimal(str(tx_info['value'])) / COIN if self.cur_exchange == "CoinDesk": tx_time_str = datetime.datetime.fromtimestamp(tx_time).strftime('%Y-%m-%d') try: tx_fiat_val = "%.2f %s" % (tx_value * Decimal(self.resp_hist['bpi'][tx_time_str]), "USD") except KeyError: - tx_fiat_val = "%.2f %s" % (self.btc_rate * Decimal(str(tx_info['value']))/100000000 , "USD") + tx_fiat_val = "%.2f %s" % (self.btc_rate * Decimal(str(tx_info['value']))/COIN , "USD") elif self.cur_exchange == "Winkdex": tx_time_str = datetime.datetime.fromtimestamp(tx_time).strftime('%Y-%m-%d') + "T16:00:00-04:00" try: tx_rate = self.resp_hist[[x['timestamp'] for x in self.resp_hist].index(tx_time_str)]['price'] tx_fiat_val = "%.2f %s" % (tx_value * Decimal(tx_rate)/Decimal("100.0"), "USD") except ValueError: - tx_fiat_val = "%.2f %s" % (self.btc_rate * Decimal(tx_info['value'])/100000000 , "USD") + tx_fiat_val = "%.2f %s" % (self.btc_rate * Decimal(tx_info['value'])/COIN , "USD") except KeyError: tx_fiat_val = _("No data") elif self.cur_exchange == "BitcoinVenezuela": @@ -520,7 +521,7 @@ class Plugin(BasePlugin): exchange_rate = self.exchanger.exchange(Decimal("1.0"), self.fiat_unit()) if exchange_rate is not None: btc_amount = fiat_amount/exchange_rate - btc_e.setAmount(int(btc_amount*Decimal(100000000))) + btc_e.setAmount(int(btc_amount*Decimal(COIN))) if fee_e: self.win.update_fee(False) fiat_e.textEdited.connect(fiat_changed) def btc_changed(): @@ -530,7 +531,7 @@ class Plugin(BasePlugin): if btc_amount is None: fiat_e.setText("") return - fiat_amount = self.exchanger.exchange(Decimal(btc_amount)/Decimal(100000000), self.fiat_unit()) + fiat_amount = self.exchanger.exchange(Decimal(btc_amount)/Decimal(COIN), self.fiat_unit()) if fiat_amount is not None: pos = fiat_e.cursorPosition() fiat_e.setText("%.2f"%fiat_amount)