pool
import "github.com/bsv8/go-bitfs/pool"
pool 包提供 002、005 和 006 使用的、与业务协议无关的 2-of-3 结算原语。它验证按角色排序的 MultisigPool v4 字节,跟踪单调递增的支付状态并暴露存储/节点端口;它有意不导入 BitFS 报价或内容类型。
索引
- 常量
- 变量
- 函数 Build2of3LockingScript(pubkeys [][]byte) ([]byte, error)
- 函数 BuildPoolLock(roles mp.ArbitratedPoolRoles) ([]byte, error)
- 函数 EncodeFundingTxDelivery(delivery *FundingTxDelivery) ([]byte, error)
- 函数 EncodeOpeningProof(proof *OpeningProof) ([]byte, error)
- 函数 EncodePaymentUpdate(update *PaymentUpdate) ([]byte, error)
- 函数 EncodeRefundPresignRequest(request *RefundPresignRequest) ([]byte, error)
- 函数 EncodeRefundPresignResponse(response *RefundPresignResponse) ([]byte, error)
- 函数 ValidateFundingTxDelivery(delivery *FundingTxDelivery) error
- 函数 ValidateOpeningProof(proof *OpeningProof) error
- 函数 ValidatePaymentUpdate(update *PaymentUpdate) error
- 函数 ValidateRefundPresignRequest(request *RefundPresignRequest) error
- 函数 ValidateRefundPresignResponse(response *RefundPresignResponse) error
- 类型 ArbiterPoolAdapter
- 类型 BSVTransactionIDCalculator
- 类型 BuyerOpeningPort
- 函数 (port BuyerOpeningPort) LoadOpeningProof(ctx context.Context, spendTxID Hash32) (*OpeningProof, error)
- 函数 (port BuyerOpeningPort) SaveOpeningProof(ctx context.Context, proof *OpeningProof) error
- 函数 (port BuyerOpeningPort) TransactionID(ctx context.Context, rawTx []byte) (Hash32, error)
- 函数 (port BuyerOpeningPort) VerifySellerRefundSignature(ctx context.Context, request *RefundPresignRequest, signature []byte) error
- 类型 BuyerPoolAdapter
- 函数 NewBuyerPoolAdapter(engine *MultisigPoolEngine, key PrivateKeyProvider) *BuyerPoolAdapter
- 函数 (adapter *BuyerPoolAdapter) BuildRefundPresignRequest(ctx context.Context, input OpeningInput, _ Signer) (*RefundPresignRequest, error)
- 函数 (adapter *BuyerPoolAdapter) SignBuyerPayment(ctx context.Context, unsigned *UnsignedPayment, _ Signer) ([]byte, error)
- 类型 BuyerPoolOpeningHooks
- 类型 BuyerPoolPort
- 类型 CloseInput
- 类型 FileStore
- 函数 NewFileStore(path string, calculator TransactionIDCalculator) (*FileStore, error)
- 函数 (store *FileStore) EnsurePoolHealthy(ctx context.Context, spendTxID Hash32) error
- 函数 (store *FileStore) Load(ctx context.Context, spendTxID Hash32) (*PendingRequest, error)
- 函数 (store *FileStore) LoadAcceptedPayment(ctx context.Context, spendTxID Hash32) (*PaymentState, error)
- 函数 (store *FileStore) LoadOpeningProof(ctx context.Context, spendTxID Hash32) (*OpeningProof, error)
- 函数 (store *FileStore) LoadOpeningProofByFundingTxID(ctx context.Context, fundingTxID Hash32) (*OpeningProof, error)
- 函数 (store *FileStore) MarkExternalStateUncertain(ctx context.Context, spendTxID, txID Hash32) error
- 函数 (store *FileStore) ReconcileExternalState(ctx context.Context, spendTxID Hash32, state *PaymentState) error
- 函数 (store *FileStore) Release(ctx context.Context, spendTxID, requestHash Hash32) error
- 函数 (store *FileStore) SaveAcceptedPayment(ctx context.Context, state *PaymentState) error
- 函数 (store *FileStore) SaveOpeningProof(ctx context.Context, proof *OpeningProof) error
- 函数 (store *FileStore) TryAcquire(ctx context.Context, request PendingRequest) (PendingAcquireResult, error)
- 类型 FundingTxDelivery
- 类型 FundingTxVerifier
- 类型 Hash32
- 类型 MemoryStore
- 函数 NewMemoryStore(calculator TransactionIDCalculator) (*MemoryStore, error)
- 函数 (store *MemoryStore) EnsurePoolHealthy(_ context.Context, spendTxID Hash32) error
- 函数 (store *MemoryStore) Load(_ context.Context, spendTxID Hash32) (*PendingRequest, error)
- 函数 (store *MemoryStore) LoadAcceptedPayment(_ context.Context, spendTxID Hash32) (*PaymentState, error)
- 函数 (store *MemoryStore) LoadOpeningProof(_ context.Context, spendTxID Hash32) (*OpeningProof, error)
- 函数 (store *MemoryStore) LoadOpeningProofByFundingTxID(_ context.Context, fundingTxID Hash32) (*OpeningProof, error)
- 函数 (store *MemoryStore) MarkExternalStateUncertain(_ context.Context, spendTxID, txID Hash32) error
- 函数 (store *MemoryStore) ReconcileExternalState(ctx context.Context, spendTxID Hash32, state *PaymentState) error
- 函数 (store *MemoryStore) Release(_ context.Context, spendTxID, requestHash Hash32) error
- 函数 (store *MemoryStore) SaveAcceptedPayment(_ context.Context, state *PaymentState) error
- 函数 (store *MemoryStore) SaveOpeningProof(ctx context.Context, proof *OpeningProof) error
- 函数 (store *MemoryStore) TryAcquire(_ context.Context, request PendingRequest) (PendingAcquireResult, error)
- 类型 MultisigPoolAdapter
- 函数 (adapter *MultisigPoolAdapter) SignArbitrationCandidate(ctx context.Context, raw []byte, proof *OpeningProof, _ Signer) ([]byte, error)
- 函数 (adapter *MultisigPoolAdapter) VerifyArbitrationCandidate(_ context.Context, raw []byte, proof *OpeningProof, terms *bitfs.ContentRequestTerms, sellerSig []byte) (*UnsignedPayment, error)
- 函数 (adapter *MultisigPoolAdapter) VerifyOpening(proof *OpeningProof) error
- 类型 MultisigPoolEngine
- 函数 NewMultisigPoolEngine(config MultisigPoolEngineConfig) (*MultisigPoolEngine, error)
- 函数 (engine *MultisigPoolEngine) BuildImmediateClose(_ context.Context, input CloseInput) (*UnsignedPayment, []byte, error)
- 函数 (engine *MultisigPoolEngine) BuildPaymentUpdate(ctx context.Context, input PaymentUpdateInput) (*UnsignedPayment, error)
- 函数 (engine *MultisigPoolEngine) BuildRefundSubmission(proof *OpeningProof) ([]byte, error)
- 函数 (engine *MultisigPoolEngine) CheckPaymentCapacity(_ context.Context, input PaymentUpdateInput) error
- 函数 (engine *MultisigPoolEngine) FundingTxID(rawTx []byte) (Hash32, error)
- 函数 (engine *MultisigPoolEngine) ParseFinalPaymentState(ctx context.Context, rawTx []byte, proof *OpeningProof) (*PaymentState, error)
- 函数 (engine *MultisigPoolEngine) ParsePaymentState(_ context.Context, rawTx []byte, proof *OpeningProof) (*PaymentState, error)
- 函数 (engine *MultisigPoolEngine) ParseUnsignedPayment(_ context.Context, rawTx []byte, proof *OpeningProof) (*UnsignedPayment, error)
- 函数 (engine *MultisigPoolEngine) TransactionID(rawTx []byte) (Hash32, error)
- 函数 (engine *MultisigPoolEngine) VerifyAcceptedPayment(state *PaymentState, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifyArbitratedPayment(state *PaymentState, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifyBuyerPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifyCompletedFinalPayment(payment *SignedPayment, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifyFinalPayment(state *PaymentState, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifyFundingTx(_ context.Context, rawTx []byte, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifyOpening(proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifyPoolParticipants(proof *OpeningProof, buyer, seller, arbiter []byte) error
- 函数 (engine *MultisigPoolEngine) VerifyRefundExpired(proof *OpeningProof, now time.Time) error
- 函数 (engine *MultisigPoolEngine) VerifySellerPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifySellerRefundSignature(_ context.Context, request *RefundPresignRequest, signature []byte) error
- 类型 MultisigPoolEngineConfig
- 类型 NonFinalPoolBackend
- 类型 NonFinalPoolNode
- 类型 OpeningByFundingStore
- 类型 OpeningInput
- 类型 OpeningProof
- 函数 BuyerAcceptRefundPresign(ctx context.Context, request *RefundPresignRequest, response *RefundPresignResponse, fundingTx []byte, hooks BuyerPoolOpeningHooks) (*OpeningProof, error)
- 函数 CloneOpeningProof(proof *OpeningProof) *OpeningProof
- 函数 DecodeOpeningProof(data []byte) (*OpeningProof, error)
- 函数 SellerAcceptFundingTx(ctx context.Context, delivery *FundingTxDelivery, hooks SellerPoolOpeningHooks) (*OpeningProof, error)
- 类型 OpeningProofStore
- 类型 ParticipantVerifier
- 类型 PaymentState
- 类型 PaymentUpdate
- 类型 PaymentUpdateInput
- 类型 PendingAcquireResult
- 类型 PendingOpeningProofStore
- 类型 PendingRequest
- 类型 PendingRequestStore
- 类型 PoolNodeVerifierPort
- 类型 PoolRefundSigner
- 类型 PoolStore
- 类型 PrivateKeyProvider
- 类型 Reference
- 类型 RefundPresignRequest
- 类型 RefundPresignResponse
- 类型 RefundTxSignatureVerifier
- 类型 RefundTxSigner
- 类型 SellerOpeningPort
- 函数 (port SellerOpeningPort) LoadOpeningProofByFundingTxID(ctx context.Context, fundingTxID Hash32) (*OpeningProof, error)
- 函数 (port SellerOpeningPort) SaveOpeningProof(ctx context.Context, proof *OpeningProof) error
- 函数 (port SellerOpeningPort) SignRefundTx(ctx context.Context, request *RefundPresignRequest) ([]byte, error)
- 函数 (port SellerOpeningPort) SubmitTransaction(ctx context.Context, rawTx []byte) (Hash32, error)
- 函数 (port SellerOpeningPort) TransactionID(ctx context.Context, rawTx []byte) (Hash32, error)
- 函数 (port SellerOpeningPort) VerifyFundingTx(ctx context.Context, fundingTx []byte, proof *OpeningProof) error
- 类型 SellerPoolAdapter
- 函数 NewSellerPoolAdapter(engine *MultisigPoolEngine, key PrivateKeyProvider) *SellerPoolAdapter
- 函数 (adapter *SellerPoolAdapter) MergeBuyerSellerPayment(unsigned *UnsignedPayment, buyerSig, sellerSig []byte) (*SignedPayment, error)
- 函数 (adapter *SellerPoolAdapter) MergeSellerArbiterPayment(unsigned *UnsignedPayment, sellerSig, arbiterSig []byte) (*SignedPayment, error)
- 函数 (adapter *SellerPoolAdapter) SignImmediateClose(ctx context.Context, unsigned *UnsignedPayment, buyerSig []byte, _ Signer) (*SignedPayment, error)
- 函数 (adapter *SellerPoolAdapter) SignSellerArbitrationCandidate(ctx context.Context, unsigned *UnsignedPayment, _ Signer) ([]byte, error)
- 函数 (adapter *SellerPoolAdapter) SignSellerPayment(ctx context.Context, unsigned *UnsignedPayment, _ Signer) ([]byte, error)
- 函数 (adapter *SellerPoolAdapter) VerifyBuyerPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
- 函数 (adapter *SellerPoolAdapter) VerifySellerPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
- 类型 SellerPoolOpeningHooks
- 类型 SellerPoolPort
- 类型 SignatureVerifier
- 类型 SignedPayment
- 类型 Signer
- 类型 TransactionIDCalculator
- 类型 TransactionSubmitter
- 类型 UnsignedPayment
- 类型 UpdateAcceptance
- 类型 VerifiedNonFinalPoolNode
- 函数 NewVerifiedNonFinalPoolNode(engine PoolNodeVerifierPort, openings OpeningByFundingStore, backend NonFinalPoolBackend) (*VerifiedNonFinalPoolNode, error)
- 函数 (node *VerifiedNonFinalPoolNode) SubmitFinal(ctx context.Context, rawTx []byte) (Hash32, error)
- 函数 (node *VerifiedNonFinalPoolNode) SubmitUpdate(ctx context.Context, rawTx []byte) (*UpdateAcceptance, error)
常量
const (
// KindPoolRefundPresignRequest is the CBOR tag for a refund presign request.
KindPoolRefundPresignRequest uint64 = 12
// KindPoolRefundPresignResponse identifies a refund signature response.
KindPoolRefundPresignResponse uint64 = 13
// KindPoolFundingTxDelivery identifies a funding transaction delivery.
KindPoolFundingTxDelivery uint64 = 14
)
MajorVersion 是当前费用池工作流协议的主版本号。
const MajorVersion uint64 = 3
MultisigProtocol 标识内嵌的 MultisigPool 交易协议。
const MultisigProtocol = "bitfs.pool.v4"
MultisigVersion 是内嵌 MultisigPool 协议的版本号。
const MultisigVersion uint64 = 4
ProtocolFamily 是 go-bitfs 费用池工作流协议标识。它与 OpeningProof 中嵌入的 MultisigPool 库协议有意分开。
const ProtocolFamily = "bitfs.pool.workflow.v3"
变量
var (
// ErrInvalidEvidence is returned when pool evidence fails structural or protocol validation.
ErrInvalidEvidence = errors.New("invalid pool evidence")
// ErrPoolBusy indicates that a pool already has an active delivery.
ErrPoolBusy = errors.New("pool busy")
// ErrStalePaymentSequence indicates that an update does not extend current state.
ErrStalePaymentSequence = errors.New("stale payment sequence")
// ErrInsufficientBalance indicates that a payment exceeds the pool balance.
ErrInsufficientBalance = errors.New("insufficient pool balance")
// ErrNonFinalRejected indicates that the node rejected a non-final payment update.
ErrNonFinalRejected = errors.New("non-final pool rejected update")
// ErrFinalRejected indicates that the node rejected a final transaction.
ErrFinalRejected = errors.New("pool node rejected final transaction")
// ErrNotExpired indicates that the refund locktime has not yet been reached.
ErrNotExpired = errors.New("pool refund expiry has not been reached")
// ErrPoolStateUncertain indicates that node acceptance must be reconciled
// after local persistence failed.
ErrPoolStateUncertain = errors.New("pool state requires external reconciliation")
)
函数 Build2of3LockingScript
func Build2of3LockingScript(pubkeys [][]byte) ([]byte, error)
Build2of3LockingScript 委托构造按角色排序的 2-of-3 MultisigPool 锁定脚本。pubkeys 必须严格按 Buyer、Seller、Arbiter 顺序提供。
函数 BuildPoolLock
func BuildPoolLock(roles mp.ArbitratedPoolRoles) ([]byte, error)
BuildPoolLock 是公开的、明确角色的锁定适配器。它通过 v4 角色对象永久采用 Buyer、Seller、Arbiter 的参数顺序。
函数 EncodeFundingTxDelivery
func EncodeFundingTxDelivery(delivery *FundingTxDelivery) ([]byte, error)
EncodeFundingTxDelivery 验证并编码 002 注资交易交付容器。它不验证注资交易是否花费所保存的开池证明。
函数 EncodeOpeningProof
func EncodeOpeningProof(proof *OpeningProof) ([]byte, error)
EncodeOpeningProof 验证并编码完整的 002 开池证明,包括退款/注资交易字节、角色密钥和费用池参数。
函数 EncodePaymentUpdate
func EncodePaymentUpdate(update *PaymentUpdate) ([]byte, error)
EncodePaymentUpdate 验证并将 005 未签名交易及买方分离签名编码为四字段确定性 CBOR 容器。它只做结构验证,不检查节点接受或签名有效性。
函数 EncodeRefundPresignRequest
func EncodeRefundPresignRequest(request *RefundPresignRequest) ([]byte, error)
EncodeRefundPresignRequest 验证并编码 002 买方退款预签名请求,包括协议版本、退款字节、费用池输出、角色密钥、费率和买方分离签名。
函数 EncodeRefundPresignResponse
func EncodeRefundPresignResponse(response *RefundPresignResponse) ([]byte, error)
EncodeRefundPresignResponse 验证并编码卖方的 002 退款签名响应,并写入固定的协议和 MultisigPool 版本字段。
函数 ValidateFundingTxDelivery
func ValidateFundingTxDelivery(delivery *FundingTxDelivery) error
ValidateFundingTxDelivery 检查 002 交付版本并要求原始注资交易字节;它不证明这些字节花费了开池输出。
函数 ValidateOpeningProof
func ValidateOpeningProof(proof *OpeningProof) error
ValidateOpeningProof 检查 002 证明标识及必需的哈希、费用池锁、角色密钥、退款签名和注资交易字节。它只做结构检查;VerifyOpening 负责交易及签名关系检查。
函数 ValidatePaymentUpdate
func ValidatePaymentUpdate(update *PaymentUpdate) error
ValidatePaymentUpdate 检查 005 信封版本、32 字节授权哈希,以及未签名交易和买方分离签名是否存在。它不会解析交易,也不确认节点是否接受。
函数 ValidateRefundPresignRequest
func ValidateRefundPresignRequest(request *RefundPresignRequest) error
ValidateRefundPresignRequest 检查 002 请求标识、必需的注资/退款证据、角色密钥、费率和买方签名是否存在。它不会对退款交易或任一签名做密码学验证。
函数 ValidateRefundPresignResponse
func ValidateRefundPresignResponse(response *RefundPresignResponse) error
ValidateRefundPresignResponse 检查 002 响应版本并要求卖方退款签名;将其与请求匹配属于工作流操作。
类型 ArbiterPoolAdapter
ArbiterPoolAdapter 将费用池引擎适配到仲裁人工作流操作。
type ArbiterPoolAdapter struct {
*MultisigPoolEngine
Key PrivateKeyProvider
}
函数 NewArbiterPoolAdapter
func NewArbiterPoolAdapter(engine *MultisigPoolEngine, key PrivateKeyProvider) *ArbiterPoolAdapter
NewArbiterPoolAdapter 将引擎绑定到仲裁人私钥提供器,供 007 工作流为选定的候选状态签名。
函数 (*ArbiterPoolAdapter) SignArbiterPayment
func (adapter *ArbiterPoolAdapter) SignArbiterPayment(ctx context.Context, unsigned *UnsignedPayment, _ Signer) ([]byte, error)
SignArbiterPayment 为未签名费用池交易生成仲裁人分离签名。
类型 BSVTransactionIDCalculator
BSVTransactionIDCalculator 将同步参考引擎适配到支持 context 的开池工作流端口。生产应用可以替换为数据库支持的计算器或节点/SDK 实现。
type BSVTransactionIDCalculator struct {
Engine *MultisigPoolEngine
}
函数 (BSVTransactionIDCalculator) TransactionID
func (calculator BSVTransactionIDCalculator) TransactionID(_ context.Context, rawTx []byte) (Hash32, error)
TransactionID 根据原始交易字节计算规范交易标识符。
类型 BuyerOpeningPort
BuyerOpeningPort 将应用存储、签名验证和交易 ID 计算适配到买方的 002 开池工作流。
type BuyerOpeningPort struct {
Store OpeningProofStore
Verifier RefundTxSignatureVerifier
Calculator TransactionIDCalculator
}
函数 (BuyerOpeningPort) LoadOpeningProof
func (port BuyerOpeningPort) LoadOpeningProof(ctx context.Context, spendTxID Hash32) (*OpeningProof, error)
LoadOpeningProof 按 spend transaction ID 加载开池证明。
函数 (BuyerOpeningPort) SaveOpeningProof
func (port BuyerOpeningPort) SaveOpeningProof(ctx context.Context, proof *OpeningProof) error
SaveOpeningProof 验证开池证明,并以 spend transaction ID 为键持久化。
函数 (BuyerOpeningPort) TransactionID
func (port BuyerOpeningPort) TransactionID(ctx context.Context, rawTx []byte) (Hash32, error)
TransactionID 根据原始交易字节计算规范交易标识符。
函数 (BuyerOpeningPort) VerifySellerRefundSignature
func (port BuyerOpeningPort) VerifySellerRefundSignature(ctx context.Context, request *RefundPresignRequest, signature []byte) error
VerifySellerRefundSignature 根据买方签名的 002 退款预签名请求检查卖方分离签名。验证器还会重建未签名退款状态,并在买方记录 OpeningProof 前确认买方和卖方角色签名。
类型 BuyerPoolAdapter
BuyerPoolAdapter 将费用池引擎适配到买方工作流操作。
type BuyerPoolAdapter struct {
*MultisigPoolEngine
Key PrivateKeyProvider
}
函数 NewBuyerPoolAdapter
func NewBuyerPoolAdapter(engine *MultisigPoolEngine, key PrivateKeyProvider) *BuyerPoolAdapter
NewBuyerPoolAdapter 将引擎绑定到买方私钥提供器,用于生成支付和退款分离签名;构造时不会执行签名。
函数 (*BuyerPoolAdapter) BuildRefundPresignRequest
func (adapter *BuyerPoolAdapter) BuildRefundPresignRequest(ctx context.Context, input OpeningInput, _ Signer) (*RefundPresignRequest, error)
BuildRefundPresignRequest 根据注资交易、开池输入和买方私钥构造 RefundPresignRequest。如果注资交易输出未使用配置的费用池锁,或买方密钥与引擎不匹配,则返回错误。
函数 (*BuyerPoolAdapter) SignBuyerPayment
func (adapter *BuyerPoolAdapter) SignBuyerPayment(ctx context.Context, unsigned *UnsignedPayment, _ Signer) ([]byte, error)
SignBuyerPayment 为未签名费用池交易生成买方分离签名。
类型 BuyerPoolOpeningHooks
BuyerPoolOpeningHooks 为买方开池提供持久化和验证能力。
type BuyerPoolOpeningHooks interface {
OpeningProofStore
RefundTxSignatureVerifier
TransactionIDCalculator
}
类型 BuyerPoolPort
BuyerPoolPort 暴露买方的费用池构造、签名和支付验证操作。
type BuyerPoolPort interface {
TransactionID([]byte) (Hash32, error)
BuildRefundPresignRequest(context.Context, OpeningInput, Signer) (*RefundPresignRequest, error)
BuildRefundSubmission(*OpeningProof) ([]byte, error)
VerifyRefundExpired(*OpeningProof, time.Time) error
VerifyOpening(*OpeningProof) error
ParsePaymentState(context.Context, []byte, *OpeningProof) (*PaymentState, error)
ParseUnsignedPayment(context.Context, []byte, *OpeningProof) (*UnsignedPayment, error)
VerifyAcceptedPayment(*PaymentState, *OpeningProof) error
VerifyBuyerPayment(*UnsignedPayment, []byte, *OpeningProof) error
VerifyCompletedFinalPayment(*SignedPayment, *OpeningProof) error
CheckPaymentCapacity(context.Context, PaymentUpdateInput) error
BuildPaymentUpdate(context.Context, PaymentUpdateInput) (*UnsignedPayment, error)
SignBuyerPayment(context.Context, *UnsignedPayment, Signer) ([]byte, error)
BuildImmediateClose(context.Context, CloseInput) (*UnsignedPayment, []byte, error)
}
类型 CloseInput
CloseInput 提供立即关闭所需的签名和交易数据。
type CloseInput struct {
Opening *OpeningProof
Latest *PaymentState
SellerAmountAfterSat uint64
}
函数 CloneCloseInput
func CloneCloseInput(input CloseInput) CloseInput
CloneCloseInput 返回 CloseInput 的独立副本,并复制其中可变的字节切片。
类型 FileStore
FileStore 是费用池存储端口的小型持久化参考实现。它使用进程协作锁,并在每次操作时重新加载当前快照,因此协作的 Unix 进程不会相互覆盖更新。若部署需要索引查询、超越原子重命名的崩溃恢复保证或权威锁服务,仍应使用事务数据库。
每次变更都通过临时文件和原子重命名写入完整快照。因此,原始交易、签名和待处理价格承诺可在进程重启后保留,协议字节不会改变。
type FileStore struct {
// contains filtered or unexported fields
}
函数 NewFileStore
func NewFileStore(path string, calculator TransactionIDCalculator) (*FileStore, error)
NewFileStore 打开 path 并恢复全部费用池、支付和交付闩锁状态。文件不存在时视为空存储。
函数 (*FileStore) EnsurePoolHealthy
func (store *FileStore) EnsurePoolHealthy(ctx context.Context, spendTxID Hash32) error
EnsurePoolHealthy 在记录外部提交结果不确定后拒绝继续操作。
函数 (*FileStore) Load
func (store *FileStore) Load(ctx context.Context, spendTxID Hash32) (*PendingRequest, error)
Load 从最新磁盘快照返回 spendTxID 对应的待处理交付请求。
函数 (*FileStore) LoadAcceptedPayment
func (store *FileStore) LoadAcceptedPayment(ctx context.Context, spendTxID Hash32) (*PaymentState, error)
LoadAcceptedPayment 返回 spend transaction ID 对应的已接受支付状态。
函数 (*FileStore) LoadOpeningProof
func (store *FileStore) LoadOpeningProof(ctx context.Context, spendTxID Hash32) (*OpeningProof, error)
LoadOpeningProof 按 spend transaction ID 加载开池证明。
函数 (*FileStore) LoadOpeningProofByFundingTxID
func (store *FileStore) LoadOpeningProofByFundingTxID(ctx context.Context, fundingTxID Hash32) (*OpeningProof, error)
LoadOpeningProofByFundingTxID 按注资交易 ID 查找开池证明。
函数 (*FileStore) MarkExternalStateUncertain
func (store *FileStore) MarkExternalStateUncertain(ctx context.Context, spendTxID, txID Hash32) error
MarkExternalStateUncertain 记录必须重新核对节点结果的交易 ID。
函数 (*FileStore) ReconcileExternalState
func (store *FileStore) ReconcileExternalState(ctx context.Context, spendTxID Hash32, state *PaymentState) error
ReconcileExternalState 在调用方提供已接受支付状态后清除不确定标记。
函数 (*FileStore) Release
func (store *FileStore) Release(ctx context.Context, spendTxID, requestHash Hash32) error
Release 仅在调用方提供匹配的请求哈希时移除待处理请求租约。
函数 (*FileStore) SaveAcceptedPayment
func (store *FileStore) SaveAcceptedPayment(ctx context.Context, state *PaymentState) error
SaveAcceptedPayment 按 spend transaction ID 保存支付,并拒绝序列号回退或同序列号状态冲突。
函数 (*FileStore) SaveOpeningProof
func (store *FileStore) SaveOpeningProof(ctx context.Context, proof *OpeningProof) error
SaveOpeningProof 验证开池证明,并以 spend transaction ID 为键持久化。
函数 (*FileStore) TryAcquire
func (store *FileStore) TryAcquire(ctx context.Context, request PendingRequest) (PendingAcquireResult, error)
TryAcquire 原子地申领待处理请求租约;若已有其他所有者或哈希冲突则不申领。
类型 FundingTxDelivery
FundingTxDelivery 携带退款验证后由买方揭示并签名的注资交易。
type FundingTxDelivery struct {
Version uint64
FundingTx []byte
}
函数 CloneFundingTxDelivery
func CloneFundingTxDelivery(delivery *FundingTxDelivery) *FundingTxDelivery
CloneFundingTxDelivery 返回 FundingTxDelivery 的独立副本,并复制其中可变的字节切片。
函数 DecodeFundingTxDelivery
func DecodeFundingTxDelivery(data []byte) (*FundingTxDelivery, error)
DecodeFundingTxDelivery 解码并检查 002 注资交付的规范性;SellerAcceptFundingTx 负责证明和节点检查。
类型 FundingTxVerifier
FundingTxVerifier 验证原始注资交易是否匹配其开池证明。
type FundingTxVerifier interface {
VerifyFundingTx(context.Context, []byte, *OpeningProof) error
}
类型 Hash32
Hash32 保存用于协议身份和交易 ID 的固定宽度 32 字节哈希。
type Hash32 [sha256.Size]byte
函数 SpendTxID
func SpendTxID(ctx context.Context, proof *OpeningProof, calculator TransactionIDCalculator) (Hash32, error)
SpendTxID 是 002 定义的稳定交易锚点,即预签名 RefundTx 证据字节的规范 ID。BuildRefundSubmission 随后为实际广播添加分离签名;由于解锁数据属于 txid,广播交易可能产生另一个交易 ID。
类型 MemoryStore
MemoryStore 是费用池持久化端口的并发安全参考实现,适合集成测试和小型嵌入式部署;替换它不会改变协议语义。
type MemoryStore struct {
// contains filtered or unexported fields
}
函数 NewMemoryStore
func NewMemoryStore(calculator TransactionIDCalculator) (*MemoryStore, error)
NewMemoryStore 要求非 nil 的交易 ID 计算器,并返回一个空的并发安全存储,用于开池证明、支付、健康标记和待处理交付租约。
函数 (*MemoryStore) EnsurePoolHealthy
func (store *MemoryStore) EnsurePoolHealthy(_ context.Context, spendTxID Hash32) error
EnsurePoolHealthy 在记录外部提交结果不确定后拒绝继续操作。
函数 (*MemoryStore) Load
func (store *MemoryStore) Load(_ context.Context, spendTxID Hash32) (*PendingRequest, error)
Load 返回 spendTxID 对应的待处理交付请求副本。
函数 (*MemoryStore) LoadAcceptedPayment
func (store *MemoryStore) LoadAcceptedPayment(_ context.Context, spendTxID Hash32) (*PaymentState, error)
LoadAcceptedPayment 返回 spend transaction ID 对应的已接受支付状态。
函数 (*MemoryStore) LoadOpeningProof
func (store *MemoryStore) LoadOpeningProof(_ context.Context, spendTxID Hash32) (*OpeningProof, error)
LoadOpeningProof 按 spend transaction ID 加载开池证明。
函数 (*MemoryStore) LoadOpeningProofByFundingTxID
func (store *MemoryStore) LoadOpeningProofByFundingTxID(_ context.Context, fundingTxID Hash32) (*OpeningProof, error)
LoadOpeningProofByFundingTxID 按注资交易 ID 查找开池证明。
函数 (*MemoryStore) MarkExternalStateUncertain
func (store *MemoryStore) MarkExternalStateUncertain(_ context.Context, spendTxID, txID Hash32) error
MarkExternalStateUncertain 记录必须重新核对节点结果的交易 ID。
函数 (*MemoryStore) ReconcileExternalState
func (store *MemoryStore) ReconcileExternalState(ctx context.Context, spendTxID Hash32, state *PaymentState) error
ReconcileExternalState 在调用方提供已接受支付状态后清除不确定标记。
函数 (*MemoryStore) Release
func (store *MemoryStore) Release(_ context.Context, spendTxID, requestHash Hash32) error
Release 仅在调用方提供匹配的请求哈希时移除待处理请求租约。
函数 (*MemoryStore) SaveAcceptedPayment
func (store *MemoryStore) SaveAcceptedPayment(_ context.Context, state *PaymentState) error
SaveAcceptedPayment 按 SpendTxID 保存状态。它拒绝更低的支付序列号和同一序列号下冲突的字节,从而在重试时保持已接受状态单调递增。
函数 (*MemoryStore) SaveOpeningProof
func (store *MemoryStore) SaveOpeningProof(ctx context.Context, proof *OpeningProof) error
SaveOpeningProof 验证开池证明,并以 spend transaction ID 为键持久化。
函数 (*MemoryStore) TryAcquire
func (store *MemoryStore) TryAcquire(_ context.Context, request PendingRequest) (PendingAcquireResult, error)
TryAcquire 原子地申领待处理请求租约;若已有其他所有者或哈希冲突则不申领。
类型 MultisigPoolAdapter
MultisigPoolAdapter 是面向仲裁人的能力接口,不包含旧角色别名,也绝不构造替代候选交易。
type MultisigPoolAdapter struct {
Engine *MultisigPoolEngine
ArbiterKey PrivateKeyProvider
}
函数 (*MultisigPoolAdapter) SignArbitrationCandidate
func (adapter *MultisigPoolAdapter) SignArbitrationCandidate(ctx context.Context, raw []byte, proof *OpeningProof, _ Signer) ([]byte, error)
SignArbitrationCandidate 使用注入的签名器为指定角色的交易或授权字节签名。
函数 (*MultisigPoolAdapter) VerifyArbitrationCandidate
func (adapter *MultisigPoolAdapter) VerifyArbitrationCandidate(_ context.Context, raw []byte, proof *OpeningProof, terms *bitfs.ContentRequestTerms, sellerSig []byte) (*UnsignedPayment, error)
VerifyArbitrationCandidate 根据独立的 003 授权验证卖方的 007 候选交易。它检查开池证明、费率和下一序列号,匹配未签名交易中的卖方金额与序列号,并验证卖方分离签名,但不会构造替代交易。
函数 (*MultisigPoolAdapter) VerifyOpening
func (adapter *MultisigPoolAdapter) VerifyOpening(proof *OpeningProof) error
VerifyOpening 通过 MultisigPool v4 验证完整的 002 OpeningProof:角色密钥、注资交易输出、未签名退款状态以及买方/卖方退款签名必须全部一致,工作流才能接受该费用池。
类型 MultisigPoolEngine
MultisigPoolEngine 是连接 MultisigPool v4 的适配边界。它保持 Buyer/Seller/Arbiter 角色顺序,并将脚本、费用、sighash、状态构造和签名顺序委托给该依赖。
type MultisigPoolEngine struct {
// contains filtered or unexported fields
}
函数 NewMultisigPoolEngine
func NewMultisigPoolEngine(config MultisigPoolEngineConfig) (*MultisigPoolEngine, error)
NewMultisigPoolEngine 解析并验证三个互不相同的角色密钥,为后续每次交易检查保留 Buyer/Seller/Arbiter 身份。密钥格式错误或重复时返回错误,且不会进行网络或存储 I/O。
函数 (*MultisigPoolEngine) BuildImmediateClose
func (engine *MultisigPoolEngine) BuildImmediateClose(_ context.Context, input CloseInput) (*UnsignedPayment, []byte, error)
BuildImmediateClose 根据已接受支付和 CloseInput 构造未签名的最终关闭状态及买方分离签名。卖方使用 SignImmediateClose 添加签名后,买方再通过其工作流提交合并的 SignedPayment。
函数 (*MultisigPoolEngine) BuildPaymentUpdate
func (engine *MultisigPoolEngine) BuildPaymentUpdate(ctx context.Context, input PaymentUpdateInput) (*UnsignedPayment, error)
BuildPaymentUpdate 根据上一笔已接受支付和请求金额构造下一笔未签名费用池状态交易。
函数 (*MultisigPoolEngine) BuildRefundSubmission
func (engine *MultisigPoolEngine) BuildRefundSubmission(proof *OpeningProof) ([]byte, error)
BuildRefundSubmission 将开池证明中的买方和卖方退款签名合并为可广播交易。
函数 (*MultisigPoolEngine) CheckPaymentCapacity
func (engine *MultisigPoolEngine) CheckPaymentCapacity(_ context.Context, input PaymentUpdateInput) error
CheckPaymentCapacity 验证请求的支付更新不超过费用池余额,并使用严格递增的序列号。
函数 (*MultisigPoolEngine) FundingTxID
func (engine *MultisigPoolEngine) FundingTxID(rawTx []byte) (Hash32, error)
FundingTxID 返回原始交易第一个输入中的 32 字节注资出点标识。
函数 (*MultisigPoolEngine) ParseFinalPaymentState
func (engine *MultisigPoolEngine) ParseFinalPaymentState(ctx context.Context, rawTx []byte, proof *OpeningProof) (*PaymentState, error)
ParseFinalPaymentState 解析已完整签名的费用池交易,并验证其为最终结算(sequence == finalPoolSequence)。
函数 (*MultisigPoolEngine) ParsePaymentState
func (engine *MultisigPoolEngine) ParsePaymentState(_ context.Context, rawTx []byte, proof *OpeningProof) (*PaymentState, error)
ParsePaymentState 将已完整签名的费用池交易解析为 PaymentState。交易的解锁脚本为空时返回错误。
函数 (*MultisigPoolEngine) ParseUnsignedPayment
func (engine *MultisigPoolEngine) ParseUnsignedPayment(_ context.Context, rawTx []byte, proof *OpeningProof) (*UnsignedPayment, error)
ParseUnsignedPayment 根据开池证明的规范状态验证并解析未签名费用池交易。
函数 (*MultisigPoolEngine) TransactionID
func (engine *MultisigPoolEngine) TransactionID(rawTx []byte) (Hash32, error)
TransactionID 根据原始交易字节计算规范交易标识符。
函数 (*MultisigPoolEngine) VerifyAcceptedPayment
func (engine *MultisigPoolEngine) VerifyAcceptedPayment(state *PaymentState, proof *OpeningProof) error
VerifyAcceptedPayment 将初始或此前接受的非仲裁支付状态与开池证明及完整角色签名进行核对。
函数 (*MultisigPoolEngine) VerifyArbitratedPayment
func (engine *MultisigPoolEngine) VerifyArbitratedPayment(state *PaymentState, proof *OpeningProof) error
VerifyArbitratedPayment 检查携带 007 仲裁流程所需卖方和仲裁人签名的最终状态。
函数 (*MultisigPoolEngine) VerifyBuyerPayment
func (engine *MultisigPoolEngine) VerifyBuyerPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
VerifyBuyerPayment 检查买方角色对精确未签名 005 支付状态的分离签名,以及该状态与 002 开池证明之间的规范关系。它不会合并签名或提交更新。
函数 (*MultisigPoolEngine) VerifyCompletedFinalPayment
func (engine *MultisigPoolEngine) VerifyCompletedFinalPayment(payment *SignedPayment, proof *OpeningProof) error
VerifyCompletedFinalPayment 验证合并后的 SignedPayment,并判断其分离签名是否构成有效的最终结算状态。
函数 (*MultisigPoolEngine) VerifyFinalPayment
func (engine *MultisigPoolEngine) VerifyFinalPayment(state *PaymentState, proof *OpeningProof) error
VerifyFinalPayment 将完整签名的最终交易与开池证明、最终序列号、角色签名、输出和规范交易字节逐项核对。
函数 (*MultisigPoolEngine) VerifyFundingTx
func (engine *MultisigPoolEngine) VerifyFundingTx(_ context.Context, rawTx []byte, proof *OpeningProof) error
VerifyFundingTx 解析交付的 002 注资交易,并将其 txid、费用池输出索引、聪值以及按角色排序的 MultisigPool v4 锁定脚本与 proof 匹配。它仅检查证据,不提交交易。
函数 (*MultisigPoolEngine) VerifyOpening
func (engine *MultisigPoolEngine) VerifyOpening(proof *OpeningProof) error
VerifyOpening 根据引擎的 Buyer/Seller/Arbiter 角色验证完整的 002 OpeningProof。它将证明与注资交易输出和未签名退款状态匹配,然后验证买方和卖方退款签名;不会进行持久化或节点提交。
函数 (*MultisigPoolEngine) VerifyPoolParticipants
func (engine *MultisigPoolEngine) VerifyPoolParticipants(proof *OpeningProof, buyer, seller, arbiter []byte) error
VerifyPoolParticipants 检查开池证明中的买方、卖方和仲裁人密钥是否匹配给定值。
函数 (*MultisigPoolEngine) VerifyRefundExpired
func (engine *MultisigPoolEngine) VerifyRefundExpired(proof *OpeningProof, now time.Time) error
VerifyRefundExpired 检查退款交易的 nLockTime 是否已到。区块高度退款需要 BlockHeight 提供器;时间戳退款则与 now 比较。
函数 (*MultisigPoolEngine) VerifySellerPayment
func (engine *MultisigPoolEngine) VerifySellerPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
VerifySellerPayment 检查卖方角色对精确未签名 005 支付状态的分离签名,以及该状态与 002 开池证明之间的规范关系。它不会合并签名或提交更新。
函数 (*MultisigPoolEngine) VerifySellerRefundSignature
func (engine *MultisigPoolEngine) VerifySellerRefundSignature(_ context.Context, request *RefundPresignRequest, signature []byte) error
VerifySellerRefundSignature 验证 request 指定的 002 预签名退款状态,包括其注资出点、角色密钥、买方签名和提供的卖方分离签名。它不会提交任何一笔交易。
类型 MultisigPoolEngineConfig
MultisigPoolEngineConfig 按角色顺序提供压缩的 Buyer、Seller 和 Arbiter 公钥。BlockHeight 可选,仅用于区块高度退款的到期检查;费用和交易规则来自 MultisigPool v4。
type MultisigPoolEngineConfig struct {
BuyerPubKey []byte
SellerPubKey []byte
ArbiterPubKey []byte
BlockHeight func() uint32
}
类型 NonFinalPoolBackend
NonFinalPoolBackend 是具体 BSV 节点/RPC 客户端的窄边界。SubmitUpdate 只有在节点接受 rawTx 作为当前非最终花费后才能返回;SubmitFinal 只有在最终接受后才能返回。JSON-RPC、gRPC 或厂商 SDK 客户端均可实现此端口,而无需耦合买方或卖方工作流代码。
type NonFinalPoolBackend interface {
SubmitUpdate(context.Context, []byte) (*UpdateAcceptance, error)
SubmitFinal(context.Context, []byte) (Hash32, error)
}
类型 NonFinalPoolNode
NonFinalPoolNode 将已验证的累计更新和最终结算交易提交到节点。
type NonFinalPoolNode interface {
SubmitUpdate(context.Context, []byte) (*UpdateAcceptance, error)
SubmitFinal(context.Context, []byte) (Hash32, error)
}
类型 OpeningByFundingStore
OpeningByFundingStore 提供开池证明,使原始支付在到达节点适配器前能够完成验证。
type OpeningByFundingStore interface {
LoadOpeningProofByFundingTxID(context.Context, Hash32) (*OpeningProof, error)
}
类型 OpeningInput
OpeningInput 仅包含通用的费用池构造数据。
type OpeningInput struct {
FundingTx []byte
PoolOutputIndex uint32
ExpiryLockTime uint32
MinerFeeRateSatPerKB uint64
SellerPubKey []byte
ArbiterPubKey []byte
}
函数 CloneOpeningInput
func CloneOpeningInput(input OpeningInput) OpeningInput
CloneOpeningInput 返回 OpeningInput 的独立副本,并复制其中可变的字节切片。
类型 OpeningProof
OpeningProof 记录双方验证过的退款和注资交易,用于开立费用池。
type OpeningProof struct {
Version uint64
MultisigProtocol string
MultisigVersion uint64
RefundTx []byte
SpendTxID []byte
FundingTxID []byte
PoolOutputIndex uint32
PoolOutputSatoshis uint64
PoolLockingScript []byte
BuyerPubKey []byte
SellerPubKey []byte
ArbiterPubKey []byte
MinerFeeRateSatPerKB uint64
BuyerRefundSignature []byte
SellerRefundSignature []byte
FundingTx []byte
}
函数 BuyerAcceptRefundPresign
func BuyerAcceptRefundPresign(ctx context.Context, request *RefundPresignRequest, response *RefundPresignResponse, fundingTx []byte, hooks BuyerPoolOpeningHooks) (*OpeningProof, error)
BuyerAcceptRefundPresign 在允许调用方向卖方揭示 FundingTx 前验证并持久化完整证明。
函数 CloneOpeningProof
func CloneOpeningProof(proof *OpeningProof) *OpeningProof
CloneOpeningProof 返回 OpeningProof 的独立副本,并复制其中可变的字节切片。
函数 DecodeOpeningProof
func DecodeOpeningProof(data []byte) (*OpeningProof, error)
DecodeOpeningProof 解码并检查 002 开池证明的规范性,然后验证字段;签名和交易关系仍必须通过 VerifyOpening 检查。
函数 SellerAcceptFundingTx
func SellerAcceptFundingTx(ctx context.Context, delivery *FundingTxDelivery, hooks SellerPoolOpeningHooks) (*OpeningProof, error)
SellerAcceptFundingTx 根据保存的退款证明验证注资交易,持久化后再提交。节点按交易 ID 提供幂等语义时,重复提交是安全的。
类型 OpeningProofStore
OpeningProofStore 按 SpendTxID(预签名退款证据的规范 ID)持久化并读取已验证的 002 开池证明。
type OpeningProofStore interface {
SaveOpeningProof(context.Context, *OpeningProof) error
LoadOpeningProof(context.Context, Hash32) (*OpeningProof, error)
}
类型 ParticipantVerifier
ParticipantVerifier 检查开池证明中的买方、卖方和仲裁人密钥是否匹配预期值。
type ParticipantVerifier interface {
VerifyPoolParticipants(*OpeningProof, []byte, []byte, []byte) error
}
类型 PaymentState
PaymentState 只表示已由节点接受的完整合并交易。工作流需要跨 API 边界携带分离签名时会显式保存它们,但 RawTx 绝不会是单签名或未签名交易。
type PaymentState struct {
SpendTxID Hash32
RawTx []byte
PaymentSequence uint32
BuyerAmountSat uint64
SellerAmountSat uint64
ArbiterAmountSat uint64
PaymentAuthorizationHash Hash32
BuyerTransactionSignature []byte
SellerTransactionSignature []byte
ArbiterTransactionSignature []byte
PoolOutputSatoshis uint64
PoolLockingScript []byte
}
函数 ClonePaymentState
func ClonePaymentState(state *PaymentState) *PaymentState
ClonePaymentState 返回 PaymentState 的独立副本,并复制其中可变的字节切片。
类型 PaymentUpdate
PaymentUpdate 是 v3 005 传输容器,携带未签名状态交易和买方分离签名;它绝不会携带部分解锁的交易。
type PaymentUpdate struct {
Version uint64
PaymentAuthorizationHash []byte
UnsignedStateTxRaw []byte
BuyerTransactionSignature []byte
}
函数 ClonePaymentUpdate
func ClonePaymentUpdate(update *PaymentUpdate) *PaymentUpdate
ClonePaymentUpdate 返回 PaymentUpdate 的独立副本,并复制其中可变的字节切片。
函数 DecodePaymentUpdate
func DecodePaymentUpdate(data []byte) (*PaymentUpdate, error)
DecodePaymentUpdate 解码并检查 005 四字段支付容器的规范性,然后验证字段结构。它不证明费用池所有权,也不根据开池证明验证买方签名。
类型 PaymentUpdateInput
PaymentUpdateInput 提供下一次累计支付状态及其交易字节。
type PaymentUpdateInput struct {
Opening *OpeningProof
Previous *PaymentState
PaymentSequenceAfter uint32
SellerAmountAfterSat uint64
}
函数 ClonePaymentUpdateInput
func ClonePaymentUpdateInput(input PaymentUpdateInput) PaymentUpdateInput
ClonePaymentUpdateInput 返回 PaymentUpdateInput 的独立副本,并复制其中可变的字节切片。
类型 PendingAcquireResult
PendingAcquireResult 报告交付租约是已取得、仍由当前方持有,还是发生冲突。
type PendingAcquireResult uint8
const (
// PendingAcquired indicates the delivery lease was successfully acquired.
PendingAcquired PendingAcquireResult = 1
// PendingAlreadyHeld indicates that another request currently owns the lock.
PendingAlreadyHeld PendingAcquireResult = 2
// PendingConflict indicates that the request hash conflicts with the owner.
PendingConflict PendingAcquireResult = 3
)
类型 PendingOpeningProofStore
PendingOpeningProofStore 在接受注资交易前持久化开池证明,并按揭示的注资交易 ID 读取。
type PendingOpeningProofStore interface {
SaveOpeningProof(context.Context, *OpeningProof) error
LoadOpeningProofByFundingTxID(context.Context, Hash32) (*OpeningProof, error)
}
类型 PendingRequest
PendingRequest 记录用于串行化交付的请求哈希和所有权租约。
type PendingRequest struct {
SpendTxID Hash32
BasePaymentSequence uint32
ContentRequestHash Hash32
ExpectedSellerAmountSat uint64
}
类型 PendingRequestStore
PendingRequestStore 按 spend transaction ID 管理内容请求交付租约。
type PendingRequestStore interface {
TryAcquire(context.Context, PendingRequest) (PendingAcquireResult, error)
Load(context.Context, Hash32) (*PendingRequest, error)
Release(context.Context, Hash32, Hash32) error
}
类型 PoolNodeVerifierPort
PoolNodeVerifierPort 在费用池交易到达具体节点适配器前验证它们。
type PoolNodeVerifierPort interface {
FundingTxID([]byte) (Hash32, error)
TransactionID([]byte) (Hash32, error)
BuildRefundSubmission(*OpeningProof) ([]byte, error)
VerifyRefundExpired(*OpeningProof, time.Time) error
ParsePaymentState(context.Context, []byte, *OpeningProof) (*PaymentState, error)
ParseUnsignedPayment(context.Context, []byte, *OpeningProof) (*UnsignedPayment, error)
ParseFinalPaymentState(context.Context, []byte, *OpeningProof) (*PaymentState, error)
VerifyAcceptedPayment(*PaymentState, *OpeningProof) error
VerifyArbitratedPayment(*PaymentState, *OpeningProof) error
VerifyCompletedFinalPayment(*SignedPayment, *OpeningProof) error
}
类型 PoolRefundSigner
PoolRefundSigner 将 SellerPoolAdapter 适配为 RefundTxSigner 接口。
type PoolRefundSigner struct{ Adapter *SellerPoolAdapter }
函数 (PoolRefundSigner) SignRefundTx
func (adapter PoolRefundSigner) SignRefundTx(ctx context.Context, request *RefundPresignRequest) ([]byte, error)
SignRefundTx 为 request 描述的预签名退款交易生成卖方分离签名。
类型 PoolStore
PoolStore 将开池证明和已接受支付的持久化、健康状态核对以及角色工作流使用的卖方交付租约组合在一起。
type PoolStore interface {
OpeningProofStore
LoadOpeningProofByFundingTxID(context.Context, Hash32) (*OpeningProof, error)
SaveAcceptedPayment(context.Context, *PaymentState) error
LoadAcceptedPayment(context.Context, Hash32) (*PaymentState, error)
EnsurePoolHealthy(context.Context, Hash32) error
MarkExternalStateUncertain(context.Context, Hash32, Hash32) error
ReconcileExternalState(context.Context, Hash32, *PaymentState) error
}
类型 PrivateKeyProvider
PrivateKeyProvider 有意比工作流 Signer 更窄:MultisigPool 必须取得实际私钥,才能计算规范 sighash 和分离签名。
type PrivateKeyProvider interface {
PrivateKey(context.Context) (*ec.PrivateKey, error)
}
类型 Reference
Reference 标识内容请求使用的结算费用池和支付序列号。
type Reference struct {
SpendTxID Hash32
BasePaymentSequence uint32
}
类型 RefundPresignRequest
RefundPresignRequest 包含预签名退款交易的买卖双方条款。
type RefundPresignRequest struct {
Version uint64
MultisigProtocol string
MultisigVersion uint64
RefundTx []byte
FundingTxID []byte
PoolOutputIndex uint32
PoolOutputSatoshis uint64
PoolLockingScript []byte
BuyerPubKey []byte
SellerPubKey []byte
ArbiterPubKey []byte
MinerFeeRateSatPerKB uint64
BuyerRefundSignature []byte
}
函数 CloneRefundPresignRequest
func CloneRefundPresignRequest(request *RefundPresignRequest) *RefundPresignRequest
CloneRefundPresignRequest 返回 RefundPresignRequest 的独立副本,并复制其中可变的字节切片。
函数 DecodeRefundPresignRequest
func DecodeRefundPresignRequest(data []byte) (*RefundPresignRequest, error)
DecodeRefundPresignRequest 解码并检查 002 请求的规范性;密码学检查和注资交易接受仍由开池工作流负责。
类型 RefundPresignResponse
RefundPresignResponse 携带卖方对预签名退款交易的签名。
type RefundPresignResponse struct {
Version uint64
SellerRefundSignature []byte
}
函数 CloneRefundPresignResponse
func CloneRefundPresignResponse(response *RefundPresignResponse) *RefundPresignResponse
CloneRefundPresignResponse 返回 RefundPresignResponse 的独立副本,并复制其中可变的字节切片。
函数 DecodeRefundPresignResponse
func DecodeRefundPresignResponse(data []byte) (*RefundPresignResponse, error)
DecodeRefundPresignResponse 解码并检查 002 卖方响应的规范性,但不判断签名是否匹配特定请求。
函数 SellerPresignRefund
func SellerPresignRefund(ctx context.Context, request *RefundPresignRequest, hooks SellerPoolOpeningHooks) (*RefundPresignResponse, error)
SellerPresignRefund 在返回前为退款证据签名并持久化。此阶段有意不要求 FundingTx。
类型 RefundTxSignatureVerifier
RefundTxSignatureVerifier 根据预签名请求验证卖方退款分离签名。
type RefundTxSignatureVerifier interface {
VerifySellerRefundSignature(context.Context, *RefundPresignRequest, []byte) error
}
类型 RefundTxSigner
RefundTxSigner 为预签名退款交易生成卖方分离签名。
type RefundTxSigner interface {
SignRefundTx(context.Context, *RefundPresignRequest) ([]byte, error)
}
类型 SellerOpeningPort
SellerOpeningPort 适配卖方的 002 开池能力。注资交易提交与非最终支付替换保持分离,因为它们是不同的外部状态转换。
type SellerOpeningPort struct {
Store PendingOpeningProofStore
RefundSigner RefundTxSigner
Calculator TransactionIDCalculator
FundingVerifier FundingTxVerifier
FundingSubmitter TransactionSubmitter
}
函数 (SellerOpeningPort) LoadOpeningProofByFundingTxID
func (port SellerOpeningPort) LoadOpeningProofByFundingTxID(ctx context.Context, fundingTxID Hash32) (*OpeningProof, error)
LoadOpeningProofByFundingTxID 按注资交易 ID 查找开池证明。
函数 (SellerOpeningPort) SaveOpeningProof
func (port SellerOpeningPort) SaveOpeningProof(ctx context.Context, proof *OpeningProof) error
SaveOpeningProof 验证开池证明,并以 spend transaction ID 为键持久化。
函数 (SellerOpeningPort) SignRefundTx
func (port SellerOpeningPort) SignRefundTx(ctx context.Context, request *RefundPresignRequest) ([]byte, error)
SignRefundTx 使用注入的签名器为指定角色的交易或授权字节签名。
函数 (SellerOpeningPort) SubmitTransaction
func (port SellerOpeningPort) SubmitTransaction(ctx context.Context, rawTx []byte) (Hash32, error)
SubmitTransaction 通过配置的节点或提交器提交已验证交易。
函数 (SellerOpeningPort) TransactionID
func (port SellerOpeningPort) TransactionID(ctx context.Context, rawTx []byte) (Hash32, error)
TransactionID 根据原始交易字节计算规范交易标识符。
函数 (SellerOpeningPort) VerifyFundingTx
func (port SellerOpeningPort) VerifyFundingTx(ctx context.Context, fundingTx []byte, proof *OpeningProof) error
VerifyFundingTx 将 002 注资交易接受委托给配置的验证器。它检查交付的原始注资交易是否具有证明中的出点、金额和按角色排序的费用池锁;提交操作另行执行。
类型 SellerPoolAdapter
SellerPoolAdapter 将费用池引擎适配到卖方工作流操作。
type SellerPoolAdapter struct {
*MultisigPoolEngine
Key PrivateKeyProvider
}
函数 NewSellerPoolAdapter
func NewSellerPoolAdapter(engine *MultisigPoolEngine, key PrivateKeyProvider) *SellerPoolAdapter
NewSellerPoolAdapter 将引擎绑定到卖方私钥提供器,用于支付、退款和仲裁候选交易的分离签名。
函数 (*SellerPoolAdapter) MergeBuyerSellerPayment
func (adapter *SellerPoolAdapter) MergeBuyerSellerPayment(unsigned *UnsignedPayment, buyerSig, sellerSig []byte) (*SignedPayment, error)
MergeBuyerSellerPayment 将分离的角色签名合并为所需的完整支付交易。
函数 (*SellerPoolAdapter) MergeSellerArbiterPayment
func (adapter *SellerPoolAdapter) MergeSellerArbiterPayment(unsigned *UnsignedPayment, sellerSig, arbiterSig []byte) (*SignedPayment, error)
MergeSellerArbiterPayment 将分离的角色签名合并为所需的完整支付交易。
函数 (*SellerPoolAdapter) SignImmediateClose
func (adapter *SellerPoolAdapter) SignImmediateClose(ctx context.Context, unsigned *UnsignedPayment, buyerSig []byte, _ Signer) (*SignedPayment, error)
SignImmediateClose 为立即关闭交易的卖方部分签名,并与买方签名合并后返回完整 SignedPayment。
函数 (*SellerPoolAdapter) SignSellerArbitrationCandidate
func (adapter *SellerPoolAdapter) SignSellerArbitrationCandidate(ctx context.Context, unsigned *UnsignedPayment, _ Signer) ([]byte, error)
SignSellerArbitrationCandidate 为仲裁候选交易生成卖方分离签名。
函数 (*SellerPoolAdapter) SignSellerPayment
func (adapter *SellerPoolAdapter) SignSellerPayment(ctx context.Context, unsigned *UnsignedPayment, _ Signer) ([]byte, error)
SignSellerPayment 为未签名费用池交易生成卖方分离签名。
函数 (*SellerPoolAdapter) VerifyBuyerPayment
func (adapter *SellerPoolAdapter) VerifyBuyerPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
VerifyBuyerPayment 在根据 002 开池证明验证规范输出后,检查买方角色对精确未签名 005 支付状态的分离签名。它不会合并卖方签名或提交该状态。
函数 (*SellerPoolAdapter) VerifySellerPayment
func (adapter *SellerPoolAdapter) VerifySellerPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
VerifySellerPayment 检查卖方角色对精确未签名 005 支付状态的分离签名,以及该状态与 002 开池证明之间的规范关系。它不会合并买方签名或提交更新。
类型 SellerPoolOpeningHooks
SellerPoolOpeningHooks 为卖方开池提供签名、验证、持久化和提交能力。
type SellerPoolOpeningHooks interface {
PendingOpeningProofStore
RefundTxSigner
TransactionIDCalculator
FundingTxVerifier
TransactionSubmitter
}
类型 SellerPoolPort
SellerPoolPort 暴露卖方的费用池验证、签名和支付合并操作。
type SellerPoolPort interface {
TransactionID([]byte) (Hash32, error)
FundingTxID([]byte) (Hash32, error)
BuildRefundSubmission(*OpeningProof) ([]byte, error)
VerifyOpening(*OpeningProof) error
ParsePaymentState(context.Context, []byte, *OpeningProof) (*PaymentState, error)
ParseUnsignedPayment(context.Context, []byte, *OpeningProof) (*UnsignedPayment, error)
VerifyAcceptedPayment(*PaymentState, *OpeningProof) error
VerifyArbitratedPayment(*PaymentState, *OpeningProof) error
VerifyBuyerPayment(*UnsignedPayment, []byte, *OpeningProof) error
VerifySellerPayment(*UnsignedPayment, []byte, *OpeningProof) error
CheckPaymentCapacity(context.Context, PaymentUpdateInput) error
BuildPaymentUpdate(context.Context, PaymentUpdateInput) (*UnsignedPayment, error)
SignSellerArbitrationCandidate(context.Context, *UnsignedPayment, Signer) ([]byte, error)
SignSellerPayment(context.Context, *UnsignedPayment, Signer) ([]byte, error)
MergeBuyerSellerPayment(*UnsignedPayment, []byte, []byte) (*SignedPayment, error)
MergeSellerArbiterPayment(*UnsignedPayment, []byte, []byte) (*SignedPayment, error)
SignImmediateClose(context.Context, *UnsignedPayment, []byte, Signer) (*SignedPayment, error)
}
类型 SignatureVerifier
SignatureVerifier 根据精确提供的字节和公钥验证分离签名;它不得规范化或重新编码载荷。
type SignatureVerifier interface {
Verify(pubkey, payload, signature []byte) error
}
类型 SignedPayment
SignedPayment 包含针对未签名支付交易的一个角色分离签名。
type SignedPayment struct {
State PaymentState
RawTx []byte
}
函数 CloneSignedPayment
func CloneSignedPayment(payment *SignedPayment) *SignedPayment
CloneSignedPayment 返回 SignedPayment 的独立副本,并复制其中可变的字节切片。
类型 Signer
Signer 暴露凭证和费用池交易使用的公钥及分离签名。实现负责在 SDK 外部保管私钥。
type Signer interface {
PublicKey(context.Context) ([]byte, error)
Sign(context.Context, []byte) ([]byte, error)
}
类型 TransactionIDCalculator
TransactionIDCalculator 根据原始交易字节计算规范的 32 字节交易标识符。
type TransactionIDCalculator interface {
TransactionID(context.Context, []byte) (Hash32, error)
}
类型 TransactionSubmitter
TransactionSubmitter 向网络广播原始交易并返回其规范交易 ID。
type TransactionSubmitter interface {
SubmitTransaction(context.Context, []byte) (Hash32, error)
}
类型 UnsignedPayment
UnsignedPayment 是单签方法唯一接受的交易对象。它不包含解锁脚本或内嵌签名。
type UnsignedPayment struct {
SpendTxID Hash32
RawTx []byte
PaymentSequence uint32
BuyerAmountSat uint64
SellerAmountSat uint64
ArbiterAmountSat uint64
PoolOutputSatoshis uint64
PoolLockingScript []byte
}
类型 UpdateAcceptance
UpdateAcceptance 描述节点对非最终支付更新的接受结果。
type UpdateAcceptance struct {
TxID Hash32
SpendTxID Hash32
PaymentSequence uint32
}
类型 VerifiedNonFinalPoolNode
VerifiedNonFinalPoolNode 是工作流代码与具体节点客户端之间的生产适配器。它在转发前验证 rawTx 中的精确输入、输出、买方授权和可用的最终签名集合,然后验证后端响应描述的是同一笔已接受交易及序列号。
type VerifiedNonFinalPoolNode struct {
// contains filtered or unexported fields
}
函数 NewVerifiedNonFinalPoolNode
func NewVerifiedNonFinalPoolNode(engine PoolNodeVerifierPort, openings OpeningByFundingStore, backend NonFinalPoolBackend) (*VerifiedNonFinalPoolNode, error)
NewVerifiedNonFinalPoolNode 要求费用池验证器、按注资交易 ID 索引的开池证明存储和后端。它返回一个适配器,在向工作流报告节点接受前验证字节和后端响应。
函数 (*VerifiedNonFinalPoolNode) SubmitFinal
func (node *VerifiedNonFinalPoolNode) SubmitFinal(ctx context.Context, rawTx []byte) (Hash32, error)
SubmitFinal 验证最终关闭或已到期退款,将其提交到后端,并要求返回的交易 ID 与原始字节匹配。
函数 (*VerifiedNonFinalPoolNode) SubmitUpdate
func (node *VerifiedNonFinalPoolNode) SubmitUpdate(ctx context.Context, rawTx []byte) (*UpdateAcceptance, error)
SubmitUpdate 验证非最终状态并提交到后端,要求返回的交易 ID、支付锚点和序列号均匹配。
由 gomarkdoc 生成