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