core

package
v0.0.0-...-bff8ceb Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AddressChecksumLen = 4
	Version            = byte(0x00)
)

Variables

This section is empty.

Functions

func Checksum

func Checksum(pubKeyHash []byte) []byte

func DBExists

func DBExists(dbFile string) bool

func HashPubKey

func HashPubKey(pub []byte) ([]byte, error)

func IntToBytes

func IntToBytes(num int64) ([]byte, error)

func ValidateAddress

func ValidateAddress(address string) bool

Types

type Block

type Block struct {
	Timestamp     int64          `json:"timestamp"`
	Nonce         uint64         `json:"nonce"`
	PrevBlockHash []byte         `json:"prev_block_hash"`
	Hash          []byte         `json:"hash"`
	Transactions  []*Transaction `json:"transactions"`
}

func DeserializeBlock

func DeserializeBlock(encData []byte) (Block, error)

func NewBlock

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

func NewGenesisBlock

func NewGenesisBlock(cbtx Transaction) (Block, error)

func (*Block) HashTXs

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

func (Block) Serialize

func (b Block) Serialize() ([]byte, error)

type Blockchain

type Blockchain struct {
	Tip []byte
	DB  *bolt.DB
}

func CreateBlockchain

func CreateBlockchain(address, dbFile string) (Blockchain, error)

func NewBlockchain

func NewBlockchain(dbFile string) (Blockchain, error)

func (*Blockchain) AddToPool

func (bc *Blockchain) AddToPool(tx Transaction) error

func (*Blockchain) FindTXByID

func (bc *Blockchain) FindTXByID(ID []byte) (Transaction, error)

func (*Blockchain) FindUTXOsWithIDX

func (chain *Blockchain) FindUTXOsWithIDX() (map[string]map[int]TXOutput, error)

scan the entire blockchain and find all UTXOs

func (*Blockchain) FindUXTOs

func (chain *Blockchain) FindUXTOs() (map[string]TXOutputs, error)

func (*Blockchain) GetBlockHeight

func (bc *Blockchain) GetBlockHeight() (uint64, error)

func (*Blockchain) Iterator

func (bc *Blockchain) Iterator() *Iterator

func (*Blockchain) MineBlock

func (bc *Blockchain) MineBlock(txs []*Transaction) (Block, error)

func (*Blockchain) SignTX

func (bc *Blockchain) SignTX(tx Transaction, privKey ecdsa.PrivateKey) error

func (*Blockchain) VerifyTX

func (bc *Blockchain) VerifyTX(tx Transaction) (bool, error)

type Iterator

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

func (*Iterator) Next

func (i *Iterator) Next() (*Block, error)

type MerkleNode

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

type MerkleTree

type MerkleTree struct {
	Root *MerkleNode
}

func NewMerkleTree

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

type PoW

type PoW struct {
	Block  *Block
	Target *big.Int
}

func NewPoW

func NewPoW(b *Block) *PoW

func (*PoW) PrepareData

func (pow *PoW) PrepareData(nonce uint64) ([]byte, error)

func (*PoW) Run

func (pow *PoW) Run() ([]byte, uint64, error)

func (*PoW) Validate

func (pow *PoW) Validate() (bool, error)

type TXInput

type TXInput struct {
	TxID      []byte `json:"txid"`
	Out       int    `json:"out"`
	PublicKey []byte `json:"public_key"`
	Signature []byte `json:"signature"`
}

func (TXInput) UsesKey

func (in TXInput) UsesKey(pubKeyHash []byte) (bool, error)

check whether the address initiated the transaction

type TXOutput

type TXOutput struct {
	Value      uint   `json:"value"`
	PubkeyHash []byte `json:"public_key_hash"`
}

func NewTXOutput

func NewTXOutput(value uint, address string) TXOutput

create a new TXOutput

func (TXOutput) IsLockedWith

func (out TXOutput) IsLockedWith(pubKeyHash []byte) bool

check if the output can be unlocked

func (*TXOutput) Lock

func (out *TXOutput) Lock(address string) error

sign the output

type TXOutputs

type TXOutputs struct {
	Outputs []TXOutput
}

func DeserializeOutputs

func DeserializeOutputs(encData []byte) (TXOutputs, error)

func (TXOutputs) Serialize

func (outs TXOutputs) Serialize() ([]byte, error)

type Transaction

type Transaction struct {
	ID      []byte     `json:"id"`
	Inputs  []TXInput  `json:"inputs"`
	Outputs []TXOutput `json:"outputs"`
	Msg     string     `json:"msg"`
}

func DeserializeTX

func DeserializeTX(data []byte) (Transaction, error)

func NewCBTX

func NewCBTX(address, data string) (Transaction, error)

func NewUTXOTransaction

func NewUTXOTransaction(receiver, sender string, senderPubKey []byte, amount uint, UTXOSet *UTXOSet, msg string) (Transaction, error)

func (Transaction) Hash

func (tx Transaction) Hash() ([]byte, error)

func (Transaction) IsCoinbase

func (tx Transaction) IsCoinbase() bool

func (Transaction) Serialize

func (tx Transaction) Serialize() ([]byte, error)

func (*Transaction) Sign

func (tx *Transaction) Sign(privKey ecdsa.PrivateKey, prevTXs map[string]Transaction) error

func (Transaction) TrimmedCopy

func (tx Transaction) TrimmedCopy() Transaction

func (*Transaction) Verify

func (tx *Transaction) Verify(prevTXs map[string]Transaction) (bool, error)

type UTXOSet

type UTXOSet struct {
	Blockchain *Blockchain
}

func (*UTXOSet) FindSpendableOutputs

func (u *UTXOSet) FindSpendableOutputs(pubkeyHash []byte, amount uint) (uint, map[string][]int, error)

func (*UTXOSet) FindUTXOs

func (u *UTXOSet) FindUTXOs(pubkeyHash []byte) ([]TXOutput, error)

func (UTXOSet) Reindex

func (u UTXOSet) Reindex() error

func (UTXOSet) Update

func (u UTXOSet) Update(block *Block) error

type Wallet

type Wallet struct {
	PrivKey ecdsa.PrivateKey
	PubKey  []byte
}

func NewWallet

func NewWallet() (Wallet, error)

func (*Wallet) DecodePrivKeys

func (w *Wallet) DecodePrivKeys(encPrivKey string) error

func (*Wallet) DecodePubKeys

func (w *Wallet) DecodePubKeys(encPubKey string) error

func (Wallet) EncodePrivKeys

func (w Wallet) EncodePrivKeys() (string, error)

func (Wallet) EncodePubKeys

func (w Wallet) EncodePubKeys() string

func (Wallet) GetAddress

func (w Wallet) GetAddress() (string, error)

Jump to

Keyboard shortcuts

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