Start up Fabric Composer REST API server - hyperledger

I am trying to use the composer-rest-server package after completing the Fabric Composer quick start, but I failed.
Please give me a hint.
The composer-rest-server package was successfully installed.
npm install -g composer-rest-server
Composer-rest-server started.
composer-rest-server
I was asked to enter simple information about the business network.
After that, I failed to load the connector module 'composer-connector-hlf'.
? Enter your Fabric Connection Profile Name: defaultProfile 
? Enter your Business Network Identifier : digitalproperty-network
? Enter your Fabric username : WebAppAdmin
? Enter your secret: DJY27pEnl16d
? Specify if you want namespaces in the generated REST API: always use namespace
s
? Specify if you want the generated REST API to be secured: Yes
To restart the REST server using the same options, issue the following command:
composer-rest-server -p defaultProfile -n digitalproperty-network -i WebAppAdmin -s DJY27pEnl16d -N always -S true
Discovering types from business network definition ...
Connection fails: Error: Failed to load connector module "composer-connector-hlf" for connection profile "defaultProfile"
It will be retried for the next request.
Error: Failed to load connector module "composer-connector-hlf" for connection profile "defaultProfile"
at connectionProfileStore.load.then.e (/home/user1/.nvm/versions/node/v6.9.5/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/connectionprofilemanager.js:148:27)
How can I solve the problem?

Your .composer-connection-profiles is not set to defaultprofile.
Check your root folder and there .composer-connection-profiles folder must be present.
Inside that folder the composer profiles will be there (if your defaultprofile is made, then there will be a folder named defaultprofile), check the connection.json inside the defaultprofile folder.
If there is any other folder with different name, use that as your profile. Or you can specifically define the folder defaultprofile and write connection.json with connection details.

Which version of npm are you using? I faced similar issue on ubuntu 16.4. When I retinstall evberything with lower version of npm it worked perfectly.
npm version when things worked:
npm --version
3.10.10
when I was getting problem as you have mentioned it was 5.x

Does your grpc module has grpc_node.node files?
It's in the composer-cli module.
In my environment
/usr/local/lib/node_modules/composer-cli/node_modules/grpc/src/node/extension_binary/grpc_node.node
if you use sudo, you may need to add --unsafe-perm option.
Like: sudo npm install -g --unsafe-perm composer-cli

Related

Lumber: Command 'lumber' not found

I just setup a Rails Application in my Ubuntu 18 machine, and I want to connect it to Forest Admin. However, Forest Admin requires that I set up a Node Application using npm first. The node application requires the installation of Lumber CLI tool in order to install Forest Admin.
I have however installed Lumber CLI tool by running the command below:
npm install -g lumber-cli#latest -s
When I run the command below npm lumber -version in my command line terminal, I get the response:
6.13.4
But when I try to generate the Forest Admin using the command below:
lumber generate "my_project"...
I get the following error:
Command 'lumber' not found
I need some help. Thank you.
Here's how I solved it:
The issue is because NPM does not have the write access to the directory that will contain the package you want to install (here lumber-cli).
To solve this issue, override the default directory where your global NPM packages will be stored:
mkdir ~/.npm-global
Then, configure NPM to use this directory instead of the default one:
npm config set prefix '~/.npm-global'
Then, make the node executables accessible from your PATH. To do so, export the environment variable PATH by opening or creating the file ~/.profile and add this line at the end:
export PATH=~/.npm-global/bin:$PATH
Finally, reload the ~/.profile file:
source ~/.profile
Try installing lumber cli again using the command below:
npm install -g lumber-cli#latest -s
It should be able to install lumber without any error, and also display the directory where lumber-cli is installed.
Reference: Prevent permission errors at installation
That's all
I hope this helps

Ubuntu, shopsys install via composer, docker, still crashing

