-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_script.js
More file actions
53 lines (42 loc) · 1.2 KB
/
run_script.js
File metadata and controls
53 lines (42 loc) · 1.2 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
const fs = require("fs");
const Blockchain = require("./blockchain");
const { generateWallet, signMessage } = require("./wallet_utils");
// Create blockchain
const bc = new Blockchain();
// Create wallet
const wallet = generateWallet();
const privateKey = wallet.privateKey;
const publicKey = wallet.publicKey;
// Transaction message
const message = {
user: "Adarsh",
action: "cleaned the road"
};
// Generate signature
const signature = signMessage(privateKey, message);
// Add block
bc.addBlock({
user: "Adarsh",
action: "cleaned the road",
signature: signature
});
// Check if chain is valid
console.log("Blockchain valid:", bc.isChainValid());
// Print blockchain
bc.chain.forEach((block) => {
console.log(`\nBlock #${block.index}`);
console.log("Timestamp:", block.timestamp);
console.log("Data:", block.data);
console.log("Previous Hash:", block.previous_hash);
console.log("Hash:", block.hash);
});
// Print balances
console.log("\n--- User Balances ---");
try {
const balances = JSON.parse(fs.readFileSync("balances.json"));
for (const user in balances) {
console.log(`${user}: ${balances[user]} CLEAN-COINs`);
}
} catch (error) {
console.log("⚠️ No balances found.");
}