@ar.io/sdk 3.3.0-alpha.1 → 3.3.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.
@@ -64,6 +64,12 @@ const utils_js_1 = require("./utils.js");
64
64
  options: options_js_1.paginationOptions,
65
65
  action: readCommands_js_1.listGateways,
66
66
  });
67
+ (0, utils_js_1.makeCommand)({
68
+ name: 'list-all-delegates',
69
+ description: 'List all paginated delegates from all gateways',
70
+ options: options_js_1.paginationOptions,
71
+ action: readCommands_js_1.listAllDelegatesCLICommand,
72
+ });
67
73
  (0, utils_js_1.makeCommand)({
68
74
  name: 'get-gateway-delegates',
69
75
  description: 'Get the delegates of a gateway',
@@ -658,6 +664,20 @@ const utils_js_1 = require("./utils.js");
658
664
  }, (0, utils_js_1.writeActionTagsFromOptions)(options));
659
665
  },
660
666
  });
667
+ (0, utils_js_1.makeCommand)({
668
+ name: 'write-action',
669
+ description: 'Send a write action to an AO Process',
670
+ options: [...options_js_1.writeActionOptions, options_js_1.optionMap.processId],
671
+ action: async (options) => {
672
+ const process = new index_js_1.AOProcess({
673
+ processId: (0, utils_js_1.requiredProcessIdFromOptions)(options),
674
+ });
675
+ return process.send({
676
+ tags: (0, utils_js_1.writeActionTagsFromOptions)(options).tags ?? [],
677
+ signer: (0, utils_js_1.requiredAoSignerFromOptions)(options),
678
+ });
679
+ },
680
+ });
661
681
  if (process.argv[1].includes('bin/ar.io') || // Running from global .bin
662
682
  process.argv[1].includes('cli/cli') // Running from source
663
683
  ) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVault = exports.getGatewayVaults = exports.getPrimaryName = exports.getCostDetails = exports.getTokenCost = exports.getPrescribedNames = exports.getPrescribedObservers = exports.getEpoch = exports.listArNSReturnedNames = exports.getArNSReturnedName = exports.listArNSReservedNames = exports.getArNSReservedName = exports.listArNSRecords = exports.getArNSRecord = exports.getAllowedDelegates = exports.getDelegations = exports.getGatewayDelegates = exports.listGateways = exports.getGateway = void 0;
3
+ exports.getVault = exports.getGatewayVaults = exports.getPrimaryName = exports.getCostDetails = exports.getTokenCost = exports.getPrescribedNames = exports.getPrescribedObservers = exports.getEpoch = exports.listArNSReturnedNames = exports.getArNSReturnedName = exports.listArNSReservedNames = exports.getArNSReservedName = exports.listArNSRecords = exports.getArNSRecord = exports.getAllowedDelegates = exports.getDelegations = exports.getGatewayDelegates = exports.listAllDelegatesCLICommand = exports.listGateways = exports.getGateway = void 0;
4
4
  const token_js_1 = require("../../types/token.js");
5
5
  const utils_js_1 = require("../utils.js");
