mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-06-02 15:11:29 +00:00
feat: added langchain class, refactored methods to use tlb parser, wrote and ran tests
This commit is contained in:
@@ -1,42 +1,22 @@
|
||||
import { Buffer } from "buffer";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import {
|
||||
getNameAccountKeySync,
|
||||
NAME_PROGRAM_ID,
|
||||
} from "@bonfida/spl-name-service";
|
||||
import { TldParser } from "@onsol/tldparser";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
|
||||
/**
|
||||
* Resolve a domain to its public key
|
||||
* Resolve all domains for a given agent and domain
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param domain Domain name to resolve
|
||||
* @returns Associated public key or null if not found
|
||||
* @returns Promise resolving to the domain or undefined if not found
|
||||
*/
|
||||
export async function resolveAllDomains(
|
||||
agent: SolanaAgentKit,
|
||||
domain: string
|
||||
): Promise<PublicKey | null> {
|
||||
): Promise<PublicKey | undefined> {
|
||||
try {
|
||||
// Convert domain name to buffer for hashing
|
||||
const hashedDomain = Buffer.from(domain);
|
||||
|
||||
// Get the name account key using the new sync method
|
||||
const nameAccountKey = getNameAccountKeySync(
|
||||
hashedDomain,
|
||||
undefined, // nameClass
|
||||
undefined // nameParent
|
||||
);
|
||||
|
||||
// Get the account info to retrieve the owner
|
||||
const owner = await agent.connection.getAccountInfo(nameAccountKey);
|
||||
|
||||
if (!owner) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// The owner's public key is stored in the data buffer starting at offset 32
|
||||
return new PublicKey(owner.data.slice(32, 64));
|
||||
let tld = new TldParser(agent.connection).getOwnerFromDomainTld(domain)
|
||||
return tld;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Domain resolution failed: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user