@ar.io/sdk 2.1.0-alpha.6 → 2.1.0-alpha.8

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.
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AoANTRegistryWriteable = exports.AoANTRegistryReadable = exports.ANTRegistry = void 0;
4
+ /**
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Affero General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Affero General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Affero General Public License
18
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+ const constants_js_1 = require("../constants.js");
21
+ const types_js_1 = require("../types.js");
22
+ const ao_js_1 = require("../utils/ao.js");
23
+ const index_js_1 = require("./index.js");
24
+ class ANTRegistry {
25
+ static init(config) {
26
+ if (config && config.signer) {
27
+ const { signer, ...rest } = config;
28
+ return new AoANTRegistryWriteable({
29
+ ...rest,
30
+ signer,
31
+ });
32
+ }
33
+ return new AoANTRegistryReadable(config);
34
+ }
35
+ }
36
+ exports.ANTRegistry = ANTRegistry;
37
+ class AoANTRegistryReadable {
38
+ process;
39
+ constructor(config) {
40
+ if (config &&
41
+ ((0, types_js_1.isProcessIdConfiguration)(config) || (0, types_js_1.isProcessConfiguration)(config))) {
42
+ if ((0, types_js_1.isProcessConfiguration)(config)) {
43
+ this.process = config.process;
44
+ }
45
+ else if ((0, types_js_1.isProcessIdConfiguration)(config)) {
46
+ this.process = new index_js_1.AOProcess({
47
+ processId: config.processId,
48
+ });
49
+ }
50
+ else {
51
+ throw new index_js_1.InvalidContractConfigurationError();
52
+ }
53
+ }
54
+ else {
55
+ this.process = new index_js_1.AOProcess({
56
+ processId: constants_js_1.ANT_REGISTRY_ID,
57
+ });
58
+ }
59
+ }
60
+ // Should we rename this to "getANTsByAddress"? seems more clear, though not same as handler name
61
+ async accessControlList({ address, }) {
62
+ return this.process.read({
63
+ tags: [
64
+ { name: 'Action', value: 'Access-Control-List' },
65
+ { name: 'Address', value: address },
66
+ ],
67
+ });
68
+ }
69
+ }
70
+ exports.AoANTRegistryReadable = AoANTRegistryReadable;
71
+ class AoANTRegistryWriteable extends AoANTRegistryReadable {
72
+ signer;
73
+ constructor({ signer, ...config }) {
74
+ super(config);
75
+ this.signer = (0, ao_js_1.createAoSigner)(signer);
76
+ }
77
+ async register({ processId, }) {
78
+ return this.process.send({
79
+ tags: [
80
+ { name: 'Action', value: 'Register' },
81
+ { name: 'Process-Id', value: processId },
82
+ ],
83
+ signer: this.signer,
84
+ });
85
+ }
86
+ }
87
+ exports.AoANTRegistryWriteable = AoANTRegistryWriteable;
@@ -204,7 +204,6 @@ class AoANTWriteable extends AoANTReadable {
204
204
  ];
205
205
  return this.process.send({
206
206
  tags,
207
- data: {},
208
207
  signer: this.signer,
209
208
  });
210
209
  }
@@ -223,7 +222,6 @@ class AoANTWriteable extends AoANTReadable {
223
222
  ];
224
223
  return this.process.send({
225
224
  tags,
226
- data: {},
227
225
  signer: this.signer,
228
226
  });
229
227
  }
@@ -242,7 +240,6 @@ class AoANTWriteable extends AoANTReadable {
242
240
  ];
243
241
  return this.process.send({
244
242
  tags,
245
- data: {},
246
243
  signer: this.signer,
247
244
  });
248
245
  }
@@ -264,7 +261,6 @@ class AoANTWriteable extends AoANTReadable {
264
261
  { name: 'Transaction-Id', value: transactionId },
265
262
  { name: 'TTL-Seconds', value: ttlSeconds.toString() },
266
263
  ],
267
- data: { transactionId, ttlSeconds },
268
264
  signer: this.signer,
269
265
  });
270
266
  }
@@ -282,7 +278,6 @@ class AoANTWriteable extends AoANTReadable {
282
278
  { name: 'Action', value: 'Remove-Record' },
283
279
  { name: 'Sub-Domain', value: undername },
284
280
  ],
285
- data: { undername },
286
281
  signer: this.signer,
287
282
  });
288
283
  }
@@ -300,7 +295,6 @@ class AoANTWriteable extends AoANTReadable {
300
295
  { name: 'Action', value: 'Set-Ticker' },
301
296
  { name: 'Ticker', value: ticker },
302
297
  ],
303
- data: { ticker },
304
298
  signer: this.signer,
305
299
  });
306
300
  }
@@ -318,7 +312,6 @@ class AoANTWriteable extends AoANTReadable {
318
312
  { name: 'Action', value: 'Set-Name' },
319
313
  { name: 'Name', value: name },
320
314
  ],
321
- data: { name },
322
315
  signer: this.signer,
323
316
  });
324
317
  }
@@ -91,7 +91,7 @@ class AOProcess {
91
91
  process: this.processId,
92
92
  // TODO: any other default tags we want to add?
93
93
  tags: [...tags, { name: 'AR-IO-SDK', value: version_js_1.version }],
94
- data: typeof data !== 'string' ? JSON.stringify(data) : data,
94
+ data,
95
95
  signer,
96
96
  });
97
97
  this.logger.debug(`Sent message to process`, {
@@ -33,6 +33,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
33
  __exportStar(require("./error.js"), exports);
34
34
  __exportStar(require("./logger.js"), exports);
35
35
  __exportStar(require("./ant.js"), exports);
36
+ __exportStar(require("./ant-registry.js"), exports);
36
37
  // ao
37
38
  __exportStar(require("./io.js"), exports);
38
39
  __exportStar(require("./contracts/ao-process.js"), exports);
@@ -544,10 +544,6 @@ class IOWriteable extends IOReadable {
544
544
  value: params.failedGateways.join(','),
545
545
  },
546
546
  ],
547
- data: {
548
- reportTxId: params.reportTxId,
549
- failedGateways: params.failedGateways,
550
- },
551
547
  });
552
548
  }
553
549
  async buyRecord(params, options) {
@@ -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.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;
3
+ exports.DEFAULT_SCHEDULER_ID = exports.ANT_LUA_ID = exports.AOS_MODULE_ID = exports.MIO_PER_IO = exports.ANT_REGISTRY_ID = 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
  *
@@ -28,6 +28,7 @@ exports.IO_DEVNET_PROCESS_ID = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc';
28
28
  // backwards compatibility - TODO: remove in v2.0.0
29
29
  exports.ioDevnetProcessId = exports.IO_DEVNET_PROCESS_ID;
30
30
  exports.IO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
31
+ exports.ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc';
31
32
  exports.MIO_PER_IO = 1_000_000;
32
33
  exports.AOS_MODULE_ID = 'cbn0KKrBZH7hdNkNokuXLtGryrWM--PjSTBqIzw9Kkk';
33
34
  exports.ANT_LUA_ID = 'Flwio4Lr08g6s6uim6lEJNnVGD9ylvz0_aafvpiL8FI';
@@ -22,7 +22,7 @@ const arbundles_1 = require("arbundles");
22
22
  const arweave_js_1 = require("../common/arweave.js");
23
23
  const index_js_1 = require("../common/index.js");
24
24
  const constants_js_1 = require("../constants.js");
25
- async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCodeTxId = constants_js_1.ANT_LUA_ID, ao = (0, aoconnect_1.connect)(), scheduler = constants_js_1.DEFAULT_SCHEDULER_ID, state, stateContractTxId, }) {
25
+ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCodeTxId = constants_js_1.ANT_LUA_ID, ao = (0, aoconnect_1.connect)(), scheduler = constants_js_1.DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = constants_js_1.ANT_REGISTRY_ID, }) {
26
26
  //TODO: cache locally and only fetch if not cached
27
27
  const luaString = (await arweave_js_1.defaultArweave.transactions.getData(luaCodeTxId, {
28
28
  decode: true,
@@ -32,6 +32,12 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
32
32
  module,
33
33
  scheduler,
34
34
  signer,
35
+ tags: [
36
+ {
37
+ name: 'ANT-Registry-Id',
38
+ value: antRegistryId,
39
+ },
40
+ ],
35
41
  });
36
42
  const aosClient = new index_js_1.AOProcess({
37
43
  processId,
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.safeDecode = void 0;
4
2
  /**
5
3
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
4
  *
@@ -17,6 +15,9 @@ exports.safeDecode = void 0;
17
15
  * You should have received a copy of the GNU Affero General Public License
18
16
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
17
  */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.safeDecode = void 0;
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
21
  function safeDecode(data) {
21
22
  try {
22
23
  return JSON.parse(data);
@@ -19,37 +19,17 @@ exports.fetchAllArNSRecords = exports.ArNSEventEmitter = exports.getANTProcesses
19
19
  */
20
20
  const eventemitter3_1 = require("eventemitter3");
21
21
  const plimit_lit_1 = require("plimit-lit");
22
+ const ant_registry_js_1 = require("../common/ant-registry.js");
22
23
  const ant_js_1 = require("../common/ant.js");
23
24
  const io_js_1 = require("../common/io.js");
24
25
  const logger_js_1 = require("../common/logger.js");
25
26
  const constants_js_1 = require("../constants.js");
26
- const getANTProcessesOwnedByWallet = async ({ address, contract = io_js_1.IO.init({
27
- processId: constants_js_1.IO_TESTNET_PROCESS_ID,
28
- }), }) => {
29
- const throttle = (0, plimit_lit_1.pLimit)(50);
30
- // get the record names of the registry - TODO: this may need to be paginated
31
- const records = await (0, exports.fetchAllArNSRecords)({
32
- contract: contract,
33
- });
34
- const uniqueContractProcessIds = Object.values(records)
35
- .filter((record) => record.processId !== undefined)
36
- .map((record) => record.processId);
37
- // check the contract owner and controllers
38
- const ownedOrControlledByWallet = await Promise.all(uniqueContractProcessIds.map(async (processId) => throttle(async () => {
39
- const ant = ant_js_1.ANT.init({
40
- processId,
41
- });
42
- const { Owner, Controllers } = await ant.getState();
43
- if (Owner === address || Controllers.includes(address)) {
44
- return processId;
45
- }
46
- return;
47
- })));
48
- if (ownedOrControlledByWallet.length === 0) {
49
- return [];
50
- }
51
- // TODO: insert gql query to find ANT processes owned by wallet given wallet not currently in the registry
52
- return [...new Set(ownedOrControlledByWallet)];
27
+ /**
28
+ * @beta This API is in beta and may change in the future.
29
+ */
30
+ const getANTProcessesOwnedByWallet = async ({ address, registry = ant_registry_js_1.ANTRegistry.init(), }) => {
31
+ const res = await registry.accessControlList({ address });
32
+ return [...new Set([...res.Owned, ...res.Controlled])];
53
33
  };
54
34
  exports.getANTProcessesOwnedByWallet = getANTProcessesOwnedByWallet;
55
35
  function timeout(ms, promise) {
@@ -82,8 +62,10 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
82
62
  this.throttle = (0, plimit_lit_1.pLimit)(concurrency);
83
63
  this.logger = logger;
84
64
  }
85
- async fetchProcessesOwnedByWallet({ address, pageSize, }) {
65
+ async fetchProcessesOwnedByWallet({ address, pageSize, antRegistry = ant_registry_js_1.ANTRegistry.init(), }) {
86
66
  const uniqueContractProcessIds = {};
67
+ const antIdRes = await antRegistry.accessControlList({ address });
68
+ const antIds = new Set([...antIdRes.Owned, ...antIdRes.Controlled]);
87
69
  await timeout(this.timeoutMs, (0, exports.fetchAllArNSRecords)({ contract: this.contract, emitter: this, pageSize }))
88
70
  .catch((e) => {
89
71
  this.emit('error', `Error getting ArNS records: ${e}`);
@@ -94,19 +76,17 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
94
76
  return {};
95
77
  })
96
78
  .then((records) => {
97
- if (!records)
98
- return;
99
- Object.entries(records).forEach(([name, record]) => {
100
- if (record.processId === undefined) {
101
- return;
102
- }
103
- if (uniqueContractProcessIds[record.processId] === undefined) {
104
- uniqueContractProcessIds[record.processId] = {
105
- state: undefined,
106
- names: {},
107
- };
79
+ Object.entries(records).forEach(([name, arnsRecord]) => {
80
+ if (antIds.has(arnsRecord.processId)) {
81
+ if (uniqueContractProcessIds[arnsRecord.processId] == undefined) {
82
+ uniqueContractProcessIds[arnsRecord.processId] = {
83
+ state: undefined,
84
+ names: {},
85
+ };
86
+ }
87
+ uniqueContractProcessIds[arnsRecord.processId].names[name] =
88
+ arnsRecord;
108
89
  }
109
- uniqueContractProcessIds[record.processId].names[name] = record;
110
90
  });
111
91
  });
112
92
  const idCount = Object.keys(uniqueContractProcessIds).length;
@@ -144,6 +124,7 @@ const fetchAllArNSRecords = async ({ contract = io_js_1.IO.init({
144
124
  do {
145
125
  const pageResult = await contract
146
126
  .getArNSRecords({ cursor, limit: pageSize })
127
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
147
128
  .catch((e) => {
148
129
  logger?.error(`Error getting ArNS records`, {
149
130
  message: e?.message,
@@ -18,4 +18,4 @@
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.version = void 0;
20
20
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
21
- exports.version = '2.1.0-alpha.6';
21
+ exports.version = '2.1.0-alpha.8';
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as published by
6
+ * the Free Software Foundation, either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import { ANT_REGISTRY_ID } from '../constants.js';
18
+ import { isProcessConfiguration, isProcessIdConfiguration, } from '../types.js';
19
+ import { createAoSigner } from '../utils/ao.js';
20
+ import { AOProcess, InvalidContractConfigurationError } from './index.js';
21
+ export class ANTRegistry {
22
+ static init(config) {
23
+ if (config && config.signer) {
24
+ const { signer, ...rest } = config;
25
+ return new AoANTRegistryWriteable({
26
+ ...rest,
27
+ signer,
28
+ });
29
+ }
30
+ return new AoANTRegistryReadable(config);
31
+ }
32
+ }
33
+ export class AoANTRegistryReadable {
34
+ process;
35
+ constructor(config) {
36
+ if (config &&
37
+ (isProcessIdConfiguration(config) || isProcessConfiguration(config))) {
38
+ if (isProcessConfiguration(config)) {
39
+ this.process = config.process;
40
+ }
41
+ else if (isProcessIdConfiguration(config)) {
42
+ this.process = new AOProcess({
43
+ processId: config.processId,
44
+ });
45
+ }
46
+ else {
47
+ throw new InvalidContractConfigurationError();
48
+ }
49
+ }
50
+ else {
51
+ this.process = new AOProcess({
52
+ processId: ANT_REGISTRY_ID,
53
+ });
54
+ }
55
+ }
56
+ // Should we rename this to "getANTsByAddress"? seems more clear, though not same as handler name
57
+ async accessControlList({ address, }) {
58
+ return this.process.read({
59
+ tags: [
60
+ { name: 'Action', value: 'Access-Control-List' },
61
+ { name: 'Address', value: address },
62
+ ],
63
+ });
64
+ }
65
+ }
66
+ export class AoANTRegistryWriteable extends AoANTRegistryReadable {
67
+ signer;
68
+ constructor({ signer, ...config }) {
69
+ super(config);
70
+ this.signer = createAoSigner(signer);
71
+ }
72
+ async register({ processId, }) {
73
+ return this.process.send({
74
+ tags: [
75
+ { name: 'Action', value: 'Register' },
76
+ { name: 'Process-Id', value: processId },
77
+ ],
78
+ signer: this.signer,
79
+ });
80
+ }
81
+ }
@@ -199,7 +199,6 @@ export class AoANTWriteable extends AoANTReadable {
199
199
  ];
200
200
  return this.process.send({
201
201
  tags,
202
- data: {},
203
202
  signer: this.signer,
204
203
  });
205
204
  }
@@ -218,7 +217,6 @@ export class AoANTWriteable extends AoANTReadable {
218
217
  ];
219
218
  return this.process.send({
220
219
  tags,
221
- data: {},
222
220
  signer: this.signer,
223
221
  });
224
222
  }
@@ -237,7 +235,6 @@ export class AoANTWriteable extends AoANTReadable {
237
235
  ];
238
236
  return this.process.send({
239
237
  tags,
240
- data: {},
241
238
  signer: this.signer,
242
239
  });
243
240
  }
@@ -259,7 +256,6 @@ export class AoANTWriteable extends AoANTReadable {
259
256
  { name: 'Transaction-Id', value: transactionId },
260
257
  { name: 'TTL-Seconds', value: ttlSeconds.toString() },
261
258
  ],
262
- data: { transactionId, ttlSeconds },
263
259
  signer: this.signer,
264
260
  });
265
261
  }
@@ -277,7 +273,6 @@ export class AoANTWriteable extends AoANTReadable {
277
273
  { name: 'Action', value: 'Remove-Record' },
278
274
  { name: 'Sub-Domain', value: undername },
279
275
  ],
280
- data: { undername },
281
276
  signer: this.signer,
282
277
  });
283
278
  }
@@ -295,7 +290,6 @@ export class AoANTWriteable extends AoANTReadable {
295
290
  { name: 'Action', value: 'Set-Ticker' },
296
291
  { name: 'Ticker', value: ticker },
297
292
  ],
298
- data: { ticker },
299
293
  signer: this.signer,
300
294
  });
301
295
  }
@@ -313,7 +307,6 @@ export class AoANTWriteable extends AoANTReadable {
313
307
  { name: 'Action', value: 'Set-Name' },
314
308
  { name: 'Name', value: name },
315
309
  ],
316
- data: { name },
317
310
  signer: this.signer,
318
311
  });
319
312
  }
@@ -88,7 +88,7 @@ export class AOProcess {
88
88
  process: this.processId,
89
89
  // TODO: any other default tags we want to add?
90
90
  tags: [...tags, { name: 'AR-IO-SDK', value: version }],
91
- data: typeof data !== 'string' ? JSON.stringify(data) : data,
91
+ data,
92
92
  signer,
93
93
  });
94
94
  this.logger.debug(`Sent message to process`, {
@@ -17,6 +17,7 @@
17
17
  export * from './error.js';
18
18
  export * from './logger.js';
19
19
  export * from './ant.js';
20
+ export * from './ant-registry.js';
20
21
  // ao
21
22
  export * from './io.js';
22
23
  export * from './contracts/ao-process.js';
@@ -539,10 +539,6 @@ export class IOWriteable extends IOReadable {
539
539
  value: params.failedGateways.join(','),
540
540
  },
541
541
  ],
542
- data: {
543
- reportTxId: params.reportTxId,
544
- failedGateways: params.failedGateways,
545
- },
546
542
  });
547
543
  }
548
544
  async buyRecord(params, options) {
@@ -25,6 +25,7 @@ export const IO_DEVNET_PROCESS_ID = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc
25
25
  // backwards compatibility - TODO: remove in v2.0.0
26
26
  export const ioDevnetProcessId = IO_DEVNET_PROCESS_ID;
27
27
  export const IO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
28
+ export const ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc';
28
29
  export const MIO_PER_IO = 1_000_000;
29
30
  export const AOS_MODULE_ID = 'cbn0KKrBZH7hdNkNokuXLtGryrWM--PjSTBqIzw9Kkk';
30
31
  export const ANT_LUA_ID = 'Flwio4Lr08g6s6uim6lEJNnVGD9ylvz0_aafvpiL8FI';
@@ -18,8 +18,8 @@ import { connect, createDataItemSigner } from '@permaweb/aoconnect';
18
18
  import { createData } from 'arbundles';
19
19
  import { defaultArweave } from '../common/arweave.js';
20
20
  import { AOProcess } from '../common/index.js';
21
- import { ANT_LUA_ID, AOS_MODULE_ID, DEFAULT_SCHEDULER_ID, } from '../constants.js';
22
- export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = ANT_LUA_ID, ao = connect(), scheduler = DEFAULT_SCHEDULER_ID, state, stateContractTxId, }) {
21
+ import { ANT_LUA_ID, ANT_REGISTRY_ID, AOS_MODULE_ID, DEFAULT_SCHEDULER_ID, } from '../constants.js';
22
+ export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = ANT_LUA_ID, ao = connect(), scheduler = DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = ANT_REGISTRY_ID, }) {
23
23
  //TODO: cache locally and only fetch if not cached
24
24
  const luaString = (await defaultArweave.transactions.getData(luaCodeTxId, {
25
25
  decode: true,
@@ -29,6 +29,12 @@ export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = A
29
29
  module,
30
30
  scheduler,
31
31
  signer,
32
+ tags: [
33
+ {
34
+ name: 'ANT-Registry-Id',
35
+ value: antRegistryId,
36
+ },
37
+ ],
32
38
  });
33
39
  const aosClient = new AOProcess({
34
40
  processId,
@@ -14,6 +14,7 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
18
  export function safeDecode(data) {
18
19
  try {
19
20
  return JSON.parse(data);
@@ -16,37 +16,17 @@
16
16
  */
17
17
  import { EventEmitter } from 'eventemitter3';
18
18
  import { pLimit } from 'plimit-lit';
19
+ import { ANTRegistry } from '../common/ant-registry.js';
19
20
  import { ANT } from '../common/ant.js';
20
21
  import { IO } from '../common/io.js';
21
22
  import { Logger } from '../common/logger.js';
22
23
  import { IO_TESTNET_PROCESS_ID } from '../constants.js';
23
- export const getANTProcessesOwnedByWallet = async ({ address, contract = IO.init({
24
- processId: IO_TESTNET_PROCESS_ID,
25
- }), }) => {
26
- const throttle = pLimit(50);
27
- // get the record names of the registry - TODO: this may need to be paginated
28
- const records = await fetchAllArNSRecords({
29
- contract: contract,
30
- });
31
- const uniqueContractProcessIds = Object.values(records)
32
- .filter((record) => record.processId !== undefined)
33
- .map((record) => record.processId);
34
- // check the contract owner and controllers
35
- const ownedOrControlledByWallet = await Promise.all(uniqueContractProcessIds.map(async (processId) => throttle(async () => {
36
- const ant = ANT.init({
37
- processId,
38
- });
39
- const { Owner, Controllers } = await ant.getState();
40
- if (Owner === address || Controllers.includes(address)) {
41
- return processId;
42
- }
43
- return;
44
- })));
45
- if (ownedOrControlledByWallet.length === 0) {
46
- return [];
47
- }
48
- // TODO: insert gql query to find ANT processes owned by wallet given wallet not currently in the registry
49
- return [...new Set(ownedOrControlledByWallet)];
24
+ /**
25
+ * @beta This API is in beta and may change in the future.
26
+ */
27
+ export const getANTProcessesOwnedByWallet = async ({ address, registry = ANTRegistry.init(), }) => {
28
+ const res = await registry.accessControlList({ address });
29
+ return [...new Set([...res.Owned, ...res.Controlled])];
50
30
  };
51
31
  function timeout(ms, promise) {
52
32
  return new Promise((resolve, reject) => {
@@ -78,8 +58,10 @@ export class ArNSEventEmitter extends EventEmitter {
78
58
  this.throttle = pLimit(concurrency);
79
59
  this.logger = logger;
80
60
  }
81
- async fetchProcessesOwnedByWallet({ address, pageSize, }) {
61
+ async fetchProcessesOwnedByWallet({ address, pageSize, antRegistry = ANTRegistry.init(), }) {
82
62
  const uniqueContractProcessIds = {};
63
+ const antIdRes = await antRegistry.accessControlList({ address });
64
+ const antIds = new Set([...antIdRes.Owned, ...antIdRes.Controlled]);
83
65
  await timeout(this.timeoutMs, fetchAllArNSRecords({ contract: this.contract, emitter: this, pageSize }))
84
66
  .catch((e) => {
85
67
  this.emit('error', `Error getting ArNS records: ${e}`);
@@ -90,19 +72,17 @@ export class ArNSEventEmitter extends EventEmitter {
90
72
  return {};
91
73
  })
92
74
  .then((records) => {
93
- if (!records)
94
- return;
95
- Object.entries(records).forEach(([name, record]) => {
96
- if (record.processId === undefined) {
97
- return;
98
- }
99
- if (uniqueContractProcessIds[record.processId] === undefined) {
100
- uniqueContractProcessIds[record.processId] = {
101
- state: undefined,
102
- names: {},
103
- };
75
+ Object.entries(records).forEach(([name, arnsRecord]) => {
76
+ if (antIds.has(arnsRecord.processId)) {
77
+ if (uniqueContractProcessIds[arnsRecord.processId] == undefined) {
78
+ uniqueContractProcessIds[arnsRecord.processId] = {
79
+ state: undefined,
80
+ names: {},
81
+ };
82
+ }
83
+ uniqueContractProcessIds[arnsRecord.processId].names[name] =
84
+ arnsRecord;
104
85
  }
105
- uniqueContractProcessIds[record.processId].names[name] = record;
106
86
  });
107
87
  });
108
88
  const idCount = Object.keys(uniqueContractProcessIds).length;
@@ -139,6 +119,7 @@ export const fetchAllArNSRecords = async ({ contract = IO.init({
139
119
  do {
140
120
  const pageResult = await contract
141
121
  .getArNSRecords({ cursor, limit: pageSize })
122
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
123
  .catch((e) => {
143
124
  logger?.error(`Error getting ArNS records`, {
144
125
  message: e?.message,
@@ -15,4 +15,4 @@
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
18
- export const version = '2.1.0-alpha.6';
18
+ export const version = '2.1.0-alpha.8';