-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbalances.js
41 lines (36 loc) · 1.01 KB
/
balances.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const {
accounts: { issuer, distributor, buyer },
serverUrl
} = require("./config.json");
const { Server } = require("stellar-sdk");
const displayTemplate = ({ name, accountId, balances }) => {
console.log(
`\u001b[33m${name}\u001b[0m \u001b[37;2m${accountId.substring(
0,
9
)}${Array.from(new Array(15 - name.length))
.map(() => "⋅")
.join("")}\u001b[0m${balances}`
);
};
const server = new Server(serverUrl);
const checkAccounts = async () => {
const stellarAccounts = await Promise.all(
[issuer, distributor, buyer].map(async ({ name, publicKey }) => {
const account = await server.loadAccount(publicKey);
return {
name,
accountId: publicKey,
balances: account.balances.map(
({ balance, asset_type, asset_code }) =>
`${balance} ${asset_type === "native" ? "XLM" : asset_code}`
)
};
})
);
stellarAccounts.forEach(displayTemplate);
};
checkAccounts().catch(e => {
console.log("Meh", e);
throw e;
});