Skip to content

Commit 1076d2d

Browse files
author
manolodewiner
committed
merge master
2 parents 6031868 + ad03590 commit 1076d2d

File tree

6 files changed

+104
-9
lines changed

6 files changed

+104
-9
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ before_install:
1818
-e BIGCHAINDB_KEYPAIR_PRIVATE=5C5Cknco7YxBRP9AgB1cbUVTL4FAcooxErLygw1DeG2D
1919
-e BIGCHAINDB_DATABASE_BACKEND=mongodb
2020
-e BIGCHAINDB_DATABASE_HOST=172.17.0.1
21-
bigchaindb/bigchaindb:1.0.0
21+
bigchaindb/bigchaindb:1.3.0
2222
start
2323
- gem install cowsay
2424
- npm install -g codecov

docs/source/usage.rst

+47-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ The function ``makeTransferTransaction()`` needs following parameters:
188188
- 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.
189189
- Metadata for transaction (e.g. price of sold bike)
190190

191-
192191
Fulfill transaction by signing it with Alice's private key.
193192

194193
.. code-block:: js
@@ -227,6 +226,10 @@ Querying for Assets
227226

228227
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.
229228

229+
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:
230+
- In the assets search the call returns the asset id which is the same id of the transaction that created the asset.
231+
- In the metadata search the call returns the transaction id that contains this metadata.
232+
230233
Let’s assume that we created 3 assets that look like this:
231234

232235
.. code-block:: js
@@ -264,7 +267,49 @@ Which leads to following result:
264267
]
265268
266269
267-
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.
270+
This call returns all the assets that match the string 'Bicycle Inc.', sorted by text score, as well as the asset id.
271+
272+
273+
Querying for Metadata
274+
-------------------
275+
276+
Similar as querying for assets, in BigchainDB you can query for metadata using simple text search.
277+
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.
278+
279+
Having 3 metadata objets that look like this:
280+
281+
.. code-block:: js
282+
283+
metadata = [
284+
{'state': {'price': 145, 'eur/us': '1.32'}},
285+
{'state': {'price': 236, 'eur/us': '1.15'}},
286+
{'state': {'price': 102, 'eur/us': '1.32'}},
287+
]
288+
289+
Let’s perform a text search for all metadata that contains the word '1.32':
290+
291+
.. code-block:: js
292+
293+
conn.searchMetadata('Bicycle Inc.')
294+
.then(assets => console.log('Found assets with serial number Bicycle Inc.:', assets))
295+
296+
Which leads to following result:
297+
298+
.. code-block:: js
299+
300+
[
301+
{
302+
'metadata': {'state': {'price': 145, 'eur/us': '1.32'}},
303+
'id': '14045a0e27ea971f8ac88762d2d74518d3a21f3f0fcd9d8a9a3b644b689cf3eb'
304+
},
305+
{
306+
'metadata': {'state': {'price': 102, 'eur/us': '1.32'}},
307+
'id': '6dd91f4700b3f66c55c50be009018e96f026d37f565d042d1aedfb322623d17d'
308+
}
309+
]
310+
311+
312+
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.
268313

269314

270315

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
"clean": "rimraf dist/bundle dist/node",
2222
"test": "npm run lint && nyc ava test/ && npm run thanks && npm run report-coverage",
2323
"thanks": "cowsay Hi, thanks for your interest in BigchainDB. We appreciate your contribution!",
24-
"release": "./node_modules/release-it/bin/release.js --src.tagName='v%s' --github.release --npm.publish --non-interactive",
25-
"release-minor": "./node_modules/release-it/bin/release.js minor --src.tagName='v%s' --github.release --npm.publish --non-interactive",
26-
"release-major": "./node_modules/release-it/bin/release.js major --src.tagName='v%s' --github.release --npm.publish --non-interactive",
27-
"prepublishOnly": "npm update && npm run build",
24+
"release": "./node_modules/release-it/bin/release-it.js --src.tagName='v%s' --github.release --npm.publish --non-interactive",
25+
"release-minor": "./node_modules/release-it/bin/release-it.js minor --src.tagName='v%s' --github.release --npm.publish --non-interactive",
26+
"release-major": "./node_modules/release-it/bin/release-it.js major --src.tagName='v%s' --github.release --npm.publish --non-interactive",
27+
"prepublishOnly": "npm run build",
2828
"precommit": "lint-staged",
2929
"report-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov"
3030
},
@@ -54,7 +54,7 @@
5454
"husky": "^0.14.0",
5555
"lint-staged": "^5.0.0",
5656
"nyc": "^11.0.2",
57-
"release-it": "^4.4.1",
57+
"release-it": "^5.0.0",
5858
"rimraf": "^2.5.4",
5959
"sinon": "^4.0.0",
6060
"webpack": "^3.0.0"

src/connection.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default class Connection {
2525
'transactions': 'transactions',
2626
'transactionsDetail': 'transactions/%(transactionId)s',
2727
'assets': 'assets',
28+
'metadata': 'metadata',
2829
'votes': 'votes'
2930
}[endpoint]
3031
}
@@ -167,7 +168,6 @@ export default class Connection {
167168
})
168169
}
169170

170-
171171
/**
172172
* @public
173173
* @param search
@@ -179,4 +179,16 @@ export default class Connection {
179179
}
180180
})
181181
}
182+
183+
/**
184+
* @public
185+
* @param search
186+
*/
187+
searchMetadata(search) {
188+
return this._req(this.getApiUrls('metadata'), {
189+
query: {
190+
search
191+
}
192+
})
193+
}
182194
}

test/connection/test_connection.js

+15
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,18 @@ test('Get asset for text', t => {
219219
{ query: { search } }
220220
))
221221
})
222+
223+
224+
test('Get metadata for text', t => {
225+
const expectedPath = 'path'
226+
const search = 'abc'
227+
228+
conn._req = sinon.spy()
229+
conn.getApiUrls = sinon.stub().returns(expectedPath)
230+
231+
conn.searchMetadata(search)
232+
t.truthy(conn._req.calledWith(
233+
expectedPath,
234+
{ query: { search } }
235+
))
236+
})

test/integration/test_integration.js

+23
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,29 @@ test('Search for an asset', t => {
326326
})
327327

328328

329+
test('Search for metadata', t => {
330+
const conn = new Connection(API_PATH)
331+
332+
const createTx = Transaction.makeCreateTransaction(
333+
asset(),
334+
metaData,
335+
[aliceOutput],
336+
alice.publicKey
337+
)
338+
const createTxSigned = Transaction.signTransaction(
339+
createTx,
340+
alice.privateKey
341+
)
342+
343+
return conn.postTransaction(createTxSigned)
344+
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
345+
.then(() => conn.searchMetadata(createTxSigned.metadata.message))
346+
.then(assets => t.truthy(
347+
assets.pop(),
348+
createTxSigned.metadata.message
349+
))
350+
})
351+
329352
test('Search blocks containing a transaction', t => {
330353
const conn = new Connection(API_PATH)
331354

0 commit comments

Comments
 (0)