docs updated

This commit is contained in:
manolodewiner 2018-03-27 09:07:31 +02:00
parent abe1c89025
commit b4e31fe786
2 changed files with 30 additions and 41 deletions

View File

@ -36,10 +36,27 @@ Compatibility Matrix
+-----------------------+----------------------------------+
| ``1.3`` | ``3.x.x`` |
+-----------------------+----------------------------------+
| ``2.0`` | ``4.x.x`` |
+-----------------------+----------------------------------+
Older versions
--------------------
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.
For versions below 3.2, a transfer transaction looked like:
.. code-block:: js

View File

@ -128,7 +128,7 @@ And sent over to a BigchainDB node:
.. code-block:: js
conn.postTransaction(txCreateAliceSimpleSigned)
conn.postTransactionCommit(txCreateAliceSimpleSigned)
Notice the transaction ``id``:
@ -136,22 +136,6 @@ Notice the transaction ``id``:
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
--------------
@ -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:
@ -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(() => {
@ -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)
@ -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(() => {
@ -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 => {
@ -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