mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-12-27 23:27:50 +01:00
merge master
This commit is contained in:
commit
1076d2d2ab
@ -18,7 +18,7 @@ before_install:
|
||||
-e BIGCHAINDB_KEYPAIR_PRIVATE=5C5Cknco7YxBRP9AgB1cbUVTL4FAcooxErLygw1DeG2D
|
||||
-e BIGCHAINDB_DATABASE_BACKEND=mongodb
|
||||
-e BIGCHAINDB_DATABASE_HOST=172.17.0.1
|
||||
bigchaindb/bigchaindb:1.0.0
|
||||
bigchaindb/bigchaindb:1.3.0
|
||||
start
|
||||
- gem install cowsay
|
||||
- npm install -g codecov
|
||||
|
@ -188,7 +188,6 @@ The function ``makeTransferTransaction()`` needs following parameters:
|
||||
- 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.
|
||||
- Metadata for transaction (e.g. price of sold bike)
|
||||
|
||||
|
||||
Fulfill transaction by signing it with Alice's private key.
|
||||
|
||||
.. code-block:: js
|
||||
@ -227,6 +226,10 @@ Querying for Assets
|
||||
|
||||
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.
|
||||
|
||||
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:
|
||||
- In the assets search the call returns the asset id which is the same id of the transaction that created the asset.
|
||||
- In the metadata search the call returns the transaction id that contains this metadata.
|
||||
|
||||
Let’s assume that we created 3 assets that look like this:
|
||||
|
||||
.. code-block:: js
|
||||
@ -264,7 +267,49 @@ Which leads to following result:
|
||||
]
|
||||
|
||||
|
||||
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.
|
||||
This call returns all the assets that match the string 'Bicycle Inc.', sorted by text score, as well as the asset id.
|
||||
|
||||
|
||||
Querying for Metadata
|
||||
-------------------
|
||||
|
||||
Similar as querying for assets, in BigchainDB you can query for metadata using simple text search.
|
||||
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.
|
||||
|
||||
Having 3 metadata objets that look like this:
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
metadata = [
|
||||
{'state': {'price': 145, 'eur/us': '1.32'}},
|
||||
{'state': {'price': 236, 'eur/us': '1.15'}},
|
||||
{'state': {'price': 102, 'eur/us': '1.32'}},
|
||||
]
|
||||
|
||||
Let’s perform a text search for all metadata that contains the word '1.32':
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
conn.searchMetadata('Bicycle Inc.')
|
||||
.then(assets => console.log('Found assets with serial number Bicycle Inc.:', assets))
|
||||
|
||||
Which leads to following result:
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
[
|
||||
{
|
||||
'metadata': {'state': {'price': 145, 'eur/us': '1.32'}},
|
||||
'id': '14045a0e27ea971f8ac88762d2d74518d3a21f3f0fcd9d8a9a3b644b689cf3eb'
|
||||
},
|
||||
{
|
||||
'metadata': {'state': {'price': 102, 'eur/us': '1.32'}},
|
||||
'id': '6dd91f4700b3f66c55c50be009018e96f026d37f565d042d1aedfb322623d17d'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
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.
|
||||
|
||||
|
||||
|
||||
|
10
package.json
10
package.json
@ -21,10 +21,10 @@
|
||||
"clean": "rimraf dist/bundle dist/node",
|
||||
"test": "npm run lint && nyc ava test/ && npm run thanks && npm run report-coverage",
|
||||
"thanks": "cowsay Hi, thanks for your interest in BigchainDB. We appreciate your contribution!",
|
||||
"release": "./node_modules/release-it/bin/release.js --src.tagName='v%s' --github.release --npm.publish --non-interactive",
|
||||
"release-minor": "./node_modules/release-it/bin/release.js minor --src.tagName='v%s' --github.release --npm.publish --non-interactive",
|
||||
"release-major": "./node_modules/release-it/bin/release.js major --src.tagName='v%s' --github.release --npm.publish --non-interactive",
|
||||
"prepublishOnly": "npm update && npm run build",
|
||||
"release": "./node_modules/release-it/bin/release-it.js --src.tagName='v%s' --github.release --npm.publish --non-interactive",
|
||||
"release-minor": "./node_modules/release-it/bin/release-it.js minor --src.tagName='v%s' --github.release --npm.publish --non-interactive",
|
||||
"release-major": "./node_modules/release-it/bin/release-it.js major --src.tagName='v%s' --github.release --npm.publish --non-interactive",
|
||||
"prepublishOnly": "npm run build",
|
||||
"precommit": "lint-staged",
|
||||
"report-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov"
|
||||
},
|
||||
@ -54,7 +54,7 @@
|
||||
"husky": "^0.14.0",
|
||||
"lint-staged": "^5.0.0",
|
||||
"nyc": "^11.0.2",
|
||||
"release-it": "^4.4.1",
|
||||
"release-it": "^5.0.0",
|
||||
"rimraf": "^2.5.4",
|
||||
"sinon": "^4.0.0",
|
||||
"webpack": "^3.0.0"
|
||||
|
@ -25,6 +25,7 @@ export default class Connection {
|
||||
'transactions': 'transactions',
|
||||
'transactionsDetail': 'transactions/%(transactionId)s',
|
||||
'assets': 'assets',
|
||||
'metadata': 'metadata',
|
||||
'votes': 'votes'
|
||||
}[endpoint]
|
||||
}
|
||||
@ -167,7 +168,6 @@ export default class Connection {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param search
|
||||
@ -179,4 +179,16 @@ export default class Connection {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param search
|
||||
*/
|
||||
searchMetadata(search) {
|
||||
return this._req(this.getApiUrls('metadata'), {
|
||||
query: {
|
||||
search
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -219,3 +219,18 @@ test('Get asset for text', t => {
|
||||
{ query: { search } }
|
||||
))
|
||||
})
|
||||
|
||||
|
||||
test('Get metadata for text', t => {
|
||||
const expectedPath = 'path'
|
||||
const search = 'abc'
|
||||
|
||||
conn._req = sinon.spy()
|
||||
conn.getApiUrls = sinon.stub().returns(expectedPath)
|
||||
|
||||
conn.searchMetadata(search)
|
||||
t.truthy(conn._req.calledWith(
|
||||
expectedPath,
|
||||
{ query: { search } }
|
||||
))
|
||||
})
|
||||
|
@ -326,6 +326,29 @@ test('Search for an asset', t => {
|
||||
})
|
||||
|
||||
|
||||
test('Search for metadata', t => {
|
||||
const conn = new Connection(API_PATH)
|
||||
|
||||
const createTx = Transaction.makeCreateTransaction(
|
||||
asset(),
|
||||
metaData,
|
||||
[aliceOutput],
|
||||
alice.publicKey
|
||||
)
|
||||
const createTxSigned = Transaction.signTransaction(
|
||||
createTx,
|
||||
alice.privateKey
|
||||
)
|
||||
|
||||
return conn.postTransaction(createTxSigned)
|
||||
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
||||
.then(() => conn.searchMetadata(createTxSigned.metadata.message))
|
||||
.then(assets => t.truthy(
|
||||
assets.pop(),
|
||||
createTxSigned.metadata.message
|
||||
))
|
||||
})
|
||||
|
||||
test('Search blocks containing a transaction', t => {
|
||||
const conn = new Connection(API_PATH)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user