Skip to content

Commit

Permalink
add divisible column to get_balances API calls
Browse files Browse the repository at this point in the history
- makes determining asset divisibility possible without additional API calls
- solves issue #1199
  • Loading branch information
jdogresorg committed Aug 26, 2022
1 parent d648bbd commit 5716a48
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions counterpartylib/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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):
Expand Down

0 comments on commit 5716a48

Please sign in to comment.