testchain

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 28 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 testchain is the local stand-ins this module's tests run against: the shared chain, and this application's host.

Index

Constants

View Source
const (
	CoinbaseValue = bc.CoinbaseValue
	Maturity      = bc.Maturity
)

CoinbaseValue and Maturity are the chain's.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain = bc.Chain

Chain is the shared local chain.

func New

func New(start uint32) *Chain

New is a chain whose tip is at height start.

type Host

type Host struct {

	// Down answers every request with 503.
	Down bool
	// Priced refuses the history classes on /lookup.
	Priced bool
	// Drop, when set, is asked about each submission; true discards it
	// unseen, as a plane that lost the object would.
	Drop func(tx *transaction.Transaction) bool
	// Rewrite, when set, rewrites the answer to an ls_borg question on
	// /lookup: a host that withholds, adds or repeats outputs.
	Rewrite func(q *borgrec.Question, outs []Output) []Output
	// Stale answers every token, carrier and sweep under a proof that names
	// another block than the one the chain mined it in: a host whose stored
	// proofs a reorganisation left behind.
	Stale bool
	// HistoryPage, when set, is the most tokens a history page holds here,
	// in place of the class's 64.
	HistoryPage int
	// Submits counts submissions; Refused counts refusals by reason.
	Submits int
	Refused map[string]int
	// contains filtered or unexported fields
}

Host is a stand-in overlay host carrying borg halls: /submit runs the engine's SPV and the borg topic manager (borgrec.Admit) over the topic's previous coins, and /lookup answers the ls_borg classes from an index that folds each chain from seq 0 and keeps one outpoint row per funding outpoint (spec sections 10.2, 11.1 and 11.2). A refusal is recorded nowhere, so the same transaction offered again is decided afresh. The priced classes are refused on /lookup when Priced is set, as a host that sells them refuses them there. Retention, restore and the evidence caps are the real module's and are not modelled.

func NewHost

func NewHost(chain *Chain, halls ...string) *Host

NewHost is a host carrying halls whose engine checks proofs against chain.

func (*Host) Answer

func (h *Host) Answer(q *borgrec.Question) ([]Output, error)

Answer answers a validated question.

func (*Host) Carry

func (h *Host) Carry(hall string)

Carry adds a hall.

func (*Host) Forget

func (h *Host) Forget(txid string)

Forget drops an object, as a host that lost it would: an honest host does not, but a test makes one that did.

func (*Host) Holds

func (h *Host) Holds(txid string) bool

Holds reports whether the host holds an object with txid.

func (*Host) ServeHTTP

func (h *Host) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Host) SetDown

func (h *Host) SetDown(down bool)

SetDown takes the host down or brings it back.

func (*Host) Status

func (h *Host) Status(txid string) string

Status is the status of a carrier the host holds, or "".

func (*Host) Txids

func (h *Host) Txids(kind string) []string

Txids are the txids of the objects the host holds of a kind: "grant", "wrap", "token" or "sweep", sorted.

type Output

type Output struct {
	Beef        []byte `json:"beef"`
	OutputIndex int    `json:"outputIndex"`
	Context     []byte `json:"context,omitempty"`
}

Output is one answered output.

type Paid struct {
	Host   *Host
	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 a stand-in for a host's terms route (spec section 10.3): 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 the chain. It answers from a Host. Requests are served one at a time.

func NewPaid

func NewPaid(host *Host, payee *ec.PrivateKey, prices map[string]uint64) *Paid

NewPaid is a terms route for host, 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 added in v0.1.1

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 Plane

type Plane struct {
	Hosts []http.Handler
	// Lost, when set, is asked per host and submission; true loses the
	// object on the way to that host.
	Lost func(host int, tx []byte) bool
}

Plane stands in for the multicast plane: a facade that delivers each submission to every host subscribed to the topic, answering with the first host's answer. Lookups go to the first host, the facade's own.

func (*Plane) ServeHTTP

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

Jump to

Keyboard shortcuts

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