-
Notifications
You must be signed in to change notification settings - Fork 8
/
block_feed.js
158 lines (116 loc) · 6.54 KB
/
block_feed.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
var dsteem = require('dsteem');
var es = require('event-stream')
const steem = new dsteem.Client('https://rpc.buildteam.io');// We use buildteam's node as they are the fastest but feel free to use https://api.steemit.com
/**
* From a block number, gets it and parses the informations within it to store them on the blockchain
* @param {int} blocknb - block number to parse.
*/
async function parseBlock(blocknb) {
console.log(blocknb);
const block = await steem.database.getBlock(blocknb);
const tx = block['transactions'];
for (let i = 0; i < tx.length; i++) { // iterate over each transaction
for (let y = 0; y < tx[i]['operations'].length; y++) { // iterate over each operation of each transaction
if (tx[i]['operations'][y][0] === "comment") {
const post = tx[i]['operations'][y][1];
if (post['parent_author'] === "") // if the parent_author field is empty it's a post.
{
console.log(post);
} else
{
// if parent_author is not empty then it's a comment
console.log(post);
}
}
else if (tx[i]['operations'][y][0] === "vote") { // Vote
const vote = tx[i]['operations'][y][1];
console.log(vote);
}
else if (tx[i]['operations'][y][0] === "custom_json") { // Almost all the time used to perform follow/unfollow
const custom_json = tx[i]['operations'][y][1];
if (custom_json['id'] === "follow") // Follow/unfollow
{
const follow_data = JSON.parse(custom_json['json']);
console.log(follow_data);
} else
console.log(custom_json); // Something else.
}
else if (tx[i]['operations'][y][0] === "transfer") { // Transfer steem/sbd
const transfer = tx[i]['operations'][y][1];
console.log(transfer);
} else if (tx[i]['operations'][y][0] === "claim_reward_balance") { // Claim reward
const claim_reward_balance = tx[i]['operations'][y][1];
console.log(claim_reward_balance);
} else if (tx[i]['operations'][y][0] === "comment_options") { // Comments options, generally used to set beneficiaries.
const comment_options = tx[i]['operations'][y][1];
console.log(comment_options);
} else if (tx[i]['operations'][y][0] === "account_update") { // Update account infos (profile pic, description name etc).
const account_update = tx[i]['operations'][y][1];
console.log(account_update);
} else if (tx[i]['operations'][y][0] === "limit_order_cancel") { // Cancel marketplace order
const limit_order_cancel = tx[i]['operations'][y][1];
console.log(limit_order_cancel);
} else if (tx[i]['operations'][y][0] === "transfer_to_vesting") { // Power up
const transfer_to_vesting = tx[i]['operations'][y][1];
console.log(transfer_to_vesting);
} else if (tx[i]['operations'][y][0] === "transfer_to_savings") { // Put steem/sbd in savings
const transfer_to_savings = tx[i]['operations'][y][1];
console.log(transfer_to_savings);
} else if (tx[i]['operations'][y][0] === "feed_publish") { // price feed from a witness
const feed_publish = tx[i]['operations'][y][1];
console.log(feed_publish);
}else if (tx[i]['operations'][y][0] === "account_witness_vote") { // vote/unvote for a witness
const account_witness_vote = tx[i]['operations'][y][1];
console.log(account_witness_vote);
}else if (tx[i]['operations'][y][0] === "limit_order_create") { // Create a limit order on the internal market
const limit_order_create = tx[i]['operations'][y][1];
console.log(limit_order_create);
}else if (tx[i]['operations'][y][0] === "account_create_with_delegation") { // Create an account with delegation
const account_create_with_delegation = tx[i]['operations'][y][1];
console.log(account_create_with_delegation);
}else if (tx[i]['operations'][y][0] === "delete_comment") { // Delete a post/comment
const delete_comment = tx[i]['operations'][y][1];
console.log(delete_comment);
}else if (tx[i]['operations'][y][0] === "delegate_vesting_shares") { // price feed from a witness
const delegate_vesting_shares = tx[i]['operations'][y][1];
console.log(delegate_vesting_shares);
}else if (tx[i]['operations'][y][0] === "transfer_from_savings") { // withdrawal from saving account
const transfer_from_savings = tx[i]['operations'][y][1];
console.log(transfer_from_savings);
}else if (tx[i]['operations'][y][0] === "withdraw_vesting") { // power down
const withdraw_vesting = tx[i]['operations'][y][1];
console.log(withdraw_vesting);
} else if (tx[i]['operations'][y][0] === "account_witness_proxy") { // proxy witness vote
const account_witness_proxy = tx[i]['operations'][y][1];
console.log(account_witness_proxy);
} else if (tx[i]['operations'][y][0] === "account_create") { // account create without delegation
const account_create = tx[i]['operations'][y][1];
console.log(account_create);
}else if (tx[i]['operations'][y][0] === "cancel_transfer_from_savings") { // Cancel Transfer From Savings
const cancel_transfer_from_savings = tx[i]['operations'][y][1];
console.log(cancel_transfer_from_savings);
}
else {
var something = tx[i]['operations'][y];
console.log(something)
}
}
}
}
/**
* Main function tp start the stream
* @param {int} from - Block from which to start streaming, most rpc nodes won't stream more than 100 blocks in one go so be careful
*/
async function main(from) {
console.log("Starting parser");
let stream = null;
if (from) {
stream = steem.blockchain.getBlockNumberStream({from: lastblock});
}
else
stream = steem.blockchain.getBlockNumberStream();
stream.pipe(es.map(function (block, callback) {
callback(null, parseBlock(block))
}));
}
main();