Skip to content

Commit

Permalink
Short branch (hyperledger-archives#1277)
Browse files Browse the repository at this point in the history
* Updates for work

* Adding Installing Index to ToC

* Removing Fabric Composer name

* Removing Fabric composer name

* Moving images for REST API doc

* Fabric Composer Name removal

* Fabric Composer name removal

* Other name changes (Stack Overflow, GitHub, Rocket.Chat, JavaScript)

* wording updates and bug splats

* ToC Updates

* HLv1 docs updates, couple more bug splats.

* Last edit for HLv1

* Whoops, bug splat

* Another bug splat...

* Quick fixes prereqs navbar

* intro diagram fix and bug fixes

* Fixes and updates

* Rollback optional script for v1.0

* QoL changes and rollback changes - Quickstart

* Link fixes

* Atom links fix, formatting fix

* Odd formatting fix.

* Name change and codeblock fix

* More odd formatting fixes

* Ubuntu root user doc fix + draft of bnd doc changes

* update for CLI define + deploy BNA

* last bnd update

* Events and bug fixes

* Last event thing

* Updates for #803 and hyperledger-archives#822

* removing unnecessary stuff

* Undeploy support #673

* Clarifications on undeploy

* Commit?

* Revert "Commit?"

This reverts commit 9094568.

* Quick Fixes

* Quick fix for connection profile keyvalstore

* Updates to show events docs in ToC

* Quick fixes

* Last minute docs updates.

* changes from issue #912

Signed-off-by: Edward Prosser <[email protected]>

* Version 1 auto-generating landing pages

* Docs Updates week 2

* 1 more set of updates

* last changes

* HLFV1 Beta and Query (hyperledger-archives#1247) (hyperledger-archives#1255)

System and unit tests
Rich query support for fabric V1 alpha
Alpha 2 Support

* Move HLF v0.6 to use Duktape instead of Otto (hyperledger-archives#1257)

* Connection profile, identity import, logic.js

* Query v0.1

* Connection profile, Query, Security, Dev Guide

* Security updates for local playground

* Last minute updates
  • Loading branch information
EdProsser authored Jun 15, 2017
1 parent 6decf2f commit c1ccdb4
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@ Once the BNA file has been created it can be deployed to a runtime using the `co

For example:

composer network deploy -p connectionProfileName -a <BusinessNetworkDefinition>.bna
composer network deploy -p connectionProfileName -a <BusinessNetworkDefinition>.bna
-i <Your EnrollmentID> -s <Your EnrollmentSecret>

To update the definition of an already deployed business network use the `composer network update` CLI command.

## Deploying business networks to {{site.data.conrefs.hlf_full}} Beta

In {{site.data.conrefs.hlf_full}} Beta peers now enforce the concepts of admins and members. Admin user's identities and crypto material must be available to the peer at deployment. To make that identity and its crypto material available, your must import it to your local `keyValStore` directory before deploying the business network. To import the identity, use the [`composer identity import` command](../reference/composer.identity.import.html). When importing an identity, you do not assign it a secret, however the `composer network deploy` command requires a secret. If you are using an imported identity, you can enter any value for the secret.

When connecting to the peer you must specify an identity where the userID contains the text `admin`, for example, `PeerAdmin`, `myadmin`, or `AdminPeer` are all valid userID's. Peers in different organizations may have different admin users. Only an admin user of peer's organization will be able to deploy a business network to their peers.

These security changes mean that {{site.data.conrefs.composer_full}} cannot support older versions of {{site.data.conrefs.hlf_full}} v1.0 (e.g. alpha 1).

### Deploying business networks using Playground locally

When deploying a business network to {{site.data.conrefs.hlf_full}} Beta using the Playground locally, you must follow the process above to connect using the peer admin identity. However, in order to create identities and interact with your business network in the Playground, you must use the certificate authority admin identity.

## References

* [**Composer CLI commands**](../reference/commands.html)
70 changes: 70 additions & 0 deletions packages/composer-website/jekylldocs/business-network/query.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
layout: default
title: Querying Business Network Data
category: tasks
section: business-network
sidebar: sidebars/businessnetworks.md
excerpt: Using {{site.data.conrefs.hlf_full}} and CouchDB, you can query assets in the stored world-state and return listed assets by using a transaction processor function.
---

# Querying business network data

>Warning
The status of this feature is experimental. You **must** use Hyperledger Composer v0.8+ with the the HLFv1 runtime to use queries. We welcome feedback and comments while we continue to iterate upon query functionality. The API may change based on the feedback received. In future releases we plan to extend this feature with a Composer specific query language, and data-binding to assets, participants and transactions.

{{site.data.conrefs.hlf_full}} v1.0 can be configured to store the world-state in a CouchDB database. CouchDB is a JSON document store, so all data in the world-state is persisted as JSON documents, including Composer assets, participants and transactions.

When {{site.data.conrefs.hlf_full}} is used in CouchDB mode chaincode can execute complex (content-based) queries against the world-state data. The queries are written in the Mango query language, the native CouchDB query language.

An example Mango _selector_ query:
var q = {
selector: {
size: 'SMALL'
}
};

This query will select all JSON documents in the document store that contain the property `size` that has the value `SMALL`. Please refer to the CouchDB documentation for the [query syntax for Mango queries](http://docs.couchdb.org/en/2.0.0/api/database/find.html). Note that CouchDB ships with a powerful web interface called [Fauxton](http://couchdb.apache.org/fauxton-visual-guide/). You can use Fauxton to inspect the documents in the document store, run queries, view results etc.

### Running Native CouchDB Mango Queries from Transaction Processor Functions

The Composer runtime API includes the `queryNative(queryString)` method, allowing transaction processor functions to submit native Mango queries to CouchDB. Composer will execute the query against CouchDB, returning a promise to a JS Object that captures the results of running the query.

The JS Object returned is composed of an array of objects, each with a `Key` and `Record` property. `Key` is a string that represents the key of the document in the document store. `Record` is a JS Object that captures the data for the document itself.

### Example

The example below runs a content-based query to select all `SMALL` marbles, verifies the number of marbles returned, and that they are indeed all `SMALL`.
```
/**
* Executes a CouchDB query and checks the results.
* @param {org.fabric_composer.marbles.QueryMarbleByOwner} transaction
* @transaction
* @return {Promise} a promise to the results of transaction processing
*/
function onQueryMarbleByOwner(transaction) {
var factory = getFactory();
// create the query
var q = {
selector: {
size: 'SMALL'
}
};
return queryNative(JSON.stringify(q))
.then(function (resultArray) {
print('TP function received query result: ', JSON.stringify(resultArray));
if (resultArray.length !== 5) {
throw new Error('The incorrect number of marbles found: ', resultArray.length);
}
for (var x = 0; x < resultArray.length; x++) {
var currentResult = resultArray[x];
if (currentResult.Record.size !== 'SMALL') {
throw new Error('Query returned a marble that is not SMALL!', currentResult.Record);
}
}
});
}
```

Using a selector it is possible to query all assets of a given type, with a given set of properties, and then to convert them back into Composer resources using `getSerializer().fromJSON(jsObject)`. Once the JS object returned by a query have been converted back into a Composer object it can be updated and persisted back into an asset registry.

>Note that in the future Composer will define a query language expressed in terms of assets, participants and transactions and automatically marshall the JS objects returned by CouchDB to the corresponding Composer modelled types.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ docker images -aq | xargs docker rmi -f

By default, the Web Browser connection profile is in use (for developing and testing in browser memory). To connect instead to the {{site.data.conrefs.hlf_full}} instance created in the previous step, click the globe icon in the top right of the UI to visit the Connection Profiles panel and change your active profile to 'hlfabric'.

## Deploying business networks to {{site.data.conrefs.hlf_full}} Beta

In {{site.data.conrefs.hlf_full}} Beta peers now enforce the concepts of admins and members. Admin user's identities and crypto material must be available to the peer at deployment. To make that identity and its crypto material available, your must import it to your local `keyValStore` directory before deploying the business network. To import the identity, use the [`composer identity import` command](../reference/composer.identity.import.html). When importing an identity, you do not assign it a secret, however the `composer network deploy` command requires a secret. If you are using an imported identity, you can enter any value for the secret.

When connecting to the peer you must specify an identity where the userID contains the text `admin`, for example, `PeerAdmin`, `myadmin`, or `AdminPeer` are all valid userID's. Peers in different organizations may have different admin users. Only an admin user of peer's organization will be able to deploy a business network to their peers.

These security changes mean that {{site.data.conrefs.composer_full}} cannot support older versions of {{site.data.conrefs.hlf_full}} v1.0 (e.g. alpha 1).

### Deploying business networks using Playground locally

When deploying a business network to {{site.data.conrefs.hlf_full}} Beta using the Playground locally, you must follow the process above to connect using the peer admin identity. However, in order to create identities and interact with your business network in the Playground, you must use the certificate authority admin identity.


---
<!--
<a name="installationoptions"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ All the options are required. The `userId` doesn't have to match any information
## Syntax example

```
composer identity import -p hlfv1 -u Org1PeerAdmin -c admin.pem -k 9022d671ceedbb24af3ea69b5a8136cc64203df6b9920e26f48123fcfcb1d2e9_sk
node cli.js identity import -p hlfv1 -u PeerAdmin -c ./peerOrganizations/org1.example.com/users/[email protected]/signcerts/[email protected].pem -k ./peerOrganizations/org1.example.com/users/[email protected]/keystore/9022d671ceedbb24af3ea69b5a8136cc64203df6b9920e26f48123fcfcb1d2e9_sk
```

## Options
Expand All @@ -32,8 +32,8 @@ Options:
-v, --version Show version number [boolean]
--connectionProfileName, -p The connection profile name [string] [required]
--userId, -u The user ID for the new identity [string] [required]
--signerCertFile, -c signerCert path [string] [required]
--keyFile, -k key file [string] [required]
--publicKeyFile, -c File containing the public key [string] [required]
--privateKeyFile, -k File containing the private key [string] [required]
```

#### Define connection profile name
Expand All @@ -54,15 +54,15 @@ Example: `-u Org1PeerAdmin`

#### Define signers public certificate

`-c` or `--signerCertFile`
`-c` or `--publicKeyFile`

Example: `-c admin.pem`

---

#### Define signers private key file

`-k` or `--keyFile`
`-k` or `--privateKeyFile`

Example: `-k 9022d671ceedbb24af3ea69b5a8136cc64203df6b9920e26f48123fcfcb1d2e9_sk`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ A Connection Profile is used by {{site.data.conrefs.composer_full}} to connect t
],
"ca": {
"url:" "https://",
"name": "",
"trustedRoots": "",
"verify": true
},
Expand All @@ -69,12 +70,16 @@ A Connection Profile is used by {{site.data.conrefs.composer_full}} to connect t
"keyValStore": "/YOUR_HOME_DIR/.hfc-key-store",
"channel": "mychannel",
"mspID": "Org1MSP",
"deployWaitTime": "300",
"invokeWaitTime": "100"
"timeout": 300,
"globalcert": "",
"maxSendSize": 10,
"maxRecvSize": 15
}

If you are connecting to {{site.data.conrefs.hlf_full}} v1.0 and are not using TLS or if you don't need the trustedRoots and verify options of the Certificate Authority definition you can use the following simplified connection profile:

_Please note: The simplified version of the connection profile will only work if the relevant certificate authority has no name defined. If the certificate authority has a defined name, it must be specified._

{
"type": "hlfv1",
"orderers": [
Expand All @@ -94,8 +99,10 @@ A Connection Profile is used by {{site.data.conrefs.composer_full}} to connect t
"keyValStore": "/home/.hfc-key-store",
"channel": "mychannel",
"mspID": "Org1MSP",
"deployWaitTime": "300",
"invokeWaitTime": "100"
"timeout": 300,
"globalcert": "",
"maxSendSize": 10,
"maxRecvSize": 15
}

- `type` defines the version of {{site.data.conrefs.hlf_full}} that you will connect to. To connect to {{site.data.conrefs.hlf_full}} v1.0-alpha is must be `hlfv1`.
Expand All @@ -108,7 +115,6 @@ A Connection Profile is used by {{site.data.conrefs.composer_full}} to connect t


- `mspid` is the Membership Service Provider ID of your organization. It is associated with the enrollment id that you will use to interact with the business network.
- `deployWaitTime` is an optional property which sets a wait time for a response before timing out when attempting to deploy your business network.
- `invokeWaitTime` is an optional property which sets a wait time for a response before timing out when invoking a transaction or making a query request.

*Please note: If you are connecting to an instance of {{site.data.conrefs.hlf_full}} v1.0 the `keyValStore` property must be `home/.hfc-key-store`*
- `timeout` is an optional property which controls the timeout for each request made to peers and orderers. Please note, some commands may make several sequential requests and the timeout will be applied individually to each request.
- `maxSendSize` is an optional property which defines the size limit of outbound grpc messages being send to orderers and peers. The value is defined in megabytes. If this is not set, grpc sets a default. Setting this property to `-1` results in no size restriction.
- `maxRecvSize` is an optional property which defines the size limit of inbound grpc messages being received from orderers and peers. The value is defined in megabytes. If this is not set, grpc sets a default. Setting this property to `-1` results in no size restriction.
38 changes: 17 additions & 21 deletions packages/composer-website/jekylldocs/tutorials/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ sidebar: sidebars/tutorials.md
excerpt: Developer Guide
---

# Create an end-to-end {{site.data.conrefs.composer_full}} solution from scratch
# Developer Tutorial for creating a {{site.data.conrefs.composer_full}} solution

---

*Note:* this tutorial was written against {{site.data.conrefs.composer_full}} v0.7.2 on Ubuntu Linux running with {{site.data.conrefs.hlf_full}} v1.0 where referenced below and also tested for a Mac environment. (The relevant steps for a {{site.data.conrefs.hlf_full}} v0.6 setup are shown in *italics*).
*Note:* this tutorial was written against {{site.data.conrefs.composer_full}} v0.8 on Ubuntu Linux running with {{site.data.conrefs.hlf_full}} v1.0 where referenced below and also tested for a Mac environment. (The relevant steps for a {{site.data.conrefs.hlf_full}} v0.6 setup are shown in *italics*).

This tutorial will walk you through the steps required to build a {{site.data.conrefs.composer_full}} blockchain solution from scratch. In the space of a day or probably less, you will be able to go from an idea for a disruptive blockchain innovation, to executing transactions against a real {{site.data.conrefs.hlf_full}} blockchain network, and generating/running a sample Angular 2 based application for Commodity Trading that interacts with a blockchain network.

Expand Down Expand Up @@ -81,6 +81,16 @@ The start of the `package.json` file should now look like this:

Save your changes to `package.json`

### Update your README.md file

Open the `README.md` file and update the markdown with a short decription of the business network.

```
# My very first Hyperledger Composer Network
```

Save your changes to `README.md`

## Define your Domain Model

Open the file `models/sample.cto` and inspect the contents. This is the domain model for the business network definition. It defines the structure (schema) for the assets, transaction and participants in the business network. You can add as many model files as convenient under the `models` folder, however each model file must have a unique namespace; do note that you can import types from one namespace into other namespaces.
Expand Down Expand Up @@ -159,7 +169,7 @@ Save your changes to `lib/sample.js`

## Update your Access Control Rules

The file `permissions.acl` defines the access control rules for the business network definition. Update the 'Default' rule to use the new namespace for the network (just cut and paste the entire contents from below if you prefer):
The file `permissions.acl` defines the access control rules for the business network definition. Replace the entire contents of `permissions.acl` with the rule below.

```
/**
Expand Down Expand Up @@ -390,19 +400,13 @@ Commodity Trading

## Import into Playground and Test

Change directory to your toplevel project folder (my-network) for example:

```
cd my-network
```

Re-generate the BNA file (overwriting the existing dist/my-network.bna file created earlier) using the following command (including the trailing '.' please note):
Change directory to your toplevel project folder (my-network). Re-generate the BNA file (overwriting the existing dist/my-network.bna file created earlier) using the following command (including the trailing '.' please note):

```
composer archive create -a dist/my-network.bna --sourceType dir --sourceName .
```

Next, in a browser, navigate to the online Bluemix Composer Playground [https://composer-playground.mybluemix.net](https://composer-playground.mybluemix.net) and import the newly-generated BNA file into the Playground using the "Import/Replace" button at the bottom left of the screen. Locate the `dist/my-network.bna` file under your 'my-network' folder and upload it, then press the "Deploy" button. Confirm to replace the current sample definition in Playground.
Next, in a browser, navigate to the online Bluemix Composer Playground <a href="https://composer-playground.mybluemix.net" target="blank">http://<span></span>composer-playground.mybluemix.net</a> and import the newly-generated BNA file into the Playground using the "Import/Replace" button at the bottom left of the screen. Locate the `dist/my-network.bna` file under your 'my-network' folder and upload it, then press the "Deploy" button. Confirm to replace the current sample definition in Playground.

<video autoplay "autoplay=autoplay" style="display:block; width:100%; height:auto;" loop="loop">
<source src="{{ site.baseurl }}/assets/img/tutorials/developer/import_replace.mp4" type="video/mp4" />
Expand Down Expand Up @@ -451,7 +455,7 @@ The Asset registry should look like this:

![Commodity Registry](../assets/img/tutorials/developer/commodity_registry.png)

Next, submit a `Trade` transaction (click the button, below left) to move the commodity from TRADER1 to TRADER2.
Next, submit a `Trade` transaction by clicking the "Submit Transaction" button, bottom left, to move the commodity from TRADER1 to TRADER2.

```
{
Expand All @@ -461,8 +465,6 @@ Next, submit a `Trade` transaction (click the button, below left) to move the co
}
```

<!-- ![Submit transaction](../assets/img/tutorials/developer/submit_tx.png) -->

After processing, you should now see the transaction in the transaction registry.

![Transaction registry](../assets/img/tutorials/developer/tx_registry.png)
Expand Down Expand Up @@ -624,14 +626,8 @@ If you navigate to this URL and press the "Assets" drop down (at the top-right o
Well done, you've now completed this tutorial and we hope you now have a much better idea how the capabilities fit together. You can start hacking on the skeleton Angular application to create the next industry defining blockchain-based application!


## Related Concepts
## Related Links

[Business Network Definition](../business-network/businessnetworkdefinition.html)

## Related Tasks

[Deploying a business network](../business-network/bnd-deploy.html)

## Related Reference

[Network deploy command](../reference/composer.network.deploy.html)
Loading

0 comments on commit c1ccdb4

Please sign in to comment.