added --include_protobuf to add hexlified protobuf to RPC responses

This commit is contained in:
Lex Berezhny 2019-04-21 11:06:03 -04:00
parent f660691e78
commit 9fae8f5153
2 changed files with 6 additions and 2 deletions

View file

@ -441,13 +441,14 @@ class Daemon(metaclass=JSONRPCServerType):
async def handle_old_jsonrpc(self, request):
data = await request.json()
include_protobuf = data.get('params', {}).pop('include_protobuf', False)
result = await self._process_rpc_call(data)
ledger = None
if 'wallet' in self.component_manager.get_components_status():
# self.ledger only available if wallet component is not skipped
ledger = self.ledger
return web.Response(
text=jsonrpc_dumps_pretty(result, ledger=ledger),
text=jsonrpc_dumps_pretty(result, ledger=ledger, include_protobuf=include_protobuf),
content_type='application/json'
)

View file

@ -98,9 +98,10 @@ def encode_file_doc():
class JSONResponseEncoder(JSONEncoder):
def __init__(self, *args, ledger: MainNetLedger, **kwargs):
def __init__(self, *args, ledger: MainNetLedger, include_protobuf=False, **kwargs):
super().__init__(*args, **kwargs)
self.ledger = ledger
self.include_protobuf = include_protobuf
def default(self, obj): # pylint: disable=method-hidden
if isinstance(obj, Account):
@ -168,6 +169,8 @@ class JSONResponseEncoder(JSONEncoder):
})
if txo.script.is_claim_name or txo.script.is_update_claim:
output['value'] = txo.claim
if self.include_protobuf:
output['protobuf'] = hexlify(txo.claim.to_bytes())
output['sub_type'] = txo.claim.claim_type
if txo.channel is not None:
output['signing_channel'] = {