Rename backend implementation decorators to be aligned with their action of registering functions

This commit is contained in:
Brett Sun 2016-12-06 10:01:45 +01:00 committed by Sylvain Bellemare
parent 6e14a63291
commit eda1c1bf55
2 changed files with 29 additions and 29 deletions

View File

@ -13,10 +13,10 @@ from bigchaindb.backend.rethinkdb.connection import RethinkDBConnection
READ_MODE = 'majority'
WRITE_DURABILITY = 'hard'
query_dispatch = make_module_dispatch_registrar(backend.query)
register_query = make_module_dispatch_registrar(backend.query)
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def write_transaction(connection, signed_transaction):
"""Write a transaction to the backlog table.
@ -32,7 +32,7 @@ def write_transaction(connection, signed_transaction):
.insert(signed_transaction, durability=WRITE_DURABILITY))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def update_transaction(connection, transaction_id, doc):
"""Update a transaction in the backlog table.
@ -50,7 +50,7 @@ def update_transaction(connection, transaction_id, doc):
.update(doc))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def delete_transaction(connection, *transaction_id):
"""Delete a transaction from the backlog.
@ -67,7 +67,7 @@ def delete_transaction(connection, *transaction_id):
.delete(durability=WRITE_DURABILITY))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_stale_transactions(connection, reassign_delay):
"""Get a cursor of stale transactions.
@ -87,7 +87,7 @@ def get_stale_transactions(connection, reassign_delay):
.filter(lambda tx: time() - tx['assignment_timestamp'] > reassign_delay))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_transaction_from_block(connection, transaction_id, block_id):
"""Get a transaction from a specific block.
@ -106,7 +106,7 @@ def get_transaction_from_block(connection, transaction_id, block_id):
.filter(lambda tx: tx['id'] == transaction_id))[0]
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_transaction_from_backlog(connection, transaction_id):
"""Get a transaction from backlog.
@ -123,7 +123,7 @@ def get_transaction_from_backlog(connection, transaction_id):
.default(None))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_blocks_status_from_transaction(connection, transaction_id):
"""Retrieve block election information given a secondary index and value
@ -141,7 +141,7 @@ def get_blocks_status_from_transaction(connection, transaction_id):
.pluck('votes', 'id', {'block': ['voters']}))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_txids_by_metadata_id(connection, metadata_id):
"""Retrieves transaction ids related to a particular metadata.
@ -169,7 +169,7 @@ def get_txids_by_metadata_id(connection, metadata_id):
.get_field('id'))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_txids_by_asset_id(connection, asset_id):
"""Retrieves transactions ids related to a particular asset.
@ -195,7 +195,7 @@ def get_txids_by_asset_id(connection, asset_id):
.get_field('id'))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_asset_by_id(connection, asset_id):
"""Returns the asset associated with an asset_id.
@ -216,7 +216,7 @@ def get_asset_by_id(connection, asset_id):
.pluck({'transaction': 'asset'}))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_spent(connection, transaction_id, condition_id):
"""Check if a `txid` was already used as an input.
@ -239,7 +239,7 @@ def get_spent(connection, transaction_id, condition_id):
lambda fulfillment: fulfillment['input'] == {'txid': transaction_id, 'cid': condition_id})))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_owned_ids(connection, owner):
"""Retrieve a list of `txids` that can we used has inputs.
@ -258,7 +258,7 @@ def get_owned_ids(connection, owner):
lambda c: c['owners_after'].contains(owner))))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_votes_by_block_id(connection, block_id):
"""Get all the votes casted for a specific block.
@ -273,7 +273,7 @@ def get_votes_by_block_id(connection, block_id):
.between([block_id, r.minval], [block_id, r.maxval], index='block_and_voter'))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_votes_by_block_id_and_voter(connection, block_id, node_pubkey):
"""Get all the votes casted for a specific block by a specific voter.
@ -289,7 +289,7 @@ def get_votes_by_block_id_and_voter(connection, block_id, node_pubkey):
.get_all([block_id, node_pubkey], index='block_and_voter'))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def write_block(connection, block):
"""Write a block to the bigchain table.
@ -304,7 +304,7 @@ def write_block(connection, block):
.insert(r.json(block), durability=WRITE_DURABILITY))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_block(connection, block_id):
"""Get a block from the bigchain table
@ -317,7 +317,7 @@ def get_block(connection, block_id):
return connection.run(r.table('bigchain').get(block_id))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def has_transaction(connection, transaction_id):
"""Check if a transaction exists in the bigchain table.
@ -332,7 +332,7 @@ def has_transaction(connection, transaction_id):
.get_all(transaction_id, index='transaction_id').count()))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def count_blocks(connection):
"""Count the number of blocks in the bigchain table.
@ -345,7 +345,7 @@ def count_blocks(connection):
.count())
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def count_backlog(connection):
"""Count the number of transactions in the backlog table.
@ -358,7 +358,7 @@ def count_backlog(connection):
.count())
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def write_vote(connection, vote):
"""Write a vote to the votes table.
@ -373,7 +373,7 @@ def write_vote(connection, vote):
.insert(vote))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_genesis_block(connection):
"""Get the genesis block
@ -386,7 +386,7 @@ def get_genesis_block(connection):
.nth(0))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_last_voted_block(connection, node_pubkey):
"""Get the last voted block for a specific node.
@ -448,7 +448,7 @@ def get_last_voted_block(connection, node_pubkey):
.get(last_block_id))
@query_dispatch(RethinkDBConnection)
@register_query(RethinkDBConnection)
def get_unvoted_blocks(connection, node_pubkey):
"""Return all the blocks that have not been voted by the specified node.

View File

@ -11,10 +11,10 @@ from bigchaindb.backend.rethinkdb.connection import RethinkDBConnection
logger = logging.getLogger(__name__)
schema_dispatch = make_module_dispatch_registrar(backend.schema)
register_schema = make_module_dispatch_registrar(backend.schema)
@schema_dispatch(RethinkDBConnection)
@register_schema(RethinkDBConnection)
def create_database(connection, name):
if connection.run(r.db_list().contains(name)):
raise exceptions.DatabaseAlreadyExists('Database `{}` already exists'.format(name))
@ -23,21 +23,21 @@ def create_database(connection, name):
connection.run(r.db_create(name))
@schema_dispatch(RethinkDBConnection)
@register_schema(RethinkDBConnection)
def create_tables(connection, name):
for table_name in ['bigchain', 'backlog', 'votes']:
logger.info('Create `%s` table.', table_name)
connection.run(r.db(name).table_create(table_name))
@schema_dispatch(RethinkDBConnection)
@register_schema(RethinkDBConnection)
def create_indexes(connection, name):
create_bigchain_secondary_index(connection, name)
create_backlog_secondary_index(connection, name)
create_votes_secondary_index(connection, name)
@schema_dispatch(RethinkDBConnection)
@register_schema(RethinkDBConnection)
def drop_database(connection, name):
try:
logger.info('Drop database `%s`', name)