@ar.io/sdk 2.1.0-alpha.7 → 2.1.0-alpha.9

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;
@@ -82,7 +82,7 @@ class AoANTReadable {
82
82
  return record;
83
83
  }
84
84
  /**
85
- * @returns {Promise<Record<string, ANTRecord>>} All the undernames managed by the ANT.
85
+ * @returns {Promise<Record<string, AoANTRecord>>} All the undernames managed by the ANT.
86
86
  * @example
87
87
  * Get the current records
88
88
  * ```ts
@@ -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);
@@ -394,11 +394,11 @@ class IOWriteable extends IOReadable {
394
394
  },
395
395
  {
396
396
  name: 'Allow-Delegated-Staking',
397
- value: allowDelegatedStaking.toString(),
397
+ value: allowDelegatedStaking?.toString(),
398
398
  },
399
399
  {
400
400
  name: 'Delegate-Reward-Share-Ratio',
401
- value: delegateRewardShareRatio.toString(),
401
+ value: delegateRewardShareRatio?.toString(),
402
402
  },
403
403
  {
404
404
  name: 'FQDN',
@@ -410,7 +410,7 @@ class IOWriteable extends IOReadable {
410
410
  },
411
411
  {
412
412
  name: 'Min-Delegated-Stake',
413
- value: minDelegatedStake.valueOf().toString(),
413
+ value: minDelegatedStake?.valueOf().toString(),
414
414
  },
415
415
  {
416
416
  name: 'Note',
@@ -418,7 +418,7 @@ class IOWriteable extends IOReadable {
418
418
  },
419
419
  {
420
420
  name: 'Port',
421
- value: port.toString(),
421
+ value: port?.toString(),
422
422
  },
423
423
  {
424
424
  name: 'Properties',
@@ -430,7 +430,7 @@ class IOWriteable extends IOReadable {
430
430
  },
431
431
  {
432
432
  name: 'Auto-Stake',
433
- value: autoStake.toString(),
433
+ value: autoStake?.toString(),
434
434
  },
435
435
  {
436
436
  name: 'Observer-Address',
@@ -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';
package/lib/cjs/io.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLeasedArNSRecord = exports.isProcessIdConfiguration = exports.isProcessConfiguration = void 0;
4
4
  const arweave_js_1 = require("./utils/arweave.js");
5
+ // Typeguard functions
5
6
  function isProcessConfiguration(config) {
6
7
  return 'process' in config;
7
8
  }
@@ -13,6 +14,6 @@ function isProcessIdConfiguration(config) {
13
14
  }
14
15
  exports.isProcessIdConfiguration = isProcessIdConfiguration;
15
16
  function isLeasedArNSRecord(record) {
16
- return record.type === 'lease' && record.endTimestamp !== undefined;
17
+ return record.type === 'lease';
17
18
  }
18
19
  exports.isLeasedArNSRecord = isLeasedArNSRecord;
package/lib/cjs/types.js CHANGED
@@ -30,7 +30,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
30
  * You should have received a copy of the GNU Affero General Public License
31
31
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
32
32
  */
33
- __exportStar(require("./contract-state.js"), exports);
34
33
  __exportStar(require("./common.js"), exports);
35
34
  __exportStar(require("./token.js"), exports);
36
35
  __exportStar(require("./io.js"), exports);
@@ -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.7';
21
+ exports.version = '2.1.0-alpha.9';
@@ -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
+ }
@@ -78,7 +78,7 @@ export class AoANTReadable {
78
78
  return record;
79
79
  }
80
80
  /**
81
- * @returns {Promise<Record<string, ANTRecord>>} All the undernames managed by the ANT.
81
+ * @returns {Promise<Record<string, AoANTRecord>>} All the undernames managed by the ANT.
82
82
  * @example
83
83
  * Get the current records
84
84
  * ```ts
@@ -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';
@@ -389,11 +389,11 @@ export class IOWriteable extends IOReadable {
389
389
  },
390
390
  {
391
391
  name: 'Allow-Delegated-Staking',
392
- value: allowDelegatedStaking.toString(),
392
+ value: allowDelegatedStaking?.toString(),
393
393
  },
394
394
  {
395
395
  name: 'Delegate-Reward-Share-Ratio',
396
- value: delegateRewardShareRatio.toString(),
396
+ value: delegateRewardShareRatio?.toString(),
397
397
  },
398
398
  {
399
399
  name: 'FQDN',
@@ -405,7 +405,7 @@ export class IOWriteable extends IOReadable {
405
405
  },
406
406
  {
407
407
  name: 'Min-Delegated-Stake',
408
- value: minDelegatedStake.valueOf().toString(),
408
+ value: minDelegatedStake?.valueOf().toString(),
409
409
  },
410
410
  {
411
411
  name: 'Note',
@@ -413,7 +413,7 @@ export class IOWriteable extends IOReadable {
413
413
  },
414
414
  {
415
415
  name: 'Port',
416
- value: port.toString(),
416
+ value: port?.toString(),
417
417
  },
418
418
  {
419
419
  name: 'Properties',
@@ -425,7 +425,7 @@ export class IOWriteable extends IOReadable {
425
425
  },
426
426
  {
427
427
  name: 'Auto-Stake',
428
- value: autoStake.toString(),
428
+ value: autoStake?.toString(),
429
429
  },
430
430
  {
431
431
  name: 'Observer-Address',
@@ -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';
package/lib/esm/io.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { validateArweaveId } from './utils/arweave.js';
2
+ // Typeguard functions
2
3
  export function isProcessConfiguration(config) {
3
4
  return 'process' in config;
4
5
  }
@@ -8,5 +9,5 @@ export function isProcessIdConfiguration(config) {
8
9
  validateArweaveId(config.processId) === true);
9
10
  }
10
11
  export function isLeasedArNSRecord(record) {
11
- return record.type === 'lease' && record.endTimestamp !== undefined;
12
+ return record.type === 'lease';
12
13
  }
package/lib/esm/types.js CHANGED
@@ -14,7 +14,6 @@
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
- export * from './contract-state.js';
18
17
  export * from './common.js';
19
18
  export * from './token.js';
20
19
  export * from './io.js';
@@ -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.7';
18
+ export const version = '2.1.0-alpha.9';