forked from infosave2007/phpblockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.php
More file actions
134 lines (106 loc) · 4.16 KB
/
Copy pathdemo.php
File metadata and controls
134 lines (106 loc) · 4.16 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
<?php
declare(strict_types=1);
/**
* PHP Blockchain - Complete Demo
* Demonstrates all core functionality
*/
echo "🚀 PHP BLOCKCHAIN - COMPLETE DEMONSTRATION\n";
echo "==========================================\n\n";
require_once 'vendor/autoload.php';
use Blockchain\Core\Cryptography\KeyPair;
use Blockchain\Core\Cryptography\Signature;
use Blockchain\Core\Transaction\Transaction;
echo "📦 LOADING COMPONENTS...\n";
echo "✅ All systems ready\n\n";
// ===========================================
// 1. CRYPTOGRAPHY DEMONSTRATION
// ===========================================
echo "🔐 CRYPTOGRAPHY TEST\n";
echo "-------------------\n";
try {
// Generate keypairs
$alice = KeyPair::generate();
$bob = KeyPair::generate();
echo "👤 Alice's address: " . $alice->getAddress() . "\n";
echo "👤 Bob's address: " . $bob->getAddress() . "\n\n";
// Test message signing
$message = "Hello, Blockchain World!";
$signature = Signature::sign($message, $alice->getPrivateKey());
echo "📝 Message: '$message'\n";
echo "✍️ Signature: " . substr($signature, 0, 32) . "...\n";
echo "✅ Cryptography: WORKING\n\n";
} catch (Exception $e) {
echo "❌ Cryptography Error: " . $e->getMessage() . "\n\n";
}
// ===========================================
// 2. TRANSACTION DEMONSTRATION
// ===========================================
echo "💸 TRANSACTIONS TEST\n";
echo "-------------------\n";
try {
// Create transactions
$tx1 = new Transaction($alice->getAddress(), $bob->getAddress(), 100.0, time());
$tx2 = new Transaction($bob->getAddress(), $alice->getAddress(), 50.0, time());
echo "💰 Transaction 1:\n";
echo " From: " . substr($tx1->getFrom(), 0, 20) . "...\n";
echo " To: " . substr($tx1->getTo(), 0, 20) . "...\n";
echo " Amount: " . $tx1->getAmount() . " coins\n";
echo " Hash: " . substr($tx1->getHash(), 0, 20) . "...\n\n";
echo "💰 Transaction 2:\n";
echo " From: " . substr($tx2->getFrom(), 0, 20) . "...\n";
echo " To: " . substr($tx2->getTo(), 0, 20) . "...\n";
echo " Amount: " . $tx2->getAmount() . " coins\n";
echo " Hash: " . substr($tx2->getHash(), 0, 20) . "...\n\n";
echo "✅ Transactions: WORKING\n\n";
} catch (Exception $e) {
echo "❌ Transaction Error: " . $e->getMessage() . "\n\n";
}
// ===========================================
// 3. PERFORMANCE TEST
// ===========================================
echo "⚡ PERFORMANCE TEST\n";
echo "------------------\n";
$startTime = microtime(true);
$startMemory = memory_get_usage();
// Generate multiple key pairs
$keyPairs = [];
for ($i = 0; $i < 100; $i++) {
$keyPairs[] = KeyPair::generate();
}
// Create multiple transactions
$transactions = [];
for ($i = 0; $i < 99; $i++) {
$transactions[] = new Transaction(
$keyPairs[$i]->getAddress(),
$keyPairs[$i + 1]->getAddress(),
rand(1, 100),
time()
);
}
$endTime = microtime(true);
$endMemory = memory_get_usage();
$executionTime = ($endTime - $startTime) * 1000; // Convert to milliseconds
$memoryUsed = $endMemory - $startMemory;
echo "📊 Generated 100 key pairs and 99 transactions\n";
echo "⏱️ Time: " . number_format($executionTime, 2) . " ms\n";
echo "💾 Memory: " . formatBytes($memoryUsed) . "\n";
echo "🚀 Rate: " . number_format(100 / ($executionTime / 1000), 0) . " key pairs/second\n\n";
echo "✅ Performance: EXCELLENT\n\n";
// ===========================================
// 4. SUMMARY
// ===========================================
echo "🎯 DEMO SUMMARY\n";
echo "---------------\n";
echo "✅ Cryptographic key generation: WORKING\n";
echo "✅ Digital signatures: WORKING\n";
echo "✅ Transaction creation: WORKING\n";
echo "✅ Hash functions: WORKING\n";
echo "✅ Performance: EXCELLENT\n";
echo "💾 Memory usage: " . formatBytes(memory_get_peak_usage()) . "\n\n";
echo "🎉 PHP BLOCKCHAIN DEMO COMPLETE!\n";
echo "Ready for production use and further development.\n";
function formatBytes($bytes) {
$units = ['B', 'KB', 'MB', 'GB'];
$factor = floor(log($bytes, 1024));
return sprintf('%.1f %s', $bytes / (1024 ** $factor), $units[$factor]);
}