Files
aitbc/apps/blockchain-node/create_genesis.py
aitbc d26e6d3772
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 22s
Blockchain Synchronization Verification / sync-verification (push) Successful in 3s
CLI Tests / test-cli (push) Failing after 13s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Failing after 3s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 3s
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been skipped
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Failing after 3s
Cross-Chain Functionality Tests / aggregate-results (push) Has been skipped
Cross-Node Transaction Testing / transaction-test (push) Successful in 2s
Deploy to Testnet / deploy-testnet (push) Successful in 1m34s
Documentation Validation / validate-docs (push) Failing after 10s
Documentation Validation / validate-policies-strict (push) Successful in 3s
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Node Failover Simulation / failover-test (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Integration Tests / test-service-integration (push) Successful in 2m42s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 3s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 5s
P2P Network Verification / p2p-verification (push) Successful in 3s
Package Tests / Python package - aitbc-agent-sdk (push) Failing after 33s
Package Tests / Python package - aitbc-core (push) Successful in 17s
Package Tests / Python package - aitbc-crypto (push) Successful in 11s
Security Scanning / security-scan (push) Has been cancelled
Package Tests / Python package - aitbc-sdk (push) Successful in 13s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 9s
Package Tests / JavaScript package - aitbc-token (push) Successful in 17s
Staking Tests / test-staking-service (push) Failing after 6s
Staking Tests / test-staking-integration (push) Has been skipped
Staking Tests / test-staking-contract (push) Has been skipped
Staking Tests / run-staking-test-runner (push) Has been skipped
fix: replace datetime.UTC with timezone.utc for Python 3.12+ compatibility
2026-05-09 12:03:26 +02:00

55 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Simple script to create genesis block
"""
import sys
sys.path.insert(0, 'src')
from aitbc_chain.database import session_scope, init_db
from aitbc_chain.models import Block
from datetime import datetime, timezone
import hashlib
def compute_block_hash(height: int, parent_hash: str, timestamp: datetime) -> str:
"""Compute block hash"""
data = f"{height}{parent_hash}{timestamp}".encode()
return hashlib.sha256(data).hexdigest()
def create_genesis():
"""Create the genesis block"""
print("Creating genesis block...")
# Initialize database
init_db()
# Check if genesis already exists
with session_scope() as session:
existing = session.exec(select(Block).order_by(Block.height.desc()).limit(1)).first()
if existing:
print(f"Genesis block already exists: #{existing.height}")
return
# Create genesis block
timestamp = datetime.now(timezone.utc)
genesis_hash = compute_block_hash(0, "0x00", timestamp)
genesis = Block(
height=0,
hash=genesis_hash,
parent_hash="0x00",
proposer="ait-devnet-proposer",
timestamp=timestamp,
tx_count=0,
state_root=None,
)
session.add(genesis)
session.commit()
print(f"Genesis block created: #{genesis.height}")
print(f"Hash: {genesis.hash}")
print(f"Proposer: {genesis.proposer}")
print(f"Timestamp: {genesis.timestamp}")
if __name__ == "__main__":
from sqlmodel import select
create_genesis()