-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (34 loc) · 1.03 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
24
25
26
27
28
29
30
31
32
33
34
35
36
// const Block = require('./models/Block.js');
const jayson = require('jayson');
const {startMining, stopMining} = require('./mine.js');
const {PORT} = require('./config');
const {utxos} = require('./db');
// create a server
const server = new jayson.server({
startMining: function(_, callback) {
callback(null, 'success!');
startMining();
},
stopMining: function(_, callback) {
callback(null, 'stop!');
stopMining();
},
// getBalance: function([address], callback) {
// console.log(utxos.length);
// const ourUTXOs = utxos.filter(x => {
// return x.owner === address && !x.spent
// });
// console.log(ourUTXOs.length);
// const sum = ourUTXOs.reduce((p,c) => p + c.amount, 0);
// callback(null, sum);
// // stopMining();
// },
getBalance: function([address], callback) {
const ourUTXOs = utxos.filter(x => {
return x.owner === address && !x.spent;
});
const sum = ourUTXOs.reduce((p,c) => p + c.amount, 0);
callback(null, sum);
}
});
server.http().listen(PORT);