-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteem_aspect.js
More file actions
57 lines (44 loc) · 1.47 KB
/
steem_aspect.js
File metadata and controls
57 lines (44 loc) · 1.47 KB
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
var steem = require('steem');
const around = require('aspectjs').around;
// tell the api how many tranzactions you want fetched
const NUMBER_OF_TRANZACTIONS = 15;
// write your account name, or any other account here :)
const NAME = 'prometheus21';
// parse tranzaction
function process_tranzaction(transaction) {
// get the transaction operation (type)
var transactionOperation = transaction[1]['op'];
// check to see whether the operation was a vote type operation and the voter is not yourself
if (transactionOperation[0] === 'vote' && transactionOperation[1]['voter'] !== NAME) {
return transactionOperation[1]['voter'];
}
return null;
}
var upvoteObject = {
add: function(supporter){
console.log('I have an upvote by ' + supporter)
},
};
var api = {
getUpvotes : function() {
steem.api.getAccountHistory(NAME, 99999999, NUMBER_OF_TRANZACTIONS, function(err, accountHistory) {
if (err) throw err
for (var i=0; i < accountHistory.length; i++) {
var name = process_tranzaction(accountHistory[i]);
if (name) {
upvoteObject.add(name)
}
}
});
},
}
var advice = {
override: function(invocation) {
console.log('Hey, I can do something cool before I find a new upvote')
invocation.proceed();
console.log('Hey, I can again do something cool, after I have found the upvote')
console.log("************")
}
};
around(upvoteObject, "add").add(advice, "override");
api.getUpvotes()