Giter Club home page Giter Club logo

bigchaindb-driver's Introduction

media/repo-banner@2x.png

Join the chat at https://gitter.im/bigchaindb/bigchaindb-driver Documentation Status
  • Free software: Apache Software License 2.0
  • Check our Documentation
  • Support for preparing, fulfilling, and sending transactions to a BigchainDB node.
  • Retrieval of transactions by id.

The instructions below were tested on Ubuntu 16.04 LTS. They should also work on other Linux distributions and on macOS. The driver might work on Windows as well, but we do not guarantee it. We recommend to set up (e.g. via Docker on Windows) an Ubuntu VM there.

We recommend you use a virtual environment to install and update to the latest stable version using pip (or pip3):

pip install -U bigchaindb-driver

That will install the latest stable BigchainDB Python Driver. If you want to install an Alpha, Beta or RC version of the Python Driver, use something like:

pip install -U bigchaindb_driver==0.5.0a4

The above command will install version 0.5.0a4 (Alpha 4). You can find a list of all versions in the release history page on PyPI.

More information on how to install the driver can be found in the Quickstart

Example: Create a divisible asset for Alice who issues 10 token to Bob so that he can use her Game Boy. Afterwards Bob spends 3 of these tokens.

If you want to send a transaction you need to Determine the BigchainDB Root URL.

# import BigchainDB and create an object
from bigchaindb_driver import BigchainDB
bdb_root_url = 'https://example.com:9984'
bdb = BigchainDB(bdb_root_url)

# generate a keypair
from bigchaindb_driver.crypto import generate_keypair
alice, bob = generate_keypair(), generate_keypair()

# create a digital asset for Alice
game_boy_token = {
    'data': {
        'token_for': {
            'game_boy': {
                'serial_number': 'LR35902'
            }
        },
        'description': 'Time share token. Each token equals one hour of usage.',
    },
}

# prepare the transaction with the digital asset and issue 10 tokens for Bob
prepared_token_tx = bdb.transactions.prepare(
    operation='CREATE',
    signers=alice.public_key,
    recipients=[([bob.public_key], 10)],
    asset=game_boy_token)

# fulfill and send the transaction
fulfilled_token_tx = bdb.transactions.fulfill(
    prepared_token_tx,
    private_keys=alice.private_key)
bdb.transactions.send_commit(fulfilled_token_tx)

# Use the tokens
# create the output and inout for the transaction
transfer_asset = {'id': fulfilled_token_tx['id']}
output_index = 0
output = fulfilled_token_tx['outputs'][output_index]
transfer_input = {'fulfillment': output['condition']['details'],
                  'fulfills': {'output_index': output_index,
                               'transaction_id': transfer_asset['id']},
                  'owners_before': output['public_keys']}

# prepare the transaction and use 3 tokens
prepared_transfer_tx = bdb.transactions.prepare(
    operation='TRANSFER',
    asset=transfer_asset,
    inputs=transfer_input,
    recipients=[([alice.public_key], 3), ([bob.public_key], 7)])

# fulfill and send the transaction
fulfilled_transfer_tx = bdb.transactions.fulfill(
    prepared_transfer_tx,
    private_keys=bob.private_key)
sent_transfer_tx = bdb.transactions.send_commit(fulfilled_transfer_tx)
BigchainDB Server BigchainDB Driver
>= 2.0.0b7 0.6.2
>= 2.0.0b7 0.6.1
>= 2.0.0b7 0.6.0
>= 2.0.0b5 0.5.3
>= 2.0.0b5 0.5.2
>= 2.0.0b5 0.5.1
>= 2.0.0b1 0.5.0
>= 2.0.0a3 0.5.0a4
>= 2.0.0a2 0.5.0a2
>= 2.0.0a1 0.5.0a1
>= 1.0.0 0.4.x
== 1.0.0rc1 0.3.x
>= 0.9.1 0.2.x
>= 0.8.2 >= 0.1.3

Although we do our best to keep the master branches in sync, there may be occasional delays.

