structures

package
v0.0.0-...-acf744c Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckTXOutputValueToAddress

func CheckTXOutputValueToAddress(tx *Transaction, PubKeyHash []byte, amount float64) error

func CheckTXOutputsAreOnlyToGivenAddresses

func CheckTXOutputsAreOnlyToGivenAddresses(tx *Transaction, PubKeyHashes [][]byte) error

Check if all TXt currency outputs are only to given addresses

func ReverseBlocksShortSlice

func ReverseBlocksShortSlice(ss []*BlockShort)

Reverce list of blocks for short info

func ReverseBlocksSlice

func ReverseBlocksSlice(ss []*Block)

Reverce list of blocks

func SerializeTransaction

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

Serialize Transaction

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 NewBlockFromBytes

func NewBlockFromBytes(bsdata []byte) (*Block, error)

Make Block object from bytes

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 NewBlockShortFromBytes

func NewBlockShortFromBytes(bsdata []byte) (*BlockShort, error)

return BlockShort object from bytes

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 ConsensusInfo

type ConsensusInfo struct {
	CoinsForBlockMade float64
}

The structure includes consensus options to use in this package

type SQLUpdate

type SQLUpdate struct {
	ReferenceID     []byte
	Query           []byte
	RollbackQuery   []byte
	PrevTransaction []byte
}

SQL Transaction keeps a query and rollback query to cancel this update

func NewSQLUpdate

func NewSQLUpdate(sql string, referenceID string, rollbackSQL string) SQLUpdate

func (SQLUpdate) IsEmpty

func (q SQLUpdate) IsEmpty() bool

func (SQLUpdate) ToBytes

func (q SQLUpdate) ToBytes() []byte

type TXCurrencyInput

type TXCurrencyInput struct {
	Txid []byte
	Vout int
}

TXInput represents a transaction input

func (TXCurrencyInput) String

func (input TXCurrencyInput) String() string

func (TXCurrencyInput) ToBytes

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

type TXCurrrencyOutput

type TXCurrrencyOutput struct {
	Value      float64
	PubKeyHash []byte
}

TXOutput represents a transaction output

func NewTXOutput

func NewTXOutput(value float64, address string) *TXCurrrencyOutput

NewTXOutput create a new TXOutput

func (TXCurrrencyOutput) HasOutAddress

func (out TXCurrrencyOutput) HasOutAddress() bool

Lock signs the output

func (*TXCurrrencyOutput) IsLockedWithKey

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

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

func (*TXCurrrencyOutput) Lock

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

Lock signs the output

func (TXCurrrencyOutput) String

func (output TXCurrrencyOutput) String() string

func (TXCurrrencyOutput) ToBytes

func (output TXCurrrencyOutput) 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 TXCurrrencyOutput, 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 []TXCurrrencyOutput
}

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
	Time       int64
	Signature  []byte // one signature for full transaction
	ByPubKey   []byte
	Vin        []TXCurrencyInput
	Vout       []TXCurrrencyOutput
	SQLCommand SQLUpdate
	SQLBaseTX  []byte // ID of transaction where same row was affected last time
}

Transaction represents a Bitcoin transaction

func DeserializeTransaction

func DeserializeTransaction(txData []byte) (*Transaction, error)

Serialize Transaction

func NewCoinbaseTransaction

func NewCoinbaseTransaction(to, data string, coinstoadd float64) (*Transaction, error)

New "currency" Coin Base transaction. This transaction must be present in each new block

func NewSQLTransaction

func NewSQLTransaction(sql SQLUpdate, inputs []TXCurrencyInput, outputs []TXCurrrencyOutput) (*Transaction, error)

New "SQL" transaction.

func NewTransaction

func NewTransaction(inputs []TXCurrencyInput, outputs []TXCurrrencyOutput) (*Transaction, error)

New "currency" transaction.

func (*Transaction) CompleteTransaction

func (tx *Transaction) CompleteTransaction(signature []byte) error

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

func (Transaction) Copy

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

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

func (Transaction) CreatedByPubKeyHash

func (tx Transaction) CreatedByPubKeyHash(pubKeyHash []byte) bool

func (*Transaction) DeserializeTransaction

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

DeserializeTransaction deserializes a transaction

func (Transaction) GetID

func (tx Transaction) GetID() []byte

Return ID of transaction

func (Transaction) GetIDString

func (tx Transaction) GetIDString() string

func (Transaction) GetSQLBaseTX

func (tx Transaction) GetSQLBaseTX() []byte

returns base TX for this SQL update TX

func (Transaction) GetSQLQuery

func (tx Transaction) GetSQLQuery() string

returns SQL command as string

func (Transaction) GetTime

func (tx Transaction) GetTime() int64

func (Transaction) IsCoinbaseTransfer

func (tx Transaction) IsCoinbaseTransfer() bool

check if TX is coin base

func (Transaction) IsComplete

func (tx Transaction) IsComplete() bool

func (Transaction) IsCurrencyTransfer

func (tx Transaction) IsCurrencyTransfer() bool

Checks whether the transaction is currency transaction (sends money to somewhere)

func (Transaction) IsSQLCommand

func (tx Transaction) IsSQLCommand() bool

IsCoinbase checks whether the transaction is coinbase

func (Transaction) NeedsSignature

func (tx Transaction) NeedsSignature() bool

check if needs signatures. in case of coin base doesn't need it

func (*Transaction) PrepareSignData

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

prepare data to sign a transaction this return []bytes. it is bytes representation of a TX.

func (*Transaction) SetSQLPart

func (tx *Transaction) SetSQLPart(sql SQLUpdate)

func (*Transaction) SetSQLPreviousTX

func (tx *Transaction) SetSQLPreviousTX(baseTX []byte)

set ID of previous TX where SQL item was updated

func (Transaction) String

func (tx Transaction) String() string

String returns a human-readable representation of a 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) Verify

func (tx *Transaction) Verify(prevTXs map[int]*Transaction, coinstoadd float64) error

Verify verifies signatures of Transaction inputs And total amount of inputs and outputs TODO in future to replace coinstoadd with some Config structure where all external things for verify are included

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