blockchain

package
v0.0.0-...-d6a16c6 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MiniCoin  = 1
	DecaCoin  = 1_0
	HectoCoin = 1_00
	KiloCoin  = 1_000
	MegaCoin  = 1_000_000
	GigaCoin  = 1_000_000_000
	TeraCoin  = 1_000_000_000_000
)
View Source
const MINING_REWARD = HectoCoin
View Source
const MiningRewardUser = "MINING_REWARD"

Variables

View Source
var HASH_START = "c0ffee"

Functions

func HashInput

func HashInput(input string) string

func IsValidHash

func IsValidHash(hash string) bool

Types

type Block

type Block struct {
	// These should not be hashed
	Index uint
	Hash  string

	// These should be included in the hash
	Transactions        []SignedTransaction
	HashOfPreviousBlock string
	Timestamp           time.Time
	Nonce               uint
}

func CreateGenesisBlock

func CreateGenesisBlock() Block

func CreateNewBlock

func CreateNewBlock(blockChain *BlockChain, transactions []SignedTransaction) Block

func (*Block) ComputeBlock

func (b *Block) ComputeBlock() error

func (Block) GetHashableString

func (b Block) GetHashableString(nonce uint) string

func (*Block) IsValid

func (b *Block) IsValid() bool

type BlockChain

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

func CreateNewBlockChain

func CreateNewBlockChain(user *Wallet) (BlockChain, error)

func (*BlockChain) AppendBlockAfterPoW

func (b *BlockChain) AppendBlockAfterPoW(block Block, miner *Wallet) error

func (*BlockChain) UpdateLedgerWithBlock

func (b *BlockChain) UpdateLedgerWithBlock(block *Block) error

func (BlockChain) ValidateChain

func (b BlockChain) ValidateChain() error

type Ledger

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

func CreateNewLedger

func CreateNewLedger() Ledger

func (*Ledger) AddTokensTo

func (l *Ledger) AddTokensTo(user string, amount uint)

func (Ledger) GetTokenTotalFrom

func (l Ledger) GetTokenTotalFrom(user string) (uint, error)

func (Ledger) IsValidTransaction

func (l Ledger) IsValidTransaction(transaction SignedTransaction) bool

func (*Ledger) ProcessTransaction

func (l *Ledger) ProcessTransaction(transaction SignedTransaction) error

func (*Ledger) RemoveTokensFrom

func (l *Ledger) RemoveTokensFrom(user string, amount uint) error

type SignedTransaction

type SignedTransaction struct {
	Signature []byte
	Transaction
}

func CreateMiningReward

func CreateMiningReward(to *Wallet) SignedTransaction

func CreateTransaction

func CreateTransaction(from *Wallet, to string, amount uint, timestamp time.Time) SignedTransaction

func (SignedTransaction) IsVerified

func (st SignedTransaction) IsVerified() bool

type Transaction

type Transaction struct {
	From      string
	To        string
	Amount    uint
	Timestamp time.Time
}

func (Transaction) Hash

func (t Transaction) Hash() []byte

func (Transaction) SignTransaction

func (t Transaction) SignTransaction(wallet *Wallet) SignedTransaction

func (Transaction) String

func (t Transaction) String() string

type Wallet

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

func GenerateWallet

func GenerateWallet() (*Wallet, error)

func (*Wallet) GetPublicAddress

func (w *Wallet) GetPublicAddress() string

Jump to

Keyboard shortcuts

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