@toon-protocol/rig 2.13.0 → 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
|
@@ -46,6 +46,7 @@ import {
|
|
|
46
46
|
minaPresetForChain
|
|
47
47
|
} from "../chunk-ACTH6ISJ.js";
|
|
48
48
|
import {
|
|
49
|
+
ARWEAVE_GATEWAYS,
|
|
49
50
|
COMMENT_KIND,
|
|
50
51
|
authorizedStatusAuthors,
|
|
51
52
|
buildComment,
|
|
@@ -560,6 +561,8 @@ var DEFAULT_RIG_WEB_BUNDLE = {
|
|
|
560
561
|
var RIG_WEB_TX_ENV = "RIG_WEB_TX";
|
|
561
562
|
var RIG_WEB_ENTRY_JS_ENV = "RIG_WEB_ENTRY_JS";
|
|
562
563
|
var RIG_WEB_ENTRY_CSS_ENV = "RIG_WEB_ENTRY_CSS";
|
|
564
|
+
var DEFAULT_RIG_WEB_GATEWAY = "https://arweave.net";
|
|
565
|
+
var RIG_WEB_GATEWAY_ENV = "RIG_WEB_GATEWAY";
|
|
563
566
|
var DEFAULT_RIG_WEB_URL = "https://toon-protocol.github.io/toon-client";
|
|
564
567
|
var RIG_WEB_URL_ENV = "RIG_WEB_URL";
|
|
565
568
|
function repoHashRoute(options) {
|
|
@@ -1079,7 +1082,7 @@ function loadPaidSession(deps, relayUrl) {
|
|
|
1079
1082
|
});
|
|
1080
1083
|
}
|
|
1081
1084
|
var defaultLoadStandalone = async (options) => {
|
|
1082
|
-
const mod = await import("../standalone-mode-
|
|
1085
|
+
const mod = await import("../standalone-mode-RG4PGALC.js");
|
|
1083
1086
|
return mod.createStandaloneContext(options);
|
|
1084
1087
|
};
|
|
1085
1088
|
function identityReport(ctx) {
|
|
@@ -1215,11 +1218,14 @@ function parsePushArgs(args) {
|
|
|
1215
1218
|
return flags;
|
|
1216
1219
|
}
|
|
1217
1220
|
function pointerGateway(env) {
|
|
1218
|
-
return (env["RIG_ARWEAVE_GATEWAY"] ?? "https://
|
|
1221
|
+
return (env["RIG_ARWEAVE_GATEWAY"] ?? "https://ar-io.dev").replace(
|
|
1219
1222
|
/\/+$/,
|
|
1220
1223
|
""
|
|
1221
1224
|
);
|
|
1222
1225
|
}
|
|
1226
|
+
function mirrorGateway(primary) {
|
|
1227
|
+
return ARWEAVE_GATEWAYS.find((g) => g !== primary);
|
|
1228
|
+
}
|
|
1223
1229
|
function planRigPointer(args) {
|
|
1224
1230
|
const html = generateRigPointerHtml({
|
|
1225
1231
|
bundle: {
|
|
@@ -1227,7 +1233,7 @@ function planRigPointer(args) {
|
|
|
1227
1233
|
entryJs: args.env[RIG_WEB_ENTRY_JS_ENV] ?? DEFAULT_RIG_WEB_BUNDLE.entryJs,
|
|
1228
1234
|
entryCss: args.env[RIG_WEB_ENTRY_CSS_ENV] ?? DEFAULT_RIG_WEB_BUNDLE.entryCss
|
|
1229
1235
|
},
|
|
1230
|
-
gateway:
|
|
1236
|
+
gateway: (args.env[RIG_WEB_GATEWAY_ENV] ?? DEFAULT_RIG_WEB_GATEWAY).replace(/\/+$/, ""),
|
|
1231
1237
|
rigWebUrl: args.env[RIG_WEB_URL_ENV] ?? DEFAULT_RIG_WEB_URL,
|
|
1232
1238
|
relay: args.relay,
|
|
1233
1239
|
ownerNpub: hexToNpub(args.ownerPubkey),
|
|
@@ -1428,6 +1434,12 @@ async function runPush(args, deps) {
|
|
|
1428
1434
|
io2.out(
|
|
1429
1435
|
`Rig page: ${rigPage2.url}` + (rigPage2.status === "published" ? ` paid ${rigPage2.feePaid}` : "") + " (renders this repo from Arweave)"
|
|
1430
1436
|
);
|
|
1437
|
+
const mirror = rigPage2.txId ? mirrorGateway(gateway) : void 0;
|
|
1438
|
+
if (mirror) {
|
|
1439
|
+
io2.out(
|
|
1440
|
+
` also: ${mirror}/${rigPage2.txId} (same page; gateways index fresh uploads at different speeds)`
|
|
1441
|
+
);
|
|
1442
|
+
}
|
|
1431
1443
|
} else if (rigPage2.detail) {
|
|
1432
1444
|
io2.err(`rig page: ${rigPage2.detail}`);
|
|
1433
1445
|
}
|
|
@@ -1606,6 +1618,39 @@ function formatUnits(amount, decimals) {
|
|
|
1606
1618
|
function renderAmount(a) {
|
|
1607
1619
|
return `${a.symbol ?? "token"} ${formatUnits(a.amount, a.decimals)}`;
|
|
1608
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
|
+
}
|
|
1609
1654
|
async function runBalance(args, deps) {
|
|
1610
1655
|
const { io: io2, env } = deps;
|
|
1611
1656
|
let json = false;
|
|
@@ -1637,16 +1682,17 @@ async function runBalance(args, deps) {
|
|
|
1637
1682
|
requireUplink: false
|
|
1638
1683
|
});
|
|
1639
1684
|
const identity = identityReport(ctx);
|
|
1640
|
-
const wallet = ctx.money ? await ctx.money.walletChainBalances() : [];
|
|
1641
1685
|
const store = new ChannelMapStore(resolveChannelPaths(env));
|
|
1642
1686
|
const channels = store.list().filter((record) => record.identity === identity.pubkey).map((record) => {
|
|
1643
1687
|
const watermark = store.readWatermark(record.channelId);
|
|
1644
1688
|
const deposited = record.depositTotal;
|
|
1645
1689
|
const claimed = watermark?.cumulativeAmount;
|
|
1646
1690
|
let available = null;
|
|
1691
|
+
let overdrawn = null;
|
|
1647
1692
|
if (deposited !== void 0 && claimed !== void 0) {
|
|
1648
1693
|
const remaining = BigInt(deposited) - BigInt(claimed);
|
|
1649
1694
|
available = (remaining > 0n ? remaining : 0n).toString();
|
|
1695
|
+
overdrawn = (remaining < 0n ? -remaining : 0n).toString();
|
|
1650
1696
|
}
|
|
1651
1697
|
return {
|
|
1652
1698
|
channelId: record.channelId,
|
|
@@ -1657,10 +1703,25 @@ async function runBalance(args, deps) {
|
|
|
1657
1703
|
depositTotal: deposited ?? null,
|
|
1658
1704
|
cumulativeClaimed: claimed ?? null,
|
|
1659
1705
|
nonce: watermark?.nonce ?? null,
|
|
1660
|
-
available
|
|
1706
|
+
available,
|
|
1707
|
+
overdrawn
|
|
1661
1708
|
};
|
|
1662
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
|
+
}
|
|
1663
1723
|
if (json) {
|
|
1724
|
+
if (walletError) return emitCliError(io2, json, "balance", walletError);
|
|
1664
1725
|
io2.emitJson({
|
|
1665
1726
|
command: "balance",
|
|
1666
1727
|
identity,
|
|
@@ -1672,10 +1733,10 @@ async function runBalance(args, deps) {
|
|
|
1672
1733
|
io2.out(renderIdentityLine(identity));
|
|
1673
1734
|
io2.out("");
|
|
1674
1735
|
io2.out("Wallet (on-chain):");
|
|
1675
|
-
if (
|
|
1676
|
-
io2.out(
|
|
1677
|
-
|
|
1678
|
-
);
|
|
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)");
|
|
1679
1740
|
}
|
|
1680
1741
|
for (const chain of wallet) {
|
|
1681
1742
|
io2.out(` ${chain.chainKey.padEnd(11)} ${chain.address}`);
|
|
@@ -1703,8 +1764,13 @@ async function runBalance(args, deps) {
|
|
|
1703
1764
|
io2.out(
|
|
1704
1765
|
` ${c.channelId} [${c.status}] deposited ${c.depositTotal ?? "?"} claimed ${c.cumulativeClaimed ?? "?"} available ${c.available ?? "?"} (${c.chain} \u2192 ${c.destination})`
|
|
1705
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
|
+
}
|
|
1706
1772
|
}
|
|
1707
|
-
return 0;
|
|
1773
|
+
return walletError ? 1 : 0;
|
|
1708
1774
|
} catch (err) {
|
|
1709
1775
|
return emitCliError(io2, json, "balance", err);
|
|
1710
1776
|
} finally {
|
|
@@ -7035,7 +7101,7 @@ function writeSiteRecord(env, record) {
|
|
|
7035
7101
|
|
|
7036
7102
|
// src/cli/site.ts
|
|
7037
7103
|
var MANIFEST_CONTENT_TYPE = "application/x.arweave-manifest+json";
|
|
7038
|
-
var DEFAULT_GATEWAY = "https://
|
|
7104
|
+
var DEFAULT_GATEWAY = "https://ar-io.dev";
|
|
7039
7105
|
var SITE_USAGE = `Usage: rig site <publish|url> [ref] [options]
|
|
7040
7106
|
|
|
7041
7107
|
Serve a pushed repo as a permanent, path-routed website. \`rig push\` already
|