-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bb5dcc
commit 546eb95
Showing
8 changed files
with
33 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,35 @@ | ||
import { Coin } from "@cosmjs/launchpad"; | ||
|
||
import { TokenConfiguration } from "./tokenmanager"; | ||
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, tokens: TokenConfiguration): string { | ||
const meta = tokens.bankTokens.find((token) => token.denom == coin.denom); | ||
if (!meta) throw new Error(`No token configuration found for denom ${coin.denom}`); | ||
return `${coin.amount} ${meta?.denom}`; | ||
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[], tokens: TokenConfiguration): string { | ||
return `[${data.map((b) => debugCoin(b, tokens)).join(", ")}]`; | ||
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, tokens: TokenConfiguration): string { | ||
return `${account.address}: ${debugBalance(account.balance, tokens)}`; | ||
export function debugAccount(account: MinimalAccount): string { | ||
return `${account.address}: ${debugBalance(account.balance)}`; | ||
} | ||
|
||
export function logAccountsState(accounts: readonly MinimalAccount[], tokens: TokenConfiguration): void { | ||
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, tokens)}`); | ||
console.info("Distributors:\n" + distributors.map((r) => ` ${debugAccount(r, tokens)}`).join("\n")); | ||
console.info("Holder:\n" + ` ${debugAccount(holder)}`); | ||
console.info("Distributors:\n" + distributors.map((r) => ` ${debugAccount(r)}`).join("\n")); | ||
} | ||
|
||
export function logSendJob(job: SendJob, tokens: TokenConfiguration): void { | ||
export function logSendJob(job: SendJob): void { | ||
const from = job.sender; | ||
const to = job.recipient; | ||
const amount = debugCoin(job.amount, tokens); | ||
const amount = debugCoin(job.amount); | ||
console.info(`Sending ${amount} from ${from} to ${to} ...`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters