support lists of constraints for all range fields
This commit is contained in:
parent
f8fe205066
commit
251cb4925a
4 changed files with 29 additions and 7 deletions
|
@ -205,12 +205,15 @@ def fix_kwargs_for_hub(**kwargs):
|
||||||
elif key == "not_channel_ids":
|
elif key == "not_channel_ids":
|
||||||
kwargs["channel_id"] = {"invert": True, "value": kwargs.pop("not_channel_ids")}
|
kwargs["channel_id"] = {"invert": True, "value": kwargs.pop("not_channel_ids")}
|
||||||
elif key in MY_RANGE_FIELDS:
|
elif key in MY_RANGE_FIELDS:
|
||||||
|
constraints = []
|
||||||
|
for v in value if isinstance(value, list) else [value]:
|
||||||
operator = '='
|
operator = '='
|
||||||
if isinstance(value, str) and value[0] in opcodes:
|
if isinstance(v, str) and v[0] in opcodes:
|
||||||
operator_length = 2 if value[:2] in opcodes else 1
|
operator_length = 2 if v[:2] in opcodes else 1
|
||||||
operator, value = value[:operator_length], value[operator_length:]
|
operator, v = v[:operator_length], v[operator_length:]
|
||||||
value = [str(value if key != 'fee_amount' else Decimal(value)*1000)]
|
v = [str(v if key != 'fee_amount' else Decimal(v)*1000)]
|
||||||
kwargs[key] = {"op": opcodes[operator], "value": value}
|
constraints.append({"op": opcodes[operator], "value": v})
|
||||||
|
kwargs[key] = constraints
|
||||||
elif key == 'order_by': # TODO: remove this after removing support for old trending args from the api
|
elif key == 'order_by': # TODO: remove this after removing support for old trending args from the api
|
||||||
value = value if isinstance(value, list) else [value]
|
value = value if isinstance(value, list) else [value]
|
||||||
new_value = []
|
new_value = []
|
||||||
|
@ -2408,6 +2411,9 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
value with an equality constraint such as '>', '>=', '<' and '<='
|
value with an equality constraint such as '>', '>=', '<' and '<='
|
||||||
eg. --height=">400000" would limit results to only claims above 400k block height.
|
eg. --height=">400000" would limit results to only claims above 400k block height.
|
||||||
|
|
||||||
|
They also support multiple constraints passed as a list of the args described above.
|
||||||
|
eg. --release_time=[">1000000", "<2000000"]
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
claim_search [<name> | --name=<name>] [--text=<text>] [--txid=<txid>] [--nout=<nout>]
|
claim_search [<name> | --name=<name>] [--text=<text>] [--txid=<txid>] [--nout=<nout>]
|
||||||
[--claim_id=<claim_id> | --claim_ids=<claim_ids>...]
|
[--claim_id=<claim_id> | --claim_ids=<claim_ids>...]
|
||||||
|
|
|
@ -574,6 +574,15 @@ def expand_query(**kwargs):
|
||||||
if key == 'fee_amount':
|
if key == 'fee_amount':
|
||||||
value = str(Decimal(value)*1000)
|
value = str(Decimal(value)*1000)
|
||||||
query['must'].append({"range": {key: {ops[operator]: value}}})
|
query['must'].append({"range": {key: {ops[operator]: value}}})
|
||||||
|
elif key in RANGE_FIELDS and isinstance(value, list) and all(v[0] in ops for v in value):
|
||||||
|
range_constraints = []
|
||||||
|
for v in value:
|
||||||
|
operator_length = 2 if v[:2] in ops else 1
|
||||||
|
operator, stripped_op_v = v[:operator_length], v[operator_length:]
|
||||||
|
if key == 'fee_amount':
|
||||||
|
stripped_op_v = str(Decimal(stripped_op_v)*1000)
|
||||||
|
range_constraints.append((operator, stripped_op_v))
|
||||||
|
query['must'].append({"range": {key: {ops[operator]: v for operator, v in range_constraints}}})
|
||||||
elif many:
|
elif many:
|
||||||
query['must'].append({"terms": {key: value}})
|
query['must'].append({"terms": {key: value}})
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -981,8 +981,9 @@ class LBRYElectrumX(SessionBase):
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
if 'release_time' in kwargs:
|
if 'release_time' in kwargs:
|
||||||
release_time = kwargs.pop('release_time')
|
release_time = kwargs.pop('release_time')
|
||||||
|
release_times = release_time if isinstance(release_time, list) else [release_time]
|
||||||
try:
|
try:
|
||||||
kwargs['release_time'] = format_release_time(release_time)
|
kwargs['release_time'] = [format_release_time(release_time) for release_time in release_times]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1796,6 +1796,12 @@ class StreamCommands(ClaimTestCase):
|
||||||
self.assertEqual(1, len(await self.claim_search(release_time='>123456', order_by=['release_time'])))
|
self.assertEqual(1, len(await self.claim_search(release_time='>123456', order_by=['release_time'])))
|
||||||
self.assertEqual(2, len(await self.claim_search(release_time='<123457', order_by=['release_time'])))
|
self.assertEqual(2, len(await self.claim_search(release_time='<123457', order_by=['release_time'])))
|
||||||
|
|
||||||
|
self.assertEqual(2, len(await self.claim_search(release_time=['<123457'], order_by=['release_time'])))
|
||||||
|
self.assertEqual(2, len(await self.claim_search(release_time=['>0', '<123457'], order_by=['release_time'])))
|
||||||
|
self.assertEqual(
|
||||||
|
2, len(await self.claim_search(release_time=['>=123097', '<123457'], order_by=['release_time']))
|
||||||
|
)
|
||||||
|
|
||||||
async def test_setting_fee_fields(self):
|
async def test_setting_fee_fields(self):
|
||||||
tx = await self.out(self.stream_create('paid-stream'))
|
tx = await self.out(self.stream_create('paid-stream'))
|
||||||
txo = tx['outputs'][0]
|
txo = tx['outputs'][0]
|
||||||
|
|
Loading…
Add table
Reference in a new issue