paidhost

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package paidhost is a stand-in for an overlay host's terms route, for an application's tests: the terms document, and lookups over BRC-104 in which a priced class is answered 402 (BRC-105) until a payment pays the price to the key BRC-29 derives for the payee, and verifies against the chain. The application gives it its lookup service: the name, the classes and how a question is asked and answered. Never for a network.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Paid struct {
	Service Service
	Prices  map[string]uint64
	// Payments are the payments it accepted: txid, satoshis, the remittance
	// and the Atomic BEEF, as a host's payment ledger records them.
	Payments []Payment

	// Again answers 402 to every priced question, a payment or none: a
	// host that keeps asking. FailPaid records a payment and then answers
	// 500: a host that took the money and did not answer.
	Again    bool
	FailPaid bool
	// OnPayment, when set, runs when a request carrying a payment arrives,
	// before anything is done with it.
	OnPayment func()
	// contains filtered or unexported fields
}

Paid is the route: the terms document, and lookups over BRC-104 in which a priced class is answered 402 (BRC-105) until a payment pays the price to the key BRC-29 derives for the payee, the prefix it issued, the payer's suffix and the payer, and verifies against Headers. Requests are served one at a time.

func New

func New(s Service, payee *ec.PrivateKey, prices map[string]uint64) *Paid

New is a terms route for the service, paid to payee.

func (*Paid) Ledger

func (p *Paid) Ledger() []byte

Ledger writes the accepted payments as the host module's payments.jsonl.

func (*Paid) Limit

func (p *Paid) Limit(nth ...int)

Limit makes it refuse the nth authenticated requests from now, counted from 1, with 429 and no signature, as a host does for a session over its budget of signed responses.

func (*Paid) ServeHTTP

func (p *Paid) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Payment

type Payment struct {
	Txid              string `json:"txid"`
	Beef              string `json:"beef"`
	OutputIndex       int    `json:"outputIndex"`
	Satoshis          uint64 `json:"satoshis"`
	DerivationPrefix  string `json:"derivationPrefix"`
	DerivationSuffix  string `json:"derivationSuffix"`
	SenderIdentityKey string `json:"senderIdentityKey"`
	Class             string `json:"class"`
}

Payment is one accepted payment, in the host ledger's shape.

type Service

type Service struct {
	// Name is the lookup service ("ls_<app>"): the terms document is at
	// /<Name>/terms and a question names it.
	Name string
	// Classes are the classes the terms document lists, in its order; a
	// class with no price is left out.
	Classes []string
	// Ask parses a question's query and returns its class and how to
	// answer it; an error is answered 400. Answer runs only once a priced
	// class is paid, and an error from it is answered 400 too.
	Ask func(query json.RawMessage) (class string, answer func() (any, error), err error)
	// Headers is what a payment's proof is verified against.
	Headers chaintracker.ChainTracker
}

Service is the application's lookup service, as the route answers it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL