mint

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package mint builds the mined transactions an application's state lives on: a transition of its state token, a funding tree, and a plain payment, each with a fee input and a change output supplied by the caller.

Every lock script arrives as a parameter and every input arrives with the template that signs it, so the package knows no application's derivation or tags and holds no key material. What it owns is the fee logic: a loop that signs to measure the size and rebuilds at the rate until the fee covers it.

A carrier is not built here: it is never mined and pays no fee, so package carrier builds it.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInsufficient = errors.New("mint: fee input cannot cover the outputs and the fee")
	ErrNoChange     = errors.New("mint: nil change script")
)
View Source
var DefaultFees = Fees{SatPerByte: 1, Floor: 250}

DefaultFees is one satoshi per byte with a 250 satoshi floor.

Functions

func FundingTree

func FundingTree(lock *script.Script, count int, sats uint64, fee Input, change *script.Script, fees Fees) (*transaction.Transaction, error)

FundingTree builds and signs a funding tree: count outputs of sats each, locked with lock, plus change. Each carrier spends one; a mined spend of any of them by the owner (a kill switch) is a transaction the caller builds with the unlocker for lock.

func Payment

func Payment(ctx context.Context, dest *script.Script, sats uint64, fee Input, change *script.Script, fees Fees) (*transaction.Transaction, error)

Payment builds and signs a simple payment: one output of sats to dest, change back to the payer. It is the BRC-29 leg: the destination is a key derived from the recipient's identity, and the transaction itself is an ordinary P2PKH spend.

ctx is unused: nothing here reaches the network, and a template that signs through a wallet carries its own context. It is kept so the signature stays stable for callers if a later version needs it.

func Transition

func Transition(lock *script.Script, sats uint64, prev *Input, fee Input, change *script.Script, fees Fees) (*transaction.Transaction, error)

Transition builds and signs a state token transaction: one output of sats locked with lock.

Inputs: the previous token output when prev is not nil (an update spends its predecessor; a create spends none), then the fee input. Outputs: the token at index 0, then change. Change below the fee floor is dropped rather than left as dust.

prev.Unlocker is required. The key that signs the previous token is not always the one the new lock names (after a rotation the predecessor signs and the successor is locked to), so which one it is stays the caller's decision rather than a default here.

Types

type Fees

type Fees struct {
	SatPerByte uint64
	Floor      uint64
}

Fees is the fee policy: a rate per byte of the signed transaction and a floor under it. The floor keeps a fee meaningful where the per-byte rate alone would round to almost nothing.

type Input

type Input struct {
	Tx       *transaction.Transaction
	Vout     uint32
	Unlocker transaction.UnlockingScriptTemplate
}

Input is one input the caller funds a transaction with: its source transaction, the output index, and the template that signs it. The template is what keeps key material out of this package: an embedded wallet's funding unlocker signs through wallet.CreateSignature.

Jump to

Keyboard shortcuts

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