core

package
v0.0.0-...-900be86 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const Version = byte(0x00)

Version Glockchain version

View Source
const WalletVersion = byte(0x00)

WalletVersion Wallet Version

Variables

This section is empty.

Functions

func AddressToPubKeyHash

func AddressToPubKeyHash(address []byte) []byte

AddressToPubKeyHash is convert address to pubkeyhash

func HashPubKey

func HashPubKey(pubKey []byte) []byte

HashPubKey is hashing pubkey

func ValidateAddress

func ValidateAddress(address []byte) bool

ValidateAddress is validation address

Types

type Block

type Block struct {
	Index        int64
	PreviousHash []byte
	Timestamp    int64
	Hash         []byte
	Nonce        int
	Transactions []*Transaction
	TXHash       []byte
}

Block is transaction block

func DeserializeBlock

func DeserializeBlock(d []byte) *Block

DeserializeBlock is deserializing block

func NewBlock

func NewBlock(transactions []*Transaction, prevBlockHash []byte) *Block

NewBlock is block constructor transactions is the transaction you want to add to the block

func NewGenesisBlock

func NewGenesisBlock(tx *Transaction) *Block

NewGenesisBlock is created genesis block tx is the coinbase transaction

func (*Block) HashTransactions

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

HashTransactions is hasing transacitons from block

func (*Block) Serialize

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

Serialize block

func (*Block) String

func (block *Block) String() string

String is convert block to string

func (*Block) ToHash

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

ToHash converts block to hash

type Blockchain

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

Blockchain is chain with block tip is last block hash

func CreateBlockchain

func CreateBlockchain(address []byte) *Blockchain

CreateBlockchain is create blockchain if blockchain exists, error it

func GetBlockchain

func GetBlockchain() (*Blockchain, []byte)

GetBlockchain is Getting exist blockchain

func (*Blockchain) AddBlock

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

AddBlock is adding block into blockchain

func (*Blockchain) Iterator

func (bc *Blockchain) Iterator() *BlockchainIterator

Iterator is created blockchain iterator

type BlockchainIterator

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

BlockchainIterator is a blockchain iterator

func (*BlockchainIterator) Next

func (bci *BlockchainIterator) Next() *Block

Next is moved index for next

type CLI

type CLI struct {
	App *urfaveCli.App
	Bc  *Blockchain
}

CLI cli

func NewCLI

func NewCLI() *CLI

NewCLI CLI constructor

type MerkleNode

type MerkleNode struct {
	Left  *MerkleNode
	Right *MerkleNode
	Data  []byte
}

MerkleNode MerkleTree Node

func NewMerkleNode

func NewMerkleNode(left, right *MerkleNode, data []byte) *MerkleNode

NewMerkleNode MerkleNode constructor

type MerkleTree

type MerkleTree struct {
	RootNode *MerkleNode
}

MerkleTree Transaction hash tree

func NewMerkleTree

func NewMerkleTree(data [][]byte) *MerkleTree

NewMerkleTree MerkleTree constructor

type ProofOfWork

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

ProofOfWork mining action with ProofOfWork

func NewProofOfWork

func NewProofOfWork(b *Block) *ProofOfWork

NewProofOfWork ProofOfWork constructor

func (*ProofOfWork) Run

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

Run Execute ProofOfWork

type TXInput

type TXInput struct {
	PrevTXHash  []byte
	PrevTXIndex int
	Signature   []byte
	PubKey      []byte
}

TXInput Transaction Input

func NewTXInput

func NewTXInput(prevTX Transaction, prevTXIndex int) *TXInput

NewTXInput TXInput constructor

func (*TXInput) Hash

func (txi *TXInput) Hash() []byte

Hash hash Transaction input

type TXOutput

type TXOutput struct {
	Value      int
	PubKeyHash []byte
}

TXOutput Transaction output

func NewTXOutput

func NewTXOutput(value int, address []byte) *TXOutput

NewTXOutput TXOutput constructor

func (*TXOutput) Hash

func (txo *TXOutput) Hash() []byte

Hash Hash transaction output

func (*TXOutput) IsLockedWithKey

func (txo *TXOutput) IsLockedWithKey(pubKeyHash []byte) bool

IsLockedWithKey Is Locked with args keyhash?

func (*TXOutput) Lock

func (txo *TXOutput) Lock(address []byte)

Lock TransactionOutput Locked

type Transaction

