1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 01:36:56 +01:00

fix: update example

Signed-off-by: getlarge <ed@getlarge.eu>
This commit is contained in:
getlarge 2021-03-09 13:49:15 +01:00
parent 978585d649
commit 3d49a6755e
No known key found for this signature in database
GPG Key ID: E4E13243600F9566
5 changed files with 33 additions and 33 deletions

View File

@ -1,4 +1,16 @@
{ {
"presets": ["es2015", "stage-3"], "presets": [["@babel/preset-env"]],
"plugins": ["syntax-async-functions", "transform-runtime", "transform-regenerator", "transform-async-to-generator"] "plugins": [
"@babel/plugin-syntax-async-generators",
[
"@babel/plugin-transform-runtime",
{
"absoluteRuntime": false,
"helpers": true,
"regenerator": true
}
],
"@babel/plugin-transform-regenerator",
"@babel/plugin-transform-async-to-generator"
]
} }

View File

@ -14,23 +14,25 @@
"author": "BigchainDB", "author": "BigchainDB",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"babel-cli": "^6.26.0", "@babel/cli": "^7.13.0",
"babel-core": "^6.13.2", "@babel/core": "^7.13.8",
"babel-loader": "^6.2.4", "@babel/eslint-parser": "^7.13.8",
"babel-plugin-syntax-async-functions": "^6.13.0", "@babel/node": "7.13.0",
"babel-plugin-transform-async-to-generator": "^6.8.0", "@babel/plugin-syntax-async-generators": "^7.8.4",
"babel-plugin-transform-regenerator": "^6.11.4", "@babel/plugin-transform-async-to-generator": "^7.13.0",
"babel-plugin-transform-runtime": "^6.12.0", "@babel/plugin-transform-regenerator": "^7.12.13",
"babel-preset-es2015": "^6.13.2", "@babel/plugin-transform-runtime": "^7.13.9",
"babel-preset-stage-3": "^6.11.0", "@babel/preset-env": "^7.13.9",
"nodemon": "^1.14.8", "@babel/register": "^7.13.8",
"rimraf": "^2.6.2" "babel-loader": "^8.2.2",
"nodemon": "^2.0.7",
"rimraf": "^3.0.2"
}, },
"repository": "/", "repository": "/",
"private": true, "private": true,
"dependencies": { "dependencies": {
"bigchaindb-driver": "^4.1.0", "bigchaindb-driver": "^4.1.2",
"bip39": "^2.5.0", "bip39": "^3.0.3",
"dotenv": "^4.0.0" "dotenv": "^8.2.0"
} }
} }

View File

