Skip to content

Instantly share code, notes, and snippets.

@mbwhite
Created January 19, 2021 11:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbwhite/ff820757b5b5cb4577c81e13c5934ed7 to your computer and use it in GitHub Desktop.
Save mbwhite/ff820757b5b5cb4577c81e13c5934ed7 to your computer and use it in GitHub Desktop.
Very simple query of IBP using the node sdk
// Apache-2
// Import and IBP Node SDK, and also two cli helpers
const ibp = require('ibp-node-sdk');
const { table } = require('table');
const chalk = require('chalk');
// package JSON contains
// "chalk": "^4.1.0",
// "ibp-node-sdk": "^0.1.11",
// "table": "^6.0.7"
// the API key, and endpoint need to used here. Get these from a IBP Service Credential
// Create an authenticator
const authenticator = new ibp.IamAuthenticator({
apikey: process.env.IBP_KEY,
});
// Create client from the "BlockchainV3" class
const client = ibp.BlockchainV3.newInstance({
authenticator: authenticator,
url: process.env.IBP_ENDPOINT,
});
// utility to format the json object
const format = (results, title, data) => {
for (const key in results) {
const version = results[key];
if (version.default) {
data.push([chalk.bold(title), chalk.bold(version.version), chalk.bold.blueBright('*')])
} else {
data.push([title, version.version, ''])
}
}
}
// main method
const main = async () => {
response = await client.getFabVersions();
let data = [[chalk.bold('Component'), chalk.bold('Version'), chalk.bold('Default')]];
let results = response.result.versions;
format(results.ca, 'ca', data);
format(results.peer, 'peer', data);
format(results.orderer, 'orderer', data);
config = {
columns: {
0: {
alignment: 'left',
width: 10,
},
1: {
alignment: 'center',
width: 10
},
2: {
alignment: 'right',
width: 10
}
}
};
console.log(table(data));
}
main().then().catch((e) => { console.error(e) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment