wakacoin

package
v0.0.0-...-f9c6845 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IsTest                   = false
	DefaultHubIsIP           = false
	DefaultHub               = "each1.net:1024"
	SetLocalhostStaticIPAddr = false
	LocalhostStaticIPAddr    = ""
	SetLocalhostDomainName   = false
	LocalhostDomainName      = ""
)
View Source
const (
	CommandLength uint8 = 14
)

Variables

View Source
var (
	MiningAddress string

	WebServerLanAddress string
)

Functions

func AddInUse

func AddInUse(utxoBucket []byte) (inUseID int)

func Base58Decode

func Base58Decode(input []byte) []byte

func Base58Encode

func Base58Encode(input []byte) []byte

func ByteToUint32

func ByteToUint32(b []byte) (num uint32)

func CheckErr

func CheckErr(err error)

func CliCheckErr

func CliCheckErr(err error)

func ConnectDefaultHub

func ConnectDefaultHub(db *bolt.DB)

func ConnectHubs

func ConnectHubs(db *bolt.DB)

func ContractChainBlockHashDecodeString

func ContractChainBlockHashDecodeString(contractChainBlockHashString string) (contractChainBlockHash [20]byte, err error)

func ExcludeNode

func ExcludeNode(addr string, db *bolt.DB)

func GetAddress

func GetAddress(pubKeyHash [20]byte) []byte

func GetBalance

func GetBalance(address, nodeID string, printDetail bool) (balance, balanceSpendable uint32)

func GetPrivateKey

func GetPrivateKey(pubKeyHash [20]byte, wallets *Wallets) (ecdsa.PrivateKey, error)

func GetUTXOBucketID

func GetUTXOBucketID(utxoBucket []byte) (utxoBucketID string)

func HasBeenRegisteredOnBlockchain

func HasBeenRegisteredOnBlockchain(nodeID string, wallet *Wallet) (register bool, err error)

func HashPubKey

func HashPubKey(pubKey []byte) [20]byte

func Int64ToByte

func Int64ToByte(num int64) []byte

func IsInUse

func IsInUse(utxoBucket []byte) (isInUse bool)

func NewMerkleNode

func NewMerkleNode(left, right [32]byte) [32]byte

func NewMerkleTree

func NewMerkleTree(data [][32]byte) [32]byte

func NodeIsOnBlacklist

func NodeIsOnBlacklist(addr string) (nodeIsOnBlacklist bool)

func PrintErr

func PrintErr(err interface{})

func PrintMessage

func PrintMessage(str string)

func PutOnBlacklist

func PutOnBlacklist(addr string)

func RemoteAddr

func RemoteAddr(version uint32, isStaticAddr bool, staticHost, port, remoteAddrHost string) (string, error)

func Reverse20ByteHashes

func Reverse20ByteHashes(data [][20]byte)

func ReverseBytes

func ReverseBytes(data []byte)

func ReverseHashes

func ReverseHashes(data [][32]byte)

func SendAdminEmail

func SendAdminEmail(message string)

func SendConfirmedBlockInfo

func SendConfirmedBlockInfo(addr string, bc *Blockchain)

func SendMiningJob

func SendMiningJob(addr string, prepareData []byte, difficulty uint8)

func SendTXIDs

func SendTXIDs(db *bolt.DB)

func StartMine

func StartMine(bc *Blockchain, batch uint32, maxNonce uint64, sleep uint8)

func StartServer

func StartServer(nodeID, minerAddress, from, to string, sendNewTx bool, amount uint32)

func Subsidy

func Subsidy(blockHeight uint32) uint32

func Uint32ToByte

func Uint32ToByte(num uint32) []byte

func Uint64ToByte

func Uint64ToByte(num uint64) []byte

func Uint8ToByte

func Uint8ToByte(num uint8) []byte

func ValidateAddrHost

func ValidateAddrHost(addr string) error

func ValidateAddress

func ValidateAddress(address string) bool

func ValidateBlockChain

func ValidateBlockChain(blockchain string) error

func VerifyBlockHeaderWithoutChain

func VerifyBlockHeaderWithoutChain(block *Block) (err error)

func VerifyBlockWithoutChain

func VerifyBlockWithoutChain(block *Block) error

func VerifyCoinbaseWithoutChain

func VerifyCoinbaseWithoutChain(coinbase *Transaction, txAmount int) error

func VerifyTransactionWithoutChain

func VerifyTransactionWithoutChain(tx *Transaction) (uint32, error)

func VerifyTransactionsWithoutChain

func VerifyTransactionsWithoutChain(txs []*Transaction) error

Types

type Block

type Block struct {
	Header       *BlockHeader
	Transactions []*Transaction
}

func DeserializeBlock

func DeserializeBlock(d []byte) *Block

func NewBlock

func NewBlock(prevBlock [32]byte, transactions []*Transaction, difficulty uint8, bc *Blockchain, batch uint32, maxNonce uint64, sleep uint8) (*Block, error)

func NewGenesisBlock

func NewGenesisBlock(coinbase *Transaction, bc *Blockchain) *Block

func (*Block) AddBlock

