core

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2018 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSignedData

func GetSignedData(privKey ecdsa.PrivateKey, dataToSign *TxPreSignature) []byte

func HashPubKey

func HashPubKey(pubKey []byte) []byte

HashPubKey hashes public key

func ValidateAddress

func ValidateAddress(address string) bool

ValidateAddress check if address if valid

Types

type Block

type Block struct {
	Timestamp int64

	Transactions []*Tx

	PrevBlockHash []byte
	Hash          []byte
	Nonce         int64
	Height        int
}

func DeserializeBlock

func DeserializeBlock(d []byte) *Block

func NewBlock

func NewBlock(transactions []*Tx, prevBlockHash []byte, height int) *Block

func NewGenesisBlock

func NewGenesisBlock(coinbase *Tx) *Block

func (*Block) HashTransactions

func (block *Block) HashTransactions() []byte

func (*Block) Serialize

func (block *Block) Serialize() []byte

type Blockchain

type Blockchain struct {
	// contains filtered or unexported fields
}

func CreateBlockchain

func CreateBlockchain(address, nodeId string) *Blockchain

func NewBlockchain

func NewBlockchain(nodeID string) *Blockchain

func (*Blockchain) AddBlock

func (bc *Blockchain) AddBlock(block *Block)

func (*Blockchain) FindTransaction

func (bc *Blockchain) FindTransaction(ID []byte) (Tx, error)

FindTransaction finds a transaction by its ID

func (*Blockchain) FindUTXO

func (bc *Blockchain) FindUTXO() map[string]TxOutputs

FindUTXO finds all unspent transaction outputs and returns transactions with spent outputs removed

func (*Blockchain) Iterator

func (bc *Blockchain) Iterator() *BlockchainIterator

Iterator returns a BlockchainIterat

type BlockchainIterator

type BlockchainIterator struct {
	// contains filtered or unexported fields
}

BlockchainIterator is used to iterate over blockchain blocks

func (*BlockchainIterator) Next

func (i *BlockchainIterator) Next() *Block

Next returns next block starting from the tip

type CLI

type CLI struct {
	// contains filtered or unexported fields
}

func NewCLI

func NewCLI(bc *Blockchain) *CLI

func (*CLI) Run

func (cli *CLI) Run()

type ProofOfWork

type ProofOfWork struct {
	// contains filtered or unexported fields
}

func NewProofOfWork

func NewProofOfWork(b *Block) *ProofOfWork

func (*ProofOfWork) PrepareData

func (pow *ProofOfWork) PrepareData(nonce int64) []byte

func (*ProofOfWork) Run

func (pow *ProofOfWork) Run() (int64, []byte)

func (*ProofOfWork) Validate

func (pow *ProofOfWork) Validate() bool

type Transaction

type Transaction struct {
	ID     []byte
	Input  []TxInput
	Output []TxOutput
}

func CoinbaseTx

func CoinbaseTx(to string, data string) *Transaction

type Tx

type Tx struct {
	Id      []byte
	Inputs  []TxInput
	Outputs []TxOutput
}

func DeserializeTx

func DeserializeTx(data []byte) Tx

func NewCoinbaseTx

func NewCoinbaseTx(to, data string) *Tx

func NewUTXOTransaction

func NewUTXOTransaction(wallet *Wallet, to string, amount int, utxoSet *UTXOSet) *Tx

func (*Tx) Clone

func (tx *Tx) Clone() Tx

func (*Tx) Hash

func (tx *Tx) Hash() []byte

func (*Tx) IsCoinbase

func (tx *Tx) IsCoinbase() bool

func (*Tx) Serialize

func (tx *Tx) Serialize() []byte

func (*Tx) Sign

func (tx *Tx) Sign(privKey ecdsa.PrivateKey, prevTxMap map[string]Tx)

func (*Tx) String

func (tx *Tx) String() string

func (*Tx) Verify

func (tx *Tx) Verify(prevTxMap map[string]Tx) bool

type TxInput

type TxInput struct {
	Id          []byte
	OutputIndex int
	Signature   []byte
	PubKey      []byte
}

type TxOutput

type TxOutput struct {
	Value      int
	PubKeyHash []byte
}

func NewTxOutput

func NewTxOutput(value int, address string) *TxOutput

func (*TxOutput) AssignPubKeyHash

func (out *TxOutput) AssignPubKeyHash(address []byte)

func (*TxOutput) VerifyTxOutput

func (out *TxOutput) VerifyTxOutput(pubKeyHash []byte) bool

type TxOutputs

type TxOutputs struct {
	Outputs []TxOutput
}

TXOutputs collects TXOutput

type TxPreSignature

type TxPreSignature struct {
	TxId          []byte
	TxOutputIndex int
	PubKey        []byte
}

func NewPreSignature

func NewPreSignature(currentTx *Tx, prevTxMap map[string]Tx, currentInput *TxInput) TxPreSignature

type UTXOSet

type UTXOSet struct {
	Blockchain *Blockchain
}

type Wallet

type Wallet struct {
	PrivateKey ecdsa.PrivateKey
	PublicKey  []byte
}

Wallet stores private and public keys

func NewWallet

func NewWallet() *Wallet

NewWallet creates and returns a Wallet

func (Wallet) GetAddress

func (w Wallet) GetAddress() []byte

GetAddress returns wallet address

type Wallets

type Wallets struct {
	Wallets map[string]*Wallet
}

Wallets stores a collection of wallets

func NewWallets

func NewWallets(nodeID string) (*Wallets, error)

NewWallets creates Wallets and fills it from a file if it exists

func (*Wallets) CreateWallet

func (ws *Wallets) CreateWallet() string

CreateWallet adds a Wallet to Wallets

func (*Wallets) GetAddresses

func (ws *Wallets) GetAddresses() []string

GetAddresses returns an array of addresses stored in the wallet file

func (Wallets) GetWallet

func (ws Wallets) GetWallet(address string) Wallet

GetWallet returns a Wallet by its address

func (*Wallets) LoadFromFile

func (ws *Wallets) LoadFromFile(nodeID string) error

LoadFromFile loads wallets from the file

func (Wallets) SaveToFile

func (ws Wallets) SaveToFile(nodeID string)

SaveToFile saves wallets to a file

Jump to

Keyboard shortcuts

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