Skip to content

Commit d7c1aae

Browse files
committed
day 2 new files
1 parent e732617 commit d7c1aae

4 files changed

Lines changed: 45 additions & 0 deletions

File tree

models/Transaction.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const {utxos} = require('../db');
2+
3+
class Transaction {
4+
constructor(inputs, outputs) {
5+
this.inputs = inputs;
6+
this.outputs = outputs;
7+
}
8+
execute() {
9+
this.inputs.forEach((input) => {
10+
input.spent = true;
11+
});
12+
this.outputs.forEach((output) => {
13+
utxos.push(output);
14+
});
15+
}
16+
}
17+
18+
module.exports = Transaction;

models/UTXO.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class UTXO {
2+
constructor(owner, amount) {
3+
this.owner = owner;
4+
this.amount = amount;
5+
this.spent = false;
6+
}
7+
}
8+
9+
module.exports = UTXO;

scripts/generate.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const EC = require('elliptic').ec;
2+
3+
const ec = new EC('secp256k1');
4+
5+
const key = ec.genKeyPair();
6+
7+
console.log({
8+
privateKey: key.getPrivate().toString(16),
9+
publicKey: key.getPublic().encode('hex'),
10+
});

scripts/getBalance.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const client = require('./client');
2+
const {argv} = require('yargs');
3+
const {address} = argv;
4+
5+
client.request('getBalance', [address], function(err, response) {
6+
if(err) throw err;
7+
console.log(response.result);
8+
});

0 commit comments

Comments
 (0)