mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-08-23 17:27:25 +00:00
correctly format lat/long and fee amounts in JSON RPC response
This commit is contained in:
parent
3567b331c0
commit
558a02d187
3 changed files with 22 additions and 4 deletions
|
@ -6,6 +6,7 @@ from typing import Tuple, List
|
||||||
from string import ascii_letters
|
from string import ascii_letters
|
||||||
from decimal import Decimal, ROUND_UP
|
from decimal import Decimal, ROUND_UP
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
|
from google.protobuf.json_format import MessageToDict
|
||||||
|
|
||||||
from torba.client.hash import Base58
|
from torba.client.hash import Base58
|
||||||
from torba.client.constants import COIN
|
from torba.client.constants import COIN
|
||||||
|
@ -446,6 +447,14 @@ class Location(Metadata):
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'Could not parse country value: {value}')
|
raise ValueError(f'Could not parse country value: {value}')
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
d = MessageToDict(self.message)
|
||||||
|
if self.message.longitude:
|
||||||
|
d['longitude'] = self.longitude
|
||||||
|
if self.message.latitude:
|
||||||
|
d['latitude'] = self.latitude
|
||||||
|
return d
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def country(self) -> str:
|
def country(self) -> str:
|
||||||
if self.message.country:
|
if self.message.country:
|
||||||
|
|
|
@ -115,6 +115,8 @@ class BaseClaim:
|
||||||
claim.update(claim.pop(self.claim_type))
|
claim.update(claim.pop(self.claim_type))
|
||||||
if 'languages' in claim:
|
if 'languages' in claim:
|
||||||
claim['languages'] = self.langtags
|
claim['languages'] = self.langtags
|
||||||
|
if 'locations' in claim:
|
||||||
|
claim['locations'] = [l.to_dict() for l in self.locations]
|
||||||
return claim
|
return claim
|
||||||
|
|
||||||
def update(self, **kwargs):
|
def update(self, **kwargs):
|
||||||
|
@ -197,7 +199,7 @@ class Stream(BaseClaim):
|
||||||
if 'address' in fee:
|
if 'address' in fee:
|
||||||
fee['address'] = self.fee.address
|
fee['address'] = self.fee.address
|
||||||
if 'amount' in fee:
|
if 'amount' in fee:
|
||||||
fee['amount'] = self.fee.amount
|
fee['amount'] = str(self.fee.amount)
|
||||||
stream_type = self.message.WhichOneof('type')
|
stream_type = self.message.WhichOneof('type')
|
||||||
if stream_type:
|
if stream_type:
|
||||||
claim['stream_type'] = stream_type
|
claim['stream_type'] = stream_type
|
||||||
|
|
|
@ -317,7 +317,7 @@ class StreamCommands(CommandTestCase):
|
||||||
'thumbnail_url': "https://co.ol/thumbnail.png",
|
'thumbnail_url': "https://co.ol/thumbnail.png",
|
||||||
'tags': ["cool", "awesome"],
|
'tags': ["cool", "awesome"],
|
||||||
'languages': ["en"],
|
'languages': ["en"],
|
||||||
'locations': ['{"country": "US"}'],
|
'locations': ['US:NH:Manchester:03101:42.990605:-71.460989'],
|
||||||
|
|
||||||
'author': "Jules Verne",
|
'author': "Jules Verne",
|
||||||
'license': 'Public Domain',
|
'license': 'Public Domain',
|
||||||
|
@ -329,7 +329,14 @@ class StreamCommands(CommandTestCase):
|
||||||
'fee_address': 'mmCsWAiXMUVecFQ3fVzUwvpT9XFMXno2Ca',
|
'fee_address': 'mmCsWAiXMUVecFQ3fVzUwvpT9XFMXno2Ca',
|
||||||
}
|
}
|
||||||
fixed_values = values.copy()
|
fixed_values = values.copy()
|
||||||
fixed_values['locations'] = [{'country': 'US'}]
|
fixed_values['locations'] = [{
|
||||||
|
'country': 'US',
|
||||||
|
'state': 'NH',
|
||||||
|
'city': 'Manchester',
|
||||||
|
'code': '03101',
|
||||||
|
'latitude': '42.990605',
|
||||||
|
'longitude': '-71.460989'
|
||||||
|
}]
|
||||||
fixed_values['thumbnail'] = {'url': fixed_values.pop('thumbnail_url')}
|
fixed_values['thumbnail'] = {'url': fixed_values.pop('thumbnail_url')}
|
||||||
fixed_values['release_time'] = str(values['release_time'])
|
fixed_values['release_time'] = str(values['release_time'])
|
||||||
fixed_values['source'] = {
|
fixed_values['source'] = {
|
||||||
|
@ -339,7 +346,7 @@ class StreamCommands(CommandTestCase):
|
||||||
}
|
}
|
||||||
fixed_values['fee'] = {
|
fixed_values['fee'] = {
|
||||||
'address': fixed_values.pop('fee_address'),
|
'address': fixed_values.pop('fee_address'),
|
||||||
'amount': float(fixed_values.pop('fee_amount')),
|
'amount': fixed_values.pop('fee_amount'),
|
||||||
'currency': fixed_values.pop('fee_currency').upper()
|
'currency': fixed_values.pop('fee_currency').upper()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue