From a290b61f1a3a6223b5405d68fd10aa1957887c1c Mon Sep 17 00:00:00 2001 From: Amos Bairn Date: Thu, 22 Aug 2013 07:35:48 -0700 Subject: [PATCH] Add listAddressbook to api listAddressbook returns label and address for each address in the addressbook. --- src/bitmessagemain.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index fd233bd5..00c79247 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -164,6 +164,21 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): streamNumber, 'enabled': shared.config.getboolean(addressInKeysFile, 'enabled')}, indent=4, separators=(',', ': ')) data += ']}' return data + elif method == 'listAddressbook': + shared.sqlLock.acquire() + shared.sqlSubmitQueue.put('''SELECT label, address from addressbook''') + shared.sqlSubmitQueue.put('') + queryreturn = shared.sqlReturnQueue.get() + shared.sqlLock.release() + data = '{"addresses":[' + for row in queryreturn: + label, address = row + label = shared.fixPotentiallyInvalidUTF8Data(label) + if len(data) > 20: + data += ',' + data += json.dumps({'label':label.encode('base64'), 'address': address}) + data += ']}' + return data elif method == 'createRandomAddress': if len(params) == 0: return 'API Error 0000: I need parameters!'