mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Fix docstring formatting
This commit is contained in:
parent
cdf63ef151
commit
0f3a15ba6e
@ -76,6 +76,7 @@ class Bigchain(object):
|
|||||||
|
|
||||||
Refer to the documentation of ``bigchaindb.util.sign_tx``
|
Refer to the documentation of ``bigchaindb.util.sign_tx``
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return util.sign_tx(transaction, private_key)
|
return util.sign_tx(transaction, private_key)
|
||||||
|
|
||||||
def verify_signature(self, signed_transaction):
|
def verify_signature(self, signed_transaction):
|
||||||
@ -88,8 +89,8 @@ class Bigchain(object):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True if the signature is correct, False otherwise.
|
bool: True if the signature is correct, False otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = signed_transaction.copy()
|
data = signed_transaction.copy()
|
||||||
|
|
||||||
# if assignee field in the transaction, remove it
|
# if assignee field in the transaction, remove it
|
||||||
@ -143,8 +144,8 @@ class Bigchain(object):
|
|||||||
A dict with the transaction details if the transaction was found.
|
A dict with the transaction details if the transaction was found.
|
||||||
|
|
||||||
If no transaction with that `txid` was found it returns `None`
|
If no transaction with that `txid` was found it returns `None`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
response = r.table('bigchain').concat_map(lambda doc: doc['block']['transactions'])\
|
response = r.table('bigchain').concat_map(lambda doc: doc['block']['transactions'])\
|
||||||
.filter(lambda transaction: transaction['id'] == txid).run(self.conn)
|
.filter(lambda transaction: transaction['id'] == txid).run(self.conn)
|
||||||
|
|
||||||
@ -174,8 +175,8 @@ class Bigchain(object):
|
|||||||
Returns:
|
Returns:
|
||||||
A list of transactions containing that payload. If no transaction exists with that payload it
|
A list of transactions containing that payload. If no transaction exists with that payload it
|
||||||
returns `None`
|
returns `None`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cursor = r.table('bigchain')\
|
cursor = r.table('bigchain')\
|
||||||
.get_all(payload_hash, index='payload_hash')\
|
.get_all(payload_hash, index='payload_hash')\
|
||||||
.run(self.conn)
|
.run(self.conn)
|
||||||
@ -194,7 +195,6 @@ class Bigchain(object):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The transaction that used the `txid` as an input if it exists else it returns `None`
|
The transaction that used the `txid` as an input if it exists else it returns `None`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# checks if an input was already spent
|
# checks if an input was already spent
|
||||||
@ -221,8 +221,8 @@ class Bigchain(object):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: list of `txids` currently owned by `owner`
|
list: list of `txids` currently owned by `owner`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
response = r.table('bigchain')\
|
response = r.table('bigchain')\
|
||||||
.concat_map(lambda doc: doc['block']['transactions'])\
|
.concat_map(lambda doc: doc['block']['transactions'])\
|
||||||
.filter({'transaction': {'new_owner': owner}})\
|
.filter({'transaction': {'new_owner': owner}})\
|
||||||
@ -255,6 +255,7 @@ class Bigchain(object):
|
|||||||
InvalidHash: if the hash of the transaction is wrong
|
InvalidHash: if the hash of the transaction is wrong
|
||||||
InvalidSignature: if the signature of the transaction is wrong
|
InvalidSignature: if the signature of the transaction is wrong
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# If the operation is CREATE the transaction should have no inputs and should be signed by a
|
# If the operation is CREATE the transaction should have no inputs and should be signed by a
|
||||||
# federation node
|
# federation node
|
||||||
if transaction['transaction']['operation'] == 'CREATE':
|
if transaction['transaction']['operation'] == 'CREATE':
|
||||||
@ -304,8 +305,8 @@ class Bigchain(object):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: `True` if the transaction is valid, `False` otherwise
|
bool: `True` if the transaction is valid, `False` otherwise
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.validate_transaction(transaction)
|
self.validate_transaction(transaction)
|
||||||
return transaction
|
return transaction
|
||||||
@ -325,8 +326,8 @@ class Bigchain(object):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: created block.
|
dict: created block.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Create the new block
|
# Create the new block
|
||||||
block = {
|
block = {
|
||||||
'timestamp': util.timestamp(),
|
'timestamp': util.timestamp(),
|
||||||
@ -359,7 +360,6 @@ class Bigchain(object):
|
|||||||
Returns:
|
Returns:
|
||||||
The block if the block is valid else it raises and exception
|
The block if the block is valid else it raises and exception
|
||||||
describing the reason why the block is invalid.
|
describing the reason why the block is invalid.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# 1. Check if current hash is correct
|
# 1. Check if current hash is correct
|
||||||
@ -385,8 +385,8 @@ class Bigchain(object):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: `True` if the block is valid, `False` otherwise.
|
bool: `True` if the block is valid, `False` otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.validate_block(block)
|
self.validate_block(block)
|
||||||
return True
|
return True
|
||||||
@ -398,8 +398,8 @@ class Bigchain(object):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
block (dict): block to write to bigchain.
|
block (dict): block to write to bigchain.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
block_serialized = rapidjson.dumps(block)
|
block_serialized = rapidjson.dumps(block)
|
||||||
r.table('bigchain').insert(r.json(block_serialized), durability=durability).run(self.conn)
|
r.table('bigchain').insert(r.json(block_serialized), durability=durability).run(self.conn)
|
||||||
|
|
||||||
@ -448,8 +448,8 @@ class Bigchain(object):
|
|||||||
previous_block_id (str): The id of the previous block.
|
previous_block_id (str): The id of the previous block.
|
||||||
decision (bool): Whether the block is valid or invalid.
|
decision (bool): Whether the block is valid or invalid.
|
||||||
invalid_reason (Optional[str]): Reason the block is invalid
|
invalid_reason (Optional[str]): Reason the block is invalid
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
vote = {
|
vote = {
|
||||||
'voting_for_block': block['id'],
|
'voting_for_block': block['id'],
|
||||||
'previous_block': previous_block_id,
|
'previous_block': previous_block_id,
|
||||||
@ -470,9 +470,8 @@ class Bigchain(object):
|
|||||||
return vote_signed
|
return vote_signed
|
||||||
|
|
||||||
def write_vote(self, block, vote, block_number):
|
def write_vote(self, block, vote, block_number):
|
||||||
"""
|
"""Write the vote to the database."""
|
||||||
Write the vote to the database
|
|
||||||
"""
|
|
||||||
update = {'votes': r.row['votes'].append(vote)}
|
update = {'votes': r.row['votes'].append(vote)}
|
||||||
|
|
||||||
# We need to *not* override the existing block_number, if any
|
# We need to *not* override the existing block_number, if any
|
||||||
@ -486,9 +485,8 @@ class Bigchain(object):
|
|||||||
.run(self.conn)
|
.run(self.conn)
|
||||||
|
|
||||||
def get_last_voted_block(self):
|
def get_last_voted_block(self):
|
||||||
"""
|
"""Returns the last block that this node voted on."""
|
||||||
Returns the last block that this node voted on
|
|
||||||
"""
|
|
||||||
# query bigchain for all blocks this node is a voter but didn't voted on
|
# query bigchain for all blocks this node is a voter but didn't voted on
|
||||||
last_voted = r.table('bigchain')\
|
last_voted = r.table('bigchain')\
|
||||||
.filter(r.row['block']['voters'].contains(self.me))\
|
.filter(r.row['block']['voters'].contains(self.me))\
|
||||||
@ -507,9 +505,7 @@ class Bigchain(object):
|
|||||||
return last_voted[0]
|
return last_voted[0]
|
||||||
|
|
||||||
def get_unvoted_blocks(self):
|
def get_unvoted_blocks(self):
|
||||||
"""
|
"""Return all the blocks that has not been voted by this node."""
|
||||||
Return all the blocks that has not been voted by this node.
|
|
||||||
"""
|
|
||||||
|
|
||||||
unvoted = r.table('bigchain')\
|
unvoted = r.table('bigchain')\
|
||||||
.filter(lambda doc: doc['votes'].contains(lambda vote: vote['node_pubkey'] == self.me).not_())\
|
.filter(lambda doc: doc['votes'].contains(lambda vote: vote['node_pubkey'] == self.me).not_())\
|
||||||
@ -531,8 +527,8 @@ class Bigchain(object):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: dict resulting from the serialization of a JSON formatted string.
|
dict: dict resulting from the serialization of a JSON formatted string.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return json.loads(data, encoding="utf-8")
|
return json.loads(data, encoding="utf-8")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -542,7 +538,7 @@ class Bigchain(object):
|
|||||||
Returns:
|
Returns:
|
||||||
tuple: `(private_key, public_key)`. ECDSA key pair using the secp256k1 curve encoded
|
tuple: `(private_key, public_key)`. ECDSA key pair using the secp256k1 curve encoded
|
||||||
in base58.
|
in base58.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# generates and returns the keys serialized in hex
|
# generates and returns the keys serialized in hex
|
||||||
return generate_key_pair()
|
return generate_key_pair()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user