INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Log a committed operation | def log_commit( self, block_id, vtxindex, op, opcode, op_data ):
"""
Log a committed operation
"""
debug_op = self.sanitize_op( op_data )
if 'history' in debug_op:
del debug_op['history']
log.debug("COMMIT %s (%s) at (%s, %s) data: %s", opcode, op, block_id... |
Log a rejected operation | def log_reject( self, block_id, vtxindex, op, op_data ):
"""
Log a rejected operation
"""
debug_op = self.sanitize_op( op_data )
if 'history' in debug_op:
del debug_op['history']
log.debug("REJECT %s at (%s, %s) data: %s", op_get_opcode_name( op ), block_id,... |
Remove unnecessary fields for an operation, i.e. prior to committing it.
This includes any invariant tags we've added with our invariant decorators
(such as @state_create or @state_transition).
TODO: less ad-hoc way to do this | def sanitize_op( self, op_data ):
"""
Remove unnecessary fields for an operation, i.e. prior to committing it.
This includes any invariant tags we've added with our invariant decorators
(such as @state_create or @state_transition).
TODO: less ad-hoc way to do this
... |
Given a history ID, see if it already exists
at the given block ID (i.e. it's not expired),
using the given collision state.
Return True if so; False if not.
If there is a collision, set the __collided__ field in each checked_ops that
has a matching history_id value and has an op... | def check_collision_state( cls, collision_state, history_id_key, history_id, block_id, checked_ops, affected_opcodes ):
"""
Given a history ID, see if it already exists
at the given block ID (i.e. it's not expired),
using the given collision state.
Return True if so; False if not... |
Given a list of checked operations, find the ones that collide.
Return a dict structured as history_id_key --> [history_id] | def find_collisions( self, checked_ops ):
"""
Given a list of checked operations, find the ones that collide.
Return a dict structured as history_id_key --> [history_id]
"""
collisions = {}
for op in checked_ops:
if BlockstackDB.nameop_is_collided( op ):
... |
Put collision state for a particular block.
Any operations checked at this block_id that collide
with the given collision state will be rejected. | def put_collisions( self, block_id, collisions ):
"""
Put collision state for a particular block.
Any operations checked at this block_id that collide
with the given collision state will be rejected.
"""
self.collisions[ block_id ] = copy.deepcopy( collisions ) |
Given a history ID, see if it already exists
at the given block ID (i.e. it's not expired).
Return True if so; False if not.
If there is a collision, set the __collided__ field in each checked_ops that
has a matching history_id value and has an opcode in affected_opcodes. | def check_collision( self, history_id_key, history_id, block_id, checked_ops, affected_opcodes ):
"""
Given a history ID, see if it already exists
at the given block ID (i.e. it's not expired).
Return True if so; False if not.
If there is a collision, set the __collided__ field i... |
Are there any colliding preorders in this block?
Set the '__collided__' flag and related flags if so, so we don't commit them.
Not called directly; called by the @state_preorder() decorator in blockstack.lib.operations.preorder and blockstack.lib.operations.namespacepreorder | def check_preorder_collision( self, preorder_hash, block_id, checked_ops ):
"""
Are there any colliding preorders in this block?
Set the '__collided__' flag and related flags if so, so we don't commit them.
Not called directly; called by the @state_preorder() decorator in blockstack.lib... |
Are there any colliding names in this block?
Set the '__collided__' flag and related flags if so, so we don't commit them.
Not called directly; called by the @state_create() decorator in blockstack.lib.operations.register | def check_name_collision( self, name, block_id, checked_ops ):
"""
Are there any colliding names in this block?
Set the '__collided__' flag and related flags if so, so we don't commit them.
Not called directly; called by the @state_create() decorator in blockstack.lib.operations... |
Are there any colliding namespaces in this block?
Set the '__collided__' flag and related flags if so, so we don't commit them
Not called directly; called by the @state_create() decorator in blockstack.lib.operations.namespacereveal | def check_namespace_collision( self, namespace_id, block_id, checked_ops ):
"""
Are there any colliding namespaces in this block?
Set the '__collided__' flag and related flags if so, so we don't commit them
Not called directly; called by the @state_create() decorator in blocksta... |
Given a namespace ID, get the ready namespace op for it.
Return the dict with the parameters on success.
Return None if the namespace has not yet been revealed. | def get_namespace( self, namespace_id, include_history=True ):
"""
Given a namespace ID, get the ready namespace op for it.
Return the dict with the parameters on success.
Return None if the namespace has not yet been revealed.
"""
cur = self.db.cursor()
return ... |
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 i... | 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 NAME... |
Given a namespace preorder hash, get the associated namespace
reveal or ready (it may be expired). | def get_namespace_by_preorder( self, preorder_hash ):
"""
Given a namespace preorder hash, get the associated namespace
reveal or ready (it may be expired).
"""
cur = self.db.cursor()
return namedb_get_namespace_by_preorder_hash( cur, preorder_hash ) |
Given a name preorder hash, get the associated name record.
(It may be expired or revoked) | def get_name_by_preorder( self, preorder_hash ):
"""
Given a name preorder hash, get the associated name record.
(It may be expired or revoked)
"""
cur = self.db.cursor()
return namedb_get_name_by_preorder_hash( cur, preorder_hash ) |
Given a name, return the latest version and history of
the metadata gleaned from the blockchain.
Name must be fully-qualified (i.e. name.ns_id)
Return None if no such name is currently registered.
NOTE: returns names that are revoked | def get_name( self, name, lastblock=None, include_expired=False, include_history=True ):
"""
Given a name, return the latest version and history of
the metadata gleaned from the blockchain.
Name must be fully-qualified (i.e. name.ns_id)
Return None if no such name is currently re... |
Given a name, find its DID (decentralized identifier) information.
Returns {'address': ..., 'index': ...}
Returns None if there is no such name | def get_name_DID_info(self, name, lastblock=None):
"""
Given a name, find its DID (decentralized identifier) information.
Returns {'address': ..., 'index': ...}
Returns None if there is no such name
"""
if lastblock is None:
lastblock = self.lastblock
... |
Given a DID, get the name
Return None if not found, or if the name was revoked
Raise if the DID is invalid | def get_DID_name(self, did):
"""
Given a DID, get the name
Return None if not found, or if the name was revoked
Raise if the DID is invalid
"""
did = str(did)
did_info = None
try:
did_info = parse_DID(did)
assert did_info['name_type... |
Get the list of tokens that this address owns | def get_account_tokens(self, address):
"""
Get the list of tokens that this address owns
"""
cur = self.db.cursor()
return namedb_get_account_tokens(cur, address) |
Get the state of an account for a given token type | def get_account(self, address, token_type):
"""
Get the state of an account for a given token type
"""
cur = self.db.cursor()
return namedb_get_account(cur, address, token_type) |
What's the balance of an account?
Aborts if its negative | def get_account_balance(self, account):
"""
What's the balance of an account?
Aborts if its negative
"""
balance = namedb_get_account_balance(account)
assert isinstance(balance, (int,long)), 'BUG: account balance of {} is {} (type {})'.format(account['address'], balance, ... |
Get two consecutive account states---the one at (block_id, vtxindex), and the one prior. | def get_account_delta(self, address, token_type, block_id, vtxindex):
"""
Get two consecutive account states---the one at (block_id, vtxindex), and the one prior.
"""
cur = self.db.cursor()
return namedb_get_account_delta(cur, address, token_type, block_id, vtxindex) |
Get the history of account transactions over a block range
Returns a dict keyed by blocks, which map to lists of account state transitions | def get_account_history(self, address, offset=None, count=None):
"""
Get the history of account transactions over a block range
Returns a dict keyed by blocks, which map to lists of account state transitions
"""
cur = self.db.cursor()
return namedb_get_account_history(cur... |
Generate and return the sequence of of states a name record was in
at a particular block number. | def get_name_at( self, name, block_number, include_expired=False ):
"""
Generate and return the sequence of of states a name record was in
at a particular block number.
"""
cur = self.db.cursor()
return namedb_get_name_at(cur, name, block_number, include_expired=include_e... |
Generate and return the sequence of states a namespace record was in
at a particular block number.
Includes expired namespaces by default. | def get_namespace_at( self, namespace_id, block_number ):
"""
Generate and return the sequence of states a namespace record was in
at a particular block number.
Includes expired namespaces by default.
"""
cur = self.db.cursor()
return namedb_get_namespace_at(cur... |
Get the sequence of states an account was in at a given block.
Returns a list of states | def get_account_at(self, address, block_number):
"""
Get the sequence of states an account was in at a given block.
Returns a list of states
"""
cur = self.db.cursor()
return namedb_get_account_at(cur, address, block_number) |
Get the historic states for a name, grouped by block height. | def get_name_history( self, name, offset=None, count=None, reverse=False):
"""
Get the historic states for a name, grouped by block height.
"""
cur = self.db.cursor()
name_hist = namedb_get_history( cur, name, offset=offset, count=count, reverse=reverse )
return name_hist |
Was a zone file sent by a name? | def is_name_zonefile_hash(self, name, zonefile_hash):
"""
Was a zone file sent by a name?
"""
cur = self.db.cursor()
return namedb_is_name_zonefile_hash(cur, name, zonefile_hash) |
Get all name, namespace, and account records affected at a particular block,
in the state they were at the given block number.
Paginate if offset, count are given. | def get_all_blockstack_ops_at( self, block_number, offset=None, count=None, include_history=None, restore_history=None ):
"""
Get all name, namespace, and account records affected at a particular block,
in the state they were at the given block number.
Paginate if offset, count ... |
Get the name from a name hash | def get_name_from_name_hash128( self, name ):
"""
Get the name from a name hash
"""
cur = self.db.cursor()
name = namedb_get_name_from_name_hash128( cur, name, self.lastblock )
return name |
Get the set of names owned by a particular address.
NOTE: only works for cases where we could extract an address. | def get_names_owned_by_address( self, address ):
"""
Get the set of names owned by a particular address.
NOTE: only works for cases where we could extract an address.
"""
cur = self.db.cursor()
names = namedb_get_names_owned_by_address( cur, address, self.lastblock )
... |
Get the list of names owned by an address throughout history (used for DIDs)
Return a list of {'name': ..., 'block_id': ..., 'vtxindex': ...} | def get_historic_names_by_address( self, address, offset=None, count=None ):
"""
Get the list of names owned by an address throughout history (used for DIDs)
Return a list of {'name': ..., 'block_id': ..., 'vtxindex': ...}
"""
cur = self.db.cursor()
names = namedb_get_his... |
Get the number of names historically owned by an address | def get_num_historic_names_by_address( self, address ):
"""
Get the number of names historically owned by an address
"""
cur = self.db.cursor()
count = namedb_get_num_historic_names_by_address( cur, address )
return count |
Get the set of names owned by a particular script-pubkey. | def get_names_owned_by_sender( self, sender_pubkey, lastblock=None ):
"""
Get the set of names owned by a particular script-pubkey.
"""
cur = self.db.cursor()
if lastblock is None:
lastblock = self.lastblock
names = namedb_get_names_by_sender( cur, sender_pu... |
Get the number of names that exist. | def get_num_names( self, include_expired=False ):
"""
Get the number of names that exist.
"""
cur = self.db.cursor()
return namedb_get_num_names( cur, self.lastblock, include_expired=include_expired ) |
Get the set of all registered names, with optional pagination
Returns the list of names. | def get_all_names( self, offset=None, count=None, include_expired=False ):
"""
Get the set of all registered names, with optional pagination
Returns the list of names.
"""
if offset is not None and offset < 0:
offset = None
if count is not None and count < 0:... |
Get the number of names in a namespace | def get_num_names_in_namespace( self, namespace_id ):
"""
Get the number of names in a namespace
"""
cur = self.db.cursor()
return namedb_get_num_names_in_namespace( cur, namespace_id, self.lastblock ) |
Get the set of all registered names in a particular namespace.
Returns the list of names. | def get_names_in_namespace( self, namespace_id, offset=None, count=None ):
"""
Get the set of all registered names in a particular namespace.
Returns the list of names.
"""
if offset is not None and offset < 0:
offset = None
if count is not None and count < ... |
Get the set of all existing, READY namespace IDs. | def get_all_namespace_ids( self ):
"""
Get the set of all existing, READY namespace IDs.
"""
cur = self.db.cursor()
namespace_ids = namedb_get_all_namespace_ids( cur )
return namespace_ids |
Get all revealed namespace IDs that have not expired. | def get_all_revealed_namespace_ids( self ):
"""
Get all revealed namespace IDs that have not expired.
"""
cur = self.db.cursor()
namespace_ids = namedb_get_all_revealed_namespace_ids( cur, self.lastblock )
return namespace_ids |
Get all oustanding namespace preorder hashes that have not expired.
Used for testing | def get_all_preordered_namespace_hashes( self ):
"""
Get all oustanding namespace preorder hashes that have not expired.
Used for testing
"""
cur = self.db.cursor()
namespace_hashes = namedb_get_all_preordered_namespace_hashes( cur, self.lastblock )
return namespa... |
Get the set of all preordered and revealed namespace hashes that have not expired. | def get_all_importing_namespace_hashes( self ):
"""
Get the set of all preordered and revealed namespace hashes that have not expired.
"""
cur = self.db.cursor()
namespace_hashes = namedb_get_all_importing_namespace_hashes( cur, self.lastblock )
return namespace_hashes |
Find the name.ns_id from hash( name.ns_id, consensus_hash ), given the sender and
block_id, and assuming that name.ns_id is already registered.
There are only a small number of values this hash can take, so test all of them to
see if the hash matches one of them.
This is used for name ... | def get_name_from_name_consensus_hash( self, name_consensus_hash, sender_script_pubkey, block_id ):
"""
Find the name.ns_id from hash( name.ns_id, consensus_hash ), given the sender and
block_id, and assuming that name.ns_id is already registered.
There are only a small number of values... |
Get the current preorder for a name, given the name, the sender's script pubkey, and
the registration address used to calculate the preorder hash.
Return the preorder record on success.
Return None if not found, or the preorder is already registered and not expired (even if revoked).
N... | def get_name_preorder( self, name, sender_script_pubkey, register_addr, include_failed=False ):
"""
Get the current preorder for a name, given the name, the sender's script pubkey, and
the registration address used to calculate the preorder hash.
Return the preorder record on success.
... |
Given the hash(namesapce_id, sender_script_pubkey, reveal_addr) for a
namespace that is being imported, get its associated NAMESPACE_PREORDER
record.
Return the namespace preorder record on success.
Return None if not found, if the namespace is currently not preordered, or if the preor... | def get_namespace_preorder( self, namespace_id_hash ):
"""
Given the hash(namesapce_id, sender_script_pubkey, reveal_addr) for a
namespace that is being imported, get its associated NAMESPACE_PREORDER
record.
Return the namespace preorder record on success.
Return None ... |
Get the list of names with the given value hash, at the current block height.
This excludes revoked names and expired names.
Return None if there are no such names | def get_names_with_value_hash( self, value_hash ):
"""
Get the list of names with the given value hash, at the current block height.
This excludes revoked names and expired names.
Return None if there are no such names
"""
cur = self.db.cursor()
names = namedb_ge... |
Get the blockchain-ordered sequence of names, value hashes, and txids.
added at the given block height. The order will be
in tx-order.
Return [{'name': name, 'value_hash': value_hash, 'txid': txid}] | def get_atlas_zonefile_info_at( self, block_id ):
"""
Get the blockchain-ordered sequence of names, value hashes, and txids.
added at the given block height. The order will be
in tx-order.
Return [{'name': name, 'value_hash': value_hash, 'txid': txid}]
"""
nameo... |
Given a name and a value hash (i.e. the zone file hash), return the txid for the value hash.
Return None if the name doesn't exist, or is revoked, or did not
receive a NAME_UPDATE since it was last preordered. | def get_name_value_hash_txid( self, name, value_hash ):
"""
Given a name and a value hash (i.e. the zone file hash), return the txid for the value hash.
Return None if the name doesn't exist, or is revoked, or did not
receive a NAME_UPDATE since it was last preordered.
"""
... |
Given the name of a namespace, get it if it is currently
being revealed.
Return the reveal record on success.
Return None if it is not being revealed, or is expired. | def get_namespace_reveal( self, namespace_id, include_history=True ):
"""
Given the name of a namespace, get it if it is currently
being revealed.
Return the reveal record on success.
Return None if it is not being revealed, or is expired.
"""
cur = self.db.curso... |
Given a name and block number, determine if it is expired at that block.
* names in revealed but not ready namespaces are never expired, unless the namespace itself is expired;
* names in ready namespaces expire once max(ready_block, renew_block) + lifetime blocks passes
Return True if so
... | def is_name_expired( self, name, block_number ):
"""
Given a name and block number, determine if it is expired at that block.
* names in revealed but not ready namespaces are never expired, unless the namespace itself is expired;
* names in ready namespaces expire once max(ready_block, r... |
Get the expiry and renewal deadlines for a (registered) name.
NOTE: expire block here is NOT the block at which the owner loses the name, but the block at which lookups fail.
The name owner has until renewal_deadline to renew the name.
Return {'expire_block': ..., 'renewal_deadline': ...} on s... | def get_name_deadlines( self, name_rec, namespace_rec, block_number ):
"""
Get the expiry and renewal deadlines for a (registered) name.
NOTE: expire block here is NOT the block at which the owner loses the name, but the block at which lookups fail.
The name owner has until renewal_dead... |
Given a name and block number, determine if it is in the renewal grace period at that block.
* names in revealed but not ready namespaces are never expired, unless the namespace itself is expired;
* names in ready namespaces enter the grace period once max(ready_block, renew_block) + lifetime - grace_pe... | def is_name_in_grace_period(self, name, block_number):
"""
Given a name and block number, determine if it is in the renewal grace period at that block.
* names in revealed but not ready namespaces are never expired, unless the namespace itself is expired;
* names in ready namespaces ente... |
Given the fully-qualified name, is it registered, not revoked, and not expired
at the current block? | def is_name_registered( self, name ):
"""
Given the fully-qualified name, is it registered, not revoked, and not expired
at the current block?
"""
name_rec = self.get_name( name ) # won't return the name if expired
if name_rec is None:
return False
... |
Given a namespace ID, determine if the namespace is ready
at the current block. | def is_namespace_ready( self, namespace_id ):
"""
Given a namespace ID, determine if the namespace is ready
at the current block.
"""
namespace = self.get_namespace( namespace_id )
if namespace is not None:
return True
else:
return False |
Given a namespace preorder hash, determine if it is preordered
at the current block. | def is_namespace_preordered( self, namespace_id_hash ):
"""
Given a namespace preorder hash, determine if it is preordered
at the current block.
"""
namespace_preorder = self.get_namespace_preorder(namespace_id_hash)
if namespace_preorder is None:
return False... |
Given the name of a namespace, has it been revealed but not made ready
at the current block? | def is_namespace_revealed( self, namespace_id ):
"""
Given the name of a namespace, has it been revealed but not made ready
at the current block?
"""
namespace_reveal = self.get_namespace_reveal( namespace_id )
if namespace_reveal is not None:
return True
... |
Given the fully-qualified name and a sender's script pubkey,
determine if the sender owns the name.
The name must exist and not be revoked or expired at the
current block. | def is_name_owner( self, name, sender_script_pubkey ):
"""
Given the fully-qualified name and a sender's script pubkey,
determine if the sender owns the name.
The name must exist and not be revoked or expired at the
current block.
"""
if not self.is_name_register... |
Given a preorder hash of a name, determine whether or not it is unseen before. | def is_new_preorder( self, preorder_hash, lastblock=None ):
"""
Given a preorder hash of a name, determine whether or not it is unseen before.
"""
if lastblock is None:
lastblock = self.lastblock
preorder = namedb_get_name_preorder( self.db, preorder_hash, lastblock... |
Given a namespace preorder hash, determine whether or not is is unseen before. | def is_new_namespace_preorder( self, namespace_id_hash, lastblock=None ):
"""
Given a namespace preorder hash, determine whether or not is is unseen before.
"""
if lastblock is None:
lastblock = self.lastblock
preorder = namedb_get_namespace_preorder( self.db, names... |
Determine if a name is revoked at this block. | def is_name_revoked( self, name ):
"""
Determine if a name is revoked at this block.
"""
name = self.get_name( name )
if name is None:
return False
if name['revoked']:
return True
else:
return False |
Get the list of txids by value hash | def get_value_hash_txids(self, value_hash):
"""
Get the list of txids by value hash
"""
cur = self.db.cursor()
return namedb_get_value_hash_txids(cur, value_hash) |
Mark a nameop as collided | def nameop_set_collided( cls, nameop, history_id_key, history_id ):
"""
Mark a nameop as collided
"""
nameop['__collided__'] = True
nameop['__collided_history_id_key__'] = history_id_key
nameop['__collided_history_id__'] = history_id |
Record a nameop as collided with another nameop in this block. | def nameop_put_collision( cls, collisions, nameop ):
"""
Record a nameop as collided with another nameop in this block.
"""
# these are supposed to have been put here by nameop_set_collided
history_id_key = nameop.get('__collided_history_id_key__', None)
history_id = name... |
Using the operation data extracted from parsing the virtualchain operation (@op_data),
and the checked, processed operation (@processed_op_data), return a dict that contains
(1) all of the consensus fields to snapshot this operation, and
(2) all of the data fields that we need to store for the n... | def extract_consensus_op(self, opcode, op_data, processed_op_data, current_block_number):
"""
Using the operation data extracted from parsing the virtualchain operation (@op_data),
and the checked, processed operation (@processed_op_data), return a dict that contains
(1) all of the conse... |
Commit an operation, thereby carrying out a state transition.
Returns a dict with the new db record fields | def commit_operation( self, input_op_data, accepted_nameop, current_block_number ):
"""
Commit an operation, thereby carrying out a state transition.
Returns a dict with the new db record fields
"""
# have to have read-write disposition
if self.disposition != DISPOS... |
Given the account info set by a state-create or state-transition or a token-operation,
debit the relevant account.
Do not call this directly.
Return True on success
Abort on error | def commit_account_debit(self, opcode, account_payment_info, current_block_number, current_vtxindex, current_txid):
"""
Given the account info set by a state-create or state-transition or a token-operation,
debit the relevant account.
Do not call this directly.
Return T... |
Given the account info set by a state-create or state-transition or a token-operation,
debit the relevant account.
Do not call this directly.
Return True on success
Abort on error | def commit_account_credit(self, opcode, account_credit_info, current_block_number, current_vtxindex, current_txid):
"""
Given the account info set by a state-create or state-transition or a token-operation,
debit the relevant account.
Do not call this directly.
Return T... |
Commit a state preorder (works for namespace_preorder and name_preorder),
DO NOT CALL THIS DIRECTLY | def commit_state_preorder( self, nameop, current_block_number ):
"""
Commit a state preorder (works for namespace_preorder and name_preorder),
DO NOT CALL THIS DIRECTLY
"""
# have to have read-write disposition
if self.disposition != DISPOSITION_RW:
log.err... |
Commit a state-creation operation (works for name_registration,
namespace_reveal, name_import).
Returns the sequence of dicts of fields to serialize.
DO NOT CALL THIS DIRECTLY | def commit_state_create( self, nameop, current_block_number ):
"""
Commit a state-creation operation (works for name_registration,
namespace_reveal, name_import).
Returns the sequence of dicts of fields to serialize.
DO NOT CALL THIS DIRECTLY
"""
# have to have... |
Commit a state transition (update, transfer, revoke, renew, namespace_ready).
Returns the new canonicalized record (with all compatibility quirks preserved)
DO NOT CALL THIS DIRECTLY | def commit_state_transition( self, nameop, current_block_number ):
"""
Commit a state transition (update, transfer, revoke, renew, namespace_ready).
Returns the new canonicalized record (with all compatibility quirks preserved)
DO NOT CALL THIS DIRECTLY
"""
# h... |
Commit a token operation that debits one account and credits another
Returns the new canonicalized record (with all compatibility quirks preserved)
DO NOT CALL THIS DIRECTLY | def commit_token_operation(self, token_op, current_block_number):
"""
Commit a token operation that debits one account and credits another
Returns the new canonicalized record (with all compatibility quirks preserved)
DO NOT CALL THIS DIRECTLY
"""
# have to have read-wr... |
vest any tokens at this block height | def commit_account_vesting(self, block_height):
"""
vest any tokens at this block height
"""
# save all state
log.debug("Commit all database state before vesting")
self.db.commit()
if block_height in self.vesting:
traceback.print_stack()
l... |
Is a fully-qualified name acceptable?
Return True if so
Return False if not
>>> is_name_valid('abcd')
False
>>> is_name_valid('abcd.')
False
>>> is_name_valid('.abcd')
False
>>> is_name_valid('Abcd.abcd')
False
>>> is_name_valid('abcd.abc.d')
False
>>> is_name_valid(... | def is_name_valid(fqn):
"""
Is a fully-qualified name acceptable?
Return True if so
Return False if not
>>> is_name_valid('abcd')
False
>>> is_name_valid('abcd.')
False
>>> is_name_valid('.abcd')
False
>>> is_name_valid('Abcd.abcd')
False
>>> is_name_valid('abcd.abc.... |
Is a namespace ID valid?
>>> is_namespace_valid('abcd')
True
>>> is_namespace_valid('+abcd')
False
>>> is_namespace_valid('abc.def')
False
>>> is_namespace_valid('.abcd')
False
>>> is_namespace_valid('abcdabcdabcdabcdabcd')
False
>>> is_namespace_valid('abcdabcdabcdabcdabc')... | def is_namespace_valid( namespace_id ):
"""
Is a namespace ID valid?
>>> is_namespace_valid('abcd')
True
>>> is_namespace_valid('+abcd')
False
>>> is_namespace_valid('abc.def')
False
>>> is_namespace_valid('.abcd')
False
>>> is_namespace_valid('abcdabcdabcdabcdabcd')
Fal... |
Tests whether fqa is a fully-qualified subdomain name
@fqa must be a string
If it isn't, returns False, None, None.
If it is, returns True and a tuple (subdomain_name, domain)
>>> is_address_subdomain('abc')
(False, None, None)
>>> is_address_subdomain('abc.def')
(False, None, None)
>>>... | def is_address_subdomain(fqa):
"""
Tests whether fqa is a fully-qualified subdomain name
@fqa must be a string
If it isn't, returns False, None, None.
If it is, returns True and a tuple (subdomain_name, domain)
>>> is_address_subdomain('abc')
(False, None, None)
>>> is_address_subdomain... |
Get a name's price in Stacks, regardless of whether or not
the namespace it was created in was created before Stacks
existed. This is because any name can be purchased with
Stacks. If the namespace price curve was meant for BTC
(per its version bits), then the BTC price will be converted
to the S... | def price_name_stacks(name, namespace, block_height):
"""
Get a name's price in Stacks, regardless of whether or not
the namespace it was created in was created before Stacks
existed. This is because any name can be purchased with
Stacks. If the namespace price curve was meant for BTC
(per it... |
Calculate the price of a name (without its namespace ID), given the
namespace parameters.
The minimum price is NAME_COST_UNIT (or NAME_COST_UNIT_STACKS)
This method returns an integer in the *current* epoch,
but it will return a float in previous epochs for backwards
compatibility. The units are ... | def price_name(name, namespace, block_height):
"""
Calculate the price of a name (without its namespace ID), given the
namespace parameters.
The minimum price is NAME_COST_UNIT (or NAME_COST_UNIT_STACKS)
This method returns an integer in the *current* epoch,
but it will return a float in previ... |
Calculate the cost of a namespace.
Returns the price on success
Returns None if the namespace is invalid or if the units are invalid | def price_namespace( namespace_id, block_height, units ):
"""
Calculate the cost of a namespace.
Returns the price on success
Returns None if the namespace is invalid or if the units are invalid
"""
price_table = get_epoch_namespace_prices( block_height, units )
if price_table is None:
... |
Given all previously-accepted operations in this block,
find the ones that are of a particular opcode.
@opcode can be one opcode, or a list of opcodes
>>> find_by_opcode([{'op': '+'}, {'op': '>'}], 'NAME_UPDATE')
[{'op': '+'}]
>>> find_by_opcode([{'op': '+'}, {'op': '>'}], ['NAME_UPDATE', 'NAM... | def find_by_opcode( checked_ops, opcode ):
"""
Given all previously-accepted operations in this block,
find the ones that are of a particular opcode.
@opcode can be one opcode, or a list of opcodes
>>> find_by_opcode([{'op': '+'}, {'op': '>'}], 'NAME_UPDATE')
[{'op': '+'}]
>>> find_by_... |
Given a list of inputs and the address of one of the inputs,
find the public key.
This only works for p2pkh scripts.
We only really need this for NAMESPACE_REVEAL, but we included
it in other transactions' consensus data for legacy reasons that
now have to be supported forever :( | def get_public_key_hex_from_tx( inputs, address ):
"""
Given a list of inputs and the address of one of the inputs,
find the public key.
This only works for p2pkh scripts.
We only really need this for NAMESPACE_REVEAL, but we included
it in other transactions' consensus data for legacy reason... |
Verify the name is well-formed
>>> check_name(123)
False
>>> check_name('')
False
>>> check_name('abc')
False
>>> check_name('abc.def')
True
>>> check_name('abc.def.ghi')
False
>>> check_name('abc.d-ef')
True
>>> check_name('abc.d+ef')
False
>>> check_name('.... | def check_name(name):
"""
Verify the name is well-formed
>>> check_name(123)
False
>>> check_name('')
False
>>> check_name('abc')
False
>>> check_name('abc.def')
True
>>> check_name('abc.def.ghi')
False
>>> check_name('abc.d-ef')
True
>>> check_name('abc.d+ef... |
Verify that a namespace ID is well-formed
>>> check_namespace(123)
False
>>> check_namespace(None)
False
>>> check_namespace('')
False
>>> check_namespace('abcd')
True
>>> check_namespace('Abcd')
False
>>> check_namespace('a+bcd')
False
>>> check_namespace('.abcd')
... | def check_namespace(namespace_id):
"""
Verify that a namespace ID is well-formed
>>> check_namespace(123)
False
>>> check_namespace(None)
False
>>> check_namespace('')
False
>>> check_namespace('abcd')
True
>>> check_namespace('Abcd')
False
>>> check_namespace('a+bcd... |
Verify that a token type is well-formed
>>> check_token_type('STACKS')
True
>>> check_token_type('BTC')
False
>>> check_token_type('abcdabcdabcd')
True
>>> check_token_type('abcdabcdabcdabcdabcd')
False | def check_token_type(token_type):
"""
Verify that a token type is well-formed
>>> check_token_type('STACKS')
True
>>> check_token_type('BTC')
False
>>> check_token_type('abcdabcdabcd')
True
>>> check_token_type('abcdabcdabcdabcdabcd')
False
"""
return check_string(token_... |
Verify that the given fqn is a subdomain
>>> check_subdomain('a.b.c')
True
>>> check_subdomain(123)
False
>>> check_subdomain('a.b.c.d')
False
>>> check_subdomain('A.b.c')
False
>>> check_subdomain('abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.a.b')
True
>>> check_subdom... | def check_subdomain(fqn):
"""
Verify that the given fqn is a subdomain
>>> check_subdomain('a.b.c')
True
>>> check_subdomain(123)
False
>>> check_subdomain('a.b.c.d')
False
>>> check_subdomain('A.b.c')
False
>>> check_subdomain('abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdab... |
Verify that a block ID is valid
>>> check_block(FIRST_BLOCK_MAINNET)
True
>>> check_block(FIRST_BLOCK_MAINNET-1)
False
>>> check_block(-1)
False
>>> check_block("abc")
False
>>> check_block(int(1e7) + 1)
False
>>> check_block(int(1e7) - 1)
True | def check_block(block_id):
"""
Verify that a block ID is valid
>>> check_block(FIRST_BLOCK_MAINNET)
True
>>> check_block(FIRST_BLOCK_MAINNET-1)
False
>>> check_block(-1)
False
>>> check_block("abc")
False
>>> check_block(int(1e7) + 1)
False
>>> check_block(int(1e7) -... |
Verify that an offset is valid
>>> check_offset(0)
True
>>> check_offset(-1)
False
>>> check_offset(2, max_value=2)
True
>>> check_offset(0)
True
>>> check_offset(2, max_value=1)
False
>>> check_offset('abc')
False | def check_offset(offset, max_value=None):
"""
Verify that an offset is valid
>>> check_offset(0)
True
>>> check_offset(-1)
False
>>> check_offset(2, max_value=2)
True
>>> check_offset(0)
True
>>> check_offset(2, max_value=1)
False
>>> check_offset('abc')
False
... |
verify that a count is valid
>>> check_count(None)
False
>>> check_count('abc')
False
>>> check_count({})
False
>>> check_count([])
False
>>> check_count(True)
False
>>> check_count(0)
True
>>> check_count(-1)
False
>>> check_count(1)
True
>>> che... | def check_count(count, max_value=None):
"""
verify that a count is valid
>>> check_count(None)
False
>>> check_count('abc')
False
>>> check_count({})
False
>>> check_count([])
False
>>> check_count(True)
False
>>> check_count(0)
True
>>> check_count(-1)
... |
verify that a string has a particular size and conforms
to a particular alphabet
>>> check_string(1)
False
>>> check_string(None)
False
>>> check_string(True)
False
>>> check_string({})
False
>>> check_string([])
False
>>> check_string((1,2))
False
>>> check_stri... | def check_string(value, min_length=None, max_length=None, pattern=None):
"""
verify that a string has a particular size and conforms
to a particular alphabet
>>> check_string(1)
False
>>> check_string(None)
False
>>> check_string(True)
False
>>> check_string({})
False
>>... |
verify that a string is a base58check address
>>> check_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg')
True
>>> check_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJh')
False
>>> check_address('mkkJsS22dnDJhD8duFkpGnHNr9uz3JEcWu')
True
>>> check_address('mkkJsS22dnDJhD8duFkpGnHNr9uz3JEcWv')
F... | def check_address(address):
"""
verify that a string is a base58check address
>>> check_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg')
True
>>> check_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJh')
False
>>> check_address('mkkJsS22dnDJhD8duFkpGnHNr9uz3JEcWu')
True
>>> check_address('mk... |
verify that a string is a valid account address.
Can be a b58-check address, a c32-check address, as well as the string "treasury" or "unallocated" or a string starting with 'not_distributed_'
>>> check_account_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg')
True
>>> check_account_address('16EMaNw3pkn3v6... | def check_account_address(address):
"""
verify that a string is a valid account address.
Can be a b58-check address, a c32-check address, as well as the string "treasury" or "unallocated" or a string starting with 'not_distributed_'
>>> check_account_address('16EMaNw3pkn3v6f2BgnSSs53zAKH4Q8YJg')
Tr... |
Verify that the list of transaction outputs are acceptable | def check_tx_output_types(outputs, block_height):
"""
Verify that the list of transaction outputs are acceptable
"""
# for now, we do not allow nonstandard outputs (all outputs must be p2pkh or p2sh outputs)
# this excludes bech32 outputs, for example.
supported_output_types = get_epoch_btc_scri... |
Verify that the list of transaction senders are acceptable
* a sender should have 1 address
* that address should match the epoch's supported sender types | def check_tx_sender_types(senders, block_height):
"""
Verify that the list of transaction senders are acceptable
* a sender should have 1 address
* that address should match the epoch's supported sender types
"""
supported_sender_types = get_epoch_btc_sender_types(block_height)
for sender in... |
Given a b58check or c32check address,
return the b58check encoding | def address_as_b58(addr):
"""
Given a b58check or c32check address,
return the b58check encoding
"""
if is_c32_address(addr):
return c32ToB58(addr)
else:
if check_address(addr):
return addr
else:
raise ValueError('Address {} is not b58 or c32'.for... |
Translates from api_calls dictionary [returned from get_api_calls()]
into a markdown spec (i.e., docs/api-specs.md)
$ python -c "from api.utils import *; f = open('/tmp/foo', 'w'); write_markdown_spec(f, get_api_calls('api/api_v1.md')); f.close()" | def write_markdown_spec(f_out, api_calls):
"""
Translates from api_calls dictionary [returned from get_api_calls()]
into a markdown spec (i.e., docs/api-specs.md)
$ python -c "from api.utils import *; f = open('/tmp/foo', 'w'); write_markdown_spec(f, get_api_calls('api/api_v1.md')); f.close()"
"""
... |
Decode a serialized zone file into a zonefile structure that could contain subdomain info.
Ignore duplicate subdomains. The subdomain with the lower sequence number will be accepted.
In the event of a tie, the *first* subdomain will be accepted
Returns the list of subdomain operations, as Subdomain object... | def decode_zonefile_subdomains(domain, zonefile_txt, block_height, zonefile_index, txid):
"""
Decode a serialized zone file into a zonefile structure that could contain subdomain info.
Ignore duplicate subdomains. The subdomain with the lower sequence number will be accepted.
In the event of a tie, the... |
Verify that a given plaintext is signed by the given scriptSig, given the address | def verify(address, plaintext, scriptSigb64):
"""
Verify that a given plaintext is signed by the given scriptSig, given the address
"""
assert isinstance(address, str)
assert isinstance(scriptSigb64, str)
scriptSig = base64.b64decode(scriptSigb64)
hash_hex = hashlib.sha256(plaintext).hexdig... |
Verify that a p2pkh address is signed by the given pay-to-pubkey-hash scriptsig | def verify_singlesig(address, hash_hex, scriptSig):
"""
Verify that a p2pkh address is signed by the given pay-to-pubkey-hash scriptsig
"""
try:
sighex, pubkey_hex = virtualchain.btc_script_deserialize(scriptSig)
except:
log.warn("Wrong signature structure for {}".format(address))
... |
verify that a p2sh address is signed by the given scriptsig | def verify_multisig(address, hash_hex, scriptSig):
"""
verify that a p2sh address is signed by the given scriptsig
"""
script_parts = virtualchain.btc_script_deserialize(scriptSig)
if len(script_parts) < 2:
log.warn("Verfiying multisig failed, couldn't grab script parts")
return Fals... |
Does a given parsed zone file TXT record encode a missing-zonefile vector?
Return True if so
Return False if not | def is_subdomain_missing_zonefiles_record(rec):
"""
Does a given parsed zone file TXT record encode a missing-zonefile vector?
Return True if so
Return False if not
"""
if rec['name'] != SUBDOMAIN_TXT_RR_MISSING:
return False
txt_entry = rec['txt']
if isinstance(txt_entry, list)... |
Does a given parsed zone file TXT record (@rec) encode a subdomain?
Return True if so
Return False if not | def is_subdomain_record(rec):
"""
Does a given parsed zone file TXT record (@rec) encode a subdomain?
Return True if so
Return False if not
"""
txt_entry = rec['txt']
if not isinstance(txt_entry, list):
return False
has_parts_entry = False
has_pk_entry = False
has_seqn_e... |
Static method for getting the state of a subdomain, given its fully-qualified name.
Return the subdomain record on success.
Return None if not found. | def get_subdomain_info(fqn, db_path=None, atlasdb_path=None, zonefiles_dir=None, check_pending=False, include_did=False):
"""
Static method for getting the state of a subdomain, given its fully-qualified name.
Return the subdomain record on success.
Return None if not found.
"""
opts = get_block... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.