create a class for transaction dialog
[electrum-nvc.git] / lib / util.py
index 50d8ec3..9503b88 100644 (file)
@@ -24,7 +24,10 @@ def print_msg(*args):
 
 def print_json(obj):
     import json
-    s = json.dumps(obj,sort_keys = True, indent = 4)
+    try:
+        s = json.dumps(obj,sort_keys = True, indent = 4)
+    except TypeError:
+        s = repr(obj)
     sys.stdout.write(s + "\n")
     sys.stdout.flush()
 
@@ -79,14 +82,14 @@ def local_data_dir():
     return local_data
 
 
-def format_satoshis(x, is_diff=False, num_zeros = 0):
+def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespaces=False):
     from decimal import Decimal
     s = Decimal(x)
     sign, digits, exp = s.as_tuple()
     digits = map(str, digits)
-    while len(digits) < 9:
+    while len(digits) < decimal_point + 1:
         digits.insert(0,'0')
-    digits.insert(-8,'.')
+    digits.insert(-decimal_point,'.')
     s = ''.join(digits).rstrip('0')
     if sign: 
         s = '-' + s
@@ -95,8 +98,9 @@ def format_satoshis(x, is_diff=False, num_zeros = 0):
 
     p = s.find('.')
     s += "0"*( 1 + num_zeros - ( len(s) - p ))
-    s += " "*( 9 - ( len(s) - p ))
-    s = " "*( 5 - ( p )) + s
+    if whitespaces:
+        s += " "*( 1 + decimal_point - ( len(s) - p ))
+        s = " "*( 13 - decimal_point - ( p )) + s 
     return s