code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def run(self, instance):
"""Run the recorded chain of methods on `instance`.
Args:
instance: an object.
"""
last = instance
for item in self.stack:
if isinstance(item, str):
last = getattr(last, item)
else:
la... | Run the recorded chain of methods on `instance`.
Args:
instance: an object.
| run | python | bigchaindb/bigchaindb | bigchaindb/utils.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/utils.py | Apache-2.0 |
def tendermint_version_is_compatible(running_tm_ver):
"""
Check Tendermint compatability with BigchainDB server
:param running_tm_ver: Version number of the connected Tendermint instance
:type running_tm_ver: str
:return: True/False depending on the compatability with BigchainDB server
:rtype: ... |
Check Tendermint compatability with BigchainDB server
:param running_tm_ver: Version number of the connected Tendermint instance
:type running_tm_ver: str
:return: True/False depending on the compatability with BigchainDB server
:rtype: bool
| tendermint_version_is_compatible | python | bigchaindb/bigchaindb | bigchaindb/utils.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/utils.py | Apache-2.0 |
def connect(backend=None, host=None, port=None, name=None, max_tries=None,
connection_timeout=None, replicaset=None, ssl=None, login=None, password=None,
ca_cert=None, certfile=None, keyfile=None, keyfile_passphrase=None,
crlfile=None):
"""Create a new connection to the database ... | Create a new connection to the database backend.
All arguments default to the current configuration's values if not
given.
Args:
backend (str): the name of the backend to use.
host (str): the host to connect to.
port (int): the port to connect to.
name (str): the name of th... | connect | python | bigchaindb/bigchaindb | bigchaindb/backend/connection.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/backend/connection.py | Apache-2.0 |
def __init__(self, host=None, port=None, dbname=None,
connection_timeout=None, max_tries=None,
**kwargs):
"""Create a new :class:`~.Connection` instance.
Args:
host (str): the host to connect to.
port (int): the port to connect to.
d... | Create a new :class:`~.Connection` instance.
Args:
host (str): the host to connect to.
port (int): the port to connect to.
dbname (str): the name of the database to use.
connection_timeout (int, optional): the milliseconds to wait
until timing out... | __init__ | python | bigchaindb/bigchaindb | bigchaindb/backend/connection.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/backend/connection.py | Apache-2.0 |
def init_database(connection=None, dbname=None):
"""Initialize the configured backend for use with BigchainDB.
Creates a database with :attr:`dbname` with any required tables
and supporting indexes.
Args:
connection (:class:`~bigchaindb.backend.connection.Connection`): an
existing ... | Initialize the configured backend for use with BigchainDB.
Creates a database with :attr:`dbname` with any required tables
and supporting indexes.
Args:
connection (:class:`~bigchaindb.backend.connection.Connection`): an
existing connection to use to initialize the database.
... | init_database | python | bigchaindb/bigchaindb | bigchaindb/backend/schema.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/backend/schema.py | Apache-2.0 |
def validate_language_key(obj, key):
"""Validate all nested "language" key in `obj`.
Args:
obj (dict): dictionary whose "language" key is to be validated.
Returns:
None: validation successful
Raises:
ValidationError: will raise exception in case language is... | Validate all nested "language" key in `obj`.
Args:
obj (dict): dictionary whose "language" key is to be validated.
Returns:
None: validation successful
Raises:
ValidationError: will raise exception in case language is not valid.
| validate_language_key | python | bigchaindb/bigchaindb | bigchaindb/backend/schema.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/backend/schema.py | Apache-2.0 |
def validate_language(value):
"""Check if `value` is a valid language.
https://docs.mongodb.com/manual/reference/text-search-languages/
Args:
value (str): language to validated
Returns:
None: validation successful
Raises:
ValidationError: will ra... | Check if `value` is a valid language.
https://docs.mongodb.com/manual/reference/text-search-languages/
Args:
value (str): language to validated
Returns:
None: validation successful
Raises:
ValidationError: will raise exception in case language is not... | validate_language | python | bigchaindb/bigchaindb | bigchaindb/backend/schema.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/backend/schema.py | Apache-2.0 |
def __init__(self, replicaset=None, ssl=None, login=None, password=None,
ca_cert=None, certfile=None, keyfile=None,
keyfile_passphrase=None, crlfile=None, **kwargs):
"""Create a new Connection instance.
Args:
replicaset (str, optional): the name of the repl... | Create a new Connection instance.
Args:
replicaset (str, optional): the name of the replica set to
connect to.
**kwargs: arbitrary keyword arguments provided by the
configuration's ``database`` settings
| __init__ | python | bigchaindb/bigchaindb | bigchaindb/backend/localmongodb/connection.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/backend/localmongodb/connection.py | Apache-2.0 |
def _connect(self):
"""Try to connect to the database.
Raises:
:exc:`~ConnectionError`: If the connection to the database
fails.
:exc:`~AuthenticationError`: If there is a OperationFailure due to
Authentication failure after connecting to the data... | Try to connect to the database.
Raises:
:exc:`~ConnectionError`: If the connection to the database
fails.
:exc:`~AuthenticationError`: If there is a OperationFailure due to
Authentication failure after connecting to the database.
:exc:`~Config... | _connect | python | bigchaindb/bigchaindb | bigchaindb/backend/localmongodb/connection.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/backend/localmongodb/connection.py | Apache-2.0 |
def run_configure(args):
"""Run a script to configure the current node."""
config_path = args.config or bigchaindb.config_utils.CONFIG_DEFAULT_PATH
config_file_exists = False
# if the config path is `-` then it's stdout
if config_path != '-':
config_file_exists = os.path.exists(config_path)... | Run a script to configure the current node. | run_configure | python | bigchaindb/bigchaindb | bigchaindb/commands/bigchaindb.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/commands/bigchaindb.py | Apache-2.0 |
def run_election_new_upsert_validator(args, bigchain):
"""Initiates an election to add/update/remove a validator to an existing BigchainDB network
:param args: dict
args = {
'public_key': the public key of the proposed peer, (str)
'power': the proposed validator power for the new peer, ... | Initiates an election to add/update/remove a validator to an existing BigchainDB network
:param args: dict
args = {
'public_key': the public key of the proposed peer, (str)
'power': the proposed validator power for the new peer, (str)
'node_id': the node_id of the new peer (str)
... | run_election_new_upsert_validator | python | bigchaindb/bigchaindb | bigchaindb/commands/bigchaindb.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/commands/bigchaindb.py | Apache-2.0 |
def run_election_approve(args, bigchain):
"""Approve an election
:param args: dict
args = {
'election_id': the election_id of the election (str)
'sk': the path to the private key of the signer (str)
}
:param bigchain: an instance of BigchainDB
:return: success log messag... | Approve an election
:param args: dict
args = {
'election_id': the election_id of the election (str)
'sk': the path to the private key of the signer (str)
}
:param bigchain: an instance of BigchainDB
:return: success log message or `False` in case of error
| run_election_approve | python | bigchaindb/bigchaindb | bigchaindb/commands/bigchaindb.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/commands/bigchaindb.py | Apache-2.0 |
def run_election_show(args, bigchain):
"""Retrieves information about an election
:param args: dict
args = {
'election_id': the transaction_id for an election (str)
}
:param bigchain: an instance of BigchainDB
"""
election = bigchain.get_transaction(args.election_id)
if... | Retrieves information about an election
:param args: dict
args = {
'election_id': the transaction_id for an election (str)
}
:param bigchain: an instance of BigchainDB
| run_election_show | python | bigchaindb/bigchaindb | bigchaindb/commands/bigchaindb.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/commands/bigchaindb.py | Apache-2.0 |
def run_start(args):
"""Start the processes to run the node"""
# Configure Logging
setup_logging()
logger.info('BigchainDB Version %s', bigchaindb.__version__)
run_recover(bigchaindb.lib.BigchainDB())
if not args.skip_initialize_database:
logger.info('Initializing database')
_... | Start the processes to run the node | run_start | python | bigchaindb/bigchaindb | bigchaindb/commands/bigchaindb.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/commands/bigchaindb.py | Apache-2.0 |
def configure_bigchaindb(command):
"""Decorator to be used by command line functions, such that the
configuration of bigchaindb is performed before the execution of
the command.
Args:
command: The command to decorate.
Returns:
The command wrapper function.
"""
@functools.w... | Decorator to be used by command line functions, such that the
configuration of bigchaindb is performed before the execution of
the command.
Args:
command: The command to decorate.
Returns:
The command wrapper function.
| configure_bigchaindb | python | bigchaindb/bigchaindb | bigchaindb/commands/utils.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/commands/utils.py | Apache-2.0 |
def input_on_stderr(prompt='', default=None, convert=None):
"""Output a string to stderr and wait for input.
Args:
prompt (str): the message to display.
default: the default value to return if the user
leaves the field empty
convert (callable): a callable to be used to conve... | Output a string to stderr and wait for input.
Args:
prompt (str): the message to display.
default: the default value to return if the user
leaves the field empty
convert (callable): a callable to be used to convert
the value the user inserted. If None, the type of
... | input_on_stderr | python | bigchaindb/bigchaindb | bigchaindb/commands/utils.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/commands/utils.py | Apache-2.0 |
def start(parser, argv, scope):
"""Utility function to execute a subcommand.
The function will look up in the ``scope``
if there is a function called ``run_<parser.args.command>``
and will run it using ``parser.args`` as first positional argument.
Args:
parser: an ArgumentParser instance.
... | Utility function to execute a subcommand.
The function will look up in the ``scope``
if there is a function called ``run_<parser.args.command>``
and will run it using ``parser.args`` as first positional argument.
Args:
parser: an ArgumentParser instance.
argv: the list of command line ... | start | python | bigchaindb/bigchaindb | bigchaindb/commands/utils.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/commands/utils.py | Apache-2.0 |
def generate_key_pair():
"""Generates a cryptographic key pair.
Returns:
:class:`~bigchaindb.common.crypto.CryptoKeypair`: A
:obj:`collections.namedtuple` with named fields
:attr:`~bigchaindb.common.crypto.CryptoKeypair.private_key` and
:attr:`~bigchaindb.common.crypto.CryptoKey... | Generates a cryptographic key pair.
Returns:
:class:`~bigchaindb.common.crypto.CryptoKeypair`: A
:obj:`collections.namedtuple` with named fields
:attr:`~bigchaindb.common.crypto.CryptoKeypair.private_key` and
:attr:`~bigchaindb.common.crypto.CryptoKeypair.public_key`.
| generate_key_pair | python | bigchaindb/bigchaindb | bigchaindb/common/crypto.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/crypto.py | Apache-2.0 |
def key_pair_from_ed25519_key(hex_private_key):
"""Generate base58 encode public-private key pair from a hex encoded private key"""
priv_key = crypto.Ed25519SigningKey(bytes.fromhex(hex_private_key)[:32], encoding='bytes')
public_key = priv_key.get_verifying_key()
return CryptoKeypair(private_key=priv_k... | Generate base58 encode public-private key pair from a hex encoded private key | key_pair_from_ed25519_key | python | bigchaindb/bigchaindb | bigchaindb/common/crypto.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/crypto.py | Apache-2.0 |
def __init__(self, fulfillment, owners_before, fulfills=None):
"""Create an instance of an :class:`~.Input`.
Args:
fulfillment (:class:`cryptoconditions.Fulfillment`): A
Fulfillment to be signed with a private key.
owners_before (:obj:`list` of :o... | Create an instance of an :class:`~.Input`.
Args:
fulfillment (:class:`cryptoconditions.Fulfillment`): A
Fulfillment to be signed with a private key.
owners_before (:obj:`list` of :obj:`str`): A list of owners
after a Transaction was co... | __init__ | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def to_dict(self):
"""Transforms the object to a Python dictionary.
Note:
If an Input hasn't been signed yet, this method returns a
dictionary representation.
Returns:
dict: The Input as an alternative serialization format.
"""
... | Transforms the object to a Python dictionary.
Note:
If an Input hasn't been signed yet, this method returns a
dictionary representation.
Returns:
dict: The Input as an alternative serialization format.
| to_dict | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def from_dict(cls, data):
"""Transforms a Python dictionary to an Input object.
Note:
Optionally, this method can also serialize a Cryptoconditions-
Fulfillment that is not yet signed.
Args:
data (dict): The Input to be transformed.
... | Transforms a Python dictionary to an Input object.
Note:
Optionally, this method can also serialize a Cryptoconditions-
Fulfillment that is not yet signed.
Args:
data (dict): The Input to be transformed.
Returns:
:cla... | from_dict | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def _fulfillment_to_details(fulfillment):
"""Encode a fulfillment as a details dictionary
Args:
fulfillment: Crypto-conditions Fulfillment object
"""
if fulfillment.type_name == 'ed25519-sha-256':
return {
'type': 'ed25519-sha-256',
'public_key': base58.b58encod... | Encode a fulfillment as a details dictionary
Args:
fulfillment: Crypto-conditions Fulfillment object
| _fulfillment_to_details | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def _fulfillment_from_details(data, _depth=0):
"""Load a fulfillment for a signing spec dictionary
Args:
data: tx.output[].condition.details dictionary
"""
if _depth == 100:
raise ThresholdTooDeep()
if data['type'] == 'ed25519-sha-256':
public_key = base58.b58decode(data['p... | Load a fulfillment for a signing spec dictionary
Args:
data: tx.output[].condition.details dictionary
| _fulfillment_from_details | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def __init__(self, txid=None, output=None):
"""Create an instance of a :class:`~.TransactionLink`.
Note:
In an IPLD implementation, this class is not necessary anymore,
as an IPLD link can simply point to an object, as well as an
objects properties. S... | Create an instance of a :class:`~.TransactionLink`.
Note:
In an IPLD implementation, this class is not necessary anymore,
as an IPLD link can simply point to an object, as well as an
objects properties. So instead of having a (de)serializable
... | __init__ | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def from_dict(cls, link):
"""Transforms a Python dictionary to a TransactionLink object.
Args:
link (dict): The link to be transformed.
Returns:
:class:`~bigchaindb.common.transaction.TransactionLink`
"""
try:
return cls(link[... | Transforms a Python dictionary to a TransactionLink object.
Args:
link (dict): The link to be transformed.
Returns:
:class:`~bigchaindb.common.transaction.TransactionLink`
| from_dict | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def to_dict(self):
"""Transforms the object to a Python dictionary.
Returns:
(dict|None): The link as an alternative serialization format.
"""
if self.txid is None and self.output is None:
return None
else:
return {
'tr... | Transforms the object to a Python dictionary.
Returns:
(dict|None): The link as an alternative serialization format.
| to_dict | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def __init__(self, fulfillment, public_keys=None, amount=1):
"""Create an instance of a :class:`~.Output`.
Args:
fulfillment (:class:`cryptoconditions.Fulfillment`): A
Fulfillment to extract a Condition from.
public_keys (:obj:`list` of :obj:`str`... | Create an instance of a :class:`~.Output`.
Args:
fulfillment (:class:`cryptoconditions.Fulfillment`): A
Fulfillment to extract a Condition from.
public_keys (:obj:`list` of :obj:`str`, optional): A list of
owners before a Transaction w... | __init__ | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def to_dict(self):
"""Transforms the object to a Python dictionary.
Note:
A dictionary serialization of the Input the Output was
derived from is always provided.
Returns:
dict: The Output as an alternative serialization format.
""... | Transforms the object to a Python dictionary.
Note:
A dictionary serialization of the Input the Output was
derived from is always provided.
Returns:
dict: The Output as an alternative serialization format.
| to_dict | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def generate(cls, public_keys, amount):
"""Generates a Output from a specifically formed tuple or list.
Note:
If a ThresholdCondition has to be generated where the threshold
is always the number of subconditions it is split between, a
list of the foll... | Generates a Output from a specifically formed tuple or list.
Note:
If a ThresholdCondition has to be generated where the threshold
is always the number of subconditions it is split between, a
list of the following structure is sufficient:
[(a... | generate | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def _gen_condition(cls, initial, new_public_keys):
"""Generates ThresholdSha256 conditions from a list of new owners.
Note:
This method is intended only to be used with a reduce function.
For a description on how to use this method, see
:meth:`~.Outpu... | Generates ThresholdSha256 conditions from a list of new owners.
Note:
This method is intended only to be used with a reduce function.
For a description on how to use this method, see
:meth:`~.Output.generate`.
Args:
initial (:clas... | _gen_condition | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def from_dict(cls, data):
"""Transforms a Python dictionary to an Output object.
Note:
To pass a serialization cycle multiple times, a
Cryptoconditions Fulfillment needs to be present in the
passed-in dictionary, as Condition URIs are not serializable... | Transforms a Python dictionary to an Output object.
Note:
To pass a serialization cycle multiple times, a
Cryptoconditions Fulfillment needs to be present in the
passed-in dictionary, as Condition URIs are not serializable
anymore.
... | from_dict | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def __init__(self, operation, asset, inputs=None, outputs=None,
metadata=None, version=None, hash_id=None, tx_dict=None):
"""The constructor allows to create a customizable Transaction.
Note:
When no `version` is provided, one is being
generated by t... | The constructor allows to create a customizable Transaction.
Note:
When no `version` is provided, one is being
generated by this method.
Args:
operation (str): Defines the operation of the Transaction.
asset (dict): Asset payload ... | __init__ | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def unspent_outputs(self):
"""UnspentOutput: The outputs of this transaction, in a data
structure containing relevant information for storing them in
a UTXO set, and performing validation.
"""
if self.operation == self.CREATE:
self._asset_id = self._id
elif se... | UnspentOutput: The outputs of this transaction, in a data
structure containing relevant information for storing them in
a UTXO set, and performing validation.
| unspent_outputs | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def spent_outputs(self):
"""Tuple of :obj:`dict`: Inputs of this transaction. Each input
is represented as a dictionary containing a transaction id and
output index.
"""
return (
input_.fulfills.to_dict()
for input_ in self.inputs if input_.fulfills
... | Tuple of :obj:`dict`: Inputs of this transaction. Each input
is represented as a dictionary containing a transaction id and
output index.
| spent_outputs | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def create(cls, tx_signers, recipients, metadata=None, asset=None):
"""A simple way to generate a `CREATE` transaction.
Note:
This method currently supports the following Cryptoconditions
use cases:
- Ed25519
- ThresholdSha256
... | A simple way to generate a `CREATE` transaction.
Note:
This method currently supports the following Cryptoconditions
use cases:
- Ed25519
- ThresholdSha256
Additionally, it provides support for the following BigchainDB... | create | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def transfer(cls, inputs, recipients, asset_id, metadata=None):
"""A simple way to generate a `TRANSFER` transaction.
Note:
Different cases for threshold conditions:
Combining multiple `inputs` with an arbitrary number of
`recipients` can yield inter... | A simple way to generate a `TRANSFER` transaction.
Note:
Different cases for threshold conditions:
Combining multiple `inputs` with an arbitrary number of
`recipients` can yield interesting cases for the creation of
threshold conditions we'd ... | transfer | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def to_inputs(self, indices=None):
"""Converts a Transaction's outputs to spendable inputs.
Note:
Takes the Transaction's outputs and derives inputs
from that can then be passed into `Transaction.transfer` as
`inputs`.
A list of intege... | Converts a Transaction's outputs to spendable inputs.
Note:
Takes the Transaction's outputs and derives inputs
from that can then be passed into `Transaction.transfer` as
`inputs`.
A list of integers can be passed to `indices` that
... | to_inputs | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def add_input(self, input_):
"""Adds an input to a Transaction's list of inputs.
Args:
input_ (:class:`~bigchaindb.common.transaction.
Input`): An Input to be added to the Transaction.
"""
if not isinstance(input_, Input):
raise TypeEr... | Adds an input to a Transaction's list of inputs.
Args:
input_ (:class:`~bigchaindb.common.transaction.
Input`): An Input to be added to the Transaction.
| add_input | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def add_output(self, output):
"""Adds an output to a Transaction's list of outputs.
Args:
output (:class:`~bigchaindb.common.transaction.
Output`): An Output to be added to the
Transaction.
"""
if not isinstance(output, Output)... | Adds an output to a Transaction's list of outputs.
Args:
output (:class:`~bigchaindb.common.transaction.
Output`): An Output to be added to the
Transaction.
| add_output | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def sign(self, private_keys):
"""Fulfills a previous Transaction's Output by signing Inputs.
Note:
This method works only for the following Cryptoconditions
currently:
- Ed25519Fulfillment
- ThresholdSha256
Furt... | Fulfills a previous Transaction's Output by signing Inputs.
Note:
This method works only for the following Cryptoconditions
currently:
- Ed25519Fulfillment
- ThresholdSha256
Furthermore, note that all keys required to f... | sign | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def _sign_input(cls, input_, message, key_pairs):
"""Signs a single Input.
Note:
This method works only for the following Cryptoconditions
currently:
- Ed25519Fulfillment
- ThresholdSha256.
Args:
in... | Signs a single Input.
Note:
This method works only for the following Cryptoconditions
currently:
- Ed25519Fulfillment
- ThresholdSha256.
Args:
input_ (:class:`~bigchaindb.common.transaction.
... | _sign_input | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def _sign_simple_signature_fulfillment(cls, input_, message, key_pairs):
"""Signs a Ed25519Fulfillment.
Args:
input_ (:class:`~bigchaindb.common.transaction.
Input`) The input to be signed.
message (str): The message to be signed
k... | Signs a Ed25519Fulfillment.
Args:
input_ (:class:`~bigchaindb.common.transaction.
Input`) The input to be signed.
message (str): The message to be signed
key_pairs (dict): The keys to sign the Transaction with.
| _sign_simple_signature_fulfillment | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def _sign_threshold_signature_fulfillment(cls, input_, message, key_pairs):
"""Signs a ThresholdSha256.
Args:
input_ (:class:`~bigchaindb.common.transaction.
Input`) The Input to be signed.
message (str): The message to be signed
k... | Signs a ThresholdSha256.
Args:
input_ (:class:`~bigchaindb.common.transaction.
Input`) The Input to be signed.
message (str): The message to be signed
key_pairs (dict): The keys to sign the Transaction with.
| _sign_threshold_signature_fulfillment | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def _inputs_valid(self, output_condition_uris):
"""Validates an Input against a given set of Outputs.
Note:
The number of `output_condition_uris` must be equal to the
number of Inputs a Transaction has.
Args:
output_condition_uris (:obj:`... | Validates an Input against a given set of Outputs.
Note:
The number of `output_condition_uris` must be equal to the
number of Inputs a Transaction has.
Args:
output_condition_uris (:obj:`list` of :obj:`str`): A list of
Outputs... | _inputs_valid | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def _input_valid(self, input_, operation, message, output_condition_uri=None):
"""Validates a single Input against a single Output.
Note:
In case of a `CREATE` Transaction, this method
does not validate against `output_condition_uri`.
Args:
... | Validates a single Input against a single Output.
Note:
In case of a `CREATE` Transaction, this method
does not validate against `output_condition_uri`.
Args:
input_ (:class:`~bigchaindb.common.transaction.
Input`) The Input t... | _input_valid | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def to_dict(self):
"""Transforms the object to a Python dictionary.
Returns:
dict: The Transaction as an alternative serialization format.
"""
return {
'inputs': [input_.to_dict() for input_ in self.inputs],
'outputs': [output.to_dict() for ou... | Transforms the object to a Python dictionary.
Returns:
dict: The Transaction as an alternative serialization format.
| to_dict | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def _remove_signatures(tx_dict):
"""Takes a Transaction dictionary and removes all signatures.
Args:
tx_dict (dict): The Transaction to remove all signatures from.
Returns:
dict
"""
# NOTE: We remove the reference since we need `tx_dict`... | Takes a Transaction dictionary and removes all signatures.
Args:
tx_dict (dict): The Transaction to remove all signatures from.
Returns:
dict
| _remove_signatures | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def get_asset_id(cls, transactions):
"""Get the asset id from a list of :class:`~.Transactions`.
This is useful when we want to check if the multiple inputs of a
transaction are related to the same asset id.
Args:
transactions (:obj:`list` of :class:`~bigchaindb.common.
... | Get the asset id from a list of :class:`~.Transactions`.
This is useful when we want to check if the multiple inputs of a
transaction are related to the same asset id.
Args:
transactions (:obj:`list` of :class:`~bigchaindb.common.
transaction.Transaction`): A list o... | get_asset_id | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def validate_id(tx_body):
"""Validate the transaction ID of a transaction
Args:
tx_body (dict): The Transaction to be transformed.
"""
# NOTE: Remove reference to avoid side effects
# tx_body = deepcopy(tx_body)
tx_body = rapidjson.loads(rapidjson.dum... | Validate the transaction ID of a transaction
Args:
tx_body (dict): The Transaction to be transformed.
| validate_id | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def from_dict(cls, tx, skip_schema_validation=True):
"""Transforms a Python dictionary to a Transaction object.
Args:
tx_body (dict): The Transaction to be transformed.
Returns:
:class:`~bigchaindb.common.transaction.Transaction`
"""
oper... | Transforms a Python dictionary to a Transaction object.
Args:
tx_body (dict): The Transaction to be transformed.
Returns:
:class:`~bigchaindb.common.transaction.Transaction`
| from_dict | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def from_db(cls, bigchain, tx_dict_list):
"""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:`~bigch... | 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.tendermint.BigchainDB`): An instance
... | from_db | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def resolve_class(operation):
"""For the given `tx` based on the `operation` key return its implementation class"""
create_txn_class = Transaction.type_registry.get(Transaction.CREATE)
return Transaction.type_registry.get(operation, create_txn_class) | For the given `tx` based on the `operation` key return its implementation class | resolve_class | python | bigchaindb/bigchaindb | bigchaindb/common/transaction.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/transaction.py | Apache-2.0 |
def validate_txn_obj(obj_name, obj, key, validation_fun):
"""Validate value of `key` in `obj` using `validation_fun`.
Args:
obj_name (str): name for `obj` being validated.
obj (dict): dictionary object.
key (str): key to be validated in `obj`.
validation_fun ... | Validate value of `key` in `obj` using `validation_fun`.
Args:
obj_name (str): name for `obj` being validated.
obj (dict): dictionary object.
key (str): key to be validated in `obj`.
validation_fun (function): function used to validate the value
of `k... | validate_txn_obj | python | bigchaindb/bigchaindb | bigchaindb/common/utils.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/utils.py | Apache-2.0 |
def validate_all_keys_in_obj(obj_name, obj, validation_fun):
"""Validate all (nested) keys in `obj` by using `validation_fun`.
Args:
obj_name (str): name for `obj` being validated.
obj (dict): dictionary object.
validation_fun (function): function used to validate the va... | Validate all (nested) keys in `obj` by using `validation_fun`.
Args:
obj_name (str): name for `obj` being validated.
obj (dict): dictionary object.
validation_fun (function): function used to validate the value
of `key`.
Returns:
None: indica... | validate_all_keys_in_obj | python | bigchaindb/bigchaindb | bigchaindb/common/utils.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/utils.py | Apache-2.0 |
def validate_all_values_for_key_in_obj(obj, key, validation_fun):
"""Validate value for all (nested) occurrence of `key` in `obj`
using `validation_fun`.
Args:
obj (dict): dictionary object.
key (str): key whose value is to be validated.
validation_fun (function)... | Validate value for all (nested) occurrence of `key` in `obj`
using `validation_fun`.
Args:
obj (dict): dictionary object.
key (str): key whose value is to be validated.
validation_fun (function): function used to validate the value
of `key`.
Rais... | validate_all_values_for_key_in_obj | python | bigchaindb/bigchaindb | bigchaindb/common/utils.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/utils.py | Apache-2.0 |
def validate_transaction_schema(tx):
"""Validate a transaction dict.
TX_SCHEMA_COMMON contains properties that are common to all types of
transaction. TX_SCHEMA_[TRANSFER|CREATE] add additional constraints on top.
"""
_validate_schema(TX_SCHEMA_COMMON, tx)
if tx['operation'] == 'TRANSFER':
... | Validate a transaction dict.
TX_SCHEMA_COMMON contains properties that are common to all types of
transaction. TX_SCHEMA_[TRANSFER|CREATE] add additional constraints on top.
| validate_transaction_schema | python | bigchaindb/bigchaindb | bigchaindb/common/schema/__init__.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/common/schema/__init__.py | Apache-2.0 |
def get_validator_change(cls, bigchain):
"""Return the validator set from the most recent approved block
:return: {
'height': <block_height>,
'validators': <validator_set>
}
"""
latest_block = bigchain.get_latest_block()
if latest_block is None:
... | Return the validator set from the most recent approved block
:return: {
'height': <block_height>,
'validators': <validator_set>
}
| get_validator_change | python | bigchaindb/bigchaindb | bigchaindb/elections/election.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/elections/election.py | Apache-2.0 |
def get_validators(cls, bigchain, height=None):
"""Return a dictionary of validators with key as `public_key` and
value as the `voting_power`
"""
validators = {}
for validator in bigchain.get_validators(height):
# NOTE: we assume that Tendermint encodes public key ... | Return a dictionary of validators with key as `public_key` and
value as the `voting_power`
| get_validators | python | bigchaindb/bigchaindb | bigchaindb/elections/election.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/elections/election.py | Apache-2.0 |
def recipients(cls, bigchain):
"""Convert validator dictionary to a recipient list for `Transaction`"""
recipients = []
for public_key, voting_power in cls.get_validators(bigchain).items():
recipients.append(([public_key], voting_power))
return recipients | Convert validator dictionary to a recipient list for `Transaction` | recipients | python | bigchaindb/bigchaindb | bigchaindb/elections/election.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/elections/election.py | Apache-2.0 |
def validate(self, bigchain, current_transactions=[]):
"""Validate election transaction
NOTE:
* A valid election is initiated by an existing validator.
* A valid election is one where voters are validators and votes are
allocated according to the voting power of each validato... | Validate election transaction
NOTE:
* A valid election is initiated by an existing validator.
* A valid election is one where voters are validators and votes are
allocated according to the voting power of each validator node.
Args:
:param bigchain: (BigchainDB) a... | validate | python | bigchaindb/bigchaindb | bigchaindb/elections/election.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/elections/election.py | Apache-2.0 |
def validate_schema(cls, tx):
"""Validate the election transaction. Since `ELECTION` extends `CREATE` transaction, all the validations for
`CREATE` transaction should be inherited
"""
_validate_schema(TX_SCHEMA_COMMON, tx)
_validate_schema(TX_SCHEMA_CREATE, tx)
if cls.TX_... | Validate the election transaction. Since `ELECTION` extends `CREATE` transaction, all the validations for
`CREATE` transaction should be inherited
| validate_schema | python | bigchaindb/bigchaindb | bigchaindb/elections/election.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/elections/election.py | Apache-2.0 |
def has_concluded(self, bigchain, current_votes=[]):
"""Check if the election can be concluded or not.
* Elections can only be concluded if the validator set has not changed
since the election was initiated.
* Elections can be concluded only if the current votes form a supermajority.
... | Check if the election can be concluded or not.
* Elections can only be concluded if the validator set has not changed
since the election was initiated.
* Elections can be concluded only if the current votes form a supermajority.
Custom elections may override this function and introdu... | has_concluded | python | bigchaindb/bigchaindb | bigchaindb/elections/election.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/elections/election.py | Apache-2.0 |
def process_block(cls, bigchain, new_height, txns):
"""Looks for election and vote transactions inside the block, records
and processes elections.
Every election is recorded in the database.
Every vote has a chance to conclude the corresponding election. When
an ele... | Looks for election and vote transactions inside the block, records
and processes elections.
Every election is recorded in the database.
Every vote has a chance to conclude the corresponding election. When
an election is concluded, the corresponding database record is
... | process_block | python | bigchaindb/bigchaindb | bigchaindb/elections/election.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/elections/election.py | Apache-2.0 |
def validate_schema(cls, tx):
"""Validate the validator election vote transaction. Since `VOTE` extends `TRANSFER`
transaction, all the validations for `CREATE` transaction should be inherited
"""
_validate_schema(TX_SCHEMA_COMMON, tx)
_validate_schema(TX_SCHEMA_TRANSFER, tx)
... | Validate the validator election vote transaction. Since `VOTE` extends `TRANSFER`
transaction, all the validations for `CREATE` transaction should be inherited
| validate_schema | python | bigchaindb/bigchaindb | bigchaindb/elections/vote.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/elections/vote.py | Apache-2.0 |
def validate(self, bigchain, current_transactions=[]):
"""For more details refer BEP-21: https://github.com/bigchaindb/BEPs/tree/master/21
"""
current_validators = self.get_validators(bigchain)
super(ValidatorElection, self).validate(bigchain, current_transactions=current_transactions)... | For more details refer BEP-21: https://github.com/bigchaindb/BEPs/tree/master/21
| validate | python | bigchaindb/bigchaindb | bigchaindb/upsert_validator/validator_election.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/upsert_validator/validator_election.py | Apache-2.0 |
def add_routes(app):
"""Add the routes to an app"""
for (prefix, routes) in API_SECTIONS:
api = Api(app, prefix=prefix)
for ((pattern, resource, *args), kwargs) in routes:
kwargs.setdefault('strict_slashes', False)
api.add_resource(resource, pattern, *args, **kwargs) | Add the routes to an app | add_routes | python | bigchaindb/bigchaindb | bigchaindb/web/routes.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/routes.py | Apache-2.0 |
def __init__(self, app, *, options=None):
"""Initialize a new standalone application.
Args:
app: A wsgi Python application.
options (dict): the configuration.
"""
self.options = options or {}
self.application = app
super().__init__() | Initialize a new standalone application.
Args:
app: A wsgi Python application.
options (dict): the configuration.
| __init__ | python | bigchaindb/bigchaindb | bigchaindb/web/server.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/server.py | Apache-2.0 |
def create_app(*, debug=False, threads=1, bigchaindb_factory=None):
"""Return an instance of the Flask application.
Args:
debug (bool): a flag to activate the debug mode for the app
(default: False).
threads (int): number of threads to use
Return:
an instance of the Flas... | Return an instance of the Flask application.
Args:
debug (bool): a flag to activate the debug mode for the app
(default: False).
threads (int): number of threads to use
Return:
an instance of the Flask application.
| create_app | python | bigchaindb/bigchaindb | bigchaindb/web/server.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/server.py | Apache-2.0 |
def create_server(settings, log_config=None, bigchaindb_factory=None):
"""Wrap and return an application ready to be run.
Args:
settings (dict): a dictionary containing the settings, more info
here http://docs.gunicorn.org/en/latest/settings.html
Return:
an initialized instance... | Wrap and return an application ready to be run.
Args:
settings (dict): a dictionary containing the settings, more info
here http://docs.gunicorn.org/en/latest/settings.html
Return:
an initialized instance of the application.
| create_server | python | bigchaindb/bigchaindb | bigchaindb/web/server.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/server.py | Apache-2.0 |
def __call__(self, environ, start_response):
"""Run the middleware and then call the original WSGI application."""
if environ['REQUEST_METHOD'] == 'GET':
try:
del environ['CONTENT_TYPE']
except KeyError:
pass
else:
logg... | Run the middleware and then call the original WSGI application. | __call__ | python | bigchaindb/bigchaindb | bigchaindb/web/strip_content_type_middleware.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/strip_content_type_middleware.py | Apache-2.0 |
def _multiprocessing_to_asyncio(in_queue, out_queue, loop):
"""Bridge between a synchronous multiprocessing queue
and an asynchronous asyncio queue.
Args:
in_queue (multiprocessing.Queue): input queue
out_queue (asyncio.Queue): output queue
"""
while True:
value = in_queue.... | Bridge between a synchronous multiprocessing queue
and an asynchronous asyncio queue.
Args:
in_queue (multiprocessing.Queue): input queue
out_queue (asyncio.Queue): output queue
| _multiprocessing_to_asyncio | python | bigchaindb/bigchaindb | bigchaindb/web/websocket_server.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/websocket_server.py | Apache-2.0 |
def __init__(self, event_source):
"""Create a new instance.
Args:
event_source: a source of events. Elements in the queue
should be strings.
"""
self.event_source = event_source
self.subscribers = {} | Create a new instance.
Args:
event_source: a source of events. Elements in the queue
should be strings.
| __init__ | python | bigchaindb/bigchaindb | bigchaindb/web/websocket_server.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/websocket_server.py | Apache-2.0 |
async def publish(self):
"""Publish new events to the subscribers."""
while True:
event = await self.event_source.get()
str_buffer = []
if event == POISON_PILL:
return
if isinstance(event, str):
str_buffer.append(event)
... | Publish new events to the subscribers. | publish | python | bigchaindb/bigchaindb | bigchaindb/web/websocket_server.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/websocket_server.py | Apache-2.0 |
def init_app(event_source, *, loop=None):
"""Init the application server.
Return:
An aiohttp application.
"""
dispatcher = Dispatcher(event_source)
# Schedule the dispatcher
loop.create_task(dispatcher.publish())
app = web.Application(loop=loop)
app['dispatcher'] = dispatcher... | Init the application server.
Return:
An aiohttp application.
| init_app | python | bigchaindb/bigchaindb | bigchaindb/web/websocket_server.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/websocket_server.py | Apache-2.0 |
def start(sync_event_source, loop=None):
"""Create and start the WebSocket server."""
if not loop:
loop = asyncio.get_event_loop()
event_source = asyncio.Queue(loop=loop)
bridge = threading.Thread(target=_multiprocessing_to_asyncio,
args=(sync_event_source, event... | Create and start the WebSocket server. | start | python | bigchaindb/bigchaindb | bigchaindb/web/websocket_server.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/websocket_server.py | Apache-2.0 |
def base_ws_uri():
"""Base websocket URL that is advertised to external clients.
Useful when the websocket URL advertised to the clients needs to be
customized (typically when running behind NAT, firewall, etc.)
"""
config_wsserver = config['wsserver']
scheme = config_wsserver['advertised_sch... | Base websocket URL that is advertised to external clients.
Useful when the websocket URL advertised to the clients needs to be
customized (typically when running behind NAT, firewall, etc.)
| base_ws_uri | python | bigchaindb/bigchaindb | bigchaindb/web/views/base.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/views/base.py | Apache-2.0 |
def get(self, block_id):
"""API endpoint to get details about a block.
Args:
block_id (str): the id of the block.
Return:
A JSON string containing the data about the block.
"""
pool = current_app.config['bigchain_pool']
with pool() as bigchain:... | API endpoint to get details about a block.
Args:
block_id (str): the id of the block.
Return:
A JSON string containing the data about the block.
| get | python | bigchaindb/bigchaindb | bigchaindb/web/views/blocks.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/views/blocks.py | Apache-2.0 |
def get(self):
"""API endpoint to get the related blocks for a transaction.
Return:
A ``list`` of ``block_id``s that contain the given transaction. The
list may be filtered when provided a status query parameter:
"valid", "invalid", "undecided".
"""
p... | API endpoint to get the related blocks for a transaction.
Return:
A ``list`` of ``block_id``s that contain the given transaction. The
list may be filtered when provided a status query parameter:
"valid", "invalid", "undecided".
| get | python | bigchaindb/bigchaindb | bigchaindb/web/views/blocks.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/views/blocks.py | Apache-2.0 |
def get_api_v1_info(api_prefix):
"""Return a dict with all the information specific for the v1 of the
api.
"""
websocket_root = base_ws_uri() + EVENTS_ENDPOINT
docs_url = [
'https://docs.bigchaindb.com/projects/server/en/v',
version.__version__,
'/http-client-server-api.html'... | Return a dict with all the information specific for the v1 of the
api.
| get_api_v1_info | python | bigchaindb/bigchaindb | bigchaindb/web/views/info.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/views/info.py | Apache-2.0 |
def get(self):
"""API endpoint to retrieve a list of links to transaction
outputs.
Returns:
A :obj:`list` of :cls:`str` of links to outputs.
"""
parser = reqparse.RequestParser()
parser.add_argument('public_key', type=parameters.valid_ed25519,
... | API endpoint to retrieve a list of links to transaction
outputs.
Returns:
A :obj:`list` of :cls:`str` of links to outputs.
| get | python | bigchaindb/bigchaindb | bigchaindb/web/views/outputs.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/views/outputs.py | Apache-2.0 |
def get(self, tx_id):
"""API endpoint to get details about a transaction.
Args:
tx_id (str): the id of the transaction.
Return:
A JSON string containing the data about the transaction.
"""
pool = current_app.config['bigchain_pool']
with pool() a... | API endpoint to get details about a transaction.
Args:
tx_id (str): the id of the transaction.
Return:
A JSON string containing the data about the transaction.
| get | python | bigchaindb/bigchaindb | bigchaindb/web/views/transactions.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/views/transactions.py | Apache-2.0 |
def post(self):
"""API endpoint to push transactions to the Federation.
Return:
A ``dict`` containing the data about the transaction.
"""
parser = reqparse.RequestParser()
parser.add_argument('mode', type=parameters.valid_mode,
default=BRO... | API endpoint to push transactions to the Federation.
Return:
A ``dict`` containing the data about the transaction.
| post | python | bigchaindb/bigchaindb | bigchaindb/web/views/transactions.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/views/transactions.py | Apache-2.0 |
def get(self):
"""API endpoint to get validators set.
Return:
A JSON string containing the validator set of the current node.
"""
pool = current_app.config['bigchain_pool']
with pool() as bigchain:
validators = bigchain.get_validators()
return ... | API endpoint to get validators set.
Return:
A JSON string containing the validator set of the current node.
| get | python | bigchaindb/bigchaindb | bigchaindb/web/views/validators.py | https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/web/views/validators.py | Apache-2.0 |
def generate_validators(powers):
"""Generates an arbitrary number of validators with random public keys.
The object under the `storage` key is in the format expected by DB.
The object under the `eleciton` key is in the format expected by
the upsert validator election.
`public_key`, `p... | Generates an arbitrary number of validators with random public keys.
The object under the `storage` key is in the format expected by DB.
The object under the `eleciton` key is in the format expected by
the upsert validator election.
`public_key`, `private_key` are in the format used for s... | generate_validators | python | bigchaindb/bigchaindb | tests/utils.py | https://github.com/bigchaindb/bigchaindb/blob/master/tests/utils.py | Apache-2.0 |
def _test_additionalproperties(node, path=''):
"""Validate that each object node has additionalProperties set, so that
objects with junk keys do not pass as valid.
"""
if isinstance(node, list):
for i, nnode in enumerate(node):
_test_additionalproperties(nnode, path + str(i) + '.')
... | Validate that each object node has additionalProperties set, so that
objects with junk keys do not pass as valid.
| _test_additionalproperties | python | bigchaindb/bigchaindb | tests/common/test_schema.py | https://github.com/bigchaindb/bigchaindb/blob/master/tests/common/test_schema.py | Apache-2.0 |
def test_cant_spend_same_input_twice_in_tx(b, alice):
"""Recreate duplicated fulfillments bug
https://github.com/bigchaindb/bigchaindb/issues/1099
"""
from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import DoubleSpend
# create a divisible asset
tx_create = Transa... | Recreate duplicated fulfillments bug
https://github.com/bigchaindb/bigchaindb/issues/1099
| test_cant_spend_same_input_twice_in_tx | python | bigchaindb/bigchaindb | tests/db/test_bigchain_api.py | https://github.com/bigchaindb/bigchaindb/blob/master/tests/db/test_bigchain_api.py | Apache-2.0 |
def get_txs_patched(conn, **args):
"""Patch `get_transactions_filtered` so that rather than return an array
of transactions it returns an array of shims with a to_dict() method
that reports one of the arguments passed to `get_transactions_filtered`.
"""
return [type('... | Patch `get_transactions_filtered` so that rather than return an array
of transactions it returns an array of shims with a to_dict() method
that reports one of the arguments passed to `get_transactions_filtered`.
| get_txs_patched | python | bigchaindb/bigchaindb | tests/web/test_transactions.py | https://github.com/bigchaindb/bigchaindb/blob/master/tests/web/test_transactions.py | Apache-2.0 |
def call(self, x, training=None):
"""
Apply random channel-swap augmentation to `x`.
Args:
x (`Tensor`): A batch tensor of 1D (signals) or 2D (spectrograms) data
"""
if training in (None, False):
return x
# figure out input data format
if... |
Apply random channel-swap augmentation to `x`.
Args:
x (`Tensor`): A batch tensor of 1D (signals) or 2D (spectrograms) data
| call | python | keunwoochoi/kapre | kapre/augmentation.py | https://github.com/keunwoochoi/kapre/blob/master/kapre/augmentation.py | MIT |
def _apply_masks_to_axis(self, x, axis, mask_param, n_masks):
"""
Applies a number of masks (defined by the parameter n_masks) to the spectrogram
by the axis provided.
Args:
x (float `Tensor`): A spectrogram. Its shape is (time, freq, ch) or (ch, time, freq)
... |
Applies a number of masks (defined by the parameter n_masks) to the spectrogram
by the axis provided.
Args:
x (float `Tensor`): A spectrogram. Its shape is (time, freq, ch) or (ch, time, freq)
depending on data_format.
axis (int): The axis where the m... | _apply_masks_to_axis | python | keunwoochoi/kapre | kapre/augmentation.py | https://github.com/keunwoochoi/kapre/blob/master/kapre/augmentation.py | MIT |
def _apply_spec_augment(self, x):
"""
Main method that applies SpecAugment technique by both frequency and
time axis.
Args:
x (float `Tensor`) : A spectrogram. Its shape is (time, freq, ch) or (ch, time, freq)
depending on data_format.
Returns:
... |
Main method that applies SpecAugment technique by both frequency and
time axis.
Args:
x (float `Tensor`) : A spectrogram. Its shape is (time, freq, ch) or (ch, time, freq)
depending on data_format.
Returns:
(float `Tensor`): The spectrogram ma... | _apply_spec_augment | python | keunwoochoi/kapre | kapre/augmentation.py | https://github.com/keunwoochoi/kapre/blob/master/kapre/augmentation.py | MIT |
def get_window_fn(window_name=None):
"""Return a window function given its name.
This function is used inside layers such as `STFT` to get a window function.
Args:
window_name (None or str): name of window function. On Tensorflow 2.3, there are five windows available in
`tf.signal` (`hammin... | Return a window function given its name.
This function is used inside layers such as `STFT` to get a window function.
Args:
window_name (None or str): name of window function. On Tensorflow 2.3, there are five windows available in
`tf.signal` (`hamming_window`, `hann_window`, `kaiser_bessel_der... | get_window_fn | python | keunwoochoi/kapre | kapre/backend.py | https://github.com/keunwoochoi/kapre/blob/master/kapre/backend.py | MIT |
def validate_data_format_str(data_format):
"""A function that validates the data format string."""
if data_format not in (_CH_DEFAULT_STR, _CH_FIRST_STR, _CH_LAST_STR):
raise ValueError(
'data_format should be one of {}'.format(
str([_CH_FIRST_STR, _CH_LAST_STR, _CH_DEFAULT_S... | A function that validates the data format string. | validate_data_format_str | python | keunwoochoi/kapre | kapre/backend.py | https://github.com/keunwoochoi/kapre/blob/master/kapre/backend.py | MIT |
def magnitude_to_decibel(x, ref_value=1.0, amin=1e-5, dynamic_range=80.0):
"""A function that converts magnitude to decibel scaling.
In essence, it runs `10 * log10(x)`, but with some other utility operations.
Similar to `librosa.power_to_db` with `ref=1.0` and `top_db=dynamic_range`
Args:
x (... | A function that converts magnitude to decibel scaling.
In essence, it runs `10 * log10(x)`, but with some other utility operations.
Similar to `librosa.power_to_db` with `ref=1.0` and `top_db=dynamic_range`
Args:
x (`Tensor`): float tensor. Can be batch or not. Something like magnitude of STFT.
... | magnitude_to_decibel | python | keunwoochoi/kapre | kapre/backend.py | https://github.com/keunwoochoi/kapre/blob/master/kapre/backend.py | MIT |
def filterbank_mel(
sample_rate, n_freq, n_mels=128, f_min=0.0, f_max=None, htk=False, norm='slaney'
):
"""A wrapper for librosa.filters.mel that additionally does transpose and tensor conversion
Args:
sample_rate (`int`): sample rate of the input audio
n_freq (`int`): number of frequency b... | A wrapper for librosa.filters.mel that additionally does transpose and tensor conversion
Args:
sample_rate (`int`): sample rate of the input audio
n_freq (`int`): number of frequency bins in the input STFT magnitude.
n_mels (`int`): the number of mel bands
f_min (`float`): lowest fr... | filterbank_mel | python | keunwoochoi/kapre | kapre/backend.py | https://github.com/keunwoochoi/kapre/blob/master/kapre/backend.py | MIT |
def get_stft_magnitude_layer(
input_shape=None,
n_fft=2048,
win_length=None,
hop_length=None,
window_name=None,
pad_begin=False,
pad_end=False,
return_decibel=False,
db_amin=1e-5,
db_ref_value=1.0,
db_dynamic_range=80.0,
input_data_format='default',
output_data_format... | A function that returns a stft magnitude layer.
The layer is a `keras.Sequential` model consists of `STFT`, `Magnitude`, and optionally `MagnitudeToDecibel`.
Args:
input_shape (None or tuple of integers): input shape of the model. Necessary only if this melspectrogram layer is
is the first ... | get_stft_magnitude_layer | python | keunwoochoi/kapre | kapre/composed.py | https://github.com/keunwoochoi/kapre/blob/master/kapre/composed.py | MIT |
def get_melspectrogram_layer(
input_shape=None,
n_fft=2048,
win_length=None,
hop_length=None,
window_name=None,
pad_begin=False,
pad_end=False,
sample_rate=22050,
n_mels=128,
mel_f_min=0.0,
mel_f_max=None,
mel_htk=False,
mel_norm='slaney',
return_decibel=False,
... | A function that returns a melspectrogram layer, which is a `keras.Sequential` model consists of
`STFT`, `Magnitude`, `ApplyFilterbank(_mel_filterbank)`, and optionally `MagnitudeToDecibel`.
Args:
input_shape (None or tuple of integers): input shape of the model. Necessary only if this melspectrogram la... | get_melspectrogram_layer | python | keunwoochoi/kapre | kapre/composed.py | https://github.com/keunwoochoi/kapre/blob/master/kapre/composed.py | MIT |
def get_log_frequency_spectrogram_layer(
input_shape=None,
n_fft=2048,
win_length=None,
hop_length=None,
window_name=None,
pad_begin=False,
pad_end=False,
sample_rate=22050,
log_n_bins=84,
log_f_min=None,
log_bins_per_octave=12,
log_spread=0.125,
return_decibel=False,... | A function that returns a log-frequency STFT layer, which is a `keras.Sequential` model consists of
`STFT`, `Magnitude`, `ApplyFilterbank(_log_filterbank)`, and optionally `MagnitudeToDecibel`.
Args:
input_shape (None or tuple of integers): input shape of the model if this melspectrogram layer is
... | get_log_frequency_spectrogram_layer | python | keunwoochoi/kapre | kapre/composed.py | https://github.com/keunwoochoi/kapre/blob/master/kapre/composed.py | MIT |
def get_perfectly_reconstructing_stft_istft(
stft_input_shape=None,
istft_input_shape=None,
n_fft=2048,
win_length=None,
hop_length=None,
forward_window_name=None,
waveform_data_format='default',
stft_data_format='default',
stft_name='stft',
istft_name='istft',
):
"""A functi... | A function that returns two layers, stft and inverse stft, which would be perfectly reconstructing pair.
Args:
stft_input_shape (tuple): Input shape of single waveform.
Must specify this if the returned stft layer is going to be used as first layer of a Sequential model.
istft_input_sha... | get_perfectly_reconstructing_stft_istft | python | keunwoochoi/kapre | kapre/composed.py | https://github.com/keunwoochoi/kapre/blob/master/kapre/composed.py | MIT |
def get_stft_mag_phase(
input_shape,
n_fft=2048,
win_length=None,
hop_length=None,
window_name=None,
pad_begin=False,
pad_end=False,
return_decibel=False,
db_amin=1e-5,
db_ref_value=1.0,
db_dynamic_range=80.0,
input_data_format='default',
output_data_format='default',... | A function that returns magnitude and phase of input audio.
Args:
input_shape (None or tuple of integers): input shape of the stft layer.
Because this mag_phase is based on keras.Functional model, it is required to specify the input shape.
E.g., (44100, 2) for 44100-sample stereo au... | get_stft_mag_phase | python | keunwoochoi/kapre | kapre/composed.py | https://github.com/keunwoochoi/kapre/blob/master/kapre/composed.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.