Created
July 31, 2018 06:06
-
-
Save robertDurst/05e84a174ec774fcdcd31e901ed2e2e3 to your computer and use it in GitHub Desktop.
Code for calculating inflation for an account since a given time.
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
var StellarSdk = require('stellar-sdk'); | |
var server = new StellarSdk.Server('https://horizon.stellar.org'); | |
// Make sure date is in # of seconds since unix epoch | |
async function getInflationForAccountSinceDate(account, time) { | |
const resp = await server.transactions() | |
.forAccount(account) | |
.limit(200) | |
.order("desc") | |
.call(); | |
const r = resp.records.filter(x => x.source_account === "GDC2XPNEM4YAH22FK2TW7FSVGWQRGZGXLA3DAJLHNJ7YL5L5RSIXXXXX"); | |
let z = []; | |
for (var i = 0; i < r.length; i ++) { | |
const time_raw = (new Date(r[i].created_at)).getTime(); | |
if (time_raw > time) { | |
const x = await r[i].effects(); | |
z.push({ | |
date: r[i].created_at, | |
effects: x, | |
}) | |
}; | |
} | |
const p = z.map(x => x.effects.records.filter(y => y.type=='account_credited' && y.account == account)[0].amount); | |
return p.reduce((sum, x) => sum + parseFloat(x), 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment