Automated maintenance update - Mo 30 Mär 2026 07:52:40 CEST
All checks were successful
CLI Tests / test-cli (push) Successful in 1m30s
Documentation Validation / validate-docs (push) Successful in 26s
Integration Tests / test-service-integration (push) Successful in 1m0s
Python Tests / test-python (push) Successful in 1m16s
Security Scanning / security-scan (push) Successful in 1m3s
All checks were successful
CLI Tests / test-cli (push) Successful in 1m30s
Documentation Validation / validate-docs (push) Successful in 26s
Integration Tests / test-service-integration (push) Successful in 1m0s
Python Tests / test-python (push) Successful in 1m16s
Security Scanning / security-scan (push) Successful in 1m3s
This commit is contained in:
59
apps/blockchain-node/scripts/load_genesis_fixed.py
Executable file
59
apps/blockchain-node/scripts/load_genesis_fixed.py
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Load genesis accounts into the blockchain database"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add the src directory to the path
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
|
||||
|
||||
from aitbc_chain.database import session_scope
|
||||
from aitbc_chain.models import Account
|
||||
from aitbc_chain.config import settings
|
||||
|
||||
def load_genesis_accounts(genesis_path: str = "data/devnet/genesis.json"):
|
||||
"""Load accounts from genesis file into database"""
|
||||
|
||||
# Read genesis file
|
||||
genesis_file = Path(genesis_path)
|
||||
if not genesis_file.exists():
|
||||
print(f"Error: Genesis file not found at {genesis_path}")
|
||||
return False
|
||||
|
||||
with open(genesis_file) as f:
|
||||
genesis = json.load(f)
|
||||
|
||||
chain_id = genesis.get("chain_id", settings.chain_id)
|
||||
|
||||
# Load accounts
|
||||
with session_scope() as session:
|
||||
for account_data in genesis.get("allocations", []):
|
||||
address = account_data["address"]
|
||||
balance = account_data["balance"]
|
||||
nonce = account_data.get("nonce", 0)
|
||||
|
||||
# Check if account already exists
|
||||
existing = session.query(Account).filter_by(chain_id=chain_id, address=address).first()
|
||||
if existing:
|
||||
existing.balance = balance
|
||||
existing.nonce = nonce
|
||||
print(f"Updated account {address}: balance={balance}")
|
||||
else:
|
||||
account = Account(chain_id=chain_id, address=address, balance=balance, nonce=nonce)
|
||||
session.add(account)
|
||||
print(f"Created account {address}: balance={balance}")
|
||||
|
||||
session.commit()
|
||||
|
||||
print("\\nGenesis accounts loaded successfully!")
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
genesis_path = sys.argv[1]
|
||||
else:
|
||||
genesis_path = "data/devnet/genesis.json"
|
||||
|
||||
success = load_genesis_accounts(genesis_path)
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in New Issue
Block a user