@ar.io/sdk 3.0.1-alpha.1 → 3.1.0-alpha.10
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/README.md +38 -0
- package/bundles/web.bundle.min.js +79 -79
- package/lib/cjs/cli/cli.js +27 -71
- 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 +17 -38
- package/lib/cjs/cli/commands/transfer.js +5 -1
- package/lib/cjs/cli/options.js +14 -7
- package/lib/cjs/cli/utils.js +59 -7
- package/lib/cjs/common/contracts/ao-process.js +41 -19
- package/lib/cjs/common/io.js +107 -101
- package/lib/cjs/types/io.js +6 -1
- package/lib/cjs/utils/arweave.js +22 -13
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +30 -74
- 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 +16 -38
- package/lib/esm/cli/commands/transfer.js +6 -2
- package/lib/esm/cli/options.js +13 -6
- package/lib/esm/cli/utils.js +53 -5
- package/lib/esm/common/contracts/ao-process.js +41 -19
- package/lib/esm/common/io.js +108 -102
- package/lib/esm/types/io.js +4 -0
- 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/commands/readCommands.d.ts +24 -2
- package/lib/types/cli/options.d.ts +5 -9
- package/lib/types/cli/types.d.ts +3 -5
- package/lib/types/cli/utils.d.ts +25 -4
- package/lib/types/common/contracts/ao-process.d.ts +3 -1
- package/lib/types/common/io.d.ts +15 -43
- package/lib/types/types/common.d.ts +1 -0
- package/lib/types/types/io.d.ts +46 -12
- package/lib/types/utils/arweave.d.ts +6 -18
- package/lib/types/version.d.ts +1 -1
- package/package.json +2 -2
|
@@ -31,7 +31,13 @@ class AOProcess {
|
|
|
31
31
|
this.logger = logger;
|
|
32
32
|
this.ao = ao;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
isMessageDataEmpty(messageData) {
|
|
35
|
+
return (messageData === undefined ||
|
|
36
|
+
messageData === 'null' || // This is what the CU returns for 'nil' values that are json.encoded
|
|
37
|
+
messageData === '' ||
|
|
38
|
+
messageData === null);
|
|
39
|
+
}
|
|
40
|
+
async read({ tags, retries = 3, fromAddress, }) {
|
|
35
41
|
let attempts = 0;
|
|
36
42
|
let lastError;
|
|
37
43
|
while (attempts < retries) {
|
|
@@ -40,27 +46,29 @@ class AOProcess {
|
|
|
40
46
|
tags,
|
|
41
47
|
});
|
|
42
48
|
// map tags to inputs
|
|
43
|
-
const
|
|
49
|
+
const dryRunInput = {
|
|
44
50
|
process: this.processId,
|
|
45
51
|
tags,
|
|
46
|
-
}
|
|
52
|
+
};
|
|
53
|
+
if (fromAddress !== undefined) {
|
|
54
|
+
dryRunInput['Owner'] = fromAddress;
|
|
55
|
+
}
|
|
56
|
+
const result = await this.ao.dryrun(dryRunInput);
|
|
47
57
|
this.logger.debug(`Read interaction result`, {
|
|
48
58
|
result,
|
|
49
59
|
});
|
|
60
|
+
const error = errorMessageFromOutput(result);
|
|
61
|
+
if (error !== undefined) {
|
|
62
|
+
throw new Error(error);
|
|
63
|
+
}
|
|
50
64
|
if (result.Messages === undefined || result.Messages.length === 0) {
|
|
51
65
|
this.logger.debug(`Process ${this.processId} does not support provided action.`, result, tags);
|
|
52
66
|
throw new Error(`Process ${this.processId} does not support provided action.`);
|
|
53
67
|
}
|
|
54
|
-
const tagsOutput = result.Messages?.[0]?.Tags;
|
|
55
68
|
const messageData = result.Messages?.[0]?.Data;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
throw new Error(`${error}${messageData ? `: ${messageData}` : ''}`);
|
|
60
|
-
}
|
|
61
|
-
// return empty object if no data is returned
|
|
62
|
-
if (messageData === undefined) {
|
|
63
|
-
return {};
|
|
69
|
+
// return undefined if no data is returned
|
|
70
|
+
if (this.isMessageDataEmpty(messageData)) {
|
|
71
|
+
return undefined;
|
|
64
72
|
}
|
|
65
73
|
const response = (0, json_js_1.safeDecode)(result.Messages[0].Data);
|
|
66
74
|
return response;
|
|
@@ -68,7 +76,7 @@ class AOProcess {
|
|
|
68
76
|
catch (e) {
|
|
69
77
|
attempts++;
|
|
70
78
|
this.logger.debug(`Read attempt ${attempts} failed`, {
|
|
71
|
-
error: e,
|
|
79
|
+
error: e instanceof Error ? e.message : e,
|
|
72
80
|
tags,
|
|
73
81
|
});
|
|
74
82
|
lastError = e;
|
|
@@ -115,11 +123,8 @@ class AOProcess {
|
|
|
115
123
|
messageId,
|
|
116
124
|
processId: this.processId,
|
|
117
125
|
});
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')
|
|
121
|
-
?.value;
|
|
122
|
-
if (error) {
|
|
126
|
+
const error = errorMessageFromOutput(output);
|
|
127
|
+
if (error !== undefined) {
|
|
123
128
|
throw new error_js_1.WriteInteractionError(error);
|
|
124
129
|
}
|
|
125
130
|
// check if there are any Messages in the output
|
|
@@ -129,7 +134,7 @@ class AOProcess {
|
|
|
129
134
|
if (output.Messages.length === 0) {
|
|
130
135
|
throw new Error(`Process ${this.processId} does not support provided action.`);
|
|
131
136
|
}
|
|
132
|
-
if (output.Messages[0].Data
|
|
137
|
+
if (this.isMessageDataEmpty(output.Messages[0].Data)) {
|
|
133
138
|
return { id: messageId };
|
|
134
139
|
}
|
|
135
140
|
const resultData = (0, json_js_1.safeDecode)(output.Messages[0].Data);
|
|
@@ -167,3 +172,20 @@ class AOProcess {
|
|
|
167
172
|
}
|
|
168
173
|
}
|
|
169
174
|
exports.AOProcess = AOProcess;
|
|
175
|
+
function errorMessageFromOutput(output) {
|
|
176
|
+
const errorData = output.Error;
|
|
177
|
+
if (errorData !== undefined) {
|
|
178
|
+
// TODO: Could clean this one up too, current error is verbose, but not always deterministic for parsing
|
|
179
|
+
// Throw the whole raw error if AO process level error
|
|
180
|
+
return errorData;
|
|
181
|
+
}
|
|
182
|
+
const error = output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
|
|
183
|
+
if (error !== undefined) {
|
|
184
|
+
// from [string "aos"]:6846: Name is already registered
|
|
185
|
+
const lineNumber = error.match(/\d+/)?.[0];
|
|
186
|
+
const message = error.replace(/\[string "aos"\]:\d+:/, '');
|
|
187
|
+
// to more user friendly: Name is already registered (line 6846)
|
|
188
|
+
return `${message} (line ${lineNumber})`.trim();
|
|
189
|
+
}
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
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,23 +231,45 @@ class ARIOReadable {
|
|
|
251
231
|
async getDistributions(epoch) {
|
|
252
232
|
const allTags = [
|
|
253
233
|
{ name: 'Action', value: 'Epoch-Distributions' },
|
|
234
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
235
|
+
];
|
|
236
|
+
return this.process.read({
|
|
237
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
async getTokenCost({ intent, type, years, name, quantity, fromAddress, }) {
|
|
241
|
+
const allTags = [
|
|
242
|
+
{ name: 'Action', value: 'Token-Cost' },
|
|
254
243
|
{
|
|
255
|
-
name: '
|
|
256
|
-
value:
|
|
257
|
-
(await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
244
|
+
name: 'Intent',
|
|
245
|
+
value: intent,
|
|
258
246
|
},
|
|
259
247
|
{
|
|
260
|
-
name: '
|
|
261
|
-
value:
|
|
248
|
+
name: 'Name',
|
|
249
|
+
value: name,
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: 'Years',
|
|
253
|
+
value: years?.toString(),
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: 'Quantity',
|
|
257
|
+
value: quantity?.toString(),
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
name: 'Purchase-Type',
|
|
261
|
+
value: type,
|
|
262
262
|
},
|
|
263
263
|
];
|
|
264
264
|
return this.process.read({
|
|
265
265
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
266
|
+
fromAddress,
|
|
266
267
|
});
|
|
267
268
|
}
|
|
268
|
-
|
|
269
|
+
// TODO: Can overload this function to refine different types of cost details params
|
|
270
|
+
async getCostDetails({ intent, type, years, name, quantity, fromAddress, fundFrom, }) {
|
|
269
271
|
const allTags = [
|
|
270
|
-
{ name: 'Action', value: '
|
|
272
|
+
{ name: 'Action', value: 'Get-Cost-Details-For-Action' },
|
|
271
273
|
{
|
|
272
274
|
name: 'Intent',
|
|
273
275
|
value: intent,
|
|
@@ -289,19 +291,13 @@ class ARIOReadable {
|
|
|
289
291
|
value: type,
|
|
290
292
|
},
|
|
291
293
|
{
|
|
292
|
-
name: '
|
|
293
|
-
value:
|
|
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(),
|
|
294
|
+
name: 'Fund-From',
|
|
295
|
+
value: fundFrom,
|
|
301
296
|
},
|
|
302
297
|
];
|
|
303
298
|
return this.process.read({
|
|
304
299
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
300
|
+
fromAddress,
|
|
305
301
|
});
|
|
306
302
|
}
|
|
307
303
|
async getRegistrationFees() {
|
|
@@ -667,6 +663,7 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
667
663
|
{ name: 'Years', value: params.years?.toString() ?? '1' },
|
|
668
664
|
{ name: 'Process-Id', value: params.processId },
|
|
669
665
|
{ name: 'Purchase-Type', value: params.type || 'lease' },
|
|
666
|
+
{ name: 'Fund-From', value: params.fundFrom },
|
|
670
667
|
];
|
|
671
668
|
return this.process.send({
|
|
672
669
|
signer: this.signer,
|
|
@@ -683,13 +680,15 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
683
680
|
*/
|
|
684
681
|
async upgradeRecord(params, options) {
|
|
685
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
|
+
];
|
|
686
689
|
return this.process.send({
|
|
687
690
|
signer: this.signer,
|
|
688
|
-
tags:
|
|
689
|
-
...tags,
|
|
690
|
-
{ name: 'Action', value: 'Upgrade-Name' }, // TODO: align on Update-Record vs. Upgrade-Name (contract currently uses Upgrade-Name)
|
|
691
|
-
{ name: 'Name', value: params.name },
|
|
692
|
-
],
|
|
691
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
693
692
|
});
|
|
694
693
|
}
|
|
695
694
|
/**
|
|
@@ -703,26 +702,30 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
703
702
|
*/
|
|
704
703
|
async extendLease(params, options) {
|
|
705
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
|
+
];
|
|
706
712
|
return this.process.send({
|
|
707
713
|
signer: this.signer,
|
|
708
|
-
tags:
|
|
709
|
-
...tags,
|
|
710
|
-
{ name: 'Action', value: 'Extend-Lease' },
|
|
711
|
-
{ name: 'Name', value: params.name },
|
|
712
|
-
{ name: 'Years', value: params.years.toString() },
|
|
713
|
-
],
|
|
714
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
714
715
|
});
|
|
715
716
|
}
|
|
716
717
|
async increaseUndernameLimit(params, options) {
|
|
717
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
|
+
];
|
|
718
726
|
return this.process.send({
|
|
719
727
|
signer: this.signer,
|
|
720
|
-
tags:
|
|
721
|
-
...tags,
|
|
722
|
-
{ name: 'Action', value: 'Increase-Undername-Limit' },
|
|
723
|
-
{ name: 'Name', value: params.name },
|
|
724
|
-
{ name: 'Quantity', value: params.increaseCount.toString() },
|
|
725
|
-
],
|
|
728
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
726
729
|
});
|
|
727
730
|
}
|
|
728
731
|
/**
|
|
@@ -747,13 +750,16 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
747
750
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
748
751
|
});
|
|
749
752
|
}
|
|
750
|
-
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
|
+
];
|
|
751
760
|
return this.process.send({
|
|
752
761
|
signer: this.signer,
|
|
753
|
-
tags:
|
|
754
|
-
{ name: 'Action', value: 'Request-Primary-Name' },
|
|
755
|
-
{ name: 'Name', value: params.name },
|
|
756
|
-
],
|
|
762
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
757
763
|
});
|
|
758
764
|
}
|
|
759
765
|
/**
|
package/lib/cjs/types/io.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isLeasedArNSRecord = exports.isProcessIdConfiguration = exports.isProcessConfiguration = exports.isValidIntent = exports.intentsUsingYears = exports.validIntents = void 0;
|
|
3
|
+
exports.isLeasedArNSRecord = exports.isProcessIdConfiguration = exports.isProcessConfiguration = exports.isValidFundFrom = exports.fundFromOptions = exports.isValidIntent = exports.intentsUsingYears = exports.validIntents = void 0;
|
|
4
4
|
const arweave_js_1 = require("../utils/arweave.js");
|
|
5
5
|
exports.validIntents = [
|
|
6
6
|
'Buy-Record',
|
|
@@ -14,6 +14,11 @@ const isValidIntent = (intent) => {
|
|
|
14
14
|
return exports.validIntents.indexOf(intent) !== -1;
|
|
15
15
|
};
|
|
16
16
|
exports.isValidIntent = isValidIntent;
|
|
17
|
+
exports.fundFromOptions = ['balance', 'stakes', 'any'];
|
|
18
|
+
const isValidFundFrom = (fundFrom) => {
|
|
19
|
+
return exports.fundFromOptions.indexOf(fundFrom) !== -1;
|
|
20
|
+
};
|
|
21
|
+
exports.isValidFundFrom = isValidFundFrom;
|
|
17
22
|
// Typeguard functions
|
|
18
23
|
function isProcessConfiguration(config) {
|
|
19
24
|
return 'process' in config;
|
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