transactions

package
v4.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TxTypeReceive is a tx which sends funds to our wallet.
	TxTypeReceive TxType = "receive"
	// TxTypeSend is a tx which sends funds out of our wallet.
	TxTypeSend = "send"
	// TxTypeSendSelf is a tx from out wallet to our wallet.
	TxTypeSendSelf = "sendSelf"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Balance

type Balance struct {
	// Available funds are all confirmed funds which are not spent by any tx. Exception: unconfirmed
	// transactions that spend from the wallet are available.
	Available btcutil.Amount
	// Incoming balance are unconfirmed funds coming into the wallet.
	Incoming btcutil.Amount
}

Balance contains the available and incoming balance of the wallet.

type DBInterface

type DBInterface interface {
	// Begin starts a DB transaction. Apply `defer tx.Rollback()` in any case after. Use
	// `tx.Commit()` to commit the write operations.
	Begin() (DBTxInterface, error)
	Close() error
}

DBInterface can be implemented by database backends to open database transactions.

type DBTxInterface

type DBTxInterface interface {
	// Commit closes the transaction, writing the changes.
	Commit() error

	// Rollback closes the transaction without writing anything and be called safely after Commit().
	Rollback()

	// PutTx stores a transaction and it's height (according to
	// https://github.com/kyuupichan/electrumx/blob/46f245891cb62845f9eec0f9549526a7e569eb03/docs/protocol-basics.rst#status).
	PutTx(txHash chainhash.Hash, tx *wire.MsgTx, height int) error

	// DeleteTx deletes a transaction (nothing happens if not found).
	DeleteTx(txHash chainhash.Hash)

	// AddAddressToTx adds an address associated with a transaction. Retrieve them with `TxInfo()`.
	AddAddressToTx(chainhash.Hash, blockchain.ScriptHashHex) error
	RemoveAddressFromTx(chainhash.Hash, blockchain.ScriptHashHex) (bool, error)

	// TxInfo retrieves all data stored with for a transaction. Default values (nil, nil, 0, nil)
	// are returned for the values not found.
	TxInfo(chainhash.Hash) (
		tx *wire.MsgTx, addresses []string, height int, headerTimestamp *time.Time, err error)

	// Transactions retrieves all stored transaction hashes.
	Transactions() ([]chainhash.Hash, error)

	// UnverifiedTransactions retrieves all stored transaction hashes of unverified transactions.
	UnverifiedTransactions() ([]chainhash.Hash, error)

	// MarkTxVerified marks a tx as verified. Stores timestamp of the header this tx appears in.
	MarkTxVerified(txHash chainhash.Hash, headerTimestamp time.Time) error

	// PutInput stores a transaction input. It is referenced by output it spends. The transaction
	// hash of the transaction this input was found in is recorded. TODO: store slice of inputs
	// along with the txhash they appear in. If there are more than one, a double spend is detected.
	PutInput(wire.OutPoint, chainhash.Hash) error

	// Input retrieves an input. `nil, nil` is returned if not found.
	Input(wire.OutPoint) (*chainhash.Hash, error)

	// DeleteInput deletes an input (nothing happens if not found).
	DeleteInput(wire.OutPoint)

	// PutOutput stores an Output.
	PutOutput(wire.OutPoint, *wire.TxOut) error

	// Output retrieves an output. `nil, nil` is returned if not found.
	Output(wire.OutPoint) (*wire.TxOut, error)
	Outputs() (map[wire.OutPoint]*wire.TxOut, error)

	// DeleteOutput deletes an output (nothing happens if not found).
	DeleteOutput(wire.OutPoint)

	// PutAddressHistory stores an address history.
	PutAddressHistory(blockchain.ScriptHashHex, blockchain.TxHistory) error

	// AddressHistory retrieves an address history. If not found, returns an empty history.
	AddressHistory(blockchain.ScriptHashHex) (blockchain.TxHistory, error)
}

DBTxInterface needs to be implemented to persist all wallet/transaction related data.

type SpendableOutput

type SpendableOutput struct {
	*wire.TxOut
	Address string
}

SpendableOutput is an unspent coin.

func (*SpendableOutput) ScriptHashHex

func (txOut *SpendableOutput) ScriptHashHex() blockchain.ScriptHashHex

ScriptHashHex returns the hash of the PkScript of the output, in hex format.

type Transactions

type Transactions struct {
	locker.Locker
	// contains filtered or unexported fields
}

Transactions handles wallet transactions: keeping an index of the transactions, inputs, (unspent) outputs, etc.

func NewTransactions

func NewTransactions(
	net *chaincfg.Params,
	db DBInterface,
	headers headers.Interface,
	synchronizer *synchronizer.Synchronizer,
	blockchain blockchain.Interface,
	log *logrus.Entry,
) *Transactions

NewTransactions creates a new instance of Transactions.

func (*Transactions) Balance

func (transactions *Transactions) Balance() *Balance

Balance computes the confirmed and unconfirmed balance of the wallet.

func (*Transactions) Close

func (transactions *Transactions) Close()

Close cleans up when finished using.

func (*Transactions) SpendableOutputs

func (transactions *Transactions) SpendableOutputs() map[wire.OutPoint]*SpendableOutput

SpendableOutputs returns all unspent outputs of the wallet which are eligible to be spent. Those include all unspent outputs of confirmed transactions, and unconfirmed outputs that we created ourselves.

func (*Transactions) Transactions

func (transactions *Transactions) Transactions(
	isChange func(blockchain.ScriptHashHex) bool) []*TxInfo

Transactions returns an ordered list of transactions.

func (*Transactions) UpdateAddressHistory

func (transactions *Transactions) UpdateAddressHistory(scriptHashHex blockchain.ScriptHashHex, txs []*blockchain.TxInfo)

UpdateAddressHistory should be called when initializing a wallet address, or when the history of an address changes (a new transaction that touches it appears or disappears). The transactions are downloaded and indexed.

type TxInfo

type TxInfo struct {
	Tx *wire.MsgTx
	// VSize is the tx virtual size in
	// "vbytes". https://bitcoincore.org/en/segwit_wallet_dev/#transaction-fee-estimation
	VSize int64
	// Size is the serialized tx size in bytes.
	Size int64
	// Weight is the tx weight.
	Weight int64
	// Height is the height this tx was confirmed at. 0 (or -1) for unconfirmed.
	Height int
	// NumConfirmations is the number of confirmations. 0 for unconfirmed.
	NumConfirmations int
	Type             TxType
	// Amount is always >0 and is the amount received or sent (not including the fee).
	Amount btcutil.Amount
	// Fee is nil if for a receiving tx (TxTypeReceive). The fee is only displayed (and relevant)
	// when sending funds from the wallet.
	Fee *btcutil.Amount
	// Time of confirmation. nil for unconfirmed tx or when the headers are not synced yet.
	Timestamp *time.Time
	// Addresses money was sent to / received on (without change addresses).
	Addresses []string
}

TxInfo contains additional tx information to display to the user.

func (*TxInfo) FeeRatePerKb

func (txInfo *TxInfo) FeeRatePerKb() *btcutil.Amount

FeeRatePerKb returns the fee rate of the tx (fee / tx size).

type TxType

type TxType string

TxType is a type of transaction. See the TxType* constants.

Jump to

Keyboard shortcuts

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