Documentation ¶
Index ¶
- Constants
- func BytesToBig(b []byte) *big.Int
- func PaddedBytes(x *big.Int, n int) []byte
- type Account
- type AccountNonce
- type Address
- type Block
- type BlockBody
- type BlockHeader
- type BlockNonce
- type Chain
- type Hash
- type InsufficientFundsError
- type Ledger
- type MissingBodyError
- type State
- type Transaction
- type TransactionBody
- type TxInput
- type TxOutput
Constants ¶
const ( HashLength = 32 AddressLength = 20 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Account ¶
type Account struct { Nonce AccountNonce Addr Address Balance *big.Int }
func GetAccount ¶
Gets account object from database using account address as key
func NewAccount ¶
func NewAccount() (*Account, *ecdsa.PrivateKey, error)
Returns an Account with a randomly generate private key/address
type AccountNonce ¶
type AccountNonce BlockNonce
type Address ¶
type Address [AddressLength]byte
func AddressFromPubKey ¶
Uses HASH160 (SHA256 + RIPEMD160) to generate the address from given public key Makes no assumption about whether this is a compressed or uncompressed public key
func BigToAddress ¶
func StringToAddress ¶
type Block ¶
type Block struct { Header *BlockHeader Body *BlockBody }
func GetHeadBlock ¶
Gets whole head block from database
func GetOrCreateGenesisBlock ¶
Gets and returns the genesis block if it exists in the database Otherwise, creates the genesis block, commits it to the database and returns it
func (*Block) AddTransaction ¶
func (b *Block) AddTransaction(t *Transaction) error
Adds transaction to block body
type BlockHeader ¶
func GetBlockHeader ¶
Gets block header from database in rlp format, constructs object and returns
func GetHeadBlockHeader ¶
func GetHeadBlockHeader(db meddb.Database) (*BlockHeader, error)
Gets head block header from database in rlp format, constructs objects and returns
func (*BlockHeader) Hash ¶
func (h *BlockHeader) Hash() Hash
Returns Sha256 hash of block header in rlp format
type BlockNonce ¶
type BlockNonce [8]byte
func (BlockNonce) Uint64 ¶
func (nonce BlockNonce) Uint64() uint64
type Chain ¶
func NewChain ¶
Builds and returns a chain from the existing database If the chain does not yet exist, creates a chain containing only genesis
func (*Chain) AddTransaction ¶
func (c *Chain) AddTransaction(t *Transaction) (*Transaction, error)
Adds transaction to head block in chain, gives reward to owner TODO: Basically redo when we have tables done
type InsufficientFundsError ¶
Sum of transaction inputs is less than sum of transaction outputs
func (*InsufficientFundsError) Error ¶
func (e *InsufficientFundsError) Error() string
type MissingBodyError ¶
type MissingBodyError struct {
B *Block
}
Block is missing its body
func (*MissingBodyError) Error ¶
func (e *MissingBodyError) Error() string
type Transaction ¶
func SignTx ¶
func SignTx(t *Transaction, priv *ecdsa.PrivateKey) (*Transaction, error)
Signs the transaction body and writes the corresponding values to V, R, S
func (*Transaction) From ¶
func (t *Transaction) From() (Address, error)
Returns the From address for the transaction derived from the V, R, S signature
func (*Transaction) SigHash ¶
func (t *Transaction) SigHash() Hash
Returns the hash to be used for signing the transaction
type TransactionBody ¶
type TxOutput ¶
func GetUnspentTxOutput ¶
Gets a transaction output from the unspent pool
func (*TxOutput) DeleteUnspent ¶
Removes a transaction output from the unspent pool