This package was initially created using Cookiecutter and the audreyr/cookiecutter-pypackage project template. Many BigchainDB developers have contributed since then.

bigchaindb-driver's People

Contributors

aruseni avatar codegeschrei avatar dependabot[bot] avatar diminator avatar gitter-badger avatar kansi avatar krish7919 avatar ldmberman avatar muawiakh avatar nickfitton avatar r-marques avatar sbellem avatar shahbazn avatar sohkai avatar ssadler avatar timdaub avatar ttmc avatar tucanae47 avatar ucg8j avatar vrde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bigchaindb-driver's Issues

Support multiple owners_after, different from owner_before, for the CREATE

current BigchainDB.transactions.create():

def create(self, payload=None, verifying_key=None, signing_key=None):
    # ...

assumes that the verifying_key represents both the owner_before and the owner_after. This is one possible case, but there are others, which we also need to support. The other cases are that there can be one owner_before, and multiple owners_after, which can all differ from the owner_before.

Document library

  • modules and their classes
  • instructions for devs on running tests, especially integration tests with the server

Testing code examples and auto-generating their output

Once we have some example code showing how to use the Python driver API, we should consider:

  1. testing the code snippets (to see if they throw exceptions)
  2. auto-generating the output to be consistent with the actual output

Maybe we can use the Sphinx extension named doctest? See http://www.sphinx-doc.org/en/stable/ext/doctest.html

Note that RethinkDB and BigchainDB would have to be configured and running. That might not be possible on ReadTheDocs.

Another option is to use an IPython Notebook (i.e. run it and then convert the finished notebook to .rst).

This issue was inspired by bigchaindb/bigchaindb#607 and bigchaindb/bigchaindb#637

rename pick* to select*

e.g.: class Picker --> class Selector

etc

Why? The name select seems to be more well suited than pick.

Feedback most welcomed!

Should transaction validation be performed on client side?

Assuming transaction validation is performed on the server side, should the client nevertheless perform transaction validation?

And if transaction validation occurs on the client side, when should it be done in the request-response cycle?

  1. Before a request is sent?
  2. Upon reception of a response?

What are the pros and cons of each approach?

Support multiple endpoints via namespaces

By endpoints is meant:

/transactions
/assets
/blocks

and so forth.

This ticket proposes that the implementation provides a convenient way to perform actions for specific endpoints. Example:

BigchainDB.transactions.create()
BigchainDB.assets.create()
BigchainDB.blocks.get(txid=1)

The above approach is heavily inspired by the elasticsearch client.

New docs page about how to connect to various API endpoint server options

I noticed that the Basic Usage Examples page and the Advanced Usage [Examples] page both start out with some information about how to make a connection to some BigchainDB API endpoint server running somewhere.

I wonder if it would make sense to put that on a new separate page between Quickstart / Installation and Basic Usage Examples. Maybe it could be titled Step 2: Connect. It could have several sections, one for each case, starting with the easiest and most common. The Basic Usage Examples page and the Advanced Usage [Examples] page could start by saying they must be connected to a BigchainDB API endpoint server running somewhere, with a link to the new page if they need to do that.

TestTrasnportError

There's a class named TestTrasnportError in tests/test_exceptions.py. I suppose it could be named anything and it would still work, but I'd feel better if it was named TestTransportError.

Support multiple inputs (tx) in transfer

As an example, we wish to support the now outdated use case outlined in https://docs.bigchaindb.com/projects/server/en/latest/drivers-clients/python-server-api-examples.html#multiple-inputs-and-outputs

# Create some assets for bulk transfer
for i in range(3):
    tx_mimo_asset = b.create_transaction(b.me, testuser1_pub, None, 'CREATE')
    tx_mimo_asset_signed = b.sign_transaction(tx_mimo_asset, b.me_private)
    b.write_transaction(tx_mimo_asset_signed)

# Wait until they appear on the bigchain and get the inputs
owned_mimo_inputs = b.get_owned_ids(testuser1_pub)

# Check the number of assets
print(len(owned_mimo_inputs))

# Create a signed TRANSFER transaction with all the assets
tx_mimo = b.create_transaction(testuser1_pub, testuser2_pub, owned_mimo_inputs, 'TRANSFER')
tx_mimo_signed = b.sign_transaction(tx_mimo, testuser1_priv)

# Write the transaction
b.write_transaction(tx_mimo_signed)

# Check if the transaction is already in the bigchain
tx_mimo_retrieved = b.get_transaction(tx_mimo_signed['id'])

Fix intersphinx inventory 'objects.inv' not fetchable

loading intersphinx inventory from https://docs.python.org/3/objects.inv...
loading intersphinx inventory from https://docs.bigchaindb.com/projects/server/en/latest/objects.inv...
WARNING: intersphinx inventory 'https://docs.bigchaindb.com/projects/server/en/latest/objects.inv' not fetchable due to <class 'urllib.error.HTTPError'>: HTTP Error 403: Forbidden

Notes

This was working last week. Not sure why it does not now. One thing that is new is that docs.bigchaindb.com is now available under https. Could that be related? Needs investigations.

Suggested troubleshooting approach

In order to troubleshoot this issue, one may simply use the fetch_inventory method from intersphinx:

>>> import warnings
>>> from sphinx.ext.intersphinx import fetch_inventory
>>> uri = 'https://docs.python.org/3/'
>>> fetch_inventory(warnings, uri, uri + 'objects.inv')
  # ..., ..., ..., ..., ..., ...,
  'yield_atom': ('Python',
   '3.5',
   'https://docs.python.org/3/reference/expressions.html#grammar-token-yield_atom',
   '-'),
  'yield_expression': ('Python',
   '3.5',
   'https://docs.python.org/3/reference/expressions.html#grammar-token-yield_expression',
   '-'),
  'yield_stmt': ('Python',
   '3.5',
   'https://docs.python.org/3/reference/simple_stmts.html#grammar-token-yield_stmt',
   '-')}}

As shown above, it should work for Python. If you now try with BigchainDB:

>>> uri = 'https://docs.bigchaindb.com/projects/server/en/latest/'
>>> fetch_inventory(warnings, uri, uri + 'objects.inv')
/usr/local/lib/python3.5/site-packages/sphinx/ext/intersphinx.py:238: UserWarning: intersphinx inventory 'https://docs.bigchaindb.com/projects/server/en/latest/objects.inv' not fetchable due to <class 'urllib.error.HTTPError'>: HTTP Error 403: Forbidden
  '%s: %s' % (inv, err.__class__, err))

Other variations of uri have been tried and all failed as well:

In [37]: uri = 'https://docs.bigchaindb.com/projects/server/en/'

In [38]: fetch_inventory(warnings, uri, uri + 'objects.inv')
/usr/local/lib/python3.5/site-packages/sphinx/ext/intersphinx.py:238: UserWarning: intersphinx inventory 'https://docs.bigchaindb.com/projects/server/en/objects.inv' not fetchable due to <class 'urllib.error.HTTPError'>: HTTP Error 403: Forbidden
  '%s: %s' % (inv, err.__class__, err))

In [39]: uri = 'https://docs.bigchaindb.com/projects/server/'

In [40]: fetch_inventory(warnings, uri, uri + 'objects.inv')
/usr/local/lib/python3.5/site-packages/sphinx/ext/intersphinx.py:238: UserWarning: intersphinx inventory 'https://docs.bigchaindb.com/projects/server/objects.inv' not fetchable due to <class 'urllib.error.HTTPError'>: HTTP Error 403: Forbidden
  '%s: %s' % (inv, err.__class__, err))

In [41]: uri = 'https://docs.bigchaindb.com/projects/'

