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 ¶
- Variables
- func Admitted(ans map[string]any, topic string) (bool, string)
- func AloneBEEF(tx *transaction.Transaction) ([]byte, error)
- func PubKey(s string) *ec.PublicKey
- func Verify(q *storerec.Request, raw, signed []byte, o *Object, f *Fetcher) storerec.Verdict
- type Ad
- type Call
- type Chain
- type Fetcher
- type Hold
- type Object
- type Payee
- type Put
- type Settlement
- type Terms
- type Writer
- func (w *Writer) Ads(ctx context.Context, host string, root [32]byte) ([]Ad, error)
- func (w *Writer) Build(ctx context.Context, content []byte) (*Object, error)
- func (w *Writer) Carrier(ctx context.Context, d pushdrop.Derivation, record []byte, ...) ([]byte, string, error)
- func (w *Writer) Challenge(ctx context.Context, front string, raw []byte, entry string, maxPay uint64) (*Call, error)
- func (w *Writer) Delete(ctx context.Context, key string) (*Put, error)
- func (w *Writer) Entry(ctx context.Context, o *Object, key string, t Terms) (*Put, error)
- func (w *Writer) HoldOutput(ctx context.Context, sats uint64) (*Hold, error)
- func (w *Writer) Identity() []byte
- func (w *Writer) NewChain(ctx context.Context, bucket string, writers [][]byte) (*Chain, []byte, error)
- func (w *Writer) Post(ctx context.Context, url string, body []byte, maxPay uint64) (*Call, error)
- func (w *Writer) Request(ctx context.Context, b *storerec.Built, provider []byte, c uint64, ...) (*storerec.Request, []byte, error)
- func (w *Writer) Settle(ctx context.Context, put *Put, payees []Payee) (*Settlement, error)
- func (w *Writer) Submit(ctx context.Context, base, topic string, beef []byte) (map[string]any, error)
- func (w *Writer) Tree(ctx context.Context, d pushdrop.Derivation, n int) (*transaction.Transaction, error)
Constants ¶
This section is empty.
Variables ¶
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 AloneBEEF ¶
func AloneBEEF(tx *transaction.Transaction) ([]byte, error)
AloneBEEF is a mined transaction as a host admits a mined object.
Types ¶
type Ad ¶
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 ¶
Anchor mints the next token applying batch (spec section 3.4) and returns its BEEF.
func (*Chain) Entries ¶
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).
type Hold ¶
type Hold struct {
Tx *transaction.Transaction
Vout uint32
Sats uint64
}
Hold is a mined hold output.
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) 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) Delete ¶ added in v0.11.0
Delete makes the delete entry for key: the put it ends is whichever the bucket holds under that key, created no later than this.
func (*Writer) HoldOutput ¶
HoldOutput mints a hold output of sats.
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) 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 ¶
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 ¶
func (w *Writer) Tree(ctx context.Context, d pushdrop.Derivation, n int) (*transaction.Transaction, error)
Tree mints a funding tree of n outputs of one satoshi under d.