transactions

package
v4.12.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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,
	notifier accounts.Notifier,
	log *logrus.Entry,
) *Transactions

NewTransactions creates a new instance of Transactions.

func (*Transactions) Balance

func (transactions *Transactions) Balance() *accounts.Balance

Balance computes the confirmed and unconfirmed balance of the account.

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
	// contains filtered or unexported fields
}

TxInfo contains additional tx information to display to the user.

func (*TxInfo) Addresses

func (txInfo *TxInfo) Addresses() []accounts.AddressAndAmount

Addresses implements accounts.Transaction.

func (*TxInfo) Amount

func (txInfo *TxInfo) Amount() coin.Amount

Amount implements accounts.Transaction.

func (*TxInfo) Fee

func (txInfo *TxInfo) Fee() *coin.Amount

Fee implements accounts.Transaction.

func (*TxInfo) FeeRatePerKb

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

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

func (*TxInfo) ID

func (txInfo *TxInfo) ID() string

ID implements accounts.Transaction.

func (*TxInfo) NumConfirmations

func (txInfo *TxInfo) NumConfirmations() int

NumConfirmations implements accounts.Transaction.

func (*TxInfo) Status

func (txInfo *TxInfo) Status() accounts.TxStatus

Status implements accounts.Transaction.

func (*TxInfo) Timestamp

func (txInfo *TxInfo) Timestamp() *time.Time

Timestamp implements accounts.Transaction.

func (*TxInfo) Type

func (txInfo *TxInfo) Type() accounts.TxType

Type implements accounts.Transaction.

Jump to

Keyboard shortcuts

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