Documentation ¶
Index ¶
- func CheckTXOutputValueToAddress(tx *Transaction, PubKeyHash []byte, amount float64) error
- func CheckTXOutputsAreOnlyToGivenAddresses(tx *Transaction, PubKeyHashes [][]byte) error
- func ReverseBlocksShortSlice(ss []*BlockShort)
- func ReverseBlocksSlice(ss []*Block)
- func SerializeTransaction(tx *Transaction) ([]byte, error)
- type Block
- func (b *Block) Copy() *Block
- func (b *Block) DeserializeBlock(d []byte) error
- func (b *Block) GetShortCopy() *BlockShort
- func (b *Block) GetSimpler() *BlockSimpler
- func (b *Block) HashTransactions() ([]byte, error)
- func (b *Block) PrepareNewBlock(transactions []Transaction, prevBlockHash []byte, height int) error
- func (b *Block) Serialize() ([]byte, error)
- type BlockShort
- type BlockSimpler
- type ConsensusInfo
- type SQLUpdate
- type TXCurrencyInput
- type TXCurrrencyOutput
- type TXOutputIndependent
- type TXOutputIndependentList
- type TXOutputs
- type Transaction
- func DeserializeTransaction(txData []byte) (*Transaction, error)
- func NewCoinbaseTransaction(to, data string, coinstoadd float64) (*Transaction, error)
- func NewSQLTransaction(sql SQLUpdate, inputs []TXCurrencyInput, outputs []TXCurrrencyOutput) (*Transaction, error)
- func NewTransaction(inputs []TXCurrencyInput, outputs []TXCurrrencyOutput) (*Transaction, error)
- func (tx *Transaction) CompleteTransaction(signature []byte) error
- func (tx Transaction) Copy() (*Transaction, error)
- func (tx Transaction) CreatedByPubKeyHash(pubKeyHash []byte) bool
- func (tx *Transaction) DeserializeTransaction(data []byte) error
- func (tx Transaction) GetID() []byte
- func (tx Transaction) GetIDString() string
- func (tx Transaction) GetSQLBaseTX() []byte
- func (tx Transaction) GetSQLQuery() string
- func (tx Transaction) GetTime() int64
- func (tx Transaction) IsCoinbaseTransfer() bool
- func (tx Transaction) IsComplete() bool
- func (tx Transaction) IsCurrencyTransfer() bool
- func (tx Transaction) IsSQLCommand() bool
- func (tx Transaction) NeedsSignature() bool
- func (tx *Transaction) PrepareSignData(pubKey []byte, prevTXs map[int]*Transaction) ([]byte, error)
- func (tx *Transaction) SetSQLPart(sql SQLUpdate)
- func (tx *Transaction) SetSQLPreviousTX(baseTX []byte)
- func (tx Transaction) String() string
- func (tx Transaction) ToBytes() ([]byte, error)
- func (tx *Transaction) Verify(prevTXs map[int]*Transaction, coinstoadd float64) error
- type Transactions
- type TransactionsHistory
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 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 ¶
Make Block object from bytes
func (*Block) DeserializeBlock ¶
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 ¶
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
type BlockShort ¶
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
type TXCurrencyInput ¶
TXInput represents a transaction input
func (TXCurrencyInput) String ¶
func (input TXCurrencyInput) String() string
func (TXCurrencyInput) ToBytes ¶
func (input TXCurrencyInput) ToBytes() ([]byte, error)
type TXCurrrencyOutput ¶
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 ¶
DeserializeOutputs deserializes 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) 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)