txauthor

package
v1.9.16 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: Unlicense Imports: 14 Imported by: 0

Documentation

Overview

Package txauthor provides transaction creation code for wallets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAllInputScripts

func AddAllInputScripts(tx *wire.MsgTx, prevPkScripts [][]byte, inputValues []util.Amount,
	secrets SecretsSource) error

AddAllInputScripts modifies transaction a transaction by adding inputs scripts for each input. Previous output scripts being redeemed by each input are passed in prevPkScripts and the slice length must match the number of inputs. Private keys and redeem scripts are looked up using a SecretsSource based on the previous output script.

func Check added in v0.4.14

func Check(err error) bool

func Debug added in v0.4.14

func Debug(a ...interface{})

func Debugc added in v0.4.14

func Debugc(fn func() string)

func Debugf added in v0.4.14

func Debugf(format string, a ...interface{})

func Debugs added in v0.4.14

func Debugs(a interface{})

func Error added in v0.4.14

func Error(a ...interface{})

func Errorc added in v0.4.14

func Errorc(fn func() string)

func Errorf added in v0.4.14

func Errorf(format string, a ...interface{})

func Errors added in v0.4.14

func Errors(a interface{})

func Fatal added in v0.4.14

func Fatal(a ...interface{})

func Fatalc added in v0.4.14

func Fatalc(fn func() string)

func Fatalf added in v0.4.14

func Fatalf(format string, a ...interface{})

func Fatals added in v0.4.14

func Fatals(a interface{})

func Info added in v0.4.14

func Info(a ...interface{})

func Infoc added in v0.4.14

func Infoc(fn func() string)

func Infof added in v0.4.14

func Infof(format string, a ...interface{})

func Infos added in v0.4.14

func Infos(a interface{})

func RandomizeOutputPosition

func RandomizeOutputPosition(outputs []*wire.TxOut, index int) int

RandomizeOutputPosition randomizes the position of a transaction's output by swapping it with a random output. The new index is returned. This should be done before signing.

func Trace added in v0.4.14

func Trace(a ...interface{})

func Tracec added in v0.4.14

func Tracec(fn func() string)

func Tracef added in v0.4.14

func Tracef(format string, a ...interface{})

func Traces added in v0.4.14

func Traces(a interface{})

func Warn added in v0.4.14

func Warn(a ...interface{})

func Warnc added in v0.4.14

func Warnc(fn func() string)

func Warnf added in v0.4.14

func Warnf(format string, a ...interface{})

func Warns added in v0.4.14

func Warns(a interface{})

Types

type AuthoredTx

type AuthoredTx struct {
	Tx              *wire.MsgTx
	PrevScripts     [][]byte
	PrevInputValues []util.Amount
	TotalInput      util.Amount
	ChangeIndex     int // negative if no change
}

AuthoredTx holds the state of a newly-created transaction and the change output (if one was added).

func NewUnsignedTransaction

func NewUnsignedTransaction(outputs []*wire.TxOut, relayFeePerKb util.Amount,
	fetchInputs InputSource, fetchChange ChangeSource) (*AuthoredTx, error)

NewUnsignedTransaction creates an unsigned transaction paying to one or more non-change outputs. An appropriate transaction fee is included based on the transaction size.

Transaction inputs are chosen from repeated calls to fetchInputs with increasing targets amounts.

If any remaining output value can be returned to the wallet via a change output without violating mempool dust rules, a P2WPKH change output is appended to the transaction outputs. Since the change output may not be necessary, fetchChange is called zero or one times to generate this script. This function must return a P2WPKH script or smaller, otherwise fee estimation will be incorrect.

If successful, the transaction, total input value spent, and all previous output scripts are returned. If the input source was unable to provide enough input value to pay for every output any any necessary fees, an InputSourceError is returned.

BUGS: Fee estimation may be off when redeeming non-compressed P2PKH outputs.

func (*AuthoredTx) AddAllInputScripts

func (tx *AuthoredTx) AddAllInputScripts(secrets SecretsSource) error

AddAllInputScripts modifies an authored transaction by adding inputs scripts for each input of an authored transaction. Private keys and redeem scripts are looked up using a SecretsSource based on the previous output script.

func (*AuthoredTx) RandomizeChangePosition

func (tx *AuthoredTx) RandomizeChangePosition()

RandomizeChangePosition randomizes the position of an authored transaction's change output. This should be done before signing.

type ChangeSource

type ChangeSource func() ([]byte, error)

ChangeSource provides P2PKH change output scripts for transaction creation.

type InputSource

type InputSource func(target util.Amount) (total util.Amount, inputs []*wire.TxIn,
	inputValues []util.Amount, scripts [][]byte, err error)

InputSource provides transaction inputs referencing spendable outputs to construct a transaction outputting some target amount. If the target amount can not be satisified, this can be signaled by returning a total amount less than the target or by returning a more detailed error implementing InputSourceError.

type InputSourceError

type InputSourceError interface {
	error
	InputSourceError()
}

InputSourceError describes the failure to provide enough input value from unspent transaction outputs to meet a target amount. A typed error is used so input sources can provide their own implementations describing the reason for the error, for example, due to spendable policies or locked coins rather than the wallet not having enough available input value.

type SecretsSource

type SecretsSource interface {
	txscript.KeyDB
	txscript.ScriptDB
	ChainParams() *netparams.Params
}

SecretsSource provides private keys and redeem scripts necessary for constructing transaction input signatures. Secrets are looked up by the corresponding Address for the previous output script. Addresses for lookup are created using the source's blockchain parameters and means a single SecretsSource can only manage secrets for a single chain.

TODO: Rewrite this interface to look up private keys and redeem scripts for pubkeys, pubkey hashes, script

hashes, etc. as separate interface methods.

This would remove the ChainParams requirement of the interface and could avoid unnecessary conversions from previous output scripts to Addresses. This can not be done without modifications to the txscript package.

Jump to

Keyboard shortcuts

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