separate bitcoin related functions from wallet.py
This commit is contained in:
27
lib/util.py
27
lib/util.py
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
import os, sys
|
||||
import platform
|
||||
import sys
|
||||
|
||||
def print_error(*args):
|
||||
# Stringify args
|
||||
@@ -8,6 +7,7 @@ def print_error(*args):
|
||||
sys.stderr.write(" ".join(args) + "\n")
|
||||
sys.stderr.flush()
|
||||
|
||||
|
||||
def user_dir():
|
||||
if "HOME" in os.environ:
|
||||
return os.path.join(os.environ["HOME"], ".electrum")
|
||||
@@ -18,6 +18,7 @@ def user_dir():
|
||||
else:
|
||||
raise BaseException("No home directory found in environment variables.")
|
||||
|
||||
|
||||
def appdata_dir():
|
||||
"""Find the path to the application data directory; add an electrum folder and return path."""
|
||||
if platform.system() == "Windows":
|
||||
@@ -30,9 +31,11 @@ def appdata_dir():
|
||||
else:
|
||||
raise Exception("Unknown system")
|
||||
|
||||
|
||||
def get_resource_path(*args):
|
||||
return os.path.join(".", *args)
|
||||
|
||||
|
||||
def local_data_dir():
|
||||
"""Return path to the data folder."""
|
||||
assert sys.argv
|
||||
@@ -40,3 +43,23 @@ def local_data_dir():
|
||||
local_data = os.path.join(prefix_path, "data")
|
||||
return local_data
|
||||
|
||||
|
||||
def format_satoshis(x, is_diff=False, num_zeros = 0):
|
||||
from decimal import Decimal
|
||||
s = Decimal(x)
|
||||
sign, digits, exp = s.as_tuple()
|
||||
digits = map(str, digits)
|
||||
while len(digits) < 9:
|
||||
digits.insert(0,'0')
|
||||
digits.insert(-8,'.')
|
||||
s = ''.join(digits).rstrip('0')
|
||||
if sign:
|
||||
s = '-' + s
|
||||
elif is_diff:
|
||||
s = "+" + s
|
||||
|
||||
p = s.find('.')
|
||||
s += "0"*( 1 + num_zeros - ( len(s) - p ))
|
||||
s += " "*( 9 - ( len(s) - p ))
|
||||
s = " "*( 5 - ( p )) + s
|
||||
return s
|
||||
|
||||
Reference in New Issue
Block a user