diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..5a067f4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,24 @@ +[submodule "git/marbles"] + path = git/marbles + url = https://github.com/joequant/marbles.git +[submodule "git/chaincode-investigator"] + path = git/chaincode-investigator + url = https://github.com/joequant/chaincode-investigator.git +[submodule "git/marbles-chaincode"] + path = git/marbles-chaincode + url = https://github.com/joequant/marbles-chaincode.git +[submodule "git/cp-web"] + path = git/cp-web + url = https://github.com/joequant/cp-web.git +[submodule "git/cp-chaincode-v2"] + path = git/cp-chaincode-v2 + url = https://github.com/joequant/cp-chaincode-v2.git +[submodule "git/hyperledger-fabric-js"] + path = git/hyperledger-fabric-js + url = https://github.com/joequant/hyperledger-fabric-js.git +[submodule "git/car-lease-demo"] + path = git/car-lease-demo + url = https://github.com/joequant/car-lease-demo.git +[submodule "git/fabric"] + path = git/fabric + url = https://github.com/joequant/fabric.git diff --git a/Dockerfile b/Dockerfile index 2b343c3..ce06c75 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,39 +2,19 @@ # Data is stored under /var/hyperledger/db and /var/hyperledger/production # Under $GOPATH/bin, there are two config files: core.yaml and config.yaml. -FROM golang:1.6 -MAINTAINER Baohua Yang +FROM library/ubuntu:xenial +MAINTAINER Joseph Wang -ENV DEBIAN_FRONTEND noninteractive - -RUN apt-get update \ - && apt-get install -y libsnappy-dev zlib1g-dev libbz2-dev \ - && rm -rf /var/cache/apt - -# install rocksdb -RUN cd /tmp \ - && git clone --single-branch -b v4.1 --depth 1 https://github.com/facebook/rocksdb.git \ - && cd rocksdb \ - && PORTABLE=1 make shared_lib \ - && INSTALL_PATH=/usr/local make install-shared \ - && ldconfig \ - && cd / \ - && rm -rf /tmp/rocksdb - -RUN mkdir -p /var/hyperledger/db \ - && mkdir -p /var/hyperledger/production +# install go +ENV GOPATH /usr/lib/go-1.6 +ENV GOROOT /usr/lib/go-1.6 +ENV PATH /opt/gopath/bin:/opt/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -# install hyperledger -RUN mkdir -p $GOPATH/src/github.com/hyperledger \ - && cd $GOPATH/src/github.com/hyperledger \ - && git clone --single-branch -b master --depth 1 https://github.com/hyperledger/fabric.git \ - && cd $GOPATH/src/github.com/hyperledger/fabric \ - && CGO_CFLAGS=" " CGO_LDFLAGS="-lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy" go install \ - && go clean - - -RUN cp $GOPATH/src/github.com/hyperledger/fabric/core.yaml $GOPATH/bin \ - && cp $GOPATH/src/github.com/hyperledger/fabric/consensus/obcpbft/config.yaml $GOPATH/bin +ENV DEBIAN_FRONTEND noninteractive -# this is only a workaround for current hard-coded problem. -RUN ln -s $GOPATH /opt/gopath \ No newline at end of file +RUN rm -f /var/lib/apt/lists/*Sources* /var/lib/apt/lists/*universe* \ + && sed -i /universe/d /etc/apt/sources.list \ + && apt-get update \ + && apt-get install -y curl \ + && curl https://raw.githubusercontent.com/joequant/hyperledger/master/docker-setup.sh | bash +WORKDIR "$GOPATH/bin diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8bb49a1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) 2015, Bitquant Research Laboratories (Asia) Limited +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +1. Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index ca8f3a1..dd4122e 100644 --- a/README.md +++ b/README.md @@ -2,60 +2,43 @@ Docker-Hyperledger === Base Docker images for [Hyperledger](https://www.hyperledger.org). -# Supported tags and respective Dockerfile links +Quick Start +=== +Make sure that docker runs with options -* [`0.1, latest` (latest/Dockerfile)](https://github.com/yeasy/docker-hyperledger/blob/master/Dockerfile) -* [`dev` (dev/Dockerfile)](https://github.com/yeasy/docker-hyperledger/blob/master/dev/Dockerfile) +--api-cors-header="*" -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock + +install-docker.sh does this on Redhat/Mageia systems -For more information about this image and its history, please see the relevant manifest file in the [`yeasy/docker-hyperledger` GitHub repo](https://github.com/yeasy/docker-hyperledger). +If you want to build the image locally rather than download the +dockerhub image -# What is docker-hyperledger? -Base Docker image with hyperledger deployed. Your can see [hyperledger-peer](https://hub.docker.com/r/yeasy/hyperledger-peer/) if you want to deploy a hyperledger cluster. +./fabric-setup.sh -# How to use this image? -The docker image is auto built at [https://registry.hub.docker.com/u/yeasy/hyperledger/](https://registry.hub.docker.com/u/yeasy/hyperledger/). +Otherwise -## In Dockerfile -```sh -FROM yeasy/hyperledger:latest -``` +./startnet.sh or ./startnet-secure.sh -## Local Run -The image is only for the base environment. So please refer to [hyperledger-peer](https://hub.docker.com/r/yeasy/hyperledger-peer/) if you want a local run. +Run test items -# Which image is based on? -The image is built based on [golang:1.6](https://hub.docker.com/_/golang) image. +./fabric-run.sh scripts/deploy.sh +./fabric-run.sh scripts/run-test.sh +./fabric-rest.js json/method.chaincode.json json/example02-deploy.json +./fabric-rest.js json/method.chaincode.json json/example02-invoke.json +./fabric-rest.js json/method.chaincode.json json/example02-query.json -# What has been changed? -## install dependencies -Install required libsnappy-dev, zlib1g-dev, libbz2-dev. +# Supported tags and respective Dockerfile links + +For more information about this image and its history, please see the relevant manifest file in the [`joequant/hyperledger` GitHub repo](https://github.com/joequant/hyperledger). -## install rocksdb -Install required rocksdb 4.1. +# How to use this image? +The docker image is auto built at [https://registry.hub.docker.com/u/yeasy/hyperledger/](https://registry.hub.docker.com/u/yeasy/hyperledger/). ## install hyperledger Install hyperledger and build the fabric as peer -# Supported Docker versions - -This image is officially supported on Docker version 1.7.0. - -Support for older versions (down to 1.0) is provided on a best-effort basis. - -# Known Issues -* N/A. - -# User Feedback -## Documentation -Be sure to familiarize yourself with the [repository's `README.md`](https://github.com/yeasy/docker-hyperledger/blob/master/README.md) file before attempting a pull request. - -## Issues -If you have any problems with or questions about this image, please contact us through a [GitHub issue](https://github.com/yeasy/docker-hyperledger/issues). - -You can also reach many of the official image maintainers via the email. - -## Contributing +Notes +===== -You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can. +fabric-rest.js json/chain.method -Before you start to code, we recommend discussing your plans through a [GitHub issue](https://github.com/yeasy/docker-hyperledger/issues), especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give you feedback on your design, and help you find out if someone else is working on the same thing. diff --git a/config/core.yaml b/config/core.yaml new file mode 100644 index 0000000..2b5e160 --- /dev/null +++ b/config/core.yaml @@ -0,0 +1,467 @@ +############################################################################### +# +# CLI section +# +############################################################################### +cli: + + # The address that the cli process will use for callbacks from chaincodes + address: 0.0.0.0:30304 + + + +############################################################################### +# +# REST section +# +############################################################################### +rest: + + # Enable/disable setting for the REST service. It is recommended to disable + # REST service on validators in production deployment and use non-validating + # nodes to host REST service + enabled: true + + # The address that the REST service will listen on for incoming requests. + address: 0.0.0.0:5000 + + +############################################################################### +# +# LOGGING section +# +############################################################################### +logging: + + # Valid logging levels are case-insensitive strings chosen from + + # CRITICAL | ERROR | WARNING | NOTICE | INFO | DEBUG + + # Logging 'module' names are also strings, however valid module names are + # defined at runtime and are not checked for validity during option + # processing. + + # Default logging levels are specified here for each of the peer + # commands. For commands that have subcommands, the defaults also apply to + # all subcommands of the command. These logging levels can be overridden + # on the command line using the --logging-level command-line option, or by + # setting the CORE_LOGGING_LEVEL environment variable. + + # The logging level specification is of the form + + # [[,...]=][:[[,...]=]...] + + # A logging level by itself is taken as the overall default. Otherwise, + # overrides for individual or groups of modules can be specified using the + # [,...]= syntax. + + # Examples: + # info - Set default to INFO + # warning:main,db=debug:chaincode=info - Override default WARNING in main,db,chaincode + # chaincode=info:main=debug:db=debug:warning - Same as above + peer: debug + crypto: info + status: warning + stop: warning + login: warning + vm: warning + chaincode: warning + + +############################################################################### +# +# Peer section +# +############################################################################### +peer: + + # Peer Version following version semantics as described here http://semver.org/ + # The Peer supplies this version in communications with other Peers + version: 0.1.0 + + # The Peer id is used for identifying this Peer instance. + id: jdoe + + # The privateKey to be used by this peer + # privateKey: 794ef087680e2494fa4918fd8fb80fb284b50b57d321a31423fe42b9ccf6216047cea0b66fe8365a8e3f2a8140c6866cc45852e63124668bee1daa9c97da0c2a + + # The networkId allows for logical seperation of networks + # networkId: dev + # networkId: test + networkId: dev + + # The Address this Peer will listen on + listenAddress: 0.0.0.0:30303 + # The Address this Peer will bind to for providing services + address: 0.0.0.0:30303 + # Whether the Peer should programmatically determine the address to bind to. + # This case is useful for docker containers. + addressAutoDetect: false + + # Setting for runtime.GOMAXPROCS(n). If n < 1, it does not change the current setting + gomaxprocs: -1 + workers: 2 + + # Sync related configuration + sync: + blocks: + # Channel size for readonly SyncBlocks messages channel for receiving + # blocks from oppositie Peer Endpoints. + # NOTE: currently messages are not stored and forwarded, but rather + # lost if the channel write blocks. + channelSize: 10 + state: + snapshot: + # Channel size for readonly syncStateSnapshot messages channel + # for receiving state deltas for snapshot from oppositie Peer Endpoints. + # NOTE: currently messages are not stored and forwarded, but + # rather lost if the channel write blocks. + channelSize: 50 + deltas: + # Channel size for readonly syncStateDeltas messages channel for + # receiving state deltas for a syncBlockRange from oppositie + # Peer Endpoints. + # NOTE: currently messages are not stored and forwarded, + # but rather lost if the channel write blocks. + channelSize: 20 + + # Validator defines whether this peer is a validating peer or not, and if + # it is enabled, what consensus plugin to load + validator: + enabled: true + + consensus: + # Consensus plugin to use. The value is the name of the plugin, e.g. pbft, noops ( this value is case-insensitive) + # if the given value is not recognized, we will default to noops + plugin: noops + + # total number of consensus messages which will be buffered per connection before delivery is rejected + buffersize: 1000 + + events: + # The address that the Event service will be enabled on the validator + address: 0.0.0.0:31315 + + # total number of events that could be buffered without blocking the + # validator sends + buffersize: 100 + + # milliseconds timeout for producer to send an event. + # if < 0, if buffer full, unblocks immediately and not send + # if 0, if buffer full, will block and guarantee the event will be sent out + # if > 0, if buffer full, blocks till timeout + timeout: 10 + + # TLS Settings for p2p communications + tls: + enabled: false + cert: + file: testdata/server1.pem + key: + file: testdata/server1.key + # The server name use to verify the hostname returned by TLS handshake + serverhostoverride: + + # PKI member services properties + pki: + eca: + paddr: localhost:50051 + tca: + paddr: localhost:50051 + tlsca: + paddr: localhost:50051 + tls: + enabled: false + rootcert: + file: tlsca.cert + # The server name use to verify the hostname returned by TLS handshake + serverhostoverride: + + # Peer discovery settings. Controls how this peer discovers other peers + discovery: + + # The root nodes are used for bootstrapping purposes, and generally + # supplied through ENV variables + # It can be either a single host or a comma separated list of hosts. + rootnode: + + # The duration of time between attempts to asks peers for their connected peers + period: 5s + + ## leaving this in for example of sub map entry + # testNodes: + # - node : 1 + # ip : 127.0.0.1 + # port : 30303 + # - node : 2 + # ip : 127.0.0.1 + # port : 30303 + + # Should the discovered nodes and their reputations + # be stored in DB and persisted between restarts + persist: true + + # if peer discovery is off + # the peer window will show + # only what retrieved by active + # peer [true/false] + enabled: true + + # number of workers that + # tast the peers for being + # online [1..10] + workers: 8 + + # the period in seconds with which the discovery + # tries to reconnect to successful nodes + # 0 means the nodes are not reconnected + touchPeriod: 6s + + # the maximum nuber of nodes to reconnect to + # -1 for unlimited + touchMaxNodes: 100 + + # Path on the file system where peer will store data + fileSystemPath: /var/hyperledger/production + + + profile: + enabled: false + listenAddress: 0.0.0.0:6060 + +############################################################################### +# +# VM section +# +############################################################################### +vm: + + # Endpoint of the vm management system. For docker can be one of the following in general + # unix:///var/run/docker.sock + # http://localhost:2375 + # https://localhost:2376 + endpoint: unix:///var/run/docker.sock + + # settings for docker vms + docker: + tls: + enabled: false + cert: + file: /path/to/server.pem + ca: + file: /path/to/ca.pem + key: + file: /path/to/server-key.pem + # Parameters of docker container creating. For docker can created by custom parameters + # If you have your own ipam & dns-server for cluster you can use them to create container efficient. + # NetworkMode Sets the networking mode for the container. Supported standard values are: `host`(default),`bridge`,`ipvlan`,`none` + # dns A list of DNS servers for the container to use. + # note: not support customize for `Privileged` + # LogConfig sets the logging driver (Type) and related options (Config) for Docker + # you can refer https://docs.docker.com/engine/admin/logging/overview/ for more detail configruation. + hostConfig: + NetworkMode: host + Dns: + # - 192.168.0.1 + LogConfig: + Type: json-file + Config: + max-size: "50m" + max-file: "5" + +############################################################################### +# +# Chaincode section +# +############################################################################### +chaincode: + + # The id is used by the Chaincode stub to register the executing Chaincode + # ID with the Peerand is generally supplied through ENV variables + # the Path form of ID is provided when deploying the chaincode. The name is + # used for all other requests. The name is really a hashcode + # returned by the system in response to the deploy transaction. In + # development mode where user runs the chaincode, the name can be any string + id: + path: + name: + + golang: + + # This is the basis for the Golang Dockerfile. Additional commands will + # be appended depedendent upon the chaincode specification. + Dockerfile: | + from hyperledger/fabric-baseimage + #from utxo:0.1.0 + COPY src $GOPATH/src + WORKDIR $GOPATH + + car: + + # This is the basis for the CAR Dockerfile. Additional commands will + # be appended depedendent upon the chaincode specification. + Dockerfile: | + FROM hyperledger/fabric-ccenv + + # timeout in millisecs for starting up a container and waiting for Register + # to come through. 1sec should be plenty for chaincode unit tests + startuptimeout: 1000 + + #timeout in millisecs for deploying chaincode from a remote repository. + deploytimeout: 30000 + + #mode - options are "dev", "net" + #dev - in dev mode, user runs the chaincode after starting validator from + # command line on local machine + #net - in net mode validator will run chaincode in a docker container + + mode: net + # typically installpath should not be modified. Otherwise, user must ensure + # the chaincode executable is placed in the path specifed by installpath in + # the image + installpath: /opt/gopath/bin/ + + # keepalive in seconds. In situations where the communiction goes through a + # proxy that does not support keep-alive, this parameter will maintain connection + # between peer and chaincode. + # A value <= 0 turns keepalive off + keepalive: 0 + +############################################################################### +# +############################################################################### +# +# Ledger section - ledger configuration encompases both the blockchain +# and the state +# +############################################################################### +ledger: + + blockchain: + + # Define the genesis block + genesisBlock: + + state: + + # Control the number state deltas that are maintained. This takes additional + # disk space, but allow the state to be rolled backwards and forwards + # without the need to replay transactions. + deltaHistorySize: 500 + + # The data structure in which the state will be stored. Different data + # structures may offer different performance characteristics. + # Options are 'buckettree', 'trie' and 'raw'. + # ( Note:'raw' is experimental and incomplete. ) + # If not set, the default data structure is the 'buckettree'. + # This CANNOT be changed after the DB has been created. + dataStructure: + # The name of the data structure is for storing the state + name: buckettree + # The data structure specific configurations + configs: + # configurations for 'bucketree'. These CANNOT be changed after the DB + # has been created. 'numBuckets' defines the number of bins that the + # state key-values are to be divided + numBuckets: 1000003 + # 'maxGroupingAtEachLevel' defines the number of bins that are grouped + #together to construct next level of the merkle-tree (this is applied + # repeatedly for constructing the entire tree). + maxGroupingAtEachLevel: 5 + # 'bucketCacheSize' defines the size (in MBs) of the cache that is used to keep + # the buckets (from root upto secondlast level) in memory. This cache helps + # in making state hash computation faster. A value less than or equals to zero + # leads to disabling this caching. This caching helps more if transactions + # perform significant writes. + bucketCacheSize: 100 + + # configurations for 'trie' + # 'tire' has no additional configurations exposed as yet + + +############################################################################### +# +# Security section - Applied to all entities (client, NVP, VP) +# +############################################################################### +security: + # Enable security will force every entity on the network to enroll with obc-ca + # and maintain a valid set of certificates in order to communicate with + # other peers + enabled: false + # To enroll NVP or VP with membersrvc. These parameters are for 1 time use. + # They will not be valid on subsequent times without un-enroll first. + # The values come from off-line registration with obc-ca. For testing, make + # sure the values are in membersrvc/membersrvc.yaml file eca.users + enrollID: vp + enrollSecret: f3489fy98ghf + # To enable privacy of transactions (requires security to be enabled). This + # encrypts the transaction content during transit and at rest. The state + # data is also encrypted + privacy: false + + # Can be 256 or 384. If you change here, you have to change also + # the same property in membersrvc.yaml to the same value + level: 256 + + # Can be SHA2 or SHA3. If you change here, you have to change also + # the same property in membersrvc.yaml to the same value + hashAlgorithm: SHA3 + + # TCerts related configuration + tcert: + batch: + # The size of the batch of TCerts + size: 200 + # Enable the release of keys needed to decrypt attributes from TCerts in + # the chaincode using the metadata field of the transaction (requires + # security to be enabled). + attributes: + enabled: false + multithreading: + enabled: false + + # Confidentiality protocol version could be 1.1 or 1.2 + confidentialityProtocolVersion: 1.2 + +################################################################################ +# +# SECTION: STATETRANSFER +# +# - This applies to recovery behavior when the replica has detected +# a state transfer is required +# +# - This might happen: +# - During a view change in response to a faulty primary +# - After a network outage which has isolated the replica +# - If the current blockchain/state is determined to be corrupt +# +################################################################################ +statetransfer: + + # Should a replica attempt to fix damaged blocks? + # In general, this should be set to true, setting to false will cause + # the replica to panic, and require a human's intervention to intervene + # and fix the corruption + recoverdamage: true + + # The number of blocks to retrieve per sync request + blocksperrequest: 20 + + # The maximum number of state deltas to attempt to retrieve + # If more than this number of deltas is required to play the state up to date + # then instead the state will be flagged as invalid, and a full copy of the state + # will be retrieved instead + maxdeltas: 200 + + # Timeouts + timeout: + + # How long may returning a single block take + singleblock: 2s + + # How long may returning a single state delta take + singlestatedelta: 2s + + # How long may transferring the complete state take + fullstate: 60s diff --git a/config/gopath.sh b/config/gopath.sh new file mode 100644 index 0000000..5d60a0e --- /dev/null +++ b/config/gopath.sh @@ -0,0 +1,4 @@ +export GOPATH=/opt/gopath +export GOROOT=/opt/go +export PATH="$GOROOT/bin:$GOPATH/bin:\$PATH" + diff --git a/config/membersrvc.yaml b/config/membersrvc.yaml new file mode 100644 index 0000000..25f7364 --- /dev/null +++ b/config/membersrvc.yaml @@ -0,0 +1,172 @@ +# CA server parameters +# +server: + # current version of the CA + version: "0.1" + + # limits the number of operating system threads used by the CA + # set to negative to use the system default setting + gomaxprocs: -1 + + # path to the OBC state directory and CA state subdirectory + rootpath: "/var/hyperledger/production" + cadir: ".membersrvc" + + # port the CA services are listening on + port: ":50051" + + # TLS certificate and key file paths + tls: + cert: + file: + key: + file: + +security: + # Can be 256 or 384 + # Must be the same as in core.yaml + level: 256 + + # Can be SHA2 or SHA3 + # Must be the same as in core.yaml + hashAlgorithm: SHA3 + +# Enabling/disabling different logging levels of the CA. +# +logging: + trace: 0 + info: 1 + warning: 1 + error: 1 + panic: 1 + +# Default users to be registered with the CA on first launch. The role is a binary OR +# of the different roles a user can have: +# +# - simple client such as a wallet: CLIENT +# - non-validating peer: PEER +# - validating client: VALIDATOR +# - auditing client: AUDITOR +# +eca: + # This hierarchy is used to create the Pre-key tree, affiliations is the top of this hierarchy, 'banks_and_institutions' is used to create the key associated to auditors of both banks and + # institutions, 'banks' is used to create a key associated to auditors of banks, 'bank_a' is used to create a key associated to auditors of bank_a, etc. + affiliations: + banks_and_institutions: + banks: + - bank_a + - bank_b + - bank_c + institutions: + - institution_a + users: + # + # The fields of each user are as follows: + # : + # + # The optional JSON_Metadata field is of the following format: + # { "registrar": { "roles": , "delegateRoles": } } + # The 'registrar' section is used to control access to registration of new users directly via the ECAA.RegisterUser GRPC call. + # (See the 'fabric/membersrvc/protos/ca.proto' file for the definition of ECAA.RegisterUser.) + # Note that this also controls who can register users via the client SDK. + # + # Only users with a 'registrar' section may be a registrar to register other users. In particular, + # 1) the "roles" field specifies which member roles may be registered by this user, and + # 2) the "delegateRoles" field specifies which member roles may become the "roles" field of registered users. + # The valid role names are "client", "peer", "validator", and "auditor". + # + # Example1: + # The 'admin' user below can register clients, peers, validators, or auditors; furthermore, the 'admin' user can register other + # users who can then register clients only. + # + # Example2: + # The 'WebAppAdmin' user below can register clients only, but none of the users registered by this user can register other users. + # + admin: 1 Xurw3yU9zI0l institution_a 00001 '{"registrar":{"roles":["client","peer","validator","auditor"],"delegateRoles":["client"]}}' + WebAppAdmin: 1 DJY27pEnl16d institution_a 00002 '{"registrar":{"roles":["client"]}}' + lukas: 1 NPKYL39uKbkj bank_a 00001 + system_chaincode_invoker: 1 DRJ20pEql15a institution_a 00002 + diego: 1 DRJ23pEQl16a institution_a 00003 + jim: 1 6avZQLwcUe9b bank_a 00004 + binhn: 1 7avZQLwcUe9q institution_a 00005 + + # Users for asset transfer with roles test located at + # sdk/node/test/unit/asset-mgmt-with-roles.js + alice: 1 CMS10pEQlB16 bank_a 00006 + bob: 1 NOE63pEQbL25 bank_a 00007 + assigner: 1 Tc43PeqBl11 bank_a 00008 + + vp: 4 f3489fy98ghf + vp0: 4 vp0_secret + vp1: 4 vp1_secret + + test_vp0: 4 MwYpmSRjupbT + test_vp1: 4 5wgHK9qqYaPy + test_vp2: 4 vQelbRvja7cJ + test_vp3: 4 9LKqKH5peurL + test_vp4: 4 Pqh90CEW5juZ + test_vp5: 4 FfdvDkAdY81P + test_vp6: 4 QiXJgHyV4t7A + test_vp7: 4 twoKZouEyLyB + test_vp8: 4 BxP7QNh778gI + test_vp9: 4 wu3F1EwJWHvQ + + test_user0: 1 MS9qrN8hFjlE bank_a 00001 + test_user1: 1 jGlNl6ImkuDo institution_a 00007 + test_user2: 1 zMflqOKezFiA bank_c 00008 + test_user3: 1 vWdLCE00vJy0 bank_a 00009 + test_user4: 1 4nXSrfoYGFCP institution_a 00010 + test_user5: 1 yg5DVhm0er1z bank_b 00011 + test_user6: 1 b7pmSxzKNFiw bank_a 00012 + test_user7: 1 YsWZD4qQmYxo institution_a 00013 + test_user8: 1 W8G0usrU7jRk bank_a 00014 + test_user9: 1 H80SiB5ODKKQ institution_a 00015 + + test_nvp0: 2 iywrPBDEPl0K bank_a 00006 + test_nvp1: 2 DcYXuRSocuqd institution_a 00007 + test_nvp2: 2 flpChShlY7xt bank_c 00008 + test_nvp3: 2 jeruawMomclo bank_a 00009 + test_nvp4: 2 RMYVxSZCk370 institution_a 00010 + test_nvp5: 2 XHYVCIJGZGK7 bank_b 00011 + test_nvp6: 2 4cIn63j8ahYp bank_a 00012 + test_nvp7: 2 E7FAJUtWVn2h institution_a 00013 + test_nvp8: 2 LJu8DkUilBEH bank_a 00014 + test_nvp9: 2 VlEsBsiyXSjw institution_a 00015 + +tca: + # Enabling/disabling attributes encryption, currently false is unique possible value due attributes encryption is not yet implemented. + attribute-encryption: + enabled: false +aca: + # Attributes is a list of the valid attributes to each user, attribute certificate authority is emulated temporarily using this file entries. + # In the future an external attribute certificate authority will be invoked. The format to each entry is: + # + # attribute-entry-#:{userid};{affiliation};{attributeName};{attributeValue};{valid from};{valid to} + # + # If valid to is empty the attribute never expire, if the valid from is empty the attribute is valid from the time zero. + attributes: + attribute-entry-0: diego;institution_a;company;ACompany;2015-01-01T00:00:00-03:00;; + attribute-entry-1: diego;institution_a;position;Software Staff;2015-01-01T00:00:00-03:00;2015-07-12T23:59:59-03:00; + attribute-entry-2: diego;institution_a;position;Software Engineer;2015-07-13T00:00:00-03:00;; + attribute-entry-3: jim,;institution_a;company;ACompany;2001-02-02T00:00:00-03:00;; + attribute-entry-4: jim;institution_a;position;Project Manager;2001-02-02T00:00:00-03:00;; + attribute-entry-5: binhn,;institution_a;company;ACompany;2015-01-01T00:00:00-03:00;; + attribute-entry-6: binhn;institution_a;position;Technical Leader;2015-01-01T00:00:00-03:00;; + + # User attributes for asset transfer with roles test located at + #sdk/node/test/unit/asset-mgmt-with-roles.js + attribute-entry-7: alice;bank_a;role;client;2016-01-01T00:00:00-03:00;; + attribute-entry-8: alice;bank_a;account;12345-56789;2016-01-01T00:00:00-03:00;; + attribute-entry-9: bob;bank_a;role;client;2015-02-02T00:00:00-03:00;; + attribute-entry-10: bob;bank_a;account;23456-67890;2015-02-02T00:00:00-03:00;; + attribute-entry-11: assigner;bank_a;role;assigner;2015-01-01T00:00:00-03:00;; + + address: localhost:50051 + server-name: acap + # Enabling/disabling Attribute Certificate Authority, if ACA is enabled attributes will be added into the TCert. + enabled: false +pki: + ca: + subject: + organization: Hyperledger + country: US diff --git a/dev/Dockerfile b/dev/Dockerfile deleted file mode 100644 index b0769ab..0000000 --- a/dev/Dockerfile +++ /dev/null @@ -1,58 +0,0 @@ -# Dockerfile for Hyperledger base image, with everything to go! -# Data is stored under /var/hyperledger/db and /var/hyperledger/production -# Under $GOPATH/bin, there are two config files: core.yaml and config.yaml. - -FROM golang:1.6 -MAINTAINER Baohua Yang - -ENV DEBIAN_FRONTEND noninteractive - -RUN apt-get update \ - && apt-get install -y libsnappy-dev zlib1g-dev libbz2-dev software-properties-common curl wget unzip autoconf build-essential libtool nodejs \ - && rm -rf /var/cache/apt - -# install nodejs -#RUN cd /tmp \ -#&& wget --quiet https://nodejs.org/dist/node-v0.12.7/node-v0.12.7-linux-x64.tar.gz \ -#&& cd /usr/local \ -#&& tar --strip-components 1 -xzf /tmp/node-v0.12.7/node-v0.12.7-linux-x64.tar.gz - -# install protoc -RUN cd /tmp \ - && git clone --single-branch https://github.com/google/protobuf.git \ - && cd protobuf \ - && git checkout 12fb61b292d7ec4cb14b0d60e58ed5c35adda3b7 \ - && ./autogen.sh \ - && ./configure --prefix=/usr \ - && make \ - && make check \ - && make install \ - && export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH - -# install rocksdb -RUN cd /tmp \ - && git clone --single-branch -b v4.1 --depth 1 https://github.com/facebook/rocksdb.git \ - && cd rocksdb \ - && PORTABLE=1 make shared_lib \ - && INSTALL_PATH=/usr/local make install-shared \ - && ldconfig - -RUN mkdir -p /var/hyperledger/db \ - && mkdir -p /var/hyperledger/production - -# install hyperledger -RUN mkdir -p $GOPATH/src/github.com/hyperledger \ - && cd $GOPATH/src/github.com/hyperledger \ - && git clone --single-branch -b master --depth 1 https://github.com/hyperledger/fabric.git \ - && cd $GOPATH/src/github.com/hyperledger/fabric \ - && CGO_CFLAGS=" " CGO_LDFLAGS="-lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy" go install \ - && go clean - - -RUN cp $GOPATH/src/github.com/hyperledger/fabric/core.yaml $GOPATH/bin \ - && cp $GOPATH/src/github.com/hyperledger/fabric/consensus/obcpbft/config.yaml $GOPATH/bin - -RUN export GOROOT=/go - -# this is only a workaround for current hard-coded problem. -RUN ln -s $GOPATH /opt/gopath \ No newline at end of file diff --git a/docker-network.sysconfig b/docker-network.sysconfig new file mode 100644 index 0000000..af03f80 --- /dev/null +++ b/docker-network.sysconfig @@ -0,0 +1,2 @@ +# /etc/sysconfig/docker-network +DOCKER_NETWORK_OPTIONS='--api-cors-header="*" -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock' diff --git a/docker-setup.sh b/docker-setup.sh new file mode 100644 index 0000000..23aabc6 --- /dev/null +++ b/docker-setup.sh @@ -0,0 +1,60 @@ +#!/bin/bash +set -e +export FABRIC_REPO=joequant +export PATH=/opt/gopath/bin:/opt/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +#install go and protobuf +rm -f /var/lib/apt/lists/*Sources* /var/lib/apt/lists/*universe* +sed -i /universe/d /etc/apt/sources.list +apt-get purge -y eject whiptail +apt-get install -y curl binutils golang-1.6-go apt-utils +rm -rf /var/cache/apt /usr/share/doc /usr/share/man +rm -rf /usr/share/go-1.6/test +ln -s $GOROOT /opt/go +ln -s $GOROOT /opt/gopath +mkdir -p /var/hyperledger/db +mkdir -p /var/hyperledger/production +strip --strip-unneeded /usr/bin/* /usr/sbin/* || true +strip --strip-unneeded $GOROOT/bin/* $GOROOT/pkg/tool/*/* || true +apt-get install -y protobuf-compiler libsnappy-dev zlib1g-dev libbz2-dev \ + unzip build-essential git-core libstdc++-5-dev \ + --no-install-recommends --no-install-suggests +strip --strip-unneeded /usr/bin/* /usr/sbin/* || true +strip --strip-unneeded /usr/lib/* /usr/local/lib/* || true +rm -rf /var/cache/apt /usr/share/doc /usr/share/man + +#install rocksdb +cd /tmp +git clone --single-branch -b v4.6.1 --depth 1 https://github.com/facebook/rocksdb.git +cd rocksdb +PORTABLE=1 make shared_lib +INSTALL_PATH=/usr/local make install-shared +ldconfig +cd .. +rm -rf rocksdb +apt-get purge -y make patch xz-utils g++ libdpkg-perl \ + libtimedate-perl sgml-base xml-core xdg-user-dirs manpages \ + krb5-locales libglib2.0-0 libxtables11 shared-mime-info \ + ifupdown rename +apt-get purge -y --allow-remove-essential sed e2fsprogs +apt-get autoremove -y +strip --strip-unneeded /usr/local/lib/* || true + +# install hyperledger +mkdir -p $GOPATH/src/github.com/hyperledger +cd $GOPATH/src/github.com/hyperledger +git clone --single-branch --depth 1 https://github.com/$FABRIC_REPO/fabric.git +cd $GOPATH/src/github.com/hyperledger/fabric/peer +CGO_CFLAGS=" " CGO_LDFLAGS="-lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy" go install +curl https://raw.githubusercontent.com/joequant/hyperledger/master/config/core.yaml > $GOPATH/bin/core.yaml +go clean + +cd $GOPATH/src/github.com/hyperledger/fabric/membersrvc +CGO_CFLAGS=" " CGO_LDFLAGS="-lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy" go install +curl https://raw.githubusercontent.com/joequant/hyperledger/master/config/membersrvc.yaml > $GOPATH/bin/membersrvc.yaml +go clean + +strip $GOPATH/bin/* || true +cp $GOPATH/src/github.com/hyperledger/fabric/consensus/noops/config.yaml $GOPATH/bin + + diff --git a/examples/chaincode/go/map/map.go b/examples/chaincode/go/map/map.go new file mode 100644 index 0000000..693e4d5 --- /dev/null +++ b/examples/chaincode/go/map/map.go @@ -0,0 +1,136 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +package main + +import ( + "encoding/json" + "errors" + "fmt" + + "github.com/hyperledger/fabric/core/chaincode/shim" +) + +// This chaincode implements a simple map that is stored in the state. +// The following operations are available. + +// Invoke operations +// put - requires two arguments, a key and value +// remove - requires a key + +// Query operations +// get - requires one argument, a key, and returns a value +// keys - requires no arguments, returns all keys + +// SimpleChaincode example simple Chaincode implementation +type SimpleChaincode struct { +} + +func (t *SimpleChaincode) Init(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) { + return nil, nil +} + +// Run callback representing the invocation of a chaincode +func (t *SimpleChaincode) Invoke(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) { + + switch function { + case "put": + if len(args) < 2 { + return nil, errors.New("put operation must include two arguments, a key and value") + } + key := args[0] + value := args[1] + + err := stub.PutState(key, []byte(value)) + if err != nil { + fmt.Printf("Error putting state %s", err) + return nil, fmt.Errorf("put operation failed. Error updating state: %s", err) + } + return nil, nil + + case "remove": + if len(args) < 1 { + return nil, errors.New("remove operation must include one argument, a key") + } + key := args[0] + + err := stub.DelState(key) + if err != nil { + return nil, fmt.Errorf("remove operation failed. Error updating state: %s", err) + } + return nil, nil + + default: + return nil, errors.New("Unsupported operation") + } + + return nil, nil +} + +// Query callback representing the query of a chaincode +func (t *SimpleChaincode) Query(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) { + + switch function { + + case "get": + if len(args) < 1 { + return nil, errors.New("get operation must include one argument, a key") + } + key := args[0] + value, err := stub.GetState(key) + if err != nil { + return nil, fmt.Errorf("get operation failed. Error accessing state: %s", err) + } + return value, nil + + case "keys": + + keysIter, err := stub.RangeQueryState("", "") + if err != nil { + return nil, fmt.Errorf("keys operation failed. Error accessing state: %s", err) + } + defer keysIter.Close() + + var keys []string + for keysIter.HasNext() { + key, _, err := keysIter.Next() + if err != nil { + return nil, fmt.Errorf("keys operation failed. Error accessing state: %s", err) + } + keys = append(keys, key) + } + + jsonKeys, err := json.Marshal(keys) + if err != nil { + return nil, fmt.Errorf("keys operation failed. Error marshaling JSON: %s", err) + } + + return jsonKeys, nil + + default: + return nil, errors.New("Unsupported operation") + } +} + +func main() { + err := shim.Start(new(SimpleChaincode)) + if err != nil { + fmt.Printf("Error starting chaincode: %s", err) + } +} diff --git a/fabric-rest.js b/fabric-rest.js new file mode 100755 index 0000000..f979677 --- /dev/null +++ b/fabric-rest.js @@ -0,0 +1,43 @@ +#!/bin/node + +// fabric-rest.js method args + +var fs = require('fs') +var async = require('async') +var jsonfile = require('jsonfile') +var argv = require('minimist')(process.argv.slice(2)) +var Client = require('node-rest-client').Client; +var client = new Client(); +var local = "http://localhost:5000"; + +var filename = argv["_"][0] + +var args = { +}; +function run_data(method, data) { + client.registerMethod("method", local + method.method, method.action); + client.methods.method({data: data, + headers: + {"Content-Type": "application/json"}}, + function(data, response) { + console.log(data); + }); +} + +jsonfile.readFile(argv["_"][0], function(err, method) { + if (err != null) { + console.log(err); + } else { + if (argv["_"][1] != undefined) { + jsonfile.readFile(argv['_'][1], function(err, data) { + if (err != null) { + console.log(err); + } else { + run_data(method, data); + } + }); + } else { + run_data(method, {}); + } + } +}); diff --git a/fabric-run.sh b/fabric-run.sh new file mode 100755 index 0000000..d4ca624 --- /dev/null +++ b/fabric-run.sh @@ -0,0 +1,3 @@ +#!/bin/bash +docker exec -it vp0 /local-dev/$1 + diff --git a/fabric-setup.sh b/fabric-setup.sh new file mode 100755 index 0000000..b5db69d --- /dev/null +++ b/fabric-setup.sh @@ -0,0 +1,5 @@ +#!/bin/bash +sudo ./install-docker.sh +docker build $* -t joequant/hyperledger . +docker tag -f joequant/hyperledger hyperledger +docker tag -f joequant/hyperledger hyperledger/fabric-baseimage diff --git a/fabric-shell.sh b/fabric-shell.sh new file mode 100755 index 0000000..e805322 --- /dev/null +++ b/fabric-shell.sh @@ -0,0 +1,3 @@ +#!/bin/bash +exec docker exec -it vp0 bash + diff --git a/git/add-upstream.sh b/git/add-upstream.sh new file mode 100755 index 0000000..6d40421 --- /dev/null +++ b/git/add-upstream.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +git submodule add https://github.com/joequant/fabric.git +pushd fabric +git remote add upstream https://github.com/hyperledger/fabric.git +popd + +git submodule add https://github.com/joequant/hyperledger-fabric-js.git +pushd hyperledger-fabric-js +git remote add upstream https://github.com/IBM-Blockchain/ibm-blockchain-js.git +popd + +for i in marbles chaincode-investigator cp-web car-lease-demo ; do +git submodule add https://github.com/joequant/$i.git +pushd $i +git remote add upstream https://github.com/IBM-Blockchain/$i.git +popd +done + diff --git a/git/car-lease-demo b/git/car-lease-demo new file mode 160000 index 0000000..7e2fcd9 --- /dev/null +++ b/git/car-lease-demo @@ -0,0 +1 @@ +Subproject commit 7e2fcd92c1b2a17fd07a5bec75f9ad0fde97c416 diff --git a/git/chaincode-investigator b/git/chaincode-investigator new file mode 160000 index 0000000..64714e5 --- /dev/null +++ b/git/chaincode-investigator @@ -0,0 +1 @@ +Subproject commit 64714e540bd3a4c474bf072b5598edbe79948b13 diff --git a/git/cp-web b/git/cp-web new file mode 160000 index 0000000..2af8c09 --- /dev/null +++ b/git/cp-web @@ -0,0 +1 @@ +Subproject commit 2af8c09b4c5d6d877dc50893edf766c4f7de12ae diff --git a/git/example.js b/git/example.js new file mode 100755 index 0000000..49fe27c --- /dev/null +++ b/git/example.js @@ -0,0 +1,57 @@ +#!/usr/bin/node +global.rootRequire = function(name) { + return require(__dirname + '/' + name); +} + +var logger = {log: console.log, error: console.error, debug: console.log, warn: console.log}; +var Ibc1 = rootRequire('hyperledger-fabric-js'); + var ibc = new Ibc1(/*logger*/); //you can pass a logger such as winston here - optional + var chaincode = {}; + + // ================================== + // configure ibc-js sdk + // ================================== + var options = { + network:{ + peers: [{ + "api_host": "172.17.0.2", + "api_port": "5000", + "id": "vp1", + + }], + options: { //this is optional + tls: false, + timeout: 6000000, + quiet: false + } + }, + chaincode:{ + zip_url: 'https://github.com/joequant/marbles-chaincode/archive/master.zip', + unzip_dir: 'marbles-chaincode-master/hyperledger/part2', + git_url: 'https://github.com/joequant/marbles-chaincode/hyperledger/part2' + } + }; + + // Step 2 ================================== + ibc.load(options, cb_ready); + + // Step 3 ================================== + function cb_ready(err, cc){ //response has chaincode functions + chaincode = cc; + logger.log('deployed_name ', cc); + // Step 4 ================================== + if(!cc.details.deployed_name || cc.details.deployed_name === ""){ //decide if I need to deploy or not + cc.deploy('init', ['99'], null, null, cb_deployed); + } + else{ + logger.log('chaincode summary file indicates chaincode has been previously deployed'); + cb_deployed(); + } + } + + // Step 5 ================================== +function cb_deployed(err){ + logger.log(err); + console.log('sdk has deployed code and waited'); + chaincode.query.read(['a']); + } diff --git a/git/fabric b/git/fabric new file mode 160000 index 0000000..9de36e3 --- /dev/null +++ b/git/fabric @@ -0,0 +1 @@ +Subproject commit 9de36e34ec275f7b87c94722e463981fc7223ec5 diff --git a/git/hyperledger-fabric-js b/git/hyperledger-fabric-js new file mode 160000 index 0000000..983fa55 --- /dev/null +++ b/git/hyperledger-fabric-js @@ -0,0 +1 @@ +Subproject commit 983fa555f05120c30abee0ef4234ec2de4529ba7 diff --git a/git/marbles b/git/marbles new file mode 160000 index 0000000..e63eeda --- /dev/null +++ b/git/marbles @@ -0,0 +1 @@ +Subproject commit e63eeda1f385b5c7082d587818e52eb11aaaa5cf diff --git a/git/push-upstream.sh b/git/push-upstream.sh new file mode 100755 index 0000000..caf918b --- /dev/null +++ b/git/push-upstream.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +for i in fabric hyperledger-fabric-js marbles chaincode-investigator cp-web cp-chaincode-v2 car-lease-demo ; do + pushd $i + git checkout master + git push + popd +done diff --git a/git/sync-upstream.sh b/git/sync-upstream.sh new file mode 100755 index 0000000..297a3b0 --- /dev/null +++ b/git/sync-upstream.sh @@ -0,0 +1,9 @@ +#!/bin/bash +for i in fabric hyperledger-fabric-js marbles chaincode-investigator cp-web cp-chaincode-v2 car-lease-demo; do + pushd $i + git fetch upstream + git rebase upstream/master + popd +done + + diff --git a/install-docker.sh b/install-docker.sh new file mode 100755 index 0000000..9011e5d --- /dev/null +++ b/install-docker.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "Please remember to unblock port 2375 from local firewall" +cp docker-network.sysconfig /etc/sysconfig/docker-network +systemctl restart docker diff --git a/json/example02-deploy.json b/json/example02-deploy.json new file mode 100644 index 0000000..ffce4eb --- /dev/null +++ b/json/example02-deploy.json @@ -0,0 +1,16 @@ +{ + "jsonrpc": "2.0", + "method" : "deploy", + "params": { + "type": 1, + "chaincodeID":{ + "path":"github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" + }, + "ctorMsg": { + "function":"init", + "args":["a", "100", "b", "200"] + } + }, + "id":1 +} + diff --git a/json/example02-invoke.json b/json/example02-invoke.json new file mode 100644 index 0000000..98771d2 --- /dev/null +++ b/json/example02-invoke.json @@ -0,0 +1,16 @@ +{ + "jsonrpc": "2.0", + "method" : "invoke", + "params": { + "type": 1, + "chaincodeID": { + "name":"1edd7021ab71b766f4928a9ef91182c018dffb86fef7a4b5a5516ac590a87957e21a62d939df817f5105f524abddcddfc7b1a60d780f02d8235bd7af9db81b66" + }, + "ctorMsg": { + "function":"invoke", + "args":["a", "b", "20"] + } + }, + "id":2 +} + diff --git a/json/example02-query.json b/json/example02-query.json new file mode 100644 index 0000000..1db986f --- /dev/null +++ b/json/example02-query.json @@ -0,0 +1,16 @@ +{ + "jsonrpc": "2.0", + "method" : "query", + "params": { + "type": 1, + "chaincodeID": { + "name":"1edd7021ab71b766f4928a9ef91182c018dffb86fef7a4b5a5516ac590a87957e21a62d939df817f5105f524abddcddfc7b1a60d780f02d8235bd7af9db81b66" + }, + "ctorMsg": { + "function":"query", + "args":["a"] + } + }, + "id":2 +} + diff --git a/json/method.chain.json b/json/method.chain.json new file mode 100644 index 0000000..500cb30 --- /dev/null +++ b/json/method.chain.json @@ -0,0 +1,4 @@ +{ + "action" : "GET", + "method" : "/chain" +} diff --git a/json/method.chaincode.json b/json/method.chaincode.json new file mode 100644 index 0000000..6a4c6d9 --- /dev/null +++ b/json/method.chaincode.json @@ -0,0 +1,4 @@ +{ + "action" : "POST", + "method" : "/chaincode" +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..be6d2e3 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ "name" : "hyperledger-scripts", + "version" : "0.0.0", + "license" : "BSD-2-Clause", + "dependencies" : + { "fs" : "latest", + "async" : "latest", + "node-rest-client" : "latest", + "jsonfile" : "latest"}, + "repository": + {"type" : "git", + "url" : "https://github.com/joequant/hyperledger.git" + } +} diff --git a/rm-stopped-containers.sh b/rm-stopped-containers.sh new file mode 100755 index 0000000..913e623 --- /dev/null +++ b/rm-stopped-containers.sh @@ -0,0 +1,2 @@ +#!/bin/bash +$SUDO docker rm $($SUDO docker ps -a -q) diff --git a/rm-untagged-images.sh b/rm-untagged-images.sh new file mode 100755 index 0000000..150e911 --- /dev/null +++ b/rm-untagged-images.sh @@ -0,0 +1,2 @@ +#!/bin/bash +$SUDO docker rmi $($SUDO docker images | grep "^" | awk '{print $3}') diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 0000000..fe2f9d3 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,6 @@ +#!/bin/bash +export CORE_PEER_ADDRESS=vp0:30303 + +peer chaincode deploy $FABRIC_ARGS -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Function":"init", "Args": ["a","100", "b", "200"]}' + +#peer chaincode deploy -p github.com/joequant/hyperledger/examples/chaincode/go/map -c '{"Function":"init", "Args": []}' diff --git a/scripts/login.sh b/scripts/login.sh new file mode 100755 index 0000000..e49a222 --- /dev/null +++ b/scripts/login.sh @@ -0,0 +1,3 @@ +#!/bin/bash +export CORE_PEER_ADDRESS=vp0:30303 +peer network login jim diff --git a/scripts/run-test.sh b/scripts/run-test.sh new file mode 100755 index 0000000..072d4cf --- /dev/null +++ b/scripts/run-test.sh @@ -0,0 +1,8 @@ +#!/bin/bash +export CORE_PEER_ADDRESS=vp0:30303 + +NAME=`peer chaincode deploy $FABRIC_ARGS -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Function":"init", "Args": ["a","100", "b", "200"]}'` + +peer chaincode invoke -n $NAME $FABRIC_ARGS -c '{"Function": "invoke", "Args": ["a", "b", "10"]}' +peer chaincode query -l golang -n $NAME $FABRIC_ARGS -c '{"Function": "query", "Args": ["a"]}' + diff --git a/startnet-secure.sh b/startnet-secure.sh new file mode 100755 index 0000000..df996ad --- /dev/null +++ b/startnet-secure.sh @@ -0,0 +1,69 @@ +#!/bin/bash +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +docker stop vp0 +docker stop vp1 +docker stop ca +docker rm vp0 +docker rm vp1 +docker rm ca + +docker run joequant/hyperledger echo +docker run --name=ca \ + -p 50051:50051 \ + --hostname=ca \ + -v $SCRIPT_DIR:/local-dev \ + -v $SCRIPT_DIR/git/fabric:/usr/lib/go-1.6/src/github.com/hyperledger/fabric \ + -i \ + joequant/hyperledger \ + ./membersrvc --logging-level=debug >& ca.log & + +sleep 5 + +docker run --name=vp0 \ + --hostname=vp0 \ + --link ca:ca \ + -v $SCRIPT_DIR:/local-dev \ + -v $SCRIPT_DIR/git/fabric:/usr/lib/go-1.6/src/github.com/hyperledger/fabric \ + -p 5000:5000 \ + -p 30303:30303 \ + -e CORE_PEER_ID=vp0 \ + -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 \ + -e CORE_PEER_ADDRESSAUTODETECT=true \ + -e CORE_SECURITY_ENABLED=true \ + -e CORE_SECURITY_PRIVACY=true \ + -e CORE_PEER_PKI_ECA_PADDR=ca:50051 \ + -e CORE_PEER_PKI_TCA_PADDR=ca:50051 \ + -e CORE_PEER_PKI_TLSCA_PADDR=ca:50051 \ + -e CORE_SECURITY_ENROLLID=vp0 \ + -e CORE_SECURITY_ENROLLSECRET=vp0_secret \ + -e FABRIC_ARGS="-u jim" \ + joequant/hyperledger peer node start --logging-level=debug >& vp0.log & + +sleep 5 + +docker run --name=vp1 \ + --hostname=vp1 \ + -v $SCRIPT_DIR:/local-dev \ + -v $SCRIPT_DIR/git/fabric:/usr/lib/go-1.6/src/github.com/hyperledger/fabric \ + -i \ + --link vp0:vp0 \ + --link ca:ca \ + -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e \ + CORE_PEER_ID=vp1 -e CORE_PEER_ADDRESSAUTODETECT=true \ + -e CORE_PEER_DISCOVERY_ROOTNODE=vp0:30303 \ + -e CORE_SECURITY_ENABLED=true \ + -e CORE_SECURITY_PRIVACY=true \ + -e CORE_PEER_PKI_ECA_PADDR=ca:50051 \ + -e CORE_PEER_PKI_TCA_PADDR=ca:50051 \ + -e CORE_PEER_PKI_TLSCA_PADDR=ca:50051 \ + -e CORE_SECURITY_ENROLLID=vp1 \ + -e CORE_SECURITY_ENROLLSECRET=vp1_secret \ + -e FABRIC_ARGS="-u jim" \ + joequant/hyperledger \ + peer node start --logging-level=debug >& vp1.log & + +echo "Get the password from config/membersrvc.yaml" +docker exec -it vp0 /local-dev/scripts/login.sh + + + diff --git a/startnet.sh b/startnet.sh new file mode 100755 index 0000000..01c2af4 --- /dev/null +++ b/startnet.sh @@ -0,0 +1,33 @@ +#!/bin/bash +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +docker stop vp0 +docker stop vp1 +docker rm vp0 +docker rm vp1 + +docker run joequant/hyperledger echo + +docker run --name=vp0 \ + --hostname=vp0 \ + -v $SCRIPT_DIR:/local-dev \ + -v $SCRIPT_DIR/git/fabric:/usr/lib/go-1.6/src/github.com/hyperledger/fabric \ + -p 5000:5000 \ + -p 30303:30303 \ + -e CORE_PEER_ID=vp0 \ + -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 \ + -e CORE_PEER_ADDRESSAUTODETECT=true \ + joequant/hyperledger peer node start --logging-level=debug >& vp0.log & + +sleep 5 + +docker run --name=vp1 \ + --hostname=vp1 \ + -v $SCRIPT_DIR:/local-dev \ + -v $SCRIPT_DIR/git/fabric:/usr/lib/go-1.6/src/github.com/hyperledger/fabric \ + -i \ + --link vp0:vp0 \ + -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e \ +CORE_PEER_ID=vp1 -e CORE_PEER_ADDRESSAUTODETECT=true -e \ +CORE_PEER_DISCOVERY_ROOTNODE=vp0:30303 joequant/hyperledger \ + peer node start --logging-level=debug >& vp1.log & + diff --git a/stopnet.sh b/stopnet.sh new file mode 100755 index 0000000..de0a724 --- /dev/null +++ b/stopnet.sh @@ -0,0 +1,9 @@ +#!/bin/bash +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +docker stop vp0 +docker stop vp1 +docker stop ca +docker rm vp0 +docker rm vp1 +docker rm ca +