@ar.io/sdk 1.2.0-alpha.9 → 1.2.0
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 +914 -70
- package/bundles/web.bundle.min.js +76 -76
- package/lib/cjs/common/ant-ao.js +11 -4
- package/lib/cjs/common/contracts/ao-process.js +16 -5
- package/lib/cjs/common/io.js +95 -100
- package/lib/cjs/constants.js +7 -4
- package/lib/cjs/utils/graphql/processes.js +87 -7
- package/lib/cjs/utils/index.js +1 -0
- package/lib/cjs/utils/json.js +28 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/ant-ao.js +11 -4
- package/lib/esm/common/contracts/ao-process.js +16 -5
- package/lib/esm/common/io.js +95 -100
- package/lib/esm/constants.js +6 -3
- package/lib/esm/utils/graphql/processes.js +85 -6
- package/lib/esm/utils/index.js +1 -0
- package/lib/esm/utils/json.js +24 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/common/ant-ao.d.ts +2 -1
- package/lib/types/common/io.d.ts +11 -4
- package/lib/types/constants.d.ts +4 -2
- package/lib/types/io.d.ts +29 -3
- package/lib/types/utils/graphql/processes.d.ts +30 -0
- package/lib/types/utils/index.d.ts +1 -0
- package/lib/types/utils/json.d.ts +17 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +7 -1
package/lib/cjs/common/ant-ao.js
CHANGED
|
@@ -19,6 +19,13 @@ class AoANTReadable {
|
|
|
19
19
|
throw new error_js_1.InvalidContractConfigurationError();
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
async getState() {
|
|
23
|
+
const tags = [{ name: 'Action', value: 'State' }];
|
|
24
|
+
const res = await this.process.read({
|
|
25
|
+
tags,
|
|
26
|
+
});
|
|
27
|
+
return res;
|
|
28
|
+
}
|
|
22
29
|
async getInfo() {
|
|
23
30
|
const tags = [{ name: 'Action', value: 'Info' }];
|
|
24
31
|
const info = await this.process.read({
|
|
@@ -38,7 +45,7 @@ class AoANTReadable {
|
|
|
38
45
|
async getRecord({ undername }) {
|
|
39
46
|
const tags = [
|
|
40
47
|
{ name: 'Sub-Domain', value: undername },
|
|
41
|
-
{ name: 'Action', value: '
|
|
48
|
+
{ name: 'Action', value: 'Record' },
|
|
42
49
|
];
|
|
43
50
|
const record = await this.process.read({
|
|
44
51
|
tags,
|
|
@@ -54,7 +61,7 @@ class AoANTReadable {
|
|
|
54
61
|
* ````
|
|
55
62
|
*/
|
|
56
63
|
async getRecords() {
|
|
57
|
-
const tags = [{ name: 'Action', value: '
|
|
64
|
+
const tags = [{ name: 'Action', value: 'Records' }];
|
|
58
65
|
const records = await this.process.read({
|
|
59
66
|
tags,
|
|
60
67
|
});
|
|
@@ -81,7 +88,7 @@ class AoANTReadable {
|
|
|
81
88
|
* ```
|
|
82
89
|
*/
|
|
83
90
|
async getControllers() {
|
|
84
|
-
const tags = [{ name: 'Action', value: '
|
|
91
|
+
const tags = [{ name: 'Action', value: 'Controllers' }];
|
|
85
92
|
const controllers = await this.process.read({
|
|
86
93
|
tags,
|
|
87
94
|
});
|
|
@@ -182,7 +189,7 @@ class AoANTWriteable extends AoANTReadable {
|
|
|
182
189
|
*/
|
|
183
190
|
async addController({ controller, }) {
|
|
184
191
|
const tags = [
|
|
185
|
-
{ name: 'Action', value: '
|
|
192
|
+
{ name: 'Action', value: 'Add-Controller' },
|
|
186
193
|
{ name: 'Controller', value: controller },
|
|
187
194
|
];
|
|
188
195
|
return this.process.send({
|
|
@@ -19,6 +19,7 @@ exports.AOProcess = void 0;
|
|
|
19
19
|
*/
|
|
20
20
|
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
21
21
|
const arbundles_1 = require("arbundles");
|
|
22
|
+
const json_js_1 = require("../../utils/json.js");
|
|
22
23
|
const version_js_1 = require("../../version.js");
|
|
23
24
|
const error_js_1 = require("../error.js");
|
|
24
25
|
const logger_js_1 = require("../logger.js");
|
|
@@ -60,18 +61,22 @@ class AOProcess {
|
|
|
60
61
|
process: this.processId,
|
|
61
62
|
tags,
|
|
62
63
|
});
|
|
64
|
+
if (result.Messages.length === 0) {
|
|
65
|
+
throw new Error(`Process ${this.processId} does not support provided action.`);
|
|
66
|
+
}
|
|
63
67
|
const tagsOutput = result.Messages[0].Tags;
|
|
64
68
|
const error = tagsOutput.find((tag) => tag.name === 'Error');
|
|
65
69
|
if (error) {
|
|
66
70
|
throw new Error(`${error.Value}: ${result.Messages[0].Data}`);
|
|
67
71
|
}
|
|
68
|
-
if (result.Messages.length === 0) {
|
|
69
|
-
throw new Error('Process does not support provided action.');
|
|
70
|
-
}
|
|
71
72
|
this.logger.debug(`Read interaction result`, {
|
|
72
73
|
result: result.Messages[0].Data,
|
|
73
74
|
});
|
|
74
|
-
|
|
75
|
+
// return empty object if no data is returned
|
|
76
|
+
if (result.Messages[0].Data === undefined) {
|
|
77
|
+
return {};
|
|
78
|
+
}
|
|
79
|
+
const response = (0, json_js_1.safeDecode)(result.Messages[0].Data);
|
|
75
80
|
return response;
|
|
76
81
|
}
|
|
77
82
|
catch (e) {
|
|
@@ -131,7 +136,13 @@ class AOProcess {
|
|
|
131
136
|
const result = output.Messages[0].Data;
|
|
132
137
|
throw new error_js_1.WriteInteractionError(`${error.Value}: ${result}`);
|
|
133
138
|
}
|
|
134
|
-
|
|
139
|
+
if (output.Messages.length === 0) {
|
|
140
|
+
throw new Error(`Process ${this.processId} does not support provided action.`);
|
|
141
|
+
}
|
|
142
|
+
if (output.Messages[0].Data === undefined) {
|
|
143
|
+
return { id: messageId };
|
|
144
|
+
}
|
|
145
|
+
const resultData = (0, json_js_1.safeDecode)(output.Messages[0].Data);
|
|
135
146
|
this.logger.debug('Message result data', {
|
|
136
147
|
resultData,
|
|
137
148
|
messageId,
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -64,31 +64,47 @@ class IOReadable {
|
|
|
64
64
|
}
|
|
65
65
|
this.arweave = arweave;
|
|
66
66
|
}
|
|
67
|
-
async
|
|
67
|
+
async getInfo() {
|
|
68
|
+
return this.process.read({
|
|
69
|
+
tags: [{ name: 'Action', value: 'Info' }],
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async getEpochSettings(params) {
|
|
68
73
|
const allTags = [
|
|
69
|
-
{ name: 'Action', value: 'Epoch' },
|
|
74
|
+
{ name: 'Action', value: 'Epoch-Settings' },
|
|
70
75
|
{
|
|
71
|
-
// TODO: default this to the current network time
|
|
72
76
|
name: 'Timestamp',
|
|
73
|
-
value:
|
|
77
|
+
value: params?.timestamp?.toString() ??
|
|
78
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
79
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
80
|
+
})).timestamp.toString(),
|
|
74
81
|
},
|
|
75
82
|
{
|
|
76
|
-
name: '
|
|
77
|
-
value:
|
|
83
|
+
name: 'Epoch-Index',
|
|
84
|
+
value: params?.epochIndex?.toString(),
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
88
|
+
return this.process.read({
|
|
89
|
+
tags: prunedTags,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async getEpoch(epoch) {
|
|
93
|
+
const allTags = [
|
|
94
|
+
{ name: 'Action', value: 'Epoch' },
|
|
95
|
+
{
|
|
96
|
+
name: 'Timestamp',
|
|
97
|
+
value: epoch?.timestamp?.toString() ??
|
|
98
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
99
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
100
|
+
})).timestamp.toString(),
|
|
78
101
|
},
|
|
79
102
|
{
|
|
80
|
-
name: '
|
|
103
|
+
name: 'Epoch-Index',
|
|
81
104
|
value: epoch?.epochIndex?.toString(),
|
|
82
105
|
},
|
|
83
106
|
];
|
|
84
107
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
85
|
-
// if it only contains the action, add default timestamp
|
|
86
|
-
if (prunedTags.length === 1) {
|
|
87
|
-
prunedTags.push({
|
|
88
|
-
name: 'Timestamp',
|
|
89
|
-
value: (await this.arweave.blocks.getCurrent()).timestamp.toString(),
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
108
|
return this.process.read({
|
|
93
109
|
tags: prunedTags,
|
|
94
110
|
});
|
|
@@ -108,13 +124,13 @@ class IOReadable {
|
|
|
108
124
|
}
|
|
109
125
|
async getArNSReservedNames() {
|
|
110
126
|
return this.process.read({
|
|
111
|
-
tags: [{ name: 'Action', value: '
|
|
127
|
+
tags: [{ name: 'Action', value: 'Reserved-Names' }],
|
|
112
128
|
});
|
|
113
129
|
}
|
|
114
130
|
async getArNSReservedName({ name, }) {
|
|
115
131
|
return this.process.read({
|
|
116
132
|
tags: [
|
|
117
|
-
{ name: 'Action', value: '
|
|
133
|
+
{ name: 'Action', value: 'Reserved-Name' },
|
|
118
134
|
{ name: 'Name', value: name },
|
|
119
135
|
],
|
|
120
136
|
});
|
|
@@ -149,125 +165,98 @@ class IOReadable {
|
|
|
149
165
|
return this.process.read({
|
|
150
166
|
tags: [
|
|
151
167
|
{ name: 'Action', value: 'Epoch' },
|
|
152
|
-
{
|
|
168
|
+
{
|
|
169
|
+
name: 'Timestamp',
|
|
170
|
+
value: (await this.arweave.blocks.getCurrent().catch(() => {
|
|
171
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
172
|
+
})).timestamp.toString(),
|
|
173
|
+
},
|
|
153
174
|
],
|
|
154
175
|
});
|
|
155
176
|
}
|
|
156
177
|
async getPrescribedObservers(epoch) {
|
|
157
178
|
const allTags = [
|
|
158
|
-
{ name: 'Action', value: '
|
|
179
|
+
{ name: 'Action', value: 'Epoch-Prescribed-Observers' },
|
|
159
180
|
{
|
|
160
181
|
name: 'Timestamp',
|
|
161
|
-
value: epoch
|
|
182
|
+
value: epoch?.timestamp?.toString() ??
|
|
183
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
184
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
185
|
+
})).timestamp.toString(),
|
|
162
186
|
},
|
|
163
187
|
{
|
|
164
|
-
name: '
|
|
165
|
-
value: epoch?.blockHeight?.toString(),
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
name: 'EpochIndex',
|
|
188
|
+
name: 'Epoch-Index',
|
|
169
189
|
value: epoch?.epochIndex?.toString(),
|
|
170
190
|
},
|
|
171
191
|
];
|
|
172
192
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
173
|
-
// if it only contains the action, add default timestamp
|
|
174
|
-
if (prunedTags.length === 1) {
|
|
175
|
-
prunedTags.push({
|
|
176
|
-
name: 'Timestamp',
|
|
177
|
-
value: `${Date.now()}`,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
193
|
return this.process.read({
|
|
181
194
|
tags: prunedTags,
|
|
182
195
|
});
|
|
183
196
|
}
|
|
184
197
|
async getPrescribedNames(epoch) {
|
|
185
198
|
const allTags = [
|
|
186
|
-
{ name: 'Action', value: '
|
|
199
|
+
{ name: 'Action', value: 'Epoch-Prescribed-Names' },
|
|
187
200
|
{
|
|
188
201
|
name: 'Timestamp',
|
|
189
|
-
value: epoch
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
value: epoch?.blockHeight?.toString(),
|
|
202
|
+
value: epoch?.timestamp?.toString() ??
|
|
203
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
204
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
205
|
+
})).timestamp.toString(),
|
|
194
206
|
},
|
|
195
207
|
{
|
|
196
|
-
name: '
|
|
208
|
+
name: 'Epoch-Index',
|
|
197
209
|
value: epoch?.epochIndex?.toString(),
|
|
198
210
|
},
|
|
199
211
|
];
|
|
200
212
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
201
|
-
// if it only contains the action, add default timestamp
|
|
202
|
-
if (prunedTags.length === 1) {
|
|
203
|
-
prunedTags.push({
|
|
204
|
-
name: 'Timestamp',
|
|
205
|
-
value: `${Date.now()}`, // TODO; replace with fetch the current network time
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
213
|
return this.process.read({
|
|
209
214
|
tags: prunedTags,
|
|
210
215
|
});
|
|
211
216
|
}
|
|
212
217
|
async getObservations(epoch) {
|
|
213
218
|
const allTags = [
|
|
214
|
-
{ name: 'Action', value: '
|
|
219
|
+
{ name: 'Action', value: 'Epoch-Observations' },
|
|
215
220
|
{
|
|
216
221
|
name: 'Timestamp',
|
|
217
|
-
value: epoch
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
value: epoch?.blockHeight?.toString(),
|
|
222
|
+
value: epoch?.timestamp?.toString() ??
|
|
223
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
224
|
+
return { timestamp: `${Date.now()}` }; // fallback to current time
|
|
225
|
+
})).timestamp.toString(),
|
|
222
226
|
},
|
|
223
227
|
{
|
|
224
|
-
name: '
|
|
228
|
+
name: 'Epoch-Index',
|
|
225
229
|
value: epoch?.epochIndex?.toString(),
|
|
226
230
|
},
|
|
227
231
|
];
|
|
228
232
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
229
|
-
// if it only contains the action, add default timestamp
|
|
230
|
-
if (prunedTags.length === 1) {
|
|
231
|
-
prunedTags.push({
|
|
232
|
-
name: 'Timestamp',
|
|
233
|
-
value: (await this.arweave.blocks.getCurrent()).timestamp.toString(),
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
233
|
return this.process.read({
|
|
237
234
|
tags: prunedTags,
|
|
238
235
|
});
|
|
239
236
|
}
|
|
240
237
|
async getDistributions(epoch) {
|
|
241
238
|
const allTags = [
|
|
242
|
-
{ name: 'Action', value: '
|
|
239
|
+
{ name: 'Action', value: 'Epoch-Distributions' },
|
|
243
240
|
{
|
|
244
241
|
name: 'Timestamp',
|
|
245
|
-
value: epoch
|
|
242
|
+
value: epoch?.timestamp?.toString() ??
|
|
243
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
244
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
245
|
+
})).timestamp.toString(),
|
|
246
246
|
},
|
|
247
247
|
{
|
|
248
|
-
name: '
|
|
249
|
-
value: epoch?.blockHeight?.toString(),
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
name: 'EpochIndex',
|
|
248
|
+
name: 'Epoch-Index',
|
|
253
249
|
value: epoch?.epochIndex?.toString(),
|
|
254
250
|
},
|
|
255
251
|
];
|
|
256
252
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
257
|
-
// if it only contains the action, add default timestamp
|
|
258
|
-
if (prunedTags.length === 1) {
|
|
259
|
-
prunedTags.push({
|
|
260
|
-
name: 'Timestamp',
|
|
261
|
-
value: (await this.arweave.blocks.getCurrent()).timestamp.toString(),
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
253
|
return this.process.read({
|
|
265
254
|
tags: prunedTags,
|
|
266
255
|
});
|
|
267
256
|
}
|
|
268
257
|
async getTokenCost({ intent, purchaseType, years, name, quantity, }) {
|
|
269
258
|
const allTags = [
|
|
270
|
-
{ name: 'Action', value: '
|
|
259
|
+
{ name: 'Action', value: 'Token-Cost' },
|
|
271
260
|
{
|
|
272
261
|
name: 'Intent',
|
|
273
262
|
value: intent,
|
|
@@ -285,9 +274,15 @@ class IOReadable {
|
|
|
285
274
|
value: quantity?.toString(),
|
|
286
275
|
},
|
|
287
276
|
{
|
|
288
|
-
name: '
|
|
277
|
+
name: 'Purchase-Type',
|
|
289
278
|
value: purchaseType,
|
|
290
279
|
},
|
|
280
|
+
{
|
|
281
|
+
name: 'Timestamp',
|
|
282
|
+
value: (await this.arweave.blocks.getCurrent().catch(() => {
|
|
283
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
284
|
+
})).timestamp.toString(),
|
|
285
|
+
},
|
|
291
286
|
];
|
|
292
287
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
293
288
|
return this.process.read({
|
|
@@ -345,17 +340,17 @@ class IOWriteable extends IOReadable {
|
|
|
345
340
|
const { tags = [] } = options || {};
|
|
346
341
|
const allTags = [
|
|
347
342
|
...tags,
|
|
348
|
-
{ name: 'Action', value: '
|
|
343
|
+
{ name: 'Action', value: 'Join-Network' },
|
|
349
344
|
{
|
|
350
|
-
name: '
|
|
345
|
+
name: 'Operator-Stake',
|
|
351
346
|
value: operatorStake.valueOf().toString(),
|
|
352
347
|
},
|
|
353
348
|
{
|
|
354
|
-
name: '
|
|
349
|
+
name: 'Allow-Delegated-Staking',
|
|
355
350
|
value: allowDelegatedStaking.toString(),
|
|
356
351
|
},
|
|
357
352
|
{
|
|
358
|
-
name: '
|
|
353
|
+
name: 'Delegate-Reward-Share-Ratio',
|
|
359
354
|
value: delegateRewardShareRatio.toString(),
|
|
360
355
|
},
|
|
361
356
|
{
|
|
@@ -367,7 +362,7 @@ class IOWriteable extends IOReadable {
|
|
|
367
362
|
value: label,
|
|
368
363
|
},
|
|
369
364
|
{
|
|
370
|
-
name: '
|
|
365
|
+
name: 'Min-Delegated-Stake',
|
|
371
366
|
value: minDelegatedStake.valueOf().toString(),
|
|
372
367
|
},
|
|
373
368
|
{
|
|
@@ -387,11 +382,11 @@ class IOWriteable extends IOReadable {
|
|
|
387
382
|
value: protocol,
|
|
388
383
|
},
|
|
389
384
|
{
|
|
390
|
-
name: '
|
|
385
|
+
name: 'Auto-Stake',
|
|
391
386
|
value: autoStake.toString(),
|
|
392
387
|
},
|
|
393
388
|
{
|
|
394
|
-
name: '
|
|
389
|
+
name: 'Observer-Address',
|
|
395
390
|
value: observerAddress,
|
|
396
391
|
},
|
|
397
392
|
];
|
|
@@ -405,27 +400,27 @@ class IOWriteable extends IOReadable {
|
|
|
405
400
|
const { tags = [] } = options || {};
|
|
406
401
|
const allTags = [
|
|
407
402
|
...tags,
|
|
408
|
-
{ name: 'Action', value: '
|
|
403
|
+
{ name: 'Action', value: 'Update-Gateway-Settings' },
|
|
409
404
|
{ name: 'Label', value: label },
|
|
410
405
|
{ name: 'Note', value: note },
|
|
411
406
|
{ name: 'FQDN', value: fqdn },
|
|
412
407
|
{ name: 'Port', value: port?.toString() },
|
|
413
408
|
{ name: 'Properties', value: properties },
|
|
414
409
|
{ name: 'Protocol', value: protocol },
|
|
415
|
-
{ name: '
|
|
410
|
+
{ name: 'Observer-Address', value: observerAddress },
|
|
416
411
|
{
|
|
417
|
-
name: '
|
|
412
|
+
name: 'Allow-Delegated-Staking',
|
|
418
413
|
value: allowDelegatedStaking?.toString(),
|
|
419
414
|
},
|
|
420
415
|
{
|
|
421
|
-
name: '
|
|
416
|
+
name: 'Delegate-Reward-Share-Ratio',
|
|
422
417
|
value: delegateRewardShareRatio?.toString(),
|
|
423
418
|
},
|
|
424
419
|
{
|
|
425
|
-
name: '
|
|
420
|
+
name: 'Min-Delegated-Stake',
|
|
426
421
|
value: minDelegatedStake?.valueOf().toString(),
|
|
427
422
|
},
|
|
428
|
-
{ name: '
|
|
423
|
+
{ name: 'Auto-Stake', value: autoStake?.toString() },
|
|
429
424
|
];
|
|
430
425
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
431
426
|
return this.process.send({
|
|
@@ -439,7 +434,7 @@ class IOWriteable extends IOReadable {
|
|
|
439
434
|
signer: this.signer,
|
|
440
435
|
tags: [
|
|
441
436
|
...tags,
|
|
442
|
-
{ name: 'Action', value: '
|
|
437
|
+
{ name: 'Action', value: 'Delegate-Stake' },
|
|
443
438
|
{ name: 'Target', value: params.target },
|
|
444
439
|
{ name: 'Quantity', value: params.stakeQty.valueOf().toString() },
|
|
445
440
|
],
|
|
@@ -451,7 +446,7 @@ class IOWriteable extends IOReadable {
|
|
|
451
446
|
signer: this.signer,
|
|
452
447
|
tags: [
|
|
453
448
|
...tags,
|
|
454
|
-
{ name: 'Action', value: '
|
|
449
|
+
{ name: 'Action', value: 'Decrease-Delegate-Stake' },
|
|
455
450
|
{ name: 'Target', value: params.target },
|
|
456
451
|
{ name: 'Quantity', value: params.decreaseQty.valueOf().toString() },
|
|
457
452
|
],
|
|
@@ -463,7 +458,7 @@ class IOWriteable extends IOReadable {
|
|
|
463
458
|
signer: this.signer,
|
|
464
459
|
tags: [
|
|
465
460
|
...tags,
|
|
466
|
-
{ name: 'Action', value: '
|
|
461
|
+
{ name: 'Action', value: 'Increase-Operator-Stake' },
|
|
467
462
|
{ name: 'Quantity', value: params.increaseQty.valueOf().toString() },
|
|
468
463
|
],
|
|
469
464
|
});
|
|
@@ -474,7 +469,7 @@ class IOWriteable extends IOReadable {
|
|
|
474
469
|
signer: this.signer,
|
|
475
470
|
tags: [
|
|
476
471
|
...tags,
|
|
477
|
-
{ name: 'Action', value: '
|
|
472
|
+
{ name: 'Action', value: 'Decrease-Operator-Stake' },
|
|
478
473
|
{ name: 'Quantity', value: params.decreaseQty.valueOf().toString() },
|
|
479
474
|
],
|
|
480
475
|
});
|
|
@@ -485,13 +480,13 @@ class IOWriteable extends IOReadable {
|
|
|
485
480
|
signer: this.signer,
|
|
486
481
|
tags: [
|
|
487
482
|
...tags,
|
|
488
|
-
{ name: 'Action', value: '
|
|
483
|
+
{ name: 'Action', value: 'Save-Observations' },
|
|
489
484
|
{
|
|
490
|
-
name: '
|
|
485
|
+
name: 'Report-Tx-Id',
|
|
491
486
|
value: params.reportTxId,
|
|
492
487
|
},
|
|
493
488
|
{
|
|
494
|
-
name: '
|
|
489
|
+
name: 'Failed-Gateways',
|
|
495
490
|
value: params.failedGateways.join(','),
|
|
496
491
|
},
|
|
497
492
|
],
|
|
@@ -505,11 +500,11 @@ class IOWriteable extends IOReadable {
|
|
|
505
500
|
const { tags = [] } = options || {};
|
|
506
501
|
const allTags = [
|
|
507
502
|
...tags,
|
|
508
|
-
{ name: 'Action', value: '
|
|
503
|
+
{ name: 'Action', value: 'Buy-Record' },
|
|
509
504
|
{ name: 'Name', value: params.name },
|
|
510
505
|
{ name: 'Years', value: params.years?.toString() ?? '1' },
|
|
511
|
-
{ name: '
|
|
512
|
-
{ name: '
|
|
506
|
+
{ name: 'Process-Id', value: params.processId },
|
|
507
|
+
{ name: 'Purchase-Type', value: params.type || 'lease' },
|
|
513
508
|
];
|
|
514
509
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
515
510
|
return this.process.send({
|
|
@@ -523,7 +518,7 @@ class IOWriteable extends IOReadable {
|
|
|
523
518
|
signer: this.signer,
|
|
524
519
|
tags: [
|
|
525
520
|
...tags,
|
|
526
|
-
{ name: 'Action', value: '
|
|
521
|
+
{ name: 'Action', value: 'Extend-Lease' },
|
|
527
522
|
{ name: 'Name', value: params.name },
|
|
528
523
|
{ name: 'Years', value: params.years.toString() },
|
|
529
524
|
],
|
|
@@ -535,7 +530,7 @@ class IOWriteable extends IOReadable {
|
|
|
535
530
|
signer: this.signer,
|
|
536
531
|
tags: [
|
|
537
532
|
...tags,
|
|
538
|
-
{ name: 'Action', value: '
|
|
533
|
+
{ name: 'Action', value: 'Increase-Undername-Limit' },
|
|
539
534
|
{ name: 'Name', value: params.name },
|
|
540
535
|
{ name: 'Quantity', value: params.increaseCount.toString() },
|
|
541
536
|
],
|
package/lib/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_SCHEDULER_ID = exports.ANT_LUA_ID = exports.AOS_MODULE_ID = exports.MIO_PER_IO = exports.ioDevnetProcessId = exports.ARNS_DEVNET_REGISTRY_TX = exports.ARNS_TESTNET_REGISTRY_TX = exports.SORT_KEY_REGEX = exports.FQDN_REGEX = exports.ARWEAVE_TX_REGEX = void 0;
|
|
3
|
+
exports.DEFAULT_SCHEDULER_ID = exports.ANT_LUA_ID = exports.AOS_MODULE_ID = exports.MIO_PER_IO = exports.IO_TESTNET_PROCESS_ID = exports.ioDevnetProcessId = exports.IO_DEVNET_PROCESS_ID = exports.ARNS_DEVNET_REGISTRY_TX = exports.ARNS_TESTNET_REGISTRY_TX = exports.SORT_KEY_REGEX = exports.FQDN_REGEX = exports.ARWEAVE_TX_REGEX = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
6
6
|
*
|
|
@@ -24,8 +24,11 @@ exports.FQDN_REGEX = new RegExp('^(?:(?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{
|
|
|
24
24
|
exports.SORT_KEY_REGEX = new RegExp('^[0-9]{12},[0-9]{13},[a-fA-F0-9]{64}$');
|
|
25
25
|
exports.ARNS_TESTNET_REGISTRY_TX = process.env.ARNS_REGISTRY_TX ?? 'bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U';
|
|
26
26
|
exports.ARNS_DEVNET_REGISTRY_TX = '_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8';
|
|
27
|
-
exports.
|
|
27
|
+
exports.IO_DEVNET_PROCESS_ID = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc';
|
|
28
|
+
// backwards compatibility - TODO: remove in v2.0.0
|
|
29
|
+
exports.ioDevnetProcessId = exports.IO_DEVNET_PROCESS_ID;
|
|
30
|
+
exports.IO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
|
|
28
31
|
exports.MIO_PER_IO = 1_000_000;
|
|
29
|
-
exports.AOS_MODULE_ID = '
|
|
30
|
-
exports.ANT_LUA_ID = '
|
|
32
|
+
exports.AOS_MODULE_ID = 'cbn0KKrBZH7hdNkNokuXLtGryrWM--PjSTBqIzw9Kkk';
|
|
33
|
+
exports.ANT_LUA_ID = '3OlGzE5mrsN2GsxCYM0Tae1KzWepGOr5a94deOWmApM';
|
|
31
34
|
exports.DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getANTProcessesOwnedByWallet = void 0;
|
|
3
|
+
exports.ArNSEventEmitter = exports.getANTProcessesOwnedByWallet = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
6
6
|
*
|
|
@@ -17,15 +17,15 @@ exports.getANTProcessesOwnedByWallet = void 0;
|
|
|
17
17
|
* You should have received a copy of the GNU Affero General Public License
|
|
18
18
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
+
const eventemitter3_1 = require("eventemitter3");
|
|
20
21
|
const plimit_lit_1 = require("plimit-lit");
|
|
21
22
|
const ant_js_1 = require("../../common/ant.js");
|
|
22
23
|
const io_js_1 = require("../../common/io.js");
|
|
23
24
|
const constants_js_1 = require("../../constants.js");
|
|
24
|
-
// throttle the requests to avoid rate limiting
|
|
25
|
-
const throttle = (0, plimit_lit_1.pLimit)(50);
|
|
26
25
|
const getANTProcessesOwnedByWallet = async ({ address, contract = io_js_1.IO.init({
|
|
27
26
|
processId: constants_js_1.ioDevnetProcessId,
|
|
28
27
|
}), }) => {
|
|
28
|
+
const throttle = (0, plimit_lit_1.pLimit)(50);
|
|
29
29
|
// get the record names of the registry - TODO: this may need to be paginated
|
|
30
30
|
const uniqueContractProcessIds = await contract
|
|
31
31
|
.getArNSRecords()
|
|
@@ -33,15 +33,95 @@ const getANTProcessesOwnedByWallet = async ({ address, contract = io_js_1.IO.ini
|
|
|
33
33
|
.filter((record) => record.processId !== undefined)
|
|
34
34
|
.map((record) => record.processId));
|
|
35
35
|
// check the contract owner and controllers
|
|
36
|
-
const ownedOrControlledByWallet = await Promise.all(uniqueContractProcessIds.
|
|
36
|
+
const ownedOrControlledByWallet = await Promise.all(uniqueContractProcessIds.map(async (processId) => throttle(async () => {
|
|
37
37
|
const ant = ant_js_1.ANT.init({
|
|
38
38
|
processId,
|
|
39
39
|
});
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const { Owner, Controllers } = await ant.getState();
|
|
41
|
+
if (Owner === address || Controllers.includes(address)) {
|
|
42
|
+
return processId;
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
43
45
|
})));
|
|
46
|
+
if (ownedOrControlledByWallet.length === 0) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
44
49
|
// TODO: insert gql query to find ANT processes owned by wallet given wallet not currently in the registry
|
|
45
50
|
return [...new Set(ownedOrControlledByWallet)];
|
|
46
51
|
};
|
|
47
52
|
exports.getANTProcessesOwnedByWallet = getANTProcessesOwnedByWallet;
|
|
53
|
+
function timeout(ms, promise) {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
const timer = setTimeout(() => {
|
|
56
|
+
reject(new Error('Timeout'));
|
|
57
|
+
}, ms);
|
|
58
|
+
promise
|
|
59
|
+
.then((value) => {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
resolve(value);
|
|
62
|
+
})
|
|
63
|
+
.catch((err) => {
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
reject(err);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
70
|
+
contract;
|
|
71
|
+
timeoutMs; // timeout for each request to 3 seconds
|
|
72
|
+
throttle;
|
|
73
|
+
constructor({ contract = io_js_1.IO.init({
|
|
74
|
+
processId: constants_js_1.ioDevnetProcessId,
|
|
75
|
+
}), timeoutMs = 60_000, concurrency = 30, }) {
|
|
76
|
+
super();
|
|
77
|
+
this.contract = contract;
|
|
78
|
+
this.timeoutMs = timeoutMs;
|
|
79
|
+
this.throttle = (0, plimit_lit_1.pLimit)(concurrency);
|
|
80
|
+
}
|
|
81
|
+
async fetchProcessesOwnedByWallet({ address }) {
|
|
82
|
+
const uniqueContractProcessIds = {};
|
|
83
|
+
await timeout(this.timeoutMs, this.contract.getArNSRecords().catch((e) => {
|
|
84
|
+
this.emit('error', `Error getting ArNS records: ${e}`);
|
|
85
|
+
return {};
|
|
86
|
+
})).then((records) => {
|
|
87
|
+
if (!records)
|
|
88
|
+
return;
|
|
89
|
+
Object.entries(records).forEach(([name, record]) => {
|
|
90
|
+
if (record.processId === undefined) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (uniqueContractProcessIds[record.processId] === undefined) {
|
|
94
|
+
uniqueContractProcessIds[record.processId] = {
|
|
95
|
+
state: undefined,
|
|
96
|
+
names: {},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
uniqueContractProcessIds[record.processId].names[name] = record;
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
const idCount = Object.keys(uniqueContractProcessIds).length;
|
|
103
|
+
// check the contract owner and controllers
|
|
104
|
+
this.emit('progress', 0, idCount);
|
|
105
|
+
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) => this.throttle(async () => {
|
|
106
|
+
if (uniqueContractProcessIds[processId].state !== undefined) {
|
|
107
|
+
this.emit('progress', i + 1, idCount);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const ant = ant_js_1.ANT.init({
|
|
111
|
+
processId,
|
|
112
|
+
});
|
|
113
|
+
const state = (await timeout(this.timeoutMs, ant.getState()).catch((e) => {
|
|
114
|
+
this.emit('error', `Error getting state for process ${processId}: ${e}`);
|
|
115
|
+
return undefined;
|
|
116
|
+
}));
|
|
117
|
+
if (state?.Owner === address ||
|
|
118
|
+
state?.Controllers.includes(address)) {
|
|
119
|
+
uniqueContractProcessIds[processId].state = state;
|
|
120
|
+
this.emit('process', processId, uniqueContractProcessIds[processId]);
|
|
121
|
+
}
|
|
122
|
+
this.emit('progress', i + 1, idCount);
|
|
123
|
+
})));
|
|
124
|
+
this.emit('end', uniqueContractProcessIds);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.ArNSEventEmitter = ArNSEventEmitter;
|
package/lib/cjs/utils/index.js
CHANGED