@ -7,9 +7,8 @@
const driver = require('bigchaindb-driver') const driver = require('bigchaindb-driver')
require('dotenv').config() require('dotenv').config()
// ======== Preparation ======== // // ======== Preparation ======== //
const conn = new driver.Connection('https://example.com/api/v1/', { const conn = new driver.Connection('https://test.ipdb.io/api/v1/', {
header1: 'header1_value', header1: 'header1_value',
header2: 'header2_value' header2: 'header2_value'
}) })
@ -26,11 +25,9 @@ const assetdata = {
const metadata = { 'planet': 'earth' } const metadata = { 'planet': 'earth' }
// Call async basic usage function // Call async basic usage function
basicUsage() basicUsage()
async function basicUsage() { async function basicUsage() {
// ======== Create Transaction Bicycle ======== // // ======== Create Transaction Bicycle ======== //
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction( const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
@ -45,7 +42,6 @@ async function basicUsage() {
const txCreateAliceSimpleSigned = const txCreateAliceSimpleSigned =
driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey) driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
// ======== POST CREATE Transaction ======== // // ======== POST CREATE Transaction ======== //
const createdTx = await conn.postTransactionCommit(txCreateAliceSimpleSigned) const createdTx = await conn.postTransactionCommit(txCreateAliceSimpleSigned)
@ -60,7 +56,6 @@ async function basicUsage() {
await conn.postTransactionCommit(txTransferBobSigned) await conn.postTransactionCommit(txTransferBobSigned)
// ======== Querying Assets ======== // // ======== Querying Assets ======== //
const assets = await conn.searchAssets('Bicycle Inc.') const assets = await conn.searchAssets('Bicycle Inc.')
console.log(assets) // eslint-disable-line no-console console.log(assets) // eslint-disable-line no-console

View File

@ -7,9 +7,8 @@
const driver = require('bigchaindb-driver') const driver = require('bigchaindb-driver')
require('dotenv').config() require('dotenv').config()
// ======== Preparation ======== // // ======== Preparation ======== //
const conn = new driver.Connection('https://example.com/api/v1/', { const conn = new driver.Connection('https://test.ipdb.io/api/v1/', {
header1: 'header1_value', header1: 'header1_value',
header2: 'header2_value' header2: 'header2_value'
}) })
@ -26,7 +25,6 @@ const assetdata = {
const metadata = { 'planet': 'earth' } const metadata = { 'planet': 'earth' }
// ======== Create Transaction Bicycle ======== // // ======== Create Transaction Bicycle ======== //
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction( const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
assetdata, assetdata,
@ -60,7 +58,6 @@ conn.postTransactionCommit(txCreateAliceSimpleSigned)
console.log('Was Alice the previous owner?', tx.inputs[0].owners_before[0] === alice.publicKey) // eslint-disable-line no-console console.log('Was Alice the previous owner?', tx.inputs[0].owners_before[0] === alice.publicKey) // eslint-disable-line no-console
}) })
// ======== Search Asset by Serial Number ======== // // ======== Search Asset by Serial Number ======== //
.then(() => conn.searchAssets('Bicycle Inc.')) .then(() => conn.searchAssets('Bicycle Inc.'))
.then(assets => console.log('Found assets with serial number Bicycle Inc.:', assets)) // eslint-disable-line no-console .then(assets => console.log('Found assets with serial number Bicycle Inc.:', assets)) // eslint-disable-line no-console

View File

@ -7,7 +7,6 @@
const driver = require('bigchaindb-driver') const driver = require('bigchaindb-driver')
require('dotenv').config() require('dotenv').config()
// ======== Preparation ======== // // ======== Preparation ======== //
const conn = new driver.Connection('https://example.com/api/v1/', { const conn = new driver.Connection('https://example.com/api/v1/', {
header1: 'header1_value', header1: 'header1_value',
@ -16,7 +15,6 @@ const conn = new driver.Connection('https://example.com/api/v1/', {
const alice = new driver.Ed25519Keypair() const alice = new driver.Ed25519Keypair()
// ======== Asset Array ======== // // ======== Asset Array ======== //
const assetArray = [] const assetArray = []
assetArray.push({ 'bicycle': { 'serial_number': 'abc', 'manufacturer': 'BicyclesInc' } }) assetArray.push({ 'bicycle': { 'serial_number': 'abc', 'manufacturer': 'BicyclesInc' } })
@ -25,7 +23,6 @@ assetArray.push({ 'bicycle': { 'serial_number': 'fgh', 'manufacturer': 'Bicycles
const metadata = { 'planet': 'Pluto' } const metadata = { 'planet': 'Pluto' }
// ======== Create Transactions for bicycles ======== // // ======== Create Transactions for bicycles ======== //
function createTx(assetdata) { function createTx(assetdata) {
const txCreate = driver.Transaction.makeCreateTransaction( const txCreate = driver.Transaction.makeCreateTransaction(
@ -41,16 +38,13 @@ function createTx(assetdata) {
return conn.postTransactionCommit(txCreateSigned) return conn.postTransactionCommit(txCreateSigned)
} }
// ======== Execute all promises in order to post transactions and fetch them ======== // // ======== Execute all promises in order to post transactions and fetch them ======== //
Promise.all(assetArray.map(createTx)) Promise.all(assetArray.map(createTx))
// ======== Querying Assets for Assetdata ======== // // ======== Querying Assets for Assetdata ======== //
.then(() => conn.searchAssets('BicyclesInc')) .then(() => conn.searchAssets('BicyclesInc'))
.then(assets => console.log('Found assets with serial number "BicyclesInc":', assets)) // eslint-disable-line no-console .then(assets => console.log('Found assets with serial number "BicyclesInc":', assets)) // eslint-disable-line no-console
// ======== Querying Assets for Metadata ======== // // ======== Querying Assets for Metadata ======== //
.then(() => conn.searchMetadata('Pluto')) .then(() => conn.searchMetadata('Pluto'))
.then(assets => console.log('Found assets with metadata "Pluto":', assets)) // eslint-disable-line no-console .then(assets => console.log('Found assets with metadata "Pluto":', assets)) // eslint-disable-line no-console