func (b *Block) AddBlock(db *bolt.DB)

func (*Block) GetHeight

func (b *Block) GetHeight() uint32

func (*Block) HashTransactions

func (b *Block) HashTransactions() [32]byte

func (*Block) Serialize

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

type BlockHeader

type BlockHeader struct {
	Version    uint32
	PrevBlock  [32]byte
	MerkleRoot [32]byte
	Timestamp  int64
	Difficulty uint8
	Nonce      uint64
}

func NewBlockHeader

func NewBlockHeader(prevBlock, merkleRoot [32]byte, difficulty uint8, bc *Blockchain, batch uint32, maxNonce uint64, sleep uint8) (*BlockHeader, error)

func (*BlockHeader) HashBlockHeader

func (bh *BlockHeader) HashBlockHeader() [32]byte

type Blockchain

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

func NewBlockchain

func NewBlockchain(nodeID string) *Blockchain

func (*Blockchain) AddLastBlock

func (bc *Blockchain) AddLastBlock(block *Block) error

func (*Blockchain) ChangeMainChain

func (bc *Blockchain) ChangeMainChain(bestHeight uint32, lastHash [32]byte)

func (*Blockchain) FindTXOutputPubKeyHash

func (bc *Blockchain) FindTXOutputPubKeyHash(blockHash, txid [32]byte, index int8) ([20]byte, error)

func (*Blockchain) GetBlock

func (bc *Blockchain) GetBlock(blockHash [32]byte) (*Block, error)

func (*Blockchain) GetBlockHashes

func (bc *Blockchain) GetBlockHashes() *[][32]byte

func (*Blockchain) GetValidDifficulty

func (bc *Blockchain) GetValidDifficulty(block *Block) uint8

func (*Blockchain) Iterator

func (bc *Blockchain) Iterator() *BlockchainIterator

func (*Blockchain) MineBlock

func (bc *Blockchain) MineBlock(transactions []*Transaction, batch uint32, maxNonce uint64, sleep uint8) (*Block, error)

func (*Blockchain) RebuildBlockHashesFromGenesisToTip

func (bc *Blockchain) RebuildBlockHashesFromGenesisToTip()

func (*Blockchain) SetDifficulty

func (bc *Blockchain) SetDifficulty(height uint32, prevBlock [32]byte) uint8

func (*Blockchain) Trim

func (bc *Blockchain) Trim()

func (*Blockchain) UpdateMainChain

func (bc *Blockchain) UpdateMainChain(blockHash [32]byte, block *Block)

func (*Blockchain) VerifyBlock

func (bc *Blockchain) VerifyBlock(block *Block, blockHashes *[][32]byte) error

func (*Blockchain) VerifyBlockHashCollision

func (bc *Blockchain) VerifyBlockHashCollision(blockHash [32]byte) error

func (*Blockchain) VerifyBlockHeader

func (bc *Blockchain) VerifyBlockHeader(block *Block) error

func (*Blockchain) VerifyCoinbase

func (bc *Blockchain) VerifyCoinbase(block *Block) error

func (*Blockchain) VerifyLog

func (bc *Blockchain) VerifyLog(blockHash [32]byte, isValid bool)

func (*Blockchain) VerifyProtect

func (bc *Blockchain) VerifyProtect() error

func (*Blockchain) VerifyTransaction

func (bc *Blockchain) VerifyTransaction(index int, block *Block, blockHashes *[][32]byte) error

func (*Blockchain) VerifyTransactions

func (bc *Blockchain) VerifyTransactions(block *Block, blockHashes *[][32]byte) error

type BlockchainIterator

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

func (*BlockchainIterator) Next

func (i *BlockchainIterator) Next() (block *Block)

type BlockchainIteratorTwo

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

func (*BlockchainIteratorTwo) NextIfBlockExists

func (i *BlockchainIteratorTwo) NextIfBlockExists() (findNonExistingBlock, findIllegalBlock bool, blockHash [32]byte, height uint32)

type CLI

type CLI struct{}

func (*CLI) Run

func (cli *CLI) Run()

type ContractBlock

type ContractBlock struct {
	Version   uint32
	PrevBlock [20]byte
	Height    uint32
	Timestamp int64
	FileName  []byte
	File      []byte
}

func DeserializeContractBlock

func DeserializeContractBlock(d []byte) *ContractBlock

func (*ContractBlock) HashBlock

func (b *ContractBlock) HashBlock() [20]byte

func (*ContractBlock) Serialize

func (b *ContractBlock) Serialize() []byte

type ContractChain

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

func NewContractChain

func NewContractChain(address string) *ContractChain

func (*ContractChain) Iterator

func (cc *ContractChain) Iterator() *ContractChainIterator

type ContractChainIterator

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

func (*ContractChainIterator) Next

func (i *ContractChainIterator) Next() (block *ContractBlock)

type ProofOfWork

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

func NewProofOfWork

func NewProofOfWork(bh *BlockHeader) *ProofOfWork

func (*ProofOfWork) Run

func (pow *ProofOfWork) Run(bc *Blockchain, batch uint32, maxNonce uint64, sleep uint8) (uint64, error)

func (*ProofOfWork) Validate

func (pow *ProofOfWork) Validate() bool

type SpendableOutput

type SpendableOutput struct {
	Block  [32]byte
	Txid   [32]byte
	Index  int8
	Value  uint32
	PubKey []byte
}

type SpendableOutputs

type SpendableOutputs struct {
	Outputs []*SpendableOutput
}

type SpendedOutput

type SpendedOutput struct {
	Block [32]byte
	Txid  [32]byte
	Index int8
}

type SpendedOutputs

type SpendedOutputs struct {
	Outputs []*SpendedOutput
}

type TXInput

type TXInput struct {
	Block     [32]byte
	Txid      [32]byte
	Index     int8
	Signature []byte
	PubKey    []byte
}

type TXOutput

type TXOutput struct {
	Value      uint32
	PubKeyHash [20]byte
}

func NewTXOutput

func NewTXOutput(value uint32, address []byte) TXOutput

func (*TXOutput) Lock

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

type Transaction

type Transaction struct {
	ID      [32]byte
	Version uint32
	Vin     []TXInput
	Vout    []TXOutput
}

func DeserializeTransaction

func DeserializeTransaction(data []byte) Transaction

func NewCoinbaseTX

func NewCoinbaseTX(to string, txAmount uint, blockHeight uint32) *Transaction

func NewUTXOTransaction

func NewUTXOTransaction(from, to string, amount uint32, bc *Blockchain) (tx *Transaction, err error)

func (*Transaction) AddNewTxToBucket

func (tnx *Transaction) AddNewTxToBucket(db *bolt.DB) error

func (*Transaction) Hash

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

func (*Transaction) IsCoinbase

func (tx *Transaction) IsCoinbase() bool

func (*Transaction) MarshalJSON

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

func (*Transaction) Serialize

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

func (*Transaction) Sign

func (tx *Transaction) Sign(wallets *Wallets, bc *Blockchain)

func (*Transaction) String

func (tx *Transaction) String() string

func (*Transaction) TrimmedCopy

func (tx *Transaction) TrimmedCopy() *Transaction

func (*Transaction) VerifySign

func (tx *Transaction) VerifySign(bc *Blockchain) bool

func (*Transaction) VerifySize

func (tx *Transaction) VerifySize() (uint32, error)

type UTXOSet

type UTXOSet struct {
	Blockchain *Blockchain
}

func (UTXOSet) Balance

func (u UTXOSet) Balance(pubKeyHash [20]byte, printDetail bool) (balance, balanceSpendable uint32)

func (UTXOSet) FindSpendableOutputs

func (u UTXOSet) FindSpendableOutputs(usableWallets *Wallets, amountAndFee uint32) (uint32, *ValidOutputs, error)

func (UTXOSet) GetAvailableUTXO

func (u UTXOSet) GetAvailableUTXO() (utxoBucket, contractBucket []byte)

func (UTXOSet) GetUTXOLastBlock

func (u UTXOSet) GetUTXOLastBlock(utxoBucket []byte) (utxoLastBlockHash [32]byte)

func (UTXOSet) GetUnAvailableUTXO

func (u UTXOSet) GetUnAvailableUTXO() (utxoBucket, contractBucket []byte)

func (UTXOSet) Rebuild

func (u UTXOSet) Rebuild(utxoBucket, contractBucket []byte) error

func (UTXOSet) Reindex

func (u UTXOSet) Reindex() error

func (UTXOSet) ResetUTXOLastBlock

func (u UTXOSet) ResetUTXOLastBlock(utxoBucket []byte)

func (UTXOSet) SetAvailable

func (u UTXOSet) SetAvailable(utxoBucket []byte, utxoLastBlockHash [32]byte)

func (UTXOSet) Update

func (u UTXOSet) Update(utxoBucket, contractBucket []byte, block *Block)

func (UTXOSet) UpdateLastBlock

func (u UTXOSet) UpdateLastBlock() error

type UTXOutput

type UTXOutput struct {
	Index      int8
	Value      uint32
	PubKeyHash [20]byte
	Height     uint32
}

type UTXOutputs

type UTXOutputs struct {
	Outputs []*UTXOutput
}

func DeserializeUTXOutputs

func DeserializeUTXOutputs(data []byte) UTXOutputs

func (*UTXOutputs) Serialize

func (outs *UTXOutputs) Serialize() []byte

type ValidOutput

type ValidOutput struct {
	Block  [32]byte
	Txid   [32]byte
	Index  int8
	PubKey []byte
}

type ValidOutputs

type ValidOutputs struct {
	Outputs []*ValidOutput
}

type Wallet

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

func NewWallet

func NewWallet() *Wallet

type Wallets

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

func NewWallets

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

func (*Wallets) CreateWallet

func (ws *Wallets) CreateWallet() string

func (*Wallets) GetAddresses

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

func (*Wallets) GetWallet

func (ws *Wallets) GetWallet(address string) (wallet *Wallet, err error)

func (*Wallets) LoadFromFile

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

func (Wallets) SaveToFile

func (ws Wallets) SaveToFile(nodeID string)

Jump to

Keyboard shortcuts

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