use decimal instead of float
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import sys, base64, os, re, hashlib, socket, getpass, copy, operator, ast
|
import sys, base64, os, re, hashlib, socket, getpass, copy, operator, ast
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ecdsa
|
import ecdsa
|
||||||
@@ -383,7 +384,9 @@ class Wallet:
|
|||||||
self.change_addresses, self.status, self.history,
|
self.change_addresses, self.status, self.history,
|
||||||
self.labels, self.addressbook) = sequence
|
self.labels, self.addressbook) = sequence
|
||||||
except:
|
except:
|
||||||
raise BaseException("version error.")
|
# it is safer to exit immediately
|
||||||
|
print "Error; could not parse wallet."
|
||||||
|
exit(1)
|
||||||
if self.version != WALLET_VERSION:
|
if self.version != WALLET_VERSION:
|
||||||
raise BaseException("Wallet version error.\nPlease move your balance to a new wallet.\nSee the release notes for more informations.")
|
raise BaseException("Wallet version error.\nPlease move your balance to a new wallet.\nSee the release notes for more informations.")
|
||||||
self.update_tx_history()
|
self.update_tx_history()
|
||||||
@@ -490,8 +493,6 @@ class Wallet:
|
|||||||
def choose_inputs_outputs( self, to_addr, amount, fee, password):
|
def choose_inputs_outputs( self, to_addr, amount, fee, password):
|
||||||
""" todo: minimize tx size """
|
""" todo: minimize tx size """
|
||||||
|
|
||||||
amount = int( 1e8*amount )
|
|
||||||
fee = int( 1e8*fee )
|
|
||||||
total = 0
|
total = 0
|
||||||
inputs = []
|
inputs = []
|
||||||
for addr in self.addresses:
|
for addr in self.addresses:
|
||||||
@@ -609,7 +610,7 @@ class Wallet:
|
|||||||
def mktx(self, to_address, amount, label, password, fee=None):
|
def mktx(self, to_address, amount, label, password, fee=None):
|
||||||
if not self.is_valid(to_address):
|
if not self.is_valid(to_address):
|
||||||
return False, "Invalid address"
|
return False, "Invalid address"
|
||||||
if fee is None: fee = self.fee
|
if fee is None: fee = int( self.fee )
|
||||||
try:
|
try:
|
||||||
inputs, outputs = wallet.choose_inputs_outputs( to_address, amount, fee, password )
|
inputs, outputs = wallet.choose_inputs_outputs( to_address, amount, fee, password )
|
||||||
if not inputs:
|
if not inputs:
|
||||||
@@ -720,9 +721,9 @@ if __name__ == '__main__':
|
|||||||
if cmd in ['payto', 'mktx']:
|
if cmd in ['payto', 'mktx']:
|
||||||
try:
|
try:
|
||||||
to_address = args[1]
|
to_address = args[1]
|
||||||
amount = float(args[2])
|
amount = int( 100000000 * Decimal(args[2]) )
|
||||||
label = ' '.join(args[3:])
|
label = ' '.join(args[3:])
|
||||||
if options.tx_fee: options.tx_fee = float(options.tx_fee)
|
if options.tx_fee: options.tx_fee = int( 100000000 * Decimal(options.tx_fee) )
|
||||||
except:
|
except:
|
||||||
firstarg = cmd
|
firstarg = cmd
|
||||||
cmd = 'help'
|
cmd = 'help'
|
||||||
|
|||||||
@@ -23,14 +23,17 @@ import pygtk
|
|||||||
pygtk.require('2.0')
|
pygtk.require('2.0')
|
||||||
import gtk, gobject
|
import gtk, gobject
|
||||||
import pyqrnative
|
import pyqrnative
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
gtk.gdk.threads_init()
|
gtk.gdk.threads_init()
|
||||||
APP_NAME = "Electrum"
|
APP_NAME = "Electrum"
|
||||||
|
|
||||||
def format_satoshis(x):
|
def format_satoshis(x):
|
||||||
xx = ("%f"%(x*1e-8)).rstrip('0')
|
xx = str( Decimal(x) /100000000 )
|
||||||
if xx[-1] =='.': xx+="00"
|
#xx = ("%f"%(x*1e-8)).rstrip('0')
|
||||||
if xx[-2] =='.': xx+="0"
|
if not '.' in xx: xx = xx + '.'
|
||||||
|
if len(xx) > 0 and xx[-1] =='.': xx+="00"
|
||||||
|
if len(xx) > 1 and xx[-2] =='.': xx+="0"
|
||||||
return xx
|
return xx
|
||||||
|
|
||||||
def numbify(entry, is_int = False):
|
def numbify(entry, is_int = False):
|
||||||
@@ -201,7 +204,7 @@ def run_settings_dialog(wallet, is_create, is_recovery, parent):
|
|||||||
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("%f"%(wallet.fee))
|
fee_entry.set_text( str( Decimal(wallet.fee) /100000000 ) )
|
||||||
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)
|
||||||
@@ -243,7 +246,7 @@ def run_settings_dialog(wallet, is_create, is_recovery, parent):
|
|||||||
if is_recovery:
|
if is_recovery:
|
||||||
gap = int(gap)
|
gap = int(gap)
|
||||||
if not is_create:
|
if not is_create:
|
||||||
fee = float(fee)
|
fee = int( 100000000 * Decimal(fee) )
|
||||||
gap = int(gap)
|
gap = int(gap)
|
||||||
except:
|
except:
|
||||||
show_message("error")
|
show_message("error")
|
||||||
@@ -582,7 +585,7 @@ class BitcoinGUI:
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
amount = float(amount_entry.get_text())
|
amount = int( Decimal(amount_entry.get_text()) * 100000000 )
|
||||||
except:
|
except:
|
||||||
show_message( "invalid amount" )
|
show_message( "invalid amount" )
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user