type Transaction struct {
	Version   byte
	ID        []byte
	BlockHash []byte
	Input     []TXInput
	Output    []TXOutput
}

Transaction TX Data

func DeserializeTransaction

func DeserializeTransaction(data []byte) Transaction

DeserializeTransaction deserialize tx

func NewCoinbaseTX

func NewCoinbaseTX(value int, to []byte) *Transaction

NewCoinbaseTX Create New Coinbase TX

func NewTransaction

func NewTransaction(wallet *Wallet, to []byte, amount int) *Transaction

NewTransaction create New TX

func (*Transaction) Bytes

func (tx *Transaction) Bytes() []byte

Bytes Get Transaction Bytes

func (*Transaction) Hash

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

Hash Hash to transaction

func (*Transaction) Serialize

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

Serialize serialize tx

func (*Transaction) Sign

func (tx *Transaction) Sign(privateKey ecdsa.PrivateKey)

Sign sign TX

func (*Transaction) String

func (tx *Transaction) String() string

func (*Transaction) TrimmedCopy

func (tx *Transaction) TrimmedCopy() Transaction

TrimmedCopy copy TX (not in TXI pubkey and Signature)

func (*Transaction) Verify

func (tx *Transaction) Verify() bool

Verify verify TX

type TransactionPool

type TransactionPool struct {
	Pool []*Transaction
}

TransactionPool Not take up transaction into block

func NewTransactionPool

func NewTransactionPool() *TransactionPool

NewTransactionPool TransactionPool constructor

func (*TransactionPool) AddTransaction

func (txp *TransactionPool) AddTransaction(transaction *Transaction)

AddTransaction Pool Transaciton

func (*TransactionPool) ClearTransactionPool

func (txp *TransactionPool) ClearTransactionPool()

ClearTransactionPool clear pool

type UTXO

type UTXO struct {
	TX    *Transaction
	Index int
}

UTXO UTXO Data (tryal)

func DeserializeUtxo

func DeserializeUtxo(data []byte) UTXO

DeserializeUtxo deserialize UTXO

func (*UTXO) Key

func (utxo *UTXO) Key() []byte

Key is Gneerate UTXO Key

func (*UTXO) Serialize

func (utxo *UTXO) Serialize() []byte

Serialize UTXO

func (*UTXO) String

func (utxo *UTXO) String() string

String is UTXO to string

type UTXOPool

type UTXOPool struct {
	Pool map[string]*UTXO
}

UTXOPool is singleton

func GetUTXOPool

func GetUTXOPool() *UTXOPool

GetUTXOPool is create singleton instance

func (*UTXOPool) AddUTXO

func (up *UTXOPool) AddUTXO(t *Transaction)

AddUTXO is create UTXO and Pooling UTXP

func (*UTXOPool) FindSpendableOutputs

func (up *UTXOPool) FindSpendableOutputs(pubKeyHash []byte, amount int) (int, map[string]UTXO)

FindSpendableOutputs is finc tx from pool with pubkeyhash ando amount

func (*UTXOPool) FindUTXOs

func (up *UTXOPool) FindUTXOs(pubKeyHash []byte) (int, map[string]UTXO)

FindUTXOs is find tx from pool with pubkeyhash

func (*UTXOPool) String

func (up *UTXOPool) String() string

String is convert UTXOPool to string

type Wallet

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

Wallet is Glockchain Wallet private and publick keyValue pair

func NewWallet

func NewWallet() *Wallet

NewWallet is Create new wallet

func (Wallet) GetAddress

func (w Wallet) GetAddress() []byte

GetAddress is create address from pub/private key

type Wallets

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

Wallets is Wallet collection

func NewWallets

func NewWallets() *Wallets

NewWallets is Create Wallets

func (*Wallets) CreateWallet

func (ws *Wallets) CreateWallet() string

CreateWallet is created wallet and added Wallets collection

func (*Wallets) GetAddresses

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

GetAddresses is calling wallet function with Wallets collection

func (Wallets) GetWallet

func (ws Wallets) GetWallet(address []byte) Wallet

GetWallet is Wallet from Wallets collection

func (*Wallets) LoadFromFile

func (ws *Wallets) LoadFromFile() error

LoadFromFile is Loading wallets from file

func (Wallets) SaveToFile

func (ws Wallets) SaveToFile()

SaveToFile is Save wallets data to file

Jump to

Keyboard shortcuts

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