Skip to content

Commit 9304715

Browse files
authored
Merge pull request #381 from bigchaindb/bigchaindb-2.0
Problem: Driver needs to be updated to support BigchainDB 2.0
2 parents e6c0c46 + c058686 commit 9304715

26 files changed

+277
-429
lines changed

.ci/travis-after-success.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
set -e -x
44

55
if [ "${TOXENV}" == "py36" ]; then
6-
codecov
6+
codecov -v
77
fi

.ci/travis-before-install.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/bin/bash
22

33
if [[ "${TOXENV}" == "py35" || "${TOXENV}" == "py36" ]]; then
4-
source /etc/lsb-release
5-
echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | tee -a /etc/apt/sources.list.d/rethinkdb.list
6-
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | apt-key add -
7-
apt-get update -qq
4+
sudo apt-get update
5+
sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
6+
7+
sudo rm /usr/local/bin/docker-compose
8+
curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
9+
chmod +x docker-compose
10+
sudo mv docker-compose /usr/local/bin
811
fi

.ci/travis-before-script.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
set -e -x
44

55
if [[ "${TOXENV}" == "py35" || "${TOXENV}" == "py36" ]]; then
6-
rethinkdb --daemon
7-
export BIGCHAINDB_KEYPAIR_PUBLIC=GW1nrdZm4mbVC8ePeiGWz6DqHexqewqy5teURVHi3RG4
8-
export BIGCHAINDB_KEYPAIR_PRIVATE=2kQgBtQnHoauw8QchKM7xYvEBW1QDoHzhBsCL9Vi1AzB
9-
10-
# Start BigchainDB in the background and ignore any output
11-
bigchaindb start >/dev/null 2>&1 &
6+
docker-compose up -d bigchaindb
127
fi

.ci/travis-install.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pip install --upgrade pip
66
pip install --upgrade tox
77

88
if [[ "${TOXENV}" == "py35" || "${TOXENV}" == "py36" ]]; then
9-
sudo apt-get install rethinkdb
10-
pip install git+https://github.com/bigchaindb/bigchaindb.git
9+
docker-compose build --no-cache bigchaindb bigchaindb-driver
1110
pip install --upgrade codecov
1211
fi

.ci/travis_script.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -e -x
4+
5+
if [[ "${TOXENV}" == "py35" || "${TOXENV}" == "py36" ]]; then
6+
docker-compose run --rm bigchaindb-driver pytest -v
7+
else
8+
tox -e ${TOXENV}
9+
fi

.travis.yml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@ python:
44
- 3.6
55

66
env:
7-
- TOXENV=py35
8-
- TOXENV=py36
9-
- TOXENV=flake8
10-
- TOXENV=docs
11-
7+
global:
8+
- DOCKER_COMPOSE_VERSION=1.19.0
9+
matrix:
10+
- TOXENV=py35
11+
- TOXENV=py36
12+
- TOXENV=flake8
13+
- TOXENV=docs
14+
1215
matrix:
1316
fast_finish: true
1417
exclude:
15-
- python: 3.5
16-
env: TOXENV=flake8
17-
- python: 3.5
18-
env: TOXENV=docs
19-
- python: 3.5
20-
env: TOXENV=py36
21-
- python: 3.6
22-
env: TOXENV=py35
18+
- python: 3.5
19+
env: TOXENV=flake8
20+
- python: 3.5
21+
env: TOXENV=docs
22+
- python: 3.5
23+
env: TOXENV=py36
24+
- python: 3.6
25+
env: TOXENV=py35
2326

2427
before_install:
2528
- sudo .ci/travis-before-install.sh
@@ -30,7 +33,7 @@ install:
3033
before_script:
3134
- .ci/travis-before-script.sh
3235

33-
script: tox -e ${TOXENV}
36+
script: .ci/travis_script.sh
3437

3538
after_success:
3639
- .ci/travis-after-success.sh

CONTRIBUTING.rst

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ Development Environment with Docker
8686
Depending on what you are doing, you may need to run at least one BigchainDB
8787
node. You can use the `docker-compose.yml`_ file to run a node, and perform
8888
other tasks that depend on the running node. To run a BigchainDB node, (for
89-
development), you start a MongoDB node, followed by the linked BigchainDB
89+
development), you start a MongoDB and Tendermint node, followed by the linked BigchainDB
9090
node::
9191

92-
$ docker-compose up -d db
93-
$ docker-compose up -d bdb-server
92+
# Implicitly creates a MongoDB and Tendermint instance
93+
$ docker-compose up -d bigchaindb
9494

9595
You can monitor the logs::
9696

@@ -102,44 +102,22 @@ Tests
102102

103103
To run a subset of tests::
104104

105-
$ docker-compose run --rm bdb pytest -v tests/test_driver.py
105+
$ docker-compose run --rm bigchaindb-driver pytest -v tests/test_driver.py
106106

107107
.. important:: When running tests, unless you are targeting a test that does
108108
not require a connection with the BigchainDB server, you need to run the
109-
BigchainDB and MongoDB servers::
109+
BigchainDB, MongoDB and Tendermint servers::
110110

111-
$ docker-compose up -d db
112-
$ docker-compose up -d bdb-server
113-
114-
115-
Using RethinkDB as the backend
116-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117-
The default docker-compose file runs MongoDB as a backend. In order to work
118-
with RethinkDB, one has to use the ``docker-compose.rdb.yml`` file, which
119-
implies working with `multiple compose files`_. The workflow is the same as
120-
with MongoDB.
121-
122-
First start RethinkDB::
123-
124-
$ docker-compose -f docker-compose.rdb.yml up -d db
125-
126-
then one BigchainDB server node::
127-
128-
$ docker-compose -f docker-compose.rdb.yml up -d bdb-server
129-
130-
and run the tests::
131-
132-
$ docker-compose -f docker-compose.rdb.yml run --rm bdb pytest -v
111+
$ docker-compose up -d bigchaindb
133112

