structures

package
v0.0.0-...-f7c9202 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReverseBlocksShortSlice

func ReverseBlocksShortSlice(ss []*BlockShort)

Reverce list of blocks for short info

func ReverseBlocksSlice

func ReverseBlocksSlice(ss []*Block)

Reverce list of blocks

Types

type Block

type Block struct {
	Timestamp     int64
	Transactions  []*Transaction
	PrevBlockHash []byte
	Hash          []byte
	Nonce         int
	Height        int
}

Block represents a block in the blockchain

func (*Block) Copy

func (b *Block) Copy() *Block

Creates copy of a block

func (*Block) DeserializeBlock

func (b *Block) DeserializeBlock(d []byte) error

DeserializeBlock deserializes a block

func (*Block) GetShortCopy

func (b *Block) GetShortCopy() *BlockShort

Returns short copy of a block. It is just hash + prevhash

func (*Block) GetSimpler

func (b *Block) GetSimpler() *BlockSimpler

Returns simpler copy of a block. This is the version for easy print TODO . not sure we really need this

func (*Block) HashTransactions

func (b *Block) HashTransactions() ([]byte, error)

HashTransactions returns a hash of the transactions in the block

func (*Block) PrepareNewBlock

func (b *Block) PrepareNewBlock(transactions []*Transaction, prevBlockHash []byte, height int) error

Fills a block with transactions. But without signatures

func (*Block) Serialize

func (b *Block) Serialize() ([]byte, error)

Serialize serializes the block

type BlockShort

type BlockShort struct {
	PrevBlockHash []byte
	Hash          []byte
	Height        int
}

short info about a block. to exchange over network

func (*BlockShort) DeserializeBlock

func (b *BlockShort) DeserializeBlock(d []byte) error

Deserialize BlockShort from bytes

func (*BlockShort) Serialize

func (b *BlockShort) Serialize() ([]byte, error)

Serialise BlockShort to bytes

type BlockSimpler

type BlockSimpler struct {
	Timestamp     int64
	Transactions  []string
	PrevBlockHash []byte
	Hash          []byte
	Nonce         int
	Height        int
}

simpler representation of a block. transactions are presented as strings

type TXInput

type TXInput struct {
	Txid      []byte
	Vout      int
	Signature []byte
	PubKey    []byte // this is the wallet who spends transaction
}

TXInput represents a transaction input

func (TXInput) String

func (input TXInput) String() string

func (TXInput) ToBytes

func (input TXInput) ToBytes() ([]byte, error)

func (*TXInput) UsesKey

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

UsesKey checks whether the address initiated the transaction

type TXOutput

type TXOutput struct {
	Value      float64
	PubKeyHash []byte
}

TXOutput represents a transaction output

func NewTXOutput

func NewTXOutput(value float64, 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) String

func (output TXOutput) String() string

func (TXOutput) ToBytes

func (output TXOutput) ToBytes() ([]byte, error)

type TXOutputIndependent

type TXOutputIndependent struct {
	Value          float64
	DestPubKeyHash []byte
	SendPubKeyHash []byte
	TXID           []byte
	OIndex         int
	IsBase         bool
	BlockHash      []byte
}

Simplified output format. To use externally It has all info in human readable format this can be used to display info abut outputs wihout references to transaction object

func (*TXOutputIndependent) IsLockedWithKey

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

Same as IsLockedWithKey but for simpler structure

func (*TXOutputIndependent) LoadFromSimple

func (out *TXOutputIndependent) LoadFromSimple(sout TXOutput, txid []byte, ind int, sender []byte, iscoinbase bool, blockHash []byte)

build independed transaction from normal output

type TXOutputIndependentList

type TXOutputIndependentList []TXOutputIndependent

func (TXOutputIndependentList) Len

func (a TXOutputIndependentList) Len() int

func (TXOutputIndependentList) Less

func (a TXOutputIndependentList) Less(i, j int) bool

func (TXOutputIndependentList) Swap

func (a TXOutputIndependentList) Swap(i, j int)

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
	Time int64
}

Transaction represents a Bitcoin transaction

func (*Transaction) Copy

func (tx *Transaction) Copy() (Transaction, error)

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

func (*Transaction) DeserializeTransaction

func (tx *Transaction) DeserializeTransaction(data []byte) error

DeserializeTransaction deserializes a transaction

func (*Transaction) Hash

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

Hash returns the hash of the Transaction

func (Transaction) IsCoinbase

func (tx Transaction) IsCoinbase() bool

IsCoinbase checks whether the transaction is coinbase

func (*Transaction) MakeCoinbaseTX

func (tx *Transaction) MakeCoinbaseTX(to, data string) error

* Make a transaction to be coinbase.

func (*Transaction) PrepareSignData

func (tx *Transaction) PrepareSignData(prevTXs map[int]*Transaction) ([][]byte, error)

prepare data to sign as part of transaction this return slice of slices. Every of them must be signed for each TX Input

func (Transaction) Serialize

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

Serialize returns a serialized Transaction

func (*Transaction) SetSignatures

func (tx *Transaction) SetSignatures(signatures [][]byte) error

Sets signatures for inputs. Signatures were created separately for data set prepared before in the function PrepareSignData

func (*Transaction) SignData

func (tx *Transaction) SignData(privKey ecdsa.PrivateKey, PubKey []byte, DataToSign [][]byte) error

Sign Inouts for transaction DataToSign is output of the function PrepareSignData

func (Transaction) String

func (tx Transaction) String() string

String returns a human-readable representation of a transaction

func (*Transaction) TimeNow

func (tx *Transaction) TimeNow()

Hash returns the hash of the Transaction

func (Transaction) ToBytes

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

converts transaction to slice of bytes this will be used to do a hash of transactions

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[int]*Transaction) error

Verify verifies signatures of Transaction inputs And total amount of inputs and outputs

type Transactions

type Transactions []*Transaction

Sorting of transactions slice

func (Transactions) Len

func (c Transactions) Len() int

func (Transactions) Less

func (c Transactions) Less(i, j int) bool

func (Transactions) Swap

func (c Transactions) Swap(i, j int)

type TransactionsHistory

type TransactionsHistory struct {
	IOType  bool
	TXID    []byte
	Address string
	Value   float64
}

Jump to

Keyboard shortcuts

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