Documentation
¶
Index ¶
- type Block
- func (b *Block) AddTransaction(tx *Transaction) error
- func (b *Block) GetBlockSize() uint64
- func (b *Block) GetHash() []byte
- func (b *Block) GetHashString() string
- func (b *Block) GetTransactionByHash(hash []byte) *Transaction
- func (b *Block) Sign(v *validator.Authority) error
- func (b *Block) Verify(v *validator.Authority) bool
- type Blockchain
- func (bc *Blockchain) AddBlock(block *Block) error
- func (bc *Blockchain) AddValidator(authority *validator.Authority)
- func (bc *Blockchain) DeployContract(code []byte, owner common.Address, name, version string) (*contracts.Contract, error)
- func (bc *Blockchain) ExecuteContract(address common.Address, input []byte) ([]byte, error)
- func (bc *Blockchain) GetActiveValidatorCount() int
- func (bc *Blockchain) GetBlock(hash []byte) *Block
- func (bc *Blockchain) GetBlockByHeight(height uint64) *Block
- func (bc *Blockchain) GetBlockCount() uint64
- func (bc *Blockchain) GetBlockchainInfo() map[string]interface{}
- func (bc *Blockchain) GetContract(address common.Address) (*contracts.Contract, error)
- func (bc *Blockchain) GetCurrentValidator() (*validator.Authority, error)
- func (bc *Blockchain) GetLatestBlock() *Block
- func (bc *Blockchain) GetValidatorCount() int
- func (bc *Blockchain) IsValid() bool
- func (bc *Blockchain) ListContracts() []*contracts.Contract
- func (bc *Blockchain) RemoveValidator(address string)
- func (bc *Blockchain) VerifyContract(address common.Address) error
- type ContractEvent
- type Event
- type EventEmitter
- type EventType
- type Header
- type Mempool
- func (mp *Mempool) AddTransaction(tx *Transaction) error
- func (mp *Mempool) Clear()
- func (mp *Mempool) GetBestTransactions(gasLimit uint64) []*Transaction
- func (mp *Mempool) GetPendingNonce(address string) uint64
- func (mp *Mempool) GetSize() uint64
- func (mp *Mempool) GetTransaction(hash []byte) *Transaction
- func (mp *Mempool) RemoveTransaction(hash []byte)
- type PriorityQueue
- type Transaction
- type TransactionPriority
- type TxStatus
- type WebSocketServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
Header *Header
Transactions []*Transaction
Signature []byte // Validator's signature of the block header
// contains filtered or unexported fields
}
Block represents a block in the blockchain
func NewBlock ¶
func NewBlock( height uint64, prevHash []byte, stateRoot []byte, gasLimit uint64, v *validator.Authority, ) (*Block, error)
NewBlock creates a new block
func (*Block) AddTransaction ¶
func (b *Block) AddTransaction(tx *Transaction) error
AddTransaction adds a transaction to the block
func (*Block) GetBlockSize ¶
GetBlockSize returns the approximate size of the block in bytes
func (*Block) GetHashString ¶
GetHashString returns the block hash as a hex string
func (*Block) GetTransactionByHash ¶
func (b *Block) GetTransactionByHash(hash []byte) *Transaction
GetTransactionByHash returns a transaction by its hash
type Blockchain ¶
type Blockchain struct {
Blocks []*Block
PendingBlock *Block
Validators map[string]*validator.Authority
CurrentIndex int
LastBlockTime time.Time
ContractManager *contracts.Manager
EventEmitter *EventEmitter
WebSocketServer *WebSocketServer
// contains filtered or unexported fields
}
Blockchain represents the entire chain of blocks
func NewBlockchain ¶
func NewBlockchain(v *validator.Authority) (*Blockchain, error)
NewBlockchain creates a new blockchain instance
func (*Blockchain) AddBlock ¶
func (bc *Blockchain) AddBlock(block *Block) error
AddBlock adds a new block to the chain
func (*Blockchain) AddValidator ¶
func (bc *Blockchain) AddValidator(authority *validator.Authority)
AddValidator adds a new validator to the blockchain
func (*Blockchain) DeployContract ¶
func (bc *Blockchain) DeployContract(code []byte, owner common.Address, name, version string) (*contracts.Contract, error)
DeployContract deploys a new smart contract
func (*Blockchain) ExecuteContract ¶
ExecuteContract executes a smart contract
func (*Blockchain) GetActiveValidatorCount ¶
func (bc *Blockchain) GetActiveValidatorCount() int
GetActiveValidatorCount aktif validator sayısını döndürür
func (*Blockchain) GetBlock ¶
func (bc *Blockchain) GetBlock(hash []byte) *Block
GetBlock returns a block by its hash
func (*Blockchain) GetBlockByHeight ¶
func (bc *Blockchain) GetBlockByHeight(height uint64) *Block
GetBlockByHeight returns a block by its height
func (*Blockchain) GetBlockCount ¶
func (bc *Blockchain) GetBlockCount() uint64
GetBlockCount toplam blok sayısını döndürür
func (*Blockchain) GetBlockchainInfo ¶
func (bc *Blockchain) GetBlockchainInfo() map[string]interface{}
GetBlockchainInfo zincir hakkında genel bilgileri döndürür
func (*Blockchain) GetContract ¶
GetContract returns a contract by address
func (*Blockchain) GetCurrentValidator ¶
func (bc *Blockchain) GetCurrentValidator() (*validator.Authority, error)
GetCurrentValidator returns the current validator in the rotation
func (*Blockchain) GetLatestBlock ¶
func (bc *Blockchain) GetLatestBlock() *Block
GetLatestBlock returns the latest block in the chain
func (*Blockchain) GetValidatorCount ¶
func (bc *Blockchain) GetValidatorCount() int
GetValidatorCount toplam validator sayısını döndürür
func (*Blockchain) IsValid ¶
func (bc *Blockchain) IsValid() bool
IsValid checks if the blockchain is valid
func (*Blockchain) ListContracts ¶
func (bc *Blockchain) ListContracts() []*contracts.Contract
ListContracts returns all contracts
func (*Blockchain) RemoveValidator ¶
func (bc *Blockchain) RemoveValidator(address string)
RemoveValidator removes a validator from the blockchain
func (*Blockchain) VerifyContract ¶
func (bc *Blockchain) VerifyContract(address common.Address) error
VerifyContract verifies a deployed contract
type ContractEvent ¶
type ContractEvent struct {
Address common.Address `json:"address"`
Name string `json:"name"`
Args map[string]interface{} `json:"args"`
BlockNumber uint64 `json:"blockNumber"`
TxHash common.Hash `json:"transactionHash"`
Timestamp int64 `json:"timestamp"`
}
ContractEvent represents a smart contract event
type Event ¶
type Event struct {
Type EventType `json:"type"`
Timestamp int64 `json:"timestamp"`
Data map[string]interface{} `json:"data"`
}
Event represents a blockchain event
type EventEmitter ¶
type EventEmitter struct {
// contains filtered or unexported fields
}
EventEmitter handles event emission and subscription
func NewEventEmitter ¶
func NewEventEmitter() *EventEmitter
NewEventEmitter creates a new event emitter
func (*EventEmitter) Emit ¶
func (e *EventEmitter) Emit(eventType EventType, data map[string]interface{})
Emit an event
func (*EventEmitter) EmitContractEvent ¶
func (e *EventEmitter) EmitContractEvent(event ContractEvent)
EmitContractEvent emits a contract-specific event
func (*EventEmitter) Subscribe ¶
func (e *EventEmitter) Subscribe(eventType EventType) chan Event
Subscribe to specific event type
func (*EventEmitter) Unsubscribe ¶
func (e *EventEmitter) Unsubscribe(eventType EventType, ch chan Event)
Unsubscribe from specific event type
type Header ¶
type Header struct {
Version uint32 // Protocol version
Timestamp time.Time // Block creation time
PrevHash []byte // Previous block hash
Height uint64 // Block height
StateRoot []byte // State trie root hash
TransactionRoot []byte // Transaction trie root hash
ReceiptRoot []byte // Receipt trie root hash
GasLimit uint64 // Block gas limit
GasUsed uint64 // Total gas used by transactions
ValidatorAddress string // Block producer address
}
Header represents the block header
type Mempool ¶
type Mempool struct {
// contains filtered or unexported fields
}
Mempool işlem havuzunu yönetir
func NewMempool ¶
NewMempool yeni bir işlem havuzu oluşturur
func (*Mempool) AddTransaction ¶
func (mp *Mempool) AddTransaction(tx *Transaction) error
AddTransaction işlemi havuza ekler
func (*Mempool) GetBestTransactions ¶
func (mp *Mempool) GetBestTransactions(gasLimit uint64) []*Transaction
GetBestTransactions en yüksek öncelikli işlemleri döndürür
func (*Mempool) GetPendingNonce ¶
GetPendingNonce bir adres için bekleyen en yüksek nonce değerini döndürür
func (*Mempool) GetTransaction ¶
func (mp *Mempool) GetTransaction(hash []byte) *Transaction
GetTransaction belirtilen hash'e sahip işlemi döndürür
func (*Mempool) RemoveTransaction ¶
RemoveTransaction işlemi havuzdan kaldırır
type PriorityQueue ¶
type PriorityQueue []*TransactionPriority
PriorityQueue işlem öncelik kuyruğu için heap implementasyonu
func (PriorityQueue) Len ¶
func (pq PriorityQueue) Len() int
func (PriorityQueue) Less ¶
func (pq PriorityQueue) Less(i, j int) bool
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() interface{}
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(x interface{})
func (PriorityQueue) Swap ¶
func (pq PriorityQueue) Swap(i, j int)
type Transaction ¶
type Transaction struct {
Hash []byte
From string
To string
Value *big.Int
Data []byte
GasPrice uint64
GasLimit uint64
GasUsed uint64
Nonce uint64
Signature []byte
Status TxStatus
}
Transaction represents a blockchain transaction
func (*Transaction) GetSize ¶
func (tx *Transaction) GetSize() uint64
GetSize işlemin yaklaşık boyutunu hesaplar
type TransactionPriority ¶
type TransactionPriority struct {
// contains filtered or unexported fields
}
TransactionPriority işlemlerin öncelik sırasını belirler
type WebSocketServer ¶
type WebSocketServer struct {
// contains filtered or unexported fields
}
WebSocketServer handles WebSocket connections
func NewWebSocketServer ¶
func NewWebSocketServer(bc *Blockchain) *WebSocketServer
NewWebSocketServer creates a new WebSocket server
func (*WebSocketServer) BroadcastToAll ¶
func (s *WebSocketServer) BroadcastToAll(event Event)
BroadcastToAll sends an event to all connected clients
func (*WebSocketServer) HandleWebSocket ¶
func (s *WebSocketServer) HandleWebSocket(w http.ResponseWriter, r *http.Request)
HandleWebSocket handles WebSocket connections