Skip to content

Commit

Permalink
Assets relation added to README, get rid of native from examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gzigzigzeo committed Jul 3, 2019
1 parent f344231 commit c973de1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions examples/balance-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ client
limit
asset {
code
native
issuer { id }
}
}
Expand All @@ -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);
}
});
4 changes: 1 addition & 3 deletions examples/balance-monitor-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const SUBSCRIPTION = gql`
asset {
code
issuer { id }
native
}
balance
limit
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit c973de1

Please sign in to comment.