mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-24 15:10:46 +00:00
feat: tool description + types
This commit is contained in:
@@ -3,18 +3,16 @@ import { SolanaAgentKit } from "../index";
|
||||
import { getAllTld } from "@onsol/tldparser";
|
||||
|
||||
/**
|
||||
* Get all active top-level domains (TLDs) in the Solana name service
|
||||
* Get all active top-level domains (TLDs) in the AllDomains Name Service
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @returns Array of active TLD strings
|
||||
*/
|
||||
export async function getAllDomainsTLDs(
|
||||
agent: SolanaAgentKit
|
||||
): Promise<Array<{
|
||||
tld: String;
|
||||
parentAccount: PublicKey;
|
||||
}>> {
|
||||
): Promise<String[]> {
|
||||
try {
|
||||
return getAllTld(agent.connection)
|
||||
let tlds = await getAllTld(agent.connection)
|
||||
return tlds.map((tld) => tld.tld)
|
||||
} catch (error: any) {
|
||||
throw new Error(`Failed to fetch TLDs: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -11,9 +11,10 @@ import { NameAccountAndDomain, TldParser } from "@onsol/tldparser";
|
||||
export async function getOwnedAllDomains(
|
||||
agent: SolanaAgentKit,
|
||||
owner:PublicKey
|
||||
): Promise<NameAccountAndDomain[]> {
|
||||
): Promise<string[]> {
|
||||
try {
|
||||
return new TldParser(agent.connection).getParsedAllUserDomains(owner);
|
||||
let domains = await new TldParser(agent.connection).getParsedAllUserDomains(owner);
|
||||
return domains.map((domain) => domain.domain)
|
||||
} catch (error: any) {
|
||||
throw new Error(`Failed to fetch owned domains: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { NameAccountAndDomain, TldParser } from "@onsol/tldparser";
|
||||
import { TldParser } from "@onsol/tldparser";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
/**
|
||||
* Get all domains owned by an address for a specific TLD
|
||||
* @param agent SolanaAgentKit instance
|
||||
@@ -10,13 +9,14 @@ import { PublicKey } from "@solana/web3.js";
|
||||
export async function getOwnedDomainsForTLD(
|
||||
agent: SolanaAgentKit,
|
||||
tld: string
|
||||
): Promise<NameAccountAndDomain[]> {
|
||||
): Promise<string[]> {
|
||||
try {
|
||||
return new TldParser(agent.connection)
|
||||
let domains = await new TldParser(agent.connection)
|
||||
.getParsedAllUserDomainsFromTld(
|
||||
agent.wallet_address,
|
||||
tld
|
||||
)
|
||||
return domains.map((domain) => domain.domain)
|
||||
} catch (error: any) {
|
||||
throw new Error(`Failed to fetch domains for TLD: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -13,10 +13,18 @@ export async function resolveAllDomains(
|
||||
domain: string
|
||||
): Promise<PublicKey | undefined> {
|
||||
try {
|
||||
let tld = new TldParser(agent.connection).getOwnerFromDomainTld(domain)
|
||||
return tld;
|
||||
console.log("domain", domain);
|
||||
let tld = await new TldParser(agent.connection).getOwnerFromDomainTld(
|
||||
domain
|
||||
);
|
||||
console.log("tld", tld);
|
||||
return tld;
|
||||
} catch (error: any) {
|
||||
// console.log("error", error.);
|
||||
|
||||
if(error.message.includes("Cannot read properties of undefined (reading 'owner')")) {
|
||||
return undefined
|
||||
}
|
||||
throw new Error(`Domain resolution failed: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user