- Added generic smart contract template

- Refer README to quickly create a smart contract using the template
parent f15c46df
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed 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.
# fabric_chaincode_template
Hyperledger fabric chaincode template
**To create New chaincode :**
- Edit CHAINCODE_NAME and CHAINCODE_CLASS_NAME in the file https://github.com/bityoga/fabric_chaincode_template/blob/main/create_chaincode.sh
- Execute the script "create_chaincode.sh"
- For couchdb rich queries support, edit the fields in the index file under the directory ***"chaincode/src/lib/META-INF/statedb/couchdb/indexes/"***
![Screenshot from 2020-12-31 16-27-41](https://user-images.githubusercontent.com/30879156/103416081-3fea8600-4b85-11eb-9d82-35dc22185b02.png)
#!/bin/bash
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHANNEL_NAME="appchannel"
QUERY_PARAMS='{"Args":["GetAllAssets"]}'
export PEER_HOST=peer2
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
CORE_PEER_ADDRESS=$CORE_PEER_ADDRESS CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp CORE_PEER_TLS_ROOTCERT_FILE=$CORE_PEER_TLS_ROOTCERT_FILE peer chaincode query -C $CHANNEL_NAME -n $CHAINCODE_NAME -c $QUERY_PARAMS
#!/bin/bash
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHAINCODE_VERSION="1.0"
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CHAINCODE_DIR=${PWD%/*}
CHAINCODE_SRC_CODE_PATH="$CHAINCODE_DIR/src"
export PEER_HOST=peer2
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
CORE_PEER_ADDRESS=$CORE_PEER_ADDRESS CORE_PEER_MSPCONFIGPATH=$CORE_PEER_MSPCONFIGPATH CORE_PEER_TLS_ROOTCERT_FILE=$CORE_PEER_TLS_ROOTCERT_FILE peer chaincode install -n $CHAINCODE_NAME -v $CHAINCODE_VERSION -l node -p $CHAINCODE_SRC_CODE_PATH
#!/bin/bash
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHAINCODE_VERSION="1.0"
INSTANTIATE_PARAMS='{"Args":["InitLedger"]}'
CHANNEL_NAME="appchannel"
export PEER_HOST=peer2
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
CORE_PEER_ADDRESS=$CORE_PEER_ADDRESS CORE_PEER_MSPCONFIGPATH=$CORE_PEER_MSPCONFIGPATH CORE_PEER_TLS_ROOTCERT_FILE=$CORE_PEER_TLS_ROOTCERT_FILE peer chaincode instantiate -C $CHANNEL_NAME -n $CHAINCODE_NAME -v $CHAINCODE_VERSION -c $INSTANTIATE_PARAMS -o ${ORDERER_HOST}:7050 --tls --cafile ${CORE_PEER_TLS_ROOTCERT_FILE}
#!/bin/bash
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHANNEL_NAME="appchannel"
INVOKE_PARAMS='{"Args":["CreateAssetJson","srk","1000","InitialCredit"]}'
export PEER_HOST=peer2
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
CORE_PEER_ADDRESS=$CORE_PEER_ADDRESS CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp CORE_PEER_TLS_ROOTCERT_FILE=$CORE_PEER_TLS_ROOTCERT_FILE peer chaincode invoke -C $CHANNEL_NAME -n $CHAINCODE_NAME -c $INVOKE_PARAMS -o ${ORDERER_HOST}:7050 --tls --cafile ${CORE_PEER_TLS_ROOTCERT_FILE}
#!/bin/bash
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHAINCODE_VERSION="1.2"
INSTANTIATE_PARAMS='{"Args":["InitLedger"]}'
CHANNEL_NAME="appchannel"
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CHAINCODE_DIR=${PWD%/*}
CHAINCODE_SRC_CODE_PATH="$CHAINCODE_DIR/src"
export PEER_HOST=peer2
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
CORE_PEER_ADDRESS=$CORE_PEER_ADDRESS CORE_PEER_MSPCONFIGPATH=$CORE_PEER_MSPCONFIGPATH CORE_PEER_TLS_ROOTCERT_FILE=$CORE_PEER_TLS_ROOTCERT_FILE peer chaincode install -n $CHAINCODE_NAME -v $CHAINCODE_VERSION -l node -p $CHAINCODE_SRC_CODE_PATH &&
CORE_PEER_ADDRESS=$CORE_PEER_ADDRESS CORE_PEER_MSPCONFIGPATH=$CORE_PEER_MSPCONFIGPATH CORE_PEER_TLS_ROOTCERT_FILE=$CORE_PEER_TLS_ROOTCERT_FILE peer chaincode upgrade -C $CHANNEL_NAME -n $CHAINCODE_NAME -v $CHAINCODE_VERSION -c $INSTANTIATE_PARAMS -p $CHAINCODE_SRC_CODE_PATH -o ${ORDERER_HOST}:7050 --tls --cafile ${CORE_PEER_TLS_ROOTCERT_FILE}
#!/bin/bash
# peer lifecycle chaincode package CHAINCODE-NAME.tar.gz --path ../src/ --lang node --label smart_meter_1.0
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHAINCODE_VERSION="1.0"
PACKAGE_NAME="${CHAINCODE_NAME}.tar.gz"
CHAINCODE_LABEL="${CHAINCODE_NAME}_${CHAINCODE_VERSION}"
CHANCODE_LANGUAGE="node"
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CHAINCODE_DIR=${PWD%/*}
CHAINCODE_SRC_CODE_PATH="$CHAINCODE_DIR/src"
export ORGANISATION_NAME="hlfMSP"
export PEER_HOST=peer2
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID=${ORGANISATION_NAME}
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
peer lifecycle chaincode package ${PACKAGE_NAME} --path ${CHAINCODE_SRC_CODE_PATH} --lang ${CHANCODE_LANGUAGE} --label ${CHAINCODE_LABEL}
\ No newline at end of file
#!/bin/bash
# peer lifecycle chaincode install CHAINCODE-NAME.tar.gz
# peer lifecycle chaincode queryinstalled --output json
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHAINCODE_VERSION="1.0"
PACKAGE_NAME="${CHAINCODE_NAME}.tar.gz"
CHAINCODE_LABEL="${CHAINCODE_NAME}_${CHAINCODE_VERSION}"
CHANCODE_LANGUAGE="node"
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CHAINCODE_DIR=${PWD%/*}
CHAINCODE_SRC_CODE_PATH="$CHAINCODE_DIR/src"
export ORGANISATION_NAME="hlfMSP"
export PEER_HOST=peer2
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID=${ORGANISATION_NAME}
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
peer lifecycle chaincode install ${PACKAGE_NAME} &&
peer lifecycle chaincode queryinstalled --output json
\ No newline at end of file
#!/bin/bash
# peer lifecycle chaincode queryinstalled --output json | jq .installed_chaincodes[0].package_id
# peer lifecycle chaincode approveformyorg -o orderer:7050 --channelID appchannel --name CHAINCODE-NAME --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile /root/CLI/orgca/orderer/msp/tls/ca.crt
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHAINCODE_VERSION="1.0"
PACKAGE_NAME="${CHAINCODE_NAME}.tar.gz"
CHAINCODE_LABEL="${CHAINCODE_NAME}_${CHAINCODE_VERSION}"
CHANCODE_LANGUAGE="node"
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CHAINCODE_DIR=${PWD%/*}
CHAINCODE_SRC_CODE_PATH="$CHAINCODE_DIR/src"
export ORGANISATION_NAME="hlfMSP"
SIGNATURE_POLICY="OR('${ORGANISATION_NAME}.member')"
CHANNEL_NAME="appchannel"
SEQUENCE="1"
export PEER_HOST=peer2
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID=${ORGANISATION_NAME}
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
export CC_PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq .installed_chaincodes[0].package_id)
export ORDERER_CA=/root/CLI/${ORGCA_HOST}/${ORDERER_HOST}/msp/tls/ca.crt
peer lifecycle chaincode approveformyorg -o ${ORDERER_HOST}:7050 --channelID ${CHANNEL_NAME} --name ${CHAINCODE_NAME} --version ${CHAINCODE_VERSION} --package-id ${CC_PACKAGE_ID} --sequence ${SEQUENCE} --tls --cafile ${ORDERER_CA}
\ No newline at end of file
#!/bin/bash
# peer lifecycle chaincode checkcommitreadiness --channelID appchannel --name CHAINCODE-NAME --version 1.0 --sequence 1 --tls --cafile /root/CLI/orgca/orderer/msp/tls/ca.crt --output json
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHAINCODE_VERSION="1.0"
PACKAGE_NAME="${CHAINCODE_NAME}.tar.gz"
CHAINCODE_LABEL="${CHAINCODE_NAME}_${CHAINCODE_VERSION}"
CHANCODE_LANGUAGE="node"
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CHAINCODE_DIR=${PWD%/*}
CHAINCODE_SRC_CODE_PATH="$CHAINCODE_DIR/src"
export ORGANISATION_NAME="hlfMSP"
SIGNATURE_POLICY="OR('${ORGANISATION_NAME}.peer')"
CHANNEL_NAME="appchannel"
SEQUENCE="1"
export PEER_HOST=peer2
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID=${ORGANISATION_NAME}
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
export CC_PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq .installed_chaincodes[0].package_id)
export ORDERER_CA=/root/CLI/${ORGCA_HOST}/${ORDERER_HOST}/msp/tls/ca.crt
peer lifecycle chaincode checkcommitreadiness --channelID ${CHANNEL_NAME} --name ${CHAINCODE_NAME} --version ${CHAINCODE_VERSION} --sequence ${SEQUENCE} --tls --cafile ${ORDERER_CA} --output json
\ No newline at end of file
#!/bin/bash
# peer lifecycle chaincode commit -o orderer:7050 --channelID appchannel --name CHAINCODE-NAME --version 1.0 --sequence 1 --tls --cafile /root/CLI/orgca/orderer/msp/tls/ca.crt --peerAddresses peer2:7051 --tlsRootCertFiles /root/CLI/orgca/peer2/msp/tls/ca.crt
# peer lifecycle chaincode querycommitted --channelID appchannel --name CHAINCODE-NAME --cafile /root/CLI/orgca/orderer/msp/tls/ca.crt
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHAINCODE_VERSION="1.0"
PACKAGE_NAME="${CHAINCODE_NAME}.tar.gz"
CHAINCODE_LABEL="${CHAINCODE_NAME}_${CHAINCODE_VERSION}"
CHANCODE_LANGUAGE="node"
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CHAINCODE_DIR=${PWD%/*}
CHAINCODE_SRC_CODE_PATH="$CHAINCODE_DIR/src"
export ORGANISATION_NAME="hlfMSP"
SIGNATURE_POLICY="OR('${ORGANISATION_NAME}.peer')"
CHANNEL_NAME="appchannel"
SEQUENCE="1"
export PEER_HOST=peer2
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID=${ORGANISATION_NAME}
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
export CC_PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq .installed_chaincodes[0].package_id)
export ORDERER_CA=/root/CLI/${ORGCA_HOST}/${ORDERER_HOST}/msp/tls/ca.crt
peer lifecycle chaincode commit -o ${ORDERER_HOST}:7050 --channelID ${CHANNEL_NAME} --name ${CHAINCODE_NAME} --version ${CHAINCODE_VERSION} --sequence ${SEQUENCE} --tls --cafile ${ORDERER_CA} --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_ROOTCERT_FILE} &&
peer lifecycle chaincode querycommitted --channelID ${CHANNEL_NAME} --name ${CHAINCODE_NAME} --cafile ${ORDERER_CA}
#!/bin/bash
# peer chaincode invoke -o orderer:7050 --tls --cafile /root/CLI/orgca/orderer/msp/tls/ca.crt -C appchannel -n CHAINCODE-NAME --peerAddresses peer2:7051 --tlsRootCertFiles /root/CLI/orgca/peer2/msp/tls/ca.crt -c '{"Args":["CreateAsset","admin_test","1000","Initial Credit"]}'
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHANNEL_NAME="appchannel"
INVOKE_PARAMS='{"Args":["CreateAsset","admin_test","1000","Initial Credit"]}'
export ORGANISATION_NAME="hlfMSP"
export PEER_HOST=peer2
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID=${ORGANISATION_NAME}
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
export ORDERER_CA=/root/CLI/${ORGCA_HOST}/${ORDERER_HOST}/msp/tls/ca.crt
export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq .installed_chaincodes[0].package_id)
peer chaincode invoke -o ${ORDERER_HOST}:7050 --tls --cafile ${ORDERER_CA} -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_ROOTCERT_FILE} -c ${INVOKE_PARAMS}
#!/bin/bash
# peer chaincode invoke -o orderer:7050 --tls --cafile /root/CLI/orgca/orderer/msp/tls/ca.crt -C appchannel -n CHAINCODE-NAME --peerAddresses peer2:7051 --tlsRootCertFiles /root/CLI/orgca/peer2/msp/tls/ca.crt -c '{"Args":["InitLedger"]}'
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHANNEL_NAME="appchannel"
INVOKE_PARAMS='{"Args":["InitLedger"]}'
export ORGANISATION_NAME="hlfMSP"
export PEER_HOST=peer2
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID=${ORGANISATION_NAME}
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
export ORDERER_CA=/root/CLI/${ORGCA_HOST}/${ORDERER_HOST}/msp/tls/ca.crt
export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq .installed_chaincodes[0].package_id)
peer chaincode invoke -o ${ORDERER_HOST}:7050 --tls --cafile ${ORDERER_CA} -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_ROOTCERT_FILE} -c ${INVOKE_PARAMS}
\ No newline at end of file
#!/bin/bash
# peer chaincode invoke -o orderer:7050 --tls --cafile /root/CLI/orgca/orderer/msp/tls/ca.crt -C appchannel -n CHAINCODE-NAME --peerAddresses peer2:7051 --tlsRootCertFiles /root/CLI/orgca/peer2/msp/tls/ca.crt -c '{"Args":["InitLedger"]}'
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHANNEL_NAME="appchannel"
INVOKE_PARAMS='{"Args":["TransferBalance","ark","srk","5"]}'
export ORGANISATION_NAME="hlfMSP"
export PEER_HOST=peer2
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID=${ORGANISATION_NAME}
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
export ORDERER_CA=/root/CLI/${ORGCA_HOST}/${ORDERER_HOST}/msp/tls/ca.crt
export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq .installed_chaincodes[0].package_id)
#peer chaincode invoke -o ${ORDERER_HOST}:7050 --tls --cafile ${ORDERER_CA} -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_ROOTCERT_FILE} -c ${INSTANTIATE_PARAMS}
peer chaincode invoke -o ${ORDERER_HOST}:7050 --tls --cafile ${ORDERER_CA} -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_ROOTCERT_FILE} -c ${INVOKE_PARAMS}
\ No newline at end of file
#!/bin/bash
# peer chaincode query -C appchannel -n CHAINCODE-NAME -c '{"Args":["GetAllAssets"]}'
set -x #echo on
CHAINCODE_NAME="CHAINCODE-NAME"
CHANNEL_NAME="appchannel"
QUERY_PARAMS='{"Args":["GetAllAssets"]}'
export ORGANISATION_NAME="hlfMSP"
export PEER_HOST=peer2
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID=${ORGANISATION_NAME}
export CORE_PEER_TLS_ROOTCERT_FILE=/root/CLI/${ORGCA_HOST}/${PEER_HOST}/msp/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/root/CLI/${ORGCA_HOST}/${ADMIN_USER}/msp
export CORE_PEER_ADDRESS=${PEER_HOST}:7051
export ORDERER_CA=/root/CLI/${ORGCA_HOST}/${ORDERER_HOST}/msp/tls/ca.crt
export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq .installed_chaincodes[0].package_id)
peer chaincode query -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} -c ${QUERY_PARAMS}
\ No newline at end of file
#
# SPDX-License-Identifier: Apache-2.0
#
coverage
/*
* SPDX-License-Identifier: Apache-2.0
*/
'use strict';
module.exports = {
env: {
node: true,
mocha: true
},
parserOptions: {
ecmaVersion: 8,
sourceType: 'script'
},
extends: 'eslint:recommended',
rules: {
indent: ['error', 'tab'],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
'no-unused-vars': ['error', { args: 'none' }],
'no-console': 'off',
curly: 'error',
eqeqeq: 'error',
'no-throw-literal': 'error',
strict: 'error',
'no-var': 'error',
'dot-notation': 'error',
'no-trailing-spaces': 'error',
'no-use-before-define': 'error',
'no-useless-call': 'error',
'no-with': 'error',
'operator-linebreak': 'error',
yoda: 'error',
'quote-props': ['error', 'as-needed']
}
};
/*
* Copyright IBM Corp. All Rights Reserved.
*
*
* SPDX-License-Identifier: Apache-2.0
*/
'use strict';
const CC = require('./lib/chaincode.js');
module.exports.CC = CC;
module.exports.contracts = [ CC ];
/*
* Copyright IBM Corp. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
const moment = require("moment");
let SUCCESS_CODE = 200;
let FAILURE_CODE = 500;
// CreateAsset issues a new asset to the world state with given details.
async function CreateAssetJson(ctx, assetId, assetJSON, TransactionMessage) {
let returnValue = {};
returnValue["status"] = SUCCESS_CODE;
try {
// Parse json object
const assetData = JSON.parse(assetJSON);
// If array of objects, loop through them
if (Array.isArray(assetData)) {
let currentTimestamp;
for (const asset of assetData) {
currentTimestamp = moment();
asset["TransactionUnixTimestamp"] = currentTimestamp.unix();
asset["TransactionIsoTimestamp"] = currentTimestamp.toISOString();
asset["TransactionMessage"] = TransactionMessage;
asset["AssetId"] = assetId;
await ctx.stub.putState(assetId, Buffer.from(JSON.stringify(asset)));
console.info(`Asset ${assetId} initialized`);
}
returnValue["message"] = `${assets.length} Assets created successfully`;
console.info(returnValue["message"]);
} else {
let currentTimestamp = moment();
assetData["TransactionMessage"] = TransactionMessage;
assetData["TransactionUnixTimestamp"] = currentTimestamp.unix();
assetData["TransactionIsoTimestamp"] = currentTimestamp.toISOString();
assetData["AssetId"] = assetId;
await ctx.stub.putState(assetId, Buffer.from(JSON.stringify(assetData)));
returnValue["message"] = `Asset ${assetId} created successfully`;
console.info(returnValue["message"]);
}
} catch (error) {
returnValue["status"] = FAILURE_CODE;
returnValue["message"] = `Failed to create Asset: ${error}`;
} finally {
return returnValue;
}
}
// DeleteAsset deletes an given asset from the world state.
async function DeleteAsset(ctx, id) {
let returnValue = {};
returnValue["status"] = SUCCESS_CODE;
try {
const exists = await AssetExists(ctx, id);
if (!exists) {
returnValue["status"] = FAILURE_CODE;
returnValue["message"] = `The asset ${id} does not exist`;
} else {
returnValue["message"] = ctx.stub.deleteState(id);
}
} catch (error) {
returnValue["status"] = FAILURE_CODE;
returnValue["message"] = `Failed to Delete Asset: ${error}`;
} finally {
return returnValue;
}
}
// UpdateAsset updates an existing asset in the world state with provided parameters.
async function UpdateAssetJson(ctx, id, updateParamsJSON, TransactionMessage) {
let returnValue = {};
returnValue["status"] = SUCCESS_CODE;
try {
const exists = await AssetExists(ctx, id);
if (!exists) {
returnValue["status"] = FAILURE_CODE;
returnValue["message"] = `The asset ${id} does not exist`;
} else {
let currentAsset = JSON.parse(await GetAsset(ctx, id));
let updateParams = JSON.parse(updateParamsJSON);
let updatedAsset = update_obj(currentAsset, updateParams);
let currentTimestamp = moment();
updatedAsset["TransactionUnixTimestamp"] = currentTimestamp.unix();
updatedAsset["TransactionIsoTimestamp"] = currentTimestamp.toISOString();
updatedAsset["TransactionMessage"] = TransactionMessage;
returnValue["message"] = ctx.stub.putState(
id,
Buffer.from(JSON.stringify(updatedAsset))
);
}
} catch (error) {
returnValue["status"] = FAILURE_CODE;
returnValue["message"] = `Failed to Update Asset: ${error}`;
} finally {
return returnValue;
}
}
// AssetExists returns true when asset with given ID exists in world state.
async function AssetExists(ctx, id) {
const assetJSON = await ctx.stub.getState(id);
return assetJSON && assetJSON.length > 0;
}
// GetAsset returns the asset stored in the world state with given id.
async function GetAsset(ctx, id) {
const assetJSON = await ctx.stub.getState(id); // get the asset from chaincode state
if (!assetJSON || assetJSON.length === 0) {
throw new Error(`The asset ${id} does not exist`);
}
return assetJSON.toString();
}
// GetQueryResultForQueryString executes the passed in query string.
// Result set is built and returned as a byte array containing the JSON results.
async function GetQueryResultForQueryString(ctx, queryString) {
let resultsIterator = await ctx.stub.getQueryResult(queryString);
let results = await GetAllResults(resultsIterator, false);
return JSON.stringify(results);
}
// Example: Ad hoc rich query
// QueryAssets uses a query string to perform a query for assets.
// Query string matching state database syntax is passed in and executed as is.
// Supports ad hoc queries that can be defined at runtime by the client.
// If this is not desired, follow the QueryAssetsForOwner example for parameterized queries.
// Only available on state databases that support rich query (e.g. CouchDB)
async function QueryAssets(ctx, queryString) {
return await GetQueryResultForQueryString(ctx, queryString);
}
// Example: Pagination with Range Query
// GetAssetsByRangeWithPagination performs a range query based on the start & end key,
// page size and a bookmark.
// The number of fetched records will be equal to or lesser than the page size.
// Paginated range queries are only valid for read only transactions.
async function GetAssetsByRangeWithPagination(
ctx,
startKey,
endKey,
pageSize,
bookmark
) {
const { iterator, metadata } = await ctx.stub.getStateByRangeWithPagination(
startKey,
endKey,
pageSize,
bookmark
);
console.log("iterator");
console.log(iterator);
console.log("metadata");
console.log(JSON.stringify(metadata));
const results = await GetAllResults(iterator, false);
const final_output = {};
final_output["RecordsCount"] = metadata.fetchedRecordsCount;
final_output["Bookmark"] = metadata.bookmark;
final_output["RecordsData"] = results;
console.log("final_output");
console.log(JSON.stringify(final_output));
return JSON.stringify(final_output);
}
// Example: Pagination with Ad hoc Rich Query
// QueryAssetsWithPagination uses a query string, page size and a bookmark to perform a query
// for assets. Query string matching state database syntax is passed in and executed as is.
// The number of fetched records would be equal to or lesser than the specified page size.
// Supports ad hoc queries that can be defined at runtime by the client.
// If this is not desired, follow the QueryAssetsForOwner example for parameterized queries.
// Only available on state databases that support rich query (e.g. CouchDB)
// Paginated queries are only valid for read only transactions.
async function QueryAssetsWithPagination(ctx, queryString, pageSize, bookmark) {
let returnValue = {};
returnValue["status"] = SUCCESS_CODE;
const { iterator, metadata } = await ctx.stub.getQueryResultWithPagination(
queryString,
pageSize,
bookmark
);
console.log("iterator");
console.log(iterator);
console.log("metadata");
console.log(JSON.stringify(metadata));
const results = await GetAllResults(iterator, false);
const final_output = {};
final_output["RecordsCount"] = metadata.fetchedRecordsCount;
final_output["Bookmark"] = metadata.bookmark;
final_output["RecordsData"] = results;
console.log("final_output");
console.log(JSON.stringify(final_output));
return JSON.stringify(final_output);
}
// GetAssetHistory returns the chain of custody for an asset since issuance.
async function GetAssetHistory(ctx, assetId) {
let resultsIterator = await ctx.stub.getHistoryForKey(assetId);
let results = await GetAllResults(resultsIterator, true);
return JSON.stringify(results);
}
// GetAllAssets returns all assets found in the world state.
async function GetAllAssets(ctx) {
const allResults = [];
// range query with empty string for startKey and endKey does an open-ended query of all assets in the chaincode namespace.
const iterator = await ctx.stub.getStateByRange("", "");
let result = await iterator.next();
while (!result.done) {
const strValue = Buffer.from(result.value.value.toString()).toString(
"utf8"
);
let record;
try {
record = JSON.parse(strValue);
} catch (err) {
console.log(err);
record = strValue;
}
allResults.push({ Key: result.value.key, Record: record });
result = await iterator.next();
}
return JSON.stringify(allResults);
}
async function GetAllResults(iterator, isHistory) {
let allResults = [];
let res = await iterator.next();
while (!res.done) {
if (res.value && res.value.value.toString()) {
let jsonRes = {};
console.log(res.value.value.toString("utf8"));
if (isHistory && isHistory === true) {
jsonRes.TxId = res.value.tx_id;
jsonRes.Timestamp = res.value.timestamp;
try {
jsonRes.Value = JSON.parse(res.value.value.toString("utf8"));
} catch (err) {
console.log(err);
jsonRes.Value = res.value.value.toString("utf8");
}
} else {
jsonRes.Key = res.value.key;
try {
jsonRes.Record = JSON.parse(res.value.value.toString("utf8"));
} catch (err) {
console.log(err);
jsonRes.Record = res.value.value.toString("utf8");
}
}
allResults.push(jsonRes);
}
res = await iterator.next();
}
iterator.close();
return allResults;
}
function update_obj(obj /*, …*/) {
for (var i = 1; i < arguments.length; i++) {
for (var prop in arguments[i]) {
var val = arguments[i][prop];
if (typeof val == "object")
// this also applies to arrays or null!
update(obj[prop], val);
else obj[prop] = val;
}
}
return obj;
}
module.exports = {
SUCCESS_CODE: SUCCESS_CODE,
FAILURE_CODE: FAILURE_CODE,
CreateAssetJson: CreateAssetJson,
DeleteAsset: DeleteAsset,
UpdateAssetJson: UpdateAssetJson,
AssetExists: AssetExists,
GetAsset: GetAsset,
GetQueryResultForQueryString: GetQueryResultForQueryString,
QueryAssets: QueryAssets,
GetAssetsByRangeWithPagination: GetAssetsByRangeWithPagination,
QueryAssetsWithPagination: QueryAssetsWithPagination,
GetAssetHistory: GetAssetHistory,
GetAllAssets: GetAllAssets,
};
{
"index":{
"fields":["AssetId","TransactionUnixTimestamp"]
},
"ddoc":"indexAssetUtilDoc",
"name":"indexAssetUtil",
"type":"json"
}
\ No newline at end of file
/*
* Copyright IBM Corp. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
const { Contract } = require("fabric-contract-api");
const AssetUtil = require("./AssetUtil");
class CHAINCODE_CLASS_NAME extends Contract {
async InitLedger(ctx) {
let initialAsset = [];
return AssetUtil.CreateAssetJson(ctx, JSON.stringify(initialAsset));
}
// CreateAsset issues a new asset to the world state with given details.
async CreateAssetJson(ctx, assetId, assetJSON, TransactionMessage) {
return AssetUtil.CreateAssetJson(
ctx,
assetId,
assetJSON,
TransactionMessage
);
}
// ReadAsset returns the asset stored in the world state with given id.
async GetAsset(ctx, id) {
return AssetUtil.GetAsset(ctx, id);
}
// UpdateAsset updates an existing asset in the world state with provided parameters.
async UpdateAssetJson(ctx, assetId, updateParamsJSON, TransactionMessage) {
return AssetUtil.UpdateAssetJson(
ctx,
assetId,
updateParamsJSON,
TransactionMessage
);
}
// DeleteAsset deletes an given asset from the world state.
async DeleteAsset(ctx, id) {
return AssetUtil.DeleteAsset(ctx, id);
}
// AssetExists returns true when asset with given ID exists in world state.
async AssetExists(ctx, id) {
return AssetUtil.AssetExists(ctx, id);
}
// GetAsset returns the asset stored in the world state with given id.
async GetAsset(ctx, id) {
return AssetUtil.GetAsset(ctx, id);
}
// GetQueryResultForQueryString executes the passed in query string.
// Result set is built and returned as a byte array containing the JSON results.
async GetQueryResultForQueryString(ctx, queryString) {
return AssetUtil.GetQueryResultForQueryString(ctx, queryString);
}
// Example: Ad hoc rich query
// QueryAssets uses a query string to perform a query for assets.
// Query string matching state database syntax is passed in and executed as is.
// Supports ad hoc queries that can be defined at runtime by the client.
// If this is not desired, follow the QueryAssetsForOwner example for parameterized queries.
// Only available on state databases that support rich query (e.g. CouchDB)
async QueryAssets(ctx, queryString) {
return await this.GetQueryResultForQueryString(ctx, queryString);
}
// Example: Pagination with Range Query
// GetAssetsByRangeWithPagination performs a range query based on the start & end key,
// page size and a bookmark.
// The number of fetched records will be equal to or lesser than the page size.
// Paginated range queries are only valid for read only transactions.
async GetAssetsByRangeWithPagination(
ctx,
startKey,
endKey,
pageSize,
bookmark
) {
return AssetUtil.GetAssetsByRangeWithPagination(
ctx,
startKey,
endKey,
pageSize,
bookmark
);
}
// Example: Pagination with Ad hoc Rich Query
// QueryAssetsWithPagination uses a query string, page size and a bookmark to perform a query
// for assets. Query string matching state database syntax is passed in and executed as is.
// The number of fetched records would be equal to or lesser than the specified page size.
// Supports ad hoc queries that can be defined at runtime by the client.
// If this is not desired, follow the QueryAssetsForOwner example for parameterized queries.
// Only available on state databases that support rich query (e.g. CouchDB)
// Paginated queries are only valid for read only transactions.
async QueryAssetsWithPagination(ctx, queryString, pageSize, bookmark) {
return AssetUtil.QueryAssetsWithPagination(
ctx,
queryString,
pageSize,
bookmark
);
}
// GetAssetHistory returns the chain of custody for an asset since issuance.
async GetAssetHistory(ctx, assetId) {
return AssetUtil.GetAssetHistory(ctx, assetId);
}
// GetAllAssets returns all assets found in the world state.
async GetAllAssets(ctx) {
return AssetUtil.GetAllAssets(ctx);
}
}
module.exports = CHAINCODE_CLASS_NAME;
{
"name": "fabric-chaincode",
"version": "1.0.0",
"description": "fabric chaincode implemented in node.js",
"main": "index.js",
"engines": {
"node": ">=12",
"npm": ">=5.3.0"
},
"scripts": {
"start": "fabric-chaincode-node start"
},
"engine-strict": true,
"license": "Apache-2.0",
"dependencies": {
"fabric-contract-api": "^2.0.0",
"fabric-shim": "^2.0.0",
"moment": "^2.29.1"
}
}
#!/bin/bash
set -x #echo on
CHAINCODE_NAME="transaction"
CHAINCODE_CLASS_NAME="TransactionChaincode"
platform='unknown'
unamestr=$(uname)
if [ "$unamestr" = 'Linux' ]; then
platform='linux'
elif [ "$unamestr" = 'FreeBSD' ]; then
platform='freebsd'
fi
if [ "$platform" = 'linux' ]; then
find ./chaincode/ -type f -exec sed -i "s/CHAINCODE-NAME/$CHAINCODE_NAME/g" {} \; &&
find ./chaincode/ -type f -exec sed -i "s/CHAINCODE_CLASS_NAME/$CHAINCODE_CLASS_NAME/g" {} \;
elif [ "$platform" = 'freebsd' ]; then
find ./chaincode/ -type f -exec sed -i '.bak' "s/CHAINCODE-NAME/$CHAINCODE_NAME/g" {} \;&&
find ./chaincode/ -type f -exec sed -i '.bak' "s/CHAINCODE_CLASS_NAME/$CHAINCODE_CLASS_NAME/g" {} \;
fi
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment