blockchain

package
v0.0.0-...-c374b59 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectFee

func CollectFee(txs *[]Transaction) float64

func GetChecksum

func GetChecksum(in []byte) []byte

func HashPublicKey

func HashPublicKey(publicKey []byte) []byte

Types

type Block

type Block struct {
	ID           uint64        `json:"id"`
	Transactions []Transaction `json:"transactions"`
	Hash         string        `json:"hash"`
	PrevHash     string        `json:"prev_hash"`
	Timestamp    int64         `json:"timestamp"`
	Miner        string        `json:"miner"`
	Reward       float64       `json:"reward"`
	Fee          float64       `json:"fee"`
	Nonce        uint64        `json:"nonce"`
}

func NewBlock

func NewBlock(id uint64, txs *[]Transaction, ph string, r float64, miner string) *Block

func (*Block) GetHash

func (b *Block) GetHash() string

func (*Block) Mine

func (b *Block) Mine(d int, txs *[]Transaction)

type Blockchain

type Blockchain struct {
	Blocks      []Block       `json:"blocks"`
	Pending_txs []Transaction `json:"pending_txs"`
}

func InitBlockchain

func InitBlockchain() *Blockchain

func LoadBlockchain

func LoadBlockchain() *Blockchain

func (*Blockchain) AddTransaction

func (bc *Blockchain) AddTransaction(tx *Transaction)

func (*Blockchain) GetBalance

func (bc *Blockchain) GetBalance(address string) float64

func (*Blockchain) NewBlock

func (bc *Blockchain) NewBlock(miner string)

func (*Blockchain) NewTransaction

func (bc *Blockchain) NewTransaction(pk *rsa.PrivateKey, from string, to string, amount float64) Transaction

func (*Blockchain) ReplaceBlockchain

func (bc *Blockchain) ReplaceBlockchain(blocks []Block)

func (*Blockchain) ValidateChain

func (bc *Blockchain) ValidateChain() error

type Transaction

type Transaction struct {
	Hash   string  `json:"hash"`
	From   string  `json:"from"`
	To     string  `json:"to"`
	Amount float64 `json:"amount"`
	Fee    float64 `json:"fee"`
	Sign   string  `json:"sign"`
}

func NewTransaction

func NewTransaction(privateKey *rsa.PrivateKey, from string, to string, amount float64) *Transaction

func (*Transaction) VerifyTransaction

func (tx *Transaction) VerifyTransaction(pub *rsa.PublicKey, sign string, checksum string) error

type Wallet

type Wallet struct {
	PublicKey  *rsa.PublicKey  `json:"public_key"`
	PrivateKey *rsa.PrivateKey `json:"private_key"`
}

func LoadWallet

func LoadWallet() Wallet

func NewWallet

func NewWallet() Wallet

func (*Wallet) GetAddress

func (w *Wallet) GetAddress() string

Jump to

Keyboard shortcuts

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