UNPKG

@solana/spl-name-service

Version:

SPL Name Service JavaScript API

44 lines 2.08 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.NameRegistryState = void 0; const web3_js_1 = require("@solana/web3.js"); const borsh_1 = require("borsh"); class NameRegistryState { constructor(obj) { this.parentName = new web3_js_1.PublicKey(obj.parentName); this.owner = new web3_js_1.PublicKey(obj.owner); this.class = new web3_js_1.PublicKey(obj.class); } static retrieve(connection, nameAccountKey) { return __awaiter(this, void 0, void 0, function* () { var _a; const nameAccount = yield connection.getAccountInfo(nameAccountKey, 'processed'); if (!nameAccount) { throw new Error('Invalid name account provided'); } const deserialized = (0, borsh_1.deserialize)(this.schema, nameAccount.data); const res = new NameRegistryState(deserialized); res.data = (_a = nameAccount.data) === null || _a === void 0 ? void 0 : _a.slice(this.HEADER_LEN); return res; }); } } exports.NameRegistryState = NameRegistryState; NameRegistryState.HEADER_LEN = 96; NameRegistryState.schema = { struct: { parentName: { array: { type: 'u8', len: 32 } }, owner: { array: { type: 'u8', len: 32 } }, class: { array: { type: 'u8', len: 32 } }, }, }; //# sourceMappingURL=state.js.map