UNPKG

@ar.io/sdk

Version:

[![codecov](https://codecov.io/gh/ar-io/ar-io-sdk/graph/badge.svg?token=7dXKcT7dJy)](https://codecov.io/gh/ar-io/ar-io-sdk)

197 lines (196 loc) 8.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getGateway = getGateway; exports.listGateways = listGateways; exports.listAllDelegatesCLICommand = listAllDelegatesCLICommand; exports.getGatewayDelegates = getGatewayDelegates; exports.getDelegations = getDelegations; exports.getAllowedDelegates = getAllowedDelegates; exports.getArNSRecord = getArNSRecord; exports.listArNSRecords = listArNSRecords; exports.getArNSReservedName = getArNSReservedName; exports.listArNSReservedNames = listArNSReservedNames; exports.getArNSReturnedName = getArNSReturnedName; exports.listArNSReturnedNames = listArNSReturnedNames; exports.getEpoch = getEpoch; exports.getPrescribedObservers = getPrescribedObservers; exports.getPrescribedNames = getPrescribedNames; exports.getTokenCost = getTokenCost; exports.getCostDetails = getCostDetails; exports.getPrimaryName = getPrimaryName; exports.getGatewayVaults = getGatewayVaults; exports.getAllGatewayVaults = getAllGatewayVaults; exports.getVault = getVault; exports.resolveArNSName = resolveArNSName; const token_js_1 = require("../../types/token.js"); const utils_js_1 = require("../utils.js"); async function getGateway(o) { const address = (0, utils_js_1.requiredAddressFromOptions)(o); const gateway = await (0, utils_js_1.readARIOFromOptions)(o).getGateway({ address, }); return gateway ?? { message: `No gateway found for address ${address}` }; } async function listGateways(o) { const gateways = await (0, utils_js_1.readARIOFromOptions)(o).getGateways((0, utils_js_1.paginationParamsFromOptions)(o)); return gateways.items.length ? gateways : { message: 'No gateways found' }; } async function listAllDelegatesCLICommand(o) { const delegates = await (0, utils_js_1.readARIOFromOptions)(o).getAllDelegates((0, utils_js_1.paginationParamsFromOptions)(o)); return delegates.items.length ? delegates : { message: 'No delegates found' }; } async function getGatewayDelegates(o) { const address = (0, utils_js_1.requiredAddressFromOptions)(o); const result = await (0, utils_js_1.readARIOFromOptions)(o).getGatewayDelegates({ address, ...(0, utils_js_1.paginationParamsFromOptions)(o), }); return result.items?.length ? result : { message: `No delegates found for gateway ${address}`, }; } async function getDelegations(o) { const address = (0, utils_js_1.requiredAddressFromOptions)(o); const result = await (0, utils_js_1.readARIOFromOptions)(o).getDelegations({ address, ...(0, utils_js_1.paginationParamsFromOptions)(o), }); return result.items?.length ? result : { message: `No delegations found for address ${address}`, }; } async function getAllowedDelegates(o) { const address = (0, utils_js_1.requiredAddressFromOptions)(o); const result = await (0, utils_js_1.readARIOFromOptions)(o).getAllowedDelegates({ address, ...(0, utils_js_1.paginationParamsFromOptions)(o), }); return result.items?.length ? result : { message: `No allow list found for gateway delegate ${address}`, }; } async function getArNSRecord(o) { const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name'); return ((await (0, utils_js_1.readARIOFromOptions)(o).getArNSRecord({ name, })) ?? { message: `No record found for name ${name}` }); } async function listArNSRecords(o) { const records = await (0, utils_js_1.readARIOFromOptions)(o).getArNSRecords((0, utils_js_1.paginationParamsFromOptions)(o)); return records.items.length ? records : { message: 'No records found' }; } async function getArNSReservedName(o) { const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name'); return ((await (0, utils_js_1.readARIOFromOptions)(o).getArNSReservedName({ name, })) ?? { message: `No reserved name found for name ${name}` }); } async function listArNSReservedNames(o) { const reservedNames = await (0, utils_js_1.readARIOFromOptions)(o).getArNSReservedNames((0, utils_js_1.paginationParamsFromOptions)(o)); return reservedNames.items.length ? reservedNames : { message: 'No reserved names found' }; } async function getArNSReturnedName(o) { const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name'); const result = await (0, utils_js_1.readARIOFromOptions)(o).getArNSReturnedName({ name }); return result ?? { message: `No returned name found for name ${name}` }; } async function listArNSReturnedNames(o) { const returnedNames = await (0, utils_js_1.readARIOFromOptions)(o).getArNSReturnedNames((0, utils_js_1.paginationParamsFromOptions)(o)); return returnedNames.items.length ? returnedNames : { message: 'No returned names found' }; } async function getEpoch(o) { const epoch = await (0, utils_js_1.readARIOFromOptions)(o).getEpoch((0, utils_js_1.epochInputFromOptions)(o)); return epoch ?? { message: `No epoch found for provided input` }; } async function getPrescribedObservers(o) { const epoch = (0, utils_js_1.epochInputFromOptions)(o); const result = await (0, utils_js_1.readARIOFromOptions)(o).getPrescribedObservers(epoch); return (result ?? { message: `No prescribed observers found for epoch ${epoch}` }); } async function getPrescribedNames(o) { const epoch = (0, utils_js_1.epochInputFromOptions)(o); const result = await (0, utils_js_1.readARIOFromOptions)(o).getPrescribedNames((0, utils_js_1.epochInputFromOptions)(o)); return result ?? { message: `No prescribed names found for epoch ${epoch}` }; } async function getTokenCost(o) { const tokenCost = await (0, utils_js_1.readARIOFromOptions)(o).getTokenCost((0, utils_js_1.getTokenCostParamsFromOptions)(o)); const output = { mARIOTokenCost: tokenCost, message: `The cost of the provided action is ${(0, utils_js_1.formatARIOWithCommas)(new token_js_1.mARIOToken(tokenCost).toARIO())} ARIO`, }; return output; } async function getCostDetails(o) { const costDetails = await (0, utils_js_1.readARIOFromOptions)(o).getCostDetails({ ...(0, utils_js_1.getTokenCostParamsFromOptions)(o), fundFrom: (0, utils_js_1.fundFromFromOptions)(o), }); const output = { ...costDetails, message: `The cost of the provided action is ${(0, utils_js_1.formatARIOWithCommas)(new token_js_1.mARIOToken(costDetails.tokenCost).toARIO())} ARIO${costDetails.fundingPlan && costDetails.fundingPlan.shortfall > 0 ? `. Insufficient funds for action. There is a shortfall of ${(0, utils_js_1.formatARIOWithCommas)(new token_js_1.mARIOToken(costDetails.fundingPlan.shortfall).toARIO())} ARIO` : ''}`, }; return output; } async function getPrimaryName(o) { const address = (0, utils_js_1.addressFromOptions)(o); const name = o.name; const params = name !== undefined ? { name } : address !== undefined ? { address } : undefined; if (params === undefined) { throw new Error('Either --address or --name is required'); } const result = await (0, utils_js_1.readARIOFromOptions)(o).getPrimaryName(params); return (result ?? { message: `No primary name found`, }); } async function getGatewayVaults(o) { const address = (0, utils_js_1.requiredAddressFromOptions)(o); const result = await (0, utils_js_1.readARIOFromOptions)(o).getGatewayVaults({ address, ...(0, utils_js_1.paginationParamsFromOptions)(o), }); return result.items?.length ? result : { message: `No vaults found for gateway ${address}`, }; } async function getAllGatewayVaults(o) { const result = await (0, utils_js_1.readARIOFromOptions)(o).getAllGatewayVaults((0, utils_js_1.paginationParamsFromOptions)(o)); return result.items?.length ? result : { message: `No vaults found`, }; } async function getVault(o) { return (0, utils_js_1.readARIOFromOptions)(o) .getVault({ address: (0, utils_js_1.requiredAddressFromOptions)(o), vaultId: (0, utils_js_1.requiredStringFromOptions)(o, 'vaultId'), }) .then((r) => r ?? { message: `No vault found for provided address and vault ID`, }); } async function resolveArNSName(o) { const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name'); const result = await (0, utils_js_1.readARIOFromOptions)(o).resolveArNSName({ name }); return result ?? { message: `No record found for name ${name}` }; }