Skip to content

Commit

Permalink
Merge pull request #159 from bigchaindb/tendermint-tx-fixed
Browse files Browse the repository at this point in the history
Update driver in order to be compatible with BigchainDB2.0
  • Loading branch information
Manolo authored Mar 29, 2018
2 parents a1b25b1 + a905260 commit 618c252
Show file tree
Hide file tree
Showing 19 changed files with 261 additions and 228 deletions.
23 changes: 1 addition & 22 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
{
"presets": [
"@ava/stage-4",
"@ava/transform-test-files",
"es2015-no-commonjs"
],
"presets": ["env"],

"plugins": [
"transform-export-extensions",
"transform-object-assign",
"transform-object-rest-spread"
],
"sourceMaps": true,

"env": {
"bundle": {
"plugins": [
["transform-runtime", {
"polyfill": true,
"regenerator": false
}]
]
},
"cjs": {
"plugins": [
"add-module-exports",
"transform-es2015-modules-commonjs"
]
}
}
}
9 changes: 9 additions & 0 deletions .ci/travis-before-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

sudo apt-get update
sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce

sudo rm /usr/local/bin/docker-compose
curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
chmod +x docker-compose
sudo mv docker-compose /usr/local/bin
5 changes: 5 additions & 0 deletions .ci/travis-before-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e -x

docker-compose up -d bigchaindb
5 changes: 5 additions & 0 deletions .ci/travis-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e -x

docker-compose build --no-cache bigchaindb
5 changes: 5 additions & 0 deletions .ci/travis_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e -x

docker-compose run --rm js-bigchaindb-driver yarn test
23 changes: 13 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ cache:
directories:
- node_modules

env:
global:
- DOCKER_COMPOSE_VERSION=1.19.0

before_install:
- docker run -d -p 27017:27017 mongo:3.4 --replSet=bigchain-rs
- docker run -d -p 9984:9984
-e BIGCHAINDB_KEYPAIR_PUBLIC=8wHUvvraRo5yEoJAt66UTZaFq9YZ9tFFwcauKPDtjkGw
-e BIGCHAINDB_KEYPAIR_PRIVATE=5C5Cknco7YxBRP9AgB1cbUVTL4FAcooxErLygw1DeG2D
-e BIGCHAINDB_DATABASE_BACKEND=mongodb
-e BIGCHAINDB_DATABASE_HOST=172.17.0.1
bigchaindb/bigchaindb:1.3.0
start
- gem install cowsay
- npm install -g codecov
- .ci/travis-before-install.sh

install:
- .ci/travis-install.sh

before_script:
- .ci/travis-before-script.sh
- gem install cowsay
- npm install -g codecov

script: yarn test

Expand Down
12 changes: 12 additions & 0 deletions compose/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.6

RUN apt-get update && apt-get install -y vim

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

RUN pip install --upgrade pip ipdb ipython

COPY . /usr/src/app/

RUN pip install git+https://github.com/bigchaindb/bigchaindb.git
17 changes: 17 additions & 0 deletions compose/tendermint/tmdata/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml

proxy_app = "tcp://bigchaindb:46658"
moniker = "anonymous"
fast_sync = true
db_backend = "leveldb"
log_level = "state:debug,*:error"

[consensus]
create_empty_blocks = false

[rpc]
laddr = "tcp://0.0.0.0:46657"

[p2p]
laddr = "tcp://0.0.0.0:46656"
39 changes: 39 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: '2.1'

services:
mongodb:
image: mongo:3.4.13
ports:
- "27017"
command: mongod
bigchaindb:
depends_on:
- mongodb
- tendermint
image: bigchaindb/bigchaindb:master
environment:
BIGCHAINDB_DATABASE_HOST: mongodb
BIGCHAINDB_DATABASE_PORT: 27017
BIGCHAINDB_SERVER_BIND: 0.0.0.0:9984
BIGCHAINDB_WSSERVER_HOST: 0.0.0.0
BIGCHAINDB_TENDERMINT_HOST: tendermint
BIGCHAINDB_TENDERMINT_PORT: 46657
ports:
- "9984:9984"
- "9985:9985"
- "46658"
healthcheck:
test: ["CMD", "bash", "-c", "curl http://bigchaindb:9984 && curl http://tendermint:46657/abci_query"]
interval: 3s
timeout: 5s
retries: 3
command: -l DEBUG start
tendermint:
image: tendermint/tendermint:0.12
volumes:
- ./compose/tendermint/tmdata/config.toml:/tendermint/config.toml
entrypoint: ''
ports:
- "46656"
- "46657"
command: bash -c "tendermint init && tendermint node"
25 changes: 24 additions & 1 deletion docs/source/readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,33 @@ Compatibility Matrix
+-----------------------+----------------------------------+
| ``1.3`` | ``3.x.x`` |
+-----------------------+----------------------------------+
| ``2.0`` | ``4.x.x`` |
+-----------------------+----------------------------------+



Older versions
--------------------

#### Versions 4.x.x



As part of the changes in the BigchainDB 2.0 server, some endpoint were
modified. In order to be consistent with them, the JS driver does not have
anymore the `pollStatusAndFetchTransaction()` method as there are three
different ways of posting a transaction.
- `async` using the `postTransaction`: the response will return immediately and not wait to see if the transaction is valid.
- `sync` using the `postTransactionSync`: the response will return after the transaction is validated.
- `commit` using the `postTransactionCommit`: the response will return after the transaction is committed to a block.

