heldpay

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package heldpay is a BRC-105 client's side of a payment the server holds for confirmation. A server that takes a payment it cannot yet trust broadcasts it and answers 202 with the code ERR_PAYMENT_HELD; the same payment, sent again once it is mined, buys the answer. (Servers built before that answered 402 with the same code and no BRC-105 headers, which a BRC-105 client such as go-sdk's AuthFetch takes for a price it cannot read; Tap recognizes both.)

A client wraps its HTTP transport in a Tap, makes its paid request, and when Tap.Held reports a hold, waits for the payment to mine (Mined) and sends the request again with Tap.Payment as its x-bsv-payment header, paying nothing more.

Index

Constants

View Source
const Code = "ERR_PAYMENT_HELD"

Code is the error code of a held payment's answer.

Variables

This section is empty.

Functions

func Mined

func Mined(ctx context.Context, chain nodeapi.Chain, tx *transaction.Transaction, wait, poll time.Duration) error

Mined waits, up to wait, for tx to be mined on chain, asking every poll (zero is nodeapi's default). An error is a payment not mined in time, or one the chain shows spent elsewhere.

Types

type Tap

type Tap struct {
	Next http.RoundTripper
	// contains filtered or unexported fields
}

Tap is an http.RoundTripper over Next (nil is http.DefaultTransport) that keeps the x-bsv-payment header of the last request that sent one, and whether, and why, the server held a payment. Its methods are safe for concurrent use; a client makes one paid call at a time through it.

func (*Tap) Held

func (t *Tap) Held() (string, bool)

Held reports whether the server held a payment since the last Reset, and the reason it gave.

func (*Tap) Payment

func (t *Tap) Payment() string

Payment is the x-bsv-payment header last sent, "" when none was.

func (*Tap) Reset

func (t *Tap) Reset()

Reset forgets the hold seen, keeping the payment: what a client calls before it sends the held payment again.

func (*Tap) RoundTrip

func (t *Tap) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip sends req, noting a payment it carries and a held answer.

Jump to

Keyboard shortcuts

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