Skip to content

Instantly share code, notes, and snippets.

@robertDurst
Created July 31, 2018 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertDurst/05e84a174ec774fcdcd31e901ed2e2e3 to your computer and use it in GitHub Desktop.
Save robertDurst/05e84a174ec774fcdcd31e901ed2e2e3 to your computer and use it in GitHub Desktop.
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