transaction

package
v0.0.0-...-1f6f007 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Subsidy = 10
)

Exported constants

Variables

This section is empty.

Functions

This section is empty.

Types

type TXInput

type TXInput struct {
	Txid      []byte
	Vout      int
	Signature []byte
	PubKey    []byte
}

TXInput represents a transaction input

func (*TXInput) UsesKey

func (in *TXInput) UsesKey(pubKeyHash []byte) bool

UsesKey checks whether the address initiated the transaction

type TXOutput

type TXOutput struct {
	Value      int
	PubKeyHash []byte
}

TXOutput represents a transaction output

func NewTXOutput

func NewTXOutput(value int, address string) *TXOutput

NewTXOutput create a new TXOutput

func (*TXOutput) IsLockedWithKey

func (out *TXOutput) IsLockedWithKey(pubKeyHash []byte) bool

IsLockedWithKey checks if the output can be used by the owner of the pubkey

func (*TXOutput) Lock

func (out *TXOutput) Lock(address []byte)

Lock signs the output

func (*TXOutput) Serialize

func (out *TXOutput) Serialize() []byte

Serialize serializes TXOutputs

type TXOutputs

type TXOutputs struct {
	Outputs []TXOutput
}

TXOutputs collects TXOutput

func DeserializeOutputs

func DeserializeOutputs(data []byte) TXOutputs

DeserializeOutputs deserializes TXOutputs

func (TXOutputs) Serialize

func (outs TXOutputs) Serialize() []byte

Serialize serializes TXOutputs

type Transaction

type Transaction struct {
	ID   []byte
	Vin  []TXInput
	Vout []TXOutput
}

Transaction represents a Bitcoin-like transaction

func DeserializeTransaction

func DeserializeTransaction(data []byte) Transaction

DeserializeTransaction deserializes a transaction

func NewCoinbaseTX

func NewCoinbaseTX(to, data string) *Transaction

NewCoinbaseTX creates a new coinbase transaction

func NewUTXOTransaction

func NewUTXOTransaction(acc int, validOutputs map[string][]int, to string, amount int, addrFrom []byte) (*Transaction, error)

NewUTXOTransaction creates a new transaction from the passed transaction inputs

func (*Transaction) Hash

func (tx *Transaction) Hash() []byte

Hash calculates the hash of the transaction and returns it as a byte array

func (Transaction) IsCoinbase

func (tx Transaction) IsCoinbase() bool

IsCoinbase checks whether the transaction is coinbase

func (*Transaction) Serialize

func (tx *Transaction) Serialize() []byte

Serialize sets ID of a transaction

func (*Transaction) Sign

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

Sign signs each input of a Transaction

func (Transaction) String

func (tx Transaction) String() string

String returns a human-readable representation of a transaction

func (*Transaction) TrimmedCopy

func (tx *Transaction) TrimmedCopy() Transaction

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

func (*Transaction) Verify

func (tx *Transaction) Verify(prevTXs map[string]Transaction) bool

Verify verifies signatures of Transaction inputs

Jump to

Keyboard shortcuts

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