2026-07-29 13:54:34 +02:00
|
|
|
// Usage: node src/resolve.js [name] — resolves one name, or lists all.
|
|
|
|
|
import { loadWallet } from "./lib/wallet.js";
|
|
|
|
|
import { buildIndex, resolveName } from "./lib/bns.js";
|
|
|
|
|
|
|
|
|
|
const [name] = process.argv.slice(2);
|
|
|
|
|
const wallet = await loadWallet();
|
|
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
|
const entry = await resolveName(wallet.provider, name);
|
|
|
|
|
console.log(entry ?? `NXDOMAIN: ${name}`);
|
|
|
|
|
} else {
|
|
|
|
|
const index = await buildIndex(wallet.provider);
|
|
|
|
|
if (index.size === 0) console.log("(no names registered yet)");
|
|
|
|
|
for (const e of index.values()) {
|
2026-07-30 08:16:55 +02:00
|
|
|
// `e.name` is the on-chain form: a bare label for .bch, "<label>.<tld>" for
|
|
|
|
|
// anything else. Appending ".bch" unconditionally printed "demo.p2p.bch".
|
|
|
|
|
const display = e.name.includes(".") ? e.name : `${e.name}.bch`;
|
|
|
|
|
console.log(`${display} -> ${JSON.stringify(e.records)} [category ${e.category.slice(0, 12)}…]`);
|
2026-07-29 13:54:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
process.exit(0);
|