1 Star 0 Fork 8

Kerbores / fabric-net-server

forked from Aberic / fabric-net-server 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

注意: 这是一个依赖于已经部署好的HyperLedger Fabric项目,关于前者搭建部署的方案可以通过参考从零开始或购买开发实战等途径学习。Fabric环境部署等都不在当前项目的支持范围内,未来也许会计划开发一套基于Fabric深度定制的一键部署及管理平台(非K8S)。

Fabric Net Server fabric-sdk image

version apache 2 codebeat badge Join the chat at https://gitter.im/fabric-net-server/Lobby

本项目目前提供一套Fabric网络后台服务,包括对已经在Fabric网络中创建好的org、peer、channel、chaincode等进行网络新增,并基于已经新增成功的内容提供REST API服务,目前支持合约安装、实例化、执行、查询以及溯源功能,未来计划支持后台动态加入通道等基于fabric-sdk-java已有接口的实现。

本项目开发环境和框架大致有:IntelliJ IDEA、Maven、JDK8+、spring-boot、thymeleaf以及Docker等。具体实践可使用项目中提供的Docker镜像部署,也可以自定义源码二次开发。

由于个人人力实在有限,后面的工程和工作量会逐步变大变多,在保证个人工作顺利的情况下,会将大部分精力都投入到本项目中。

项目预览

后台首页界面预览
首页视图

api执行介绍界面预览

首页视图

api执行结果及使用方案界面预览
首页视图

版本说明

1、如有源码学习需要的,可以参阅v0.1或含MySQL数据库的v0.2版本。
2、从v1.0-RC开始提供后台视图服务,之前的beta版仅提供接口方案。
3、如有二次开发需求,建议以v0.1为蓝本。
4、下一版计划实现安装、实例化智能合约及加入通道等功能。

版本历史


version Description
v0.1 无数据库版,适合轻量级的Fabric平台应用。
v0.2 含关系型数据库版,适合单服务管理多Fabric网络。
v1.0-alpha 提供Docker容器服务,方便SDK快速部署。此版本为单排序服务及单节点服务配置,符合绝大部分需求。
v1.0-beta 新增支持多服务节点。
v1.0-beta2 修复重新新增组织、排序服务和节点服务的bug;提供更新组织、排序服务和节点服务的接口;新增Swagger2文档支持。
v1.0-beta3 删除docker-sdk.yaml环境变量配置,取消hash标识(容易被误会),细化Fabric网络及数据库结构,简化启动脚本。
v1.0-RC1 提供后台视图服务,结构解耦度高,相对灵活,需部署多镜像
v1.0-RC2 新增智能合约安装、实例化功能,结构增加耦合,部署难度降低



使用

1、确定Linux内核在3.10及以上。
2、在待部署SDK服务器上安装Dockerdocker compose环境。
3、执行docker pull aberic/fabric-edge:1.0-RC2下载镜像。
4、编辑docker-fabric-net-server.yaml,主要目的就是选择你所计划启用的物理机端口号。
5、执行docker-compose -f docker-fabric-net-server.yaml up启动镜像,如不需要观察日志,则在命令最后追加-d即可。
6、服务启动完成后,通过http://localhost:port 访问即可。
7、后台部署可参考由微信群的Larryleo5编写的详细说明文档

docker-fabric-net-server.yaml说明

version: '2'

services:

  edge:
    container_name: edge
    image: aberic/fabric-edge
    command: bash /home/init-edge.sh
    ports:
      - 8080:8080

1、上述配置主要关注自己的端口映射,edge的端口号决定了项目访问的最终地址。
2、yaml启动需要指定镜像版本号,或tag镜像版本号为latest。

架构(请无视小图标)

