@ar.io/sdk 3.1.0-alpha.1 → 3.1.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/web.bundle.min.js +68 -68
- package/lib/cjs/cli/cli.js +19 -69
- package/lib/cjs/cli/commands/arnsPurchaseCommands.js +167 -0
- package/lib/cjs/cli/commands/gatewayWriteCommands.js +8 -4
- package/lib/cjs/cli/commands/readCommands.js +1 -22
- package/lib/cjs/cli/commands/transfer.js +5 -1
- package/lib/cjs/cli/options.js +8 -7
- package/lib/cjs/cli/utils.js +39 -7
- package/lib/cjs/common/contracts/ao-process.js +34 -16
- package/lib/cjs/common/io.js +76 -116
- package/lib/cjs/utils/arweave.js +22 -13
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +21 -71
- package/lib/esm/cli/commands/arnsPurchaseCommands.js +159 -0
- package/lib/esm/cli/commands/gatewayWriteCommands.js +6 -2
- package/lib/esm/cli/commands/readCommands.js +2 -23
- package/lib/esm/cli/commands/transfer.js +6 -2
- package/lib/esm/cli/options.js +7 -6
- package/lib/esm/cli/utils.js +34 -5
- package/lib/esm/common/contracts/ao-process.js +34 -16
- package/lib/esm/common/io.js +77 -117
- package/lib/esm/utils/arweave.js +21 -11
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +22 -0
- package/lib/types/cli/options.d.ts +1 -9
- package/lib/types/cli/types.d.ts +3 -5
- package/lib/types/cli/utils.d.ts +16 -3
- package/lib/types/common/contracts/ao-process.d.ts +1 -0
- package/lib/types/common/io.d.ts +14 -43
- package/lib/types/types/common.d.ts +1 -0
- package/lib/types/types/io.d.ts +16 -10
- package/lib/types/utils/arweave.d.ts +6 -18
- package/lib/types/version.d.ts +1 -1
- package/package.json +2 -2
package/lib/cjs/common/io.js
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ARIOWriteable = exports.ARIOReadable = exports.ARIO = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
4
19
|
const constants_js_1 = require("../constants.js");
|
|
5
20
|
const io_js_1 = require("../types/io.js");
|
|
6
21
|
const ao_js_1 = require("../utils/ao.js");
|
|
7
22
|
const arweave_js_1 = require("../utils/arweave.js");
|
|
8
|
-
const arweave_js_2 = require("./arweave.js");
|
|
9
23
|
const ao_process_js_1 = require("./contracts/ao-process.js");
|
|
10
24
|
const error_js_1 = require("./error.js");
|
|
11
25
|
class ARIO {
|
|
@@ -23,8 +37,8 @@ class ARIO {
|
|
|
23
37
|
exports.ARIO = ARIO;
|
|
24
38
|
class ARIOReadable {
|
|
25
39
|
process;
|
|
26
|
-
|
|
27
|
-
constructor(config
|
|
40
|
+
epochSettings;
|
|
41
|
+
constructor(config) {
|
|
28
42
|
if (!config) {
|
|
29
43
|
this.process = new ao_process_js_1.AOProcess({
|
|
30
44
|
processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
|
|
@@ -41,7 +55,6 @@ class ARIOReadable {
|
|
|
41
55
|
else {
|
|
42
56
|
throw new error_js_1.InvalidContractConfigurationError();
|
|
43
57
|
}
|
|
44
|
-
this.arweave = arweave;
|
|
45
58
|
}
|
|
46
59
|
async getInfo() {
|
|
47
60
|
return this.process.read({
|
|
@@ -53,35 +66,32 @@ class ARIOReadable {
|
|
|
53
66
|
tags: [{ name: 'Action', value: 'Total-Token-Supply' }],
|
|
54
67
|
});
|
|
55
68
|
}
|
|
56
|
-
async
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
async computeEpochIndexForTimestamp(timestamp) {
|
|
70
|
+
const epochSettings = await this.getEpochSettings();
|
|
71
|
+
const epochZeroStartTimestamp = epochSettings.epochZeroStartTimestamp;
|
|
72
|
+
const epochLengthMs = epochSettings.durationMs;
|
|
73
|
+
return Math.floor((timestamp - epochZeroStartTimestamp) / epochLengthMs);
|
|
74
|
+
}
|
|
75
|
+
async computeEpochIndex(params) {
|
|
76
|
+
const epochIndex = params?.epochIndex;
|
|
77
|
+
if (epochIndex !== undefined) {
|
|
78
|
+
return epochIndex.toString();
|
|
79
|
+
}
|
|
80
|
+
const timestamp = params?.timestamp;
|
|
81
|
+
if (timestamp !== undefined) {
|
|
82
|
+
return (await this.computeEpochIndexForTimestamp(timestamp)).toString();
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
async getEpochSettings() {
|
|
87
|
+
return (this.epochSettings ??= await this.process.read({
|
|
88
|
+
tags: [{ name: 'Action', value: 'Epoch-Settings' }],
|
|
89
|
+
}));
|
|
72
90
|
}
|
|
73
91
|
async getEpoch(epoch) {
|
|
74
92
|
const allTags = [
|
|
75
93
|
{ name: 'Action', value: 'Epoch' },
|
|
76
|
-
{
|
|
77
|
-
name: 'Timestamp',
|
|
78
|
-
value: epoch?.timestamp?.toString() ??
|
|
79
|
-
(await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: 'Epoch-Index',
|
|
83
|
-
value: epoch?.epochIndex?.toString(),
|
|
84
|
-
},
|
|
94
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
85
95
|
];
|
|
86
96
|
return this.process.read({
|
|
87
97
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -188,27 +198,13 @@ class ARIOReadable {
|
|
|
188
198
|
}
|
|
189
199
|
async getCurrentEpoch() {
|
|
190
200
|
return this.process.read({
|
|
191
|
-
tags: [
|
|
192
|
-
{ name: 'Action', value: 'Epoch' },
|
|
193
|
-
{
|
|
194
|
-
name: 'Timestamp',
|
|
195
|
-
value: (await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
196
|
-
},
|
|
197
|
-
],
|
|
201
|
+
tags: [{ name: 'Action', value: 'Epoch' }],
|
|
198
202
|
});
|
|
199
203
|
}
|
|
200
204
|
async getPrescribedObservers(epoch) {
|
|
201
205
|
const allTags = [
|
|
202
206
|
{ name: 'Action', value: 'Epoch-Prescribed-Observers' },
|
|
203
|
-
{
|
|
204
|
-
name: 'Timestamp',
|
|
205
|
-
value: epoch?.timestamp?.toString() ??
|
|
206
|
-
(await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
name: 'Epoch-Index',
|
|
210
|
-
value: epoch?.epochIndex?.toString(),
|
|
211
|
-
},
|
|
207
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
212
208
|
];
|
|
213
209
|
return this.process.read({
|
|
214
210
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -217,15 +213,7 @@ class ARIOReadable {
|
|
|
217
213
|
async getPrescribedNames(epoch) {
|
|
218
214
|
const allTags = [
|
|
219
215
|
{ name: 'Action', value: 'Epoch-Prescribed-Names' },
|
|
220
|
-
{
|
|
221
|
-
name: 'Timestamp',
|
|
222
|
-
value: epoch?.timestamp?.toString() ??
|
|
223
|
-
(await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
name: 'Epoch-Index',
|
|
227
|
-
value: epoch?.epochIndex?.toString(),
|
|
228
|
-
},
|
|
216
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
229
217
|
];
|
|
230
218
|
return this.process.read({
|
|
231
219
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -234,15 +222,7 @@ class ARIOReadable {
|
|
|
234
222
|
async getObservations(epoch) {
|
|
235
223
|
const allTags = [
|
|
236
224
|
{ name: 'Action', value: 'Epoch-Observations' },
|
|
237
|
-
{
|
|
238
|
-
name: 'Timestamp',
|
|
239
|
-
value: epoch?.timestamp?.toString() ??
|
|
240
|
-
(await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
name: 'Epoch-Index',
|
|
244
|
-
value: epoch?.epochIndex?.toString(),
|
|
245
|
-
},
|
|
225
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
246
226
|
];
|
|
247
227
|
return this.process.read({
|
|
248
228
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -251,15 +231,7 @@ class ARIOReadable {
|
|
|
251
231
|
async getDistributions(epoch) {
|
|
252
232
|
const allTags = [
|
|
253
233
|
{ name: 'Action', value: 'Epoch-Distributions' },
|
|
254
|
-
{
|
|
255
|
-
name: 'Timestamp',
|
|
256
|
-
value: epoch?.timestamp?.toString() ??
|
|
257
|
-
(await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
name: 'Epoch-Index',
|
|
261
|
-
value: epoch?.epochIndex?.toString(),
|
|
262
|
-
},
|
|
234
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
263
235
|
];
|
|
264
236
|
return this.process.read({
|
|
265
237
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -288,17 +260,6 @@ class ARIOReadable {
|
|
|
288
260
|
name: 'Purchase-Type',
|
|
289
261
|
value: type,
|
|
290
262
|
},
|
|
291
|
-
{
|
|
292
|
-
name: 'Timestamp',
|
|
293
|
-
value: (await this.arweave.blocks
|
|
294
|
-
.getCurrent()
|
|
295
|
-
.then((block) => {
|
|
296
|
-
return { timestamp: block.timestamp * 1000 };
|
|
297
|
-
})
|
|
298
|
-
.catch(() => {
|
|
299
|
-
return { timestamp: Date.now() }; // fallback to current time
|
|
300
|
-
})).timestamp.toString(),
|
|
301
|
-
},
|
|
302
263
|
];
|
|
303
264
|
return this.process.read({
|
|
304
265
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -333,17 +294,6 @@ class ARIOReadable {
|
|
|
333
294
|
name: 'Fund-From',
|
|
334
295
|
value: fundFrom,
|
|
335
296
|
},
|
|
336
|
-
{
|
|
337
|
-
name: 'Timestamp',
|
|
338
|
-
value: (await this.arweave.blocks
|
|
339
|
-
.getCurrent()
|
|
340
|
-
.then((block) => {
|
|
341
|
-
return { timestamp: block.timestamp * 1000 };
|
|
342
|
-
})
|
|
343
|
-
.catch(() => {
|
|
344
|
-
return { timestamp: Date.now() }; // fallback to current time
|
|
345
|
-
})).timestamp.toString(),
|
|
346
|
-
},
|
|
347
297
|
];
|
|
348
298
|
return this.process.read({
|
|
349
299
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -713,6 +663,7 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
713
663
|
{ name: 'Years', value: params.years?.toString() ?? '1' },
|
|
714
664
|
{ name: 'Process-Id', value: params.processId },
|
|
715
665
|
{ name: 'Purchase-Type', value: params.type || 'lease' },
|
|
666
|
+
{ name: 'Fund-From', value: params.fundFrom },
|
|
716
667
|
];
|
|
717
668
|
return this.process.send({
|
|
718
669
|
signer: this.signer,
|
|
@@ -729,13 +680,15 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
729
680
|
*/
|
|
730
681
|
async upgradeRecord(params, options) {
|
|
731
682
|
const { tags = [] } = options || {};
|
|
683
|
+
const allTags = [
|
|
684
|
+
...tags,
|
|
685
|
+
{ name: 'Action', value: 'Upgrade-Name' }, // TODO: align on Update-Record vs. Upgrade-Name (contract currently uses Upgrade-Name)
|
|
686
|
+
{ name: 'Name', value: params.name },
|
|
687
|
+
{ name: 'Fund-From', value: params.fundFrom },
|
|
688
|
+
];
|
|
732
689
|
return this.process.send({
|
|
733
690
|
signer: this.signer,
|
|
734
|
-
tags:
|
|
735
|
-
...tags,
|
|
736
|
-
{ name: 'Action', value: 'Upgrade-Name' }, // TODO: align on Update-Record vs. Upgrade-Name (contract currently uses Upgrade-Name)
|
|
737
|
-
{ name: 'Name', value: params.name },
|
|
738
|
-
],
|
|
691
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
739
692
|
});
|
|
740
693
|
}
|
|
741
694
|
/**
|
|
@@ -749,26 +702,30 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
749
702
|
*/
|
|
750
703
|
async extendLease(params, options) {
|
|
751
704
|
const { tags = [] } = options || {};
|
|
705
|
+
const allTags = [
|
|
706
|
+
...tags,
|
|
707
|
+
{ name: 'Action', value: 'Extend-Lease' },
|
|
708
|
+
{ name: 'Name', value: params.name },
|
|
709
|
+
{ name: 'Years', value: params.years.toString() },
|
|
710
|
+
{ name: 'Fund-From', value: params.fundFrom },
|
|
711
|
+
];
|
|
752
712
|
return this.process.send({
|
|
753
713
|
signer: this.signer,
|
|
754
|
-
tags:
|
|
755
|
-
...tags,
|
|
756
|
-
{ name: 'Action', value: 'Extend-Lease' },
|
|
757
|
-
{ name: 'Name', value: params.name },
|
|
758
|
-
{ name: 'Years', value: params.years.toString() },
|
|
759
|
-
],
|
|
714
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
760
715
|
});
|
|
761
716
|
}
|
|
762
717
|
async increaseUndernameLimit(params, options) {
|
|
763
718
|
const { tags = [] } = options || {};
|
|
719
|
+
const allTags = [
|
|
720
|
+
...tags,
|
|
721
|
+
{ name: 'Action', value: 'Increase-Undername-Limit' },
|
|
722
|
+
{ name: 'Name', value: params.name },
|
|
723
|
+
{ name: 'Quantity', value: params.increaseCount.toString() },
|
|
724
|
+
{ name: 'Fund-From', value: params.fundFrom },
|
|
725
|
+
];
|
|
764
726
|
return this.process.send({
|
|
765
727
|
signer: this.signer,
|
|
766
|
-
tags:
|
|
767
|
-
...tags,
|
|
768
|
-
{ name: 'Action', value: 'Increase-Undername-Limit' },
|
|
769
|
-
{ name: 'Name', value: params.name },
|
|
770
|
-
{ name: 'Quantity', value: params.increaseCount.toString() },
|
|
771
|
-
],
|
|
728
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
772
729
|
});
|
|
773
730
|
}
|
|
774
731
|
/**
|
|
@@ -793,13 +750,16 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
793
750
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
794
751
|
});
|
|
795
752
|
}
|
|
796
|
-
async requestPrimaryName(params) {
|
|
753
|
+
async requestPrimaryName(params, options) {
|
|
754
|
+
const { tags = [] } = options || {};
|
|
755
|
+
const allTags = [
|
|
756
|
+
...tags,
|
|
757
|
+
{ name: 'Action', value: 'Request-Primary-Name' },
|
|
758
|
+
{ name: 'Name', value: params.name },
|
|
759
|
+
];
|
|
797
760
|
return this.process.send({
|
|
798
761
|
signer: this.signer,
|
|
799
|
-
tags:
|
|
800
|
-
{ name: 'Action', value: 'Request-Primary-Name' },
|
|
801
|
-
{ name: 'Name', value: params.name },
|
|
802
|
-
],
|
|
762
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
803
763
|
});
|
|
804
764
|
}
|
|
805
765
|
/**
|
package/lib/cjs/utils/arweave.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.paginationParamsToTags = exports.
|
|
3
|
+
exports.paginationParamsToTags = exports.pruneTags = exports.isBlockHeight = exports.validateArweaveId = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
4
19
|
const constants_js_1 = require("../constants.js");
|
|
5
20
|
const validateArweaveId = (id) => {
|
|
6
21
|
return constants_js_1.ARWEAVE_TX_REGEX.test(id);
|
|
@@ -10,21 +25,15 @@ function isBlockHeight(height) {
|
|
|
10
25
|
return height !== undefined && !isNaN(parseInt(height.toString()));
|
|
11
26
|
}
|
|
12
27
|
exports.isBlockHeight = isBlockHeight;
|
|
28
|
+
/**
|
|
29
|
+
* Prune tags that are undefined or empty.
|
|
30
|
+
* @param tags - The tags to prune.
|
|
31
|
+
* @returns The pruned tags.
|
|
32
|
+
*/
|
|
13
33
|
const pruneTags = (tags) => {
|
|
14
|
-
return tags.filter((tag) => tag.value !== undefined);
|
|
34
|
+
return tags.filter((tag) => tag.value !== undefined && tag.value !== '');
|
|
15
35
|
};
|
|
16
36
|
exports.pruneTags = pruneTags;
|
|
17
|
-
const getCurrentBlockUnixTimestampMs = async (arweave) => {
|
|
18
|
-
return await arweave.blocks
|
|
19
|
-
.getCurrent()
|
|
20
|
-
.then((block) => {
|
|
21
|
-
return block.timestamp * 1000;
|
|
22
|
-
})
|
|
23
|
-
.catch(() => {
|
|
24
|
-
return Date.now(); // fallback to current time
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
exports.getCurrentBlockUnixTimestampMs = getCurrentBlockUnixTimestampMs;
|
|
28
37
|
const paginationParamsToTags = (params) => {
|
|
29
38
|
const tags = [
|
|
30
39
|
{ name: 'Cursor', value: params?.cursor?.toString() },
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/cli/cli.js
CHANGED
|
@@ -19,11 +19,12 @@ import { program } from 'commander';
|
|
|
19
19
|
import { spawnANT } from '../node/index.js';
|
|
20
20
|
import { mARIOToken } from '../types/token.js';
|
|
21
21
|
import { version } from '../version.js';
|
|
22
|
+
import { buyRecordCLICommand, extendLeaseCLICommand, increaseUndernameLimitCLICommand, requestPrimaryNameCLICommand, upgradeRecordCLICommand, } from './commands/arnsPurchaseCommands.js';
|
|
22
23
|
import { cancelWithdrawal, decreaseDelegateStake, decreaseOperatorStake, delegateStake, increaseOperatorStake, instantWithdrawal, joinNetwork, leaveNetwork, redelegateStake, saveObservations, updateGatewaySettings, } from './commands/gatewayWriteCommands.js';
|
|
23
24
|
import { getAllowedDelegates, getArNSRecord, getArNSReservedName, getArNSReturnedName, getCostDetails, getDelegations, getEpoch, getGateway, getGatewayDelegates, getGatewayVaults, getPrescribedNames, getPrescribedObservers, getPrimaryName, getTokenCost, getVault, listArNSRecords, listArNSReservedNames, listArNSReturnedNames, listGateways, } from './commands/readCommands.js';
|
|
24
25
|
import { transfer } from './commands/transfer.js';
|
|
25
|
-
import { addressAndVaultIdOptions,
|
|
26
|
-
import { applyOptions, arioProcessIdFromOptions, assertConfirmationPrompt, epochInputFromOptions, formatARIOWithCommas, getANTStateFromOptions, getLoggerFromOptions, makeCommand, paginationParamsFromOptions,
|
|
26
|
+
import { addressAndVaultIdOptions, antStateOptions, arnsPurchaseOptions, buyRecordOptions, decreaseDelegateStakeOptions, delegateStakeOptions, epochOptions, getVaultOptions, globalOptions, joinNetworkOptions, operatorStakeOptions, optionMap, paginationAddressOptions, paginationOptions, redelegateStakeOptions, tokenCostOptions, transferOptions, updateGatewaySettingsOptions, writeActionOptions, } from './options.js';
|
|
27
|
+
import { applyOptions, arioProcessIdFromOptions, assertConfirmationPrompt, epochInputFromOptions, formatARIOWithCommas, getANTStateFromOptions, getLoggerFromOptions, makeCommand, paginationParamsFromOptions, readANTFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredAoSignerFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, writeANTFromOptions, writeActionTagsFromOptions, } from './utils.js';
|
|
27
28
|
applyOptions(program
|
|
28
29
|
.name('ar.io')
|
|
29
30
|
.version(version)
|
|
@@ -52,7 +53,7 @@ makeCommand({
|
|
|
52
53
|
makeCommand({
|
|
53
54
|
name: 'get-gateway',
|
|
54
55
|
description: 'Get the gateway of an address',
|
|
55
|
-
options:
|
|
56
|
+
options: [optionMap.address],
|
|
56
57
|
action: getGateway,
|
|
57
58
|
});
|
|
58
59
|
makeCommand({
|
|
@@ -70,7 +71,7 @@ makeCommand({
|
|
|
70
71
|
makeCommand({
|
|
71
72
|
name: 'get-delegations',
|
|
72
73
|
description: 'Get all stake delegated to gateways from this address',
|
|
73
|
-
options:
|
|
74
|
+
options: [optionMap.address],
|
|
74
75
|
action: getDelegations,
|
|
75
76
|
});
|
|
76
77
|
makeCommand({
|
|
@@ -82,7 +83,7 @@ makeCommand({
|
|
|
82
83
|
makeCommand({
|
|
83
84
|
name: 'get-arns-record',
|
|
84
85
|
description: 'Get an ArNS record by name',
|
|
85
|
-
options:
|
|
86
|
+
options: [optionMap.name],
|
|
86
87
|
action: getArNSRecord,
|
|
87
88
|
});
|
|
88
89
|
makeCommand({
|
|
@@ -94,7 +95,7 @@ makeCommand({
|
|
|
94
95
|
makeCommand({
|
|
95
96
|
name: 'get-arns-reserved-name',
|
|
96
97
|
description: 'Get a reserved ArNS name',
|
|
97
|
-
options:
|
|
98
|
+
options: [optionMap.name],
|
|
98
99
|
action: getArNSReservedName,
|
|
99
100
|
});
|
|
100
101
|
makeCommand({
|
|
@@ -106,7 +107,7 @@ makeCommand({
|
|
|
106
107
|
makeCommand({
|
|
107
108
|
name: 'get-arns-returned-name',
|
|
108
109
|
description: 'Get an ArNS returned name by name',
|
|
109
|
-
options:
|
|
110
|
+
options: [optionMap.name],
|
|
110
111
|
action: getArNSReturnedName,
|
|
111
112
|
});
|
|
112
113
|
makeCommand({
|
|
@@ -174,7 +175,7 @@ makeCommand({
|
|
|
174
175
|
makeCommand({
|
|
175
176
|
name: 'get-primary-name-request',
|
|
176
177
|
description: 'Get primary name request',
|
|
177
|
-
options:
|
|
178
|
+
options: [optionMap.initiator],
|
|
178
179
|
action: (o) => readARIOFromOptions(o)
|
|
179
180
|
.getPrimaryNameRequest({
|
|
180
181
|
initiator: requiredStringFromOptions(o, 'initiator'),
|
|
@@ -194,7 +195,7 @@ makeCommand({
|
|
|
194
195
|
makeCommand({
|
|
195
196
|
name: 'get-primary-name',
|
|
196
197
|
description: 'Get primary name',
|
|
197
|
-
options: [
|
|
198
|
+
options: [optionMap.address, optionMap.name],
|
|
198
199
|
action: getPrimaryName,
|
|
199
200
|
});
|
|
200
201
|
makeCommand({
|
|
@@ -208,7 +209,7 @@ makeCommand({
|
|
|
208
209
|
makeCommand({
|
|
209
210
|
name: 'balance',
|
|
210
211
|
description: 'Get the balance of an address',
|
|
211
|
-
options:
|
|
212
|
+
options: [optionMap.address],
|
|
212
213
|
action: (options) => readARIOFromOptions(options)
|
|
213
214
|
.getBalance({ address: requiredAddressFromOptions(options) })
|
|
214
215
|
.then((result) => ({
|
|
@@ -228,7 +229,7 @@ makeCommand({
|
|
|
228
229
|
makeCommand({
|
|
229
230
|
name: 'get-redelegation-fee',
|
|
230
231
|
description: 'Get redelegation fee',
|
|
231
|
-
options:
|
|
232
|
+
options: [optionMap.address],
|
|
232
233
|
action: (options) => readARIOFromOptions(options).getRedelegationFee({
|
|
233
234
|
address: requiredAddressFromOptions(options),
|
|
234
235
|
}),
|
|
@@ -324,82 +325,31 @@ makeCommand({
|
|
|
324
325
|
name: 'buy-record',
|
|
325
326
|
description: 'Buy a record',
|
|
326
327
|
options: buyRecordOptions,
|
|
327
|
-
action:
|
|
328
|
-
const ario = writeARIOFromOptions(options).ario;
|
|
329
|
-
const name = requiredStringFromOptions(options, 'name');
|
|
330
|
-
const type = recordTypeFromOptions(options);
|
|
331
|
-
const years = positiveIntegerFromOptions(options, 'years');
|
|
332
|
-
// TODO: Assert balance is sufficient for action
|
|
333
|
-
// TODO: Assert record is not already owned
|
|
334
|
-
const processId = options.processId;
|
|
335
|
-
if (processId === undefined) {
|
|
336
|
-
// TODO: Spawn ANT process, register it to ANT registry, get process ID
|
|
337
|
-
throw new Error('Process ID must be provided for buy-record');
|
|
338
|
-
}
|
|
339
|
-
await assertConfirmationPrompt(`Are you sure you want to ${type} the record ${name}?`, options);
|
|
340
|
-
return ario.buyRecord({
|
|
341
|
-
name: requiredStringFromOptions(options, 'name'),
|
|
342
|
-
processId,
|
|
343
|
-
type,
|
|
344
|
-
years,
|
|
345
|
-
});
|
|
346
|
-
},
|
|
328
|
+
action: buyRecordCLICommand,
|
|
347
329
|
});
|
|
348
330
|
makeCommand({
|
|
349
331
|
name: 'upgrade-record',
|
|
350
332
|
description: 'Upgrade the lease of a record to a permabuy',
|
|
351
|
-
options:
|
|
352
|
-
|
|
353
|
-
action: async (options) => {
|
|
354
|
-
const name = requiredStringFromOptions(options, 'name');
|
|
355
|
-
await assertConfirmationPrompt(`Are you sure you want to upgrade the lease of ${name} to a permabuy?`, options);
|
|
356
|
-
return writeARIOFromOptions(options).ario.upgradeRecord({
|
|
357
|
-
name,
|
|
358
|
-
});
|
|
359
|
-
},
|
|
333
|
+
options: arnsPurchaseOptions,
|
|
334
|
+
action: upgradeRecordCLICommand,
|
|
360
335
|
});
|
|
361
336
|
makeCommand({
|
|
362
337
|
name: 'extend-lease',
|
|
363
338
|
description: 'Extend the lease of a record',
|
|
364
|
-
options: [...
|
|
365
|
-
action:
|
|
366
|
-
const name = requiredStringFromOptions(options, 'name');
|
|
367
|
-
const years = requiredPositiveIntegerFromOptions(options, 'years');
|
|
368
|
-
await assertConfirmationPrompt(`Are you sure you want to extend the lease of ${name} by ${years}?`, options);
|
|
369
|
-
return writeARIOFromOptions(options).ario.extendLease({
|
|
370
|
-
name,
|
|
371
|
-
years,
|
|
372
|
-
}, writeActionTagsFromOptions(options));
|
|
373
|
-
},
|
|
339
|
+
options: [...arnsPurchaseOptions, optionMap.years],
|
|
340
|
+
action: extendLeaseCLICommand,
|
|
374
341
|
});
|
|
375
342
|
makeCommand({
|
|
376
343
|
name: 'increase-undername-limit',
|
|
377
344
|
description: 'Increase the limit of a name',
|
|
378
|
-
options: [...
|
|
379
|
-
action:
|
|
380
|
-
const name = requiredStringFromOptions(options, 'name');
|
|
381
|
-
const increaseCount = requiredPositiveIntegerFromOptions(options, 'increaseCount');
|
|
382
|
-
await assertConfirmationPrompt(`Are you sure you want to increase the undername limit of ${name} by ${increaseCount}?`, options);
|
|
383
|
-
return writeARIOFromOptions(options).ario.increaseUndernameLimit({
|
|
384
|
-
name,
|
|
385
|
-
increaseCount,
|
|
386
|
-
}, writeActionTagsFromOptions(options));
|
|
387
|
-
},
|
|
345
|
+
options: [...arnsPurchaseOptions, optionMap.increaseCount],
|
|
346
|
+
action: increaseUndernameLimitCLICommand,
|
|
388
347
|
});
|
|
389
348
|
makeCommand({
|
|
390
349
|
name: 'request-primary-name',
|
|
391
350
|
description: 'Request a primary name',
|
|
392
|
-
options:
|
|
393
|
-
action:
|
|
394
|
-
// TODO: Assert balance is sufficient for action?
|
|
395
|
-
// TODO: Assert name requested is not already owned
|
|
396
|
-
// TODO: More assertions?
|
|
397
|
-
const name = requiredStringFromOptions(options, 'name');
|
|
398
|
-
await assertConfirmationPrompt(`Are you sure you want to request the primary name ${name}?`, options);
|
|
399
|
-
return writeARIOFromOptions(options).ario.requestPrimaryName({
|
|
400
|
-
name,
|
|
401
|
-
});
|
|
402
|
-
},
|
|
351
|
+
options: arnsPurchaseOptions,
|
|
352
|
+
action: requestPrimaryNameCLICommand,
|
|
403
353
|
});
|
|
404
354
|
makeCommand({
|
|
405
355
|
name: 'spawn-ant',
|