Skip to content

Commit

Permalink
fix: update example
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Mar 9, 2021
1 parent f5cd60e commit cc3aa3f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
18 changes: 15 additions & 3 deletions examples/.babelrc
Original file line number Diff line number Diff line change
@@ -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"
]
}
30 changes: 16 additions & 14 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
7 changes: 1 addition & 6 deletions examples/src/basic-usage-async-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
Expand All @@ -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(
Expand All @@ -45,7 +42,6 @@ async function basicUsage() {
const txCreateAliceSimpleSigned =
driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey)


// ======== POST CREATE Transaction ======== //
const createdTx = await conn.postTransactionCommit(txCreateAliceSimpleSigned)

Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions examples/src/basic-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
Expand All @@ -26,7 +25,6 @@ const assetdata = {

const metadata = { 'planet': 'earth' }


// ======== Create Transaction Bicycle ======== //
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction(
assetdata,
Expand Down Expand Up @@ -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
6 changes: 0 additions & 6 deletions examples/src/query-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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' } })
Expand All @@ -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(
Expand All @@ -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

0 comments on commit cc3aa3f

Please sign in to comment.