This repository has been archived by the owner on Feb 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a legacy import of the release originally managed in pure github. You may find the history of this release in the archives here: https://github.com/hyperledger-archives/fabric-chaintool/releases/tag/v0.10.1 Change-Id: I57fcb68c85ccf92b6eee4b57f97f41ddf0f59e2b Signed-off-by: Gregory Haskins <[email protected]>
- Loading branch information
Showing
48 changed files
with
447 additions
and
585 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
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 |
---|---|---|
|
@@ -14,48 +14,36 @@ This directory contains an implementation of the chaincode application called "e | |
│ ├── appinit.cci | ||
│ └── org.hyperledger.chaincode.example02.cci | ||
└── client | ||
├── rest | ||
│ ├── cljs | ||
│ │ ├── Makefile | ||
│ │ ├── appinit.proto | ||
│ │ ├── org.hyperledger.chaincode.example02.proto | ||
│ │ ├── project.clj | ||
│ │ └── src | ||
│ │ └── example02 | ||
│ │ ├── core.cljs | ||
│ │ ├── main.cljs | ||
│ │ └── rpc.cljs | ||
│ └── nodejs | ||
│ ├── appinit.proto | ||
│ ├── index.js | ||
│ ├── org.hyperledger.chaincode.example02.proto | ||
│ └── package.json | ||
└── sdk | ||
├── Makefile | ||
├── cljs | ||
│ ├── Makefile | ||
│ ├── appinit.proto | ||
│ ├── org.hyperledger.chaincode.example02.proto | ||
│ ├── project.clj | ||
│ └── src | ||
│ └── example02 | ||
│ ├── core.cljs | ||
│ ├── hlc | ||
│ │ ├── core.cljs | ||
│ │ └── user.cljs | ||
│ ├── main.cljs | ||
│ ├── rpc.cljs | ||
│ └── util.cljs | ||
└── nodejs | ||
├── appinit.proto | ||
├── index.js | ||
├── util.js | ||
├── org.hyperledger.chaincode.example02.proto | ||
├── project.clj | ||
└── src | ||
└── example02 | ||
├── core.cljs | ||
├── hlc | ||
│ ├── core.cljs | ||
│ └── user.cljs | ||
├── main.cljs | ||
├── rpc.cljs | ||
└── util.cljs | ||
└── package.json | ||
``` | ||
* app - contains a org.hyperledger.chaincode.golang platform based chaincode application. | ||
* This is the code deployed to the blockchain | ||
* client - client applications for interacting with the chaincode application | ||
* rest - REST api based clients | ||
* nodejs - A simple demonstration of using nodejs+REST. | ||
* cljs - A complete client for example02 over REST written in ClojureScript | ||
* sdk - SDK based client, written in ClojureScript | ||
* nodejs - A simple demonstration of using nodejs. | ||
* cljs - A complete client for example02 written in ClojureScript | ||
|
||
## Deploying and interacting with the example02 | ||
### Step 1 - Fabric environment | ||
You will need a functioning peer that has chaintool v0.7 or higher available in the $PATH. You may check the version of chaintool you have with 'chaintool -h'. Once confirmed, start the peer with _peer node start_ as you normally would. It is advised to keep the configuration as simple as possible (1 VP, no security, noops consensus) | ||
You will need a functioning peer that has chaintool v0.10.1 or higher available in the $PATH. You may check the version of chaintool you have with 'chaintool -h'. Once confirmed, start the peer with _peer node start_ as you normally would. It is advised to keep the configuration as simple as possible (1 VP, no security, noops consensus) | ||
|
||
### Step 2 - Package the chaincode application | ||
Run 'chaintool package' from the app folder, noting the CAR output path | ||
|
@@ -82,11 +70,11 @@ Chaincode SHA3: f7026e0675b22a9d78b9f7f0cb97c93165bdefedc86de97f00e76b506c7 | |
#### Note: | ||
The _chaintool package_ command is designed to package for deployment, not development. If you started your node with _peer node start --peer-chaincodedev_, run _chaintool build_ instead. This is analogous to building non-chaintool chaincode using _go build_. The output will be placed in the _app/build/bin/_ directory. | ||
### Step 3 - Compile the client | ||
Run 'make' from the client/rest/cljs folder | ||
Run 'make' from the client/cljs folder | ||
``` | ||
$ make | ||
lein npm install | ||
[email protected] /Users/ghaskins/sandbox/git/chaintool/examples/example02/client/rest/cljs | ||
[email protected] /Users/ghaskins/sandbox/git/chaintool/examples/example02/client/cljs | ||
├─┬ [email protected] | ||
│ ├─┬ [email protected] | ||
│ │ ├── [email protected] | ||
|
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
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,153 @@ | ||
var program = require('commander'); | ||
var pb = require("protobufjs"); | ||
|
||
var builder = pb.newBuilder({ convertFieldsToCamelCase: true }); | ||
|
||
pb.loadProtoFile("./protos/appinit.proto", builder); | ||
var init = builder.build("appinit"); | ||
|
||
pb.loadProtoFile("./protos/org.hyperledger.chaincode.example02.proto", builder); | ||
var app = builder.build("org.hyperledger.chaincode.example02"); | ||
|
||
var hfc = require('fabric-client'); | ||
var hfcutils = require('fabric-client/lib/utils.js'); | ||
var utils = require('./lib/util.js'); | ||
var Peer = require('fabric-client/lib/Peer.js'); | ||
var Orderer = require('fabric-client/lib/Orderer.js'); | ||
var CA = require('fabric-ca-client/lib/FabricCAClientImpl.js'); | ||
var User = require('fabric-client/lib/User.js'); | ||
|
||
var chain; | ||
var peer; | ||
|
||
function createRequest(fcn, args) { | ||
var tx_id = hfcutils.buildTransactionID({length:12}); | ||
var nonce = hfcutils.getNonce(); | ||
|
||
// send proposal to endorser | ||
var request = { | ||
type: 'car', | ||
targets: [peer], | ||
chainId: 'testchainid', | ||
chaincodeId: 'mycc', | ||
fcn: fcn, | ||
args: [args.toBase64()], | ||
txId: tx_id, | ||
nonce: nonce | ||
}; | ||
|
||
return request; | ||
} | ||
|
||
function connect() { | ||
var client = new hfc(); | ||
chain = client.newChain('chaintool-demo'); | ||
|
||
peer = new Peer('grpc://localhost:7051'); | ||
var orderer = new Orderer('grpc://localhost:7050'); | ||
|
||
chain.addOrderer(orderer); | ||
chain.addPeer(peer); | ||
|
||
return utils.setStateStore(client, ".hfc-kvstore") | ||
.then(function() { | ||
var ca = new CA('http://localhost:7054'); | ||
|
||
return utils.getUser(client, ca, 'admin', 'adminpw'); | ||
}); | ||
} | ||
|
||
function deploy(args, path) { | ||
|
||
var request = createRequest('init', new init.Init(args)); | ||
if (path) { | ||
request.chaincodePath = path; | ||
} else { | ||
chain.setDevMode(true); | ||
} | ||
|
||
// send proposal to endorser | ||
return chain.sendDeploymentProposal(request) | ||
.then(function(response) { utils.processProposalResponse(chain, response); }) | ||
.then(utils.intradelay); | ||
} | ||
|
||
function sendTransaction(fcn, args) { | ||
var request = createRequest(fcn, args); | ||
return chain.sendTransactionProposal(request) | ||
.then(function(response) { utils.processProposalResponse(chain, response); }) | ||
.then(utils.intradelay); | ||
} | ||
|
||
function sendQuery(fcn, args) { | ||
var request = createRequest(fcn, args); | ||
return chain.queryByChaincode(request); | ||
} | ||
|
||
function makePayment(args) { | ||
return sendTransaction('org.hyperledger.chaincode.example02/fcn/1', | ||
new app.PaymentParams(args)); | ||
} | ||
|
||
function checkBalance(args) { | ||
return sendQuery('org.hyperledger.chaincode.example02/fcn/3', | ||
new app.Entity(args)) | ||
.then(function(results) { | ||
return app.BalanceResult.decode64(results[0].toString('utf-8')); | ||
}); | ||
} | ||
|
||
program | ||
.version('0.0.1'); | ||
|
||
program | ||
.command('deploy') | ||
.description('deploy description') | ||
.option("-p, --path <path>", "Path to chaincode.car") | ||
.action(function(options){ | ||
return connect() | ||
.then(function() { | ||
return deploy({ | ||
'partyA': {'entity':'A', 'value':100}, | ||
'partyB': {'entity':'B', 'value':200}}, | ||
options.path); | ||
}) | ||
.catch(function(err) { | ||
console.log("error:" + err); | ||
}); | ||
}); | ||
|
||
program | ||
.command('makepayment <partySrc> <partyDst> <amount>') | ||
.description('makepayment description') | ||
.action(function(partySrc, partyDst, amount){ | ||
return connect() | ||
.then(function() { | ||
return makePayment({ | ||
'partySrc': partySrc, | ||
'partyDst': partyDst, | ||
'amount': parseInt(amount)}); | ||
}) | ||
.catch(function(err) { | ||
console.log("error:" + err); | ||
}); | ||
}); | ||
|
||
program | ||
.command('checkbalance <id>') | ||
.description('checkbalance description') | ||
.action(function(id){ | ||
return connect() | ||
.then(function() { | ||
return checkBalance({'id':id}); | ||
}) | ||
.then(function(result) { | ||
console.log("balance:" + result.balance); | ||
}) | ||
.catch(function(err) { | ||
console.log("error:" + err); | ||
}); | ||
}); | ||
|
||
|
||
program.parse(process.argv); |
Oops, something went wrong.