blockchain

package
v0.0.0-...-5d48b45 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MINING_DIFICULTY = 4
	MINING_SENDER    = "BLOCKCHAIN REWARD SYSTEM"
	MINING_REWARD    = 1.0
	AIRDROP_SENDER   = "BLOCKCHAIN AIRDROP SYSTEM"
	AIRDROP_AMOUNT   = 1000
)

Variables

This section is empty.

Functions

func GenerateMerkleProof

func GenerateMerkleProof(transactions []*Transaction, index int) ([][]byte, error)

func HashData

func HashData(data []byte) []byte

func HashTransaction

func HashTransaction(tx *Transaction) []byte

func VerifyTransaction

func VerifyTransaction(rootHash []byte, tx *Transaction, proof [][]byte) bool

Types

type AddTransactionResult

type AddTransactionResult int
const (
	SUCCESS AddTransactionResult = iota
	FAILED_INSUFFICIENT_BALANCE
	FAILED_INVALID_SIGNATURE
)

func (AddTransactionResult) String

func (atr AddTransactionResult) String() string

type Block

type Block struct {
	BlockHeight  int32
	Timestamp    int64
	Nonce        int
	PreviousHash [32]byte
	Transactions []*Transaction
	MerkleRoot   []byte
}

func NewBlock

func NewBlock(nonce int, previousHash [32]byte, transactions []*Transaction, block []*Block) *Block

func (*Block) GetTransactionByOrderNumber

func (b *Block) GetTransactionByOrderNumber(orderNumber int) *Transaction

func (*Block) Hash

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

func (*Block) MarshalJSON

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

func (*Block) Print

func (b *Block) Print()

type BlockChain

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

func NewBlockchain

func NewBlockchain(blockchainAddress string, port uint16) *BlockChain

func (*BlockChain) AddBlockReward

func (bc *BlockChain) AddBlockReward() bool

func (*BlockChain) AddTransaction

func (bc *BlockChain) AddTransaction(id [32]byte, sender string, recipient string, value float32, senderPublicKey *ecdsa.PublicKey, s *utils.Signature, transactionType TransactionType, timestamp int64) (bool, AddTransactionResult)

func (*BlockChain) AddTransactionToPool

func (bc *BlockChain) AddTransactionToPool(t *Transaction) bool

func (*BlockChain) Airdrop

func (bc *BlockChain) Airdrop(address string)

func (*BlockChain) CopyTransactionPool

func (bc *BlockChain) CopyTransactionPool() []*Transaction

func (*BlockChain) CreateBlock

func (bc *BlockChain) CreateBlock(nonce int, previousHash [32]byte) *Block

func (*BlockChain) GetBlockByHeight

func (bc *BlockChain) GetBlockByHeight(height int) (*Block, error)

func (*BlockChain) GetTransactionsByWalletAddress

func (bc *BlockChain) GetTransactionsByWalletAddress(walletAddress string) []*TransactionBlockHeight

func (*BlockChain) GetWalletBalanceByAddress

func (bc *BlockChain) GetWalletBalanceByAddress(address string) float32

func (*BlockChain) LasBlock

func (bc *BlockChain) LasBlock() *Block

func (*BlockChain) MarshalJSON

func (bc *BlockChain) MarshalJSON() ([]byte, error)

func (*BlockChain) Mining

func (bc *BlockChain) Mining() bool

func (*BlockChain) Print

func (bc *BlockChain) Print()

func (*BlockChain) ProofOfWork

func (bc *BlockChain) ProofOfWork() int

func (*BlockChain) ValidProof

func (bc *BlockChain) ValidProof(nonce int, previousHash [32]byte, transactions []*Transaction, difficulty int) bool

func (*BlockChain) VerifyTransactionSignature

func (bc *BlockChain) VerifyTransactionSignature(senderPublicKey *ecdsa.PublicKey, s *utils.Signature, t *Transaction) bool

type Node

type Node struct {
	Left  *Node
	Right *Node
	Hash  []byte
}

func BuildMerkleTree

func BuildMerkleTree(leaves []*Node) *Node

func CreateLeafNodes

func CreateLeafNodes(transactions []*Transaction) []*Node

type Transaction

type Transaction struct {
	Id               [32]byte
	Timestamp        int64
	SenderAddress    string
	RecipientAddress string
	Value            float32
	Signature        *utils.Signature
	TransactionType  TransactionType
}

func NewSystemTransaction

func NewSystemTransaction(sender string, recipient string, value float32, transactionType TransactionType) *Transaction

func NewTransaction

func NewTransaction(id [32]byte, sender string, recipient string, value float32, signature *utils.Signature, transactionType TransactionType, timestamp int64) *Transaction

func (*Transaction) MarshalJSON

func (t *Transaction) MarshalJSON() ([]byte, error)

func (*Transaction) Print

func (t *Transaction) Print()

type TransactionBlockHeight

type TransactionBlockHeight struct {
	BlockHeight      int          `json:"block_height"`
	TransactionIndex int          `json:"transaction_index"`
	Transaction      *Transaction `json:"transaction"`
}

type TransactionPool

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

type TransactionPoolStatus

type TransactionPoolStatus int
const (
	POOL_PENDING TransactionPoolStatus = iota
	POOL_ACCEPTED
	POOL_PROVING
	POOL_REJECTED
)

type TransactionType

type TransactionType int
const (
	TRANSFER TransactionType = iota
	BLOCK_REWARD
	SYSTEM_AIRDROP
)

func (TransactionType) String

func (tt TransactionType) String() string

type WalletTransactionIndex

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

Jump to

Keyboard shortcuts

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