I wanna install shopsys via composer and docker, as is recommended.
https://github.com/shopsys/shopsys/blob/master/docs/installation/installation-using-docker-linux.md
I installed git, php-fpm (configured), postgres (configured), composer, docker, docker-compose.
sudo apt install git
sudo apt install php7.2-fpm
sudo apt install postgresql
sudo apt install composer
sudo apt install docker-ce
sudo apt install docker-compose
Everything ok.
I added my user to docker group.
sudo usermod -a -G docker $(whoami)
Ok.
Next I made folder /var/www/html/shopsys, created project shopsys via composer.
composer create-project shopsys/project-base --no-install --keep-vcs
cd project-base/
Then I run this in /var/www/html/shopsys/project-base.
./scripts/install.sh
Everything seems to be ok, until this.
[RuntimeException]
/var/www/html/vendor does not exist and could not be created.
I set rights to 777 for folder /var/www/html, and run it again, but same problem.
The I run this.
sudo composer install
It shows me this error.
....Exception\InvalidConfigurationException]
Invalid configuration for path "monolog.handlers.main": You can only use ex
cluded_http_codes/excluded_404s with a FingersCrossedHandler definition
In ScriptHandler.php line 294:
An error occurred when executing the "'shopsys:domains-urls:configure'" command:
In BaseNode.php line 319:
...\Exception\InvalidConfigurationException]
Invalid configuration for path "monolog.handlers.main": You can only use ex
cluded_http_codes/excluded_404s with a FingersCrossedHandler definition
...
etc., error is quite ugly.
Last error when i run script install.sh.
file_put_contents(/var/www/html/vendor/composer/installed.json): failed to open stream: Permission denied
But this folder does not exist.
ls: cannot access '/var/www/html/vendor/': No such file or directory
Just question, where could be the problem?
Is possible to download sources from some link, extract it, configure and display in web browser with easy way, for example as wordpress?
Thanks.
To solve problem with vendor:
It seems that your UID and GID is different than default 1000, that is set in docker-compose.yml for Linux by default.
To solve your issue you can continue by step 3 in https://github.com/shopsys/shopsys/blob/master/docs/installation/installation-using-docker-linux.md#3-set-the-uid-and-gid-to-allow-file-access-in-mounted-volumes
You found issue with installation script, I have created issue on GitHub.
To solve problem with Invalid configuration for path "monolog.handlers.main":
Currently there is problem with new minor version (3.4.0) of symfony/monolog-bundle that created BC break. There is already created issue about this problem and there is already merged fix in Shopsys master.
To solve problem in your project you have to add
"symfony/monolog-bundle": ">=3.4.0", in conflict section in your composer.json file and then run composer install again.
We are trying to answer questions on stackoverflow as soon as possible, but we also have Slack where is many users and you might get your question answered much faster.

IBM Blockchain - Simple Application

