Documentation
¶
Index ¶
- Constants
- func BuildSignedServiceReceipt(serverPrivHex string, isMainnet bool, offerHash string, serviceType string, ...) ([]byte, error)
- func CalcFee(t *tx.Transaction) uint64
- func CalcFeeWithInputAmount(t *tx.Transaction, inputAmount uint64) uint64
- func ClientIDAliasesForQuery(clientID string) []string
- func CountChargeEventsByClientAndReason(db *sql.DB, clientID string, reason string) (int, error)
- func FinalizeServiceResult[T any](serverPrivHex string, isMainnet bool, clientID string, payOut PayConfirmResp, ...) (T, error)
- func FreezeOtherActiveSessionsByClientTx(tx *sql.Tx, clientID string, keepSpendTxID string, reason string, ...) error
- func GetGatewayAdminConfig(db *sql.DB, key string) (string, bool, error)
- func HashServiceParamsPayload(raw []byte) string
- func InitGatewayStore(db *sql.DB) error
- func InsertChargeEvent(db *sql.DB, clientID string, spendTxID string, sequence uint32, reason string, ...) error
- func InsertChargeEventTx(tx *sql.Tx, clientID string, spendTxID string, sequence uint32, reason string, ...) error
- func InsertServiceQuotePayment(db *sql.DB, row ServiceQuotePaymentRow) error
- func InsertSession(db *sql.DB, row GatewaySessionRow) error
- func Libp2pMarshalPubHexToSecpCompressedHex(marshalPubHex string) (string, error)
- func ListClientsByChargeReason(db *sql.DB, reason string) ([]string, error)
- func ListenOfferBudgetToDurationSeconds(proposedPayment uint64, minimumPayment uint64, minimumDurationSeconds uint32) (uint64, error)
- func LoadOfferByHash(db *sql.DB, offerHash string) (payflow.ServiceOffer, bool, error)
- func MarshalClientIDHexFromCanonical(canonicalHex string) (string, error)
- func MarshalListenCycleQuotePayload(requestedDurationSeconds uint32, requestedUntilUnix int64, ...) ([]byte, error)
- func NormalizeClientIDLoose(clientID string) string
- func NormalizeClientIDStrict(clientID string) (string, error)
- func NormalizeServiceOfferPricingMode(raw string) string
- func ParseAndVerifyServiceQuote(raw []byte, serviceNodePub *ec.PublicKey) (payflow.ServiceQuote, string, error)
- func PeerIDFromClientID(clientID string) (peer.ID, error)
- func ServiceOfferFromRow(row ServiceOfferRow) payflow.ServiceOffer
- func SetGatewayAdminConfig(db *sql.DB, key string, value string) error
- func UpdateSession(db *sql.DB, row GatewaySessionRow) error
- func UpdateSessionTx(tx *sql.Tx, row GatewaySessionRow) error
- func UpsertClientPresence(db *sql.DB, clientID string, _ string, online bool) error
- func UpsertServiceOffer(db *sql.DB, row ServiceOfferRow) error
- func ValidateServiceQuoteBinding(quote payflow.ServiceQuote, offer payflow.ServiceOffer, ...) error
- type Actor
- type BaseTxReq
- type BaseTxResp
- type BillableServiceContext
- type BillableServiceDecision
- type BillableServiceDecl
- type BillableServiceQuoteFunc
- type BoundQuoteChargeReasons
- type ChainClient
- type CloseReq
- type CloseRequest
- type CloseResp
- type CloseResponse
- type CreateReq
- type CreateResp
- type GatewayParams
- type GatewayService
- func (s *GatewayService) BaseTx(req BaseTxReq) (BaseTxResp, error)
- func (s *GatewayService) BuildServiceQuote(input ServiceQuoteBuildInput) (payflow.ServiceQuote, []byte, string, error)
- func (s *GatewayService) Close(req CloseReq) (CloseResp, error)
- func (s *GatewayService) Create(req CreateReq) (CreateResp, error)
- func (s *GatewayService) Info(clientID string) (InfoResp, error)
- func (s *GatewayService) MarkClientOffline(clientID string, peerID string, reason string) error
- func (s *GatewayService) MarkClientOnline(clientID string, peerID string, reason string) error
- func (s *GatewayService) PassiveCloseExpiredOnce() error
- func (s *GatewayService) PayConfirm(req PayConfirmReq) (PayConfirmResp, error)
- func (s *GatewayService) ReconcileServiceStates(reason string) error
- func (s *GatewayService) RequiresBoundServiceQuote(chargeReason string) bool
- func (s *GatewayService) RunPassiveCloseLoop(ctx context.Context, interval time.Duration)
- func (s *GatewayService) State(req StateReq) (StateResp, error)
- func (s *GatewayService) SyncServiceStateByClient(clientID string, reason string, spendTxID string, peerID string) error
- type GatewaySessionRow
- func ListSessionsByLifecycleStates(db *sql.DB, states ...string) ([]GatewaySessionRow, error)
- func LoadLatestNonClosedSessionByClientID(db *sql.DB, clientID string) (GatewaySessionRow, bool, error)
- func LoadLatestSessionByClientID(db *sql.DB, clientID string) (GatewaySessionRow, bool, error)
- func LoadPreferredSessionByClientID(db *sql.DB, clientID string) (GatewaySessionRow, bool, error)
- func LoadSessionBySpendTxID(db *sql.DB, spendTxID string) (GatewaySessionRow, bool, error)
- type InfoReq
- type InfoResp
- type ListenCycleServicePayload
- type ListenerTargetRow
- type OpenBaseTxRequest
- type OpenCreateRequest
- type OpenCreateResponse
- type PayConfirmReq
- type PayConfirmRequest
- type PayConfirmResp
- type PayStep
- type ReceiptFinalizeSpec
- type ServiceCatalog
- type ServiceOfferRow
- type ServiceQuoteBuildInput
- type ServiceQuotePaymentRow
- type ServiceQuoteReq
- type ServiceQuoteResp
- type Session
- type StateReq
- type StateResp
- type SystemEndpoint
- func (s *SystemEndpoint) Close(req *CloseRequest) (*CloseResponse, error)
- func (s *SystemEndpoint) OpenBaseTx(req *OpenBaseTxRequest) (string, error)
- func (s *SystemEndpoint) OpenCreate(client *Actor, server *Actor, req *OpenCreateRequest, inputAmount uint64) (*OpenCreateResponse, error)
- func (s *SystemEndpoint) PayConfirm(req *PayConfirmRequest) (string, error)
- type UTXO
Constants ¶
const ( // 费用池参数查询(握手参数下发)。 ProtoFeePoolInfo protocol.ID = "/bsv-transfer/fee_pool/info/1.0.0" // Open 阶段:Create + BaseTx。 ProtoFeePoolCreate protocol.ID = "/bsv-transfer/fee_pool/create/1.0.0" ProtoFeePoolBaseTx protocol.ID = "/bsv-transfer/fee_pool/base_tx/1.0.0" // Pay 阶段:更新 spend tx(不上链)。 ProtoFeePoolPayConfirm protocol.ID = "/bsv-transfer/fee_pool/pay_confirm/1.0.0" // Close 阶段:最终结算并广播 final tx。 ProtoFeePoolClose protocol.ID = "/bsv-transfer/fee_pool/close/1.0.0" // 状态查询(用于观测/e2e)。 ProtoFeePoolSessionState protocol.ID = "/bsv-transfer/fee_pool/state/1.0.0" )
const ( QuoteServiceTypeListenCycle = "listen_cycle_fee" ServiceOfferPricingModeFixedPrice = "fixed_price" ServiceOfferPricingModeBudgetForService = "budget_for_service" )
Variables ¶
This section is empty.
Functions ¶
func BuildSignedServiceReceipt ¶
func BuildSignedServiceReceipt(serverPrivHex string, isMainnet bool, offerHash string, serviceType string, payloadBytes []byte) ([]byte, error)
BuildSignedServiceReceipt 基于一次已受理扣费结果生成链下业务回执。 设计说明: - 回执必须绑定 offer_hash,避免把别的业务结果嫁接到本次成交; - payloadBytes 由业务层自己定义,只要求 client/server 使用同一份规范化编码。
func CalcFee ¶
func CalcFee(t *tx.Transaction) uint64
func CalcFeeWithInputAmount ¶
func CalcFeeWithInputAmount(t *tx.Transaction, inputAmount uint64) uint64
func ClientIDAliasesForQuery ¶
ClientIDAliasesForQuery 返回查询别名集合(canonical + legacy marshal + 输入本身)。 说明:用于过渡期兼容旧数据,迁移完成后理论上只命中 canonical。
func FinalizeServiceResult ¶
func FinalizeServiceResult[T any](serverPrivHex string, isMainnet bool, clientID string, payOut PayConfirmResp, resp T, spec ReceiptFinalizeSpec[T]) (T, error)
func GetGatewayAdminConfig ¶
func InitGatewayStore ¶
func InsertChargeEvent ¶
func InsertChargeEventTx ¶
func InsertServiceQuotePayment ¶
func InsertServiceQuotePayment(db *sql.DB, row ServiceQuotePaymentRow) error
func InsertSession ¶
func InsertSession(db *sql.DB, row GatewaySessionRow) error
func Libp2pMarshalPubHexToSecpCompressedHex ¶
Libp2pMarshalPubHexToSecpCompressedHex 兼容两种输入并统一输出 secp256k1 压缩公钥(hex,33字节): - libp2p MarshalPublicKey(hex) - secp256k1 压缩公钥(hex) 这是把 pproto 的 sender_pubkey 语义,桥接到 KeymasterMultisigPool 的 BSV 公钥语义上。
func LoadOfferByHash ¶
func MarshalClientIDHexFromCanonical ¶
MarshalClientIDHexFromCanonical 将 canonical compressed pubkey 还原为历史 marshal hex。
func NormalizeClientIDLoose ¶
NormalizeClientIDLoose 尝试规范化 client_pubkey_hex;无法解析时仅做 lower+trim。 说明:该函数用于历史数据迁移与兼容查询,避免旧测试夹具(如 client_a)被硬失败。
func NormalizeClientIDStrict ¶
NormalizeClientIDStrict 统一 client_pubkey_hex 到 secp256k1 压缩公钥 hex(小写)。 说明:输入支持历史 marshal 格式与标准 compressed 格式;非法输入返回错误。
func PeerIDFromClientID ¶
PeerIDFromClientID 把系统内唯一 ID(压缩公钥 hex)映射到 libp2p transport 语境里的 peer.ID。 设计约束:peer.ID 只用于 libp2p 内部连接,不进入系统业务层主语义。
func ServiceOfferFromRow ¶
func ServiceOfferFromRow(row ServiceOfferRow) payflow.ServiceOffer
func UpdateSession ¶
func UpdateSession(db *sql.DB, row GatewaySessionRow) error
func UpdateSessionTx ¶
func UpdateSessionTx(tx *sql.Tx, row GatewaySessionRow) error
func UpsertClientPresence ¶
func UpsertServiceOffer ¶
func UpsertServiceOffer(db *sql.DB, row ServiceOfferRow) error
func ValidateServiceQuoteBinding ¶
func ValidateServiceQuoteBinding(quote payflow.ServiceQuote, offer payflow.ServiceOffer, expectedServiceNodePubkeyHex string, expectedClientID string, expectedServiceType string, requestParamsPayload []byte, nowUnix int64) error
Types ¶
type Actor ¶
type BaseTxReq ¶
type BaseTxReq struct {
ClientID string `protobuf:"bytes,1,opt,name=client_pubkey_hex,json=clientId,proto3" json:"client_pubkey_hex"`
SpendTxID string `protobuf:"bytes,2,opt,name=spend_txid,json=spendTxid,proto3" json:"spend_txid"`
BaseTx []byte `protobuf:"bytes,3,opt,name=base_tx,json=baseTx,proto3" json:"base_tx"`
ClientSig []byte `protobuf:"bytes,4,opt,name=client_sig,json=clientSig,proto3" json:"client_signature"`
}
func (*BaseTxReq) ProtoMessage ¶
func (*BaseTxReq) ProtoMessage()
type BaseTxResp ¶
type BaseTxResp struct {
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success"`
Status string `protobuf:"bytes,2,opt,name=status,proto3" json:"status"`
BaseTxID string `protobuf:"bytes,3,opt,name=base_txid,json=baseTxid,proto3" json:"base_txid,omitempty"`
Error string `protobuf:"bytes,4,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"`
}
func (*BaseTxResp) ProtoMessage ¶
func (*BaseTxResp) ProtoMessage()
func (*BaseTxResp) Reset ¶
func (m *BaseTxResp) Reset()
func (*BaseTxResp) String ¶
func (m *BaseTxResp) String() string
type BillableServiceContext ¶
type BillableServiceContext struct {
Request ServiceQuoteReq
Offer payflow.ServiceOffer
ServiceParamsPayload []byte
Gateway *GatewayService
}
type BillableServiceDecision ¶
type BillableServiceDecision struct {
Status string
Error string
ChargeReason string
ChargeAmountSatoshi uint64
QuoteTTLSeconds uint32
}
BillableServiceDecision 是单个收费服务在报价阶段给费用池底座的决策结果。 设计说明: - 业务模块只声明“这个 service_type 怎么验、怎么报价”; - poolcore 继续统一处理 offer 绑定校验、签名报价和公共状态推进; - 这样业务目录能正式收口,但底座仍然不反向依赖具体业务实现。
type BillableServiceDecl ¶
type BillableServiceDecl struct {
ServiceType string
ChargeReason string
Quote BillableServiceQuoteFunc
}
type BillableServiceQuoteFunc ¶
type BillableServiceQuoteFunc func(BillableServiceContext) (BillableServiceDecision, error)
type BoundQuoteChargeReasons ¶
type BoundQuoteChargeReasons map[string]struct{}
BoundQuoteChargeReasons 是运行时注入的“必须绑定 service quote 才允许 pay”的业务集合。 设计说明: - listen_cycle_fee 属于费用池底座自有能力,因此仍由 poolcore 内建; - 其它公开业务能力在装配阶段自行注入,避免 poolcore 认识具体模块名字; - 这里故意只做字符串集合,不把业务逻辑反向拉回底座。
func NewBoundQuoteChargeReasons ¶
func NewBoundQuoteChargeReasons(reasons ...string) BoundQuoteChargeReasons
type ChainClient ¶
type ChainClient interface {
GetUTXOs(address string) ([]UTXO, error)
GetTipHeight() (uint32, error)
Broadcast(txHex string) (string, error)
}
ChainClient 是费用池协议需要的最小链后端能力: - client 侧:查询 UTXO / tip height - gateway 侧:广播 base/final tx
生产环境统一使用 chainbridge;E2E 可注入 fake 实现。
type CloseReq ¶
type CloseReq struct {
ClientID string `protobuf:"bytes,1,opt,name=client_pubkey_hex,json=clientId,proto3" json:"client_pubkey_hex"`
SpendTxID string `protobuf:"bytes,2,opt,name=spend_txid,json=spendTxid,proto3" json:"spend_txid"`
ServerAmount uint64 `protobuf:"varint,3,opt,name=server_amount,json=serverAmount,proto3" json:"server_amount"`
Fee uint64 `protobuf:"varint,4,opt,name=fee,proto3" json:"fee"`
ClientSig []byte `protobuf:"bytes,5,opt,name=client_sig,json=clientSig,proto3" json:"signature"`
}
func (*CloseReq) ProtoMessage ¶
func (*CloseReq) ProtoMessage()
type CloseRequest ¶
type CloseResp ¶
type CloseResp struct {
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success"`
Status string `protobuf:"bytes,2,opt,name=status,proto3" json:"status"`
Broadcasted bool `protobuf:"varint,3,opt,name=broadcasted,proto3" json:"broadcasted"`
FinalSpendTxID string `protobuf:"bytes,4,opt,name=final_spend_txid,json=finalSpendTxid,proto3" json:"final_spend_txid,omitempty"`
Error string `protobuf:"bytes,5,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"`
}
func (*CloseResp) ProtoMessage ¶
func (*CloseResp) ProtoMessage()
type CloseResponse ¶
type CreateReq ¶
type CreateReq struct {
ClientID string `protobuf:"bytes,1,opt,name=client_pubkey_hex,json=clientId,proto3" json:"client_pubkey_hex"`
SpendTx []byte `protobuf:"bytes,2,opt,name=spend_tx,json=spendTx,proto3" json:"spend_tx"`
InputAmount uint64 `protobuf:"varint,3,opt,name=input_amount,json=inputAmount,proto3" json:"input_amount"`
SequenceNumber uint32 `protobuf:"varint,4,opt,name=sequence_number,json=sequenceNumber,proto3" json:"sequence_number"`
ServerAmount uint64 `protobuf:"varint,5,opt,name=server_amount,json=serverAmount,proto3" json:"server_amount"`
ClientSig []byte `protobuf:"bytes,6,opt,name=client_sig,json=clientSig,proto3" json:"client_signature"`
}
func (*CreateReq) ProtoMessage ¶
func (*CreateReq) ProtoMessage()
type CreateResp ¶
type CreateResp struct {
SpendTxID string `protobuf:"bytes,1,opt,name=spend_txid,json=spendTxid,proto3" json:"spend_txid"`
ServerSig []byte `protobuf:"bytes,2,opt,name=server_sig,json=serverSig,proto3" json:"server_signature"`
ErrorMessage string `protobuf:"bytes,3,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"`
SpendTxFeeSat uint64 `protobuf:"varint,4,opt,name=spend_tx_fee_satoshi,json=spendTxFeeSatoshi,proto3" json:"spend_tx_fee_satoshi"`
PoolAmountSat uint64 `protobuf:"varint,5,opt,name=pool_amount_satoshi,json=poolAmountSatoshi,proto3" json:"pool_amount_satoshi"`
}
func (*CreateResp) ProtoMessage ¶
func (*CreateResp) ProtoMessage()
func (*CreateResp) Reset ¶
func (m *CreateResp) Reset()
func (*CreateResp) String ¶
func (m *CreateResp) String() string
type GatewayParams ¶
type GatewayParams struct {
MinimumPoolAmountSatoshi uint64
LockBlocks uint32
FeeRateSatPerByte float64
// PayRejectBeforeExpiryBlocks 控制“临近到期时拒绝继续 pay”的安全窗口(单位:区块)。
// 取值为 0 时,会使用默认值 1。
PayRejectBeforeExpiryBlocks uint32
BillingCycleSeconds uint32
SingleCycleFeeSatoshi uint64
SinglePublishFeeSatoshi uint64
SingleQueryFeeSatoshi uint64
RenewNotifyBeforeSeconds uint32
}
type GatewayService ¶
type GatewayService struct {
DB *sql.DB
Actor *sqliteactor.Actor
Chain ChainClient
ServerPrivHex string
Params GatewayParams
// BoundQuoteChargeReasons 由模块装配阶段注入。
// 费用池底座只持有“哪些 charge_reason 必须绑定 quote”的策略,不直接依赖具体业务模块。
BoundQuoteChargeReasons BoundQuoteChargeReasons
// IsMainnet 控制地址派生与签名脚本等网络相关参数。
// 说明:BSV 主网/测试网的地址格式不同;公私钥本身不变。
IsMainnet bool
// contains filtered or unexported fields
}
func (*GatewayService) BaseTx ¶
func (s *GatewayService) BaseTx(req BaseTxReq) (BaseTxResp, error)
func (*GatewayService) BuildServiceQuote ¶
func (s *GatewayService) BuildServiceQuote(input ServiceQuoteBuildInput) (payflow.ServiceQuote, []byte, string, error)
func (*GatewayService) Create ¶
func (s *GatewayService) Create(req CreateReq) (CreateResp, error)
func (*GatewayService) MarkClientOffline ¶
func (s *GatewayService) MarkClientOffline(clientID string, peerID string, reason string) error
func (*GatewayService) MarkClientOnline ¶
func (s *GatewayService) MarkClientOnline(clientID string, peerID string, reason string) error
func (*GatewayService) PassiveCloseExpiredOnce ¶
func (s *GatewayService) PassiveCloseExpiredOnce() error
func (*GatewayService) PayConfirm ¶
func (s *GatewayService) PayConfirm(req PayConfirmReq) (PayConfirmResp, error)
func (*GatewayService) ReconcileServiceStates ¶
func (s *GatewayService) ReconcileServiceStates(reason string) error
func (*GatewayService) RequiresBoundServiceQuote ¶
func (s *GatewayService) RequiresBoundServiceQuote(chargeReason string) bool
func (*GatewayService) RunPassiveCloseLoop ¶
func (s *GatewayService) RunPassiveCloseLoop(ctx context.Context, interval time.Duration)
func (*GatewayService) SyncServiceStateByClient ¶
type GatewaySessionRow ¶
type GatewaySessionRow struct {
SpendTxID string
ClientID string
ClientBSVCompressedPubHex string
ServerBSVCompressedPubHex string
InputAmountSat uint64
PoolAmountSat uint64
SpendTxFeeSat uint64
Sequence uint32
ServerAmountSat uint64
ClientAmountSat uint64
BaseTxID string
FinalTxID string
BaseTxHex string
CurrentTxHex string
LifecycleState string
FrozenReason string
LastSubmitError string
SubmitRetryCount int
LastSubmitAttemptAtUnix int64
CloseSubmitAtUnix int64
CloseObservedAtUnix int64
CloseObserveStatus string
CloseObserveReason string
CreatedAt int64
UpdatedAt int64
}
func ListSessionsByLifecycleStates ¶
func ListSessionsByLifecycleStates(db *sql.DB, states ...string) ([]GatewaySessionRow, error)
func LoadPreferredSessionByClientID ¶
LoadPreferredSessionByClientID 优先返回 active 会话;若没有 active,则回退到最新会话。
func LoadSessionBySpendTxID ¶
type InfoReq ¶
type InfoReq struct {
ClientID string `protobuf:"bytes,1,opt,name=client_pubkey_hex,json=clientId,proto3" json:"client_pubkey_hex"`
}
InfoReq/InfoResp 用于 client 启动时获取网关的费用池握手参数。 说明:client_pubkey_hex 规范为 secp256k1 压缩公钥 hex(33 字节,02/03 开头,小写)。 网关会兼容旧输入(libp2p MarshalPublicKey hex)并在落库前归一化到上述格式。
func (*InfoReq) ProtoMessage ¶
func (*InfoReq) ProtoMessage()
type InfoResp ¶
type InfoResp struct {
Status string `protobuf:"bytes,1,opt,name=status,proto3" json:"status"`
MinimumPoolAmountSatoshi uint64 `` /* 128-byte string literal not displayed */
LockBlocks uint32 `protobuf:"varint,3,opt,name=lock_blocks,json=lockBlocks,proto3" json:"lock_blocks"`
FeeRateSatPerByte float64 `protobuf:"fixed64,4,opt,name=fee_rate_sat_per_byte,json=feeRateSatPerByte,proto3" json:"fee_rate_sat_per_byte"`
BillingCycleSeconds uint32 `protobuf:"varint,5,opt,name=billing_cycle_seconds,json=billingCycleSeconds,proto3" json:"billing_cycle_seconds"`
SingleCycleFeeSatoshi uint64 `protobuf:"varint,6,opt,name=single_cycle_fee_satoshi,json=singleCycleFeeSatoshi,proto3" json:"single_cycle_fee_satoshi"`
SinglePublishFeeSatoshi uint64 `protobuf:"varint,7,opt,name=single_publish_fee_satoshi,json=singlePublishFeeSatoshi,proto3" json:"single_publish_fee_satoshi"`
RenewNotifyBeforeSeconds uint32 `` /* 128-byte string literal not displayed */
SingleQueryFeeSatoshi uint64 `protobuf:"varint,9,opt,name=single_query_fee_satoshi,json=singleQueryFeeSatoshi,proto3" json:"single_query_fee_satoshi"`
}
func (*InfoResp) ProtoMessage ¶
func (*InfoResp) ProtoMessage()
type ListenCycleServicePayload ¶
type ListenCycleServicePayload struct {
RequestedDurationSeconds uint32
RequestedUntilUnix int64
ProposedPaymentSatoshi uint64
}
func UnmarshalListenCycleQuotePayload ¶
func UnmarshalListenCycleQuotePayload(raw []byte) (ListenCycleServicePayload, error)
type ListenerTargetRow ¶
type ListenerTargetRow struct {
ClientID string
}
func ListServingListenerTargetsByChargeReason ¶
func ListServingListenerTargetsByChargeReason(db *sql.DB, reason string) ([]ListenerTargetRow, error)
type OpenBaseTxRequest ¶
type OpenCreateRequest ¶
type OpenCreateResponse ¶
type PayConfirmReq ¶
type PayConfirmReq struct {
ClientID string `protobuf:"bytes,1,opt,name=client_pubkey_hex,json=clientId,proto3" json:"client_pubkey_hex"`
SpendTxID string `protobuf:"bytes,2,opt,name=spend_txid,json=spendTxid,proto3" json:"spend_txid"`
SequenceNumber uint32 `protobuf:"varint,3,opt,name=sequence_number,json=sequenceNumber,proto3" json:"sequence_number"`
ServerAmount uint64 `protobuf:"varint,4,opt,name=server_amount,json=serverAmount,proto3" json:"server_amount"`
Fee uint64 `protobuf:"varint,5,opt,name=fee,proto3" json:"fee"`
ClientSig []byte `protobuf:"bytes,6,opt,name=client_sig,json=clientSig,proto3" json:"signature"`
// 业务字段(不上链,仅用于观测/审计/幂等核对)。
ChargeReason string `protobuf:"bytes,7,opt,name=charge_reason,json=chargeReason,proto3" json:"charge_reason,omitempty"`
ChargeAmountSatoshi uint64 `protobuf:"varint,8,opt,name=charge_amount_satoshi,json=chargeAmountSatoshi,proto3" json:"charge_amount_satoshi,omitempty"`
FileHash string `protobuf:"bytes,9,opt,name=file_hash,json=fileHash,proto3" json:"file_hash,omitempty"`
ProofIntent []byte `protobuf:"bytes,10,opt,name=proof_intent,json=proofIntent,proto3" json:"proof_intent,omitempty"`
SignedProofCommit []byte `protobuf:"bytes,11,opt,name=signed_proof_commit,json=signedProofCommit,proto3" json:"signed_proof_commit,omitempty"`
ServiceQuote []byte `protobuf:"bytes,13,opt,name=service_quote,json=serviceQuote,proto3" json:"service_quote,omitempty"`
}
func (*PayConfirmReq) ProtoMessage ¶
func (*PayConfirmReq) ProtoMessage()
func (*PayConfirmReq) Reset ¶
func (m *PayConfirmReq) Reset()
func (*PayConfirmReq) String ¶
func (m *PayConfirmReq) String() string
type PayConfirmRequest ¶
type PayConfirmResp ¶
type PayConfirmResp struct {
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success"`
Status string `protobuf:"bytes,2,opt,name=status,proto3" json:"status"`
UpdatedTxID string `protobuf:"bytes,3,opt,name=updated_txid,json=updatedTxid,proto3" json:"updated_txid,omitempty"`
Sequence uint32 `protobuf:"varint,4,opt,name=sequence,proto3" json:"sequence,omitempty"`
ServerAmount uint64 `protobuf:"varint,5,opt,name=server_amount,json=serverAmount,proto3" json:"server_amount,omitempty"`
ClientAmount uint64 `protobuf:"varint,6,opt,name=client_amount,json=clientAmount,proto3" json:"client_amount,omitempty"`
ErrorCode string `protobuf:"bytes,7,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"`
Error string `protobuf:"bytes,8,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"`
MergedCurrentTx []byte `protobuf:"bytes,9,opt,name=merged_current_tx,json=mergedCurrentTx,proto3" json:"merged_current_tx,omitempty"`
ProofStatePayload []byte `protobuf:"bytes,10,opt,name=proof_state_payload,json=proofStatePayload,proto3" json:"proof_state_payload,omitempty"`
ServiceReceipt []byte `protobuf:"bytes,11,opt,name=service_receipt,json=serviceReceipt,proto3" json:"service_receipt,omitempty"`
}
func (*PayConfirmResp) ProtoMessage ¶
func (*PayConfirmResp) ProtoMessage()
func (*PayConfirmResp) Reset ¶
func (m *PayConfirmResp) Reset()
func (*PayConfirmResp) String ¶
func (m *PayConfirmResp) String() string
type PayStep ¶
type PayStep struct {
CycleIndex uint32 `json:"cycle_index"`
Sequence uint32 `json:"sequence"`
ServerAmount uint64 `json:"server_amount"`
ClientAmount uint64 `json:"client_amount"`
UpdatedTxID string `json:"updated_txid"`
}
PayStep 记录每一次 Pay 周期的关键数据(用于集成测试核对)。 注意:Pay 阶段不会上链(只更新 spend tx 的状态),真正上链的是 Open(base tx) 与 Close(final tx)。
type ReceiptFinalizeSpec ¶
type ReceiptFinalizeSpec[T any] struct { ServiceType string OfferHash func(T) string ApplyPayOut func(T, PayConfirmResp) T MarshalPayload func(T) ([]byte, error) SetServiceReceipt func(T, []byte) T }
ReceiptFinalizeSpec 描述一次已扣费业务结果如何补齐公共回执骨架。 约束: - 业务层自己决定 payload 长什么样、result_code 取什么值; - poolcore 只负责把 payConfirm 结果和标准 service receipt 拼进去; - 这样共享的是“骨架”,不是业务结果对象本身。
type ServiceCatalog ¶
type ServiceCatalog struct {
// contains filtered or unexported fields
}
func MustNewServiceCatalog ¶
func MustNewServiceCatalog(decls ...BillableServiceDecl) ServiceCatalog
func NewServiceCatalog ¶
func NewServiceCatalog(decls ...BillableServiceDecl) (ServiceCatalog, error)
func (ServiceCatalog) BoundQuoteChargeReasons ¶
func (c ServiceCatalog) BoundQuoteChargeReasons() BoundQuoteChargeReasons
func (ServiceCatalog) Quote ¶
func (c ServiceCatalog) Quote(service *GatewayService, req ServiceQuoteReq) (ServiceQuoteResp, error)
type ServiceOfferRow ¶
type ServiceOfferRow struct {
OfferHash string
ServiceType string
ServiceNodePubkeyHex string
ClientPubkeyHex string
RequestParams []byte
CreatedAtUnix int64
LastQuotedAtUnix int64
LastQuotedAmountSat uint64
LastQuoteExpiresAtUnix int64
}
func LoadServiceOfferByHash ¶
type ServiceQuoteBuildInput ¶
type ServiceQuoteBuildInput struct {
Offer payflow.ServiceOffer
ChargeAmountSatoshi uint64
QuoteTTLSeconds uint32
}
type ServiceQuotePaymentRow ¶
type ServiceQuotePaymentRow struct {
QuoteHash string
OfferHash string
PaymentScheme string
PaymentTxID string
ClientPubkeyHex string
AcceptedAtUnix int64
}
func LoadServiceQuotePayment ¶
type ServiceQuoteReq ¶
type ServiceQuoteReq struct {
ClientID string `protobuf:"bytes,1,opt,name=client_pubkey_hex,json=clientId,proto3" json:"client_pubkey_hex"`
ServiceOffer []byte `protobuf:"bytes,2,opt,name=service_offer,json=serviceOffer,proto3" json:"service_offer,omitempty"`
ServiceParamsPayload []byte `protobuf:"bytes,3,opt,name=service_params_payload,json=serviceParamsPayload,proto3" json:"service_params_payload,omitempty"`
}
func (*ServiceQuoteReq) ProtoMessage ¶
func (*ServiceQuoteReq) ProtoMessage()
func (*ServiceQuoteReq) Reset ¶
func (m *ServiceQuoteReq) Reset()
func (*ServiceQuoteReq) String ¶
func (m *ServiceQuoteReq) String() string
type ServiceQuoteResp ¶
type ServiceQuoteResp struct {
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success"`
Status string `protobuf:"bytes,2,opt,name=status,proto3" json:"status"`
ServiceQuote []byte `protobuf:"bytes,3,opt,name=service_quote,json=serviceQuote,proto3" json:"service_quote,omitempty"`
Error string `protobuf:"bytes,4,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"`
}
func (*ServiceQuoteResp) ProtoMessage ¶
func (*ServiceQuoteResp) ProtoMessage()
func (*ServiceQuoteResp) Reset ¶
func (m *ServiceQuoteResp) Reset()
func (*ServiceQuoteResp) String ¶
func (m *ServiceQuoteResp) String() string
type StateReq ¶
type StateReq struct {
ClientID string `protobuf:"bytes,1,opt,name=client_pubkey_hex,json=clientId,proto3" json:"client_pubkey_hex"`
SpendTxID string `protobuf:"bytes,2,opt,name=spend_txid,json=spendTxid,proto3" json:"spend_txid,omitempty"`
}
func (*StateReq) ProtoMessage ¶
func (*StateReq) ProtoMessage()
type StateResp ¶
type StateResp struct {
Status string `protobuf:"bytes,1,opt,name=status,proto3" json:"status"`
SpendTxID string `protobuf:"bytes,2,opt,name=spend_txid,json=spendTxid,proto3" json:"spend_txid,omitempty"`
BaseTxID string `protobuf:"bytes,3,opt,name=base_txid,json=baseTxid,proto3" json:"base_txid,omitempty"`
FinalTxID string `protobuf:"bytes,4,opt,name=final_txid,json=finalTxid,proto3" json:"final_txid,omitempty"`
CurrentTx []byte `protobuf:"bytes,5,opt,name=current_tx,json=currentTx,proto3" json:"current_tx,omitempty"`
PoolAmountSat uint64 `protobuf:"varint,6,opt,name=pool_amount_satoshi,json=poolAmountSatoshi,proto3" json:"pool_amount_satoshi"`
SpendTxFeeSat uint64 `protobuf:"varint,7,opt,name=spend_tx_fee_satoshi,json=spendTxFeeSatoshi,proto3" json:"spend_tx_fee_satoshi"`
Sequence uint32 `protobuf:"varint,8,opt,name=sequence,proto3" json:"sequence"`
ServerAmountSat uint64 `protobuf:"varint,9,opt,name=server_amount_satoshi,json=serverAmountSatoshi,proto3" json:"server_amount_satoshi"`
ClientAmountSat uint64 `protobuf:"varint,10,opt,name=client_amount_satoshi,json=clientAmountSatoshi,proto3" json:"client_amount_satoshi"`
LifecycleState string `protobuf:"bytes,11,opt,name=lifecycle_state,json=lifecycleState,proto3" json:"lifecycle_state,omitempty"`
Payability string `protobuf:"bytes,12,opt,name=payability,proto3" json:"payability,omitempty"`
Phase string `protobuf:"bytes,13,opt,name=phase,proto3" json:"phase,omitempty"`
ExpireHeight uint32 `protobuf:"varint,14,opt,name=expire_height,json=expireHeight,proto3" json:"expire_height,omitempty"`
TipHeight uint32 `protobuf:"varint,15,opt,name=tip_height,json=tipHeight,proto3" json:"tip_height,omitempty"`
OutpointSpent bool `protobuf:"varint,16,opt,name=outpoint_spent,json=outpointSpent,proto3" json:"outpoint_spent"`
ProofStatePayload []byte `protobuf:"bytes,17,opt,name=proof_state_payload,json=proofStatePayload,proto3" json:"proof_state_payload,omitempty"`
}
func (*StateResp) ProtoMessage ¶
func (*StateResp) ProtoMessage()
type SystemEndpoint ¶
type SystemEndpoint struct {
Name string
Chain ChainClient
FeeRate float64
Sessions map[string]*Session // key=spend_txid
}
SystemEndpoint 表示“网关/系统端”对费用池协议的处理器。 关键点:Open/Close 会真实广播上链(WOC)。
func NewSystemEndpoint ¶
func NewSystemEndpoint(name string, chain ChainClient, feeRate float64) *SystemEndpoint
func (*SystemEndpoint) Close ¶
func (s *SystemEndpoint) Close(req *CloseRequest) (*CloseResponse, error)
func (*SystemEndpoint) OpenBaseTx ¶
func (s *SystemEndpoint) OpenBaseTx(req *OpenBaseTxRequest) (string, error)
func (*SystemEndpoint) OpenCreate ¶
func (s *SystemEndpoint) OpenCreate(client *Actor, server *Actor, req *OpenCreateRequest, inputAmount uint64) (*OpenCreateResponse, error)
func (*SystemEndpoint) PayConfirm ¶
func (s *SystemEndpoint) PayConfirm(req *PayConfirmRequest) (string, error)
Source Files
¶
- chain_iface.go
- gateway_service.go
- gateway_service_db.go
- gateway_service_timeline.go
- gateway_store_sqlite.go
- key_conv.go
- lifecycle.go
- p2p_proto_messages.go
- p2p_types.go
- peer_id.go
- proof_state.go
- protos.go
- service_catalog.go
- service_quote.go
- service_quote_binding.go
- service_quote_payload.go
- service_receipt.go
- service_result.go
- string_list.go
- system_endpoint.go
- types.go