-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
28 lines (20 loc) · 1.04 KB
/
app.js
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
const { Blockchain } = require('./Blockchain');
const { Wallet } = require('./Wallet');
const { Miner } = require('./Miner');
// We create the main blockchain network
const mainNet = new Blockchain('Main net');
// Three wallets, one for Alice, one for Bob and one for Toni, the miner.
const alicesWallet = new Wallet(mainNet, 'Alice'); alicesWallet._addFunds(150); //This doesn't happen in real life. It's just as done for the base case.
const bobsWallet = new Wallet(mainNet, 'Bob');
const tonisWallet = new Wallet(mainNet, 'Toni');
console.log("Silvia's balance: " + bobsWallet.getBalance());
console.log("Dani's balance: " + alicesWallet.getBalance());
// Dani wants to send 100 coins to Silvia
alicesWallet.transferTo(bobsWallet.getAddress(), 100);
console.log("Alice transfers 100 coins to Bob");
// A miner mines a block;
const miner = new Miner(tonisWallet.name, mainNet, tonisWallet);
miner.mineBlock();
console.log("Bob's balance: " + bobsWallet.getBalance());
console.log("Alice's balance: " + alicesWallet.getBalance());
console.log('FINISHED');