blockchain

package
v0.0.0-...-ad293f4 Latest Latest
Warning

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

Go to latest
Published: May 3, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const COINBASE_AMOUNT = 25
View Source
const (
	CONN_TYPE = "tcp"
)

Variables

This section is empty.

Functions

func HashMatchesDifficulty

func HashMatchesDifficulty(hash []byte, difficulty int) bool

Types

type Block

type Block struct {
	Height        int           `json:"height"`
	Hash          []byte        `json:"hash"`
	Transactions  []Transaction `json:"transactions"`
	PreviousBlock []byte        `json:"previous_block"`
	Difficulty    int           `json:"difficulty"`
	Nonce         int32         `json:"nonce"`
}

func GenerateGenesisBlock

func GenerateGenesisBlock(publicKey ed25519.PublicKey,
	privateKey ed25519.PrivateKey,
	difficulty int) (Block, error)

func (*Block) GetBase58Hash

func (b *Block) GetBase58Hash() (string, error)

func (*Block) GetCBOR

func (b *Block) GetCBOR() ([]byte, error)

func (*Block) GetHash

func (b *Block) GetHash() ([]byte, error)

type Input

type Input struct {
	Signature       []byte `json:"signature"`
	TransactionHash []byte `json:"transaction_hash"`
	OutputID        int    `json:"output_id"`
}

type Output

type Output struct {
	PublicKey ed25519.PublicKey `json:"public_key"`
	Amount    int               `json:"amount"`
}

func (*Output) GetCBOR

func (o *Output) GetCBOR() ([]byte, error)

type Peer

type Peer struct {
	Port  string
	Host  string
	Store Store
}

func (*Peer) CheckHeartBeat

func (p *Peer) CheckHeartBeat()

func (*Peer) DiscoverPeers

func (p *Peer) DiscoverPeers(peer string) error

func (*Peer) Discovery

func (p *Peer) Discovery() error

func (*Peer) Download

func (p *Peer) Download() ([][]Block, error)

func (*Peer) DownloadChain

func (p *Peer) DownloadChain(peer string) ([]Block, error)

func (*Peer) GetChain

func (p *Peer) GetChain() ([]byte, error)

func (*Peer) GetPeers

func (p *Peer) GetPeers() ([]byte, error)

func (*Peer) GossipBlock

func (p *Peer) GossipBlock(block Block)

func (*Peer) GossipTransaction

func (p *Peer) GossipTransaction(transaction Transaction)

func (*Peer) Handle

func (p *Peer) Handle(conn net.Conn)

func (*Peer) Ping

func (p *Peer) Ping(peer string) error

func (*Peer) Pong

func (p *Peer) Pong() []byte

func (*Peer) RegisterDefaultPeers

func (p *Peer) RegisterDefaultPeers() error

func (*Peer) RegisterPeer

func (p *Peer) RegisterPeer(peer string) []byte

func (*Peer) SendPayload

func (p *Peer) SendPayload(peer string, header []byte, payload []byte) error

func (*Peer) SendTransaction

func (p *Peer) SendTransaction(peer string, transaction Transaction) error

func (*Peer) Start

func (p *Peer) Start()

type Store

type Store struct {
	DB   *bolt.DB
	Peer *Peer
}

func (*Store) AddBlock

func (s *Store) AddBlock(block Block) error

func (*Store) AddPeer

func (s *Store) AddPeer(peer string) error

func (*Store) AddTransaction

func (s *Store) AddTransaction(transaction Transaction) error

func (*Store) Delete

func (s *Store) Delete(bucket []byte, key []byte) error

func (*Store) DeletePeer

func (s *Store) DeletePeer(peer string) error

func (*Store) EvaluateChains

func (s *Store) EvaluateChains(chains [][]Block) ([]Block, error)

func (*Store) Get

func (s *Store) Get(bucket []byte, key []byte) ([]byte, error)

func (*Store) GetChain

func (s *Store) GetChain() ([]Block, error)

func (*Store) GetPeers

func (s *Store) GetPeers() ([]string, error)

func (*Store) GetTransaction

func (s *Store) GetTransaction(hash []byte, mempool bool) (Transaction, error)

func (*Store) GetTransactions

func (s *Store) GetTransactions() ([]Transaction, error)

func (*Store) Open

func (s *Store) Open(location string, peer *Peer) error

func (*Store) Put

func (s *Store) Put(bucket []byte, key []byte, value []byte) error

func (*Store) StoreGenesisBlock

func (s *Store) StoreGenesisBlock(difficulty int) (Block, error)

func (*Store) VerifyTransaction

func (s *Store) VerifyTransaction(transaction Transaction, index int) (bool, error)

type Transaction

type Transaction struct {
	Hash    []byte   `json:"hash"`
	Inputs  []Input  `json:"inputs"`
	Outputs []Output `json:"outputs"`
}

func GenerateCoinbase

func GenerateCoinbase(publicKey ed25519.PublicKey,
	privateKey ed25519.PrivateKey, amount int) (Transaction,
	error)

func (*Transaction) GetBase58Hash

func (t *Transaction) GetBase58Hash() (string, error)

func (*Transaction) GetCBOR

func (t *Transaction) GetCBOR() ([]byte, error)

func (*Transaction) GetHash

func (t *Transaction) GetHash() ([]byte, error)

func (*Transaction) Sign

func (t *Transaction) Sign(privateKey ed25519.PrivateKey, index int) error

func (*Transaction) Verify

func (t *Transaction) Verify(publicKey ed25519.PublicKey, index int) (bool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL