From 49883ffcf2b01f4ca85f87cd55ba17cc8d6aaea9 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 16 Sep 2020 23:05:14 -0700 Subject: add account network, fix internal asset transfers --- routes/assets.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'routes/assets.js') diff --git a/routes/assets.js b/routes/assets.js index 06ad42dc..2468b394 100644 --- a/routes/assets.js +++ b/routes/assets.js @@ -1,7 +1,8 @@ const axios = require("axios"); const crypto = require("crypto"); -app.get("/assets", ah(async (req, res) => { +let fetchAssets; +(fetchAssets = async () => { try { const { data: assets } = await axios.get( "https://assets.blockstream.info/" @@ -16,11 +17,18 @@ app.get("/assets", ah(async (req, res) => { if (!assets[a.asset]) assets[a.asset] = a; }); - res.send(assets); + app.set('assets', assets); } catch (e) { l.error("error fetching assets", e.message); res.status(500).send("error fetching assets"); } + + setTimeout(fetchAssets, 7200000); +})(); + +app.get("/assets", ah(async (req, res) => { + if (app.get('assets')) res.send(app.get('assets')); + else app.status(500).send('Problem fetching blockstream asset registry data'); })); app.post("/assets", auth, ah(async (req, res) => { -- cgit v1.2.3