purse

package
v0.33.10 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 24 Imported by: 5 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 purse is the two payment actions the embedded wallet does not implement, over the embedded wallet (the identity key and its coin pool): the client leg and the payee leg of a BRC-105 payment for a priced question.

  • CreateAction pays one output from the pool, unbroadcast, and returns the payment as Atomic BEEF: what the SDK's AuthFetch asks a wallet for when a host answers a priced question with 402 (BRC-105). It pays at most MaxPay, and nothing else: any other shape is refused.
  • InternalizeAction takes a BRC-29 payment to this identity ("wallet payment" outputs, BRC-100): it checks each output pays the key this identity derives for the remittance and the sender, verifies the transaction against the headers, broadcasts it through the settlement leg, waits for its proof, and adds the outputs to the pool with their derivation, so the pool can spend them: what an operator does with a payment a host accepted for a priced question, and what a recipient does with a payment sent to it.

A Purse is a wallet.Interface, so it is handed to the SDK's AuthFetch as the wallet. After a question is answered the caller calls Settle when the host accepted a payment and Refund when it did not.

A remote BRC-100 wallet does both actions itself; an application that uses one needs neither.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrRefusedAction is an action this wallet does not make.
	ErrRefusedAction = errors.New("purse: this wallet makes no such action")
	// ErrOverMaxPay is a payment of more than MaxPay.
	ErrOverMaxPay = errors.New("purse: the payee asks more than this wallet may pay")
	// ErrNoNode is a Purse with no Asset to read a payment's proof from.
	ErrNoNode = errors.New("purse: no node to read the payment's proof from")
	// ErrNoSettler is a Purse with no Settler to broadcast a payment on.
	ErrNoSettler = errors.New("purse: no settlement leg to broadcast the payment on")
	// ErrNotMined is a payment that is broadcast and did not mine within
	// Wait. It is not refused: Await again, or Check and Broadcast again,
	// takes it once it has mined.
	ErrNotMined = errors.New("purse: the payment is broadcast and not yet mined")
)

The refusals an application may word itself: which flag raises the cap, which setting names the node or the leg, and what to run again are the application's to say.

Functions

func Remittance

func Remittance(prefix, suffix, senderHex string) (*wallet.Payment, error)

Remittance is the BRC-100 remittance of a payment, from its base64 prefix and suffix and the sender's key, as a host's payment ledger writes them.

Example

A payee takes a payment from what a host's ledger recorded about it: the derivation prefix and suffix, in base64, and the sender's identity key. Remittance turns those into what InternalizeAction checks the payment's output against, and refuses anything that is not that.

package main

import (
	"encoding/base64"
	"fmt"

	"github.com/lightwebinc/bcommon/goldentest"
	"github.com/lightwebinc/bcommon/purse"
)

func main() {
	prefix := base64.StdEncoding.EncodeToString([]byte("prefix-1"))
	suffix := base64.StdEncoding.EncodeToString([]byte("suffix-1"))
	sender := fmt.Sprintf("%x", goldentest.FixedKey().PubKey().Compressed())

	r, err := purse.Remittance(prefix, suffix, sender)
	fmt.Println(string(r.DerivationPrefix), string(r.DerivationSuffix), err)

	_, err = purse.Remittance("not base64!", suffix, sender)
	fmt.Println(err)
	_, err = purse.Remittance(prefix, suffix, "02"+sender[2:10])
	fmt.Println(err != nil)
}
Output:
prefix-1 suffix-1 <nil>
purse: derivation prefix "not base64!" is not base64
true

func Txid

func Txid(h chainhash.Hash) string

Txid is a hash as the display txid.

func Unmined

Unmined are the ancestors of tx its BEEF carries without a proof, each after its own.

Types

type Incoming

type Incoming struct {
	Tx   *transaction.Transaction
	Txid string
	// contains filtered or unexported fields
}

Incoming is a payment Check found paying this identity and verifying against the headers, on its way into the pool.

type Purse

type Purse struct {
	*bwallet.Embedded
	// NewPayer is a Payer over the wallet's pool, for CreateAction's fee
	// coin and change.
	NewPayer func() *producer.Payer
	// Fees is the payment's fee policy.
	Fees mint.Fees
	// MaxPay is the most one CreateAction pays; zero pays nothing.
	MaxPay uint64
	// Settler and Asset broadcast an internalized payment and wait for its
	// proof; Headers verify it first. Wait bounds the wait, Poll paces it.
	Settler publish.Settler
	Asset   *nodeapi.Asset
	// Chain, when set, is asked for proofs and spends in Asset's place: a
	// chain view that needs no node (nodeapi.ParseChain).
	Chain   nodeapi.Chain
	Headers chaintracker.ChainTracker
	Wait    time.Duration
	Poll    time.Duration
	// contains filtered or unexported fields
}

Purse is the wallet. The embedded wallet answers the key and signature methods; the fields below serve the two actions.

func (*Purse) Await

func (p *Purse) Await(ctx context.Context, in *Incoming) error

Await waits, up to Wait, for a broadcast payment to mine, and stops at once when the node shows one of its inputs spent by another transaction.

func (*Purse) Broadcast

func (p *Purse) Broadcast(ctx context.Context, in *Incoming) error

Broadcast hands a checked payment to the settlement leg. One already mined is taken as it is; one the network already holds is not an error.

func (*Purse) Check

Check is InternalizeAction's checks: the outputs pay this identity's derived keys, and the transaction verifies against Headers.

func (*Purse) CreateAction

func (p *Purse) CreateAction(ctx context.Context, args wallet.CreateActionArgs, _ string) (*wallet.CreateActionResult, error)

CreateAction pays exactly one output of at most MaxPay satoshis to its locking script from the pool, with change back to the fund key, signs it and returns it as Atomic BEEF without broadcasting it. The payee broadcasts it (BRC-105). Settle or Refund must follow. A payment over MaxPay is ErrOverMaxPay; any other shape is ErrRefusedAction.

func (*Purse) InternalizeAction

InternalizeAction takes the "wallet payment" outputs of args.Tx, an Atomic BEEF, into the pool. Each output must pay the key this identity derives under BRC-29 for its remittance's prefix, suffix and sender; the transaction must verify against Headers. It is broadcast through the settlement leg (a transaction the network already holds is not an error) and its proof awaited, then the outputs are pooled with their derivation. A basket insertion is refused: this wallet has one basket.

It is Check, Broadcast, Await and Take in turn; a caller settling many payments runs those halves itself, so it can broadcast them all before it waits.

func (*Purse) Refund

func (p *Purse) Refund()

Refund returns the fee coin of every payment CreateAction made to the pool: none was accepted, so none can be broadcast by the payee.

func (*Purse) Settle

func (p *Purse) Settle() *transaction.Transaction

Settle keeps the last payment CreateAction made, which the payee accepted: its fee coin is spent and its change, unproven until the payment mines, is held in the pool. Every earlier payment is refunded. It returns the kept payment, or nil when none was made. The caller keeps the payment (funding.BEEF) for as long as it is unmined, so that a later payment can spend its change and carry it, and may broadcast it itself: it is the payer's own transaction, and the same bytes the payee settles.

func (*Purse) Take

func (p *Purse) Take(in *Incoming) error

Take adds a mined payment's outputs to the pool with their derivation.

type RefusedError

type RefusedError struct {
	Txid string
	Why  string
}

RefusedError is a payment the network will never mine: the leg refused it for good, or one of its inputs is spent by another transaction. The payer took the coins back; there is nothing to settle.

func (*RefusedError) Error

func (e *RefusedError) Error() string

Jump to

Keyboard shortcuts

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