You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -190,7 +190,7 @@ The function ``makeTransferTransaction()`` needs following parameters:
190
190
- Array of output objects to add to the transaction: Think of these as the recipients of the asset after the transaction. For `TRANSFER` transactions, this should usually just be a list of outputs wrapping Ed25519 conditions generated from the public keys of the recipients.
191
191
- Indices of the outputs in `unspent transaction` that this transaction fulfills.
192
192
193
-
Fulfill transaction by signing it with Alice's private key.
193
+
Fulfill transaction by signing it with Alice's private key.
194
194
195
195
.. code-block:: js
196
196
@@ -228,6 +228,10 @@ Querying for Assets
228
228
229
229
BigchainDB allows you to query for assets using simple text search. This search is applied to all the strings inside the asset payload and returns all the assets that match a given text search string.
230
230
231
+
BigchainDB also allows you to query for metadata, but there are some differences. The response of the text search call, beside retrieving the asset or metadata in each case, it consist of:
232
+
- In the assets search the call returns the asset id which is the same id of the transaction that created the asset.
233
+
- In the metadata search the call returns the transaction id that contains this metadata.
234
+
231
235
Let’s assume that we created 3 assets that look like this:
232
236
233
237
.. code-block:: js
@@ -245,9 +249,9 @@ Let’s perform a text search for all assets that contain the word 'Bicycle Inc.
245
249
conn.searchAssets('Bicycle Inc.')
246
250
.then(assets=>console.log('Found assets with serial number Bicycle Inc.:', assets))
247
251
248
-
Which leads to following result:
252
+
Which leads to following result:
249
253
250
-
.. code-block:: js
254
+
.. code-block:: js
251
255
252
256
[
253
257
{
@@ -265,7 +269,49 @@ Which leads to following result:
265
269
]
266
270
267
271
268
-
This call returns all the assets that match the string 'Bicycle Inc.', sorted by text score, as well as the asset id. This is the same id of the transaction that created the asset.
272
+
This call returns all the assets that match the string 'Bicycle Inc.', sorted by text score, as well as the asset id.
273
+
274
+
275
+
Querying for Metadata
276
+
-------------------
277
+
278
+
Similar as querying for assets, in BigchainDB you can query for metadata using simple text search.
279
+
This search is applied to all the strings inside the metadata payload and returns all the metadata payloads that match a given text search string.
280
+
281
+
Having 3 metadata objets that look like this:
282
+
283
+
.. code-block:: js
284
+
285
+
metadata = [
286
+
{'state': {'price':145, 'eur/us':'1.32'}},
287
+
{'state': {'price':236, 'eur/us':'1.15'}},
288
+
{'state': {'price':102, 'eur/us':'1.32'}},
289
+
]
290
+
291
+
Let’s perform a text search for all metadata that contains the word '1.32':
292
+
293
+
.. code-block:: js
294
+
295
+
conn.searchMetadata('Bicycle Inc.')
296
+
.then(assets=>console.log('Found assets with serial number Bicycle Inc.:', assets))
This call returns all the metadata objects that match the string '1.32', sorted by text score, as well as the transaction id corresponding to each metadata object.
269
315
270
316
271
317
@@ -335,9 +381,9 @@ Recap: Asset Creation & Transfer
let txTransferBobSigned =driver.Transaction.signTransaction(txTransferBob, alice.privateKey)
343
389
console.log('Posting signed transaction: ', txTransferBobSigned)
@@ -356,13 +402,13 @@ Recap: Asset Creation & Transfer
356
402
// Search for asset based on the serial number of the bicycle
357
403
.then(() =>conn.searchAssets('Bicycle Inc.'))
358
404
.then(assets=>console.log('Found assets with serial number Bicycle Inc.:', assets))
359
-
360
405
361
-
Ed25519Keypair Seed Functionality
406
+
407
+
Ed25519Keypair Seed Functionality
362
408
---------------------------------
363
409
364
-
BigchainDB JavaScript driver allows you to create a keypair based on a seed.
365
-
The constructor accepts a 32 byte seed. One of the ways to create a seed from
410
+
BigchainDB JavaScript driver allows you to create a keypair based on a seed.
411
+
The constructor accepts a 32 byte seed. One of the ways to create a seed from
366
412
a string (e.g. a passphrase) is the one used by ``bip39``, specifically the function ``mnemonicToSeed``.
367
413
368
414
Install bip39 with npm: ``npm install bip39``
@@ -490,7 +536,7 @@ Below piece of code can be opened in your web browser. It will connect to your w
490
536
</div>
491
537
492
538
493
-
Besides that, a NodeJs version has been created to display the validated transactions.
539
+
Besides that, a NodeJs version has been created to display the validated transactions.
494
540
All transactions are printed to the console. To use this piece of code, you will need the ``ws`` (WebSocket package) through npm: ``npm install --save ws``.
495
541
496
542
.. code-block:: js
@@ -514,22 +560,22 @@ All transactions are printed to the console. To use this piece of code, you will
514
560
Difference unspent and spent output
515
561
-----------------------------------
516
562
An unspent output is simply an output of a transaction which isn't yet an input of another transaction.
517
-
So, if we transfer an asset, the output becomes spent, because it becomes the input of the transfer transaction.
563
+
So, if we transfer an asset, the output becomes spent, because it becomes the input of the transfer transaction.
518
564
The transfer transactions its output becomes unspent now until he transfers the asset again to somebody else.
519
565
520
-
We will demonstrate this with a piece of code where we transfer a bicycle from Alice to Bob,
566
+
We will demonstrate this with a piece of code where we transfer a bicycle from Alice to Bob,
521
567
and further we transfer it from Bob to Chris. Expectations:
522
568
523
-
* Output for Alice is spent
569
+
* Output for Alice is spent
524
570
* Output for Bob is spent
525
571
* Output for Chris is unspent (he is the last person in transaction chain)
526
572
527
573
.. code-block:: js
528
574
529
575
constdriver=require('bigchaindb-driver')
530
576
constAPI_PATH='http://localhost:9984/api/v1/'
531
-
constconn=newdriver.Connection(API_PATH)
532
-
577
+
constconn=newdriver.Connection(API_PATH)
578
+
533
579
constalice=newdriver.Ed25519Keypair()
534
580
constbob=newdriver.Ed25519Keypair()
535
581
constchris=newdriver.Ed25519Keypair()
@@ -573,9 +619,9 @@ and further we transfer it from Bob to Chris. Expectations:
0 commit comments