Skip to content

fabric-smart-client · API 参考

Go API

View 接口

来源:platform/view/view/view.go:10-14

go
type View interface {
    Call(context Context) (interface{}, error)
}

Context 接口

来源:platform/view/view/context.go:95-138platform/view/services/view/view.go:24ViewContext = view.Context 别名引用)。

go
type Context interface {
    SpanStarter
    GetService(v interface{}) (interface{}, error)
    ID() string
    RunView(view View, opts ...RunViewOption) (interface{}, error)
    Me() Identity
    IsMe(id Identity) bool
    Initiator() View
    GetSession(caller View, party Identity, boundToViews ...View) (Session, error)
    GetSessionByID(id string, party Identity) (Session, error)
    Session() Session
    Context() context.Context
    OnError(callback func())
}

Session 接口

来源:platform/view/view/session.go:65-85

go
type Session interface {
    Info() SessionInfo
    Send(payload []byte) error
    SendWithContext(ctx context.Context, payload []byte) error
    SendError(payload []byte) error
    SendErrorWithContext(ctx context.Context, payload []byte) error
    Receive() <-chan *Message
    Close()
}

Send / Receive 的用法见 integration/fsc/pingpong/README.md:41-134

Identity 类型

来源:platform/view/view/identity.go:14platform/common/services/identity/identity.go:15

Identityidentity.Identity 的别名,底层为 []byte,包装更低层身份(X.509 证书、ECDSA 公钥、Idemix 身份等,见 docs/core-concepts.md:75-77)。

Registry 方法

来源:platform/view/services/view/registry.go

方法行号说明
RegisterFactory(id string, factory Factory) error45-52注册 View 工厂
NewView(id string, in []byte) (view.View, error)54-70创建 View 实例
RegisterResponder(responder view.View, initiatedBy any) error81-83注册响应者
RegisterResponderWithIdentity(responder view.View, id view.Identity, initiatedBy any) error86-95带身份注册
GetResponder(initiatedBy any) (view.View, error)99-130查响应者
GetRegistry(sp services.Provider) *Registry237取 Registry 单例

Factory 接口

来源:platform/view/services/view/factory.go:14-17

go
type Factory interface {
    NewView(in []byte) (view.View, error)
}

ViewManager 接口

来源:platform/view/services/view/grpc/server/vm.go:16-25

go
type ViewManager interface {
    NewView(id string, in []byte) (view.View, error)
    InitiateView(ctx context.Context, view view.View) (any, error)
    InitiateContext(ctx context.Context, view view.View) (view.Context, error)
    DeleteContext(contextID string)
}

Common driver 接口

来源:platform/common/driver/。详见 04-modules · platform/common/driver

gRPC

View Service

来源:platform/view/services/view/grpc/server/protos/service.proto:16-24

ViewService 暴露两个 RPC:

  • ProcessCommand(SignedCommand) returns (SignedCommandResponse)(单次命令)
  • StreamCommand(stream SignedCommand) returns (stream SignedCommandResponse)(双向流)

通信消息

来源:platform/view/services/comm/messages.proto

  • ViewPacket 等(具体字段 [未核])

其它 Proto

文件用途
commands.proto命令消息
test.proto测试 proto(platform/view/services/grpc/testdata/testpb/
next.proto基准测试 proto(integration/benchmark/grpc/remote/

CLI — fsccli

来源:cmd/fsccli/main.go:24-31

fsccli                  # 根命令(line 24)
├── artifactgen         # (line 26)
├── cryptogen           # (line 27)
├── view                # View 服务客户端(line 28)
├── hsm                 # HSM 支持(line 29)
├── validate            # (line 30)
└── version             # (line 31)

各子命令均以 NewCmd() / Cmd() 注册(main.go:26-31);view 子命令源码:platform/view/services/view/grpc/client/cmd

完整子命令文档:docs/reference/fsc-cli.md [未核]。

Node CLI

来源:docs/reference/node-cli.md [未核]、node/start/start.go

具体命令 [未核]。

Makefile target

详见 03-quickstart。完整列表运行 make helpMakefile:25-28)。

集成测试 API

来源:integration/

函数 / 类型出处
integration.Generate(startPort, topology...)integration/fsc/pingpong/README.md:343-352
ii.Start()
ii.Client(name)
client.CallView(id, input)
fsc.NewTopology()integration/fsc/pingpong/README.md:205-218
topology.AddNodeByName(name)
node.SetExecutable(...) / node.RegisterResponder(responder, initiator)

具体类型签名 [未核]。