├── .eslintrc.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README-ja.md ├── README-ko.md ├── README.md ├── images ├── 1.png ├── 10.png ├── 11.png ├── 12.png ├── 13.png ├── 14.png ├── 15.png ├── 16.png ├── 17.png ├── 18.png ├── 19.png ├── 2.png ├── 20.png ├── 21.png ├── 22.png ├── 23.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png ├── 9.png ├── admin-pub.gif ├── connection.gif ├── gc.png ├── home.png ├── setup.gif └── sync-certs.gif ├── lib └── logic.js ├── models └── org.global.citizens.net.cto ├── package-lock.json ├── package.json └── permissions.acl /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | env: 2 | node: true 3 | mocha: true 4 | extends: 'eslint:recommended' 5 | parserOptions: 6 | sourceType: 7 | - script 8 | globals: 9 | getFactory: true 10 | getSerializer: true 11 | getAssetRegistry: true 12 | getParticipantRegistry: true 13 | getCurrentParticipant: true 14 | post: true 15 | emit: true 16 | rules: 17 | indent: 18 | - error 19 | - 4 20 | linebreak-style: 21 | - error 22 | - unix 23 | quotes: 24 | - error 25 | - single 26 | semi: 27 | - error 28 | - always 29 | no-unused-vars: 30 | - 0 31 | - args: none 32 | no-console: off 33 | curly: error 34 | eqeqeq: error 35 | no-throw-literal: error 36 | strict: error 37 | dot-notation: error 38 | no-tabs: error 39 | no-trailing-spaces: error 40 | no-useless-call: error 41 | no-with: error 42 | operator-linebreak: error 43 | require-jsdoc: 44 | - error 45 | - require: 46 | ClassDeclaration: true 47 | MethodDefinition: true 48 | FunctionDeclaration: true 49 | yoda: error 50 | no-confusing-arrow: 2 51 | no-constant-condition: 2 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Emacs backup files 2 | *~ 3 | *# 4 | .#* 5 | # Vim file artifacts 6 | .*.sw* 7 | # installed platform-specific binaries 8 | .DS_Store 9 | 10 | .project 11 | 12 | # Logs 13 | logs 14 | *.log 15 | npm-debug.log* 16 | 17 | # Runtime data 18 | pids 19 | *.pid 20 | *.seed 21 | 22 | # Directory for instrumented libs generated by jscoverage/JSCover 23 | lib-cov 24 | 25 | # Coverage directory used by tools like istanbul 26 | coverage 27 | 28 | # nyc test coverage 29 | .nyc_output 30 | 31 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 32 | .grunt 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (http://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules 42 | jspm_packages 43 | 44 | # Optional npm cache directory 45 | .npm 46 | 47 | # Optional REPL history 48 | .node_repl_history 49 | 50 | # JSDoc 51 | out 52 | 53 | # Mac files. 54 | **/.DS_Store 55 | 56 | *.swp 57 | 58 | # Build generated files should be ignored by git, but not by npm. 59 | dist 60 | 61 | node_modules 62 | credentials 63 | admin@global-citizens-network.card 64 | adminCard.card 65 | ca.card 66 | connection-profile.json 67 | global-citizens-network.bna 68 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | ## 1. Purpose 4 | 5 | A primary goal of Global Citizen is to be inclusive to the largest number of contributors, with the most varied and diverse backgrounds possible. As such, we are committed to providing a friendly, safe and welcoming environment for all, regardless of gender, sexual orientation, ability, ethnicity, socioeconomic status, and religion (or lack thereof). 6 | 7 | This code of conduct outlines our expectations for all those who participate in our community, as well as the consequences for unacceptable behavior. 8 | 9 | We invite all those who participate in Global Citizen to help us create safe and positive experiences for everyone. 10 | 11 | ## 2. Open Source Citizenship 12 | 13 | A supplemental goal of this Code of Conduct is to increase open source citizenship by encouraging participants to recognize and strengthen the relationships between our actions and their effects on our community. 14 | 15 | Communities mirror the societies in which they exist and positive action is essential to counteract the many forms of inequality and abuses of power that exist in society. 16 | 17 | If you see someone who is making an extra effort to ensure our community is welcoming, friendly, and encourages all participants to contribute to the fullest extent, we want to know. 18 | 19 | ## 3. Expected Behavior 20 | 21 | The following behaviors are expected and requested of all community members: 22 | 23 | * Participate in an authentic and active way. In doing so, you contribute to the health and longevity of this community. 24 | * Exercise consideration and respect in your speech and actions. 25 | * Attempt collaboration before conflict. 26 | * Refrain from demeaning, discriminatory, or harassing behavior and speech. 27 | * Be mindful of your surroundings and of your fellow participants. Alert community leaders if you notice a dangerous situation, someone in distress, or violations of this Code of Conduct, even if they seem inconsequential. 28 | * Remember that community event venues may be shared with members of the public; please be respectful to all patrons of these locations. 29 | 30 | ## 4. Unacceptable Behavior 31 | 32 | The following behaviors are considered harassment and are unacceptable within our community: 33 | 34 | * Violence, threats of violence or violent language directed against another person. 35 | * Sexist, racist, homophobic, transphobic, ableist or otherwise discriminatory jokes and language. 36 | * Posting or displaying sexually explicit or violent material. 37 | * Posting or threatening to post other people’s personally identifying information ("doxing"). 38 | * Personal insults, particularly those related to gender, sexual orientation, race, religion, or disability. 39 | * Inappropriate photography or recording. 40 | * Inappropriate physical contact. You should have someone’s consent before touching them. 41 | * Unwelcome sexual attention. This includes, sexualized comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances. 42 | * Deliberate intimidation, stalking or following (online or in person). 43 | * Advocating for, or encouraging, any of the above behavior. 44 | * Sustained disruption of community events, including talks and presentations. 45 | 46 | ## 5. Consequences of Unacceptable Behavior 47 | 48 | Unacceptable behavior from any community member, including sponsors and those with decision-making authority, will not be tolerated. 49 | 50 | Anyone asked to stop unacceptable behavior is expected to comply immediately. 51 | 52 | If a community member engages in unacceptable behavior, the community organizers may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion from the community without warning (and without refund in the case of a paid event). 53 | 54 | ## 6. Reporting Guidelines 55 | 56 | If you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. lbenn@us.ibm.com. 57 | 58 | Additionally, community organizers are available to help community members engage with local law enforcement or to otherwise help those experiencing unacceptable behavior feel safe. In the context of in-person events, organizers will also provide escorts as desired by the person experiencing distress. 59 | 60 | ## 7. Addressing Grievances 61 | 62 | If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify lbenn@us.ibm.com with a concise description of your grievance. Your grievance will be handled in accordance with our existing governing policies. 63 | 64 | ## 8. Scope 65 | 66 | We expect all community participants (contributors, paid or otherwise; sponsors; and other guests) to abide by this Code of Conduct in all community venues–online and in-person–as well as in all one-on-one communications pertaining to community business. 67 | 68 | This code of conduct and its related procedures also applies to unacceptable behavior occurring outside the scope of community activities when such behavior has the potential to adversely affect the safety and well-being of community members. 69 | 70 | ## 9. Contact info 71 | 72 | lbenn@us.ibm.com 73 | 74 | ## 10. License and attribution 75 | 76 | This Code of Conduct is distributed under a [Creative Commons Attribution-ShareAlike license](http://creativecommons.org/licenses/by-sa/3.0/). 77 | 78 | Portions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy). 79 | 80 | Retrieved on November 22, 2016 from [http://citizencodeofconduct.org/](http://citizencodeofconduct.org/) 81 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README-ja.md: -------------------------------------------------------------------------------- 1 | *Read this in other languages: [English](README.md), [한국어](README-ko.md).* 2 | 3 | # Global-citizen 4 | 5 | 6 | ここでの目標は、IBM ブロックチェーン・プラットフォームを使用して、以下の3メンバーからなるブロックチェーン・アプリケーションを構築することです。 7 | 8 | * 政府機関を代表する組織 9 | * 支援の提供に重点を置くNGOを代表する組織 10 | * Global Citizen 11 | 12 | 対象レベル:中級 開発者 13 | 14 | ## 前提条件 15 | 16 | 1. フリーの [IBM Cloud アカウント](https://www.ibm.com/cloud/) 17 | 18 | 2. [NPM](https://www.npmjs.com/) と Node (version 8.10.0) のインストール 19 | 20 | 3. 他のバージョンの composer-cli を導入済みの場合、または以前に .bna ファイルをデプロイしている場合は、以下のコマンドを実行してください 21 | ``` 22 | npm uninstall -g composer-cli 23 | npm uninstall -g composer-rest-server 24 | rm -rf ~/.composer 25 | rm *.card 26 | rm -rf credentials/ 27 | ``` 28 | 29 | 4. composer-cli のインストール 30 | ```bash 31 | npm install -g composer-cli@0.19.5 32 | ``` 33 | 34 | ## 手順 35 | 36 | 1. [Business Network Archive (BNA) の生成](#1-generate-the-business-network-archive-bna) 37 | 38 | 2. [ブロックチェーン サービスの作成](#2-create-blockchain-service) 39 | 40 | 3. [シークレットを入手](#3-get-the-secret) 41 | 42 | 4. [シークレットを使用して認証局から証明書を取得する](#4-use-secret-to-get-certificates-from-the-certificate-authority) 43 | 44 | 5. [admin-pub.pem ファイルを使用してピアに証明書を追加](#5-use-admin-pubpem-file-to-add-certificates-to-the-peers) 45 | 46 | 6. [管理者用 Business Network カードの作成](#6-create-admin-business-network-card) 47 | 48 | 7. [ランタイムをインストールし Network を開始する](#7-install-runtime-and-start-the-network) 49 | 50 | 8. [新しい Business Network カードを作成する](#8-create-a-new-business-network-card) 51 | 52 | 9. [Business Network と対話する](#9-interact-with-the-business-network) 53 | 54 | 55 | ## 1. Business Network Archive (BNA) の生成 56 | 57 | Business Network は、資産(assets)、参加者(participants)、トランザクション、アクセス制御ルール、およびオプションでイベントと参照で構成されています。 58 | この Business Network の雛形 (スケルトン) には、Business Network 内のすべての資産、参加者、およびトランザクションのクラス定義を含むモデル (**.cto**) ファイルがあります。 59 | また、Business Network の雛形には、基本的なアクセス制御ルールを含むアクセス制御 (**permissions.acl**) ドキュメント、トランザクションのプロセッサ機能を含むスクリプト (**logic.js**) ファイル、および Business Network のメタデータを含む **package.json** ファイルも含まれます。 60 | 61 | まず、BNAファイルを作成するために必要な3つのコンポーネント、ロジックファイル (**.js**)・モデルファイル (**.cto**)・アクセス制御ファイル (**.acl**) を含むリポジトリをクローンする必要があります。 62 | 63 | ```bash 64 | git clone https://github.com/IBM/global-citizen.git 65 | ``` 66 | 67 | ファイルの構造が有効であることを確認するために、Business Network 定義のための Business Network Archive (BNA) ファイルを生成できます。 68 | BNAファイルは、デプロイ可能なユニットで、実行のために Composer ランタイムにデプロイできるファイルです。 69 | Network Archive を生成するには、次のコマンドを使用します: 70 | ```bash 71 | cd global-citizen 72 | npm install 73 | ``` 74 | 75 | 次の出力が表示されます: 76 | ```bash 77 | Creating Business Network Archive 78 | 79 | 80 | Looking for package.json of Business Network Definition 81 | Input directory: /Users/ishan/Documents/proj/global-citizens/global-citizens-network/global-citizen 82 | 83 | Found: 84 | Description: This pattern should be able to Construct a 3-member blockchain application using the IBM Blockchain Platform, consisting of the following entities: an organization representing a government entity, an organization representing an NGO focused on the provision of aid, and an organization representing Global Citizen. 85 | Name: global-citizens-network 86 | Identifier: global-citizens-network@0.0.1 87 | 88 | Written Business Network Definition Archive file to 89 | Output file: global-citizens-network@0.0.1.bna 90 | 91 | Command succeeded 92 | ``` 93 | 94 | これで BNA ファイル (global-citizens-network.bna) が `global-citizens/dist` ディレクトリに作成されるはずです。 95 | 96 | 97 | ## 2. ブロックチェーン サービスの作成 98 | 99 | 1. ブラウザで [IBM Cloud アカウント](https://console.bluemix.net/dashboard/apps) にログインします 100 | 101 | 2. ブロックチェーン サービスを作成します: 102 | ![](images/setup.gif) 103 | 104 | 105 | ## 3. シークレットを入手 106 | 107 | 1. ブロックチェーンサービスを起動し、接続プロファイルをクリックし、JSON形式そのままで表示します 108 | 109 | 2. `registrar` まで下にスクロールし、`enrollId` の下に `enrollSecret` を表示します。このシークレットをコピーしておき、次のステップで、認証局(CA)用の Business Network カードを作成する際に使用します。 110 | ![](images/connection.gif) 111 | 112 | 113 | ## 4. シークレットを使用して認証局から証明書を取得する 114 | 115 | 1. 接続プロファイルをダウンロードします 116 | 117 | 2. ダウンロードした JSON ファイルを `connection-profile.json` にリネームします 118 | 119 | 3. `connection-profile.json` ファイルを `global-citizen` ディレクトリに移動します 120 | 121 | 4. 前のステップの `enrollSecret` を使用して以下のコマンドを発行し、認証局(CA)の Business Network カード (ca.card ファイル) を作成します 122 | ```bash 123 | composer card create -f ca.card -p connection-profile.json -u admin -s 124 | ``` 125 | 126 | 5. 以下のコマンドを使用してローカルシステム上の Wallet にカードをインポートします 127 | ```bash 128 | composer card import -f ca.card -c ca 129 | ``` 130 | 131 | 6. 最後に、`enrollSecret` を含むインポート済みのカードを使用して、CAから証明書を要求します。以下のコマンドの完了後に作成される `credentials` ディレクトリに、証明書が格納されます 132 | ```bash 133 | composer identity request --card ca --path ./credentials 134 | ``` 135 | 136 | 137 | ## 5. admin-pub.pem ファイルを使用してピアに証明書を追加 138 | 139 | 1. ブロックチェーン サービスに戻り、`Members` タブをクリックして証明書を追加します。`global-citizen/credentials` ディレクトリに移動し、`admin-pub.pem` ファイルの内容をコピーして `Certificate` テキスト入力欄に貼り付けます。 `Submit` ボタンをクリックして送信し、ピアを再起動します。 140 | 141 | ![](images/admin-pub.gif) 142 | >ノート: ピアを再起動するのに1分ほどかかります。 143 | 144 | 2. 次に、チャネルの証明書を同期させる必要があります。ブロックチェーンサービスから、`my network` の下にある `Channels` をクリックし、次に3点ドット(`…`)ボタンをクリックします。次に、`Sync Certificate` をクリックします。 145 | 146 | ![](images/sync-certs.gif) 147 | 148 | 149 | ## 6. 管理者用 Business Network カードの作成 150 | 151 | 1. ピアと証明書を同期させたので、Hyperledger Composer ランタイムをインストールし、管理者用カードを作成して Network を開始することができます。次のコマンドを使用して、チャネル管理者およびピア管理者の役割を持つ管理者カードを作成します: 152 | ```bash 153 | composer card create -f adminCard.card -p connection-profile.json -u admin -c ./credentials/admin-pub.pem -k ./credentials/admin-priv.pem --role PeerAdmin --role ChannelAdmin 154 | ``` 155 | 156 | 2. 前のコマンドで作成したカードをインポートします: 157 | ```bash 158 | composer card import -f adminCard.card -c adminCard 159 | ``` 160 | 161 | 162 | ## 7. ランタイムをインストールし Network を開始する 163 | 164 | 1. 管理者用カードを使用して、次のコマンドで Network をインストールします: 165 | ```bash 166 | composer network install --card adminCard --archiveFile global-citizens-network@0.0.1.bna 167 | ``` 168 | >ノート: この時点でエラーが発生した場合は、1分待ってからもう一度試してください。 169 | 170 | 2. 管理者用カード、.bnaファイルのパス、CAから受信した資格情報を入力して、Business Network を開始します。 このコマンドは削除すべきカードを発行します。これは ‘delete_me.card’ と呼ばれます。 171 | ```bash 172 | composer network start --networkName global-citizens-network --networkVersion 0.0.1 -c adminCard -A admin -C ./credentials/admin-pub.pem -f delete_me.card 173 | ``` 174 | >ノート: この時点でエラーが発生した場合は、1分待ってからもう一度試してください。 175 | 176 | 3. 次に、‘delete_me.card’ を削除しましょう: 177 | ```bash 178 | rm delete_me.card 179 | ``` 180 | 181 | 182 | ## 8. 新しい Business Network カードを作成する 183 | 184 | 1. ランタイムをインストールして Network を開始したら、Starter プランにデプロイするカードを作成する必要があります。次のコマンドを使用して `adminCard.card` を作成してください: 185 | ```bash 186 | composer card create -n global-citizens-network -p connection-profile.json -u admin -c ./credentials/admin-pub.pem -k ./credentials/admin-priv.pem 187 | ``` 188 | 189 | 2. Business Network カードをインポートします: 190 | ```bash 191 | composer card import -f admin@global-citizens-network.card 192 | ``` 193 | 194 | 3. Business Network カードをテストします: 195 | ```bash 196 | composer network ping -c admin@global-citizens-network 197 | ``` 198 | 199 | 200 | ## 9. Business Network と対話する 201 | 202 | Composer-Playground または Composer-Rest-Server を使用して、Business Network と対話することができます。 203 | 204 | より詳しい情報は [composer-playground](https://hyperledger.github.io/composer/latest/introduction/introduction) や [composer-rest-server](https://hyperledger.github.io/composer/latest/integrating/getting-started-rest-api) を参照してください。 205 | 206 | 207 | ### a. Composer-Playground を使って対話する 208 | 209 | 1. Composer-Playground をインストールする: 210 | ```bash 211 | npm install -g composer-playground@0.19.5 212 | ``` 213 | 2. さあ、サーバーを起動しましょう。`connection-profile.json` ファイルのあるディレクトリで、以下を実行します: 214 | ```bash 215 | composer-playground 216 | ``` 217 | 3. ブラウザで [http://localhost:8080/test](http://localhost:8080/test) を開き、Business Network を操作します。 218 | 219 | global-citizen Business Network のための `Admin card` が、Composer Playground に作成されます。 220 | 221 | ![](images/home.png) 222 | 223 | `admin@global-citizens-network` カードの `Connect now` ボタンをクリックして、global-citizen Business Network に接続してください 224 | 225 | ![](images/5.png) 226 | 227 | Business Network の定義をテストするには、まず **Test** タブをクリックします。 228 | 229 | `AidOrg` 参加者レジストリで、新しい参加者を作成します。 左にあるメニューの最初にある `AidOrg` をクリックし、`Create New Participant` ボタンをクリックしてください。 230 | 231 | ![](images/6.png) 232 | 233 | `AidOrg` 参加者の情報を入力し、`Create New` をクリックします。 234 | 235 | ![](images/7.png) 236 | 237 | 新しい `AidOrg` 参加者が、参加者レジストリに作成されました。同様に、ネットワークの他の参加者を作成します。 238 | 239 | ![](images/8.png) 240 | 241 | 接続プロファイルには、Fabric に接続するために必要な情報が含まれています。Business Network カードは、接続プロファイル、ID、証明書を組み合わせて、Hyperledger Composer Playground 内の Business Network に接続できるようにします。 242 | 243 | これでネットワークの参加者のために **Network カード** を追加する準備が整いました。これを行うには、最初に `admin` タブをクリックし、`ID Registry` を選択して **新しい ID** を参加者に発行し、IDをウォレットに追加します。下のイメージに示された手順に従ってください: 244 | 245 | ![](images/9.png) 246 | 247 | ![](images/10.png) 248 | 249 | ![](images/11.png) 250 | 251 | ![](images/12.png) 252 | 253 | Network のトランザクションを実行するため、`AidOrg` 参加者レジストリを選択して `Use Now` をクリックします。 254 | 255 | ![](images/13.png) 256 | 257 | `CreateProjectPledge` トランザクションを実行します。 258 | ``` 259 | { 260 | "$class": "org.global.citizens.net.CreateProjectPledge", 261 | "pledgeId": "p1", 262 | "name": "child care", 263 | "decription": "child care fund", 264 | "fundsRequired": 100000, 265 | "aidOrg": "resource:org.global.citizens.net.AidOrg#aid" 266 | } 267 | ``` 268 | ![](images/14.png) 269 | 270 | 資産の登録簿に新しいプロジェクト Pledge (寄付の提案書) が作成されます。 271 | ![](images/15.png) 272 | 273 | `SendPledgeToGlobalCitizen` トランザクションを実行し、作成した Pledge を Global Citizen に送信することで、プロジェクトへの資金を得ます。 274 | ``` 275 | { 276 | "$class": "org.global.citizens.net.SendPledgeToGlobalCitizen", 277 | "citizenId": "resource:org.global.citizens.net.GlobalCitizen#gc", 278 | "pledgeId": "resource:org.global.citizens.net.ProjectPledge#p1" 279 | } 280 | ``` 281 | ![](images/16.png) 282 | 283 | Global Citizen 参加者の登録簿は、新たな Pledge の要求で更新されます。 284 | ![](images/17.png) 285 | 286 | Global Citizen が Pledge をレビューします。検証して問題がなければ、政府機関から Pledge のための資金を得るために、`SendPledgeToGovOrg` トランザクションを実行します。 287 | ``` 288 | { 289 | "$class": "org.global.citizens.net.SendPledgeToGovOrg", 290 | "govOrg": ["resource:org.global.citizens.net.GovOrg#gov"], 291 | "pledgeId": "resource:org.global.citizens.net.ProjectPledge#p1" 292 | } 293 | ``` 294 | ![](images/18.png) 295 | 296 | 政府機関が Pledge をレビューします。彼らがプロジェクトに資金を提供するかどうかを検討した後、彼らはプロジェクトの Pledge 資産を更新するために `UpdatePledge` トランザクションを実行します。 297 | ``` 298 | { 299 | "$class": "org.global.citizens.net.UpdatePledge", 300 | "govOrgId": "resource:org.global.citizens.net.GovOrg#gov", 301 | "pledgeId": "resource:org.global.citizens.net.ProjectPledge#p1", 302 | "fundingType": "WEEKLY", 303 | "approvedFunding": 100000, 304 | "fundsPerInstallment": 1000 305 | } 306 | ``` 307 | ![](images/19.png) 308 | 309 | ![](images/20.png) 310 | 311 | ![](images/21.png) 312 | 313 | 政府機関は定期的に `TransferFunds` トランザクションを実行してプロジェクトに資金を送ります。 314 | ``` 315 | { 316 | "$class": "org.global.citizens.net.TransferFunds", 317 | "govOrgId": "resource:org.global.citizens.net.GovOrg#gov", 318 | "pledgeId": "resource:org.global.citizens.net.ProjectPledge#p1" 319 | } 320 | ``` 321 | ![](images/22.png) 322 | 323 | ![](images/23.png) 324 | 325 | ### b. composer-rest-server を使って対話する 326 | 327 | 1. composer-rest-server をインストールする: 328 | ```bash 329 | npm install -g composer-rest-server@0.19.5 330 | ``` 331 | 332 | 2. さあ、サーバーを起動しましょう。`connection-profile.json` ファイルのあるディレクトリで、以下を実行します: 333 | ```bash 334 | composer-rest-server -c admin@global-citizens-network -n never -w true 335 | ``` 336 | 337 | 3. ブラウザで [http://localhost:3000/explorer](http://localhost:3000/explorer) をアクセスします 338 | 339 | 4. これで swagger API が利用可能になり、[Composer-Playground を使って対話する](#a-interact-using-composer-playground) セクションで示された内容を Business Network に対して実行できます。 340 | 341 | ## パターンの拡張 342 | 343 | 1. ネットワーク権限を追加する 344 | 2. ダッシュボードの実装 345 | 3. 支払いのデフォルトを追跡するロジックを実装する 346 | 4. 通知ロジックの実装 347 | 5. ファンドの移転ロジックを改善する 348 | 349 | ## その他のリソース 350 | * [Hyperledger Fabric ドキュメント](http://hyperledger-fabric.readthedocs.io/en/latest/) 351 | * [Hyperledger Composer ドキュメント](https://hyperledger.github.io/composer/latest/introduction/introduction.html) 352 | 353 | ## ライセンス 354 | [Apache 2.0](LICENSE) 355 | -------------------------------------------------------------------------------- /README-ko.md: -------------------------------------------------------------------------------- 1 | *Read this in other languages: [English](README.md), [日本語](README-ja.md).* 2 | 3 | # Global-citizen 4 | 5 | 이 코드 패턴의 목표는 다음의 3개의 단체로 - 정부 기관을 대표하는 조직, 구호 제공을 목적으로 하는 NGO를 대표하는 조직, 그리고 Global Citizen을 대표하는 조직 - 구성된 블록체인 애플리케이션을 IBM Blockchain 플랫폼을 사용하여 빌드하는 것입니다. 6 | 7 | 튜토리얼 레벨 : 중급 개발자 8 | 9 | ## 준비 사항 10 | 11 | 1. 무료 [IBM Cloud 계정](https://www.ibm.com/cloud/) 12 | 13 | 2. [NPM](https://www.npmjs.com/) 및 Node 설치 (노드 버전 8.10.0) 14 | 15 | 3. 다른 버전의 composer-cli를 사용하거나, .bna 파일을 배포해 본 적이 있는 경우에는 다음 명령어를 실행합니다 16 | ``` 17 | npm uninstall -g composer-cli 18 | npm uninstall -g composer-rest-server 19 | rm -rf ~/.composer 20 | rm *.card 21 | rm -rf credentials/ 22 | ``` 23 | 24 | 4. composer-cli 설치 25 | ```bash 26 | npm install -g composer-cli@0.19.5 27 | ``` 28 | 29 | ## 단계 30 | 1. [비즈니스 네트워크 아카이브 (BNA) 생성하기](#1-비즈니스-네트워크-아카이브-bna-생성하기) 31 | 32 | 2. [블록체인 서비스 생성하기](#2-블록체인-서비스-생성하기) 33 | 34 | 3. [암호 얻기](#3-암호-얻기) 35 | 36 | 4. [암호를 사용하여 인증 기관에서 인증서 가져오기](#4-암호를-사용하여-인증-기관에서-인증서-가져오기) 37 | 38 | 5. [admin-pub.pem 파일을 사용하여 피어에 인증서 추가하기](#5-admin-pubpem-파일을-사용하여-피어에-인증서-추가하기) 39 | 40 | 6. [어드민 비즈니스 네트워크 카드 만들기](#6-어드민-비즈니스-네트워크-카드-만들기) 41 | 42 | 7. [런타임 설치하고 네트워크 시작하기](#7-런타임-설치하고-네트워크-시작하기) 43 | 44 | 8. [새로운 비즈니스 네트워크 카드 생성하기](#8-비즈니스-네트워크-카드-생성하기) 45 | 46 | 9. [비즈니스 네트워크와 상호작용 하기](#9-비즈니스-네트워크와-상호작용-하기) 47 | 48 | ## 1. 비즈니스 네트워크 아카이브 (BNA) 생성하기 49 | 50 | 비즈니스 네트워크는 자산, 참가자, 트랜잭션, 엑세스 제어 규칙과 선택적으로 이벤트 및 쿼리로 구성됩니다. 이 스켈레톤 비즈니스 네트워크에는 비즈니스 네트워크의 모든 자산, 참가자, 및 트랜잭션에 대한 클래스 정의를 담고 있는 모델 (**.cto**) 파일이 있습니다. 스켈레톤 비즈니스 네트워크에는 또한 기본 엑세스 제어 규칙이 있는 엑세스 제어 (**permissions.acl**) 문서, 트랜잭션 프로세서 기능이 포함된 (**logic.js**) 스크립트 파일 그리고 비즈니스 네트워크 메타데이터를 담고 있는 **package.json** 파일도 포함되어 있습니다. 51 | 52 | 우선 BNA 파일을 만드는데 필요한 세 가지 구성요소인 로직 파일(**.js**), 모델 파일(**.cto**), 그리고 엑세스 제어 파일(**.acl**)이 포함된 저장소를 복제해야 합니다. 53 | ```bash 54 | git clone https://github.com/IBM/global-citizen.git 55 | ``` 56 | 57 | 파일의 구조가 유효한지 확인하기 위해 이제는 비즈니스 네트워크 정의에 대한 BNA (Business Network Archive) 파일을 생성합니다. 이 BNA 파일은 배포 가능한 유닛으로 실행을 위해 Composer 런타임에 배포할 수 있는 파일입니다. 58 | 다음 명령어를 사용하여 네트워크 아카이브를 생성하십시오: 59 | ```bash 60 | cd global-citizen 61 | npm install 62 | ``` 63 | 64 | 그러면 다음의 결과를 확인하실 수 있습니다: 65 | ```bash 66 | Creating Business Network Archive 67 | 68 | 69 | Looking for package.json of Business Network Definition 70 | Input directory: /Users/ishan/Documents/proj/global-citizens/global-citizens-network/global-citizen 71 | 72 | Found: 73 | Description: This pattern should be able to Construct a 3-member blockchain application using the IBM Blockchain Platform, consisting of the following entities: an organization representing a government entity, an organization representing an NGO focused on the provision of aid, and an organization representing Global Citizen. 74 | Name: global-citizens-network 75 | Identifier: global-citizens-network@0.0.1 76 | 77 | Written Business Network Definition Archive file to 78 | Output file: global-citizens-network@0.0.1.bna 79 | 80 | Command succeeded 81 | ``` 82 | 83 | 이제 `global-citizens/dist` 디렉토리 안에 BNA 파일 (global-citizens-network.bna)이 있어야 합니다. 84 | 85 | ## 2. 블록체인 서비스 생성하기 86 | 87 | 1. 브라우저에서 이제 막 만들어 반짝반짝한 새 [IBM Cloud 계정](https://console.bluemix.net/dashboard/apps)으로 이동하십시오 88 | 89 | 2. 블록체인 서비스를 생성합니다: 90 | ![](images/setup.gif) 91 | 92 | ## 3. 암호 얻기 93 | 94 | 1. 블록체인 서비스를 실행하고, 연결 프로파일을 클릭하여 JSON으로 봅니다 95 | 96 | 2. `registrar`가 보일 때까지 스크롤 다운한 다음 `enrollId` 아래에 `enrollSecret`이 있습니다. 이 암호를 복사하세요. 다음 단계에서 인증 기관(CA)용 비즈니스 네트워크 카드를 생성할 때 사용해야 합니다. 97 | ![](images/connection.gif) 98 | 99 | ## 4. 암호를 사용하여 인증 기관에서 인증서 가져오기 100 | 101 | 1. 연결 프로파일을 다운로드합니다 102 | 103 | 2. 다운로드한 JSON 파일의 이름을 `connection-profile.json`로 변경합니다 104 | 105 | 3. `connection-profile.json` 파일을 `global-citizen` 디렉토리로 이동합니다 106 | 107 | 4. 이전 단계에서 확인한 `enrollSecret` 암호로 다음의 명령어가 인증기관(CA)용 비즈니스 네트워크 카드를 생성합니다 108 | ```bash 109 | composer card create -f ca.card -p connection-profile.json -u admin -s 110 | ``` 111 | 112 | 5. 다음의 명령어로 로컬 시스템 월렛에서 카드를 가져옵니다 113 | ```bash 114 | composer card import -f ca.card -c ca 115 | ``` 116 | 117 | 6. 마지막으로 `enrollSecret`이 포함된 가져온 카드를 사용하여 인증기관으로부터 인증서를 요청합니다. 인증서는 다음의 명령어를 완료한 후 생성되는 신임정보 디렉토리에 저장됩니다. 118 | ```bash 119 | composer identity request --card ca --path ./credentials 120 | ``` 121 | 122 | ## 5. admin-pub.pem 파일을 사용하여 피어에 인증서 추가하기 123 | 124 | 1. 다시 블록체인 서비스로 돌아와서 Members 탭을 클릭하여 인증서를 추가합니다. `global-citizen/credentials` 디렉토리로 가서 `admin-pub.pem`의 내용을 복사하여 인증서 박스에 붙여 넣습니다. 인증서를 제출하고 피어를 다시 시작합니다. 125 | ![](images/admin-pub.gif) 126 | >주의: 피어를 다시 시작하는 데에는 1분 정도 소요됩니다. 127 | 128 | 2. 다음으로 채널의 인정서를 동기화해야 합니다. 블록체인 서비스에서 `my network` 밑에 있는 `Channels`를 클릭한 다음 3개의 점이 있는 버튼을 클릭합니다. 그런 다음 `Sync Certificate`을 클릭합니다. 129 | ![](images/sync-certs.gif) 130 | 131 | ## 6. 어드민 비즈니스 네트워크 카드 만들기 132 | 133 | 1. 이제 피어와 인증서를 동기화했으므로 어드민 카드를 생성하여 Hyperledger Composer 런타임을 설치하고 네트워크를 시작할 수 있습니다. 다음의 명령어를 사용하여 채널 관리자 및 피어 관리 역할을 가진 어드민 카드를 생성합니다: 134 | ```bash 135 | composer card create -f adminCard.card -p connection-profile.json -u admin -c ./credentials/admin-pub.pem -k ./credentials/admin-priv.pem --role PeerAdmin --role ChannelAdmin 136 | ``` 137 | 138 | 2. 이전 명령에서 생성된 카드 가져오기: 139 | ```bash 140 | composer card import -f adminCard.card -c adminCard 141 | ``` 142 | 143 | ## 7. 런타임 설치하고 네트워크 시작하기 144 | 145 | 146 | 1. 이제 다음의 명령어로 어드민 카드를 사용하여 네트워크를 설치합니다: 147 | ```bash 148 | composer network install --card adminCard --archiveFile global-citizens-network@0.0.1.bna 149 | ``` 150 | >주의: 이 시점에서 오류가 발생하면 잠시 기다렸다가 다시 시도해 보십시오. 151 | 152 | 2. 어드민 카드, .bna 파일 경로 및 인증기관으로부터 받은 신임정보를 제공하여 비즈니스 네트워크를 시작하십시오. 이 명령어는 ‘delete_me.card’라 불리는 카드를 발행합니다. 153 | ```bash 154 | composer network start --networkName global-citizens-network --networkVersion 0.0.1 -c adminCard -A admin -C ./credentials/admin-pub.pem -f delete_me.card 155 | ``` 156 | >주의: 이 시점에서 오류가 발생하면 잠시 기다렸다가 다시 시도해 보십시오. 157 | 158 | 3. 다음으로는 delete_me.card 를 삭제해 봅시다: 159 | ```bash 160 | rm delete_me.card 161 | ``` 162 | 163 | ## 8. 비즈니스 네트워크 카드 생성하기 164 | 165 | 1. 런타임을 설치하고 네트워크를 시작한 후에는 무료 계정(Starter Plan)에 배포할 카드를 만들어야 합니다. 다음 명령어를 사용하여 `adminCard.card`를 생성합니다: 166 | ```bash 167 | composer card create -n global-citizens-network -p connection-profile.json -u admin -c ./credentials/admin-pub.pem -k ./credentials/admin-priv.pem 168 | ``` 169 | 170 | 2. 비즈니스 네트워크 카드를 가져옵니다: 171 | ```bash 172 | composer card import -f admin@global-citizens-network.card 173 | ``` 174 | 175 | 3. 비즈니스 네트워크 카드를 테스트합니다: 176 | ```bash 177 | composer network ping -c admin@global-citizens-network 178 | ``` 179 | 180 | ## 9. 비즈니스 네트워크와 상호작용 하기 181 | 182 | composer-playground 또는 composer-rest-server를 사용하여 비즈니스 네트워크와 상호 작용할 수 있습니다. 183 | 184 | 여기 링크를 클릭하여 [composer-playground](https://hyperledger.github.io/composer/latest/introduction/introduction)와 [composer-rest-server](https://hyperledger.github.io/composer/latest/integrating/getting-started-rest-api)에 대해 자세한 정보를 얻으십시오. 185 | 186 | ### a. Composer-Playground를 사용하여 상호작용 하기 187 | 188 | 1. Composer-Playground를 설치합니다: 189 | ```bash 190 | npm install -g composer-playground@0.19.5 191 | ``` 192 | 2. 이제 서버를 시작합니다. `connection-profile.json`과 같은 디렉토리에 있는지 확인하십시오. 193 | ```bash 194 | composer-playground 195 | ``` 196 | 3. 브라우저에서 [http://localhost:8080/test](http://localhost:8080/test) 로 이동하여 비즈니스 네트워크에서 작업을 수행하십시오. 197 | 198 | global-citizen 비즈니스 네트워크용 `Admin card`는Composer Playground에 생성됩니다. 199 | 200 | ![](images/home.png) 201 | 202 | `admin@global-citizens-network` 카드에 있는 `Connect now` 버튼을 클릭하여 global-citizen 비즈니스 네트워크에 연결합니다. 203 | 204 | ![](images/5.png) 205 | 206 | 비즈니스 네트워크 정의를 테스트하려면 먼저 **Test** 탭을 클릭합니다: 207 | 208 | `AidOrg` 참가자 레지스트리에서 새 참가자를 만듭니다. 왼쪽에 위치한 `AidOrg` 탭을 클릭하고 `Create New Participant` 버튼을 클릭하십시오. 209 | ![](images/6.png) 210 | 211 | `AidOrg` 참가자의 세부 정보를 입력하고 `Create New`를 클릭합니다 212 | ![](images/7.png) 213 | 214 | 참가자 레지스트리에 새로운 `AidOrg` 참가자가 생성되었습니다. 네트워크의 다른 참가자도 마찬가지로 생성합니다. 215 | ![](images/8.png) 216 | 217 | 218 | 연결 프로파일에는 패브릭에 연결하는데 필요한 정보가 들어있습니다. 비즈니스 네트워크 카드는 연결 프로필, ID 및 인증서를 결합하여 Hyperledger Composer Playground에 있는 비즈니스 네트워크에 연결할 수 있도록 합니다. 219 | 220 | 이제 네트워크 상의 참가자들에게 **Network Cards**를 추가할 준비가 완료되었습니다. 먼저 `admin`탭을 클릭한 후 `ID Registry`를 선택하여 **new ids**를 발행하고 ID를 월렛에 추가합니다. 221 | 아래 이미지에 있는 가이드를 따라 진행하세요: 222 | ![](images/9.png) 223 | 224 | ![](images/10.png) 225 | 226 | ![](images/11.png) 227 | 228 | ![](images/12.png) 229 | 230 | `Use Now`를 클릭하여 네트워크에서 트랜잭션을 수행할 `AidOrg` 참여자 레지스트리를 선택합니다. 231 | ![](images/13.png) 232 | 233 | `CreateProjectPledge` 트랜잭션을 제출합니다. 234 | ``` 235 | { 236 | "$class": "org.global.citizens.net.CreateProjectPledge", 237 | "pledgeId": "p1", 238 | "name": "child care", 239 | "decription": "child care fund", 240 | "fundsRequired": 100000, 241 | "aidOrg": "resource:org.global.citizens.net.AidOrg#aid" 242 | } 243 | ``` 244 | ![](images/14.png) 245 | 246 | Asset 레지스트리에 새로운 프로젝트 서약서가 생성되었습니다. 247 | ![](images/15.png) 248 | 249 | Global Citizen에 프로젝트 자금을 받기 위한 서약서를 전송하기 위한 `SendPledgeToGlobalCitizen` 트랜젝션을 제출합니다. 250 | ``` 251 | { 252 | "$class": "org.global.citizens.net.SendPledgeToGlobalCitizen", 253 | "citizenId": "resource:org.global.citizens.net.GlobalCitizen#gc", 254 | "pledgeId": "resource:org.global.citizens.net.ProjectPledge#p1" 255 | } 256 | ``` 257 | ![](images/16.png) 258 | 259 | Global Citizen 참가자 레지스트리는 새로운 서약서로 업데이트됩니다. 260 | ![](images/17.png) 261 | 262 | Global Citizen에서 서약서를 검토합니다. 검증에 성공하면 프로젝트 서약서에 따른 정부 기관의 자금을 받기 위한 `SendPledgeToGovOrg` 트랜잭션이 제출됩니다. 263 | ``` 264 | { 265 | "$class": "org.global.citizens.net.SendPledgeToGovOrg", 266 | "govOrg": ["resource:org.global.citizens.net.GovOrg#gov"], 267 | "pledgeId": "resource:org.global.citizens.net.ProjectPledge#p1" 268 | } 269 | ``` 270 | ![](images/18.png) 271 | 272 | 정부 기관에서 서약서를 검토합니다. 기관에서 프로젝트에 자금을 제공하기로 결정했는지 검토한 후, `UpdatePledge` 트랜잭션을 제출하여 프로젝트 서약서 자산을 업데이트합니다. 273 | ``` 274 | { 275 | "$class": "org.global.citizens.net.UpdatePledge", 276 | "govOrgId": "resource:org.global.citizens.net.GovOrg#gov", 277 | "pledgeId": "resource:org.global.citizens.net.ProjectPledge#p1", 278 | "fundingType": "WEEKLY", 279 | "approvedFunding": 100000, 280 | "fundsPerInstallment": 1000 281 | } 282 | ``` 283 | ![](images/19.png) 284 | 285 | ![](images/20.png) 286 | 287 | ![](images/21.png) 288 | 289 | 정부 기관은 정기적으로 `TransferFunds` 트랜잭션을 제출하여 프로젝트에 자금을 송금합니다. 290 | ``` 291 | { 292 | "$class": "org.global.citizens.net.TransferFunds", 293 | "govOrgId": "resource:org.global.citizens.net.GovOrg#gov", 294 | "pledgeId": "resource:org.global.citizens.net.ProjectPledge#p1" 295 | } 296 | ``` 297 | ![](images/22.png) 298 | 299 | ![](images/23.png) 300 | 301 | ### b. composer-rest-server를 사용하여 상호작용 하기 302 | 303 | 1. composer-rest-server를 설치합니다: 304 | ```bash 305 | npm install -g composer-rest-server@0.19.5 306 | ``` 307 | 308 | 2. 이제 서버를 시작합니다. `connection-profile.json`와 같은 디렉토리에 있는지 확인합니다. 309 | ```bash 310 | composer-rest-server -c admin@global-citizens-network -n never -w true 311 | ``` 312 | 313 | 3. 브라우저에서 [http://localhost:3000/explorer](http://localhost:3000/explorer)로 이동합니다. 314 | 315 | 4. [Composer-Playground를 사용하여 상호작용 하기](#a-interact-using-composer-playground)에서 다뤘듯이 Swagger API를 사용하여 비즈니스 네트워크에서 운영할 수 있습니다. 316 | 317 | ## 코드 패턴 확장하기 318 | 319 | 1. 네트워크 권한을 추가합니다 320 | 2. 대시보드를 구현합니다 321 | 3. 결제 default를 추적하기 위한 로직을 구현합니다 322 | 4. Notification 로직을 구현합니다 323 | 5. 자금 이체 로직을 개선합니다 324 | 325 | ## 추가 리소스 326 | * [Hyperledger Fabric Docs](http://hyperledger-fabric.readthedocs.io/en/latest/) 327 | * [Hyperledger Composer Docs](https://hyperledger.github.io/composer/latest/introduction/introduction.html) 328 | 329 | ## 라이센스 330 | [Apache 2.0](LICENSE) 331 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | *Read this in other languages: [한국어](README-ko.md), [日本語](README-ja.md).* 2 | 3 | # WARNING: This repository is no longer maintained :warning: 4 | 5 | > This repository, which contains assets to run a Hyperledger Composer application, 6 | is not being actively maintained due to a shift to focus on Hyperledger Fabric. 7 | This repository will not be updated. The repository will be kept available 8 | in read-only mode. 9 | 10 | # Global-citizen 11 | 12 | The goal here is to build a 3-member blockchain application using the IBM Blockchain Platform, consisting of the following entities: an organization representing a government entity, an organization representing an NGO focused on the provision of aid, and an organization representing Global Citizen. 13 | 14 | Audience level : Intermediate Developers 15 | 16 | ## Prerequisites 17 | 18 | 1. Free [IBM Cloud account](https://www.ibm.com/cloud/) 19 | 20 | 2. [NPM](https://www.npmjs.com/) and Node installed (node version 8.10.0) 21 | 22 | 3. If you have used other versions of composer-cli, or have deployed a .bna file before, run these commands 23 | ``` 24 | npm uninstall -g composer-cli 25 | npm uninstall -g composer-rest-server 26 | rm -rf ~/.composer 27 | rm *.card 28 | rm -rf credentials/ 29 | ``` 30 | 31 | 4. Install composer-cli 32 | ```bash 33 | npm install -g composer-cli@0.20 34 | ``` 35 | 36 | ## Steps 37 | 1. [Generate the Business Network Archive (BNA)](#1-generate-the-business-network-archive-bna) 38 | 39 | 2. [Create Blockchain Service](#2-create-blockchain-service) 40 | 41 | 3. [Get the secret](#3-get-the-secret) 42 | 43 | 4. [Use secret to get certificates from the certificate authority](#4-use-secret-to-get-certificates-from-the-certificate-authority) 44 | 45 | 5. [Use admin-pub.pem file to add certificates to the peers](#5-use-admin-pubpem-file-to-add-certificates-to-the-peers) 46 | 47 | 6. [Create admin business network card](#6-create-admin-business-network-card) 48 | 49 | 7. [Install runtime and start the network](#7-install-runtime-and-start-the-network) 50 | 51 | 8. [Create a new business network card](#8-create-a-new-business-network-card) 52 | 53 | 9. [Interact with the business network](#9-interact-with-the-business-network) 54 | 55 | ## 1. Generate the Business Network Archive (BNA) 56 | 57 | A business network is made up of assets, participants, transactions, access control rules, and optionally events and queries. In this skeleton business network, there is a model (**.cto**) file which will contain the class definitions for all assets, participants, and transactions in the business network. The skeleton business network also contains an access control (**permissions.acl**) document with basic access control rules, a script (**logic.js**) file containing transaction processor functions, and a **package.json** file containing business network metadata. 58 | 59 | First we need to clone a repo that contains the three components that are needed to make a BNA file: a logic file(**.js**) , a model file(**.cto**), and an access control(**.acl**) file. 60 | ```bash 61 | git clone https://github.com/IBM/global-citizen.git 62 | ``` 63 | 64 | To check that the structure of the files is valid, you can now generate a Business Network Archive (BNA) file for your business network definition. The BNA file is the deployable unit -- a file that can be deployed to the Composer runtime for execution. 65 | Use the following command to generate the network archive: 66 | ```bash 67 | cd global-citizen 68 | npm install 69 | ``` 70 | 71 | You should see the following output: 72 | ```bash 73 | Creating Business Network Archive 74 | 75 | 76 | Looking for package.json of Business Network Definition 77 | Input directory: /Users/ishan/Documents/proj/global-citizens/global-citizens-network/global-citizen 78 | 79 | Found: 80 | Description: This pattern should be able to Construct a 3-member blockchain application using the IBM Blockchain Platform, consisting of the following entities: an organization representing a government entity, an organization representing an NGO focused on the provision of aid, and an organization representing Global Citizen. 81 | Name: global-citizens-network 82 | Identifier: global-citizens-network@0.0.1 83 | 84 | Written Business Network Definition Archive file to 85 | Output file: global-citizens-network@0.0.1.bna 86 | 87 | Command succeeded 88 | ``` 89 | 90 | Now you should have a BNA file, (global-citizens-network.bna), that is in your `global-citizens/dist` directory. 91 | 92 | ## 2. Create Blockchain Service 93 | 94 | 1. In your browser go to your shiny new [IBM Cloud account](https://console.bluemix.net/dashboard/apps) 95 | 96 | 2. Create a blockchain service: 97 | ![](images/setup.gif) 98 | 99 | ## 3. Get the secret 100 | 101 | 1. Launch your blockchain service, and click on connection profile, and view as raw JSON 102 | 103 | 2. Scroll all the way down until you see `registrar` and then under `enrollId` will be `enrollSecret`. Copy this secret, we will need it for the next step for creating the a business network card for the certificate authority (CA) 104 | ![](images/connection.gif) 105 | 106 | ## 4. Use secret to get certificates from the certificate authority 107 | 108 | 1. Download the connection profile 109 | 110 | 2. Rename the downloaded JSON file to `connection-profile.json` 111 | 112 | 3. Move the `connection-profile.json` file to the `global-citizen` directory 113 | 114 | 4. Using the `enrollSecret` from the previous step issue this command to create a business network card for the certificate authority (CA) 115 | ```bash 116 | composer card create -f ca.card -p connection-profile.json -u admin -s 117 | ``` 118 | 119 | 5. Import the card in your local system wallet with this command 120 | ```bash 121 | composer card import -f ca.card -c ca 122 | ``` 123 | 124 | 6. Finally, we request certificates from the CA using the card we imported that contains our `enrollSecret`. The certificates are stored in the credentials directory that is created after the completion of this command. 125 | ```bash 126 | composer identity request --card ca --path ./credentials 127 | ``` 128 | 129 | ## 5. Use admin-pub.pem file to add certificates to the peers 130 | 131 | 1. Back in the blockchain service, click on the members tab, then add certificate. Go to your `global-citizen/credentials` directory, and copy and paste the contents of the `admin-pub.pem` file in the certificate box. Submit the certificate and restart the peers. 132 | ![](images/admin-pub.gif) 133 | >Note: restarting the peers takes a minute. 134 | 135 | 2. Next, we need to synchronize the certificates of the channel. From our blockchain service, under `my network` click on `Channels` and then the three-dot button. Then click `Sync Certificate`. 136 | ![](images/sync-certs.gif) 137 | 138 | ## 6. Create admin business network card 139 | 140 | 1. Now that we have synced certificates with our peers, we can install the Hyperledger Composer runtime and start the network by creating an admin card. Create the admin card with the channel admin and peer admin roles with the following command: 141 | ```bash 142 | composer card create -f adminCard.card -p connection-profile.json -u admin -c ./credentials/admin-pub.pem -k ./credentials/admin-priv.pem --role PeerAdmin --role ChannelAdmin 143 | ``` 144 | 145 | 2. Import the card created from the previous command: 146 | ```bash 147 | composer card import -f adminCard.card -c adminCard 148 | ``` 149 | 150 | ## 7. Install runtime and start the network 151 | 152 | 153 | 1. Now we will use the admin card to install the network with the following command: 154 | ```bash 155 | composer network install --card adminCard --archiveFile global-citizens-network@0.0.1.bna 156 | ``` 157 | >Note: If you get an error at this point, wait a minute and try again. 158 | 159 | 2. Start the business network by providing the admin card, the path to the .bna file, and the credentials received from the CA. This command will issue a card which we will remove, called ‘delete_me.card’. 160 | ```bash 161 | composer network start --networkName global-citizens-network --networkVersion 0.0.1 -c adminCard -A admin -C ./credentials/admin-pub.pem -f delete_me.card 162 | ``` 163 | >Note: If you get an error at this point, wait a minute and try again. 164 | 165 | 3. Next, let’s delete delete_me.card : 166 | ```bash 167 | rm delete_me.card 168 | ``` 169 | 170 | ## 8. Create a new business network card 171 | 172 | 1. After we have installed the runtime and started the network, we need to create a card which we will deploy to the Starter Plan. Use the following command to create `adminCard.card`: 173 | ```bash 174 | composer card create -n global-citizens-network -p connection-profile.json -u admin -c ./credentials/admin-pub.pem -k ./credentials/admin-priv.pem 175 | ``` 176 | 177 | 2. Import the business network card: 178 | ```bash 179 | composer card import -f admin@global-citizens-network.card 180 | ``` 181 | 182 | 3. Test the business network card: 183 | ```bash 184 | composer network ping -c admin@global-citizens-network 185 | ``` 186 | 187 | ## 9. Interact with the business network 188 | 189 | You can either use composer-playground or composer-rest-server to interact with the business network. 190 | 191 | Use the links to get more information about [composer-playground](https://hyperledger.github.io/composer/latest/introduction/introduction) and [composer-rest-server](https://hyperledger.github.io/composer/latest/integrating/getting-started-rest-api). 192 | 193 | ### a. Interact using Composer-Playground 194 | 195 | 1. Install Composer-Playground: 196 | ```bash 197 | npm install -g composer-playground@0.20 198 | ``` 199 | 2. Now, let’s start up the server. Make sure you are in the same directory as your `connection-profile.json` 200 | ```bash 201 | composer-playground 202 | ``` 203 | 3. In your browser, go to [http://localhost:8080/test](http://localhost:8080/test) to perform operations in business network. 204 | 205 | `Admin card` for global-citizen business network is created in Composer Playground. 206 | 207 | ![](images/home.png) 208 | 209 | Click on `Connect now` button present on `admin@global-citizens-network` card to connect to global-citizen business network 210 | 211 | ![](images/5.png) 212 | 213 | To test your Business Network Definition, first click on the **Test** tab: 214 | 215 | In the `AidOrg` participant registry, create a new participant. Make sure you click on the `AidOrg` tab on the far left-hand side first and click on `Create New Participant` button 216 | ![](images/6.png) 217 | 218 | Fill the details for `AidOrg` participant and click on `Create New` 219 | ![](images/7.png) 220 | 221 | New `AidOrg` participant created in participant registry. Similarly create the other participants for the network. 222 | ![](images/8.png) 223 | 224 | 225 | Connection profiles contain the information necessary to connect to a fabric. Business network cards combine a connection profile, identity, and certificates to allow a connection to a business network in Hyperledger Composer Playground. 226 | 227 | Now we are ready to add **Network Cards** for the participants in network. Do this by first clicking on the `admin` tab and select `ID Registry` to issue **new ids** to the participants and add the ids to the wallet. 228 | Please follow the instructions as shown in the images below: 229 | ![](images/9.png) 230 | 231 | ![](images/10.png) 232 | 233 | ![](images/11.png) 234 | 235 | ![](images/12.png) 236 | 237 | Click on `Use Now` to select the `AidOrg` participant registry to perform transactions on network. 238 | ![](images/13.png) 239 | 240 | Submit `CreateProjectPledge` transaction. 241 | ``` 242 | { 243 | "$class": "org.global.citizens.net.CreateProjectPledge", 244 | "pledgeId": "p1", 245 | "name": "child care", 246 | "decription": "child care fund", 247 | "fundsRequired": 100000, 248 | "aidOrg": "resource:org.global.citizens.net.AidOrg#aid" 249 | } 250 | ``` 251 | ![](images/14.png) 252 | 253 | New project pledge is created in Asset Registry. 254 | ![](images/15.png) 255 | 256 | Submit `SendPledgeToGlobalCitizen` transaction to send the pledge to global citizen to get the funds for the project. 257 | ``` 258 | { 259 | "$class": "org.global.citizens.net.SendPledgeToGlobalCitizen", 260 | "citizenId": "resource:org.global.citizens.net.GlobalCitizen#gc", 261 | "pledgeId": "resource:org.global.citizens.net.ProjectPledge#p1" 262 | } 263 | ``` 264 | ![](images/16.png) 265 | 266 | Global Citizen participant registry gets update with the new pledge request. 267 | ![](images/17.png) 268 | 269 | Global Citizen reviews the pledge. After successful verification it submits a`SendPledgeToGovOrg` transaction to get funds for the project pledge from government organizations. 270 | ``` 271 | { 272 | "$class": "org.global.citizens.net.SendPledgeToGovOrg", 273 | "govOrg": ["resource:org.global.citizens.net.GovOrg#gov"], 274 | "pledgeId": "resource:org.global.citizens.net.ProjectPledge#p1" 275 | } 276 | ``` 277 | ![](images/18.png) 278 | 279 | Government organizations reviews the pledge. After reviewing if they decide to fund the project then they submit a `UpdatePledge` transaction to update the project pledge asset. 280 | ``` 281 | { 282 | "$class": "org.global.citizens.net.UpdatePledge", 283 | "govOrgId": "resource:org.global.citizens.net.GovOrg#gov", 284 | "pledgeId": "resource:org.global.citizens.net.ProjectPledge#p1", 285 | "fundingType": "WEEKLY", 286 | "approvedFunding": 100000, 287 | "fundsPerInstallment": 1000 288 | } 289 | ``` 290 | ![](images/19.png) 291 | 292 | ![](images/20.png) 293 | 294 | ![](images/21.png) 295 | 296 | Government organizations periodically sends the funds to project by submitting `TransferFunds` transaction. 297 | ``` 298 | { 299 | "$class": "org.global.citizens.net.TransferFunds", 300 | "govOrgId": "resource:org.global.citizens.net.GovOrg#gov", 301 | "pledgeId": "resource:org.global.citizens.net.ProjectPledge#p1" 302 | } 303 | ``` 304 | ![](images/22.png) 305 | 306 | ![](images/23.png) 307 | 308 | ### b. Interact using composer-rest-server 309 | 310 | 1. Install the composer-rest-server: 311 | ```bash 312 | npm install -g composer-rest-server@0.20 313 | ``` 314 | 315 | 2. Now, let’s start up the server. Make sure you are in the same directory as your `connection-profile.json` 316 | ```bash 317 | composer-rest-server -c admin@global-citizens-network -n never -w true 318 | ``` 319 | 320 | 3. In your browser, go to [http://localhost:3000/explorer](http://localhost:3000/explorer) 321 | 322 | 4. Now you can use the swagger api to perform operations in business network as shown in [Interact using Composer-Playground](#a-interact-using-composer-playground) 323 | 324 | ## Extending Pattern 325 | 326 | 1. Add Network Permissions 327 | 2. Implement Dashboards 328 | 3. Implement logic for tracking payments default 329 | 4. Implement Notification logic 330 | 5. Improve transfer fund logic 331 | 332 | ## Additional Resources 333 | * [Hyperledger Fabric Docs](http://hyperledger-fabric.readthedocs.io/en/latest/) 334 | * [Hyperledger Composer Docs](https://hyperledger.github.io/composer/latest/introduction/introduction.html) 335 | 336 | ## License 337 | This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the [Developer Certificate of Origin, Version 1.1 (DCO)](https://developercertificate.org/) and the [Apache Software License, Version 2](http://www.apache.org/licenses/LICENSE-2.0.txt). 338 | 339 | [Apache Software License (ASL) FAQ](http://www.apache.org/foundation/license-faq.html#WhatDoesItMEAN) 340 | -------------------------------------------------------------------------------- /images/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/1.png -------------------------------------------------------------------------------- /images/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/10.png -------------------------------------------------------------------------------- /images/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/11.png -------------------------------------------------------------------------------- /images/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/12.png -------------------------------------------------------------------------------- /images/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/13.png -------------------------------------------------------------------------------- /images/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/14.png -------------------------------------------------------------------------------- /images/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/15.png -------------------------------------------------------------------------------- /images/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/16.png -------------------------------------------------------------------------------- /images/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/17.png -------------------------------------------------------------------------------- /images/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/18.png -------------------------------------------------------------------------------- /images/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/19.png -------------------------------------------------------------------------------- /images/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/2.png -------------------------------------------------------------------------------- /images/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/20.png -------------------------------------------------------------------------------- /images/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/21.png -------------------------------------------------------------------------------- /images/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/22.png -------------------------------------------------------------------------------- /images/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/23.png -------------------------------------------------------------------------------- /images/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/3.png -------------------------------------------------------------------------------- /images/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/4.png -------------------------------------------------------------------------------- /images/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/5.png -------------------------------------------------------------------------------- /images/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/6.png -------------------------------------------------------------------------------- /images/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/7.png -------------------------------------------------------------------------------- /images/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/8.png -------------------------------------------------------------------------------- /images/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/9.png -------------------------------------------------------------------------------- /images/admin-pub.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/admin-pub.gif -------------------------------------------------------------------------------- /images/connection.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/connection.gif -------------------------------------------------------------------------------- /images/gc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/gc.png -------------------------------------------------------------------------------- /images/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/home.png -------------------------------------------------------------------------------- /images/setup.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/setup.gif -------------------------------------------------------------------------------- /images/sync-certs.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/global-citizen/aeb32e42fa1bab3b8adddc244fc4a99c740c268e/images/sync-certs.gif -------------------------------------------------------------------------------- /lib/logic.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /** 3 | * Write your transction processor functions here 4 | */ 5 | var NS = 'org.global.citizens.net'; 6 | /** 7 | * createProjectPledge 8 | * @param {org.global.citizens.net.CreateProjectPledge} createProjectPledge 9 | * @transaction 10 | */ 11 | function createProjectPledge(txParams) { 12 | if(!txParams.name || (txParams.name && txParams.name === "")) { 13 | throw new Error('Invalid Pledge Name!!'); 14 | } 15 | if(!txParams.aidOrg) { 16 | throw new Error('Invalid Aid Org!!'); 17 | } 18 | var factory = getFactory(); 19 | var pledge = null; 20 | return getAssetRegistry(NS + '.ProjectPledge').then(function (registry) { 21 | pledge = factory.newResource(NS, 'ProjectPledge', txParams.pledgeId); 22 | pledge.name = txParams.name; 23 | pledge.decription = txParams.decription; 24 | pledge.fundsRequired = txParams.fundsRequired; 25 | pledge.status = 'INITIALSTATE'; 26 | pledge.funds = []; 27 | pledge.aidOrg = txParams.aidOrg; 28 | return registry.add(pledge); 29 | }).then(function () { 30 | return getParticipantRegistry(NS + '.AidOrg'); 31 | }).then(function (aidOrgRegistry) { 32 | // save the buyer 33 | txParams.aidOrg.projectPledge.push(pledge); 34 | return aidOrgRegistry.update(txParams.aidOrg); 35 | }); 36 | } 37 | /** 38 | * SendPledgeToGlobalCitizen 39 | * @param {org.global.citizens.net.SendPledgeToGlobalCitizen} sendPledgeToGlobalCitizen 40 | * @transaction 41 | */ 42 | function sendPledgeToGlobalCitizen(txParams) { 43 | if(!txParams.citizenId || !txParams.pledgeId) { 44 | throw new Error('Invalid input parameters!!'); 45 | } 46 | txParams.pledgeId.status = 'GLOBALCITIZENREVIEW'; 47 | txParams.citizenId.projectPledge.push(txParams.pledgeId); 48 | var factory = getFactory(); 49 | return getAssetRegistry(NS + '.ProjectPledge').then(function (registry) { 50 | return registry.update(txParams.pledgeId); 51 | }).then(function () { 52 | return getParticipantRegistry(NS + '.GlobalCitizen'); 53 | }).then(function (registry) { 54 | return registry.update(txParams.citizenId); 55 | }); 56 | } 57 | /** 58 | * SendPledgeToGovOrg 59 | * @param {org.global.citizens.net.SendPledgeToGovOrg} sendPledgeToGovOrg 60 | * @transaction 61 | */ 62 | function sendPledgeToGovOrg(txParams) { 63 | if(!txParams.pledgeId || !txParams.govOrg || (txParams.govOrg && txParams.govOrg.length === 0)) { 64 | throw new Error('Invalid input parameters!!'); 65 | } 66 | var factory = getFactory(); 67 | txParams.pledgeId.status = 'GOVORGREVIEW'; 68 | return getAssetRegistry(NS + '.ProjectPledge').then(function (registry) { 69 | return registry.update(txParams.pledgeId); 70 | }).then(function () { 71 | return getParticipantRegistry(NS + '.GovOrg'); 72 | }).then(function (registry) { 73 | for(var i = 0; i < txParams.govOrg.length; i++) { 74 | txParams.govOrg[i].projectPledge.push(txParams.pledgeId); 75 | } 76 | return registry.updateAll(txParams.govOrg); 77 | }); 78 | } 79 | /** 80 | * UpdatePledge 81 | * @param {org.global.citizens.net.UpdatePledge} updatePledge 82 | * @transaction 83 | */ 84 | function updatePledge(txParams) { 85 | if(!txParams.govOrgId) { 86 | throw new Error('Invalid user type!!'); 87 | } 88 | var factory = getFactory(); 89 | var funding = factory.newConcept(NS, 'Funding'); 90 | var daysToAdd = 0; 91 | switch(txParams.fundingType) { 92 | case 'WEEKLY': 93 | daysToAdd = 7; 94 | break; 95 | case 'MONTHLY': 96 | daysToAdd = 30; 97 | break; 98 | case 'SEMIANNUALY': 99 | daysToAdd = 180; 100 | break; 101 | case 'ANNUALY': 102 | daysToAdd = 365; 103 | break; 104 | } 105 | funding.fundingType = txParams.fundingType; 106 | funding.nextFundingDueInDays = daysToAdd; 107 | funding.approvedFunding = txParams.approvedFunding; 108 | funding.totalFundsReceived = 0; 109 | funding.fundsPerInstallment = txParams.fundsPerInstallment; 110 | funding.govOrgId = txParams.govOrgId; 111 | txParams.pledgeId.status = 'PROPOSALFUNDED'; 112 | txParams.pledgeId.funds.push(funding); 113 | txParams.govOrgId.fundedPledges.push(txParams.pledgeId); 114 | return getAssetRegistry(NS + '.ProjectPledge').then(function (registry) { 115 | return registry.update(txParams.pledgeId); 116 | }).then(function () { 117 | return getParticipantRegistry(NS + '.GovOrg'); 118 | }).then(function (registry) { 119 | return registry.update(txParams.govOrgId); 120 | }); 121 | } 122 | /** 123 | * TransferFunds 124 | * @param {org.global.citizens.net.TransferFunds} transferFunds 125 | * @transaction 126 | */ 127 | function transferFunds(txParams) { 128 | if(!txParams.pledgeId || !txParams.govOrgId) { 129 | throw new Error('Invalid input parameters!!'); 130 | } 131 | var factory = getFactory(); 132 | var valid = false; 133 | for(var i = 0; i < txParams.govOrgId.fundedPledges.length; i++) { 134 | if(txParams.govOrgId.fundedPledges[i].pledgeId === txParams.pledgeId.pledgeId) { 135 | valid = true; 136 | break; 137 | } 138 | } 139 | if(!valid) { 140 | throw new Error('Pledge not funded!!'); 141 | } 142 | for(var i = 0; i < txParams.pledgeId.funds.length; i++) { 143 | if(txParams.pledgeId.funds[i].govOrgId === txParams.govOrgId) { 144 | var daysToAdd = 0; 145 | switch(txParams.pledgeId.funds[i].fundingType) { 146 | case 'WEEKLY': 147 | daysToAdd = 7; 148 | break; 149 | case 'MONTHLY': 150 | daysToAdd = 30; 151 | break; 152 | case 'SEMIANNUALY': 153 | daysToAdd = 180; 154 | break; 155 | case 'ANNUALY': 156 | daysToAdd = 365; 157 | break; 158 | } 159 | txParams.pledgeId.funds[i].nextFundingDueInDays = daysToAdd; 160 | txParams.pledgeId.funds[i].totalFundsReceived += txParams.pledgeId.funds[i].fundsPerInstallment; 161 | break; 162 | } 163 | } 164 | return getAssetRegistry(NS + '.ProjectPledge').then(function (registry) { 165 | return registry.update(txParams.pledgeId); 166 | }); 167 | } -------------------------------------------------------------------------------- /models/org.global.citizens.net.cto: -------------------------------------------------------------------------------- 1 | /** 2 | * Write your model definitions here 3 | */ 4 | 5 | namespace org.global.citizens.net 6 | 7 | enum Status{ 8 | o INITIALSTATE 9 | o GLOBALCITIZENREVIEW 10 | o GOVORGREVIEW 11 | o PROPOSALFUNDED 12 | } 13 | 14 | enum FundingType{ 15 | o WEEKLY 16 | o MONTHLY 17 | o SEMIANNUALY 18 | o ANNUALY 19 | } 20 | enum FundingStatus{ 21 | o COMPLETE 22 | o INCOMPLETE 23 | } 24 | 25 | enum MessageStatus{ 26 | o NOTREVIEWED 27 | o REVIEWED 28 | } 29 | 30 | concept Funding { 31 | o FundingType fundingType 32 | o Integer nextFundingDueInDays 33 | o Double approvedFunding 34 | o Double totalFundsReceived 35 | o Double fundsPerInstallment 36 | --> GovOrg govOrgId 37 | } 38 | 39 | asset ProjectPledge identified by pledgeId { 40 | o String pledgeId 41 | o String name 42 | o String decription 43 | o Double fundsRequired 44 | o Status status 45 | --> AidOrg aidOrg 46 | o Funding[] funds 47 | } 48 | 49 | abstract participant User { 50 | --> ProjectPledge[] projectPledge 51 | } 52 | 53 | participant GovOrg identified by govOrgId extends User { 54 | o String govOrgId 55 | --> ProjectPledge[] fundedPledges 56 | } 57 | 58 | participant AidOrg identified by aidOrgId extends User { 59 | o String aidOrgId 60 | } 61 | 62 | participant GlobalCitizen identified by citizenId extends User { 63 | o String citizenId 64 | } 65 | 66 | transaction CreateProjectPledge { 67 | o String pledgeId 68 | o String name 69 | o String decription 70 | o Double fundsRequired 71 | --> AidOrg aidOrg 72 | } 73 | 74 | transaction SendPledgeToGlobalCitizen { 75 | --> GlobalCitizen citizenId 76 | --> ProjectPledge pledgeId 77 | } 78 | 79 | transaction SendPledgeToGovOrg { 80 | --> GovOrg[] govOrg 81 | --> ProjectPledge pledgeId 82 | } 83 | 84 | transaction UpdatePledge { 85 | --> GovOrg govOrgId 86 | --> ProjectPledge pledgeId 87 | o FundingType fundingType 88 | o Double approvedFunding 89 | o Double fundsPerInstallment 90 | } 91 | 92 | transaction TransferFunds { 93 | --> GovOrg govOrgId 94 | --> ProjectPledge pledgeId 95 | } 96 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "global-citizens-network", 3 | "version": "0.0.1", 4 | "description": "The goal of this pattern is to build a 3-member blockchain application using the IBM Blockchain Platform, consisting of the following entities: an organization representing a government entity, an organization representing Global Citizen(i.e. NGO ) focused on the provision of aid, and an organization representing Aid organization receiving the funds from governments for the humanitarian causes", 5 | "scripts": { 6 | "prepublish": "composer archive create -t dir -n .", 7 | "test": "mocha --recursive" 8 | }, 9 | "author": "Sample", 10 | "email": "sample", 11 | "license": "Apache-2.0", 12 | "devDependencies": { 13 | "composer-admin": "latest", 14 | "composer-client": "latest", 15 | "composer-common": "latest", 16 | "composer-connector-embedded": "latest", 17 | "chai": "latest", 18 | "eslint": "latest", 19 | "istanbul": "latest", 20 | "mkdirp": "latest", 21 | "mocha": "latest" 22 | }, 23 | "dependencies": { 24 | "composer-cli": "^0.20.2" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /permissions.acl: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | /** 16 | * Sample access control list. 17 | */ 18 | /** 19 | * Access control rules for mynetwork 20 | */ 21 | 22 | rule Default { 23 | description: "Allow all participants access to all resources" 24 | participant: "ANY" 25 | operation: ALL 26 | resource: "org.global.citizens.net.*" 27 | action: ALLOW 28 | } 29 | 30 | rule SystemACL { 31 | description: "System ACL to permit all access" 32 | participant: "ANY" 33 | operation: ALL 34 | resource: "org.hyperledger.composer.system.**" 35 | action: ALLOW 36 | } 37 | --------------------------------------------------------------------------------