tx

package
v0.0.0-...-7abacdd Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: Unlicense Imports: 13 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 {
	Signature  []byte
	PubKey     []byte
	PrevOutput OutPoint
}

Input represents a transaction input, each input references the output of another transaction.

type OutPoint

type OutPoint struct {
	// Transaction ID of the previous output
	TxID []byte
	// Index of the referenced output in the previous transaction
	Index int
}

OutPoint represents the previous output being spent.

type Output

type Output struct {
	// Hashed public key of the coins' owner
	PubKeyHash []byte
	// Represented in satoshis
	Value int
}

Output represents a transaction output, they are indivisible and the place where coins are actually stored.

func NewOutput

func NewOutput(value int, address string) Output

NewOutput create a new transaction output.

func (Output) IsLockedWithKey

func (o Output) IsLockedWithKey(pubKeyHash []byte) bool

IsLockedWithKey checks if the output can be used by the owner of the public key.

type Tx

type Tx struct {
	ID      []byte
	Inputs  []Input
	Outputs []Output
	// In Bitcoin, a transaction's fee is equal to the difference between the amount of coins
	// locked in the inputs' referenced outputs and the ones in the new outputs.
	//
	// To make things simpler we just include it as a field, the input surplus will still exist.
	Fee int
}

Tx represents a transaction.

Every new transaction must have at least one input and output, except coinbase.

func New

func New(inputs []Input, outputs []Output, fee int) (*Tx, error)

New returns a new transaction with the inputs and outputs provided.

func NewCoinbase

func NewCoinbase(toAddr, data string, fees int, nextBlockHeight int32) (*Tx, error)

NewCoinbase returns a new coinbase transaction.

func (*Tx) IsCoinbase

func (tx *Tx) IsCoinbase() bool

IsCoinbase checks whether the transaction is coinbase

func (*Tx) Sign

func (tx *Tx) Sign(privKey *ecdsa.PrivateKey, prevTxs map[string]Tx) error

Sign signs the inputs of a transaction.

func (Tx) String

func (tx Tx) String() string

String returns a human-readable representation of a transaction.

func (*Tx) TrimmedCopy

func (tx *Tx) TrimmedCopy() Tx

TrimmedCopy creates a trimmed copy of Transaction to be used in signing.

https://en.bitcoin.it/w/images/en/7/70/Bitcoin_OpCheckSig_InDetail.png

func (*Tx) Verify

func (tx *Tx) Verify(prevTxs map[string]Tx) (bool, error)

Verify validates signatures of transaction inputs.

Directories

Path Synopsis
Package utxo implements operations related to unspent transaction outputs (UTXO), which allow us to check for the balance of every wallet of the network.
Package utxo implements operations related to unspent transaction outputs (UTXO), which allow us to check for the balance of every wallet of the network.

Jump to

Keyboard shortcuts

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