Skip to content

Commit

Permalink
export getDomainMint and SOL record resolve fns
Browse files Browse the repository at this point in the history
  • Loading branch information
dr497 committed Jan 19, 2024
1 parent 10fdcba commit e8b7232
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from "./twitter_bindings";
export * from "./utils";
export * from "./instructions";
export * from "./nft";
export { getDomainMint } from "./nft/name-tokenizer";
export * from "./favorite-domain";
export * from "./constants";
export * from "./int";
Expand Down
9 changes: 4 additions & 5 deletions js/src/nft/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
NftRecord,
getRecordFromMint,
} from "./name-tokenizer";
import { reverseLookupBatch } from "../utils";

/**
* This function can be used to retrieve the owner of a tokenized domain name
Expand All @@ -27,12 +26,12 @@ import { reverseLookupBatch } from "../utils";
*/
export const retrieveNftOwner = async (
connection: Connection,
nameAccount: PublicKey
nameAccount: PublicKey,
) => {
try {
const [mint] = await PublicKey.findProgramAddress(
[MINT_PREFIX, nameAccount.toBuffer()],
NAME_TOKENIZER_ID
NAME_TOKENIZER_ID,
);

const mintInfo = await getMint(connection, mint);
Expand Down Expand Up @@ -91,7 +90,7 @@ export const retrieveNfts = async (connection: Connection) => {
});
const offset = 1 + 1 + 32 + 32;
return result.map(
(e) => new PublicKey(e.account.data.slice(offset, offset + 32))
(e) => new PublicKey(e.account.data.slice(offset, offset + 32)),
);
};

Expand All @@ -114,7 +113,7 @@ const closure = async (connection: Connection, acc: RawAccount) => {

export const retrieveRecords = async (
connection: Connection,
owner: PublicKey
owner: PublicKey,
) => {
const filters: GetProgramAccountsFilter[] = [
...getFilter(owner.toBase58()),
Expand Down
4 changes: 2 additions & 2 deletions js/src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const resolve = async (connection: Connection, domain: string) => {
return registry.owner;
};

const resolveSolRecordV1 = async (
export const resolveSolRecordV1 = async (
connection: Connection,
owner: PublicKey,
domain: string,
Expand All @@ -87,7 +87,7 @@ const resolveSolRecordV1 = async (
return new PublicKey(solRecord.data.slice(0, 32));
};

const resolveSolRecordV2 = async (
export const resolveSolRecordV2 = async (
connection: Connection,
owner: PublicKey,
domain: string,
Expand Down
14 changes: 12 additions & 2 deletions js/tests/records.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as record from "../src/record";
import { Connection, PublicKey, Transaction } from "@solana/web3.js";
import { Record } from "../src/types/record";
import { createRecordInstruction } from "../src/bindings";
import { resolveSolRecordV1 } from "../src/resolve";

jest.setTimeout(20_000);

Expand Down Expand Up @@ -75,7 +76,7 @@ test("Get multiple records", async () => {
connection,
"🍍",
[Record.Telegram, Record.Github, Record.Backpack],
true
true,
);
expect(records[0]).toBe("@🍍-tg");
expect(records[1]).toBe("@🍍_dev");
Expand All @@ -96,7 +97,7 @@ test("Create", async () => {
Record.A,
"192.168.0.1",
owner,
owner
owner,
);
const tx = new Transaction().add(ix);
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
Expand All @@ -105,3 +106,12 @@ test("Create", async () => {
let res = await connection.simulateTransaction(tx);
expect(res.value.err).toBe(null);
});

test("Check sol record", async () => {
const domain = "wallet-guide-4";
const owner = new PublicKey("Fxuoy3gFjfJALhwkRcuKjRdechcgffUApeYAfMWck6w8");
const result = await resolveSolRecordV1(connection, owner, domain);
expect(result.toBase58()).toBe(
"Hf4daCT4tC2Vy9RCe9q8avT68yAsNJ1dQe6xiQqyGuqZ",
);
});

0 comments on commit e8b7232

Please sign in to comment.