optionally get name history rows in reverse

This commit is contained in:
Jude Nelson
2018-06-20 11:44:29 -04:00
parent 98c59d4f80
commit cd51534d81

View File

@@ -1285,13 +1285,17 @@ def namedb_get_blocks_with_ops( cur, history_id, start_block_id, end_block_id ):
return ret
def namedb_get_history_rows( cur, history_id, offset=None, count=None ):
def namedb_get_history_rows( cur, history_id, offset=None, count=None, reverse=False ):
"""
Get the history for a name or namespace from the history table.
Use offset/count if given.
"""
ret = []
select_query = "SELECT * FROM history WHERE history_id = ? ORDER BY block_id ASC, vtxindex ASC"
if not reverse:
select_query = "SELECT * FROM history WHERE history_id = ? ORDER BY block_id ASC, vtxindex ASC"
else:
select_query = "SELECT * FROM history WHERE history_id = ? ORDER BY block_id DESC, vtxindex DESC"
args = (history_id,)
if count is not None:
@@ -1325,14 +1329,13 @@ def namedb_get_num_history_rows( cur, history_id ):
return count
def namedb_get_history( cur, history_id ):
def namedb_get_history( cur, history_id, offset=None, count=None, reverse=False ):
"""
Get all of the history for a name or namespace.
Returns a dict keyed by block heights, paired to lists of changes (see namedb_history_extract)
"""
# get history in increasing order by block_id and then vtxindex
history_rows = namedb_get_history_rows( cur, history_id )
history_rows = namedb_get_history_rows( cur, history_id, offset=offset, count=count, reverse=reverse )
return namedb_history_extract( history_rows )