utxodb

package
v0.0.0-...-59fa258 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2016 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package utxodb implements UTXO selection and reservation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInsufficient indicates the account doesn't contain enough
	// units of the requested asset to satisfy the reservation.
	// New units must be deposited into the account in order to
	// satisfy the request; change will not be sufficient.
	ErrInsufficient = errors.New("reservation found insufficient funds")

	// ErrReserved indicates that a reservation could not be
	// satisfied because some of the outputs were already reserved.
	// When those reservations are finalized into a transaction
	// (and no other transaction spends funds from the account),
	// new change outputs will be created
	// in sufficient amounts to satisfy the request.
	ErrReserved = errors.New("reservation found outputs already reserved")
)

Functions

This section is empty.

Types

type Change

type Change struct {
	Source Source
	Amount uint64
}

Change represents reserved units beyond what was asked for. Total reservation is for Amount+Source.Amount.

type Reserver

type Reserver struct {
	DB *sql.DB
}

func (*Reserver) ExpireReservations

func (res *Reserver) ExpireReservations(ctx context.Context, period time.Duration)

ExpireReservations is meant to be run as a goroutine. It loops, calling the expire_reservations() pl/pgsql function to remove expired reservations from the reservations table. It returns when its context is canceled.

func (*Reserver) Reserve

func (res *Reserver) Reserve(ctx context.Context, sources []Source, exp time.Time) (u []*UTXO, c []Change, err error)

func (*Reserver) ReserveUTXO

func (res *Reserver) ReserveUTXO(ctx context.Context, txHash bc.Hash, pos uint32, clientToken *string, exp time.Time) (*UTXO, error)

type Source

type Source struct {
	AssetID     bc.AssetID `json:"asset_id"`
	AccountID   string     `json:"account_id"`
	TxHash      *bc.Hash
	OutputIndex *uint32
	Amount      uint64
	ClientToken *string `json:"client_token"`
}

type UTXO

type UTXO struct {
	bc.Outpoint
	bc.AssetAmount
	Script []byte

	AccountID           string
	ControlProgramIndex uint64
}

Jump to

Keyboard shortcuts

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