Alright, I need to develop a simple application in an IBM Blockchain(starter plan). But I can't get it done, after almost 1 month of trial and error and thousands of tutorials.
So, my case is really simple(I guess):
I have a models.cto file:
namespace com.test.models
/**
* A company asset.
*/
asset Company identified by company_id {
o String company_id
o String document_key
o String document_value
o String name
o String telephone
o String email
}
/**
* A person_in_charge asset.
*/
asset PersonInCharge identified by person_in_charge_id {
o String person_in_charge_id
o String company_id
o String name
o String document_key
o String document_value
o String email
o String language
o String created_date_time
}
I tried to make it as participant instead. I tried to make transaction and then do something with .js file but there are only use cases and tutorials about complex examples using assets, participants, etc. I just want to insert "PersonInCharge" and "Company" separately and query (each Company or by id whatever) also separately.
I was able to made a example using Swagger api generator, but it didn't worked as expected, even thought it created all the methods I wanted, like this:
For summarize, I wanted to deploy my chaincode in a peer, inside of a channel at IBM Blockchain. I did deployed a marble example and it did worked perfectly.
Really self describing error, not with a general message:
I am following a "how to" guide for develop locally and deploy to IBM. Therefore, I am creating a bna file composer archive create -t dir -n . and then creating a card with the downloaded connection settings(from IBM) and else using this tutorial Deploying a business network on Starter Plan
and I am failing at this step: composer network start -c adminCard -n bna-blockchain -V 0.0.1 -A admin -C ./credentials/admin-pub.pem -f delete_me.card. perhaps beucause I'm not being able to instantiate my chaincode on IBM Blockchain.
Sorry if it looks confunsing, just ask me if you have any questions about my issue.
Thanks in advance and any help would be awesome!
Before starting the network, you need to install it:
composer network install -c adminCard -a vehicle-manufacture-network.bna
I took a break in the development and came back after a month. In that time, I had help of a person inside IBM who could help me to get it done.
And I'm here so point out, some failures too.
The IBM guy(I won't say his name, of course) itself said that the service to upload a chaincode(channels/chaincode/Install chaincode) is broken and does not work well.
Also, I asked an easy to answer question in the IBM Blockchain paid forum but had no help at all(they did not even answer the question), even after almost 3 months. And you can't find a tutorial(besides marbles samples) that works from start to end.
Sorry if it looks like I'm raging for nothing in here, but I had a really hard time to put it all together to work 100%.
I will not show how to create a model file or transactional scripts(because there are a plenty of it on examples) but the commands you need to execute in order to run the chaincode on IBM and generate a loopback API. With that said...
Let's go to what's important: the code
First things first, Environment settings:
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
Release: 16.04
Codename: xenial
IMPORTANT: IBM Blockchain(until now 2019-03-23) won't run under virtualized machines like virtual box or hyperv because of a couple npm dependencies. But a hardware virtual machine(HVM) like amazon ones will do just fine.
STEPS
Install node and npm(follow the versions strictly as listed)
node -v
v8.15.1
npm -v
6.4.1
curl -O https://hyperledger.github.io/composer/unstable/prereqs-ubuntu.sh
chmod u+x prereqs-ubuntu.sh
./prereqs-ubuntu.sh
npm install -g --unsafe-perm composer-cli#0.20.5
npm install -g --unsafe-perm composer-rest-server#0.20.5
composer-rest-server -v
v0.20.5
composer -v
v0.20.5
Create a project using hyperledger composer-playground. Export it and navigate through the root directory of the project you just downloaded(the project can be developed locally too).
Download the connection settings file at IBM Blockchain(Overview/Connection Profile/Download) and name it as connection-profile.json. Find the node registrar, you'll use it to create the cards.
Run npm install. If anything goes wrong while installing the dependencies, check if you're using exactly the same versions that I am using. If you're not, uninstall it all and start again from the beginning.
tricky zone
composer card create -f ca.card -p connection-profile.json -u admin -s *your-password*
composer card import -f ca.card -c ca
composer identity request --card ca --path ./credentials -u admin -s *your-password*
You'll see that the credentials folder were generated. Inside this folder, find
the file admin-pub.pem (credentials/admin-pub.pem) copy the whole content of it, and then upload it to IBM Blockchain(Members/Certificates/Add Certificate). You'll be prompted to restart peers, click "yes"
After the peers come back online, in the same Certificates tab, find the certificate you just add, in the ACTION column click at the menu, and then choose the option "Sync Certificate".
composer archive create -t dir -n .
composer card create -f adminCard.card -p connection-profile.json -u admin -c ./credentials/admin-pub.pem -k ./credentials/admin-priv.pem --role PeerAdmin --role ChannelAdmin
composer card import -f ./adminCard.card -c adminCard
composer network install -c adminCard -a bna-name#version.bna
composer network start -c adminCard -n *bna-name* -V *bna-version* -A admin -C ./credentials/admin-pub.pem -f delete_me.card (Output: Successfully created business network card: Filename: delete_me.card)
composer card create -n *bna-name* -p connection-profile.json -u admin -c ./credentials/admin-pub.pem -k ./credentials/admin-priv.pem (Output file: admin#*bna-name*.card)
composer card import -f ./admin#*bna-name*.card (Card file: ./admin#*bna-name*.card Card name: admin#*bna-name*)
Now you'll generate the rest api using (automatically generated using swagger)
composer-rest-server -c admin#*bna-name* -n never -w true -p 8080
Enjoy!

Error: failed to request identity. Error trying to enroll user and return certificates

I am biginner in block chain development. I succesfully run ./startFabric.sh and ./createPeerAdminCard.sh .Then i succesfully run two command as follow below.
composer runtime install -c PeerAdmin#byfn-network-org1-only -n trade-network
composer runtime install -c PeerAdmin#byfn-network-org2-only -n trade-network
Then i tried to run
composer identity request -c PeerAdmin#byfn-network-org1-only -u admin -s adminpw -d alice
But i got error like the following
Error: failed to request identity. Error trying to enroll user and return certificates. Error: Calling enrollment endpoint failed with error [Error: connect ECONNREFUSED 127.0.0.1:7054]
I tried many time to kill all process in docker and remove .composer file from home directory. But always showing the same error message.
Please help me as possible
Os: Ubuntu 16.04
Fabric vertion:1.0.4
Composer vertion:0.16.6
Thanks..
This error "Failed to import the business network card Connection profile has no x-type property defined." means that a v0.20 client can't/won't import a card from an earlier version (probably v0.16).
I think maybe you are running the wrong version of createPeerAdminCard.sh script and it is trying to create and import an 'old' card.
With Composer v0.20 you need to get 'new' copies of the fabric-development-servers scripts which work with Fabric 1.2.
So I would suggest running the following:
run teardownAllDocker.sh script
remove the fabric-dev-server folder (might be fabric-tools if old)
remove the ~/.composer folder
follow the install doc from Step 4 . - make sure to export FABRIC_VERSION=hlfv12 - this is what makes sure you get Fabric 1.2.
This is difficult to help ...
The first 2 scripts you have run (./startFabric.sh and ./createPeerAdminCard.sh) are for a basic development Fabric.
The next 2 commands look like they are from the Multi-Org tutorial which uses a different Fabric and has different cards and crypto material.
Unless there is a particular reason for using an old version of Composer, I would suggest using Composer v0.20, which requires Fabric 1.2.
If you are a beginner I would suggest working with the Developer Tutorial to start with.
if you are using a default file (e.g. connection.json, env.json, etc.) to hold your base connnection profile, simply change the "type" term in that default file to "x-type"
In converting from v0.16 to v0.20, you must first remove the v0.16 composer tools from your system, then install the v0.20 version.
To remove v0.16.6:
npm uninstall -g composer-cli
npm uninstall -g generator-hyperledger-composer
npm uninstall -g composer-rest-server
To install V0.20.2:
npm install -g --python=python2.7 composer-cli#0.20.2
npm install -g --python=python2.7 generator-hyperledger-composer#0.20.2
npm install -g --python=python2.7 composer-rest-server#0.20.2
npm install -g --python=python2.7 yo
If you're running nodejs, then you also have to update both package.json files (network/package/json as well as your {base folder}package.json) from 0.16.x to ^0.20.2
The reason for error is Missing of Certificate Authorities(CA). I Just up my CA server. Now Working perfectly.

Cannot start fabric-ca server natively

I have been following this for setting up a fabric-ca server in my network of 2 organizations, 4 peers (2 in each).
I have two questions:
In the documentation, it says that we can start server locally. When I try to do the same, I'm not able to do it and getting the following error :
fabric-ca-server: command not found . So I tried using a docker image and the server now works as a docker image.
Now when I try to run the fabric-ca-client command, it cannot find the client configuration in the fabric-ca-client home. The FABRIC_CA_HOME environment variable is set as `/etc/hyperledger/fabric-ca-server' in the container. I'm confused as to what I might be missing here.
If you followed the instructions, then the fabric-ca-server executable will be under $GOPATH/bin, you will need to add this to your PATH, via export PATH=$PATH:$GOPATH/bin. Remember to also set FABRIC_CA_HOME.
Assuming you're also using the client natively, it should also be under $GOPATH/bin. In a separate terminal, set FABRIC_CA_HOME to a different path. Then you can enroll the admin user, for example: fabric-ca-client enroll -u http://admin:password#localhost:7054.
The issue is coming because you have not set the GOPATH path.
After cloning the CA repo set the GOPATH to the given directory.
For setting up GOPATH:
(Ubuntu)
If you don’t set a GOPATH, the default will be used.
You have to add $GOPATH/bin to your PATH to execute any binary installed in $GOPATH/bin, or you need to type $GOPATH/bin/the-command.
Add this to your ~/.bash_profile
export PATH=$GOPATH/bin:$PATH
Current GOPATH command:
go env GOPATH
Changing the GOPATH command:
export GOPATH=$HOME/your-desired-path
So. change the 'your-desired-path' to your Fabric-CA repo directory.
You will be facing issue with certain versions of golang. Set the flags explicitly using CGO_LDFLAGS_ALLOW='-Wl,--no-as-needed'
Reference -
Error while running make command using Fabric 1.0.6 after all the 15 steps
https://github.com/golang/go/issues/23739
➜ fabric-ca git:(release-1.0) go get -u github.com/hyperledger/fabric-ca/cmd/...
go build github.com/hyperledger/fabric-ca/vendor/github.com/miekg/pkcs11: invalid flag in #cgo LDFLAGS: -I/usr/local/share/libtool
➜ fabric-ca git:(release-1.0) export CGO_LDFLAGS_ALLOW='-Wl,--no-as-needed'
➜ fabric-ca git:(release-1.0) make

Resources