UNPKG

@gorbchain-xyz/chaindecode

Version:

GorbchainSDK V1.3+ - Complete Solana development toolkit with advanced cryptography, messaging, and collaboration features. Build secure applications with blockchain, DeFi, and end-to-end encryption.

124 lines (123 loc) 5.67 kB
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()); }); }; // RPC Account Methods - Our own implementation based on Solana RPC specs import { getGorbchainConfig } from '../utils/gorbchainConfig.js'; /** * Get account information for a given public key */ export function getAccountInfo(connection, pubkey, options) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; const config = getGorbchainConfig(); const rpcUrl = (_a = config.rpcUrl) !== null && _a !== void 0 ? _a : 'https://rpc.gorbchain.xyz'; const response = yield fetch(rpcUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getAccountInfo', params: [ pubkey, { encoding: (_b = options === null || options === void 0 ? void 0 : options.encoding) !== null && _b !== void 0 ? _b : 'base64', commitment: (_c = options === null || options === void 0 ? void 0 : options.commitment) !== null && _c !== void 0 ? _c : 'finalized' } ] }) }); const data = yield response.json(); return (_e = (_d = data.result) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : null; }); } /** * Get multiple account information at once */ export function getMultipleAccounts(connection, pubkeys, options) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; const config = getGorbchainConfig(); const rpcUrl = (_a = config.rpcUrl) !== null && _a !== void 0 ? _a : 'https://rpc.gorbchain.xyz'; const response = yield fetch(rpcUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getMultipleAccounts', params: [ pubkeys, { encoding: (_b = options === null || options === void 0 ? void 0 : options.encoding) !== null && _b !== void 0 ? _b : 'base64', commitment: (_c = options === null || options === void 0 ? void 0 : options.commitment) !== null && _c !== void 0 ? _c : 'finalized' } ] }) }); const data = yield response.json(); return (_e = (_d = data.result) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : []; }); } /** * Get all accounts owned by a specific program */ export function getProgramAccounts(connection, programId, options) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d; const config = getGorbchainConfig(); const rpcUrl = (_a = config.rpcUrl) !== null && _a !== void 0 ? _a : 'https://rpc.gorbchain.xyz'; const response = yield fetch(rpcUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getProgramAccounts', params: [ programId, { encoding: (_b = options === null || options === void 0 ? void 0 : options.encoding) !== null && _b !== void 0 ? _b : 'base64', commitment: (_c = options === null || options === void 0 ? void 0 : options.commitment) !== null && _c !== void 0 ? _c : 'finalized', filters: (options === null || options === void 0 ? void 0 : options.filters) || [] } ] }) }); const data = yield response.json(); return (_d = data.result) !== null && _d !== void 0 ? _d : []; }); } /** * Get the balance of an account in lamports */ export function getBalance(connection, pubkey, commitment) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; const config = getGorbchainConfig(); const rpcUrl = (_a = config.rpcUrl) !== null && _a !== void 0 ? _a : 'https://rpc.gorbchain.xyz'; const response = yield fetch(rpcUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getBalance', params: [ pubkey, { commitment: commitment !== null && commitment !== void 0 ? commitment : 'finalized' } ] }) }); const data = yield response.json(); return ((_b = data.result) === null || _b === void 0 ? void 0 : _b.value) || 0; }); }