FabricNet
如上图,需要对Fabric网络有一个简单的理解一致,并对以下几个点说明一下:
1、一个Fabric网络即是一个league(联盟链),一个league包含一个或多个org(组织)且含有不少于一个orderer(排序服务),一个org包含一个或多个peer(节点服务),一个peer可以加入一个或多个channel(通道),一个channel可以安装一个或多个chaincode(智能合约)。
2、根据1所述,仅有league对象集合查询不需要指定id。org集合查询需要指定联盟id,orderer及peer集合查询需要指定orgId,channel集合查询需要指定peerId,chaincode集合查询需要指定channelId。
3、可以根据某一个chaincode逆向查出该chaincode的整个league网络,因此执行state和trace接口时只需要传入chaincodeId即可。
4、执行state接口中的strArray是调用Fabric网络中部署的chaincode所传入的参数,在用go编写chaincode的时候,chaincode所接收的参数为一个字符串数组,其中字符串数组的第一个参数是chaincode的方法名。chaincode接口中的args所传入的参数就是智能合约所接收的数组参数。如chaincode_example02中执行invoke时传入的参数为["invoke", "a", "b", "10"],那么在本项目中执行state接口时传入的参数即为[invoke,a,b,10],与Fabric网络中安装的chaincode所需参数保持一致,实现与业务解耦,仅用于维护Fabric项目和做业务与chaincode的桥梁,不参与实际业务当中。
5、执行trace接口可使用项目中在chaincode管理中提供的测试工具进行测试,上一步中的操作也可以通过该方法测试,测试结果会将正确的请求方式显示出来,以便对外提供服务。
6、Fabric网络新增操作必须遵循第2点所述,即必须从league开始新增,直到最后新增chaincode。
7、新增org中需要上传用zip压缩的crypto-config目录,crypto-config二进制生成的证书文件目录。目录下的内容可参考crypto-config.dir,配置方案可参考crypto-config

对象新建字段部分释义

league、org、orderer、peer、channel及chaincode中后台创建所需的字段有如下表中释义:

Params Description Map
ORG_NAME 节点所属组织名称 参见crypto-config文件中 -> PeerOrgs-Name
ORG_TLS 节点是否开启TLS 根据自身创建网络情况选择true或false
ORG_USERNAME 节点所属组织用户名称 参见crypto-config目录下的两个用户,默认配置中选择的Admin
ORG_CRYPTO_CONFIG_DIR 映射到容器中的crypto-config目录 crypto-config目录
ORG_MSP_ID 节点所属组织ID 参见configtx文件中 -> Organizations-&Org1-Name
ORG_DOMAIN_NAME 节点所属组织域名名称 参见crypto-config文件中 -> PeerOrgs-Domain
ORG_ORDERER_DOMAIN_NAME 节点所属排序服务域名名称 参见crypto-config文件中 -> OrdererOrgs-Domain
ORDERER_NAME 排序服务名称 参见configtx文件中 -> Orderer-Addresses
ORDERER_LOCATION 排序服务访问路径 根据自身设置实际情况修改,一般为grpc://host:port的格式
PEER_NAME 节点服务域名名称 参见crypto-config目录下的节点域名列表
PEER_EVENT_HUB_NAME 节点服务事件域名名称 同上
PEER_LOCATION 节点服务路径 根据自身设置实际情况修改,一般为grpc://host:port的格式
PEER_EVENT_HUB_LOCATION 节点服务事件路径 根据自身设置实际情况修改,一般为grpc://host:port的格式
PEER_IS_EVENT_LISTENER 节点所属组织名称 根据自身需求选择是否监听回调服务
CHANNEL_NAME 自行创建的通道名称 如:peer channel create -o orderer.example.com:7050 -c mychannel -t 50 -f ./channel-artifacts/mychannel.tx 命令所创建的mychannel
CHAINCODE_NAME 智能合约名称 如:peer chaincode install -n testcc -p github.com/hyperledger/fabric/aberic/chaincode/go/chaincode_example02 -v 1.0 命令所创建的testcc
CHAINCODE_PATH 智能合约路径 如:peer chaincode install -n testcc -p github.com/hyperledger/fabric/aberic/chaincode/go/chaincode_example02 -v 1.0 命令中的github.com/hyperledger/fabric/aberic/chaincode/go/chaincode_example02
CHAINCODE_VERSION 智能合约版本 如:peer chaincode install -n testcc -p github.com/hyperledger/fabric/aberic/chaincode/go/chaincode_example02 -v 1.0 命令中的1.0
CHAINCODE_PROPOSAL_WAIT_TIME 单个提案请求超时时间以毫秒为单位 默认90000
CHAINCODE_INVOKE_WAIT_TIME 事务等待时间以秒为单位 默认120

API参考

Method REST API Description
POST /state/invoke 执行智能合约
POST /state/query 查询智能合约
POST /trace/hash 根据交易hash查询区块
POST /trace/number 根据交易区块高度查询区块
POST /trace/txid 根据交易ID查询区块
GET /trace/info/{id} 根据当前智能合约id查询当前链信息

如果有SaaS/BaaS服务的紧急需求,可以自行参考v0.1中的方案来解决。

讨论


社群

  • 扫微信订阅号加入:

HLFStudy

入门书籍

《HyperLedger Fabric开发实战——快速掌握区块链技术》

HyperLedger Fabric开发实战

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

HyperLedger/Fabric Net Server 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/ixion/fabric-net-server.git
git@gitee.com:ixion/fabric-net-server.git
ixion
fabric-net-server
fabric-net-server
master

搜索帮助