This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
490 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ logs | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
delegations.json* | ||
# Runtime data | ||
pids | ||
*.pid | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const steem = require('steem') | ||
const fs = require('fs') | ||
let store = []; | ||
async function start() { | ||
setInterval(async () => { | ||
await getData().catch(err => console.log(err)) | ||
console.log("Delegations downloaded.", Date.now()) | ||
return null; | ||
}, 300000) | ||
return null; | ||
} | ||
start() | ||
async function getData() { | ||
let data; | ||
//Number of the operation, it has to be the same or higher than limit | ||
let from = store === undefined || store.length === 0 ? 10000000 : store[store.length - 1 ][0]; | ||
await steem.api.getAccountHistoryAsync('knacksteem.org', from, from < 1000 ? from : 1000).then(res => { | ||
const sorted = res.sort(function(a, b){ | ||
const x = a[1].block; | ||
const y = b[1].block; | ||
if (x < y) {return 1;} | ||
if (x > y) {return -1;} | ||
return 0; | ||
}); | ||
data = sorted; | ||
|
||
return res; | ||
}).catch(err => { | ||
return err; | ||
}); | ||
|
||
if(store.length === 0) { | ||
store = data | ||
await getData(); | ||
return null; | ||
|
||
//if pulled data is the same function stops here | ||
} else if(data[data.length - 1][1].block === store[store.length - 1][1].block) { | ||
let arr = []; | ||
//filtering to get only delegations | ||
const filtered = store.filter(op => { | ||
return op[1].op[0] === 'delegate_vesting_shares'; | ||
}); | ||
filtered.map(sponsor => { | ||
let obj = { | ||
delegator: sponsor[1].op[1].delegator, | ||
vesting_shares: Number(sponsor[1].op[1].vesting_shares.split(' ')[0]), | ||
block: sponsor[1].block, | ||
trx_id: sponsor[1].trx_id | ||
}; | ||
//checking if delegator already exists in array | ||
const check = arr.find(x => x.delegator === obj.delegator); | ||
if(check !== undefined) { | ||
|
||
if(check.block < sponsor[1].block) { | ||
//if delegation is newer it will replace the old one | ||
const filtered = arr.filter(item => { | ||
return item.trx_id !== check.trx_id; | ||
}); | ||
arr = filtered; | ||
arr.push(obj); | ||
} | ||
} else { | ||
arr.push(obj); | ||
} | ||
|
||
}); | ||
//deleting delegations with zero vests | ||
const filterZeroVesting = arr.filter(item => { | ||
return item.vesting_shares !== 0; | ||
}); | ||
|
||
const sorted = filterZeroVesting.sort(function(a, b){ | ||
const x = a.vesting_shares; | ||
const y = b.vesting_shares; | ||
if (x < y) {return 1;} | ||
if (x > y) {return -1;} | ||
return 0; | ||
}); | ||
|
||
|
||
fs.writeFile("delegations.json", JSON.stringify(sorted), err => console.log(err)) | ||
return null; | ||
} else { | ||
store = store.concat(data) | ||
await getData(); | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.