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)

182 lines (181 loc) 7.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buyRecordCLICommand = buyRecordCLICommand; exports.upgradeRecordCLICommand = upgradeRecordCLICommand; exports.extendLeaseCLICommand = extendLeaseCLICommand; exports.increaseUndernameLimitCLICommand = increaseUndernameLimitCLICommand; exports.requestPrimaryNameCLICommand = requestPrimaryNameCLICommand; const utils_js_1 = require("../utils.js"); async function buyRecordCLICommand(o) { const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o); const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name'); const type = (0, utils_js_1.recordTypeFromOptions)(o); const years = (0, utils_js_1.positiveIntegerFromOptions)(o, 'years'); const fundFrom = (0, utils_js_1.fundFromFromOptions)(o); const referrer = (0, utils_js_1.referrerFromOptions)(o); const processId = o.processId; if (processId === undefined) { // TODO: Spawn ANT process, register it to ANT registry, get process ID throw new Error('Process ID must be provided for buy-record'); } if (!o.skipConfirmation) { const existingRecord = await ario.getArNSRecord({ name, }); if (existingRecord !== undefined) { throw new Error(`ArNS Record ${name} is already owned`); } await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({ ario, address: signerAddress, costDetailsParams: { intent: 'Buy-Name', type, name, years, fundFrom, fromAddress: signerAddress, }, }); await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to ${type} the record ${name}?`, o); } return ario.buyRecord({ name: (0, utils_js_1.requiredStringFromOptions)(o, 'name'), processId, type, years, fundFrom: (0, utils_js_1.fundFromFromOptions)(o), paidBy: (0, utils_js_1.stringArrayFromOptions)(o, 'paidBy'), referrer, }, (0, utils_js_1.customTagsFromOptions)(o)); } async function upgradeRecordCLICommand(o) { const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name'); const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o); const fundFrom = (0, utils_js_1.fundFromFromOptions)(o); const referrer = (0, utils_js_1.referrerFromOptions)(o); if (!o.skipConfirmation) { const existingRecord = await ario.getArNSRecord({ name, }); if (existingRecord === undefined) { throw new Error(`ArNS Record ${name} does not exist`); } if (existingRecord.type === 'permabuy') { throw new Error(`ArNS Record ${name} is already a permabuy`); } await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({ ario, address: signerAddress, costDetailsParams: { intent: 'Upgrade-Name', name, fundFrom, fromAddress: signerAddress, }, }); await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to upgrade the lease of ${name} to a permabuy?`, o); } return ario.upgradeRecord({ name, fundFrom, paidBy: (0, utils_js_1.stringArrayFromOptions)(o, 'paidBy'), referrer, }); } async function extendLeaseCLICommand(o) { const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name'); const years = (0, utils_js_1.requiredPositiveIntegerFromOptions)(o, 'years'); const fundFrom = (0, utils_js_1.fundFromFromOptions)(o); const referrer = (0, utils_js_1.referrerFromOptions)(o); const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o); if (!o.skipConfirmation) { const existingRecord = await ario.getArNSRecord({ name, }); if (existingRecord === undefined) { throw new Error(`ArNS Record ${name} does not exist`); } if (existingRecord.type === 'permabuy') { throw new Error(`ArNS Record ${name} is a permabuy and cannot be extended`); } await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({ ario: ario, address: signerAddress, costDetailsParams: { intent: 'Extend-Lease', name, years, fundFrom, fromAddress: signerAddress, }, }); await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to extend the lease of ${name} by ${years}?`, o); } return ario.extendLease({ name, years, paidBy: (0, utils_js_1.stringArrayFromOptions)(o, 'paidBy'), referrer, }, (0, utils_js_1.customTagsFromOptions)(o)); } async function increaseUndernameLimitCLICommand(o) { const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name'); const increaseCount = (0, utils_js_1.requiredPositiveIntegerFromOptions)(o, 'increaseCount'); const fundFrom = (0, utils_js_1.fundFromFromOptions)(o); const referrer = (0, utils_js_1.referrerFromOptions)(o); const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o); if (!o.skipConfirmation) { const existingRecord = await ario.getArNSRecord({ name, }); if (existingRecord === undefined) { throw new Error(`ArNS Record ${name} does not exist`); } await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({ ario, address: signerAddress, costDetailsParams: { intent: 'Increase-Undername-Limit', name, quantity: increaseCount, fundFrom, fromAddress: signerAddress, }, }); await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to increase the undername limit of ${name} by ${increaseCount}?`, o); } return ario.increaseUndernameLimit({ name, increaseCount, paidBy: (0, utils_js_1.stringArrayFromOptions)(o, 'paidBy'), referrer, }, (0, utils_js_1.customTagsFromOptions)(o)); } async function requestPrimaryNameCLICommand(o) { const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o); const fundFrom = (0, utils_js_1.fundFromFromOptions)(o); const referrer = (0, utils_js_1.referrerFromOptions)(o); const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name'); if (!o.skipConfirmation) { // TODO: Assert name requested is not already owned? // TODO: More assertions? await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({ ario, address: signerAddress, costDetailsParams: { intent: 'Primary-Name-Request', name, fromAddress: signerAddress, fundFrom, }, }); await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to request the primary name ${name}?`, o); } return ario.requestPrimaryName({ name, fundFrom, paidBy: (0, utils_js_1.stringArrayFromOptions)(o, 'paidBy'), referrer, }, (0, utils_js_1.customTagsFromOptions)(o)); }