Documentation ¶
Index ¶
Constants ¶
const (
CoinbaseTransactionAmount = 10
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { Address ed25519.PublicKey `json:"address"` Nonce uint `json:"nonce"` Balance uint `json:"balance"` }
Account holds coins and an incrementing nonce
type Accounts ¶
type Accounts struct {
// contains filtered or unexported fields
}
Accounts represents all the accounts within the blockchain
func AccountsFromBlockchain ¶
AccountsFromBlockchain generates the current account states from the blockchain
func (*Accounts) ApplyTransaction ¶
func (a *Accounts) ApplyTransaction(transaction Transaction) error
ApplyTransaction applies the transaction if it's valid
func (*Accounts) ListAccounts ¶
ListAccounts returns all known accounts
type Block ¶
type Block struct { Number int `json:"number"` Time time.Time `json:"time"` Transactions []Transaction `json:"transactions"` Nonce int `json:"nonce"` PreviousHash []byte `json:"previousHash"` Hash []byte `json:"hash"` }
Block is an individual block in the blockchain
func GenesisBlock ¶
func GenesisBlock() *Block
GenesisBlock returns the fixed first block in the blockchain
func NewBlock ¶
func NewBlock(number int, previousHash []byte, transactions []Transaction, nonce int) *Block
NewBlock creates a new block
func (*Block) ComputeHash ¶
ComputeHash computes the hash for the block
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
Blockchain represents a full blockchain
func NewBlockchain ¶
func NewBlockchain(keyPair *keys.KeyPair) *Blockchain
NewBlockchain returns a new blockchain with a genesis block
func (*Blockchain) AddTransaction ¶
func (b *Blockchain) AddTransaction(transaction Transaction) error
AddTransaction adds transaction to the pool of available transactions to include in next block
func (*Blockchain) LastBlock ¶
func (b *Blockchain) LastBlock() *Block
LastBlock returns the last block in the blockchain
func (*Blockchain) MineBlock ¶
func (b *Blockchain) MineBlock() Block
MineBlock mines a new valid block with transactions from the mempool
func (*Blockchain) SubmitExternalBlock ¶
func (b *Blockchain) SubmitExternalBlock(block *Block)
SubmitExternalBlock sends an externally received block to the blockchain
type ProofOfWorkRequest ¶
type ProofOfWorkRequest struct {
// contains filtered or unexported fields
}
ProofOfWorkRequest is a request to mine a new block
type Transaction ¶
type Transaction struct { Sender []byte `json:"sender"` Receiver []byte `json:"receiver"` Amount uint `json:"amount"` Nonce uint `json:"nonce"` Time time.Time `json:"time"` Signature []byte `json:"signature"` }
Transaction represents an individual transaction
func CoinbaseTransactionTo ¶
func CoinbaseTransactionTo(receiver ed25519.PublicKey) Transaction
CoinbaseTransaction contructs a coinbase transaction
func NewTransaction ¶
func NewTransaction(sender ed25519.PublicKey, receiver ed25519.PublicKey, amount uint, nonce uint) *Transaction
NewTransaction returns a new unsigned transaction
func (*Transaction) Bytes ¶
func (t *Transaction) Bytes() ([]byte, error)
Bytes returns the transaction as bytes
func (*Transaction) IsCoinbase ¶
func (t *Transaction) IsCoinbase() bool
IsCoinBase tells whether the transaction is a coinbase transaction
func (*Transaction) Sign ¶
func (t *Transaction) Sign(privateKey ed25519.PrivateKey) ([]byte, error)
Sign signs the transaction using the given key and returns the signature
func (Transaction) String ¶
func (t Transaction) String() string
String returns the string representation of a transaction
func (*Transaction) ValidSignature ¶
func (t *Transaction) ValidSignature() bool
ValidSignature indicates whether the transaction signature is valid