Last active
July 2, 2020 09:01
-
-
Save chiliec/8855e488ba8f5117f3ce3967ad696ee5 to your computer and use it in GitHub Desktop.
Lambda function to get average VIZ price feed from bts.quotes.bank.viz.plus account https://eiy5lsown5.execute-api.us-east-2.amazonaws.com
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
exports.handler = async function (event) { | |
return new Promise(function (resolve, reject) { | |
let viz = require("viz-js-lib"); | |
viz.config.set("websocket", "https://node.viz.cx/"); | |
viz.api.getAccounts(["bts.quotes.bank.viz.plus"], function (err, result) { | |
if (err) { | |
reject(Error(err)); | |
} | |
let blockNum = result[0]["custom_sequence_block_num"]; | |
viz.api.getBlock(blockNum, function (err, res) { | |
if (err) { | |
reject(Error(err)); | |
} | |
let transactions = res["transactions"]; | |
for (let t of transactions) { | |
let operations = t["operations"]; | |
for (let o of operations) { | |
if (o[0] === "custom") { | |
if (o[1]["required_regular_auths"].includes("bts.quotes.bank.viz.plus") | |
&& o[1]["id"] === "vizplus_bitshares_info") { | |
resolve(JSON.parse(o[1]["json"])[1]); | |
return; | |
} | |
} | |
} | |
} | |
reject(Error("Something went wrong")); | |
}); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment