本文基于链桨开源master分支,分析xdb模块代码。最新commit为 4e59e197e7ca92e5560ebc0f945023eb500d238c

xdb是基于区块链的去中心化存储系统,实现了文件存储、文件摘要上链、副本保持证明、健康状态监控、文件迁移等功能。xdb代码结构如下图所示:

blockchain模块

blockchain模块实现了xdb与区块链网络的交互。xdb暂时支持Xuperchain(xchain)和Fabric,以xchain为例:

xchain.go中实现了xchain客户端初始化相关功能

```gotype XChain struct {ContractNamestringContractAccount stringChainName string Account *account.AccountXchainClient*xchain.XuperClient}​// New creates a XChain client which is used for connecting and requesting blockchainfunc New(conf *config.XchainConf) (*XChain, error) {if len(conf.Mnemonic) == 0 {return nil, errorx.New(errorx.ErrCodeConfig, "missing mnemonic")}...}

client模块

client模块是xdb的客户端工具,可通过该模块和xdb server交互,具体实现详见 client/http/http.go

cmd模块

cmd模块是xdb的命令行工具,通过client请求server服务支持如下功能:

具体用法详见 cmd/client/README.md