transaction

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Input

type Input struct {
	// TransactionID points to a particular TX
	TransactionID []byte
	// OutIndex points to a particular output in the TX
	OutIndex int64
	// Sign is calculated with Signer
	Sign []byte
	// PubKey represents a public key of a sender
	PubKey []byte
}

Input represents an input

type Output

type Output struct {
	// Value has amount of coins
	Value int64
	// Address represents a PKH (public key hash) of a destination
	Address []byte
}

Output represents an output

type Signer

type Signer interface {
	Sign(*Transaction, *btcec.PrivateKey) error
}

Signer represents a signer interface

func NewSimpleSigner

func NewSimpleSigner(s Storage) Signer

NewSimpleSigner returns a new Signer

type Storage

type Storage interface {
	// FindTransactionByID finds a tx by given ID
	FindTransactionByID(TxID []byte) ([]byte, Transaction, error)
	// FindUTXOByPKH finds a set of UTXO by a given public key hash ( address )
	FindUTXOByPKH(context.Context, btcutil.AddressPubKeyHash) (UTXOSet, error)
	// TotalUTXOByPKH returns a sum of UTXO by a given public key hash ( address )
	TotalUTXOByPKH(context.Context, btcutil.AddressPubKeyHash) (int64, error)
}

Storage represents a storage for transactions A storage for transaction might differ from blockchain storage

type Transaction

type Transaction struct {
	// ID calculated with Hash method
	ID []byte
	// Inputs has a set of Input
	Inputs []Input
	// Outputs has a set of Output
	Outputs []Output
}

Transaction represents a TX

func New

New creates a TX

func NewCoinBase

func NewCoinBase(to btcutil.AddressPubKeyHash, reward amount.Amount) (Transaction, error)

NewCoinBase creates new coinbase TX with given reward

func (Transaction) Hash

func (tx Transaction) Hash() ([]byte, error)

Hash returns SHA256(SHA256(TX))

func (Transaction) HexID

func (tx Transaction) HexID() string

HexID returns hex encoded tx ID

func (Transaction) Serialize

func (tx Transaction) Serialize() ([]byte, error)

Serialize serializes TX This is not the best way to serialize TX.

type UTXO

type UTXO struct {
	TxID     []byte
	OutIndex int64
	Output
}

UTXO represents an unspent transaction output https://bitcoin.org/en/glossary/unspent-transaction-output

type UTXOSet

type UTXOSet []UTXO

UTXOSet represents a set of UTXOs

func NewUTXOSetFromTX

func NewUTXOSetFromTX(tx Transaction) UTXOSet

NewUTXOSetFromTX create UTXOSet from a TX It used in tests only

type Verifier

type Verifier interface {
	Verify(*Transaction) error
}

Verifier represents a simpleSigner TX verifier

func NewSimpleVerifier

func NewSimpleVerifier(s Storage) Verifier

NewSimpleVerifier return a new Verifier

Jump to

Keyboard shortcuts

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