Skip to content

fabric-smart-client · 快速开始

TIP

完整指引见 docs/README.mddocs/core-concepts.md。本章只列 Makefile 与 README 中可验证的命令。

工具安装

来源:Makefile:34-61

目标行号用途
make install-tools34-38tools/tools.go 安装所有工具
make install-linter-tool40-43golangci-lint v2.11.4
make install-fabricx-tools45-49fxconfigconfigtxgencryptogen(Fabric-x)
make install-fabric-bins51-53调用 ci/scripts/download_fabric.sh(默认 3.1.4)
make install-softhsm55-57ci/scripts/install_softhsm.sh
make install-fsccli59-61go install ./cmd/fsccli

版本(Makefile:8-12):

变量
FABRIC_VERSION3.1.4
FABRIC_TWO_DIGIT_VERSIONFABRIC_VERSION 取前两段 → 3.1
FABRIC_X_TOOLS_VERSIONv1.0.0
FABRIC_X_COMMITTER_VERSION1.0.0

Proto 编译

来源:Makefile:67-69

sh
make protos    # 调用 ./scripts/compile_proto.sh

拉取依赖镜像

来源:Makefile:74-100

目标行号用途
make docker-images76拉取 fabric + 监控 + 测试镜像(不含 fabricx)
make fabric-docker-images78-83fabric-baseos、fabric-ccenv(3.1)
make fabricx-docker-images85-87fabric-x-committer-test-node(1.0.0)
make monitoring-docker-images89-94explorer-db / explorer / prometheus / grafana(:latest)、jaeger(2.12.0)
make testing-docker-images97-100postgres(16.2-alpine)

示例:Ping Pong

来源:integration/fsc/pingpong/README.md

Initiator View(README.md:41-71,节选):

go
type Initiator struct{}
func (p *Initiator) Call(viewCtx view.Context) (interface{}, error) {
    responder := view2.GetIdentityProvider(viewCtx).Identity("responder")
    session, _ := viewCtx.GetSession(viewCtx.Initiator(), responder)
    session.Send([]byte("ping"))
    ch := session.Receive()
    // ...
}

Responder View(README.md:102-134,节选):

go
type Responder struct{}
func (p *Responder) Call(viewCtx view.Context) (interface{}, error) {
    session := viewCtx.Session()
    // 读 "ping",回 "pong"
}

网络拓扑(README.md:205-218):

go
func Topology() []nwo.Topology {
    topology := fsc.NewTopology()
    topology.AddNodeByName("initiator").SetExecutable(...)
    topology.AddNodeByName("responder").RegisterResponder(&Responder{}, &Initiator{})
    return []nwo.Topology{topology}
}

集成测试入口(README.md:343-352):

go
ii, _ := integration.Generate(StartPort2(), pingpong.Topology()...)
ii.Start()
initiator := ii.Client("initiator")
res, _ := initiator.CallView("init", nil)

其它示例

来源:integration/

目录示例
integration/fabric/iouatsaeventsstoprestarttwonets
integration/fabricx/iousimplemultiendorsementdeployment
integration/fsc/pingpongstoprestart
integration/benchmark/grpc/remotenode/remoteviews
integration/nwo/网络编排框架
integration/reporting/prometheusjaeger

IOU / ATSA 等示例的功能描述 [未核] —— 需逐一读其 README。

下一步