By default in the docs we will use the `postTransactionCommit` as is way of
being sure that the transaction is validated and commited to a block, so
there will not be any issue if you try to transfer the asset immediately.


#### Versions 3.2.x

For versions below 3.2, a transfer transaction looked like:

.. code-block:: js
Expand Down Expand Up @@ -72,7 +95,7 @@ transaction should be now:
The upgrade allows to create transfer transaction spending outputs that belong
to different transactions. So for instance is now possible to create a transfer
to different transactions. So for instance is now possible to create a transfer
transaction spending two outputs from two different create transactions:


Expand Down
54 changes: 13 additions & 41 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,14 @@ And sent over to a BigchainDB node:

.. code-block:: js
conn.postTransaction(txCreateAliceSimpleSigned)
conn.postTransactionCommit(txCreateAliceSimpleSigned)
Notice the transaction ``id``:

.. code-block:: js
txid = txCreateAliceSimpleSigned.id
To check the status of the transaction:

.. code-block:: js
conn.getStatus(txCreateAliceSimpleSigned.id)
It is also possible to check the status every 0.5 seconds
with use of the transaction ``id``:

.. code-block:: js
conn.pollStatusAndFetchTransaction(txCreateAliceSimpleSigned.id)
.. note:: It may take a small amount of time before a BigchainDB cluster
confirms a transaction as being valid.

Asset Transfer
--------------

Expand Down Expand Up @@ -198,13 +182,10 @@ And sent over to a BigchainDB node:

.. code-block:: js
conn.postTransaction(txTransferBobSigned)
conn.postTransactionCommit(txTransferBobSigned)
Check the status again:

.. code-block:: js
conn.pollStatusAndFetchTransaction(txTransferBobSigned.id)

Bob is the new owner:

Expand Down Expand Up @@ -362,15 +343,10 @@ Recap: Asset Creation & Transfer
// Send the transaction off to BigchainDB
const conn = new driver.Connection(API_PATH)
conn.postTransaction(txCreateAliceSimpleSigned)
// Check status of transaction every 0.5 seconds until fulfilled
.then(() => conn.pollStatusAndFetchTransaction(txCreateAliceSimpleSigned.id))
conn.postTransactionCommit(txCreateAliceSimpleSigned)
.then(retrievedTx => console.log('Transaction', retrievedTx.id, 'successfully posted.'))
// Check status after transaction has completed (result: { 'status': 'valid' })
// If you check the status of a transaction to fast without polling,
// It returns that the transaction is waiting in the 'backlog'
.then(() => conn.getStatus(txCreateAliceSimpleSigned.id))
.then(status => console.log('Retrieved status method 2: ', status))
// With the postTransactionCommit if the response is correct, then the transaction
// is valid and commited to a block
// Transfer bicycle to Bob
.then(() => {
Expand All @@ -386,12 +362,12 @@ Recap: Asset Creation & Transfer
let txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
console.log('Posting signed transaction: ', txTransferBobSigned)
// Post and poll status
return conn.postTransaction(txTransferBobSigned)
// Post with commit so transaction is validated and included in a block
return conn.postTransactionCommit(txTransferBobSigned)
})
.then(res => {
console.log('Response from BDB server:', res)
return conn.pollStatusAndFetchTransaction(res.id)
return res.id
})
.then(tx => {
console.log('Is Bob the owner?', tx['outputs'][0]['public_keys'][0] == bob.publicKey)
Expand Down Expand Up @@ -608,9 +584,7 @@ and further we transfer it from Bob to Chris. Expectations:
const txCreateAliceSimpleSigned = driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
console.log('\n\nPosting signed create transaction for Alice:\n', txCreateAliceSimpleSigned)
conn.postTransaction(txCreateAliceSimpleSigned)
// Check status of transaction every 0.5 seconds until fulfilled
.then(() => conn.pollStatusAndFetchTransaction(txCreateAliceSimpleSigned.id))
conn.postTransactionCommit(txCreateAliceSimpleSigned)
// Transfer bicycle from Alice to Bob
.then(() => {
Expand All @@ -624,10 +598,9 @@ and further we transfer it from Bob to Chris. Expectations:
txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
console.log('\n\nPosting signed transaction to Bob:\n', txTransferBobSigned)
// Post and poll status
return conn.postTransaction(txTransferBobSigned)
// Post with commit so transaction is validated and included in a block
return conn.postTransactionCommit(txTransferBobSigned)
})
.then(res => conn.pollStatusAndFetchTransaction(res.id))
// Second transfer of bicycle from Bob to Chris
.then(tx => {
Expand All @@ -641,10 +614,9 @@ and further we transfer it from Bob to Chris. Expectations:
let txTransferChrisSigned = driver.Transaction.signTransaction(txTransferChris, bob.privateKey)
console.log('\n\nPosting signed transaction to Chris:\n', txTransferChrisSigned)
// Post and poll status
return conn.postTransaction(txTransferChrisSigned)
// Post with commit so transaction is validated and included in a block
return conn.postTransactionCommit(txTransferChrisSigned)
})
.then(res => conn.pollStatusAndFetchTransaction(res.id))
.then(() => conn.listOutputs(alice.publicKey, true))
.then(listSpentOutputs => {
console.log("\nSpent outputs for Alice: ", listSpentOutputs.length) // Spent outputs: 1
Expand Down
Loading

0 comments on commit 618c252

Please sign in to comment.