In [42]: fetch_inventory(warnings, uri, uri + 'objects.inv')
/usr/local/lib/python3.5/site-packages/sphinx/ext/intersphinx.py:238: UserWarning: intersphinx inventory 'https://docs.bigchaindb.com/projects/objects.inv' not fetchable due to <class 'urllib.error.HTTPError'>: HTTP Error 403: Forbidden
  '%s: %s' % (inv, err.__class__, err))

In [43]: uri = 'https://docs.bigchaindb.com/'

In [44]: fetch_inventory(warnings, uri, uri + 'objects.inv')
/usr/local/lib/python3.5/site-packages/sphinx/ext/intersphinx.py:238: UserWarning: intersphinx inventory 'https://docs.bigchaindb.com/objects.inv' not fetchable due to <class 'urllib.error.HTTPError'>: HTTP Error 403: Forbidden
  '%s: %s' % (inv, err.__class__, err))

In [45]: uri = 'http://docs.bigchaindb.com/projects/server/en/latest/'

In [46]: fetch_inventory(warnings, uri, uri + 'objects.inv')
/usr/local/lib/python3.5/site-packages/sphinx/ext/intersphinx.py:238: UserWarning: intersphinx inventory 'http://docs.bigchaindb.com/projects/server/en/latest/objects.inv' not fetchable due to <class 'urllib.error.HTTPError'>: HTTP Error 403: Forbidden
  '%s: %s' % (inv, err.__class__, err))

In [47]: uri = 'http://docs.bigchaindb.com/projects/server/en/'

In [48]: fetch_inventory(warnings, uri, uri + 'objects.inv')
/usr/local/lib/python3.5/site-packages/sphinx/ext/intersphinx.py:238: UserWarning: intersphinx inventory 'http://docs.bigchaindb.com/projects/server/en/objects.inv' not fetchable due to <class 'urllib.error.HTTPError'>: HTTP Error 403: Forbidden
  '%s: %s' % (inv, err.__class__, err))

In [49]: uri = 'http://docs.bigchaindb.com/projects/server/'

In [50]: fetch_inventory(warnings, uri, uri + 'objects.inv')
/usr/local/lib/python3.5/site-packages/sphinx/ext/intersphinx.py:238: UserWarning: intersphinx inventory 'http://docs.bigchaindb.com/projects/server/objects.inv' not fetchable due to <class 'urllib.error.HTTPError'>: HTTP Error 403: Forbidden
  '%s: %s' % (inv, err.__class__, err))

In [51]: uri = 'http://docs.bigchaindb.com/projects/'

In [52]: fetch_inventory(warnings, uri, uri + 'objects.inv')
/usr/local/lib/python3.5/site-packages/sphinx/ext/intersphinx.py:238: UserWarning: intersphinx inventory 'http://docs.bigchaindb.com/projects/objects.inv' not fetchable due to <class 'urllib.error.HTTPError'>: HTTP Error 403: Forbidden
  '%s: %s' % (inv, err.__class__, err))

In [53]: uri = 'http://docs.bigchaindb.com/'

In [54]: fetch_inventory(warnings, uri, uri + 'objects.inv')
/usr/local/lib/python3.5/site-packages/sphinx/ext/intersphinx.py:238: UserWarning: intersphinx inventory 'http://docs.bigchaindb.com/objects.inv' not fetchable due to <class 'urllib.error.HTTPError'>: HTTP Error 403: Forbidden
  '%s: %s' % (inv, err.__class__, err))

Investigate what can be done for pynacl dependency on libffi (header file ffi.h)

Some questions:

Important note: Although this issue is being created under bigchaindb-driver for the time being, this is something, if possible, that should be pushed down to cryptoconditions, at the very least, and further to pynacl if it makes sense.

Review temp_driver()

Should temp_driver still exist? And if we do still want to keep this functionality, should we roll it up into an initialization flag for the driver (e.g. BigchainDB(autogen_keypair=True))?

broken tests

======================================================================================================================================== FAILURES =========================================================================================================================================
______________________________________________________________________________________________________________________ TestTransactionsEndpoint.test_transfer_assets ______________________________________________________________________________________________________________________

