Documentation
¶
Index ¶
- Variables
- func CloseNATS()
- func DecodeJSON(data []byte, v interface{}) error
- func EncodeJSON(v interface{}) []byte
- func EncodeTx(tx Transaction) ([]byte, error)
- func GenerateKeyPair() (*ecdsa.PrivateKey, error)
- func GetLatestBlockHash() string
- func GetLatestBlockHeight() int
- func InitBlockchain(chainID string, mp MempoolInterface)
- func SetLatestBlock(block Block)
- func SetupNATS(natsURL string)
- func ValidateTx(tx Transaction) error
- type Agent
- type AgentPersonality
- type Block
- type Blockchain
- func (bc *Blockchain) AddBlock(newBlock Block) error
- func (bc *Blockchain) CreateBlock() (*Block, error)
- func (bc *Blockchain) ProcessTransaction(tx Transaction, mp MempoolInterface) error
- func (bc *Blockchain) RegisterNode(addr string, node *p2p.Node)
- func (bc *Blockchain) ValidateBlock(block Block) bool
- type ChainInfo
- type Database
- type MempoolInterface
- type NATSBroker
- type StateRoot
- type Transaction
- type TxChecker
- type ValidationResult
Constants ¶
This section is empty.
Variables ¶
var NatsBrokerInstance *nats.Conn
Functions ¶
func DecodeJSON ¶
func EncodeJSON ¶
func EncodeJSON(v interface{}) []byte
func EncodeTx ¶
func EncodeTx(tx Transaction) ([]byte, error)
EncodeTx converts a transaction to bytes
func GenerateKeyPair ¶
func GenerateKeyPair() (*ecdsa.PrivateKey, error)
GenerateKeyPair creates a new key pair for signing transactions
func GetLatestBlockHash ¶
func GetLatestBlockHash() string
func GetLatestBlockHeight ¶
func GetLatestBlockHeight() int
func InitBlockchain ¶
func InitBlockchain(chainID string, mp MempoolInterface)
Initialize blockchain
func SetLatestBlock ¶
func SetLatestBlock(block Block)
func ValidateTx ¶
func ValidateTx(tx Transaction) error
ValidateTx performs basic validation of a transaction
Types ¶
type Agent ¶
type Agent struct { ID string `json:"id"` Name string `json:"name"` Role string `json:"role"` // "producer" or "validator" ValidatorAddress string `json:"validator_address,omitempty"` IsValidator bool `json:"is_validator"` Metadata map[string]interface{} `json:"metadata"` // Flexible metadata for external agents }
Agent represents a generic AI-powered entity in ChaosChain (Producer or Validator)
type AgentPersonality ¶
type AgentPersonality struct { Name string `json:"name"` Traits []string `json:"traits"` Style string `json:"style"` MemePreferences []string `json:"meme_preferences"` }
AgentPersonality defines an AI validator's personality and decision-making style
type Block ¶
type Block struct { Height int `json:"height"` PrevHash string `json:"prev_hash"` Txs []Transaction `json:"transactions"` Timestamp int64 `json:"timestamp"` Signature string `json:"signature"` Proposer string `json:"proposer"` ChainID string `json:"chain_id"` }
Block represents a basic block structure
func GetBlockByHeight ¶
GetBlockByHeight retrieves a block at a specific height
func (*Block) VerifyBlock ¶
VerifyBlock verifies the authenticity of a block
type Blockchain ¶
type Blockchain struct { Blocks []Block Mempool MempoolInterface ChainID string Nodes map[string]*p2p.Node NodesMu sync.RWMutex }
Blockchain represents a sequence of validated blocks
func GetBlockchain ¶
func GetBlockchain() *Blockchain
GetBlockchain returns the default blockchain instance
func NewBlockchain ¶
func NewBlockchain(chainID string, mp MempoolInterface) *Blockchain
NewBlockchain initializes a blockchain with a genesis block
func (*Blockchain) AddBlock ¶
func (bc *Blockchain) AddBlock(newBlock Block) error
AddBlock appends a new block to the chain
func (*Blockchain) CreateBlock ¶
func (bc *Blockchain) CreateBlock() (*Block, error)
CreateBlock creates a new block proposal (doesn't add to chain)
func (*Blockchain) ProcessTransaction ¶
func (bc *Blockchain) ProcessTransaction(tx Transaction, mp MempoolInterface) error
ProcessTransaction validates and adds a transaction to the mempool
func (*Blockchain) RegisterNode ¶
func (bc *Blockchain) RegisterNode(addr string, node *p2p.Node)
RegisterNode adds a node to the chain's network
func (*Blockchain) ValidateBlock ¶
func (bc *Blockchain) ValidateBlock(block Block) bool
ValidateBlock checks whether a given block follows chain rules
type ChainInfo ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database represents a simple in-memory database using string buffer
type MempoolInterface ¶
type MempoolInterface interface { AddTransaction(tx interface{}) bool GetPendingTransactions() []Transaction RemoveTransaction(txID string) CleanupExpiredTransactions() Size() int }
MempoolInterface defines the required functionality for a mempool
type NATSBroker ¶
type NATSBroker struct {
Conn *nats.Conn
}
NATSBroker encapsulates a NATS connection.
func NewNATSBroker ¶
func NewNATSBroker(url string) (*NATSBroker, error)
NewNATSBroker creates a new NATSBroker connected to the provided URL.
func (*NATSBroker) Publish ¶
func (b *NATSBroker) Publish(subject string, data []byte) error
Publish sends data on the provided subject.
func (*NATSBroker) Subscribe ¶
func (b *NATSBroker) Subscribe(subject string, cb nats.MsgHandler) error
Subscribe registers a callback for a specific subject.
type StateRoot ¶
type StateRoot struct { StateID string `json:"state_id"` Changes map[string]string `json:"changes"` // Stores arbitrary AI-generated changes }
StateRoot represents the blockchain's state at a given block height
type Transaction ¶
type Transaction struct { Type string `json:"type" amino:"bytes"` // Transaction type (e.g., "register_validator") From string `json:"from" amino:"bytes"` To string `json:"to" amino:"bytes"` Amount float64 `json:"amount" amino:"fixed64"` Fee uint64 `json:"fee" amino:"varint"` Content string `json:"content" amino:"bytes"` Timestamp int64 `json:"timestamp" amino:"varint"` Signature string `json:"signature" amino:"bytes"` PublicKey string `json:"publicKey" amino:"bytes"` ChainID string `json:"chainID" amino:"bytes"` Hash []byte `json:"hash" amino:"bytes"` // Transaction hash Data []byte `json:"data" amino:"bytes"` }
Transaction represents a basic transaction structure
func DecodeTx ¶
func DecodeTx(data []byte) (Transaction, error)
DecodeTx converts bytes to a transaction
func (*Transaction) GetHash ¶
func (tx *Transaction) GetHash() []byte
func (*Transaction) Marshal ¶
func (tx *Transaction) Marshal() ([]byte, error)
func (*Transaction) SignTransaction ¶
func (tx *Transaction) SignTransaction(privateKey *ecdsa.PrivateKey) error
SignTransaction signs a transaction with the given private key
func (*Transaction) VerifyTransaction ¶
func (tx *Transaction) VerifyTransaction(from string) bool
VerifyTransaction verifies the transaction signature
type TxChecker ¶
type TxChecker struct {
// contains filtered or unexported fields
}
TxChecker implements mempool.TxChecker for CometBFT mempool
func NewTxChecker ¶
func NewTxChecker(app abci.Application) *TxChecker