mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-11-22 01:36:56 +01:00
docs updated
This commit is contained in:
parent
abe1c89025
commit
b4e31fe786
@ -36,10 +36,27 @@ Compatibility Matrix
|
|||||||
+-----------------------+----------------------------------+
|
+-----------------------+----------------------------------+
|
||||||
| ``1.3`` | ``3.x.x`` |
|
| ``1.3`` | ``3.x.x`` |
|
||||||
+-----------------------+----------------------------------+
|
+-----------------------+----------------------------------+
|
||||||
|
| ``2.0`` | ``4.x.x`` |
|
||||||
|
+-----------------------+----------------------------------+
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Older versions
|
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:
|
For versions below 3.2, a transfer transaction looked like:
|
||||||
|
|
||||||
.. code-block:: js
|
.. code-block:: js
|
||||||
|
@ -128,7 +128,7 @@ And sent over to a BigchainDB node:
|
|||||||
|
|
||||||
.. code-block:: js
|
.. code-block:: js
|
||||||
|
|
||||||
conn.postTransaction(txCreateAliceSimpleSigned)
|
conn.postTransactionCommit(txCreateAliceSimpleSigned)
|
||||||
|
|
||||||
Notice the transaction ``id``:
|
Notice the transaction ``id``:
|
||||||
|
|
||||||
@ -136,22 +136,6 @@ Notice the transaction ``id``:
|
|||||||
|
|
||||||
txid = txCreateAliceSimpleSigned.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
|
Asset Transfer
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
@ -198,13 +182,10 @@ And sent over to a BigchainDB node:
|
|||||||
|
|
||||||
.. code-block:: js
|
.. code-block:: js
|
||||||
|
|
||||||
conn.postTransaction(txTransferBobSigned)
|
conn.postTransactionCommit(txTransferBobSigned)
|
||||||
|
|
||||||
Check the status again:
|
Check the status again:
|
||||||
|
|
||||||
.. code-block:: js
|
|
||||||
|
|
||||||
conn.pollStatusAndFetchTransaction(txTransferBobSigned.id)
|
|
||||||
|
|
||||||
Bob is the new owner:
|
Bob is the new owner:
|
||||||
|
|
||||||
@ -362,15 +343,10 @@ Recap: Asset Creation & Transfer
|
|||||||
// Send the transaction off to BigchainDB
|
// Send the transaction off to BigchainDB
|
||||||
const conn = new driver.Connection(API_PATH)
|
const conn = new driver.Connection(API_PATH)
|
||||||
|
|
||||||
conn.postTransaction(txCreateAliceSimpleSigned)
|
conn.postTransactionCommit(txCreateAliceSimpleSigned)
|
||||||
// Check status of transaction every 0.5 seconds until fulfilled
|
|
||||||
.then(() => conn.pollStatusAndFetchTransaction(txCreateAliceSimpleSigned.id))
|
|
||||||
.then(retrievedTx => console.log('Transaction', retrievedTx.id, 'successfully posted.'))
|
.then(retrievedTx => console.log('Transaction', retrievedTx.id, 'successfully posted.'))
|
||||||
// Check status after transaction has completed (result: { 'status': 'valid' })
|
// With the postTransactionCommit if the response is correct, then the transaction
|
||||||
// If you check the status of a transaction to fast without polling,
|
// is valid and commited to a block
|
||||||
// It returns that the transaction is waiting in the 'backlog'
|
|
||||||
.then(() => conn.getStatus(txCreateAliceSimpleSigned.id))
|
|
||||||
.then(status => console.log('Retrieved status method 2: ', status))
|
|
||||||
|
|
||||||
// Transfer bicycle to Bob
|
// Transfer bicycle to Bob
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@ -386,12 +362,12 @@ Recap: Asset Creation & Transfer
|
|||||||
let txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
|
let txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
|
||||||
console.log('Posting signed transaction: ', txTransferBobSigned)
|
console.log('Posting signed transaction: ', txTransferBobSigned)
|
||||||
|
|
||||||
// Post and poll status
|
// Post with commit so transaction is validated and included in a block
|
||||||
return conn.postTransaction(txTransferBobSigned)
|
return conn.postTransactionCommit(txTransferBobSigned)
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log('Response from BDB server:', res)
|
console.log('Response from BDB server:', res)
|
||||||
return conn.pollStatusAndFetchTransaction(res.id)
|
return res.id
|
||||||
})
|
})
|
||||||
.then(tx => {
|
.then(tx => {
|
||||||
console.log('Is Bob the owner?', tx['outputs'][0]['public_keys'][0] == bob.publicKey)
|
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)
|
const txCreateAliceSimpleSigned = driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
|
||||||
console.log('\n\nPosting signed create transaction for Alice:\n', txCreateAliceSimpleSigned)
|
console.log('\n\nPosting signed create transaction for Alice:\n', txCreateAliceSimpleSigned)
|
||||||
|
|
||||||
conn.postTransaction(txCreateAliceSimpleSigned)
|
conn.postTransactionCommit(txCreateAliceSimpleSigned)
|
||||||
// Check status of transaction every 0.5 seconds until fulfilled
|
|
||||||
.then(() => conn.pollStatusAndFetchTransaction(txCreateAliceSimpleSigned.id))
|
|
||||||
|
|
||||||
// Transfer bicycle from Alice to Bob
|
// Transfer bicycle from Alice to Bob
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@ -624,10 +598,9 @@ and further we transfer it from Bob to Chris. Expectations:
|
|||||||
txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
|
txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
|
||||||
console.log('\n\nPosting signed transaction to Bob:\n', txTransferBobSigned)
|
console.log('\n\nPosting signed transaction to Bob:\n', txTransferBobSigned)
|
||||||
|
|
||||||
// Post and poll status
|
// Post with commit so transaction is validated and included in a block
|
||||||
return conn.postTransaction(txTransferBobSigned)
|
return conn.postTransactionCommit(txTransferBobSigned)
|
||||||
})
|
})
|
||||||
.then(res => conn.pollStatusAndFetchTransaction(res.id))
|
|
||||||
|
|
||||||
// Second transfer of bicycle from Bob to Chris
|
// Second transfer of bicycle from Bob to Chris
|
||||||
.then(tx => {
|
.then(tx => {
|
||||||
@ -641,10 +614,9 @@ and further we transfer it from Bob to Chris. Expectations:
|
|||||||
let txTransferChrisSigned = driver.Transaction.signTransaction(txTransferChris, bob.privateKey)
|
let txTransferChrisSigned = driver.Transaction.signTransaction(txTransferChris, bob.privateKey)
|
||||||
console.log('\n\nPosting signed transaction to Chris:\n', txTransferChrisSigned)
|
console.log('\n\nPosting signed transaction to Chris:\n', txTransferChrisSigned)
|
||||||
|
|
||||||
// Post and poll status
|
// Post with commit so transaction is validated and included in a block
|
||||||
return conn.postTransaction(txTransferChrisSigned)
|
return conn.postTransactionCommit(txTransferChrisSigned)
|
||||||
})
|
})
|
||||||
.then(res => conn.pollStatusAndFetchTransaction(res.id))
|
|
||||||
.then(() => conn.listOutputs(alice.publicKey, true))
|
.then(() => conn.listOutputs(alice.publicKey, true))
|
||||||
.then(listSpentOutputs => {
|
.then(listSpentOutputs => {
|
||||||
console.log("\nSpent outputs for Alice: ", listSpentOutputs.length) // Spent outputs: 1
|
console.log("\nSpent outputs for Alice: ", listSpentOutputs.length) // Spent outputs: 1
|
||||||
|
Loading…
Reference in New Issue
Block a user