1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-24 11:01:28 +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"],
"plugins": ["syntax-async-functions", "transform-runtime", "transform-regenerator", "transform-async-to-generator"]
"presets": [["@babel/preset-env"]],
"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",
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.13.2",
"babel-loader": "^6.2.4",
"babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-transform-async-to-generator": "^6.8.0",
"babel-plugin-transform-regenerator": "^6.11.4",
"babel-plugin-transform-runtime": "^6.12.0",
"babel-preset-es2015": "^6.13.2",
"babel-preset-stage-3": "^6.11.0",
"nodemon": "^1.14.8",
"rimraf": "^2.6.2"
"@babel/cli": "^7.13.0",
"@babel/core": "^7.13.8",
"@babel/eslint-parser": "^7.13.8",
"@babel/node": "7.13.0",
"@babel/plugin-syntax-async-generators": "^7.8.4",
"@babel/plugin-transform-async-to-generator": "^7.13.0",
"@babel/plugin-transform-regenerator": "^7.12.13",
"@babel/plugin-transform-runtime": "^7.13.9",
"@babel/preset-env": "^7.13.9",
"@babel/register": "^7.13.8",
"babel-loader": "^8.2.2",
"nodemon": "^2.0.7",
"rimraf": "^3.0.2"
},
"repository": "/",
"private": true,
"dependencies": {
"bigchaindb-driver": "^4.1.0",
"bip39": "^2.5.0",
"dotenv": "^4.0.0"
"bigchaindb-driver": "^4.1.2",
"bip39": "^3.0.3",
"dotenv": "^8.2.0"
}
}

View File

@ -7,9 +7,8 @@
const driver = require('bigchaindb-driver')
require('dotenv').config()
// ======== 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',
header2: 'header2_value'
})
@ -26,11 +25,9 @@ const assetdata = {
const metadata = { 'planet': 'earth' }
// Call async basic usage function
basicUsage()
async function basicUsage() {
// ======== Create Transaction Bicycle ======== //
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
@ -45,7 +42,6 @@ async function basicUsage() {
const txCreateAliceSimpleSigned =
driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)
// ======== POST CREATE Transaction ======== //
const createdTx = await conn.postTransactionCommit(txCreateAliceSimpleSigned)
@ -60,7 +56,6 @@ async function basicUsage() {
await conn.postTransactionCommit(txTransferBobSigned)
// ======== Querying Assets ======== //
const assets = await conn.searchAssets('Bicycle Inc.')
console.log(assets) // eslint-disable-line no-console

View File

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