testwriter

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 30 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 testwriter is a minimal bstore writer for tests only: it funds itself from a local test chain's coinbase (coinbase: only on a regtest chain you run, development and tests), builds an object's CHIRP closure, mints its piece carriers, a hold output and the entry, submits them, asks hosts for advertisements, challenges providers, verifies their signed responses as a buyer does (spec section 7.4), buys renewals, and settles a bounty by rank with BRC-29 outputs and remittances (spec section 9.5). It is the least of the publisher client the provider's tests need; the publisher client proper is another component. Nothing here is for real use.

Index

Constants

This section is empty.

Variables

View Source
var Profile = bwallet.Profile{FundProtocol: storerec.Protocol, FundKeyID: storerec.KeyFund, FundBasket: "bstore fund",
	Version: "bstore-testwriter", LegacyPoolFile: "bstore-testwriter-pool.json"}

Profile is the test writer's wallet profile.

Functions

func Admitted

func Admitted(ans map[string]any, topic string) (bool, string)

Admitted reports whether a submit answer admitted any output for topic.

func AloneBEEF

func AloneBEEF(tx *transaction.Transaction) ([]byte, error)

AloneBEEF is a mined transaction as a host admits a mined object.

func PubKey

func PubKey(s string) *ec.PublicKey

PubKey parses a 66-hex key.

func Verify

func Verify(q *storerec.Request, raw, signed []byte, o *Object, f *Fetcher) storerec.Verdict

Verify is the buyer's check of a signed response (spec section 7.4).

Types

type Ad struct {
	Tx   *transaction.Transaction
	Txid string
	Vout uint32
	Ad   *storerec.Advertisement
}

Ad is an advertisement a host answered.

type Call

type Call struct {
	Status  int
	Body    []byte
	Paid    uint64
	Payment *transaction.Transaction
}

Call is one authenticated request's answer, and the BRC-105 payment made for it, if any.

type Chain

type Chain struct {
	W       *Writer
	Bucket  string
	ID      [32]byte
	Writers [][]byte
	Map     storerec.Map
	Named   map[[32]byte]bool
	Token   *transaction.Transaction
	Record  *storerec.Bucket
}

Chain is a bucket chain this writer owns, for tests only: the owner's anchoring tooling at its least (spec sections 3.4 and 3.6). It mints the first token from a chain tree and each later token from the entries a host answers by `unanchored`, resolved as spec section 3.4 has it.

func (*Chain) Anchor

func (c *Chain) Anchor(ctx context.Context, batch []storerec.Applicable) ([]byte, error)

Anchor mints the next token applying batch (spec section 3.4) and returns its BEEF.

func (*Chain) Entries

func (c *Chain) Entries(ctx context.Context, keys []string, b *storerec.Built) ([][]byte, error)

Entries mints a put entry by the owner for each key, all naming the closure b, on one entry tree, and returns their BEEFs.

func (*Chain) Unanchored

func (c *Chain) Unanchored(ctx context.Context, host string, writer []byte) ([]storerec.Applicable, error)

Unanchored asks host for writer's entries no token names (spec section 11.1, `unanchored`), every page, held to the carrier rules.

type Fetcher

type Fetcher struct {
	HTTP  *http.Client
	URL   string // the advertisement's url
	Blobs []chirp.Child
	// Ranged counts the Range fetches, Whole the whole-blob fetches.
	Ranged, Whole int
}

Fetcher fetches by-reference samples from a tested URL (spec section 7.5).

func (*Fetcher) Blob

func (f *Fetcher) Blob(blob uint64) ([]byte, error)

Blob fetches a whole blob.

func (*Fetcher) Range

func (f *Fetcher) Range(blob, offset, length uint64) ([]byte, error)

Range fetches length bytes at offset of a blob with an HTTP Range.

type Hold

type Hold struct {
	Tx   *transaction.Transaction
	Vout uint32
	Sats uint64
}

Hold is a mined hold output.

type Object

type Object struct {
	Content []byte
	Built   *storerec.Built
	Pieces  [][]byte
}

Object is an object built for a put: its closure and its pieces' BEEF.

type Payee

type Payee struct {
	Identity []byte
	Front    string
	Rank     int
	Sats     uint64
}

Payee is one rank to pay.

type Put

