@toon-protocol/rig 2.13.1 → 2.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/rig.js
CHANGED
|
@@ -1082,7 +1082,7 @@ function loadPaidSession(deps, relayUrl) {
|
|
|
1082
1082
|
});
|
|
1083
1083
|
}
|
|
1084
1084
|
var defaultLoadStandalone = async (options) => {
|
|
1085
|
-
const mod = await import("../standalone-mode-
|
|
1085
|
+
const mod = await import("../standalone-mode-RG4PGALC.js");
|
|
1086
1086
|
return mod.createStandaloneContext(options);
|
|
1087
1087
|
};
|
|
1088
1088
|
function identityReport(ctx) {
|
|
@@ -1618,6 +1618,39 @@ function formatUnits(amount, decimals) {
|
|
|
1618
1618
|
function renderAmount(a) {
|
|
1619
1619
|
return `${a.symbol ?? "token"} ${formatUnits(a.amount, a.decimals)}`;
|
|
1620
1620
|
}
|
|
1621
|
+
var WALLET_READ_TIMEOUT_ENV = "RIG_BALANCE_WALLET_TIMEOUT_MS";
|
|
1622
|
+
var DEFAULT_WALLET_READ_TIMEOUT_MS = 2e4;
|
|
1623
|
+
function walletReadTimeoutMs(env) {
|
|
1624
|
+
const raw = env[WALLET_READ_TIMEOUT_ENV];
|
|
1625
|
+
if (raw === void 0 || raw === "") return DEFAULT_WALLET_READ_TIMEOUT_MS;
|
|
1626
|
+
const n = Number(raw);
|
|
1627
|
+
return Number.isFinite(n) && n >= 0 ? n : DEFAULT_WALLET_READ_TIMEOUT_MS;
|
|
1628
|
+
}
|
|
1629
|
+
var WalletReadTimeoutError = class extends Error {
|
|
1630
|
+
constructor(timeoutMs) {
|
|
1631
|
+
super(
|
|
1632
|
+
`wallet balance read timed out after ${timeoutMs}ms \u2014 the chain RPC/GraphQL endpoint is unreachable or hanging. (A nonexistent Mina account reads as 0, so a hang points at the endpoint, not an empty balance.) Recorded channels are unaffected; retry, or set ${WALLET_READ_TIMEOUT_ENV}=0 to wait indefinitely.`
|
|
1633
|
+
);
|
|
1634
|
+
this.timeoutMs = timeoutMs;
|
|
1635
|
+
this.name = "WalletReadTimeoutError";
|
|
1636
|
+
}
|
|
1637
|
+
timeoutMs;
|
|
1638
|
+
};
|
|
1639
|
+
async function readWalletBounded(read, timeoutMs) {
|
|
1640
|
+
const settled = read();
|
|
1641
|
+
if (timeoutMs <= 0) return settled;
|
|
1642
|
+
let timer;
|
|
1643
|
+
const guard = new Promise((_resolve, reject) => {
|
|
1644
|
+
timer = setTimeout(() => reject(new WalletReadTimeoutError(timeoutMs)), timeoutMs);
|
|
1645
|
+
});
|
|
1646
|
+
settled.catch(() => {
|
|
1647
|
+
});
|
|
1648
|
+
try {
|
|
1649
|
+
return await Promise.race([settled, guard]);
|
|
1650
|
+
} finally {
|
|
1651
|
+
if (timer) clearTimeout(timer);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1621
1654
|
async function runBalance(args, deps) {
|
|
1622
1655
|
const { io: io2, env } = deps;
|
|
1623
1656
|
let json = false;
|
|
@@ -1649,16 +1682,17 @@ async function runBalance(args, deps) {
|
|
|
1649
1682
|
requireUplink: false
|
|
1650
1683
|
});
|
|
1651
1684
|
const identity = identityReport(ctx);
|
|
1652
|
-
const wallet = ctx.money ? await ctx.money.walletChainBalances() : [];
|
|
1653
1685
|
const store = new ChannelMapStore(resolveChannelPaths(env));
|
|
1654
1686
|
const channels = store.list().filter((record) => record.identity === identity.pubkey).map((record) => {
|
|
1655
1687
|
const watermark = store.readWatermark(record.channelId);
|
|
1656
1688
|
const deposited = record.depositTotal;
|
|
1657
1689
|
const claimed = watermark?.cumulativeAmount;
|
|
1658
1690
|
let available = null;
|
|
1691
|
+
let overdrawn = null;
|
|
1659
1692
|
if (deposited !== void 0 && claimed !== void 0) {
|
|
1660
1693
|
const remaining = BigInt(deposited) - BigInt(claimed);
|
|
1661
1694
|
available = (remaining > 0n ? remaining : 0n).toString();
|
|
1695
|
+
overdrawn = (remaining < 0n ? -remaining : 0n).toString();
|
|
1662
1696
|
}
|
|
1663
1697
|
return {
|
|
1664
1698
|
channelId: record.channelId,
|
|
@@ -1669,10 +1703,25 @@ async function runBalance(args, deps) {
|
|
|
1669
1703
|
depositTotal: deposited ?? null,
|
|
1670
1704
|
cumulativeClaimed: claimed ?? null,
|
|
1671
1705
|
nonce: watermark?.nonce ?? null,
|
|
1672
|
-
available
|
|
1706
|
+
available,
|
|
1707
|
+
overdrawn
|
|
1673
1708
|
};
|
|
1674
1709
|
});
|
|
1710
|
+
let wallet = [];
|
|
1711
|
+
let walletError;
|
|
1712
|
+
if (ctx.money) {
|
|
1713
|
+
const money = ctx.money;
|
|
1714
|
+
try {
|
|
1715
|
+
wallet = await readWalletBounded(
|
|
1716
|
+
() => money.walletChainBalances(),
|
|
1717
|
+
walletReadTimeoutMs(env)
|
|
1718
|
+
);
|
|
1719
|
+
} catch (err) {
|
|
1720
|
+
walletError = err instanceof Error ? err : new Error(String(err));
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1675
1723
|
if (json) {
|
|
1724
|
+
if (walletError) return emitCliError(io2, json, "balance", walletError);
|
|
1676
1725
|
io2.emitJson({
|
|
1677
1726
|
command: "balance",
|
|
1678
1727
|
identity,
|
|
@@ -1684,10 +1733,10 @@ async function runBalance(args, deps) {
|
|
|
1684
1733
|
io2.out(renderIdentityLine(identity));
|
|
1685
1734
|
io2.out("");
|
|
1686
1735
|
io2.out("Wallet (on-chain):");
|
|
1687
|
-
if (
|
|
1688
|
-
io2.out(
|
|
1689
|
-
|
|
1690
|
-
);
|
|
1736
|
+
if (walletError) {
|
|
1737
|
+
io2.out(` wallet balances unavailable \u2014 ${walletError.message}`);
|
|
1738
|
+
} else if (wallet.length === 0) {
|
|
1739
|
+
io2.out(" (no chain configured for this identity \u2014 nothing to read)");
|
|
1691
1740
|
}
|
|
1692
1741
|
for (const chain of wallet) {
|
|
1693
1742
|
io2.out(` ${chain.chainKey.padEnd(11)} ${chain.address}`);
|
|
@@ -1715,8 +1764,13 @@ async function runBalance(args, deps) {
|
|
|
1715
1764
|
io2.out(
|
|
1716
1765
|
` ${c.channelId} [${c.status}] deposited ${c.depositTotal ?? "?"} claimed ${c.cumulativeClaimed ?? "?"} available ${c.available ?? "?"} (${c.chain} \u2192 ${c.destination})`
|
|
1717
1766
|
);
|
|
1767
|
+
if (c.overdrawn !== null && BigInt(c.overdrawn) > 0n) {
|
|
1768
|
+
io2.out(
|
|
1769
|
+
` OVERDRAWN by ${c.overdrawn}: cumulative claims exceed the recorded deposit \u2014 the peer accepted claims only partially covered by on-chain collateral. Top up with \`rig channel open --deposit <amount>\`.`
|
|
1770
|
+
);
|
|
1771
|
+
}
|
|
1718
1772
|
}
|
|
1719
|
-
return 0;
|
|
1773
|
+
return walletError ? 1 : 0;
|
|
1720
1774
|
} catch (err) {
|
|
1721
1775
|
return emitCliError(io2, json, "balance", err);
|
|
1722
1776
|
} finally {
|