utxodb

package
v0.0.0-...-0b9d80d Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2016 License: AGPL-3.0 Imports: 7 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 DBReserver

type DBReserver struct {
	DB *sql.DB
}

func (*DBReserver) Cancel

func (res *DBReserver) Cancel(ctx context.Context, rid int32) error

Cancel cancels the given reservation if possible. If it doesn't exist (if it's already been consumed or canceled), it is silently ignored.

func (*DBReserver) ExpireReservations

func (res *DBReserver) ExpireReservations(ctx context.Context) error

func (*DBReserver) Reserve

func (res *DBReserver) Reserve(ctx context.Context, source Source, exp time.Time) (reservationID int32, u []*UTXO, c []Change, err error)

Reserve reserves account UTXOs to cover the provided sources. If UTXOs are successfully reserved, it's the responsbility of the caller to cancel them if an error occurs.

func (*DBReserver) ReserveUTXO

func (res *DBReserver) ReserveUTXO(ctx context.Context, txHash bc.Hash, pos uint32, clientToken *string, exp time.Time) (reservationID int32, utxo *UTXO, err 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