Skip to content

Commit

Permalink
Merge pull request #291 from Emurgo/fix/change-token-supply-api-format
Browse files Browse the repository at this point in the history
update multi asset supply endpoint API
  • Loading branch information
ozgrakkurt committed Nov 29, 2021
2 parents e2b4053 + 9bdfc2b commit 2f5db78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,12 @@ We recommend querying using payment key hashes (`addr_vkh`) when possible (other
Output

```js
// current supplies of given assets
Array<number>
{
// current supplies of given assets.
// entry for an asset is null if it is not found.
supplies: {
"${asset.policy}.${asset.name}": number | null
}
}
```
</details>
</details>
10 changes: 7 additions & 3 deletions src/services/multiAssetSupply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ export const handleGetMultiAssetSupply = (pool: Pool) => async (req: Request, re

const assets: Asset[] = req.body.assets;

const ret = await Promise.all(assets.map(async (asset) => {
const supplies: {[key: string]: number} = {};

await Promise.all(assets.map(async (asset) => {
const supply = await getMultiAssetSupply(pool, asset);

const policyAndName = `${asset.policy}.${asset.name}`;

return supply;
supplies[policyAndName] = supply;
}));

res.send(ret);
res.send({
supplies
});
};

const getMultiAssetSupply = async (pool: Pool, asset: Asset): Promise<number> => {
Expand Down

0 comments on commit 2f5db78

Please sign in to comment.