├── .gitignore ├── LICENSE ├── README.md ├── certificate.bat ├── certificate ├── admin_cert.pem ├── admin_client.crt ├── admin_client.key ├── admin_sk ├── org0-ca-chain.pem ├── org1-ca-chain.pem ├── user_cert.pem ├── user_client.crt ├── user_client.key └── user_sk ├── pom.xml └── src └── main ├── java └── litong │ └── hyperledger │ └── fabric │ └── example │ ├── Demo.java │ ├── SampleEnrollment.java │ └── SampleUser.java └── resources └── log4j.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | -------------------------------------------------------------------------------- /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.md: -------------------------------------------------------------------------------- 1 | # myfabric-demo-java-client 2 | Hyperledger Fabric联盟链定制化示例Java客户端 3 | 4 | ## 运行 5 | 6 | 1. 启动[myfabric-demo-chain](https://github.com/fftt2017/myfabric-demo-chain) 7 | 8 | 2. 修改 myfabric-demo-java-client/src/main/java/litong/hyperledger/fabric/example/Demo.java代码中 ```private static final String HOST = "192.168.99.101";```为运行docker ip地址。 9 | 10 | 如果[myfabric-demo-chain](https://github.com/fftt2017/myfabric-demo-chain)重新生成组织身份证书。需要复制相关证书文件到```certificate```目录下,可参考```certificate.bat```。 11 | -------------------------------------------------------------------------------- /certificate.bat: -------------------------------------------------------------------------------- 1 | set chain_dir= 2 | set java_client_dir= 3 | 4 | copy /y %chain_dir%\org0\data\org0-ca-chain.pem %java_client_dir%\certificate\org0-ca-chain.pem 5 | copy /y %chain_dir%\org1\data\org1-ca-chain.pem %java_client_dir%\certificate\org1-ca-chain.pem 6 | 7 | rem copy /y %chain_dir%\org1\data\admin\msp\keystore\* %java_client_dir%\certificate\admin_sk 8 | rem copy /y %chain_dir%\org1\data\admin\msp\signcerts\* %java_client_dir%\certificate\admin_cert.pem 9 | rem copy /y %chain_dir%\org1\data\admin\tls\client.crt %java_client_dir%\certificate\admin_client.crt 10 | rem copy /y %chain_dir%\org1\data\admin\tls\client.key %java_client_dir%\certificate\admin_client.key 11 | 12 | copy /y %chain_dir%\org1\data\user\msp\keystore\* %java_client_dir%\certificate\user_sk 13 | copy /y %chain_dir%\org1\data\user\msp\signcerts\* %java_client_dir%\certificate\user_cert.pem 14 | copy /y %chain_dir%\org1\data\user\tls\client.crt %java_client_dir%\certificate\user_client.crt 15 | copy /y %chain_dir%\org1\data\user\tls\client.key %java_client_dir%\certificate\user_client.key 16 | -------------------------------------------------------------------------------- /certificate/admin_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC+TCCAp+gAwIBAgIULr8B3ALGvGhFy1tfKkSZhbkYxjUwCgYIKoZIzj0EAwIw 3 | djELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNpIENodWFuMREwDwYDVQQHEwhDaGVu 4 | ZyBEdTEXMBUGA1UEChMOTXkgRmFicmljIERlbW8xDzANBgNVBAsTBmNsaWVudDEX 5 | MBUGA1UEAxMOcmNhLW9yZzEtYWRtaW4wHhcNMTkwNzEzMTQyMzAwWhcNMjAwNzEy 6 | MTQyODAwWjB/MQswCQYDVQQGEwJDTjERMA8GA1UECBMIU2kgQ2h1YW4xETAPBgNV 7 | BAcTCENoZW5nIER1MRcwFQYDVQQKEw5NeSBGYWJyaWMgRGVtbzEcMA0GA1UECxMG 8 | Y2xpZW50MAsGA1UECxMEb3JnMTETMBEGA1UEAxMKYWRtaW4tb3JnMTBZMBMGByqG 9 | SM49AgEGCCqGSM49AwEHA0IABJ41noGPGN31Npmt1sxr5CQi7t8FfOgTYedkNy2c 10 | g+8KNpYzmiE6aW4MC1cAzizxGD2Yc8rScwyuD+BgBfJH7/qjggEAMIH9MA4GA1Ud 11 | DwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBTy4BC/0ApEuVBGYruk 12 | 8RGHxMDM4zAfBgNVHSMEGDAWgBTi+PLhyyT4Hw8kk8m/yN8uDUtqxTAXBgNVHREE 13 | EDAOggw1NmUwMmFiODdmY2IwgYMGCCoDBAUGBwgBBHd7ImF0dHJzIjp7ImFiYWMu 14 | aW5pdCI6InRydWUiLCJhZG1pbiI6InRydWUiLCJoZi5BZmZpbGlhdGlvbiI6Im9y 15 | ZzEiLCJoZi5FbnJvbGxtZW50SUQiOiJhZG1pbi1vcmcxIiwiaGYuVHlwZSI6ImNs 16 | aWVudCJ9fTAKBggqhkjOPQQDAgNIADBFAiEA+ZiSx7b8iQHHLz6o7K88/cq5FnIS 17 | oRkVBcJLq8vfDRICIHWq7bdAHveGu+6tNVcdrSm9u2iYLiP/je5rftfKI4hw 18 | -----END CERTIFICATE----- 19 |  -------------------------------------------------------------------------------- /certificate/admin_client.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDGDCCAr+gAwIBAgIUEQpL+rNMLJQxy4YCqbxjeowIhhwwCgYIKoZIzj0EAwIw 3 | djELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNpIENodWFuMREwDwYDVQQHEwhDaGVu 4 | ZyBEdTEXMBUGA1UEChMOTXkgRmFicmljIERlbW8xDzANBgNVBAsTBmNsaWVudDEX 5 | MBUGA1UEAxMOcmNhLW9yZzEtYWRtaW4wHhcNMTkwNzEzMTQyMzAwWhcNMjAwNzEy 6 | MTQyODAwWjB/MQswCQYDVQQGEwJDTjERMA8GA1UECBMIU2kgQ2h1YW4xETAPBgNV 7 | BAcTCENoZW5nIER1MRcwFQYDVQQKEw5NeSBGYWJyaWMgRGVtbzEcMA0GA1UECxMG 8 | Y2xpZW50MAsGA1UECxMEb3JnMTETMBEGA1UEAxMKYWRtaW4tb3JnMTBZMBMGByqG 9 | SM49AgEGCCqGSM49AwEHA0IABIPqJbe0LIbAST7IvpEvYWxlXk/1cv77pKy4cqJx 10 | T5azXqvFUV5OiMbCFXKVHvLLDvbIC6BsVfdnoSOw5YTBwxijggEgMIIBHDAOBgNV 11 | HQ8BAf8EBAMCA6gwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1Ud 12 | EwEB/wQCMAAwHQYDVR0OBBYEFJTmGPD2pVgcN0lE4YNwe6aCZGn0MB8GA1UdIwQY 13 | MBaAFOL48uHLJPgfDySTyb/I3y4NS2rFMBcGA1UdEQQQMA6CDDU2ZTAyYWI4N2Zj 14 | YjCBgwYIKgMEBQYHCAEEd3siYXR0cnMiOnsiYWJhYy5pbml0IjoidHJ1ZSIsImFk 15 | bWluIjoidHJ1ZSIsImhmLkFmZmlsaWF0aW9uIjoib3JnMSIsImhmLkVucm9sbG1l 16 | bnRJRCI6ImFkbWluLW9yZzEiLCJoZi5UeXBlIjoiY2xpZW50In19MAoGCCqGSM49 17 | BAMCA0cAMEQCIH7jsQ0k7bDooVUsml8vKNQd7jCxMjpglQlGscLd0n5uAiB2Wtbo 18 | VJyzvp+H++GsPrmC1tpjrD//0j/QmUfM22vVEw== 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /certificate/admin_client.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgwUn6g2y2ASgNWGdk 3 | fOC5SoYBa8ADNm1Bi+CmxioIfumhRANCAASD6iW3tCyGwEk+yL6RL2FsZV5P9XL+ 4 | +6SsuHKicU+Ws16rxVFeTojGwhVylR7yyw72yAugbFX3Z6EjsOWEwcMY 5 | -----END PRIVATE KEY----- 6 | -------------------------------------------------------------------------------- /certificate/admin_sk: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgUYZfy23zfdoNanii 3 | IdsCHJNVWf/l30sLwqSU5e9ljvShRANCAASeNZ6Bjxjd9TaZrdbMa+QkIu7fBXzo 4 | E2HnZDctnIPvCjaWM5ohOmluDAtXAM4s8Rg9mHPK0nMMrg/gYAXyR+/6 5 | -----END PRIVATE KEY----- 6 |  -------------------------------------------------------------------------------- /certificate/org0-ca-chain.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICSzCCAfKgAwIBAgIUR3Vu/TsDKHRL66DaZaal93zllCwwCgYIKoZIzj0EAwIw 3 | bjELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNpIENodWFuMREwDwYDVQQHEwhDaGVu 4 | ZyBEdTEXMBUGA1UEChMOTXkgRmFicmljIERlbW8xDTALBgNVBAsTBG9yZzAxETAP 5 | BgNVBAMTCHJjYS1vcmcwMB4XDTE5MDcxMzE0MjMwMFoXDTI0MDcxMTE0MjgwMFow 6 | djELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNpIENodWFuMREwDwYDVQQHEwhDaGVu 7 | ZyBEdTEXMBUGA1UEChMOTXkgRmFicmljIERlbW8xDzANBgNVBAsTBmNsaWVudDEX 8 | MBUGA1UEAxMOcmNhLW9yZzAtYWRtaW4wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC 9 | AATlqjQsdgHXRL2nTG8rqfm/6bYs8UdmxCOXppHW+tjghUCnpV8nFNNOZ+zRbUeH 10 | xzM/WjyQVZyi7AFigmtpmVJuo2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/ 11 | BAgwBgEB/wIBADAdBgNVHQ4EFgQUKSuHM0PTqKTkIj26ZF7qFzG8peswHwYDVR0j 12 | BBgwFoAUbj8znqaL+nEm4E88q+d5B780c+swCgYIKoZIzj0EAwIDRwAwRAIgItPa 13 | emZJwn+aePolWOzmyW6YF8c9cZt0Z3GgYt5xoGcCIB6/EqbIm99f/puVbF15fcvO 14 | 7SopzyxvCcR6NWVv9EXr 15 | -----END CERTIFICATE----- 16 | -----BEGIN CERTIFICATE----- 17 | MIICIjCCAcmgAwIBAgIULa0MEmVQ1dFBL8H5RtRj5jiM5u8wCgYIKoZIzj0EAwIw 18 | bjELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNpIENodWFuMREwDwYDVQQHEwhDaGVu 19 | ZyBEdTEXMBUGA1UEChMOTXkgRmFicmljIERlbW8xDTALBgNVBAsTBG9yZzAxETAP 20 | BgNVBAMTCHJjYS1vcmcwMB4XDTE5MDcxMzE0MjMwMFoXDTM0MDcwOTE0MjMwMFow 21 | bjELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNpIENodWFuMREwDwYDVQQHEwhDaGVu 22 | ZyBEdTEXMBUGA1UEChMOTXkgRmFicmljIERlbW8xDTALBgNVBAsTBG9yZzAxETAP 23 | BgNVBAMTCHJjYS1vcmcwMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE5z9VEY82 24 | etKrjXH/ETp5Jg0rV6TVujSJDo+J43SJivW1WdPgYPjd04GHs/BMkuGUw82R68og 25 | 49Y3IlgXPcrHUaNFMEMwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8C 26 | AQEwHQYDVR0OBBYEFG4/M56mi/pxJuBPPKvneQe/NHPrMAoGCCqGSM49BAMCA0cA 27 | MEQCIA2lnMQz45sylzwee1B039aVCaCeaqZ2kAkCszqJlaFfAiBJ01ggU6cB2cN4 28 | OGxY6ejhTBVOMxvg0m7bSEJk9/Xg1g== 29 | -----END CERTIFICATE----- 30 | -------------------------------------------------------------------------------- /certificate/org1-ca-chain.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICSzCCAfKgAwIBAgIUKHyuKSgNMmwb0LtpDNmfdGdJJIAwCgYIKoZIzj0EAwIw 3 | bjELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNpIENodWFuMREwDwYDVQQHEwhDaGVu 4 | ZyBEdTEXMBUGA1UEChMOTXkgRmFicmljIERlbW8xDTALBgNVBAsTBG9yZzExETAP 5 | BgNVBAMTCHJjYS1vcmcxMB4XDTE5MDcxMzE0MjMwMFoXDTI0MDcxMTE0MjgwMFow 6 | djELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNpIENodWFuMREwDwYDVQQHEwhDaGVu 7 | ZyBEdTEXMBUGA1UEChMOTXkgRmFicmljIERlbW8xDzANBgNVBAsTBmNsaWVudDEX 8 | MBUGA1UEAxMOcmNhLW9yZzEtYWRtaW4wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC 9 | AARiaKouXn7QfgpMiuJh+wN7Mlpl3ZhmRouSeYKfqHIfXyRjV8zIjmuhKv05+01o 10 | XQbKocEfsUNLE3OLJdH5kIRto2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/ 11 | BAgwBgEB/wIBADAdBgNVHQ4EFgQU4vjy4csk+B8PJJPJv8jfLg1LasUwHwYDVR0j 12 | BBgwFoAU/lgic5GgvHK7rkVDIWoQ37MJBqMwCgYIKoZIzj0EAwIDRwAwRAIgfCQj 13 | 6T31hhbzeBzxLT+V+FUuI6wchSOAxX8uotLQQEkCIDB+mCoBigeWfCdhQ8+TJZ8z 14 | BLChxohN2LtzkNrdhmIr 15 | -----END CERTIFICATE----- 16 | -----BEGIN CERTIFICATE----- 17 | MIICIzCCAcmgAwIBAgIUaC9oWDttnFPQlW6Gu2Du/10+W0AwCgYIKoZIzj0EAwIw 18 | bjELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNpIENodWFuMREwDwYDVQQHEwhDaGVu 19 | ZyBEdTEXMBUGA1UEChMOTXkgRmFicmljIERlbW8xDTALBgNVBAsTBG9yZzExETAP 20 | BgNVBAMTCHJjYS1vcmcxMB4XDTE5MDcxMzE0MjMwMFoXDTM0MDcwOTE0MjMwMFow 21 | bjELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNpIENodWFuMREwDwYDVQQHEwhDaGVu 22 | ZyBEdTEXMBUGA1UEChMOTXkgRmFicmljIERlbW8xDTALBgNVBAsTBG9yZzExETAP 23 | BgNVBAMTCHJjYS1vcmcxMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEFV1uqfju 24 | x4+gAv3P+lPb4RTCDrPzCGmNa2ei5xcBPJk4QO3oew/HRMc9PzvNQuQ8oo5zHn2i 25 | EYC+M1O/OwVtSqNFMEMwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8C 26 | AQEwHQYDVR0OBBYEFP5YInORoLxyu65FQyFqEN+zCQajMAoGCCqGSM49BAMCA0gA 27 | MEUCIQCytuydMCiY/Axv+3sXM5aH5Hqd8PNVmHnl7+1ULtrx4QIgB0QXdwnvEw+h 28 | 2BlCkbie+09ejBxe0ExRMfTEQ7rPHTE= 29 | -----END CERTIFICATE----- 30 | -------------------------------------------------------------------------------- /certificate/user_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC0zCCAnmgAwIBAgIUOm5eD0GNOALMEyC1XMmBtl4y3RQwCgYIKoZIzj0EAwIw 3 | djELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNpIENodWFuMREwDwYDVQQHEwhDaGVu 4 | ZyBEdTEXMBUGA1UEChMOTXkgRmFicmljIERlbW8xDzANBgNVBAsTBmNsaWVudDEX 5 | MBUGA1UEAxMOcmNhLW9yZzEtYWRtaW4wHhcNMTkwNzEzMTQyMzAwWhcNMjAwNzEy 6 | MTQyODAwWjB+MQswCQYDVQQGEwJDTjERMA8GA1UECBMIU2kgQ2h1YW4xETAPBgNV 7 | BAcTCENoZW5nIER1MRcwFQYDVQQKEw5NeSBGYWJyaWMgRGVtbzEcMA0GA1UECxMG 8 | Y2xpZW50MAsGA1UECxMEb3JnMTESMBAGA1UEAxMJdXNlci1vcmcxMFkwEwYHKoZI 9 | zj0CAQYIKoZIzj0DAQcDQgAEIhO2D+903I/ffE9aammqEUBD0N9qCw5Yx8Zy1WdT 10 | ezm7L5gM/X34hpJEbGr1G7ar/wyvpZjliJu6Hfbgu+vyxqOB3DCB2TAOBgNVHQ8B 11 | Af8EBAMCB4AwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQU3Mk9Zq9oUDo7p6U4aSiG 12 | 8u1pWsIwHwYDVR0jBBgwFoAU4vjy4csk+B8PJJPJv8jfLg1LasUwFwYDVR0RBBAw 13 | DoIMNTZlMDJhYjg3ZmNiMGAGCCoDBAUGBwgBBFR7ImF0dHJzIjp7ImhmLkFmZmls 14 | aWF0aW9uIjoib3JnMSIsImhmLkVucm9sbG1lbnRJRCI6InVzZXItb3JnMSIsImhm 15 | LlR5cGUiOiJjbGllbnQifX0wCgYIKoZIzj0EAwIDSAAwRQIhAJxSRS9SkGwSqRJP 16 | OrC0/NUbvmt28ozYaeSkdNkykrn6AiBhK6URBaTT+VVqb4mfcb/g4R4a3oYGMJRA 17 | gY0uYtka5Q== 18 | -----END CERTIFICATE----- 19 |  -------------------------------------------------------------------------------- /certificate/user_client.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC8jCCApigAwIBAgIUARIgZWKuFJ0Sz/+psSQjVlIi6AowCgYIKoZIzj0EAwIw 3 | djELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNpIENodWFuMREwDwYDVQQHEwhDaGVu 4 | ZyBEdTEXMBUGA1UEChMOTXkgRmFicmljIERlbW8xDzANBgNVBAsTBmNsaWVudDEX 5 | MBUGA1UEAxMOcmNhLW9yZzEtYWRtaW4wHhcNMTkwNzEzMTQyMzAwWhcNMjAwNzEy 6 | MTQyODAwWjB+MQswCQYDVQQGEwJDTjERMA8GA1UECBMIU2kgQ2h1YW4xETAPBgNV 7 | BAcTCENoZW5nIER1MRcwFQYDVQQKEw5NeSBGYWJyaWMgRGVtbzEcMA0GA1UECxMG 8 | Y2xpZW50MAsGA1UECxMEb3JnMTESMBAGA1UEAxMJdXNlci1vcmcxMFkwEwYHKoZI 9 | zj0CAQYIKoZIzj0DAQcDQgAEQoU+a8WYbcIUuv13jZVF8fE88Q/5N3urUMaYcST4 10 | K1GxQECeW4YT0OYxehKdLym4iRoicbJpPvC5/n6wR4qN8KOB+zCB+DAOBgNVHQ8B 11 | Af8EBAMCA6gwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB 12 | /wQCMAAwHQYDVR0OBBYEFD8Xi9zjreRa72Ugn38VXOG3kB9iMB8GA1UdIwQYMBaA 13 | FOL48uHLJPgfDySTyb/I3y4NS2rFMBcGA1UdEQQQMA6CDDU2ZTAyYWI4N2ZjYjBg 14 | BggqAwQFBgcIAQRUeyJhdHRycyI6eyJoZi5BZmZpbGlhdGlvbiI6Im9yZzEiLCJo 15 | Zi5FbnJvbGxtZW50SUQiOiJ1c2VyLW9yZzEiLCJoZi5UeXBlIjoiY2xpZW50In19 16 | MAoGCCqGSM49BAMCA0gAMEUCIQCp2a2PVpBocWxe0qwTKA7w80ImPmvYFHyNJ2a9 17 | ScGLpgIgIHAin4zKGITGyQyJBrJg9vF6us7zpiDZ8TIdGUk8j7c= 18 | -----END CERTIFICATE----- 19 | -------------------------------------------------------------------------------- /certificate/user_client.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgSxEpIJtjsjXoy2Il 3 | wrPvk6nu/jJo9kVuzqzPrqTi70KhRANCAARChT5rxZhtwhS6/XeNlUXx8TzxD/k3 4 | e6tQxphxJPgrUbFAQJ5bhhPQ5jF6Ep0vKbiJGiJxsmk+8Ln+frBHio3w 5 | -----END PRIVATE KEY----- 6 | -------------------------------------------------------------------------------- /certificate/user_sk: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg2ga6GSZeO1uI26vi 3 | 4nJkv6u9jFlBzCi8KWbM+lNjqIqhRANCAAQiE7YP73Tcj998T1pqaaoRQEPQ32oL 4 | DljHxnLVZ1N7ObsvmAz9ffiGkkRsavUbtqv/DK+lmOWIm7od9uC76/LG 5 | -----END PRIVATE KEY----- 6 |  -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | myfabric-java-demo 5 | lt.myfabric 6 | myfabric-java-demo 7 | jar 8 | 1.0-SNAPSHOT 9 | 10 | 11 | 12 | org.apache.maven.plugins 13 | maven-compiler-plugin 14 | 3.3 15 | 16 | 1.8 17 | 1.8 18 | 19 | 20 | 21 | 22 | 23 | 24 | org.hyperledger.fabric-sdk-java 25 | fabric-sdk-java 26 | 1.4.1 27 | 28 | 29 | com.google.guava 30 | guava 31 | 25.1-jre 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/java/litong/hyperledger/fabric/example/Demo.java: -------------------------------------------------------------------------------- 1 | package litong.hyperledger.fabric.example; 2 | 3 | import static java.nio.charset.StandardCharsets.UTF_8; 4 | import static org.hyperledger.fabric.sdk.BlockInfo.EnvelopeType.TRANSACTION_ENVELOPE; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.io.UnsupportedEncodingException; 9 | import java.nio.charset.Charset; 10 | import java.security.KeyFactory; 11 | import java.security.PrivateKey; 12 | import java.security.spec.PKCS8EncodedKeySpec; 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | import java.util.List; 16 | import java.util.Properties; 17 | import java.util.concurrent.CompletableFuture; 18 | import java.util.concurrent.ExecutionException; 19 | import java.util.concurrent.TimeUnit; 20 | import java.util.concurrent.TimeoutException; 21 | 22 | import org.apache.commons.codec.binary.Base64; 23 | import org.apache.commons.codec.binary.Hex; 24 | import org.apache.log4j.Logger; 25 | import org.hyperledger.fabric.protos.ledger.rwset.kvrwset.KvRwset; 26 | import org.hyperledger.fabric.sdk.BlockEvent; 27 | import org.hyperledger.fabric.sdk.BlockEvent.TransactionEvent; 28 | import org.hyperledger.fabric.sdk.BlockInfo; 29 | import org.hyperledger.fabric.sdk.BlockchainInfo; 30 | import org.hyperledger.fabric.sdk.ChaincodeID; 31 | import org.hyperledger.fabric.sdk.ChaincodeResponse.Status; 32 | import org.hyperledger.fabric.sdk.Channel; 33 | import org.hyperledger.fabric.sdk.HFClient; 34 | import org.hyperledger.fabric.sdk.Orderer; 35 | import org.hyperledger.fabric.sdk.Peer; 36 | import org.hyperledger.fabric.sdk.ProposalResponse; 37 | import org.hyperledger.fabric.sdk.QueryByChaincodeRequest; 38 | import org.hyperledger.fabric.sdk.SDKUtils; 39 | import org.hyperledger.fabric.sdk.TransactionProposalRequest; 40 | import org.hyperledger.fabric.sdk.TxReadWriteSetInfo; 41 | import org.hyperledger.fabric.sdk.TxReadWriteSetInfo.NsRwsetInfo; 42 | import org.hyperledger.fabric.sdk.exception.InvalidArgumentException; 43 | import org.hyperledger.fabric.sdk.exception.InvalidProtocolBufferRuntimeException; 44 | import org.hyperledger.fabric.sdk.exception.ProposalException; 45 | import org.hyperledger.fabric.sdk.security.CryptoSuite; 46 | 47 | import com.google.common.io.Files; 48 | import com.google.protobuf.InvalidProtocolBufferException; 49 | 50 | public class Demo { 51 | private static final Logger log = Logger.getLogger(Demo.class); 52 | 53 | private static final Charset CHARSET = Charset.forName("UTF-8"); 54 | private static final String HOST = "192.168.99.101"; 55 | private static final String CHANNEL_NAME = "demo-app-chain"; 56 | private static final String CHAIN_CODE = "mycc"; 57 | 58 | private static Peer peer1; 59 | private static Orderer orderer; 60 | private static HFClient client; 61 | 62 | public static void main(String[] args) throws Exception { 63 | Channel channel = getDemoChannel(); 64 | channel.initialize(); 65 | 66 | log.info("call query method starts......"); 67 | query(client, channel, CHAIN_CODE, "query", new String[] {"a"}); 68 | log.info("call query method ends......"); 69 | 70 | log.info("call invoke method starts......"); 71 | invoke(client, channel, CHAIN_CODE, "invoke", new String[] {"a", "b", "10"}); 72 | log.info("call invoke method ends......"); 73 | 74 | log.info("call query method starts......"); 75 | query(client, channel, CHAIN_CODE, "query", new String[] {"a"}); 76 | log.info("call query method ends......"); 77 | 78 | log.info("explore blocks starts......"); 79 | blockWalker(client, channel); 80 | log.info("explore blocks ends......"); 81 | 82 | System.out.println("done!"); 83 | } 84 | 85 | private static Channel getDemoChannel() throws Exception { 86 | SampleEnrollment enrollment = loadEnrollment("certificate/user_cert.pem", "certificate/user_sk"); 87 | SampleUser user = new SampleUser("user", "org1MSP", "org1", enrollment); 88 | 89 | client = HFClient.createNewInstance(); 90 | client.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite()); 91 | client.setUserContext(user); 92 | 93 | Channel channel = client.newChannel(CHANNEL_NAME); 94 | orderer = newOrderer(client, "orderer", "certificate/org0-ca-chain.pem", "certificate/user_client.key", "certificate/user_client.crt", "orderer1-org0", "grpcs://" + HOST + ":7050"); 95 | channel.addOrderer(orderer); 96 | 97 | peer1 = newPeer(client, "peer1", "certificate/org1-ca-chain.pem", "certificate/user_client.key", "certificate/user_client.crt", "peer1-org1", "grpcs://" + HOST + ":7051"); 98 | channel.addPeer(peer1); 99 | 100 | return channel; 101 | } 102 | 103 | private static Orderer newOrderer(HFClient client, String name, String pemFile, String clientTLSKeyFile, String clientTLSCertFile, String hostName, String url) throws InvalidArgumentException { 104 | Properties orderProps = new Properties(); 105 | orderProps.setProperty("pemFile", pemFile); 106 | orderProps.setProperty("sslProvider", "openSSL"); 107 | orderProps.setProperty("negotiationType", "TLS"); 108 | orderProps.setProperty("ordererWaitTimeMilliSecs", "300000"); 109 | orderProps.setProperty("hostnameOverride", hostName); 110 | orderProps.setProperty("clientKeyFile", clientTLSKeyFile); 111 | orderProps.setProperty("clientCertFile", clientTLSCertFile); 112 | 113 | return client.newOrderer(name, url, orderProps); 114 | } 115 | 116 | private static Peer newPeer(HFClient client, String name, String pemFile, String clientTLSKeyFile, String clientTLSCertFile, String hostName, String url) throws InvalidArgumentException { 117 | Properties peerProps = new Properties(); 118 | peerProps.setProperty("pemFile", pemFile); 119 | peerProps.setProperty("sslProvider", "openSSL"); 120 | peerProps.setProperty("negotiationType", "TLS"); 121 | peerProps.setProperty("hostnameOverride", hostName); 122 | peerProps.setProperty("clientKeyFile", clientTLSKeyFile); 123 | peerProps.setProperty("clientCertFile", clientTLSCertFile); 124 | 125 | return client.newPeer(name, url, peerProps); 126 | } 127 | 128 | private static void query(HFClient client, Channel channel, String chainCode, String fcn, String[] parameters) throws Exception { 129 | QueryByChaincodeRequest req = client.newQueryProposalRequest(); 130 | ChaincodeID cid = ChaincodeID.newBuilder().setName(chainCode).build(); 131 | req.setChaincodeID(cid); 132 | req.setFcn(fcn); 133 | req.setArgs(parameters); 134 | 135 | List peers = new ArrayList<>(); 136 | peers.add(peer1); 137 | 138 | Collection resps = channel.queryByChaincode(req, peers); 139 | for (ProposalResponse resp : resps) { 140 | String payload = new String(resp.getChaincodeActionResponsePayload()); 141 | System.out.println("response: " + payload); 142 | } 143 | } 144 | 145 | private static void invoke(HFClient client, Channel channel, String chainCode, String fcn, String[] parameters) throws Exception { 146 | TransactionProposalRequest transactionProposalRequest = client.newTransactionProposalRequest(); 147 | ChaincodeID cid = ChaincodeID.newBuilder().setName(chainCode).build(); 148 | transactionProposalRequest.setChaincodeID(cid); 149 | transactionProposalRequest.setFcn(fcn); 150 | transactionProposalRequest.setArgs(parameters); 151 | 152 | List peers = new ArrayList<>(); 153 | peers.add(peer1); 154 | //peers.add(peer2); 155 | 156 | Collection invokePropResp = channel.sendTransactionProposal(transactionProposalRequest); 157 | for (ProposalResponse response : invokePropResp) { 158 | if (response.getStatus() == Status.SUCCESS) { 159 | out("Proposal response SUCC Txid=%s, peer=%s, data=[%s]", response.getTransactionID(), response.getPeer(), new String(response.getChaincodeActionResponsePayload())); 160 | dumpRWSet(response); 161 | } else { 162 | out("Proposal response FAIL Txid=%s, peer=%s, data=[%s]", response.getTransactionID(), response.getPeer(), new String(response.getChaincodeActionResponsePayload())); 163 | } 164 | } 165 | out("Sending to orderer"); 166 | 167 | sendTransaction(channel, invokePropResp); 168 | } 169 | 170 | private static void sendTransaction(Channel channel, Collection invokePropResp) throws InterruptedException, ExecutionException, TimeoutException { 171 | CompletableFuture carfuture = channel.sendTransaction(invokePropResp); 172 | out("Wait event"); 173 | TransactionEvent transactionEvent = carfuture.get(30, TimeUnit.SECONDS); 174 | out("Wait event return: " + transactionEvent.getChannelId() + " " + transactionEvent.getTransactionID() + " " + transactionEvent.getType() + " " + transactionEvent.getValidationCode()); 175 | } 176 | 177 | private static void out(String format, Object... args) { 178 | log.info(String.format(format, args)); 179 | } 180 | 181 | private static void dumpRWSet(ProposalResponse response) { 182 | try { 183 | for (NsRwsetInfo nsRwsetInfo : response.getChaincodeActionResponseReadWriteSetInfo().getNsRwsetInfos()) { 184 | String namespace = nsRwsetInfo.getNamespace(); 185 | KvRwset.KVRWSet rws = nsRwsetInfo.getRwset(); 186 | 187 | int rsid = -1; 188 | for (KvRwset.KVRead readList : rws.getReadsList()) { 189 | rsid++; 190 | out("Namespace %s read set[%d]: key[%s]=version[%d:%d]", namespace, rsid, readList.getKey(), readList.getVersion().getBlockNum(), readList.getVersion().getTxNum()); 191 | } 192 | 193 | rsid = -1; 194 | for (KvRwset.KVWrite writeList : rws.getWritesList()) { 195 | rsid++; 196 | String valAsString = printableString(new String(writeList.getValue().toByteArray(), "UTF-8")); 197 | out("Namespace %s write set[%d]: key[%s]=value[%s]", namespace, rsid, writeList.getKey(), valAsString); 198 | } 199 | } 200 | } catch (InvalidArgumentException e) { 201 | // TODO Auto-generated catch block 202 | e.printStackTrace(); 203 | } catch (InvalidProtocolBufferException e) { 204 | // TODO Auto-generated catch block 205 | e.printStackTrace(); 206 | } catch (UnsupportedEncodingException e) { 207 | // TODO Auto-generated catch block 208 | e.printStackTrace(); 209 | } 210 | } 211 | 212 | private static String printableString(final String string) { 213 | int maxLogStringLength = 64; 214 | if (string == null || string.length() == 0) { 215 | return string; 216 | } 217 | 218 | String ret = string.replaceAll("[^\\p{Print}]", "?"); 219 | ret = ret.substring(0, Math.min(ret.length(), maxLogStringLength)) + (ret.length() > maxLogStringLength ? "..." : ""); 220 | return ret; 221 | } 222 | 223 | private static SampleEnrollment loadEnrollment(String certFile, String privateKeyFile) throws Exception { 224 | String cert = getCert(certFile); 225 | PrivateKey privateKey = getPemPrivateKey(privateKeyFile); 226 | 227 | return new SampleEnrollment(cert, privateKey); 228 | } 229 | 230 | private static String getCert(String certFile) throws IOException { 231 | File f = new File(certFile); 232 | String publicKeyPEM = Files.asCharSource(f, CHARSET).read(); 233 | return publicKeyPEM; 234 | } 235 | 236 | private static PrivateKey getPemPrivateKey(String privateKeyFile) throws Exception { 237 | File f = new File(privateKeyFile); 238 | String privKeyPEM = Files.asCharSource(f, CHARSET).read(); 239 | 240 | privKeyPEM = privKeyPEM.replace("-----BEGIN PRIVATE KEY-----", ""); 241 | privKeyPEM = privKeyPEM.replace("-----END PRIVATE KEY-----", ""); 242 | log.info("privateKey: " + privKeyPEM); 243 | 244 | Base64 b64 = new Base64(); 245 | byte [] decoded = b64.decode(privKeyPEM); 246 | 247 | PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(decoded); 248 | KeyFactory kf = KeyFactory.getInstance("EC"); 249 | return kf.generatePrivate(spec); 250 | } 251 | 252 | private static void blockWalker(HFClient client, Channel channel) throws InvalidArgumentException, ProposalException, IOException { 253 | try { 254 | BlockchainInfo channelInfo = channel.queryBlockchainInfo(); 255 | out("block chain height: %d", channelInfo.getHeight()); 256 | out("current block hash: %s", Hex.encodeHexString(channelInfo.getCurrentBlockHash())); 257 | out("previous block hash: %s", Hex.encodeHexString(channelInfo.getPreviousBlockHash())); 258 | 259 | for (long current = channelInfo.getHeight() - 1; current > -1; --current) { 260 | BlockInfo returnedBlock = channel.queryBlockByNumber(current); 261 | final long blockNumber = returnedBlock.getBlockNumber(); 262 | 263 | out("current block number %d has data hash: %s", blockNumber, Hex.encodeHexString(returnedBlock.getDataHash())); 264 | out("current block number %d has previous hash id: %s", blockNumber, Hex.encodeHexString(returnedBlock.getPreviousHash())); 265 | out("current block number %d has calculated block hash is %s", blockNumber, Hex.encodeHexString(SDKUtils.calculateBlockHash(client, 266 | blockNumber, returnedBlock.getPreviousHash(), returnedBlock.getDataHash()))); 267 | 268 | out("current block number %d has %d envelope count:", blockNumber, returnedBlock.getEnvelopeCount()); 269 | int i = 0; 270 | for (BlockInfo.EnvelopeInfo envelopeInfo : returnedBlock.getEnvelopeInfos()) { 271 | ++i; 272 | 273 | out(" Transaction number %d has transaction id: %s", i, envelopeInfo.getTransactionID()); 274 | final String channelId = envelopeInfo.getChannelId(); 275 | 276 | out(" Transaction number %d has channel id: %s", i, channelId); 277 | out(" Transaction number %d has epoch: %d", i, envelopeInfo.getEpoch()); 278 | out(" Transaction number %d has transaction timestamp: %tB % roles; 19 | 20 | public SampleUser(String name, String mspId, String affiliation, SampleEnrollment enrollment) { 21 | this.name = name; 22 | this.mspId = mspId; 23 | this.affiliation = affiliation; 24 | this.enrollment = enrollment; 25 | } 26 | 27 | @Override 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | @Override 33 | public Set getRoles() { 34 | return roles; 35 | } 36 | 37 | @Override 38 | public String getAccount() { 39 | return account; 40 | } 41 | 42 | @Override 43 | public String getAffiliation() { 44 | return affiliation; 45 | } 46 | 47 | @Override 48 | public Enrollment getEnrollment() { 49 | return enrollment; 50 | } 51 | 52 | @Override 53 | public String getMspId() { 54 | return mspId; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | --------------------------------------------------------------------------------