From feed3422ee34768cd9dcc896b274ef665dbf335d Mon Sep 17 00:00:00 2001 From: Jude Nelson Date: Fri, 9 Sep 2016 11:17:53 -0400 Subject: [PATCH] get_namespace_op_state() for getting historic namespace states; on committing a state transition, include expired namespace op sequences (this is because the block we're processing is one block later than the block we used to query properties about the namespace--we need to ensure that if we have a state-transition on a namespace that occurred on the last possible block, we still accept it) --- blockstack/lib/nameset/namedb.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/blockstack/lib/nameset/namedb.py b/blockstack/lib/nameset/namedb.py index 8d58b934f..65e78ab7b 100644 --- a/blockstack/lib/nameset/namedb.py +++ b/blockstack/lib/nameset/namedb.py @@ -571,6 +571,21 @@ class BlockstackDB( virtualchain.StateEngine ): cur = self.db.cursor() return namedb_get_namespace_ready( cur, namespace_id ) + + @autofill( "opcode" ) + def get_namespace_op_state( self, namespace_id, block_number, include_expired=False ): + """ + Given a namespace ID and block number, get the current namespace op (revealed or ready) for it + if the namespace existed after that block. Optionally return the namespace + record even if it's a NAMESPACE_REVEAL and it expired. + + Return the dict with the parameters on success. + Return None if the namespace has not yet been revealed. + """ + + cur = self.db.cursor() + return namedb_get_namespace( cur, namespace_id, block_number ) + @autofill( "opcode" ) def get_namespace_by_preorder( self, preorder_hash ): @@ -1551,7 +1566,7 @@ class BlockstackDB( virtualchain.StateEngine ): cur_record = namedb_get_name( cur, history_id, current_block_number, include_history=False, include_expired=True ) elif history_id_key == "namespace_id": - cur_record = namedb_get_namespace( cur, history_id, current_block_number, include_history=False ) + cur_record = namedb_get_namespace( cur, history_id, current_block_number, include_history=False, include_expired=True ) else: raise Exception("Unknown history ID key '%s'" % history_id_key) @@ -1581,7 +1596,7 @@ class BlockstackDB( virtualchain.StateEngine ): if history_id_key == "name": new_record = namedb_get_name( cur, history_id, current_block_number, include_history=False, include_expired=True ) elif history_id_key == "namespace_id": - new_record = namedb_get_namespace( cur, history_id, current_block_number, include_history=False ) + new_record = namedb_get_namespace( cur, history_id, current_block_number, include_history=False, include_expired=True ) return new_record