-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
23 lines (19 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const EC = require('elliptic').ec;
const ec = new EC('secp256k1');
const Blockchain = require('./Blockchain');
const Transaction = require('./Transaction');
const { holderKeyPair } = require('./helpers');
const myChain = new Blockchain();
const aWalletThatBelongsToSomeoneElse = ec.genKeyPair();
console.log(`Before:`);
console.log(`Someone's Wallet Balance: ${myChain.getBalance(aWalletThatBelongsToSomeoneElse.getPublic('hex'))}`);
console.log(`Holder's Wallet Balance: ${myChain.getBalance(holderKeyPair.getPublic('hex'))}`);
console.log('\n');
const transaction = new Transaction(holderKeyPair.getPublic('hex'), aWalletThatBelongsToSomeoneElse.getPublic('hex'), 100, 5);
transaction.sign(holderKeyPair);
myChain.addTransaction(transaction);
myChain.mineTransactions(holderKeyPair.getPublic('hex'));
console.dir(myChain, { depth: null });
console.log(`\n\nAfter:`);
console.log(`Someone's Wallet Balance: ${myChain.getBalance(aWalletThatBelongsToSomeoneElse.getPublic('hex'))}`);
console.log(`Holder's Wallet Balance: ${myChain.getBalance(holderKeyPair.getPublic('hex'))}`);