From 5716a48e66d2c95ff4c1bde93cf75db364d99dca Mon Sep 17 00:00:00 2001 From: J-Dog Date: Fri, 26 Aug 2022 09:18:35 -0700 Subject: [PATCH] add `divisible` column to `get_balances` API calls - makes determining asset divisibility possible without additional API calls - solves issue #1199 --- counterpartylib/lib/api.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/counterpartylib/lib/api.py b/counterpartylib/lib/api.py index f034adb5e9..4276ff189f 100644 --- a/counterpartylib/lib/api.py +++ b/counterpartylib/lib/api.py @@ -279,6 +279,9 @@ def value_to_marker(value): query_result = db_query(db, statement, tuple(bindings)) + if table == 'balances': + return adjust_get_balances_results(query_result) + if table == 'destructions': return adjust_get_destructions_results(query_result) @@ -292,6 +295,19 @@ def value_to_marker(value): return query_result +def adjust_get_balances_results(query_result): + filtered_results = [] + assets = {} + for balances_row in list(query_result): + asset = balances_row['asset'] + if not asset in assets: + assets[asset] = util.is_divisible(db, asset) + + balances_row['divisible'] = assets[asset] + filtered_results.append(balances_row) + + return filtered_results + def adjust_get_destructions_results(query_result): filtered_results = [] for destruction_row in list(query_result):