Documentation ¶
Index ¶
- func ReverseBlocksShortSlice(ss []*BlockShort)
- func ReverseBlocksSlice(ss []*Block)
- 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 TXInput
- type TXOutput
- type TXOutputIndependent
- type TXOutputIndependentList
- type TXOutputs
- type Transaction
- func (tx *Transaction) Copy() (Transaction, error)
- func (tx *Transaction) DeserializeTransaction(data []byte) error
- func (tx *Transaction) Hash() ([]byte, error)
- func (tx Transaction) IsCoinbase() bool
- func (tx *Transaction) MakeCoinbaseTX(to, data string) error
- func (tx *Transaction) PrepareSignData(prevTXs map[int]*Transaction) ([][]byte, error)
- func (tx Transaction) Serialize() ([]byte, error)
- func (tx *Transaction) SetSignatures(signatures [][]byte) error
- func (tx *Transaction) SignData(privKey ecdsa.PrivateKey, PubKey []byte, DataToSign [][]byte) error
- func (tx Transaction) String() string
- func (tx *Transaction) TimeNow()
- func (tx Transaction) ToBytes() ([]byte, error)
- func (tx *Transaction) TrimmedCopy() Transaction
- func (tx *Transaction) Verify(prevTXs map[int]*Transaction) error
- type Transactions
- type TransactionsHistory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReverseBlocksShortSlice ¶
func ReverseBlocksShortSlice(ss []*BlockShort)
Reverce list of blocks for short info
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) 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 (*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
type TXOutput ¶
TXOutput represents a transaction output
func NewTXOutput ¶
NewTXOutput create a new TXOutput
func (*TXOutput) IsLockedWithKey ¶
IsLockedWithKey checks if the output can be used by the owner of the pubkey
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 ¶
DeserializeOutputs deserializes TXOutputs
type Transaction ¶
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)