-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
99 lines (84 loc) · 2.83 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
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var fs = require('fs');
var Blocktrail = require('blocktrail-sdk');
var Twitter = require('twitter');
var Express = require('express');
var bodyParser = require('body-parser');
var config = {};
var app = Express();
function tweetBlock (block) {
if (block == undefinied){
return
} else {
var blockNumber = block.height;
var blockHash = block.hash;
var tTx = block.transactions;
var tBalance = block.value
/*
var client = new Twitter({
consumer_key: config.Key,
consumer_secret: config.Secret,
access_token_key: config.Token_Key,
access_token_secret: config.Token_Secret
});
if (blockNumber == 0) {
client.post('statuses/update', {status: 'HARD FORK!!!'}, function(error, tweet, response) {
if(error) {
console.log('Warning: error while tweeting ' + error);
} else if(tweet == null) {
console.log('Warning: tweet is null');
} else {
console.log(tweet);
}
});
}
*/
var message = 'Block: ' + blockNumber + ' Hash: ' + blockHash + ' ' + tTx + ' Txs ' + tBalance + ' BTC ' + config.ExplorerURL + blockNumber;
console.log(message);
/*
client.post('statuses/update', {status: message}, function(error, tweet, response) {
if(error) {
console.log('Warning: error while tweeting ' + error);
} else if(tweet == null) {
console.log('Warning: tweet is null');
} else {
console.log(tweet);
}
});
*/
}
}
function loadConfig(){
try {
var configContents = fs.readFileSync('config.json');
config = JSON.parse(configContents);
}
catch (error) {
if (error.code === 'ENOENT') {
console.log('No config file found.');
process.exit(1);
} else {
throw error;
process.exit(1);
}
}
}
loadConfig()
console.log('Using configuration:');
console.log(config);
app.post('/getBlock', function(request, response){
console.log(request.body);
// tweetBlock(req.body);
response.send('Thanks');
});
var rawBodySaver = function (req, res, buf, encoding) {
if (buf && buf.length) {
req.rawBody = buf.toString(encoding || 'utf8');
}
}
app.use(bodyParser.json({ verify: rawBodySaver }));
app.use(bodyParser.urlencoded({ verify: rawBodySaver, extended: true }));
app.use(bodyParser.raw(options));
app.listen(config.Port);
console.log('Server started! At http://localhost:' + config.Port);
//var client = Blocktrail.BlocktrailSDK({apiKey: config.BlockTrail_ApiKey, apiSecret: config.BlockTrail_ApiSecret, network: config.Network, testnet: false});
//watcher(config, client);