Skip to content

fabric-token-sdk · API 参考

CLI

tokengen

来源:cmd/tokengen/main.go:25-59

五个子命令均直接挂在 tokengen 根命令下(同级,非嵌套)。

子命令注册位置用途
genpp.GenCmd() line 55生成公共参数(含按驱动的子命令 fabtoken.v1 / zkatdlognogh.v1
updatepp.UpdateCmd() line 56更新公共参数
pppp.UtilsCmd() line 57公共参数工具(子命令 print:检视公共参数)
certifier-keygencertfier.KeyPairGenCmd() line 58生成证书密钥对
versionversion.Cmd() line 59版本

env 前缀:core(line 21)。

具体 flag [未核] —— 运行 tokengen --help

artifactgen

来源:cmd/artifactgen/main.go:19-48

子命令注册位置
artifactsgen.Cmd() line 48

env 前缀:core(line 19)。

Go API — token/ 入口

ManagementService(TMS)

来源:token/tms.go:38type ManagementService struct)。

TMS 主入口。主要方法:NewRequest(line 120)、Validator(150)、Vault(155)、WalletManager(160)、PublicParametersManager(180)、SelectorManager(190)、SigService(195)、ID(200)。

Token 数据模型

来源:token/token/token.go

类型行号
TokenOwner / Type / Quantity42
IDTxId / Index16

Request

来源:token/request.go:224

聚合多个 action 的令牌请求;提供 Issue(line 286)/ Transfer(line 347)/ Redeem(line 399)等构造方法。Redeem 返回 *TransferAction

Wallet / Vault

通过 token/sdk/ 暴露;TMS 经 WalletManager / Vault 访问。

Go API — token/services/ttx

来源:token/services/ttx/transaction.go

业务层最常用的事务构造接口:

方法行号
Transaction.Issue279
Transaction.Transfer286
Transaction.Redeem293

底层委托给 token/request.goRequest.Issue / Transfer / Redeem

Go API — token/driver

来源:token/driver/

Action 接口(token/driver/action.go

go
// IssueAction — line 20(内嵌 Action + ActionWithInputs)
type IssueAction interface {
    Action
    ActionWithInputs
    Serialize() ([]byte, error)
    NumOutputs() int
    GetSerializedOutputs() ([][]byte, error)
    GetOutputs() []Output
    IsAnonymous() bool
    GetIssuer() []byte
    GetMetadata() map[string][]byte
    IsGraphHiding() bool
    ExtraSigners() []Identity
}

// TransferAction — line 62(内嵌 Action + ActionWithInputs)
type TransferAction interface {
    Action
    ActionWithInputs
    Serialize() ([]byte, error)
    NumOutputs() int
    GetSerializedOutputs() ([][]byte, error)
    GetOutputs() []Output
    IsRedeemAt(index int) bool
    SerializeOutputAt(index int) ([]byte, error)
    IsGraphHiding() bool
    GetMetadata() map[string][]byte
    GetIssuer() Identity
}

// Output — line 50
type Output interface {
    Serialize() ([]byte, error)
    IsRedeem() bool
    GetOwner() []byte
}

Token 服务(token/driver/tokens.go

go
// TokensService — line 52
type TokensService interface {
    SupportedTokenFormats() []token.Format
    Deobfuscate(ctx context.Context, output TokenOutput, outputMetadata TokenOutputMetadata) (*token.Token, Identity, []Identity, token.Format, error)
    Recipients(output TokenOutput) ([]Identity, error)
}

// TokensUpgradeService — line 34
type TokensUpgradeService interface {
    NewUpgradeChallenge() (TokensUpgradeChallenge, error)
    GenUpgradeProof(ctx context.Context, ch TokensUpgradeChallenge, tokens []token.LedgerToken, witness TokensUpgradeWitness) (TokensUpgradeProof, error)
    CheckUpgradeProof(ctx context.Context, ch TokensUpgradeChallenge, proof TokensUpgradeProof, tokens []token.LedgerToken) (bool, error)
}

services 接口

各 service 暴露的 Go 接口在对应包内。详见 04-modules · token/services/docs/services.md

具体接口签名 [未核] —— 需逐个包阅读。

Driver 实现包

FabToken

路径内容
token/core/fabtoken/v1/driver/Driver 实现
token/core/fabtoken/v1/service.go:23Service
token/core/fabtoken/v1/actions/Issue / Transfer / Redeem
token/core/fabtoken/v1/validator/验证
token/core/fabtoken/v1/auditor.go:16AuditorService

ZKAT-DLOG (NOGH)

路径内容
token/core/zkatdlog/nogh/v1/driver/Driver 实现
token/core/zkatdlog/nogh/v1/crypto/密码学原语
token/core/zkatdlog/nogh/v1/issue/transfer/Issue / Transfer
token/core/zkatdlog/nogh/v1/validator/验证
token/core/zkatdlog/nogh/v1/audit/Auditor

Makefile target

详见 03-quickstart · Makefile target

网络协议

无独立 REST / gRPC 端点。token-sdk 通过 fabric-smart-client View 协议与对等方通信,并通过 Network Service 与 Fabric / Fabric-X 交互。具体 [未核]。