Skip to content

Serve assets from issuer account#159

Merged
charlie-wasp merged 12 commits intomasterfrom
chore/assets-from-view
May 20, 2019
Merged

Serve assets from issuer account#159
charlie-wasp merged 12 commits intomasterfrom
chore/assets-from-view

Conversation

@charlie-wasp
Copy link
Contributor

@charlie-wasp charlie-wasp commented Apr 26, 2019

What we've got here:

  • I ditched Horizon regarding assets, and now we're getting assets directly from the database, namely from special postgres view, made by @nebolsin. I expanded it a little, I added flags and appended the row for the native XLM to serve everything consistently
  • Now we have the connection to assets from an account, so user now can query all assets, issued by the particular account in a graph-like manner
  • thanks to @nebolsin, we now can serve more data about an asset, like holders count and overall tokens number in circulation
  • authorization flags now live under assets, not under accounts

More technical notes:

  • I dropped AssetWithInfo from the schema, we have one type Asset now
  • I decided to omit native XLM from query { assets } response because it breaks alphanumeric sorting in pagination. It happens because we use "native" as an id for XLM, which serves as pagination token too, so native XLM won't be between other assets with codes, starting on "X". And it seems not very useful to have it there anyway. If the user would like to obtain some statistics about lumens, they can do it via query { asset(id: "native") }
  • It would be better to use the Asset class from stellar-sdk only for parsing XDR, and use our new Asset class everywhere else, but I didn't refactor that for now, because it looks like a big deal. Definitely, something to do later

This change is Reviewable

@charlie-wasp charlie-wasp requested a review from a team April 26, 2019 09:40
@charlie-wasp charlie-wasp force-pushed the chore/assets-from-view branch from f78561a to da38731 Compare May 13, 2019 16:09
@charlie-wasp
Copy link
Contributor Author

charlie-wasp commented May 13, 2019

Also here is the new assets view definition:

( 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,
    ( SELECT a.flags
           FROM accounts a
          WHERE t.issuer::text = a.accountid::text) AS flags,
    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,
    0 AS flags,
    max(accounts.lastmodified) AS last_activity
   FROM accounts;

@charlie-wasp charlie-wasp force-pushed the chore/assets-from-view branch from da38731 to 4105eb0 Compare May 14, 2019 11:27
Copy link
Member

@nebolsin nebolsin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 12 of 17 files at r1, 18 of 18 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@charlie-wasp charlie-wasp force-pushed the chore/assets-from-view branch from 9a2a094 to 01801fd Compare May 20, 2019 08:45
@charlie-wasp charlie-wasp merged commit dce3f11 into master May 20, 2019
@nebolsin nebolsin deleted the chore/assets-from-view branch November 15, 2019 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants