pool
import "github.com/bsv8/go-bitfs/pool"
Package pool 包含 002/005/006 使用的与协议无关的 2-of-3 结算原语。它验证角色顺序的 MultisigPool v4 字节、维护单调付款状态,并暴露纯交易构造、解析、签名与验证能力;刻意不引入 BitFS 报价或内容类型,也没有存储、网络或节点副作用。所有签名能力都经受约束的 protocol.Signer 端口进入;全部时间/高度判断都以显式事实到达。
索引
- 常量
- 函数 Build2of3LockingScript(keys MultisigPoolPublicKeys) ([]byte, error)
- 函数 BuildPoolLock(roles mp.ArbitratedPoolRoles) ([]byte, error)
- 函数 CheckArbitrationRefundNotExpired(refundTemplateRaw []byte, facts protocol.Facts) error
- 函数 EncodeFundingTransactionDelivery(delivery *FundingTransactionDelivery) ([]byte, error)
- 函数 EncodeOpeningProof(proof *OpeningProof) ([]byte, error)
- 函数 EncodePaymentUpdate(update *PaymentUpdate) ([]byte, error)
- 函数 EncodeRefundPresignRequest(request *RefundPresignRequest) ([]byte, error)
- 函数 EncodeRefundPresignResponse(response *RefundPresignResponse) ([]byte, error)
- 函数 ParseCanonicalTransaction(raw []byte) (*tx.Transaction, error)
- 函数 RefundTemplateLockTime(refundTemplateRaw []byte) (protocol.RefundLockTime, error)
- 函数 RefundUsesBlockHeight(refundTx []byte) (bool, error)
- 函数 ValidateArbitrationClaimStructure(poolOutputSatoshis uint64, poolOutputLockingScript, refundTemplateRaw []byte, paymentSequence uint32, sellerAmountAfterSatoshis uint64) error
- 函数 ValidateFundingTransactionDelivery(delivery *FundingTransactionDelivery) error
- 函数 ValidateOpeningProof(proof *OpeningProof) error
- 函数 ValidatePaymentUpdate(update *PaymentUpdate) error
- 函数 ValidateRefundPresignRequest(request *RefundPresignRequest) error
- 函数 ValidateRefundPresignResponse(response *RefundPresignResponse) error
- 函数 VerifyRefundPresignRequestEvidence(request *RefundPresignRequest) error
- 类型 ArbiterPoolAdapter
- 类型 BuyerPoolAdapter
- 函数 NewBuyerPoolAdapter(engine *MultisigPoolEngine, signer protocol.Signer) *BuyerPoolAdapter
- 函数 (adapter *BuyerPoolAdapter) BuildRefundPresignRequest(ctx context.Context, input OpeningInput) (*RefundPresignRequest, error)
- 函数 (adapter *BuyerPoolAdapter) SignBuyerPayment(ctx context.Context, unsigned *UnsignedPayment, proof *OpeningProof) ([]byte, error)
- 类型 CloseInput
- 类型 FundingTransactionDelivery
- 类型 Hash32
- 类型 MultisigPoolEngine
- 函数 NewMultisigPoolEngine(config MultisigPoolEngineConfig) (*MultisigPoolEngine, error)
- 函数 NewMultisigPoolEngineFromPoolLockingScript(raw []byte) (*MultisigPoolEngine, error)
- 函数 (engine *MultisigPoolEngine) BuildImmediateClose(input CloseInput) (*UnsignedPayment, error)
- 函数 (engine *MultisigPoolEngine) BuildOpeningProof(request *RefundPresignRequest, sellerSignature, fundingTx []byte) (*OpeningProof, error)
- 函数 (engine *MultisigPoolEngine) BuildPaymentUpdate(input PaymentUpdateInput) (*UnsignedPayment, error)
- 函数 (engine *MultisigPoolEngine) BuildRefundSubmission(proof *OpeningProof) ([]byte, error)
- 函数 (engine *MultisigPoolEngine) CheckPaymentCapacity(input PaymentUpdateInput) error
- 函数 (engine *MultisigPoolEngine) FundingTxID(rawTx []byte) (Hash32, error)
- 函数 (engine *MultisigPoolEngine) MergeArbitratedPoolSellerArbiterSignatures(unsigned *UnsignedPayment, sellerSignature, arbiterSignature []byte) (*SignedPayment, error)
- 函数 (engine *MultisigPoolEngine) MergeBuyerSellerPayment(unsigned *UnsignedPayment, buyerSignature, sellerSignature []byte, proof *OpeningProof) (*SignedPayment, error)
- 函数 (engine *MultisigPoolEngine) MergeSellerArbiterPayment(unsigned *UnsignedPayment, sellerSignature, arbiterSignature []byte, proof *OpeningProof) (*SignedPayment, error)
- 函数 (engine *MultisigPoolEngine) ParseFinalPaymentState(rawTx []byte, proof *OpeningProof) (*PaymentState, error)
- 函数 (engine *MultisigPoolEngine) ParseNonFinalPaymentState(rawTx []byte, proof *OpeningProof) (*PaymentState, error)
- 函数 (engine *MultisigPoolEngine) ParsePaymentState(rawTx []byte, proof *OpeningProof) (*PaymentState, error)
- 函数 (engine *MultisigPoolEngine) ParseUnsignedPayment(rawTx []byte, proof *OpeningProof) (*UnsignedPayment, error)
- 函数 (engine *MultisigPoolEngine) PaymentStateMatchesUnsigned(state *PaymentState, unsigned *UnsignedPayment, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) SignArbitrationArbiterPayment(ctx context.Context, unsigned *UnsignedPayment, signer protocol.Signer) ([]byte, error)
- 函数 (engine *MultisigPoolEngine) SignArbitrationSellerPayment(ctx context.Context, unsigned *UnsignedPayment, signer protocol.Signer) ([]byte, error)
- 函数 (engine *MultisigPoolEngine) TransactionID(rawTx []byte) (Hash32, error)
- 函数 (engine *MultisigPoolEngine) VerifyAcceptedPayment(state *PaymentState, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifyArbiterPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifyArbitratedPayment(state *PaymentState, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifyArbitrationArbiterPayment(unsigned *UnsignedPayment, signature []byte) error
- 函数 (engine *MultisigPoolEngine) VerifyArbitrationSellerPayment(unsigned *UnsignedPayment, signature []byte) 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(rawTx []byte, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifyOpening(proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifyPoolParticipants(proof *OpeningProof, buyer, seller, arbiter []byte) error
- 函数 (engine *MultisigPoolEngine) VerifyRefundExpiredAt(proof *OpeningProof, at time.Time, blockHeight uint32) error
- 函数 (engine *MultisigPoolEngine) VerifyRefundNotExpiredAt(proof *OpeningProof, at time.Time, blockHeight uint32) error
- 函数 (engine *MultisigPoolEngine) VerifySellerPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
- 函数 (engine *MultisigPoolEngine) VerifySellerRefundSignature(request *RefundPresignRequest, signature []byte) error
- 类型 MultisigPoolEngineConfig
- 类型 MultisigPoolPublicKeys
- 类型 OpeningDetails
- 类型 OpeningInput
- 类型 OpeningProof
- 函数 CloneOpeningProof(proof *OpeningProof) *OpeningProof
- 函数 DecodeOpeningProof(data []byte) (*OpeningProof, error)
- 函数 (proof *OpeningProof) OpeningArbiterPublicKey() []byte
- 函数 (proof *OpeningProof) OpeningBuyerPublicKey() []byte
- 函数 (proof *OpeningProof) OpeningRefundTemplateTxID() []byte
- 函数 (proof *OpeningProof) OpeningSellerPublicKey() []byte
- 类型 PaymentState
- 类型 PaymentUpdate
- 类型 PaymentUpdateInput
- 类型 RefundPresignRequest
- 类型 RefundPresignResponse
- 类型 RefundTemplateTxID
- 类型 SellerPoolAdapter
- 函数 NewSellerPoolAdapter(engine *MultisigPoolEngine, signer protocol.Signer) *SellerPoolAdapter
- 函数 (adapter *SellerPoolAdapter) MergeBuyerSellerPayment(unsigned *UnsignedPayment, buyerSignature, sellerSignature []byte, proof *OpeningProof) (*SignedPayment, error)
- 函数 (adapter *SellerPoolAdapter) MergeSellerArbiterPayment(unsigned *UnsignedPayment, sellerSignature, arbiterSignature []byte, proof *OpeningProof) (*SignedPayment, error)
- 函数 (adapter *SellerPoolAdapter) SignImmediateClose(ctx context.Context, unsigned *UnsignedPayment, buyerSignature []byte, proof *OpeningProof) (*SignedPayment, error)
- 函数 (adapter *SellerPoolAdapter) SignSellerPayment(ctx context.Context, unsigned *UnsignedPayment, proof *OpeningProof) ([]byte, error)
- 函数 (adapter *SellerPoolAdapter) SignSellerRefund(ctx context.Context, request *RefundPresignRequest) ([]byte, error)
- 函数 (adapter *SellerPoolAdapter) VerifyBuyerPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
- 函数 (adapter *SellerPoolAdapter) VerifySellerPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
- 类型 SignedPayment
- 类型 UnsignedPayment
- 类型 VerifiedOpening
- 函数 VerifyOpeningProof(proof *OpeningProof) (*VerifiedOpening, error)
- 函数 (v *VerifiedOpening) ArbiterPublicKey() []byte
- 函数 (v *VerifiedOpening) BuyerPublicKey() []byte
- 函数 (v *VerifiedOpening) FundingTransactionRaw() []byte
- 函数 (v *VerifiedOpening) MatchesBuyer(publicKey []byte) bool
- 函数 (v *VerifiedOpening) MatchesSeller(publicKey []byte) bool
- 函数 (v *VerifiedOpening) Proof() *OpeningProof
- 函数 (v *VerifiedOpening) RefundTemplateTxID() RefundTemplateTxID
- 函数 (v *VerifiedOpening) SellerPublicKey() []byte
- 类型 VerifiedPaymentState
- 函数 VerifyPaymentState(state *PaymentState, proof *OpeningProof) (*VerifiedPaymentState, error)
- 函数 (v *VerifiedPaymentState) ArbiterAmountSatoshis() protocol.Satoshis
- 函数 (v *VerifiedPaymentState) BuyerAmountSatoshis() protocol.Satoshis
- 函数 (v *VerifiedPaymentState) PaymentSequence() protocol.PaymentSequence
- 函数 (v *VerifiedPaymentState) RawTx() []byte
- 函数 (v *VerifiedPaymentState) RefundTemplateTxID() RefundTemplateTxID
- 函数 (v *VerifiedPaymentState) SellerAmountSatoshis() protocol.Satoshis
- 函数 (v *VerifiedPaymentState) State() *PaymentState
- 类型 VerifiedSignedTransaction
- 函数 CompleteArbitratedTransaction(unsigned *UnsignedPayment, sellerSignature, arbiterSignature []byte) (*VerifiedSignedTransaction, error)
- 函数 VerifySignedTransaction(rawTx []byte, proof *OpeningProof) (*VerifiedSignedTransaction, error)
- 函数 (t *VerifiedSignedTransaction) PaymentSequence() protocol.PaymentSequence
- 函数 (t *VerifiedSignedTransaction) RawTx() []byte
- 函数 (t *VerifiedSignedTransaction) RefundTemplateTxID() RefundTemplateTxID
- 函数 (t *VerifiedSignedTransaction) SellerAmountSatoshis() protocol.Satoshis
- 函数 (t *VerifiedSignedTransaction) State() *PaymentState
常量
PoolOutputIndex 是 FundingTransactionRaw 中资金池输出的协议固定索引。 工作流只接受第 0 个输出作为资金池输出,因此无需在消息中重复传输。 对外协议版本只使用 protocol.WireVersion,本包不再定义任何平行版本常量。
const PoolOutputIndex uint32 = 0
函数 Build2of3LockingScript
func Build2of3LockingScript(keys MultisigPoolPublicKeys) ([]byte, error)
Build2of3LockingScript 使用明确的 Buyer、Seller 和 Arbiter 公钥,委托构造 2-of-3 MultisigPool 锁定脚本。
函数 BuildPoolLock
func BuildPoolLock(roles mp.ArbitratedPoolRoles) ([]byte, error)
BuildPoolLock 是公开的、明确角色的锁定适配器。v4 角色对象通过 Buyer、Seller 和 Arbiter 字段确定每个参与方的业务含义。
函数 CheckArbitrationRefundNotExpired
func CheckArbitrationRefundNotExpired(refundTemplateRaw []byte, facts protocol.Facts) error
CheckArbitrationRefundNotExpired applies the local nLockTime forward gate to the refund template using the caller's explicit facts: 只读取锁定类型对应的 那一份事实。It proves only that the template is not yet mature; it does not prove that the source output exists, is confirmed, or remains unspent.
函数 EncodeFundingTransactionDelivery
func EncodeFundingTransactionDelivery(delivery *FundingTransactionDelivery) ([]byte, error)
EncodeFundingTransactionDelivery 校验并编码 Kind 4 资金交易交付容器及其 RefundTemplateTxID 关联 ID。它不验证资金交易是否花费了保留的开池证明。
函数 EncodeOpeningProof
func EncodeOpeningProof(proof *OpeningProof) ([]byte, error)
EncodeOpeningProof 校验并编码完整的开池证明。各 ID、固定输出索引、金额和锁定脚本被刻意省略,因为它们都能从交易证据与参与方公钥派生。开池证明是应用本地证据,不属于十一种 wire Kind;其编码自身不带版本或 Kind。
函数 EncodePaymentUpdate
func EncodePaymentUpdate(update *PaymentUpdate) ([]byte, error)
EncodePaymentUpdate 校验并编码最小化的 Kind 7 容器:付款授权 ID 加分离的买方付款交易签名,构成四字段确定性 CBOR。费用池关联 ID 和未签名状态交易不上线传输:双方在本地用开池证明、上一付款状态和该 ID 引用的签名付款授权重建同一笔精确交易。这里只做结构校验,不代表节点接受,也不验证签名。
函数 EncodeRefundPresignRequest
func EncodeRefundPresignRequest(request *RefundPresignRequest) ([]byte, error)
EncodeRefundPresignRequest 校验并编码 Kind 2 买方退款预签请求:规范的未签名退款模板原始字节、角色公钥、费率和分离的买方交易签名。资金 outpoint、资金池金额和池锁都从 refund_template_raw 与参与方公钥规范派生;请求不重复携带派生出的 RefundTemplateTxID。
函数 EncodeRefundPresignResponse
func EncodeRefundPresignResponse(response *RefundPresignResponse) ([]byte, error)
EncodeRefundPresignResponse 校验并编码卖方的 Kind 3 退款签名响应,其中的费用池 RefundTemplateTxID 关联 ID 由卖方从请求重新派生。
函数 ParseCanonicalTransaction
func ParseCanonicalTransaction(raw []byte) (*tx.Transaction, error)
ParseCanonicalTransaction 仅在原始字节是 SDK 规范序列化时解析协议交易。工作流在派生出点、ID 或签名前使用它。
函数 RefundTemplateLockTime
func RefundTemplateLockTime(refundTemplateRaw []byte) (protocol.RefundLockTime, error)
RefundTemplateLockTime 从退款模板原文提取强类型 nLockTime;模板字节必须 是 canonical 交易编码。
函数 RefundUsesBlockHeight
func RefundUsesBlockHeight(refundTx []byte) (bool, error)
RefundUsesBlockHeight 确定性判断退款锁定时间类型。它解析提供的退款字节,当 Bitcoin nLockTime 小于时间戳阈值时返回 true;格式错误的字节会被拒绝。
函数 ValidateArbitrationClaimStructure
func ValidateArbitrationClaimStructure(poolOutputSatoshis uint64, poolOutputLockingScript, refundTemplateRaw []byte, paymentSequence uint32, sellerAmountAfterSatoshis uint64) error
ValidateArbitrationClaimStructure 为尚未确定仲裁费的证据持有方暴露 007 候选交易的纯结构检查。它与成功构造器执行完全相同的 source、角色脚本、退款模板、序号和 Seller 余额校验,但不要求正仲裁费,因此证据验证永远不需要占位金额。
函数 ValidateFundingTransactionDelivery
func ValidateFundingTransactionDelivery(delivery *FundingTransactionDelivery) error
ValidateFundingTransactionDelivery 要求非零 32 字节 RefundTemplateTxID 和资金交易原始字节;它不证明这些字节花费了对应 opening。
函数 ValidateOpeningProof
func ValidateOpeningProof(proof *OpeningProof) error
ValidateOpeningProof 检查角色公钥和原始退款证据。它是结构性检查;交易与签名关系由 VerifyOpening 完成。
函数 ValidatePaymentUpdate
func ValidatePaymentUpdate(update *PaymentUpdate) error
ValidatePaymentUpdate 检查 Kind 7 最小外壳、32 字节非零授权 ID 以及分离买方付款交易签名的存在性。它不解析交易,也不证明节点接受了任何东西;被引用的签名付款授权和重建的未签名状态交易由接收方 workflow 验证。
函数 ValidateRefundPresignRequest
func ValidateRefundPresignRequest(request *RefundPresignRequest) error
ValidateRefundPresignRequest 检查 Kind 2 请求所需的退款证据、角色公钥、费率和买方交易签名是否存在。它不密码学验证退款交易或任何一方签名。
函数 ValidateRefundPresignResponse
func ValidateRefundPresignResponse(response *RefundPresignResponse) error
ValidateRefundPresignResponse 要求非零 32 字节 RefundTemplateTxID 和卖方退款交易签名;把它们与具体请求匹配属于 workflow 操作。
函数 VerifyRefundPresignRequestEvidence
func VerifyRefundPresignRequestEvidence(request *RefundPresignRequest) error
VerifyRefundPresignRequestEvidence 完整验证 Kind 2 预签请求自身证据: 结构、角色、退款模板 canonical 重建与买方对模板的交易签名。恢复路径用它 保证 checkpoint 只能由真实证据重建。
类型 ArbiterPoolAdapter
ArbiterPoolAdapter 将费用池引擎适配到仲裁人工作流操作。
type ArbiterPoolAdapter struct {
*MultisigPoolEngine
// Signer 是仲裁方受约束签名能力。
Signer protocol.Signer
}
函数 NewArbiterPoolAdapter
func NewArbiterPoolAdapter(engine *MultisigPoolEngine, signer protocol.Signer) *ArbiterPoolAdapter
NewArbiterPoolAdapter 把引擎绑定到仲裁方 signer,用于签署 007 工作流选定的 candidate 状态。
函数 (*ArbiterPoolAdapter) SignArbiterPayment
func (adapter *ArbiterPoolAdapter) SignArbiterPayment(ctx context.Context, unsigned *UnsignedPayment, proof *OpeningProof) ([]byte, error)
SignArbiterPayment 为未签名费用池交易生成仲裁人分离签名。
类型 BuyerPoolAdapter
BuyerPoolAdapter adapts the pool engine to buyer workflow operations. Signer is the caller-supplied constrained signing capability; SDK 固定构造 sighash digest,Signer 只执行密钥操作,私钥绝不进入任何 wire 报文、本地结果、日志或持久化结构。
type BuyerPoolAdapter struct {
*MultisigPoolEngine
// Signer 是买方受约束签名能力(软件私钥适配器或 HSM/KMS 远程服务)。
Signer protocol.Signer
}
函数 NewBuyerPoolAdapter
func NewBuyerPoolAdapter(engine *MultisigPoolEngine, signer protocol.Signer) *BuyerPoolAdapter
NewBuyerPoolAdapter 把引擎绑定到买方 signer,用于分离式付款与退款签名。构造时不执行任何签名。
函数 (*BuyerPoolAdapter) BuildRefundPresignRequest
func (adapter *BuyerPoolAdapter) BuildRefundPresignRequest(ctx context.Context, input OpeningInput) (*RefundPresignRequest, error)
BuildRefundPresignRequest 使用适配器绑定的买方签名器,根据注资交易和开池输入构造 RefundPresignRequest。如果注资交易第 0 个输出未使用配置的费用池锁,或买方密钥与引擎不匹配,则返回错误。
函数 (*BuyerPoolAdapter) SignBuyerPayment
func (adapter *BuyerPoolAdapter) SignBuyerPayment(ctx context.Context, unsigned *UnsignedPayment, proof *OpeningProof) ([]byte, error)
SignBuyerPayment 为未签名费用池交易生成买方分离签名。
类型 CloseInput
CloseInput 提供立即关闭资金池、构造最终付款交易所需的开池证据、调用方 选定的基准状态和业务目标金额。Base 是否为业务最新状态、目标金额是否符合 订单或账本,由调用方决定;SDK 只验证协议编码与守恒边界。
type CloseInput struct {
// Opening 是用于验证资金池身份和多签交易规则的开池证据。
Opening *OpeningProof
// Base 是调用方选定的基准付款状态;SDK 不声称它是数据库最新状态。
Base *PaymentState
// SellerAmountAfterSatoshis 是候选最终关闭状态中卖方的累计金额,单位为 satoshi。
SellerAmountAfterSatoshis uint64
}
函数 CloneCloseInput
func CloneCloseInput(input CloseInput) CloseInput
CloneCloseInput 返回 CloseInput 的独立副本,并复制其中可变的字节切片。
类型 FundingTransactionDelivery
FundingTransactionDelivery 携带买方在退款交易验证完成后公开的、已由买方签名的资金交易, 以及用于路由到对应费用池的统一关联 ID。
type FundingTransactionDelivery struct {
// RefundTemplateTxID 是费用池统一关联 ID,只能从买方已验证的 OpeningProof
// 派生,不得由调用方另行拼接。
RefundTemplateTxID RefundTemplateTxID
// FundingTransactionRaw 是买方资金交易的原始序列化字节,卖方据此验证交易 ID、输入和池输出。
FundingTransactionRaw []byte
}
函数 CloneFundingTransactionDelivery
func CloneFundingTransactionDelivery(delivery *FundingTransactionDelivery) *FundingTransactionDelivery
CloneFundingTransactionDelivery 返回 FundingTransactionDelivery 的独立副本,包括所有可变字节切片的拷贝。
函数 DecodeFundingTransactionDelivery
func DecodeFundingTransactionDelivery(data []byte) (*FundingTransactionDelivery, error)
DecodeFundingTransactionDelivery 解码并做规范性检查 Kind 4 资金交付;证明与节点检查由 SellerAcceptFundingTx 完成。
类型 Hash32
Hash32 是通用 32 字节哈希的仓库唯一真值(protocol.Hash32 的别名): 资金池域内表示资金交易 TxID 等协议身份标识。领域专属身份继续使用独立 命名类型(如 RefundTemplateTxID),不与通用哈希互换。
type Hash32 = protocol.Hash32
类型 MultisigPoolEngine
MultisigPoolEngine 是到 MultisigPool v4 的适配边界。它保持买方/卖方/仲裁方的角色顺序,把脚本、费用、sighash、状态构造和签名顺序委托给该依赖。引擎不持有业务状态,也不执行任何存储、网络或节点 I/O。
type MultisigPoolEngine struct {
// contains filtered or unexported fields
}
函数 NewMultisigPoolEngine
func NewMultisigPoolEngine(config MultisigPoolEngineConfig) (*MultisigPoolEngine, error)
NewMultisigPoolEngine 解析并验证三个互不相同的角色密钥,为后续每次交易检查保留 Buyer/Seller/Arbiter 身份。密钥格式错误或重复时返回错误,且不会进行网络或存储 I/O。
函数 NewMultisigPoolEngineFromPoolLockingScript
func NewMultisigPoolEngineFromPoolLockingScript(raw []byte) (*MultisigPoolEngine, error)
NewMultisigPoolEngineFromPoolLockingScript 根据仲裁 Claim 提供的精确 source locking script 恢复带角色信息的费用池引擎。
函数 (*MultisigPoolEngine) BuildImmediateClose
func (engine *MultisigPoolEngine) BuildImmediateClose(input CloseInput) (*UnsignedPayment, error)
BuildImmediateClose 根据已接受支付和 CloseInput 构造未签名的最终关闭状态。买方随后通过 BuyerPoolAdapter 单独获得分离签名,卖方再添加自己的签名。
函数 (*MultisigPoolEngine) BuildOpeningProof
func (engine *MultisigPoolEngine) BuildOpeningProof(request *RefundPresignRequest, sellerSignature, fundingTx []byte) (*OpeningProof, error)
BuildOpeningProof 只保留原始开池证据。卖方保存预签待定证明时 fundingTx 可以为空;使用证明时即时推导所有交易身份和资金池输出条款。
函数 (*MultisigPoolEngine) BuildPaymentUpdate
func (engine *MultisigPoolEngine) BuildPaymentUpdate(input PaymentUpdateInput) (*UnsignedPayment, error)
BuildPaymentUpdate 根据上一笔已接受支付和请求金额构造下一笔未签名费用池状态交易。
这是协议的普通付款交易构造核心:买方和卖方使用相同的本地显式输入(开池证据、上一状态、目标序号、绝对卖方金额)调用它,以确定性地重建逐字节相同的未签名交易。007 路径改用 arbitration.go 中的 BuildArbitrationPaymentFromClaim:线上没有 OpeningProof 或 previous state,而是从已签名 Claim 的 source context 重建。
函数 (*MultisigPoolEngine) BuildRefundSubmission
func (engine *MultisigPoolEngine) BuildRefundSubmission(proof *OpeningProof) ([]byte, error)
BuildRefundSubmission 将开池证明中的买方和卖方退款签名合并为可广播交易。
函数 (*MultisigPoolEngine) CheckPaymentCapacity
func (engine *MultisigPoolEngine) CheckPaymentCapacity(input PaymentUpdateInput) error
CheckPaymentCapacity 只对调用方提供的更新执行确定性算术检查。BuildPaymentUpdate 会先完成 proof 绑定的 opening 和前态验证,再调用此辅助方法。
函数 (*MultisigPoolEngine) FundingTxID
func (engine *MultisigPoolEngine) FundingTxID(rawTx []byte) (Hash32, error)
FundingTxID 返回原始交易第一个输入中的 32 字节注资出点标识。
函数 (*MultisigPoolEngine) MergeArbitratedPoolSellerArbiterSignatures
func (engine *MultisigPoolEngine) MergeArbitratedPoolSellerArbiterSignatures(unsigned *UnsignedPayment, sellerSignature, arbiterSignature []byte) (*SignedPayment, error)
MergeArbitratedPoolSellerArbiterSignatures 是新 007 候选交易的唯一合并路径。它先验证两份分离签名,再把规范解锁脚本顺序交给 MultisigPool。
函数 (*MultisigPoolEngine) MergeBuyerSellerPayment
func (engine *MultisigPoolEngine) MergeBuyerSellerPayment(unsigned *UnsignedPayment, buyerSignature, sellerSignature []byte, proof *OpeningProof) (*SignedPayment, error)
函数 (*MultisigPoolEngine) MergeSellerArbiterPayment
func (engine *MultisigPoolEngine) MergeSellerArbiterPayment(unsigned *UnsignedPayment, sellerSignature, arbiterSignature []byte, proof *OpeningProof) (*SignedPayment, error)
函数 (*MultisigPoolEngine) ParseFinalPaymentState
func (engine *MultisigPoolEngine) ParseFinalPaymentState(rawTx []byte, proof *OpeningProof) (*PaymentState, error)
ParseFinalPaymentState 解析已完整签名的费用池交易,并验证其为最终结算(sequence == finalPoolSequence)。
函数 (*MultisigPoolEngine) ParseNonFinalPaymentState
func (engine *MultisigPoolEngine) ParseNonFinalPaymentState(rawTx []byte, proof *OpeningProof) (*PaymentState, error)
ParseNonFinalPaymentState 解析完整签名的费用池交易,并在任何后端接收前拒绝保留的最终关闭序号。
函数 (*MultisigPoolEngine) ParsePaymentState
func (engine *MultisigPoolEngine) ParsePaymentState(rawTx []byte, proof *OpeningProof) (*PaymentState, error)
ParsePaymentState 将已完整签名的费用池交易解析为 PaymentState。交易的解锁脚本为空时返回错误。
函数 (*MultisigPoolEngine) ParseUnsignedPayment
func (engine *MultisigPoolEngine) ParseUnsignedPayment(rawTx []byte, proof *OpeningProof) (*UnsignedPayment, error)
ParseUnsignedPayment 根据开池证明的规范状态验证并解析未签名费用池交易。
函数 (*MultisigPoolEngine) PaymentStateMatchesUnsigned
func (engine *MultisigPoolEngine) PaymentStateMatchesUnsigned(state *PaymentState, unsigned *UnsignedPayment, proof *OpeningProof) error
PaymentStateMatchesUnsigned 证明先前接受的已签名状态与未签名候选完全相同,包括全部规范交易字节。它只用于幂等完成重试,绝不签名或提交。
函数 (*MultisigPoolEngine) SignArbitrationArbiterPayment
func (engine *MultisigPoolEngine) SignArbitrationArbiterPayment(ctx context.Context, unsigned *UnsignedPayment, signer protocol.Signer) ([]byte, error)
SignArbitrationArbiterPayment 用仲裁方角色的受约束 Signer 签署独立重建的仲裁 candidate。
函数 (*MultisigPoolEngine) SignArbitrationSellerPayment
func (engine *MultisigPoolEngine) SignArbitrationSellerPayment(ctx context.Context, unsigned *UnsignedPayment, signer protocol.Signer) ([]byte, error)
SignArbitrationSellerPayment 用卖方角色的受约束 Signer 签署独立重建的仲裁 candidate。
函数 (*MultisigPoolEngine) TransactionID
func (engine *MultisigPoolEngine) TransactionID(rawTx []byte) (Hash32, error)
TransactionID 根据原始交易字节计算规范交易标识符。
函数 (*MultisigPoolEngine) VerifyAcceptedPayment
func (engine *MultisigPoolEngine) VerifyAcceptedPayment(state *PaymentState, proof *OpeningProof) error
VerifyAcceptedPayment 将初始或此前接受的非仲裁支付状态与开池证明及完整角色签名进行核对。
函数 (*MultisigPoolEngine) VerifyArbiterPayment
func (engine *MultisigPoolEngine) VerifyArbiterPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
VerifyArbiterPayment 在仲裁签名离开 SDK 前,验证它对未签名累计状态的分离签名。
函数 (*MultisigPoolEngine) VerifyArbitratedPayment
func (engine *MultisigPoolEngine) VerifyArbitratedPayment(state *PaymentState, proof *OpeningProof) error
VerifyArbitratedPayment 检查携带 007 仲裁流程所需卖方和仲裁人签名的最终状态。
函数 (*MultisigPoolEngine) VerifyArbitrationArbiterPayment
func (engine *MultisigPoolEngine) VerifyArbitrationArbiterPayment(unsigned *UnsignedPayment, signature []byte) error
VerifyArbitrationArbiterPayment 验证 Arbiter 对精确独立重建候选交易的交易签名。
函数 (*MultisigPoolEngine) VerifyArbitrationSellerPayment
func (engine *MultisigPoolEngine) VerifyArbitrationSellerPayment(unsigned *UnsignedPayment, signature []byte) error
VerifyArbitrationSellerPayment 验证 Seller 对精确独立重建候选交易的交易签名。
函数 (*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(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) VerifyRefundExpiredAt
func (engine *MultisigPoolEngine) VerifyRefundExpiredAt(proof *OpeningProof, at time.Time, blockHeight uint32) error
VerifyRefundExpiredAt checks whether the refund transaction's nLockTime has been reached at the caller-supplied explicit facts: timestamp locks compare against at,height locks compare against blockHeight。SDK 不读取系统时钟, 也不查询节点。
函数 (*MultisigPoolEngine) VerifyRefundNotExpiredAt
func (engine *MultisigPoolEngine) VerifyRefundNotExpiredAt(proof *OpeningProof, at time.Time, blockHeight uint32) error
VerifyRefundNotExpiredAt 是正向操作门禁。它与 VerifyRefundExpiredAt 刻意分离,确保退款路径可执行后内容与付款工作流不会误继续。
函数 (*MultisigPoolEngine) VerifySellerPayment
func (engine *MultisigPoolEngine) VerifySellerPayment(unsigned *UnsignedPayment, sig []byte, proof *OpeningProof) error
VerifySellerPayment 检查卖方角色对精确未签名 005 支付状态的分离签名,以及该状态与 002 开池证明之间的规范关系。它不会合并签名或提交更新。
函数 (*MultisigPoolEngine) VerifySellerRefundSignature
func (engine *MultisigPoolEngine) VerifySellerRefundSignature(request *RefundPresignRequest, signature []byte) error
VerifySellerRefundSignature 验证 request 指定的 002 预签名退款状态,包括其注资出点、角色密钥、买方签名和提供的卖方分离签名。它不会提交任何一笔交易。
类型 MultisigPoolEngineConfig
MultisigPoolEngineConfig 按角色顺序提供压缩的买方、卖方和仲裁方公钥。退款到期检查在每次调用时显式接收调用方提供的时间和区块高度;费用与交易规则来自 MultisigPool v4。
type MultisigPoolEngineConfig struct {
// BuyerPublicKey 是费用池第一角色的压缩公钥(33 字节);角色顺序固定
// [Buyer, Seller, Arbiter],不可互换。
BuyerPublicKey []byte
// SellerPublicKey 是费用池第二角色的压缩公钥(33 字节)。
SellerPublicKey []byte
// ArbiterPublicKey 是费用池第三角色(仲裁方)的压缩公钥(33 字节)。
ArbiterPublicKey []byte
}
类型 MultisigPoolPublicKeys
MultisigPoolPublicKeys 按结算角色标识费用池的三个参与方。明确的字段让调用方无需依赖公钥的位置顺序。
type MultisigPoolPublicKeys struct {
// BuyerPublicKey 是资金池输出锁定脚本中的第一个角色公钥(压缩 33 字节)。
BuyerPublicKey []byte
// SellerPublicKey 是资金池输出锁定脚本中的第二个角色公钥(压缩 33 字节)。
SellerPublicKey []byte
// ArbiterPublicKey 是资金池输出锁定脚本中的第三个角色公钥(压缩 33 字节)。
ArbiterPublicKey []byte
}
函数 ParseArbitratedPoolLockingScript
func ParseArbitratedPoolLockingScript(raw []byte) (MultisigPoolPublicKeys, error)
ParseArbitratedPoolLockingScript 只接受规范的 OP_2 <Buyer> <Seller> <Arbiter> OP_3 OP_CHECKMULTISIG 脚本。它不会规范化 push 编码、排序公钥,也不会从签名推断角色。
类型 OpeningDetails
OpeningDetails 是从 OpeningProof 原始证据即时计算出的只读视图。它不属于协议消息,也不会被编码或持久化为 OpeningProof 的字段。
type OpeningDetails struct {
// RefundTemplateTxID 是费用池统一关联 ID(按交易 TxID 算法从规范退款模板派生,
// 不是普通 SHA-256 文档 ID),路由 002–007 的全部报文。
RefundTemplateTxID RefundTemplateTxID
// FundingTxID 是资金交易的链上交易 ID(Hash32)。
FundingTxID Hash32
// PoolOutputSatoshis 是资金池输出的聪数;重建 candidate 时作为输入金额。
PoolOutputSatoshis uint64
// PoolLockingScript 是角色顺序固定 [Buyer, Seller, Arbiter] 的 2-of-3
// 锁定脚本字节(105 字节)。
PoolLockingScript []byte
// RefundLockTime 是从规范退款模板派生的 nLockTime 原始值,供 SDK 内部
// 协议操作和调用方审计使用。时间与高度都是显式事实:timestamp 锁定由
// Facts.Now 判断,height 锁定由 Facts.BlockHeight 判断;SDK 绝不读取时钟。
RefundLockTime uint32
}
函数 DeriveOpeningDetails
func DeriveOpeningDetails(proof *OpeningProof) (*OpeningDetails, error)
DeriveOpeningDetails 从证明的交易字节和参与方公钥推导交易身份及资金池输出条款。返回的视图是临时值,绝不属于传输的 OpeningProof。
类型 OpeningInput
OpeningInput 仅包含构造资金池所需的通用输入数据。
该对象由买方使用,不携带卖方签名;它用于生成 RefundPresignRequest, 而不是直接表示已经完成的 OpeningProof。
type OpeningInput struct {
// FundingTransactionRaw 是买方资金交易的原始序列化字节;其第 0 个输出必须是资金池输出。
FundingTransactionRaw []byte
// ExpiryLockTime 是退款交易使用的到期锁定时间,具体解释遵循底层交易协议。
ExpiryLockTime uint32
// MinerFeeRateSatoshisPerKilobyte 是构造退款和付款交易时采用的矿工费率,单位为 satoshi/KB。
MinerFeeRateSatoshisPerKilobyte uint64
// SellerPublicKey 是卖方的压缩 secp256k1 公钥原始字节。
SellerPublicKey []byte
// ArbiterPublicKey 是仲裁方的压缩 secp256k1 公钥原始字节。
ArbiterPublicKey []byte
}
函数 CloneOpeningInput
func CloneOpeningInput(input OpeningInput) OpeningInput
CloneOpeningInput 返回 OpeningInput 的独立副本,并复制其中可变的字节切片。
类型 OpeningProof
OpeningProof 保存买卖双方相互验证后、用于开立资金池的退款交易和资金交易证据。
该对象通常在卖方签署退款交易后形成,在买方交付资金交易原文后补全。 RefundTemplateRaw、FundingTransactionRaw 以及各类公钥和签名均为协议要求的原始字节,调用方 不应在持久化或传输前擅自重新编码。
type OpeningProof struct {
// RefundTemplateRaw 是预签名退款交易的原始序列化字节。
// 该交易构成资金池的关联 ID 源,并由买方和卖方共同提供退款签名。
RefundTemplateRaw []byte
// BuyerPublicKey 是买方的 33 字节压缩 secp256k1 公钥。
BuyerPublicKey []byte
// SellerPublicKey 是卖方的 33 字节压缩 secp256k1 公钥。
SellerPublicKey []byte
// ArbiterPublicKey 是仲裁方的 33 字节压缩 secp256k1 公钥。
ArbiterPublicKey []byte
// MinerFeeRateSatoshisPerKilobyte 是构造池内交易时采用的矿工费率,单位为 satoshi/KB。
MinerFeeRateSatoshisPerKilobyte uint64
// BuyerRefundTransactionSignature 是买方对预签名退款交易提供的 DER 签名原始字节。
BuyerRefundTransactionSignature []byte
// SellerRefundTransactionSignature 是卖方对同一预签名退款交易提供的 DER 签名原始字节。
SellerRefundTransactionSignature []byte
// FundingTransactionRaw 是买方资金交易的原始序列化字节。
// 它通常在退款证据验证完成后单独交付给卖方。
FundingTransactionRaw []byte
}
函数 CloneOpeningProof
func CloneOpeningProof(proof *OpeningProof) *OpeningProof
CloneOpeningProof 返回 OpeningProof 的独立副本,并复制其中可变的字节切片。
函数 DecodeOpeningProof
func DecodeOpeningProof(data []byte) (*OpeningProof, error)
DecodeOpeningProof 解码并规范性检查开池证明,然后执行字段校验;签名与交易关系仍需 VerifyOpening 完成。
函数 (*OpeningProof) OpeningArbiterPublicKey
func (proof *OpeningProof) OpeningArbiterPublicKey() []byte
函数 (*OpeningProof) OpeningBuyerPublicKey
func (proof *OpeningProof) OpeningBuyerPublicKey() []byte
函数 (*OpeningProof) OpeningRefundTemplateTxID
func (proof *OpeningProof) OpeningRefundTemplateTxID() []byte
函数 (*OpeningProof) OpeningSellerPublicKey
func (proof *OpeningProof) OpeningSellerPublicKey() []byte
类型 PaymentState
PaymentState 表示角色签名完整合并后的付款状态。
RawTx 必须是完整可验证的交易,不能是未签名交易,也不能是只有一个角色签名的中间交易。若工作流需要跨 API 边界传递独立签名,可以保存在下面的签名字段中,但这些字段不改变 RawTx 必须完整的约束。是否已被节点接受由调用方根据自己的广播与对账结果决定,SDK 不做此声明。
type PaymentState struct {
// RefundTemplateTxID 是该付款所属费用池的统一关联 ID,即未嵌入角色签名的
// 规范退款模板交易 ID,而非最终链上退款 txid。
RefundTemplateTxID RefundTemplateTxID
// RawTx 是签名完整的付款状态交易原始字节。
RawTx []byte
// PaymentSequence 是该状态在资金池付款链中的序号。
// 普通内容交付更新必须相对于上一状态恰好递增 1。
PaymentSequence uint32
// BuyerAmountSatoshis 是交易向买方分配的金额,单位为 satoshi。
BuyerAmountSatoshis uint64
// SellerAmountSatoshis 是交易向卖方分配的累计金额,单位为 satoshi。
SellerAmountSatoshis uint64
// ArbiterAmountSatoshis 是交易向仲裁方分配的绝对金额,单位为 satoshi。
// 普通 005 付款恒为零;007 仲裁状态交易必须为正数,且等于回执中的
// 仲裁费。两种场景下它都是本次交易的绝对分配额,不是增量。
ArbiterAmountSatoshis uint64
// PaymentAuthorizationID 是绑定该付款的 Kind 5 文档 typed ID。
PaymentAuthorizationID protocol.PaymentAuthorizationID
// BuyerTransactionSignature 是买方在该付款交易中的 DER 签名原始字节。
BuyerTransactionSignature []byte
// SellerTransactionSignature 是卖方在该付款交易中的 DER 签名原始字节。
SellerTransactionSignature []byte
// ArbiterTransactionSignature 是仲裁方在该付款交易中的 DER 签名原始字节。
ArbiterTransactionSignature []byte
// PoolOutputSatoshis 是创建该付款状态时引用的资金池输出金额,单位为 satoshi。
PoolOutputSatoshis uint64
// PoolLockingScript 是创建该付款状态时引用的资金池输出锁定脚本原始字节。
PoolLockingScript []byte
}
函数 ClonePaymentState
func ClonePaymentState(state *PaymentState) *PaymentState
ClonePaymentState 返回 PaymentState 的独立副本,并复制其中可变的字节切片。
类型 PaymentUpdate
PaymentUpdate 是 Kind 7 PaymentUpdate 使用的最小付款凭证传输容器。
它只携带内容授权哈希和买方对确定性重建状态交易的签名;费用池 ID 与未签名 状态交易不再进入 wire。接收方先用 PaymentAuthorizationID 取回保存的精确 原始 003,再从 003、OpeningProof 和 previous PaymentState 在本地调用唯一的 BuildPaymentUpdate 重建同一笔未签名状态交易,验过买方签名后补签并合并。 授权哈希是内容寻址键,不可解码出池 ID、金额或交易字节。
type PaymentUpdate struct {
// PaymentAuthorizationID 是 payment_authorization_cbor 的 SHA-256 typed ID。
// 它是本次付款授权的应用查找键,不携带任何池身份或路由信息。
PaymentAuthorizationID protocol.PaymentAuthorizationID
// BuyerPaymentTransactionSignature 是买方针对双方本地确定性重建的未签名
// 状态交易的 DER 签名原始字节。该签名与交易原文分离传输,不能把它预先写回
// 重建交易,也不是对任何文档的普通消息签名。
BuyerPaymentTransactionSignature []byte
}
函数 ClonePaymentUpdate
func ClonePaymentUpdate(update *PaymentUpdate) *PaymentUpdate
ClonePaymentUpdate 返回 PaymentUpdate 的独立副本,并复制其中可变的字节切片。
函数 DecodePaymentUpdate
func DecodePaymentUpdate(data []byte) (*PaymentUpdate, error)
DecodePaymentUpdate 解码并规范性检查 Kind 7 四元最小容器,然后校验字段形状。其他任何形状一律直接拒绝;它不证明费用池归属,也不针对重建交易验证买方签名。
类型 PaymentUpdateInput
PaymentUpdateInput 提供构造下一笔累计付款状态所需的开池证据、上一状态和目标金额。
type PaymentUpdateInput struct {
// Opening 是用于验证资金池身份、输出和参与方密钥的开池证据。
Opening *OpeningProof
// Previous 是上一笔已接受的付款状态;首次构造付款时可表示初始退款状态。
Previous *PaymentState
// PaymentSequence 是新付款状态的目标序号;普通内容交付更新必须为
// 上一序号恰好加 1,且不得使用保留的最终关闭序号。
PaymentSequence uint32
// SellerAmountAfterSatoshis 是新状态中卖方的累计金额,单位为 satoshi。
SellerAmountAfterSatoshis uint64
}
函数 ClonePaymentUpdateInput
func ClonePaymentUpdateInput(input PaymentUpdateInput) PaymentUpdateInput
ClonePaymentUpdateInput 返回 PaymentUpdateInput 的独立副本,并复制其中可变的字节切片。
类型 RefundPresignRequest
RefundPresignRequest 包含买方请求卖方预签退款交易时发送的开池条款和交易材料。
该请求由买方构造,卖方验证退款交易、资金池输出、公钥及费率后,使用 SellerPublicKey 对退款交易签名并返回 RefundPresignResponse。请求本身不包含 FundingTransactionRaw 原文;资金交易 ID 和固定输出索引直接从 RefundTemplateRaw 的 input 推导。
type RefundPresignRequest struct {
// RefundTemplateRaw 是买方构造的预签名退款交易原始字节。
RefundTemplateRaw []byte
// BuyerPublicKey 是买方的压缩 secp256k1 公钥原始字节。
BuyerPublicKey []byte
// SellerPublicKey 是买方期望用于卖方签名校验的压缩 secp256k1 公钥。
SellerPublicKey []byte
// ArbiterPublicKey 是仲裁方的压缩 secp256k1 公钥原始字节。
ArbiterPublicKey []byte
// MinerFeeRateSatoshisPerKilobyte 是池内交易采用的矿工费率,单位为 satoshi/KB。
MinerFeeRateSatoshisPerKilobyte uint64
// BuyerRefundTransactionSignature 是买方已经附加到退款交易上的 DER 签名原始字节。
BuyerRefundTransactionSignature []byte
}
函数 CloneRefundPresignRequest
func CloneRefundPresignRequest(request *RefundPresignRequest) *RefundPresignRequest
CloneRefundPresignRequest 返回 RefundPresignRequest 的独立副本,并复制其中可变的字节切片。
函数 DecodeRefundPresignRequest
func DecodeRefundPresignRequest(data []byte) (*RefundPresignRequest, error)
DecodeRefundPresignRequest 解码并规范性检查 Kind 2 请求;密码学验证与资金交易接受仍是开池 workflow 的职责。
类型 RefundPresignResponse
RefundPresignResponse 携带卖方对预签名退款交易的 DER 签名以及该请求的 统一关联 ID。
type RefundPresignResponse struct {
// RefundTemplateTxID 是费用池统一关联 ID,由卖方从收到的 request 的
// 规范退款模板重新派生,不允许调用方任意填写。
RefundTemplateTxID RefundTemplateTxID
// SellerRefundTransactionSignature 是卖方对 RefundPresignRequest.RefundTemplateRaw 的签名原始字节。
SellerRefundTransactionSignature []byte
}
函数 CloneRefundPresignResponse
func CloneRefundPresignResponse(response *RefundPresignResponse) *RefundPresignResponse
CloneRefundPresignResponse 返回 RefundPresignResponse 的独立副本,并复制其中可变的字节切片。
函数 DecodeRefundPresignResponse
func DecodeRefundPresignResponse(data []byte) (*RefundPresignResponse, error)
DecodeRefundPresignResponse 解码并规范性检查 Kind 3 卖方响应,不判断签名是否匹配某个具体请求。
类型 RefundTemplateTxID
RefundTemplateTxID 是费用池的统一关联 ID:未嵌入角色签名的规范退款模板 交易的 TxID。它只标识资金池本身,不标识同一资金池内的某次关闭或付款尝试, 也不是最终广播退款交易的链上 txid。普通内容哈希继续使用各自的 Hash32, 不能把所有 32 字节值混成资金池关联 ID。
type RefundTemplateTxID [sha256.Size]byte
函数 DeriveRefundTemplateTxID
func DeriveRefundTemplateTxID(proof *OpeningProof) (RefundTemplateTxID, error)
DeriveRefundTemplateTxID 返回费用池统一关联 ID,即 OpeningProof 携带的未嵌入角色签名的规范退款模板交易的交易 ID。交易身份由 SDK 固定交易解析器计算,应用不提供计算器。合并后可广播的退款交易具有不同的链上 txid;该最终 txid 只是提交结果记录,绝不替换 RefundTemplateTxID。
函数 DeriveRefundTemplateTxIDFromRequest
func DeriveRefundTemplateTxIDFromRequest(request *RefundPresignRequest) (RefundTemplateTxID, error)
DeriveRefundTemplateTxIDFromRequest 在尚不存在任何 OpeningProof 时,直接从 0201 RefundPresignRequest 派生同一费用池关联 ID。它与 DeriveRefundTemplateTxID 共享唯一的规范解析和 TxID 计算,因此同一 RefundTemplateRaw 在两个入口返回逐字节相同的结果。
类型 SellerPoolAdapter
SellerPoolAdapter 将费用池引擎适配到卖方工作流操作。
type SellerPoolAdapter struct {
*MultisigPoolEngine
// Signer 是卖方受约束签名能力。
Signer protocol.Signer
}
函数 NewSellerPoolAdapter
func NewSellerPoolAdapter(engine *MultisigPoolEngine, signer protocol.Signer) *SellerPoolAdapter
NewSellerPoolAdapter 把引擎绑定到卖方 signer,用于分离式付款、退款与仲裁 candidate 签名。
函数 (*SellerPoolAdapter) MergeBuyerSellerPayment
func (adapter *SellerPoolAdapter) MergeBuyerSellerPayment(unsigned *UnsignedPayment, buyerSignature, sellerSignature []byte, proof *OpeningProof) (*SignedPayment, error)
MergeBuyerSellerPayment 将分离的角色签名合并为所需的完整支付交易。
函数 (*SellerPoolAdapter) MergeSellerArbiterPayment
func (adapter *SellerPoolAdapter) MergeSellerArbiterPayment(unsigned *UnsignedPayment, sellerSignature, arbiterSignature []byte, proof *OpeningProof) (*SignedPayment, error)
MergeSellerArbiterPayment 将分离的角色签名合并为所需的完整支付交易。
函数 (*SellerPoolAdapter) SignImmediateClose
func (adapter *SellerPoolAdapter) SignImmediateClose(ctx context.Context, unsigned *UnsignedPayment, buyerSignature []byte, proof *OpeningProof) (*SignedPayment, error)
SignImmediateClose 为立即关闭交易的卖方部分签名,并与买方签名合并后返回完整 SignedPayment。
函数 (*SellerPoolAdapter) SignSellerPayment
func (adapter *SellerPoolAdapter) SignSellerPayment(ctx context.Context, unsigned *UnsignedPayment, proof *OpeningProof) ([]byte, error)
SignSellerPayment 为未签名费用池交易生成卖方分离签名。
函数 (*SellerPoolAdapter) SignSellerRefund
func (adapter *SellerPoolAdapter) SignSellerRefund(ctx context.Context, request *RefundPresignRequest) ([]byte, error)
SignSellerRefund 为请求描述的预签名退款交易生成卖方分离签名。
函数 (*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 开池证明之间的规范关系。它不会合并买方签名或提交更新。
类型 SignedPayment
SignedPayment 包含一份付款状态及其对应的交易原始字节。
type SignedPayment struct {
// State 保存付款金额、序号、资金池身份和交易签名等解析后的状态信息。
State PaymentState
// RawTx 保存与 State 对应的付款交易原始字节。
RawTx []byte
}
函数 CloneSignedPayment
func CloneSignedPayment(payment *SignedPayment) *SignedPayment
CloneSignedPayment 返回 SignedPayment 的独立副本,并复制其中可变的字节切片。
类型 UnsignedPayment
UnsignedPayment 是单角色签名方法唯一接受的交易对象。
它只描述未签名交易及其可验证的状态元数据,不包含解锁脚本,也不包含 任何嵌入式签名;各角色应在此对象基础上独立生成签名。
type UnsignedPayment struct {
// RefundTemplateTxID 是该付款所属费用池的统一关联 ID,即未嵌入角色签名的
// 规范退款模板交易 ID。
RefundTemplateTxID RefundTemplateTxID
// RawTx 是未签名付款交易的原始字节,不得包含解锁脚本或交易签名。
RawTx []byte
// PaymentSequence 是待签名付款状态的序号。
PaymentSequence uint32
// BuyerAmountSatoshis 是交易向买方分配的金额,单位为 satoshi。
BuyerAmountSatoshis uint64
// SellerAmountSatoshis 是交易向卖方分配的累计金额,单位为 satoshi。
SellerAmountSatoshis uint64
// ArbiterAmountSatoshis 是交易向仲裁方分配的绝对金额,单位为 satoshi。
// 普通 005 付款恒为零;007 仲裁状态交易必须为正数,且等于调用方传入
// builder 的明确仲裁费。两种场景下它都是本次交易的绝对分配额,不是增量。
ArbiterAmountSatoshis uint64
// PoolOutputSatoshis 是该付款所引用的资金池输出金额,单位为 satoshi。
PoolOutputSatoshis uint64
// PoolLockingScript 是该付款所引用的资金池输出锁定脚本原始字节。
PoolLockingScript []byte
// contains filtered or unexported fields
}
函数 BuildArbitrationPaymentFromClaim
func BuildArbitrationPaymentFromClaim(poolOutputSatoshis uint64, poolOutputLockingScript, refundTemplateRaw []byte, paymentSequence uint32, sellerAmountAfterSatoshis uint64, arbiterAmountSatoshis uint64) (*UnsignedPayment, error)
BuildArbitrationPaymentFromClaim 是固定 MultisigPool 交易规则下唯一的 007 candidate 构造器。它只接受 source amount、source locking script、退款模板字节、目标序号、绝对卖方金额和明确的绝对仲裁费。成功的 007 要求正仲裁费;这里绝不接受零。source metadata 只为 ForkID sighash 计算加入内存交易,绝不会序列化进 RawTx。
类型 VerifiedOpening
VerifiedOpening 是字段私有、访问器防御性复制的已验证开池证明:它证明退款 模板结构、角色脚本、买卖双方退款签名与(若已交付)资金交易关系全部正确。 它不拥有存储或网络行为;应用自行持久化 exact evidence 并负责广播边界。
type VerifiedOpening struct {
// contains filtered or unexported fields
}
函数 VerifyOpeningProof
func VerifyOpeningProof(proof *OpeningProof) (*VerifiedOpening, error)
VerifyOpeningProof 对开池证据执行完整协议验证:退款模板 canonical 重建、 角色脚本、买卖双方退款签名与(若已交付)资金交易关系。伪造或篡改的 OpeningProof 无法得到 VerifiedOpening。角色归属绑定由调用方补充检查。
函数 (*VerifiedOpening) ArbiterPublicKey
func (v *VerifiedOpening) ArbiterPublicKey() []byte
ArbiterPublicKey 返回仲裁方压缩公钥副本。
函数 (*VerifiedOpening) BuyerPublicKey
func (v *VerifiedOpening) BuyerPublicKey() []byte
BuyerPublicKey 返回买方压缩公钥副本。
函数 (*VerifiedOpening) FundingTransactionRaw
func (v *VerifiedOpening) FundingTransactionRaw() []byte
FundingTransactionRaw 返回已交付资金交易的原始字节副本;未交付时为空。
函数 (*VerifiedOpening) MatchesBuyer
func (v *VerifiedOpening) MatchesBuyer(publicKey []byte) bool
MatchesBuyer 报告该开池证明是否属于指定买方压缩公钥。
函数 (*VerifiedOpening) MatchesSeller
func (v *VerifiedOpening) MatchesSeller(publicKey []byte) bool
MatchesSeller 报告该开池证明是否属于指定卖方压缩公钥。
函数 (*VerifiedOpening) Proof
func (v *VerifiedOpening) Proof() *OpeningProof
Proof 返回深拷贝的完整开池证据(含全部公钥、签名与交易原文)。
函数 (*VerifiedOpening) RefundTemplateTxID
func (v *VerifiedOpening) RefundTemplateTxID() RefundTemplateTxID
RefundTemplateTxID 返回派生的费用池统一关联 ID。
函数 (*VerifiedOpening) SellerPublicKey
func (v *VerifiedOpening) SellerPublicKey() []byte
SellerPublicKey 返回卖方压缩公钥副本。
类型 VerifiedPaymentState
VerifiedPaymentState 是字段私有、访问器防御性复制的已验证付款状态: RawTx 必须是完整可验证交易;SDK 不声明节点接受或业务最新状态。
type VerifiedPaymentState struct {
// contains filtered or unexported fields
}
函数 VerifyPaymentState
func VerifyPaymentState(state *PaymentState, proof *OpeningProof) (*VerifiedPaymentState, error)
VerifyPaymentState 验证一份已合并付款状态在给定 opening 下密码学完整: 依次尝试普通 Buyer+Seller 与仲裁 Seller+Arbiter 两条完整签名路径;两者都 失败即拒绝。伪造的 PaymentState 无法得到 VerifiedPaymentState。
函数 (*VerifiedPaymentState) ArbiterAmountSatoshis
func (v *VerifiedPaymentState) ArbiterAmountSatoshis() protocol.Satoshis
ArbiterAmountSatoshis 返回仲裁方绝对分配额(绝对聪数);普通付款恒为零。
函数 (*VerifiedPaymentState) BuyerAmountSatoshis
func (v *VerifiedPaymentState) BuyerAmountSatoshis() protocol.Satoshis
BuyerAmountSatoshis 返回买方分配金额(绝对聪数)。
函数 (*VerifiedPaymentState) PaymentSequence
func (v *VerifiedPaymentState) PaymentSequence() protocol.PaymentSequence
PaymentSequence 返回该状态的付款序号。
函数 (*VerifiedPaymentState) RawTx
func (v *VerifiedPaymentState) RawTx() []byte
RawTx 返回完整签名的付款状态交易原始字节副本。
函数 (*VerifiedPaymentState) RefundTemplateTxID
func (v *VerifiedPaymentState) RefundTemplateTxID() RefundTemplateTxID
RefundTemplateTxID 返回所属费用池统一关联 ID。
函数 (*VerifiedPaymentState) SellerAmountSatoshis
func (v *VerifiedPaymentState) SellerAmountSatoshis() protocol.Satoshis
SellerAmountSatoshis 返回卖方的绝对累计金额(绝对聪数)。
函数 (*VerifiedPaymentState) State
func (v *VerifiedPaymentState) State() *PaymentState
State 返回深拷贝的付款状态(金额、序号、池身份与角色签名)。
类型 VerifiedSignedTransaction
VerifiedSignedTransaction 是字段私有、访问器防御性复制的完整签名交易结果: 密码学签名已完成并经 SDK 自验/复核(Complete),但 SDK 绝不声称它已被节点 接受、已广播或已确认;广播与对账是应用的决定。
type VerifiedSignedTransaction struct {
// contains filtered or unexported fields
}
函数 CompleteArbitratedTransaction
func CompleteArbitratedTransaction(unsigned *UnsignedPayment, sellerSignature, arbiterSignature []byte) (*VerifiedSignedTransaction, error)
CompleteArbitratedTransaction 是 007 收款合并的唯一原子入口:在 pool 内部 一次完成 Seller/Arbiter 双签名验证、canonical 合并与 Verified 构造。 它不依赖任何"调用前已验证"的顺序约定——双签名中任意一个无效都会整体失败, 不产生部分结果;成功返回的 VerifiedSignedTransaction 才代表密码学完整。
函数 VerifySignedTransaction
func VerifySignedTransaction(rawTx []byte, proof *OpeningProof) (*VerifiedSignedTransaction, error)
VerifySignedTransaction 解析并完整验证一笔 opening 约束下的完整签名交易 (累计付款、立即关闭或到期退款提交):逐字节解析、池 outpoint/输出关系、 双方角色签名全部复核。伪造 raw bytes 无法得到 VerifiedSignedTransaction; 广播与否仍由应用决定。
函数 (*VerifiedSignedTransaction) PaymentSequence
func (t *VerifiedSignedTransaction) PaymentSequence() protocol.PaymentSequence
PaymentSequence 返回状态序号;无状态元数据时返回 0。
函数 (*VerifiedSignedTransaction) RawTx
func (t *VerifiedSignedTransaction) RawTx() []byte
RawTx 返回完整签名交易原始字节副本;仅供应用决定是否广播。
函数 (*VerifiedSignedTransaction) RefundTemplateTxID
func (t *VerifiedSignedTransaction) RefundTemplateTxID() RefundTemplateTxID
RefundTemplateTxID 返回所属费用池统一关联 ID。
函数 (*VerifiedSignedTransaction) SellerAmountSatoshis
func (t *VerifiedSignedTransaction) SellerAmountSatoshis() protocol.Satoshis
SellerAmountSatoshis 返回卖方累计金额(绝对聪数);无状态元数据时返回 0。
函数 (*VerifiedSignedTransaction) State
func (t *VerifiedSignedTransaction) State() *PaymentState
State 返回解析后的状态元数据深拷贝;可能为 nil(例如纯退款提交场景由 调用方自行解析)。
由 gomarkdoc 生成