-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_continuous_quantum_blockchain.py
More file actions
165 lines (135 loc) Β· 5.84 KB
/
run_continuous_quantum_blockchain.py
File metadata and controls
165 lines (135 loc) Β· 5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""
Continuous Quantum Blockchain with Auto-Generated Transactions
Runs indefinitely, automatically creating and mining transactions on quantum computers
"""
from quantum_blockchain_service import QuantumBlockchainService
import time
import random
from datetime import datetime
# Sample wallet addresses for realistic transactions
WALLETS = [
'0xAlice_Quantum',
'0xBob_Photonic',
'0xCarol_LUXBIN',
'0xDave_Hermetic',
'0xEve_Mirror',
'0xFrank_Diamond',
'0xGrace_NV_Center',
'0xHank_Entangled'
]
# Transaction types
TX_TYPES = [
'LUXBIN transfer',
'Quantum swap',
'Photonic payment',
'Hermetic mirror',
'Diamond storage',
'NV center activation'
]
def generate_random_transaction():
"""Generate a random realistic transaction"""
from_wallet = random.choice(WALLETS)
to_wallet = random.choice([w for w in WALLETS if w != from_wallet])
amount = round(random.uniform(0.1, 1000.0), 2)
tx_type = random.choice(TX_TYPES)
return {
'from': from_wallet,
'to': to_wallet,
'amount': amount,
'token': 'LUXBIN',
'type': tx_type,
'timestamp': datetime.now().isoformat(),
'data': f'{tx_type} - Quantum validated transaction'
}
def main():
print("="*70)
print("π LUXBIN CONTINUOUS QUANTUM BLOCKCHAIN")
print("="*70)
print("\nThis will:")
print("1. Generate random transactions automatically")
print("2. Mine blocks on IBM quantum computers")
print("3. Update dashboard data in real-time")
print("4. Run indefinitely until stopped (Ctrl+C)")
print("\n" + "="*70)
# Initialize service
service = QuantumBlockchainService(
validator_backends=['ibm_fez', 'ibm_torino', 'ibm_marrakesh'],
status_file='quantum_blockchain_status.json'
)
service.initialize()
print("\nβ
Quantum blockchain service initialized")
print(f"π Status file: quantum_blockchain_status.json")
print(f"βοΈ Validators: {', '.join(service.validator_backends)}")
# Configuration
transactions_per_block = 3 # Number of transactions before mining
mining_interval = 180 # Mine every 3 minutes (180 seconds)
transaction_interval = 60 # Add new transaction every 60 seconds
print(f"\nβοΈ Configuration:")
print(f" Transactions per block: {transactions_per_block}")
print(f" Mining interval: {mining_interval}s")
print(f" New transaction every: {transaction_interval}s")
print("\nπ Starting continuous operation...\n")
last_mine_time = time.time()
last_tx_time = time.time()
tx_count = 0
try:
while True:
current_time = time.time()
# Add new transaction periodically
if current_time - last_tx_time >= transaction_interval:
tx = generate_random_transaction()
service.add_transaction(tx)
tx_count += 1
print(f"π Transaction #{tx_count} added:")
print(f" {tx['from']} β {tx['to']}")
print(f" Amount: {tx['amount']} {tx['token']}")
print(f" Type: {tx['type']}")
print(f" Pending: {len(service.pending_transactions)}")
last_tx_time = current_time
# Mine block when enough transactions accumulated OR interval passed
should_mine = (
len(service.pending_transactions) >= transactions_per_block or
(len(service.pending_transactions) > 0 and
current_time - last_mine_time >= mining_interval)
)
if should_mine:
print(f"\nβοΈ Mining block #{len(service.blockchain) + 1}...")
print(f" Transactions to include: {len(service.pending_transactions)}")
block = service.mine_block()
if block:
print(f"\nπ BLOCK MINED!")
print(f" Block #{block['block_number']}")
print(f" Hash: {block['hash'][:32]}...")
print(f" Quantum Nonce: {block['nonce']}")
print(f" Transactions: {len(block.get('transactions', []))}")
print(f" Mining Backend: {block['quantum_backend']}")
print(f" Consensus: {block.get('consensus_votes', {}).get('valid', 0)}/{block.get('consensus_votes', {}).get('total', 0)}")
print(f"\nπ Blockchain Stats:")
print(f" Total Blocks: {len(service.blockchain)}")
print(f" Total Transactions: {sum(len(b.get('transactions', [])) for b in service.blockchain)}")
last_mine_time = current_time
else:
print(f"\nβ Mining failed (consensus not reached)")
# Update status file periodically
service.save_status()
# Wait a bit before next iteration
time.sleep(10)
except KeyboardInterrupt:
print(f"\n\n{'='*70}")
print("π STOPPING QUANTUM BLOCKCHAIN")
print("="*70)
# Final stats
print(f"\nπ Final Statistics:")
print(f" Total Blocks Mined: {len(service.blockchain)}")
print(f" Total Transactions: {sum(len(b.get('transactions', [])) for b in service.blockchain)}")
print(f" Pending Transactions: {len(service.pending_transactions)}")
if service.blockchain:
print(f"\nπ Block History:")
for i, block in enumerate(service.blockchain[-5:], 1): # Show last 5 blocks
print(f" Block #{block.get('block_number', i)}: {block['hash'][:16]}... ({len(block.get('transactions', []))} txs)")
# Save final state
service.save_status()
print(f"\nπΎ Final state saved to quantum_blockchain_status.json")
print(f"\nβ
Blockchain service stopped cleanly")
if __name__ == "__main__":
main()