6
6
  async function getGateway(o) {
@@ -16,6 +16,11 @@ async function listGateways(o) {
16
16
  return gateways.items.length ? gateways : { message: 'No gateways found' };
17
17
  }
18
18
  exports.listGateways = listGateways;
19
+ async function listAllDelegatesCLICommand(o) {
20
+ const delegates = await (0, utils_js_1.readARIOFromOptions)(o).getAllDelegates((0, utils_js_1.paginationParamsFromOptions)(o));
21
+ return delegates.items.length ? delegates : { message: 'No delegates found' };
22
+ }
23
+ exports.listAllDelegatesCLICommand = listAllDelegatesCLICommand;
19
24
  async function getGatewayDelegates(o) {
20
25
  const address = (0, utils_js_1.requiredAddressFromOptions)(o);
21
26
  const result = await (0, utils_js_1.readARIOFromOptions)(o).getGatewayDelegates({
@@ -22,12 +22,8 @@ const ao_js_1 = require("../utils/ao.js");
22
22
  const index_js_2 = require("./index.js");
23
23
  class ANTRegistry {
24
24
  static init(config) {
25
- if (config && config.signer) {
26
- const { signer, ...rest } = config;
27
- return new AoANTRegistryWriteable({
28
- ...rest,
29
- signer,
30
- });
25
+ if (config !== undefined && 'signer' in config) {
26
+ return new AoANTRegistryWriteable(config);
31
27
  }
32
28
  return new AoANTRegistryReadable(config);
33
29
  }
@@ -36,25 +32,22 @@ exports.ANTRegistry = ANTRegistry;
36
32
  class AoANTRegistryReadable {
37
33
  process;
38
34
  constructor(config) {
39
- if (config &&
40
- ((0, index_js_1.isProcessIdConfiguration)(config) || (0, index_js_1.isProcessConfiguration)(config))) {
41
- if ((0, index_js_1.isProcessConfiguration)(config)) {
42
- this.process = config.process;
43
- }
44
- else if ((0, index_js_1.isProcessIdConfiguration)(config)) {
45
- this.process = new index_js_2.AOProcess({
46
- processId: config.processId,
47
- });
48
- }
49
- else {
50
- throw new index_js_2.InvalidContractConfigurationError();
51
- }
52
- }
53
- else {
35
+ if (config === undefined || Object.keys(config).length === 0) {
54
36
  this.process = new index_js_2.AOProcess({
55
37
  processId: constants_js_1.ANT_REGISTRY_ID,
56
38
  });
57
39
  }
40
+ else if ((0, index_js_1.isProcessConfiguration)(config)) {
41
+ this.process = config.process;
42
+ }
43
+ else if ((0, index_js_1.isProcessIdConfiguration)(config)) {
44
+ this.process = new index_js_2.AOProcess({
45
+ processId: config.processId,
46
+ });
47
+ }
48
+ else {
49
+ throw new index_js_2.InvalidContractConfigurationError();
50
+ }
58
51
  }
59
52
  // Should we rename this to "getANTsByAddress"? seems more clear, though not same as handler name
60
53
  async accessControlList({ address, }) {
@@ -23,15 +23,12 @@ const ao_js_1 = require("../utils/ao.js");
23
23
  const schema_js_1 = require("../utils/schema.js");
24
24
  const index_js_2 = require("./index.js");
25
25
  class ANT {
26
- static init({ signer, strict = false, ...config }) {
27
- // ao supported implementation
28
- if ((0, index_js_1.isProcessConfiguration)(config) || (0, index_js_1.isProcessIdConfiguration)(config)) {
29
- if (!signer) {
30
- return new AoANTReadable({ strict, ...config });
31
- }
32
- return new AoANTWriteable({ signer, strict, ...config });
26
+ // implementation
27
+ static init(config) {
28
+ if (config !== undefined && 'signer' in config) {
29
+ return new AoANTWriteable(config);
33
30
  }
34
- throw new index_js_2.InvalidContractConfigurationError();
31
+ return new AoANTReadable(config);
35
32
  }
36
33
  }
37
34
  exports.ANT = ANT;
@@ -42,8 +42,9 @@ class AOProcess {
42
42
  let lastError;
43
43
  while (attempts < retries) {
44
44
  try {
45
- this.logger.debug(`Evaluating read interaction on contract`, {
45
+ this.logger.debug(`Evaluating read interaction on process`, {
46
46
  tags,
47
+ processId: this.processId,
47
48
  });
48
49
  // map tags to inputs
49
50
  const dryRunInput = {
@@ -56,13 +57,18 @@ class AOProcess {
56
57
  const result = await this.ao.dryrun(dryRunInput);
57
58
  this.logger.debug(`Read interaction result`, {
58
59
  result,
60
+ processId: this.processId,
59
61
  });
60
62
  const error = errorMessageFromOutput(result);
61
63
  if (error !== undefined) {
62
64
  throw new Error(error);
63
65
  }
64
66
  if (result.Messages === undefined || result.Messages.length === 0) {
65
- this.logger.debug(`Process ${this.processId} does not support provided action.`, result, tags);
67
+ this.logger.debug(`Process ${this.processId} does not support provided action.`, {
68
+ result,
69
+ tags,
70
+ processId: this.processId,
71
+ });
66
72
  throw new Error(`Process ${this.processId} does not support provided action.`);
67
73
  }
68
74
  const messageData = result.Messages?.[0]?.Data;
@@ -70,16 +76,18 @@ class AOProcess {
70
76
  if (this.isMessageDataEmpty(messageData)) {
71
77
  return undefined;
72
78
  }
73
- const response = (0, json_js_1.safeDecode)(result.Messages[0].Data);
79
+ const response = (0, json_js_1.safeDecode)(messageData);
74
80
  return response;
75
81
  }
76
- catch (e) {
82
+ catch (error) {
77
83
  attempts++;
78
84
  this.logger.debug(`Read attempt ${attempts} failed`, {
79
- error: e instanceof Error ? e.message : e,
85
+ error: error?.message,
86
+ stack: error?.stack,
80
87
  tags,
88
+ processId: this.processId,
81
89
  });
82
- lastError = e;
90
+ lastError = error;
83
91
  // exponential backoff
84
92
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 1000));
85
93
  }
@@ -147,16 +155,17 @@ class AOProcess {
147
155
  }
148
156
  catch (error) {
149
157
  this.logger.error('Error sending message to process', {
150
- error: error.message,
158
+ error: error?.message,
159
+ stack: error?.stack,
151
160
  processId: this.processId,
152
161
  tags,
153
162
  });
154
- // throw on write interaction errors. No point retrying wr ite interactions, waste of gas.
163
+ // throw on write interaction errors. No point retrying write interactions, waste of gas.
155
164
  if (error.message.includes('500')) {
156
165
  this.logger.debug('Retrying send interaction', {
157
166
  attempts,
158
167
  retries,
159
- error: error.message,
168
+ error: error?.message,
160
169
  processId: this.processId,
161
170
  });
162
171
  // exponential backoff
@@ -174,18 +183,16 @@ class AOProcess {
174
183
  exports.AOProcess = AOProcess;
175
184
  function errorMessageFromOutput(output) {
176
185
  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;
186
+ // Attempt to extract error details from Messages.Tags if Error is undefined
187
+ const error = errorData ??
188
+ output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
183
189
  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();
190
+ // Consolidated regex to match and extract line number and AO error message or Error Tags
191
+ const match = error.match(/\[string "aos"]:(\d+):\s*(.+)/);
192
+ if (match) {
193
+ const [, lineNumber, errorMessage] = match;
194
+ return `${errorMessage.trim()} (line ${lineNumber.trim()})`.trim();
195
+ }
189
196
  }
190
197
  return undefined;
191
198
  }
@@ -1,45 +1,20 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.ARIOWriteable = exports.ARIOReadable = exports.ARIO = void 0;
7
- /**
8
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
9
- *
10
- * Licensed under the Apache License, Version 2.0 (the "License");
11
- * you may not use this file except in compliance with the License.
12
- * You may obtain a copy of the License at
13
- *
14
- * http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- const arweave_1 = __importDefault(require("arweave"));
23
4
  const constants_js_1 = require("../constants.js");
24
5
  const io_js_1 = require("../types/io.js");
25
6
  const ao_js_1 = require("../utils/ao.js");
26
7
  const arweave_js_1 = require("../utils/arweave.js");
8
+ const arweave_js_2 = require("./arweave.js");
27
9
  const ao_process_js_1 = require("./contracts/ao-process.js");
28
10
  const error_js_1 = require("./error.js");
29
11
  class ARIO {
30
- static init({ arweave, ...config } = {}) {
31
- if (config !== undefined && config.signer) {
32
- const { signer, ...rest } = config;
33
- return new ARIOWriteable({
34
- ...rest,
35
- signer,
36
- arweave,
37
- });
12
+ // Implementation
13
+ static init(config) {
14
+ if (config !== undefined && 'signer' in config) {
15
+ return new ARIOWriteable(config);
38
16
  }
39
- return new ARIOReadable({
40
- arweave,
41
- ...config,
42
- });
17
+ return new ARIOReadable(config);
43
18
  }
44
19
  }
45
20
  exports.ARIO = ARIO;
@@ -47,12 +22,9 @@ class ARIOReadable {
47
22
  process;
48
23
  epochSettings;
49
24
  arweave;
50
- constructor({ arweave = arweave_1.default.init({
51
- host: 'arweave.net',
52
- port: 443,
53
- protocol: 'https',
54
- }), ...config }) {
55
- if (config === undefined) {
25
+ constructor(config) {
26
+ this.arweave = config?.arweave ?? arweave_js_2.defaultArweave;
27
+ if (config === undefined || Object.keys(config).length === 0) {
56
28
  this.process = new ao_process_js_1.AOProcess({
57
29
  processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
58
30
  });
@@ -68,7 +40,6 @@ class ARIOReadable {
68
40
  else {
69
41
  throw new error_js_1.InvalidContractConfigurationError();
70
42
  }
71
- this.arweave = arweave;
72
43
  }
73
44
  async getInfo() {
74
45
  return this.process.read({
@@ -470,36 +441,30 @@ class ARIOReadable {
470
441
  tags: [{ name: 'Action', value: 'Gateway-Registry-Settings' }],
471
442
  });
472
443
  }
444
+ async getAllDelegates(params) {
445
+ return this.process.read({
446
+ tags: [
447
+ { name: 'Action', value: 'All-Paginated-Delegates' },
448
+ ...(0, arweave_js_1.paginationParamsToTags)(params),
449
+ ],
450
+ });
451
+ }
473
452
  }
474
453
  exports.ARIOReadable = ARIOReadable;
475
454
  class ARIOWriteable extends ARIOReadable {
476
455
  signer;
477
- constructor({ signer, arweave, ...config }) {
478
- if (Object.keys(config).length === 0) {
456
+ constructor({ signer, ...config }) {
457
+ if (config === undefined) {
479
458
  super({
480
459
  process: new ao_process_js_1.AOProcess({
481
460
  processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
482
461
  }),
483
- arweave: arweave,
484
462
  });
485
- this.signer = (0, ao_js_1.createAoSigner)(signer);
486
- }
487
- else if ((0, io_js_1.isProcessConfiguration)(config)) {
488
- super({ process: config.process });
489
- this.signer = (0, ao_js_1.createAoSigner)(signer);
490
- }
491
- else if ((0, io_js_1.isProcessIdConfiguration)(config)) {
492
- super({
493
- process: new ao_process_js_1.AOProcess({
494
- processId: config.processId,
495
- }),
496
- arweave: arweave,
497
- });
498
- this.signer = (0, ao_js_1.createAoSigner)(signer);
499
463
  }
500
464
  else {
501
- throw new error_js_1.InvalidContractConfigurationError();
465
+ super(config);
502
466
  }
467
+ this.signer = (0, ao_js_1.createAoSigner)(signer);
503
468
  }
504
469
  async transfer({ target, qty, }, options) {
505
470
  const { tags = [] } = options || {};
@@ -29,6 +29,6 @@ exports.arioDevnetProcessId = exports.ARIO_DEVNET_PROCESS_ID;
29
29
  exports.ARIO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
30
30
  exports.ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc';
31
31
  exports.MARIO_PER_ARIO = 1_000_000;
32
- exports.AOS_MODULE_ID = 'tyojTpJ9fIva_7BjTA9ruGM4uk2vyTfhVUulnbVxR8I';
33
- exports.ANT_LUA_ID = '16_FyX-V2QU0RPSh1GIaEETSaUjNb0oVjCFpVbAfQq4';
32
+ exports.AOS_MODULE_ID = 'BRyNPIJWZaQ4IudfNnsfvMrZBO2YDPjgKqg_wCYT2U8';
33
+ exports.ANT_LUA_ID = 'k9tQkbnFYZOGp6ist1yFuaqk_wOkzM5KUSNDtWzCLtg';
34
34
  exports.DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
@@ -153,6 +153,20 @@ function createAoSigner(signer) {
153
153
  typeof signer.setPublicKey === 'function') {
154
154
  await signer.setPublicKey();
155
155
  }
156
+ if (signer instanceof arbundles_1.ArconnectSigner) {
157
+ // Sign using Arconnect signDataItem API
158
+ const signedDataItem = await signer['signer'].signDataItem({
159
+ data,
160
+ tags,
161
+ target,
162
+ anchor,
163
+ });
164
+ const dataItem = new arbundles_1.DataItem(Buffer.from(signedDataItem));
165
+ return {
166
+ id: await dataItem.id,
167
+ raw: await dataItem.getRaw(),
168
+ };
169
+ }
156
170
  const dataItem = (0, arbundles_1.createData)(data, signer, { tags, target, anchor });
157
171
  const signedData = dataItem.sign(signer).then(async () => ({
158
172
  id: await dataItem.id,
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '3.3.0-alpha.1';
20
+ exports.version = '3.3.0-alpha.10';
@@ -16,15 +16,15 @@
16
16
  */
17
17
  // eslint-disable-next-line header/header -- This is a CLI file
18
18
  import { program } from 'commander';
19
- import { spawnANT } from '../node/index.js';
19
+ import { AOProcess, spawnANT } from '../node/index.js';
20
20
  import { mARIOToken } from '../types/token.js';
21
21
  import { version } from '../version.js';
22
22
  import { buyRecordCLICommand, extendLeaseCLICommand, increaseUndernameLimitCLICommand, requestPrimaryNameCLICommand, upgradeRecordCLICommand, } from './commands/arnsPurchaseCommands.js';
23
23
  import { cancelWithdrawal, decreaseDelegateStake, decreaseOperatorStake, delegateStake, increaseOperatorStake, instantWithdrawal, joinNetwork, leaveNetwork, redelegateStake, saveObservations, updateGatewaySettings, } from './commands/gatewayWriteCommands.js';
24
- import { getAllowedDelegates, getArNSRecord, getArNSReservedName, getArNSReturnedName, getCostDetails, getDelegations, getEpoch, getGateway, getGatewayDelegates, getGatewayVaults, getPrescribedNames, getPrescribedObservers, getPrimaryName, getTokenCost, getVault, listArNSRecords, listArNSReservedNames, listArNSReturnedNames, listGateways, } from './commands/readCommands.js';
24
+ import { getAllowedDelegates, getArNSRecord, getArNSReservedName, getArNSReturnedName, getCostDetails, getDelegations, getEpoch, getGateway, getGatewayDelegates, getGatewayVaults, getPrescribedNames, getPrescribedObservers, getPrimaryName, getTokenCost, getVault, listAllDelegatesCLICommand, listArNSRecords, listArNSReservedNames, listArNSReturnedNames, listGateways, } from './commands/readCommands.js';
25
25
  import { transfer } from './commands/transfer.js';
26
26
  import { addressAndVaultIdOptions, antStateOptions, arnsPurchaseOptions, buyRecordOptions, decreaseDelegateStakeOptions, delegateStakeOptions, epochOptions, getVaultOptions, globalOptions, joinNetworkOptions, operatorStakeOptions, optionMap, paginationAddressOptions, paginationOptions, redelegateStakeOptions, tokenCostOptions, transferOptions, updateGatewaySettingsOptions, writeActionOptions, } from './options.js';
27
- import { applyOptions, arioProcessIdFromOptions, assertConfirmationPrompt, epochInputFromOptions, formatARIOWithCommas, getANTStateFromOptions, getLoggerFromOptions, makeCommand, paginationParamsFromOptions, readANTFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredAoSignerFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, writeANTFromOptions, writeActionTagsFromOptions, } from './utils.js';
27
+ import { applyOptions, arioProcessIdFromOptions, assertConfirmationPrompt, epochInputFromOptions, formatARIOWithCommas, getANTStateFromOptions, getLoggerFromOptions, makeCommand, paginationParamsFromOptions, readANTFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredAoSignerFromOptions, requiredProcessIdFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, writeANTFromOptions, writeActionTagsFromOptions, } from './utils.js';
28
28
  applyOptions(program
29
29
  .name('ar.io')
30
30
  .version(version)
@@ -62,6 +62,12 @@ makeCommand({
62
62
  options: paginationOptions,
63
63
  action: listGateways,
64
64
  });
65
+ makeCommand({
66
+ name: 'list-all-delegates',
67
+ description: 'List all paginated delegates from all gateways',
68
+ options: paginationOptions,
69
+ action: listAllDelegatesCLICommand,
70
+ });
65
71
  makeCommand({
66
72
  name: 'get-gateway-delegates',
67
73
  description: 'Get the delegates of a gateway',
@@ -656,6 +662,20 @@ makeCommand({
656
662
  }, writeActionTagsFromOptions(options));
657
663
  },
658
664
  });
665
+ makeCommand({
666
+ name: 'write-action',
667
+ description: 'Send a write action to an AO Process',
668
+ options: [...writeActionOptions, optionMap.processId],
669
+ action: async (options) => {
670
+ const process = new AOProcess({
671
+ processId: requiredProcessIdFromOptions(options),
672
+ });
673
+ return process.send({
674
+ tags: writeActionTagsFromOptions(options).tags ?? [],
675
+ signer: requiredAoSignerFromOptions(options),
676
+ });
677
+ },
678
+ });
659
679
  if (process.argv[1].includes('bin/ar.io') || // Running from global .bin
660
680
  process.argv[1].includes('cli/cli') // Running from source
661
681
  ) {
@@ -11,6 +11,10 @@ export async function listGateways(o) {
11
11
  const gateways = await readARIOFromOptions(o).getGateways(paginationParamsFromOptions(o));
12
12
  return gateways.items.length ? gateways : { message: 'No gateways found' };
13
13
  }
14
+ export async function listAllDelegatesCLICommand(o) {
15
+ const delegates = await readARIOFromOptions(o).getAllDelegates(paginationParamsFromOptions(o));
16
+ return delegates.items.length ? delegates : { message: 'No delegates found' };
17
+ }
14
18
  export async function getGatewayDelegates(o) {
15
19
  const address = requiredAddressFromOptions(o);
16
20
  const result = await readARIOFromOptions(o).getGatewayDelegates({
@@ -19,12 +19,8 @@ import { createAoSigner } from '../utils/ao.js';
19
19
  import { AOProcess, InvalidContractConfigurationError } from './index.js';
20
20
  export class ANTRegistry {
21
21
  static init(config) {
22
- if (config && config.signer) {
23
- const { signer, ...rest } = config;
24
- return new AoANTRegistryWriteable({
25
- ...rest,
26
- signer,
27
- });
22
+ if (config !== undefined && 'signer' in config) {
23
+ return new AoANTRegistryWriteable(config);
28
24
  }
29
25
  return new AoANTRegistryReadable(config);
30
26
  }
@@ -32,25 +28,22 @@ export class ANTRegistry {
32
28
  export class AoANTRegistryReadable {
33
29
  process;
34
30
  constructor(config) {
35
- if (config &&
36
- (isProcessIdConfiguration(config) || isProcessConfiguration(config))) {
37
- if (isProcessConfiguration(config)) {
38
- this.process = config.process;
39
- }
40
- else if (isProcessIdConfiguration(config)) {
41
- this.process = new AOProcess({
42
- processId: config.processId,
43
- });
44
- }
45
- else {
46
- throw new InvalidContractConfigurationError();
47
- }
48
- }
49
- else {
31
+ if (config === undefined || Object.keys(config).length === 0) {
50
32
  this.process = new AOProcess({
51
33
  processId: ANT_REGISTRY_ID,
52
34
  });
53
35
  }
36
+ else if (isProcessConfiguration(config)) {
37
+ this.process = config.process;
38
+ }
39
+ else if (isProcessIdConfiguration(config)) {
40
+ this.process = new AOProcess({
41
+ processId: config.processId,
42
+ });
43
+ }
44
+ else {
45
+ throw new InvalidContractConfigurationError();
46
+ }
54
47
  }
55
48
  // Should we rename this to "getANTsByAddress"? seems more clear, though not same as handler name
56
49
  async accessControlList({ address, }) {
@@ -20,15 +20,12 @@ import { createAoSigner } from '../utils/ao.js';
20
20
  import { parseSchemaResult } from '../utils/schema.js';
21
21
  import { AOProcess, InvalidContractConfigurationError } from './index.js';
22
22
  export class ANT {
23
- static init({ signer, strict = false, ...config }) {
24
- // ao supported implementation
25
- if (isProcessConfiguration(config) || isProcessIdConfiguration(config)) {
26
- if (!signer) {
27
- return new AoANTReadable({ strict, ...config });
28
- }
29
- return new AoANTWriteable({ signer, strict, ...config });
23
+ // implementation
24
+ static init(config) {
25
+ if (config !== undefined && 'signer' in config) {
26
+ return new AoANTWriteable(config);
30
27
  }
31
- throw new InvalidContractConfigurationError();
28
+ return new AoANTReadable(config);
32
29
  }
33
30
  }
34
31
  export class AoANTReadable {
@@ -39,8 +39,9 @@ export class AOProcess {
39
39
  let lastError;
40
40
  while (attempts < retries) {
41
41
  try {
42
- this.logger.debug(`Evaluating read interaction on contract`, {
42
+ this.logger.debug(`Evaluating read interaction on process`, {
43
43
  tags,
44
+ processId: this.processId,
44
45
  });
45
46
  // map tags to inputs
46
47
  const dryRunInput = {
@@ -53,13 +54,18 @@ export class AOProcess {
53
54
  const result = await this.ao.dryrun(dryRunInput);
54
55
  this.logger.debug(`Read interaction result`, {
55
56
  result,
57
+ processId: this.processId,
56
58
  });
57
59
  const error = errorMessageFromOutput(result);
58
60
  if (error !== undefined) {
59
61
  throw new Error(error);
60
62
  }
61
63
  if (result.Messages === undefined || result.Messages.length === 0) {
62
- this.logger.debug(`Process ${this.processId} does not support provided action.`, result, tags);
64
+ this.logger.debug(`Process ${this.processId} does not support provided action.`, {
65
+ result,
66
+ tags,
67
+ processId: this.processId,
68
+ });
63
69
  throw new Error(`Process ${this.processId} does not support provided action.`);
64
70
  }
65
71
  const messageData = result.Messages?.[0]?.Data;
@@ -67,16 +73,18 @@ export class AOProcess {
67
73
  if (this.isMessageDataEmpty(messageData)) {
68
74
  return undefined;
69
75
  }
70
- const response = safeDecode(result.Messages[0].Data);
76
+ const response = safeDecode(messageData);
71
77
  return response;
72
78
  }
73
- catch (e) {
79
+ catch (error) {
74
80
  attempts++;
75
81
  this.logger.debug(`Read attempt ${attempts} failed`, {
76
- error: e instanceof Error ? e.message : e,
82
+ error: error?.message,
83
+ stack: error?.stack,
77
84
  tags,
85
+ processId: this.processId,
78
86
  });
79
- lastError = e;
87
+ lastError = error;
80
88
  // exponential backoff
81
89
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 1000));
82
90
  }
@@ -144,16 +152,17 @@ export class AOProcess {
144
152
  }
145
153
  catch (error) {
146
154
  this.logger.error('Error sending message to process', {
147
- error: error.message,
155
+ error: error?.message,
156
+ stack: error?.stack,
148
157
  processId: this.processId,
149
158
  tags,
150
159
  });
151
- // throw on write interaction errors. No point retrying wr ite interactions, waste of gas.
160
+ // throw on write interaction errors. No point retrying write interactions, waste of gas.
152
161
  if (error.message.includes('500')) {
153
162
  this.logger.debug('Retrying send interaction', {
154
163
  attempts,
155
164
  retries,
156
- error: error.message,
165
+ error: error?.message,
157
166
  processId: this.processId,
158
167
  });
159
168
  // exponential backoff
@@ -170,18 +179,16 @@ export class AOProcess {
170
179
  }
171
180
  function errorMessageFromOutput(output) {
172
181
  const errorData = output.Error;
173
- if (errorData !== undefined) {
174
- // TODO: Could clean this one up too, current error is verbose, but not always deterministic for parsing
175
- // Throw the whole raw error if AO process level error
176
- return errorData;
177
- }
178
- const error = output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
182
+ // Attempt to extract error details from Messages.Tags if Error is undefined
183
+ const error = errorData ??
184
+ output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
179
185
  if (error !== undefined) {
180
- // from [string "aos"]:6846: Name is already registered
181
- const lineNumber = error.match(/\d+/)?.[0];
182
- const message = error.replace(/\[string "aos"\]:\d+:/, '');
183
- // to more user friendly: Name is already registered (line 6846)
184
- return `${message} (line ${lineNumber})`.trim();
186
+ // Consolidated regex to match and extract line number and AO error message or Error Tags
187
+ const match = error.match(/\[string "aos"]:(\d+):\s*(.+)/);
188
+ if (match) {
189
+ const [, lineNumber, errorMessage] = match;
190
+ return `${errorMessage.trim()} (line ${lineNumber.trim()})`.trim();
191
+ }
185
192
  }
186
193
  return undefined;
187
194
  }