strict tsconfig, reverse resolve

This commit is contained in:
stjet
2025-02-21 03:39:47 +00:00
parent 9afbfbbbfe
commit 7d7fe6da88
75 changed files with 394 additions and 149 deletions

View File

@@ -158,9 +158,21 @@
<input id="issue-tld" type="text" placeholder="test"/>
<br>
<button onclick="all_issued()">Find all issued by TLD</button>
<p id="issue-total"></p>
<ul id="all-issued">
</ul>
</div>
<div>
<h3>Reverse Resolve</h3>
<label for="reverse-tld">TLD Name (no dot):</label>
<input id="reverse-tld" type="text" placeholder="test"/>
<br>
<label for="reverse-address">Address:</label>
<input id="reverse-address" type="text" placeholder="ban_abcd..."/>
<br>
<button onclick="reverse_resolve()">Find Domains for Address</button>
<ul id="reverse-resolved">
</ul>
</div>
</div>
@@ -282,6 +294,7 @@
li.appendChild(a);
ul.appendChild(li);
}
d.g("issue-total").innerText = `${all.length} Issued`;
}
async function issue() {
@@ -340,6 +353,38 @@
}
}
async function find_bns_domains_for_account(account, tld) {
const resolver = new bns.Resolver(rpc2, tld_mapping);
//search up to 50 receivable blocks, find the what are likely to be Domain Resolver blocks
let receivable_resp = (await rpc.get_account_receivable(account, 50, "4224", true)).blocks;
let possible_domain_accounts = Object.keys(receivable_resp).filter((hash) => receivable_resp[hash].amount === "4224").map((hash) => receivable_resp[hash].source);
//now look through the last 500 received transactions
possible_domain_accounts.push(...(await rpc.get_account_history(account, 500)).history.filter((info) => info.type === "receive" && info.amount === "4224").map((info) => info.account));
let domains = [];
//now fetch those domains!
for (const possible of possible_domain_accounts) {
try {
let domain = await resolver.resolve_backwards_ish(possible, tld);
if (domain) domains.push(domain);
} catch (_) {}
}
return domains;
}
async function reverse_resolve() {
let ul = d.g("reverse-resolved");
ul.innerHTML = "";
const a = d.g("reverse-address").value;
const n = d.g("reverse-tld").value;
if (!tld_mapping[n]) return;
const all = await find_bns_domains_for_account(a, n);
for (const domain of all) {
let li = d.createElement("LI");
li.textContent = domain.name;
ul.appendChild(li);
}
}
function seed_proceed() {
d.g("start-2").style.display = "none";
d.g("main").style.display = "grid";