Skip to content

Instantly share code, notes, and snippets.

@robertDurst

robertDurst/code.js

Created Jul 31, 2018
Embed
What would you like to do?
Code for calculating inflation for an account since a given time.
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