Documentation
¶
Overview ¶
Package receipt implements the libp2p request/response stream protocols for burn/mint receipt submission. A client writes a cborx-framed receipt; the Server decodes it, hands it to a ReceiptHandler, and writes back a protocol.ReceiptAck.
Two protocols share one shape, differing only in protocol ID and payload:
/ynp/burnreceipt/1.0.0 — request *core.BurnReceipt, response *protocol.ReceiptAck /ynp/mintreceipt/1.0.0 — request *core.MintReceipt, response *protocol.ReceiptAck
The package never builds a host.Host: Register installs handlers on a caller-supplied host (Server satisfies protocol.Registrar), and Client dials over one.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client submits burn/mint receipts to a single peer over a caller-owned host.Host. It is a stateless convenience: the caller is responsible for making peerID reachable (adding it to the peerstore and/or dialing) before the first send.
func (*Client) SendBurnReceipt ¶
func (c *Client) SendBurnReceipt(ctx context.Context, r *core.BurnReceipt) (p2pproto.ReceiptAck, error)
SendBurnReceipt writes r on /ynp/burnreceipt/1.0.0 and returns the ack. Transport-level errors (timeout, stream, decode) come back as a non-nil error; an Accepted=false ack returns without error so the caller decides whether to retry.
func (*Client) SendMintReceipt ¶
func (c *Client) SendMintReceipt(ctx context.Context, r *core.MintReceipt) (p2pproto.ReceiptAck, error)
SendMintReceipt writes r on /ynp/mintreceipt/1.0.0. Same error semantics as SendBurnReceipt.
type ReceiptHandler ¶
type ReceiptHandler interface {
OnBurnReceipt(ctx context.Context, r *core.BurnReceipt) (p2pproto.ReceiptAck, error)
OnMintReceipt(ctx context.Context, r *core.MintReceipt) (p2pproto.ReceiptAck, error)
}
ReceiptHandler is the business seam a consumer implements to process inbound receipts. The Server decodes the wire frame and calls the matching method; the returned ReceiptAck is sent back to the peer. A non-nil error is delivered to the peer as Accepted=false with the error string.
Implementations must be idempotent on the clearing layer's natural de-dupe keys (BurnReceipt: BlockHash+EntryIndex; MintReceipt: AssetURI+TxID) so client retries are safe. A consumer that handles only one kind still implements both methods — return a reject ack for the unhandled one.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server handles inbound burn/mint receipt streams, delegating each decoded receipt to a ReceiptHandler.
func NewServer ¶
func NewServer(handler ReceiptHandler, logger log.Logger) *Server
NewServer returns a Server that delegates to handler.
func (*Server) HandleBurnReceipt ¶
HandleBurnReceipt is the stream handler for /ynp/burnreceipt/1.0.0.
func (*Server) HandleMintReceipt ¶
HandleMintReceipt is the stream handler for /ynp/mintreceipt/1.0.0.