-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: rthatcher <[email protected]>
- Loading branch information
Showing
11 changed files
with
6,884 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"name": "basic-network", | ||
"version": "1.0.0", | ||
"client": { | ||
"organization": "Org1", | ||
"connection": { | ||
"timeout": { | ||
"peer": { | ||
"endorser": "300", | ||
"eventHub": "300", | ||
"eventReg": "300" | ||
}, | ||
"orderer": "300" | ||
} | ||
} | ||
}, | ||
"channels": { | ||
"mychannel": { | ||
"orderers": [ | ||
"orderer.example.com" | ||
], | ||
"peers": { | ||
"peer0.org1.example.com": {} | ||
} | ||
} | ||
}, | ||
"organizations": { | ||
"Org1": { | ||
"mspid": "Org1MSP", | ||
"peers": [ | ||
"peer0.org1.example.com" | ||
], | ||
"certificateAuthorities": [ | ||
"ca.org1.example.com" | ||
] | ||
} | ||
}, | ||
"orderers": { | ||
"orderer.example.com": { | ||
"url": "grpc://localhost:7050" | ||
} | ||
}, | ||
"peers": { | ||
"peer0.org1.example.com": { | ||
"url": "grpc://localhost:7051", | ||
"eventUrl": "grpc://localhost:7053" | ||
} | ||
}, | ||
"certificateAuthorities": { | ||
"ca.org1.example.com": { | ||
"url": "http://localhost:7054", | ||
"caName": "ca.org1.example.com" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "nodejs", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "tradeapp.js", | ||
"scripts": { | ||
"test": "rm -rf _idwallet && node addToWallet.js && node sa1.js" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"fabric-client": "^1.2.2", | ||
"fabric-network": "^1.3.0-snapshot.35" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^5.6.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// Bring key classes into scope, most importantly Fabric SDK network class | ||
const fs = require('fs'); | ||
const { FileSystemWallet, Gateway } = require('fabric-network'); | ||
|
||
// A wallet stores a collection of identities for use | ||
const wallet = new FileSystemWallet('./wallet'); | ||
|
||
async function main() { | ||
|
||
// A gateway defines the peers used to access Fabric networks | ||
const gateway = new Gateway(); | ||
|
||
// Main try/catch block | ||
try { | ||
|
||
// define the identity to use | ||
const identityLabel = '[email protected]'; | ||
|
||
// Load connection profile; will be used to locate a gateway | ||
// let connectionProfile = yaml.safeLoad(fs.readFileSync('network.yaml', 'utf8')); | ||
let ccpFile = fs.readFileSync('connection.json'); | ||
const ccp = JSON.parse(ccpFile.toString()); | ||
console.log('~~~~~~~~~~~~connectionProfile~~~~~~~~~~~~~~~~'); | ||
//console.log(ccp); | ||
|
||
|
||
// Set connection options; use 'admin' identity from application wallet | ||
let connectionOptions = { | ||
identity: identityLabel, | ||
wallet: wallet, | ||
discovery: { | ||
asLocalHost: true | ||
} | ||
}; | ||
|
||
// Connect to gateway using application specified parameters | ||
await gateway.connect(ccp, connectionOptions); | ||
|
||
console.log('Connected to Fabric gateway.'); | ||
console.log('~~~~~~~~~~~~gateway~~~~~~~~~~~~~~~~'); | ||
//console.log(gateway); | ||
|
||
// Get addressability network (channel) | ||
const network = await gateway.getNetwork('mychannel'); | ||
console.log('~~~~~~~~~~~~network~~~~~~~~~~~~~~~~'); | ||
//console.log(network); | ||
|
||
|
||
// Get addressability to trade contract | ||
const contract = await network.getContract('tradesample'); | ||
console.log('~~~~~~~~~~~~contract~~~~~~~~~~~~~~~~'); | ||
//console.log(contract); | ||
console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~'); | ||
|
||
console.log('Submit transactions.'); | ||
|
||
// Create Commodity | ||
var testCommodityKey = 'CORN'; | ||
var testCommodityJS = { docType: 'commodity', description: 'Organic Early Harvest Corn', mainExchange: 'London', quantity: 200, owner: 'Trader3' }; | ||
var testCommodity = JSON.stringify(testCommodityJS); | ||
var response = await contract.submitTransaction('createCommodity', testCommodityKey, testCommodity); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
// Create Trader | ||
var testTraderKey = 'TRADER3'; | ||
var testTraderJS = { docType: 'trader', firstName: 'Rainer', lastName: 'Valens' }; | ||
var testTrader = JSON.stringify(testTraderJS); | ||
response = await contract.submitTransaction('createTrader', testTraderKey, testTrader); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
// Add Ten Quantity - checking quantity before and afterwards! | ||
response = await contract.submitTransaction('checkQuantity', 'CORN'); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
response = await contract.submitTransaction('plusTen', 'CORN'); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
response = await contract.submitTransaction('checkQuantity', 'CORN'); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
// Trade commodity to a new owner | ||
response = await contract.submitTransaction('trade', 'CORN', 'Trader1'); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
// Check Quantity of non-existent Commodity ! | ||
console.log('check Quantity KORNE - expected failure'); | ||
response = await contract.submitTransaction('checkQuantity', 'KORNE'); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
// Trying execute instead of submit! | ||
console.log('trying execute'); | ||
response = await contract.evaluateTransaction('checkQuantity', 'CORN'); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
// History Query | ||
console.log('trying History Query'); | ||
var response = await contract.evaluateTransaction('historyForCommodity', 'CORN'); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
// Add More data before Queries ! | ||
console.log('Add more data before Queries'); | ||
response = await contract.submitTransaction('setupDemo'); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
// Trying Commodity by Owner Query ! | ||
console.log('trying Commodity by Owner Query'); | ||
response = await contract.evaluateTransaction('qCommodityByOwner', 'Trader1'); | ||
console.log('Transaction Response:'); | ||
console.log(response.toString()); | ||
|
||
// Trying Commodity by Exchange Query ! | ||
console.log('trying Commodity by Exchange Query - London'); | ||
response = await contract.evaluateTransaction('qCommodityByExchange', 'London'); | ||
console.log('Transaction Response:'); | ||
console.log(response.toString()); | ||
|
||
// Trying Commodity by Exchange Query ! | ||
console.log('trying Commodity by Exchange Query - Cardiff'); | ||
response = await contract.evaluateTransaction('qCommodityByExchange', 'Cardiff'); | ||
console.log('Transaction Response:'); | ||
console.log(response.toString()); | ||
|
||
// Trying Commodity by Exchange Query ! | ||
console.log('trying Commodity by Exchange Query - Newport'); | ||
response = await contract.evaluateTransaction('qCommodityByExchange', 'Newport'); | ||
console.log('Transaction Response:'); | ||
console.log(response.toString()); | ||
|
||
// Delete commodity | ||
response = await contract.submitTransaction('deleteCommodity', 'CORN'); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
// Delete commodity with Wrong Doc type to test error message! | ||
response = await contract.submitTransaction('deleteCommodity', 'TRADER3'); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
// Delete GOLD Commodity | ||
console.log('Delete Gold'); | ||
response = await contract.submitTransaction('deleteCommodity', 'GOLD'); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
// Delete non-existent Commodity | ||
console.log('Delete Gold - expected failure!'); | ||
response = await contract.submitTransaction('deleteCommodity', 'GOLD'); | ||
console.log('Transaction Response:', response.toString()); | ||
|
||
} catch (error) { | ||
console.log(`Error processing transaction. ${error}`); | ||
console.log(error.stack); | ||
} finally { | ||
// Disconnect from the gateway | ||
console.log('Disconnect from Fabric gateway.'); | ||
gateway.disconnect(); | ||
} | ||
} | ||
|
||
main().then(() => { | ||
console.log('done'); | ||
}).catch((e) => { | ||
console.log(e); | ||
console.log(e.stack); | ||
process.exit(-1); | ||
}); |
5 changes: 5 additions & 0 deletions
5
[email protected]/00e4975ef7cb7558f7896384aa59327575242c0a8527948a5ba3cbc397b8172b-priv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgg9sRdM+U6Bp2/xf8 | ||
tM0z+R8QAJ+nciT0mMcTXbqC85OhRANCAATJivE9CrwK9Rf8SZOTeQYPpcvlmhov | ||
6CAQXL5rKZDu1HM6sLW0RasPYjMsSdKoHA/JLhSl5Ib3BwSpKjQOfWUM | ||
-----END PRIVATE KEY----- |
4 changes: 4 additions & 0 deletions
4
[email protected]/00e4975ef7cb7558f7896384aa59327575242c0a8527948a5ba3cbc397b8172b-pub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-----BEGIN PUBLIC KEY----- | ||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEyYrxPQq8CvUX/EmTk3kGD6XL5Zoa | ||
L+ggEFy+aymQ7tRzOrC1tEWrD2IzLEnSqBwPyS4UpeSG9wcEqSo0Dn1lDA== | ||
-----END PUBLIC KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name":"[email protected]","mspid":"Org1MSP","roles":null,"affiliation":"","enrollmentSecret":"","enrollment":{"signingIdentity":"00e4975ef7cb7558f7896384aa59327575242c0a8527948a5ba3cbc397b8172b","identity":{"certificate":"-----BEGIN CERTIFICATE-----\nMIICGDCCAb+gAwIBAgIQXABKsylk3OvOsAcaood0YDAKBggqhkjOPQQDAjBzMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu\nb3JnMS5leGFtcGxlLmNvbTAeFw0xODEwMTUxMjU1NTNaFw0yODEwMTIxMjU1NTNa\nMFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T\nYW4gRnJhbmNpc2NvMR8wHQYDVQQDDBZVc2VyMUBvcmcxLmV4YW1wbGUuY29tMFkw\nEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEyYrxPQq8CvUX/EmTk3kGD6XL5ZoaL+gg\nEFy+aymQ7tRzOrC1tEWrD2IzLEnSqBwPyS4UpeSG9wcEqSo0Dn1lDKNNMEswDgYD\nVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgvz3f7OuYKUeq\nApPjxfMNQ8p5rte8Q72j0q3v3ChZb7UwCgYIKoZIzj0EAwIDRwAwRAIgEENj60nc\nI1irgHYSdJ6cEv1wRM6LGNIJgJzRoaV2pPgCIAy6DcNZeU/cMjLgNI+fx8KzXSgs\nQ22EXFCmIQGTE47d\n-----END CERTIFICATE-----\n"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# next.js build output | ||
.next | ||
|
||
# nuxt.js build output | ||
.nuxt | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const TsContract = require('./lib/ts-contract'); | ||
|
||
module.exports.TsContract = TsContract; | ||
module.exports.contracts = [ TsContract ]; |
Oops, something went wrong.