UNPKG

@bithomp/xrpl-api

Version:

A Bithomp JavaScript/TypeScript library for interacting with the XRP Ledger

106 lines (105 loc) 3.51 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.getAccountInfo = getAccountInfo; exports.getAccountInfoData = getAccountInfoData; exports.isActivated = isActivated; const Client = __importStar(require("../client")); const account_info_1 = require("../parse/ledger/account-info"); const common_1 = require("../common"); async function getAccountInfo(account, options = {}) { const connection = options.connection || Client.findConnection(); if (!connection) { throw new Error("There is no connection"); } const response = await connection.request({ command: "account_info", account, ledger_index: options.ledgerIndex || "validated", signer_lists: !!options.signerLists, }); if (!response) { return { account, status: "error", error: "invalidResponse", }; } if (response.error) { const { error, error_code, error_message, error_exception, status, validated } = response; return (0, common_1.removeUndefined)({ account, error, error_code, error_message, error_exception, status, validated, }); } const result = response.result; if (!result) { return { account, status: "error", error: "invalidResponse", }; } if (result.signer_lists) { result.account_data.signer_lists = result.signer_lists.slice(); } return result; } async function getAccountInfoData(account, options = {}) { const formatted = options.formatted === true; const response = await getAccountInfo(account, options); if ("error" in response) { return response; } if (formatted) { return (0, account_info_1.parseAccountInfoData)(response); } return response.account_data; } async function isActivated(account) { const response = await getAccountInfo(account); if (!response) { return false; } if ("error" in response) { return false; } return true; }