forked from OnGameSteemTron/OnGame-Chat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
68 lines (59 loc) · 2.14 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
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
const { Client, BlockchainMode } = require('dsteem');
const express = require('express')
const app = express()
const port = process.env.PORT || 4000
var http = require('http').Server(app);
var io = require('socket.io')(http);
var client = new Client('https://api.steemit.com')
http.listen(port, function () {
console.log('Server Started. Listening on *:' + port);
});
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
app.get('/', function (req, res) {
res.json({ hello: 'world' });
});
io.on('connection', function (socket) {
socket.on('message', function (data) {
io.emit('send', data);
});
});
var stream = client.blockchain.getBlockStream({ mode: BlockchainMode.Latest })
stream.on("data", function (block) {
if (block != null) {
try {
var object = JSON.stringify(block.transactions)
object.replace("\\", "")
object = JSON.parse(object)
} catch (error) {
console.log(error)
}
for (i = 0; i < object.length; i++) {
if (object[i].operations[0][0] === "transfer") {
var op = object[i].operations[0][1]
var block = object[i].block_num
if(op.from === "fundition" && op.memo === "Your reward for claiming your daily chest on Fundition.io!")
{
console.log('this is a gift for ' + op.from)
op.type= 'gift'
io.emit('send', op);
}
if (op.memo.includes('Project=Fundition-')) {
console.log('this is a donation from ' + op.from)
op.type= 'donation'
op.memo = op.memo.replace("/", "°")
io.emit('send', op);
}
}
}
}
})
.on('end', function () {
// done
console.log('END');
});