In the past half century, the occurrence of catastrophes in the world has increased exponentially in terms of both the number of times and the amount of losses. The disaster with a small probability and a huge loss undoubtedly has an important influence on the national economy. According to statistics, the economic losses caused by the disaster have been close to five thousandths of the world's gross national product.
From a worldwide perspective, although the nature of the disaster and the location of the disaster vary from year to year, the total amount of loss and the total amount of government disaster relief is a stable large amount, but still can not meet the needs of disaster relief and recovery of production. It needs to be supplemented by private fund-raising or cross-border institutional contributions. Drawing on economic means such as bond financing in the financial industry, it is the design background of this project to support the government or regional institutions to introduce market mechanisms in disaster relief through the construction of convenient technology platforms, and to ensure the financial support required for disaster recovery through a series of financing means such as securitization.
The main purpose of the project is to build a multi-subject disaster financing network for cross-border and cross-regional, which is composed of institutions that undertake the relevant functional division of labor, and can provide individual users with relevant data-based query and public-facing authorized information release sharing function.
Disaster financing network can be based on volcanic, earthquake, tsunami and other catastrophic events to support related asset injection, bond issuance, financial leasing, special purpose institutions (SPV) generation, asset package securitization and reinsurance and other complex financial assets operation.
In the financing of disaster prevention and disaster reconstruction, the use of financial instruments on the basis of sovereign disaster relief assets or private fund-raising to carry out adequate resource integration and effective use of funds. The project builds a hybrid account book of multi-subject disaster relief assets injection and private fund-raising bonds across borders and regions through distributed ledger technology supported by blockchain technology. Build a trusted financing collaboration network across borders and regions based on multi-body collaboration engine technology based on smart contracts.Take advantage of technical features such as blockchain technology transparency, mutual trust, traceability, and distributed certificates.
Typical scenario application process:
Any relevant region or organization may use this project to raise funds, manage and refinance more complex assets during the disaster prevention and disaster reconstruction phase, securitization of assets and reinsurance.
The project is currently based primarily on the Fabric project in IBM's Hyper Ledger; User management and authentication part of the Bank of Communications self-research authentication platform implementation. In the future, complex scenarios such as leases and transactions based on blockchain-based financing targets can be considered in practice, and further functional design for the disclosure of financing asset information can be carried out on an ongoing basis.
Attention: The API documents and codes are written in Chinese.
Hyperledger Fabric 官方文档请参见这里。
Hyperledger Fabric 例子请参见这里。
可以在test目录中简单运行以下命令安装chaincode
node install_chaincode.js
使用cli
安装时,请将src
目录放在peer
节点的GOPATH
目录下。
使用Node.js SDK安装时,请注意指定process.env.GOPATH
路径为src
的父目录。
升级chaincode请按照如下步骤进行:
- 重新指定
install_chaincode.js
中chaincode的版本号chaincode_ver
- 执行
node install_chaincode.js
安装chaincode - 执行
node upgrade_chaincode.js
升级chaincode
成功后,执行docker ps
命令,可看到升级前后的两个chaincode均在运行。
可以通过以下简单的方法测试chaincode是否可正常install、instantiate以及调用逻辑。
- 安装Hyperledger Fabric Samples项目
- 启动Hyperledger Fabric Samples项目的
basic-network
- 到
test
目录中执行命令
npm install
- 模块安装完成后,使用node命令执行
test
目录中的测试脚本
- 执行
docker ps -a
,找到需要删除的chaincode容器IDCONTAINER ID
,一般容器对应的IMAGE名称形如dev-peer0.org1.example.com-test_abs_ledger-v0.0.1-9e60b9a5b79bd167dce10ae0550d0761dfaec438b76b117c837eee4bec3cb7f2
- 执行
docker rm ${CONTAINER ID}
来删除容器,${CONTAINER ID}
为第1步找到的CONTAINER ID
- 执行
docker images
,找到需要删除的镜像IDIMAGE ID
- 执行
docker rmi ${IMAGE ID}
删除镜像
调用chaincode的方法、参数和详细说明,请参见API文档。
dfn.go
主要作用是实现Chaincode
接口,包含:
- Init
- Invoke
二次开发添加新的Invoke
方法后,注意添加到dfn.go
中去。
dfn.go
主要提供以下能力:
- read: 通过
key
获取资产的能力 - get_history: 通过
key
获取资产历史的能力
lib.go
为工具文件,提供以下能力:
- GetAllObjectsByDocType: 通过传入分页参数和DocType分页查询某个种类的资产全部内容
- GetQueryResult: 使用
stub.GetQueryResult
接口查询并转换结果为[]byte - ConvQueryResult: 将查询结果类型
shim.StateQueryIteratorInterface
转换为[]byte - ConvHistoryResult: 将查询结果
shim.HistoryQueryIteratorInterface
转换为[]byte - UpdateStruct: 传入需要更新的Struct的指针,以及需要更新的字段名
key
(首字母可以为小写)和值value
,更新结构体。如果出现Struct定义以外的字段名或字段是受保护的字段(如id)等情况,将会返回非nil
的error
- SanitizePagingArgument: 检查并返回分页参数,如果参数有误,将会返回非
nil
的error
定义智能合约中的资产信息结构,以及对资产操作的方法。
定义智能合约中的工作流,以及对工作流定义操作的方法。
定义智能合约中的工作流流程实例,以及对流程实例操作的方法。
rsa.go
提供RSA加密存储工具,可直接使用encrypt_data
和decrypt_data
方法测试/执行加解密操作,也可使用rsa.go
提供的工具为自己的chaincode方法提供加解密支持。
详见API文档。