self = <tests.test_driver.TestTransactionsEndpoint object at 0x7fd6e0e32c50>, alice_driver = <bigchaindb_driver.driver.BigchainDB object at 0x7fd6e0e32a20>
persisted_alice_transaction = {'id': '3e724db295bc0b82362b14db0d6f6031d0cf95b7a2c91fbd58b40a034aaf826f', 'transaction': {'conditions': [{'cid': 0, '...: None, 'owners_before': ['G7J7bXF8cqSrjrxUKwcF8tCriEKC5CgyPHmtGwUi4BK3']}], 'operation': 'CREATE', ...}, 'version': 1}
bob_pubkey = '2dBVUoATxEzEqRdsi64AFsJnn2ywLCwnbNwW7K9BuVuS', bob_privkey = '4S1dzx3PSdMAfs59aBkQefPASizTs728HnhLNpYZWCad'

    def test_transfer_assets(self, alice_driver, persisted_alice_transaction,
                             bob_pubkey, bob_privkey):
        tx = alice_driver.transactions.transfer(
>           persisted_alice_transaction, bob_pubkey)

tests/test_driver.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
bigchaindb_driver/driver.py:212: in transfer
    return self._push(signed_transfer_transaction)
bigchaindb_driver/driver.py:225: in _push
    method='POST', path=self.path, json=transaction)
bigchaindb_driver/transport.py:46: in forward_request
    response = connection.request(method=method, path=path, json=json)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <bigchaindb_driver.connection.Connection object at 0x7fd6e0e32160>, method = 'POST', path = '/transactions/', json = {'message': 'Invalid transaction', 'status': 400}, kwargs = {}, url = 'http://bdb-server:9984/api/v1/transactions/', response = <Response [400]>
text = '{\n  "message": "Invalid transaction",\n  "status": 400\n}', exc_cls = <class 'bigchaindb_driver.exceptions.TransportError'>

    def request(self, method, *, path=None, json=None, **kwargs):
        """Performs an HTTP requests for the specified arguments.

            Args:
                method (str): HTTP method (e.g.: `'GET`'.
                path (str): API endpoint path (e.g.: `'/transactions'`.
                json (dict): JSON data to send along with the request.
                kwargs: Optional keyword arguments.

            """
        url = self.node_url + path if path else self.node_url
        response = self.session.request(
            method=method, url=url, json=json, **kwargs)
        text = response.text
        try:
            json = response.json()
        except ValueError:
            json = None
        if not (200 <= response.status_code < 300):
            exc_cls = HTTP_EXCEPTIONS.get(response.status_code, TransportError)
>           raise exc_cls(response.status_code, text, json)
E           bigchaindb_driver.exceptions.TransportError: (400, '{\n  "message": "Invalid transaction",\n  "status": 400\n}', {'status': 400, 'message': 'Invalid transaction'})

bigchaindb_driver/connection.py:45: TransportError
_______________________________________________________________________________________________________________ TestTransactionsEndpoint.test_transfer_assets_with_payload ________________________________________________________________________________________________________________

self = <tests.test_driver.TestTransactionsEndpoint object at 0x7fd6e0df5908>, alice_driver = <bigchaindb_driver.driver.BigchainDB object at 0x7fd6e0df5c50>
persisted_alice_transaction = {'id': 'f1040324e5142e93542f3d66f00fd2237d3c9bd13a5d4ea1ea49044ad6f1e02b', 'transaction': {'conditions': [{'cid': 0, '...: None, 'owners_before': ['G7J7bXF8cqSrjrxUKwcF8tCriEKC5CgyPHmtGwUi4BK3']}], 'operation': 'CREATE', ...}, 'version': 1}
bob_pubkey = '2dBVUoATxEzEqRdsi64AFsJnn2ywLCwnbNwW7K9BuVuS', bob_privkey = '4S1dzx3PSdMAfs59aBkQefPASizTs728HnhLNpYZWCad'

    def test_transfer_assets_with_payload(self, alice_driver,
                                          persisted_alice_transaction,
                                          bob_pubkey, bob_privkey):
        tx = alice_driver.transactions.transfer(
>           persisted_alice_transaction, bob_pubkey, payload={'a': 'b'})

tests/test_driver.py:95: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
bigchaindb_driver/driver.py:212: in transfer
    return self._push(signed_transfer_transaction)
bigchaindb_driver/driver.py:225: in _push
    method='POST', path=self.path, json=transaction)
bigchaindb_driver/transport.py:46: in forward_request
    response = connection.request(method=method, path=path, json=json)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <bigchaindb_driver.connection.Connection object at 0x7fd6e0df5d30>, method = 'POST', path = '/transactions/', json = {'message': 'Invalid transaction', 'status': 400}, kwargs = {}, url = 'http://bdb-server:9984/api/v1/transactions/', response = <Response [400]>
text = '{\n  "message": "Invalid transaction",\n  "status": 400\n}', exc_cls = <class 'bigchaindb_driver.exceptions.TransportError'>

    def request(self, method, *, path=None, json=None, **kwargs):
        """Performs an HTTP requests for the specified arguments.

            Args:
                method (str): HTTP method (e.g.: `'GET`'.
                path (str): API endpoint path (e.g.: `'/transactions'`.
                json (dict): JSON data to send along with the request.
                kwargs: Optional keyword arguments.

            """
        url = self.node_url + path if path else self.node_url
        response = self.session.request(
            method=method, url=url, json=json, **kwargs)
        text = response.text
        try:
            json = response.json()
        except ValueError:
            json = None
        if not (200 <= response.status_code < 300):
            exc_cls = HTTP_EXCEPTIONS.get(response.status_code, TransportError)
>           raise exc_cls(response.status_code, text, json)
E           bigchaindb_driver.exceptions.TransportError: (400, '{\n  "message": "Invalid transaction",\n  "status": 400\n}', {'status': 400, 'message': 'Invalid transaction'})

bigchaindb_driver/connection.py:45: TransportError
=========================================================================================================================== 2 failed, 19 passed in 3.62 seconds ===========================================================================================================================

fix docs building for rtd

from @ttmc

The ReadTheDocs build for the BigchainDB Python Driver docs is failing because:

"error: The 'bigchaindb>=0.7.0' distribution was not found and is required by bigchaindb-driver"

Revisit transfer()'s inputs

Currently, transfer() requires a user to specify a Transaction object from bigchaindb-common and a list of Condition objects from bigchaindb-common. Ideally, the user shouldn't have to worry about creating these objects and instead use their ids instead.

Driver should take host of nodes, not specific API path

Currently the driver class takes any URI as a valid parameter for a URI pointing to a BDB node:
See: https://github.com/bigchaindb/bigchaindb-driver/blob/master/bigchaindb_driver/driver.py#L34

When doing requests, the connection's path just specifies the path on a single level (e.g. /transactions), so that when initializing the driver with:

Driver('http://ipdb.foundation', 'http://localhost:9984')

requests fail, as for both specified URIS, their path to the API + VERSION is missing.
To fix the earlier given example:

Driver('http://ipdb.foundation/api/v1', 'http://localhost:9984/api/v1').

This ticket suggests to add the paths in the initialization method of the driver to the node-URI given by the user.

Support python 3.4

BigchainDB supports python 3.4, so it's odd that the driver wouldn't. I don't think there's anything in the code that doesn't let us do this, so adding tox tests for 3.4 might be enough.

Also requires a docs change.

docker-compose bdb-server service port clashes

  • bigchaindb-driver version: master branch
  • Python version: 3.5.2 (docker setup)
  • Operating System: Ubuntu (docker setup)

Description

In order to run the tests, one needs to run the BigchainDB server. When using docker-compose, one starts rethinkdb first, and then starts the bigchaindb server. The second operation resulted in an error.

What I Did

Starting bdb-server with docker-compose.

$ docker-compose up -d bdb-server
Starting bigchaindbdriver_bdb-server_1

ERROR: for bdb-server  driver failed programming external connectivity on endpoint bigchaindbdriver_bdb-server_1 (c5aa4d5bee67dd8f943cfc49c6e6b3481cc666c6334d981d018b0bdc5e8ca12b): Bind for 0.0.0.0:32769 failed: port is already allocated
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "compose/cli/main.py", line 63, in main
AttributeError: 'ProjectError' object has no attribute 'msg'
docker-compose returned -1

Setting the BigchainDB nodes attribute propagates wherever relevant

Changing, (whether it is via a setter, or directly) the nodes attribute on a BigchainDB instance will cause the transport attribute to be out of sync with the change. Briefly, the change need to be applied to:

BigchainDB --> transport --> pool of connections

Notes

  • This issue is more concerned about consistency
  • One way could be to remove the _nodes attribute

Provide a transaction/fulfillment/condition validation utility

To support cases similar to:

>>> # Create another transfer transaction with the same input
>>> tx_transfer2 = b.create_transaction(testuser1_pub, testuser2_pub, tx_retrieved_id, 'TRANSFER')
>>>
>>> # Sign the transaction
>>> tx_transfer_signed2 = b.sign_transaction(tx_transfer2, testuser1_priv)
>>>
>>> # Check if the transaction is valid
>>> b.validate_transaction(tx_transfer_signed2)
DoubleSpend: input `{'cid': 0, 'txid': '933cd83a419d2735822a2154c84176a2f419cbd449a74b94e592ab807af23861'}` was already spent

see https://github.com/bigchaindb/bigchaindb/blob/master/docs/source/drivers-clients/python-server-api-examples.md#double-spends

Support "granular" transaction creation steps

Creating a transaction via BigchainDB.transactions.create involves three main steps:

  1. Creation of the dictionary representing the transaction for the given user, and data payload.
  2. Signature of the transaction, resulting in a new dictionary
  3. Broadcast the transaction to one or more BigchainDB server nodes.

The above three steps are not directly available via the bigchaindb driver, and it is the goal of this ticket to make them available.

support strings and tuples for owners_after in .prepare

Thanks to @JosefGattermayer for reporting via the bigchaindb gitter channel (under @jgattermayer_twitter), who was trying the master branch, which had a newly merged PR #109

Hi, I'm trying the newly merged PR ...
I'm calling:

alice = generate_keypair()
bob = generate_keypair()
creation_tx = bdb.transactions.prepare(owners_before=alice.verifying_key,owners_after=bob.verifying_key,asset=None)

but it fails with:

Traceback (most recent call last):
  File "bigchain.py", line 31, in <module>
    creation_tx = bdb.transactions.prepare(owners_before=alice.verifying_key,owners_after=bob.verifying_key,asset=None)
  File "/usr/local/lib/python3.5/site-packages/bigchaindb_driver-0.0.2-py3.5.egg/bigchaindb_driver/driver.py", line 183, in prepare
    inputs=inputs,
  File "/usr/local/lib/python3.5/site-packages/bigchaindb_driver-0.0.2-py3.5.egg/bigchaindb_driver/offchain.py", line 116, in prepare_transaction
    inputs=inputs,
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/functools.py", line 743, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "/usr/local/lib/python3.5/site-packages/bigchaindb_driver-0.0.2-py3.5.egg/bigchaindb_driver/offchain.py", line 43, in _prepare_create_transaction_dispatcher
    return prepare_create_transaction(**kwargs)
  File "/usr/local/lib/python3.5/site-packages/bigchaindb_driver-0.0.2-py3.5.egg/bigchaindb_driver/offchain.py", line 168, in prepare_create_transaction
    asset=asset,
  File "/usr/local/lib/python3.5/site-packages/BigchainDB-0.7.0-py3.5.egg/bigchaindb/common/transaction.py", line 677, in create
    raise TypeError('`owners_after` must be a list instance')
TypeError: `owners_after` must be a list instance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.