Skip to content
This repository has been archived by the owner on Jan 16, 2020. It is now read-only.

ichaobuster/disaster-financing-network-chaincode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About DNF: Disaster Financing Network

Background

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.

Key

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.

Introduce

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.

Flow Chart

Typical scenario application process:

Value

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.

Roadmap

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 官方文档请参见这里

Hyperledger Fabric 例子请参见这里

关于安装 chaincode

可以在test目录中简单运行以下命令安装chaincode

node install_chaincode.js

使用cli安装时,请将src目录放在peer节点的GOPATH目录下。

使用Node.js SDK安装时,请注意指定process.env.GOPATH路径为src的父目录。

关于升级 chaincode

升级chaincode请按照如下步骤进行:

  1. 重新指定install_chaincode.js中chaincode的版本号chaincode_ver
  2. 执行node install_chaincode.js安装chaincode
  3. 执行node upgrade_chaincode.js升级chaincode

成功后,执行docker ps命令,可看到升级前后的两个chaincode均在运行。

关于测试 chaincode

可以通过以下简单的方法测试chaincode是否可正常install、instantiate以及调用逻辑。

  1. 安装Hyperledger Fabric Samples项目
  2. 启动Hyperledger Fabric Samples项目的basic-network
  3. test目录中执行命令
npm install
  1. 模块安装完成后,使用node命令执行test目录中的测试脚本

关于移除 chaincode 容器和镜像

  1. 执行docker ps -a,找到需要删除的chaincode容器IDCONTAINER ID,一般容器对应的IMAGE名称形如dev-peer0.org1.example.com-test_abs_ledger-v0.0.1-9e60b9a5b79bd167dce10ae0550d0761dfaec438b76b117c837eee4bec3cb7f2
  2. 执行docker rm ${CONTAINER ID}来删除容器,${CONTAINER ID}为第1步找到的CONTAINER ID
  3. 执行docker images,找到需要删除的镜像IDIMAGE ID
  4. 执行docker rmi ${IMAGE ID}删除镜像

API

调用chaincode的方法、参数和详细说明,请参见API文档

修改代码的说明

dfn.go

dfn.go主要作用是实现Chaincode接口,包含:

  • Init
  • Invoke

二次开发添加新的Invoke方法后,注意添加到dfn.go中去。

API文档

read_ledger.go

dfn.go主要提供以下能力:

  • read: 通过key获取资产的能力
  • get_history: 通过key获取资产历史的能力

lib.go

lib.go为工具文件,提供以下能力:

  • GetAllObjectsByDocType: 通过传入分页参数和DocType分页查询某个种类的资产全部内容
  • GetQueryResult: 使用stub.GetQueryResult接口查询并转换结果为[]byte
  • ConvQueryResult: 将查询结果类型 shim.StateQueryIteratorInterface转换为[]byte
  • ConvHistoryResult: 将查询结果shim.HistoryQueryIteratorInterface转换为[]byte
  • UpdateStruct: 传入需要更新的Struct的指针,以及需要更新的字段名key(首字母可以为小写)和值value,更新结构体。如果出现Struct定义以外的字段名或字段是受保护的字段(如id)等情况,将会返回非nilerror
  • SanitizePagingArgument: 检查并返回分页参数,如果参数有误,将会返回非nilerror

project.go

定义智能合约中的资产信息结构,以及对资产操作的方法。

workflow.go

定义智能合约中的工作流,以及对工作流定义操作的方法。

process.go

定义智能合约中的工作流流程实例,以及对流程实例操作的方法。

rsa.go

rsa.go提供RSA加密存储工具,可直接使用encrypt_datadecrypt_data方法测试/执行加解密操作,也可使用rsa.go提供的工具为自己的chaincode方法提供加解密支持。

详见API文档

About

Documents and codes for Disaster Financing Network.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published