From ce414e46f3da825143c7df3c72295a68f61f073d Mon Sep 17 00:00:00 2001 From: Rodolphe Marques Date: Thu, 11 May 2017 12:29:08 +0200 Subject: [PATCH] Added missing docstrings. Fixed typos. --- bigchaindb/backend/query.py | 4 ++-- bigchaindb/core.py | 18 +++++++++++++++++- bigchaindb/models.py | 22 +++++++++++++++++++--- tests/test_block_model.py | 2 +- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/bigchaindb/backend/query.py b/bigchaindb/backend/query.py index 5c37647c..8245fb3d 100644 --- a/bigchaindb/backend/query.py +++ b/bigchaindb/backend/query.py @@ -293,8 +293,8 @@ def get_last_voted_block_id(connection, node_pubkey): node_pubkey (str): base58 encoded public key. Returns: - The last block the node has voted on. If the node didn't cast - any vote then the genesis block is returned. + The last block id the node has voted on. If the node didn't cast + any vote then the genesis block id is returned. """ raise NotImplementedError diff --git a/bigchaindb/core.py b/bigchaindb/core.py index c6ff5608..1cd21222 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -641,8 +641,24 @@ class Bigchain(object): return self.block_election(block)['status'] def get_assets(self, asset_ids): - # TODO: write docstrings + """ + Return a list of assets that match the asset_ids + + Args: + asset_ids (:obj:`list` of :obj:`str`): A list of asset_ids to + retrieve from the database. + + Returs: + list: The list of assets returned from the database. + """ return backend.query.get_assets(self.connection, asset_ids) def write_assets(self, assets): + """ + Writes a list of assets into the database. + + Args: + assets (:obj:`list` of :obj:`dict`): A list of assets to write to + the database. + """ return backend.query.write_assets(self.connection, assets) diff --git a/bigchaindb/models.py b/bigchaindb/models.py index 53266930..c77c3338 100644 --- a/bigchaindb/models.py +++ b/bigchaindb/models.py @@ -88,8 +88,22 @@ class Transaction(Transaction): @classmethod def from_db(cls, bigchain, tx_dict): - # TODO: write docstring - if tx_dict['operation'] in [Transaction.CREATE, Transaction.CREATE]: + """ + Helper method that reconstructs a transaction dict that was returned + from the database. It checks what asset_id to retrieve, retrieves the + asset from the asset table and reconstructs the transaction. + + Args: + bigchain (:class:`~bigchaindb.Bigchain`): An instance of Bigchain + used to perform database queries. + tx_dict (:obj:`dict`): The transaction dict as returned from the + database. + + Returns: + :class:`~Transaction` + + """ + if tx_dict['operation'] in [Transaction.CREATE, Transaction.GENESIS]: # TODO: Maybe replace this call to a call to get_asset_by_id asset = list(bigchain.get_assets([tx_dict['id']]))[0] asset.pop('id') @@ -317,12 +331,14 @@ class Block(object): def from_db(cls, bigchain, block_dict): """ Helper method that reconstructs a block_dict that was returned from - the database. If checks what asset_ids to retrieve, retrieves the + the database. It checks what asset_ids to retrieve, retrieves the assets from the assets table and reconstructs the block. Args: bigchain (:class:`~bigchaindb.Bigchain`): An instance of Bigchain used to perform database queries. + block_dict(:obj:`dict`): The block dict as returned from the + database. Returns: :class:`~Block` diff --git a/tests/test_block_model.py b/tests/test_block_model.py index f2b307de..0824c40f 100644 --- a/tests/test_block_model.py +++ b/tests/test_block_model.py @@ -281,7 +281,7 @@ class TestBlockModel(object): # decouple assets assets_from_block, block_dict = block.decouple_assets() - # write the assets and block separatedly + # write the assets and block separately b.write_assets(assets_from_block) b.write_block(block)