forked from infosave2007/phpblockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_sync_config.php
More file actions
95 lines (76 loc) · 3.21 KB
/
Copy pathsetup_sync_config.php
File metadata and controls
95 lines (76 loc) · 3.21 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
<?php
/**
* Configuration Setup Script for Sync Service
* This script ensures proper network configuration for synchronization
*/
require_once 'core/Environment/EnvironmentLoader.php';
require_once 'core/Database/DatabaseManager.php';
try {
echo "=== Blockchain Sync Configuration Setup ===\n\n";
// Connect to database
$pdo = \Blockchain\Core\Database\DatabaseManager::getConnection();
echo "✓ Database connection established\n";
// Check if config table exists
$stmt = $pdo->query("SHOW TABLES LIKE 'config'");
if ($stmt->rowCount() === 0) {
echo "✗ Config table not found\n";
exit(1);
}
echo "✓ Config table found\n";
// Check for network nodes configuration
$stmt = $pdo->prepare("SELECT key_name, value FROM config WHERE key_name LIKE 'network.%'");
$stmt->execute();
$configs = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "\nCurrent network configuration:\n";
foreach ($configs as $config) {
echo " {$config['key_name']}: {$config['value']}\n";
}
// Check if network.nodes exists
$stmt = $pdo->prepare("SELECT value FROM config WHERE key_name = 'network.nodes'");
$stmt->execute();
$networkNodes = $stmt->fetchColumn();
if (empty($networkNodes)) {
echo "\n⚠ No network.nodes found, adding default genesis node...\n";
// Add default network nodes configuration
$defaultNode = "https://wallet.coursefactory.pro";
$stmt = $pdo->prepare("
INSERT INTO config (key_name, value, description, is_system)
VALUES ('network.nodes', ?, 'Network nodes for synchronization', 1)
ON DUPLICATE KEY UPDATE value = VALUES(value)
");
$stmt->execute([$defaultNode]);
echo "✓ Added default network node: $defaultNode\n";
} else {
echo "✓ Network nodes configuration found\n";
}
// Add selection strategy if not exists
$stmt = $pdo->prepare("SELECT value FROM config WHERE key_name = 'node.selection_strategy'");
$stmt->execute();
$strategy = $stmt->fetchColumn();
if (empty($strategy)) {
$stmt = $pdo->prepare("
INSERT INTO config (key_name, value, description, is_system)
VALUES ('node.selection_strategy', 'fastest_response', 'Node selection strategy for sync', 1)
ON DUPLICATE KEY UPDATE value = VALUES(value)
");
$stmt->execute();
echo "✓ Added node selection strategy\n";
}
// Test sync service
echo "\n=== Testing Sync Service ===\n";
require_once 'sync-service/SyncManager.php';
$syncManager = new SyncManager(false);
$status = $syncManager->getStatus();
echo "Current database status:\n";
foreach ($status['tables'] as $table => $count) {
echo " $table: $count records\n";
}
echo " Latest block: {$status['latest_block']}\n";
echo " Last sync: {$status['latest_timestamp']}\n";
echo "\n✓ Sync service configuration complete!\n";
echo "\nTo run full synchronization, use:\n";
echo " php sync-service/sync.php\n\n";
} catch (Exception $e) {
echo "✗ Error: " . $e->getMessage() . "\n";
exit(1);
}