type Put struct {
	Object *Object
	Entry  *storerec.Entry
	BEEF   []byte
	C      string // display txid
	Hold   *Hold
}

Put is an entry made.

type Settlement

type Settlement struct {
	Tx          *transaction.Transaction
	Remittances map[int][]byte
}

Settlement is a minted settlement and each payee's remittance body.

type Terms

type Terms struct {
	Sats                 uint64
	T, K                 uint64
	Retention            uint64
	DeadlineAhead        uint64
	CheckC               uint64
	ContentType          string
	Created              time.Time
	NoHold               bool
	ProofRootOverride    *[32]byte
	ContentHashOverride  *[32]byte
	SizeOverride         *uint64
	ExtraEntryKeySuffix  string
	BucketIDOverride     *[32]byte
	ReuseHold            *Hold
	DeadlineAbsolute     uint64
	SkipHoldConfirmation bool
}

Terms are an entry's hold terms before the hold output is known.

type Writer

type Writer struct {
	W       *bwallet.Embedded
	Signer  *bwallet.Signer
	RPC     *nodeapi.RPC
	Asset   *nodeapi.Asset
	Settler publish.Settler
	Headers chaintracker.ChainTracker
	// HTTP reaches providers (it trusts their test certificate) and hosts.
	HTTP   *http.Client
	Bucket string
	Fees   mint.Fees
	// contains filtered or unexported fields
}

Writer is one writer identity over a local chain.

func New

func New(ctx context.Context, dir, bucket string, rpc *nodeapi.RPC, asset *nodeapi.Asset, headers chaintracker.ChainTracker, hc *http.Client) (*Writer, error)

New creates and funds a writer under dir.

func (*Writer) Ads

func (w *Writer) Ads(ctx context.Context, host string, root [32]byte) ([]Ad, error)

Ads asks a host's ls_bstore for root's advertisements.

func (*Writer) Build

func (w *Writer) Build(ctx context.Context, content []byte) (*Object, error)

Build builds content's closure and mints a carrier for each piece.

func (*Writer) Carrier

func (w *Writer) Carrier(ctx context.Context, d pushdrop.Derivation, record []byte, tree *transaction.Transaction, vout uint32) ([]byte, string, error)

Carrier mints a carrier of record on output vout of tree, under d, and returns its Atomic BEEF and commitment (display txid).

func (*Writer) Challenge

func (w *Writer) Challenge(ctx context.Context, front string, raw []byte, entry string, maxPay uint64) (*Call, error)

Challenge posts a request to front's challenge route.

func (*Writer) Entry

func (w *Writer) Entry(ctx context.Context, o *Object, key string, t Terms) (*Put, error)

Entry mints the hold output (unless NoHold) and the put entry for key.

func (*Writer) HoldOutput

func (w *Writer) HoldOutput(ctx context.Context, sats uint64) (*Hold, error)

HoldOutput mints a hold output of sats.

func (*Writer) Identity

func (w *Writer) Identity() []byte

Identity is the writer's key.

func (*Writer) NewChain

func (w *Writer) NewChain(ctx context.Context, bucket string, writers [][]byte) (*Chain, []byte, error)

NewChain mints a chain's first token for bucket naming writers, and returns the chain and the token's BEEF (with its parent, the chain tree).

func (*Writer) Post

func (w *Writer) Post(ctx context.Context, url string, body []byte, maxPay uint64) (*Call, error)

Post sends body to url over BRC-104, paying a 402 up to maxPay.

func (*Writer) Request

func (w *Writer) Request(ctx context.Context, b *storerec.Built, provider []byte, c uint64, nonce [16]byte) (*storerec.Request, []byte, error)

Request builds a challenge request of c samples for provider's advertisement of the object, seeded at the tip, with nonce.

func (*Writer) Settle

func (w *Writer) Settle(ctx context.Context, put *Put, payees []Payee) (*Settlement, error)

Settle spends the hold output to the payees' BRC-29 keys, mines it, and returns each rank's remittance (spec sections 9.5 and 10.1).

func (*Writer) Submit

func (w *Writer) Submit(ctx context.Context, base, topic string, beef []byte) (map[string]any, error)

Submit posts a BEEF to base's /submit on topic and returns the answer.

func (*Writer) Tree

Tree mints a funding tree of n outputs of one satoshi under d.

Jump to

Keyboard shortcuts

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