Documentation ¶
Index ¶
- Constants
- func GenerateMerkleProof(transactions []*Transaction, index int) ([][]byte, error)
- func HashData(data []byte) []byte
- func HashTransaction(tx *Transaction) []byte
- func VerifyTransaction(rootHash []byte, tx *Transaction, proof [][]byte) bool
- type AddTransactionResult
- type Block
- type BlockChain
- func (bc *BlockChain) AddBlockReward() bool
- func (bc *BlockChain) AddTransaction(id [32]byte, sender string, recipient string, value float32, ...) (bool, AddTransactionResult)
- func (bc *BlockChain) AddTransactionToPool(t *Transaction) bool
- func (bc *BlockChain) Airdrop(address string)
- func (bc *BlockChain) CopyTransactionPool() []*Transaction
- func (bc *BlockChain) CreateBlock(nonce int, previousHash [32]byte) *Block
- func (bc *BlockChain) GetBlockByHeight(height int) (*Block, error)
- func (bc *BlockChain) GetTransactionsByWalletAddress(walletAddress string) []*TransactionBlockHeight
- func (bc *BlockChain) GetWalletBalanceByAddress(address string) float32
- func (bc *BlockChain) LasBlock() *Block
- func (bc *BlockChain) MarshalJSON() ([]byte, error)
- func (bc *BlockChain) Mining() bool
- func (bc *BlockChain) Print()
- func (bc *BlockChain) ProofOfWork() int
- func (bc *BlockChain) ValidProof(nonce int, previousHash [32]byte, transactions []*Transaction, difficulty int) bool
- func (bc *BlockChain) VerifyTransactionSignature(senderPublicKey *ecdsa.PublicKey, s *utils.Signature, t *Transaction) bool
- type Node
- type Transaction
- type TransactionBlockHeight
- type TransactionPool
- type TransactionPoolStatus
- type TransactionType
- type WalletTransactionIndex
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 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) MarshalJSON ¶
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 ¶
func BuildMerkleTree ¶
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
}
Click to show internal directories.
Click to hide internal directories.