134113

135114
Dependency on Bigchaindb
136115
~~~~~~~~~~~~~~~~~~~~~~~~
137116

138-
By default, the development requirements, `BigchainDB server Dockerfile <https://github.com/bigchaindb/bigchaindb-driver/blob/master/compose/server/Dockerfile>`_,
117+
By default, the development requirements, `BigchainDB server Dockerfile <https://github.com/bigchaindb/bigchaindb-driver/blob/master/compose/bigchaindb_server/Dockerfile>`_,
139118
and `.travis.yml <https://github.com/bigchaindb/bigchaindb-driver/blob/master/.travis.yml>`_
140119
are set to depend from BigchainDB's master branch to more easily track changes
141120
against BigchainDB's API.
142121

143122

144123
.. _docker-compose.yml: https://github.com/bigchaindb/bigchaindb-driver/blob/master/docker-compose.yml
145-
.. _multiple compose files: https://docs.docker.com/compose/extends/#multiple-compose-files

README.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Features
3030
* Support for preparing, fulfilling, and sending transactions to a BigchainDB
3131
node.
3232
* Retrieval of transactions by id.
33-
* Getting status of a transaction by id.
3433

3534
Install
3635
----------

bigchaindb_driver/driver.py

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def get(self, *, asset_id, operation=None, headers=None):
304304
headers=headers,
305305
)
306306

307-
def send(self, transaction, headers=None):
307+
def send(self, transaction, mode='async', headers=None):
308308
"""Submit a transaction to the Federation.
309309
310310
Args:
@@ -317,7 +317,11 @@ def send(self, transaction, headers=None):
317317
318318
"""
319319
return self.transport.forward_request(
320-
method='POST', path=self.path, json=transaction, headers=headers)
320+
method='POST',
321+
path=self.path,
322+
json=transaction,
323+
params={'mode': mode},
324+
headers=headers)
321325

322326
def retrieve(self, txid, headers=None):
323327
"""Retrieves the transaction with the given id.
@@ -334,25 +338,6 @@ def retrieve(self, txid, headers=None):
334338
return self.transport.forward_request(
335339
method='GET', path=path, headers=None)
336340

337-
def status(self, txid, headers=None):
338-
"""Retrieves the status of the transaction with the given id.
339-
340-
Args:
341-
txid (str): Id of the transaction to retrieve the status for.
342-
headers (dict): Optional headers to pass to the request.
343-
344-
Returns:
345-
dict: A dict containing a 'status' item for the transaction.
346-
347-
"""
348-
# TODO Once the HTTP API has stabilized, especially with matters
349-
# relating to the transaction status, this can be updated to match the
350-
# HTTP API more thoroughly.
351-
path = self.api_prefix + '/statuses'
352-
return self.transport.forward_request(
353-
method='GET', path=path, params={'transaction_id': txid},
354-
headers=headers)
355-
356341

357342
class OutputsEndpoint(NamespacedDriver):
358343
"""Exposes functionality of the ``'/outputs'`` endpoint.
@@ -409,39 +394,38 @@ class BlocksEndpoint(NamespacedDriver):
409394

410395
PATH = '/blocks/'
411396

412-
def get(self, *, txid, status=None, headers=None):
413-
"""Get the block(s) that contain the given transaction id
414-
(``txid``), and optionally that have the given ``status``.
397+
def get(self, *, txid, headers=None):
398+
"""Get the block that contains the given transaction id (``txid``)
399+
else return ``None``
415400
416401
Args:
417402
txid (str): Transaction id.
418-
status (str): Status the block should have. Accepted values
419-
are ``VALID``, ``UNDECIDED`` or ``INVALID``.
420403
headers (dict): Optional headers to pass to the request.
421404
422405
Returns:
423-
:obj:`list` of :obj:`str`: List of block ids.
406+
:obj:`list` of :obj:`int`: List of block heights.
424407
425408
"""
426-
return self.transport.forward_request(
409+
block_list = self.transport.forward_request(
427410
method='GET',
428411
path=self.path,
429-
params={'transaction_id': txid, 'status': status},
412+
params={'transaction_id': txid},
430413
headers=headers,
431414
)
415+
return block_list[0] if len(block_list) else None
432416

433-
def retrieve(self, block_id, headers=None):
417+
def retrieve(self, block_height, headers=None):
434418
"""Retrieves the transaction with the given id.
435419
436420
Args:
437-
block_id (str): Id of the block to retrieve.
421+
block_height (str): height of the block to retrieve.
438422
headers (dict): Optional headers to pass to the request.
439423
440424
Returns:
441425
dict: The block with the given id.
442426
443427
"""
444-
path = self.path + block_id
428+
path = self.path + block_height
445429
return self.transport.forward_request(
446430
method='GET', path=path, headers=None)
447431

bigchaindb_driver/offchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def prepare_transfer_transaction(*,
252252
'type': 'ed25519-sha-256'},
253253
'uri': 'ni:///sha-256;7ApQLsLLQgj5WOUipJg1txojmge68pctwFxvc3iOl54?fpt=ed25519-sha-256&cost=131072'},
254254
'public_keys': ['3Cxh1eKZk3Wp9KGBWFS7iVde465UvqUKnEqTg2MW4wNf']}],
255-
'version': '1.0'}
255+
'version': '2.0'}
256256
257257
Then, the input may be constructed in this way::
258258

0 commit comments

Comments
 (0)