From c973de1d5d0fb92d022cc6a749cdbe061f65b2e3 Mon Sep 17 00:00:00 2001 From: Viktor Sokolov Date: Wed, 3 Jul 2019 16:58:58 +0400 Subject: [PATCH] Assets relation added to README, get rid of native from examples --- README.md | 26 ++++++++++++++++++++++++++ examples/balance-cli.ts | 4 +--- examples/balance-monitor-cli.ts | 4 +--- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e3caa4e0..5289b02b 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,32 @@ $ yarn run prod # for live setup $ yarn ts-node src/ingestd.ts # live ingesting for subscriptions ``` +Create assets view in database: + +``` +( SELECT (t.assetcode::text || '-'::text) || t.issuer::text AS assetid, + t.assetcode AS code, + t.issuer, + sum(t.balance) AS total_supply, + sum(t.balance) FILTER (WHERE t.flags = 1) AS circulating_supply, + count(t.accountid) AS holders_count, + count(t.accountid) FILTER (WHERE t.flags = 0) AS unauthorized_holders_count, + max(t.lastmodified) AS last_activity + FROM trustlines t + GROUP BY t.issuer, t.assetcode + ORDER BY (count(t.accountid)) DESC) +UNION + SELECT 'native'::text AS assetid, + 'XLM'::character varying AS code, + NULL::character varying AS issuer, + sum(accounts.balance) AS total_supply, + sum(accounts.balance) AS circulating_supply, + count(*) AS holders_count, + 0 AS unauthorized_holders_count, + max(accounts.lastmodified) AS last_activity + FROM accounts; +``` + ## Configure Here is the list of available settings: diff --git a/examples/balance-cli.ts b/examples/balance-cli.ts index ba1fe1af..7be5081d 100644 --- a/examples/balance-cli.ts +++ b/examples/balance-cli.ts @@ -25,7 +25,6 @@ client limit asset { code - native issuer { id } } } @@ -38,7 +37,6 @@ client }) .then((result: { data: any }) => { for (const t of result.data.account.balances) { - const assetId = t.asset.native ? t.asset.code : `${t.asset.code}-${t.asset.issuer.id}`; - console.log("Balance", t.balance, assetId, "with limit", t.limit); + console.log("Balance", t.balance, t.id, "with limit", t.limit); } }); diff --git a/examples/balance-monitor-cli.ts b/examples/balance-monitor-cli.ts index 8ebdb3a2..6f45dda9 100644 --- a/examples/balance-monitor-cli.ts +++ b/examples/balance-monitor-cli.ts @@ -35,7 +35,6 @@ const SUBSCRIPTION = gql` asset { code issuer { id } - native } balance limit @@ -67,11 +66,10 @@ apolloClient } const values = payload.values; - const assetId = values.asset.native ? values.asset.code : `${values.asset.code}-${values.asset.issuer.id}`; console.log( "New balance for", - assetId, + values.id, "is now", values.balance, "with limit",