more json formatting

This commit is contained in:
thomasv 2013-02-27 10:24:53 +01:00
parent e4dc3f3752
commit f4ac478369
2 changed files with 17 additions and 15 deletions

View file

@ -486,9 +486,11 @@ if __name__ == '__main__':
else: else:
cmd_runner = Commands(wallet, interface) cmd_runner = Commands(wallet, interface)
func = eval('cmd_runner.' + cmd) func = eval('cmd_runner.' + cmd)
if password:
cmd_runner.password = password cmd_runner.password = password
result = func(*args[1:]) result = func(*args[1:])
if type(result) == str:
util.print_msg(result)
else:
util.print_json(result) util.print_json(result)

View file

@ -235,31 +235,31 @@ class Commands:
def balance(self, addresses = []): def balance(self, addresses = []):
if addresses == []: if addresses == []:
c, u = self.wallet.get_balance() c, u = self.wallet.get_balance()
if u:
print_msg(Decimal( c ) / 100000000 , Decimal( u ) / 100000000)
else:
print_msg(Decimal( c ) / 100000000)
else: else:
c = u = 0
for addr in addresses: for addr in addresses:
c, u = wallet.get_addr_balance(addr) cc, uu = wallet.get_addr_balance(addr)
if u: c += cc
print_msg("%s %s, %s" % (addr, str(Decimal(c)/100000000), str(Decimal(u)/100000000))) u += uu
else:
print_msg("%s %s" % (addr, str(Decimal(c)/100000000))) out = { "confirmed": str(Decimal(c)/100000000) }
if u: out["unconfirmed"] = str(Decimal(u)/100000000)
return out
def get_seed(self): def get_seed(self):
import mnemonic import mnemonic
seed = self.wallet.decode_seed(self.password) seed = self.wallet.decode_seed(self.password)
print_msg(seed + ' "' + ' '.join(mnemonic.mn_encode(seed)) + '"') return { "hex":seed, "mnemonic": ' '.join(mnemonic.mn_encode(seed)) }
def importprivkey(self, sec): def importprivkey(self, sec):
try: try:
addr = wallet.import_key(sec,self.password) addr = wallet.import_key(sec,self.password)
wallet.save() wallet.save()
print_msg("Keypair imported: ", addr) out = "Keypair imported: ", addr
except BaseException as e: except BaseException as e:
print_msg("Error: Keypair import failed: " + str(e)) out = "Error: Keypair import failed: " + str(e)
return out
def sign_message(self, address, message): def sign_message(self, address, message):