-
Notifications
You must be signed in to change notification settings - Fork 351
/
Copy pathdebugging.ts
35 lines (29 loc) · 1.35 KB
/
debugging.ts
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
import { Coin } from "@cosmjs/stargate";
import { MinimalAccount, SendJob } from "./types";
/** A string representation of a coin in a human-readable format that can change at any time */
function debugCoin(coin: Coin): string {
return `${coin.amount} ${coin.denom}`;
}
/** A string representation of a balance in a human-readable format that can change at any time */
export function debugBalance(data: readonly Coin[]): string {
return `[${data.map((b) => debugCoin(b)).join(", ")}]`;
}
/** A string representation of an account in a human-readable format that can change at any time */
export function debugAccount(account: MinimalAccount): string {
return `${account.address}: ${debugBalance(account.balance)}`;
}
export function logAccountsState(accounts: readonly MinimalAccount[]): void {
if (accounts.length < 2) {
throw new Error("List of accounts must contain at least one token holder and one distributor");
}
const holder = accounts[0];
const distributors = accounts.slice(1);
console.info("Holder:\n" + ` ${debugAccount(holder)}`);
console.info("Distributors:\n" + distributors.map((r) => ` ${debugAccount(r)}`).join("\n"));
}
export function logSendJob(job: SendJob): void {
const from = job.sender;
const to = job.recipient;
const amount = debugCoin(job.amount);
console.info(`Sending ${amount} from ${from} to ${to} ...`);
}