@ar.io/sdk 3.8.0 → 3.8.2-alpha.1

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.
@@ -75,7 +75,7 @@ function makeCommand({ description, name, options = [], action, }) {
75
75
  return appliedCommand;
76
76
  }
77
77
  exports.makeCommand = makeCommand;
78
- function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, mainnet, }) {
78
+ function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
79
79
  if (arioProcessId !== undefined) {
80
80
  return arioProcessId;
81
81
  }
@@ -85,10 +85,7 @@ function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, mainnet, })
85
85
  if (testnet) {
86
86
  return index_js_1.ARIO_TESTNET_PROCESS_ID;
87
87
  }
88
- if (mainnet) {
89
- return index_js_1.ARIO_MAINNET_PROCESS_ID;
90
- }
91
- return index_js_1.ARIO_TESTNET_PROCESS_ID; // TODO(4.0): move to mainnet
88
+ return index_js_1.ARIO_MAINNET_PROCESS_ID;
92
89
  }
93
90
  exports.arioProcessIdFromOptions = arioProcessIdFromOptions;
94
91
  function jwkFromOptions({ privateKey, walletFile, }) {
@@ -490,7 +490,7 @@ class AoANTWriteable extends AoANTReadable {
490
490
  * @returns {Promise<AoMessageResult>} The result of the interaction.
491
491
  * @example
492
492
  * ```ts
493
- * ant.releaseName({ name: "ardrive", arioProcessId: AR_TESTNET_PROCESS_ID });
493
+ * ant.releaseName({ name: "ardrive", arioProcessId: ARIO_MAINNET_PROCESS_ID });
494
494
  * ```
495
495
  */
496
496
  async releaseName({ name, arioProcessId }, options) {
@@ -514,7 +514,7 @@ class AoANTWriteable extends AoANTReadable {
514
514
  * @returns {Promise<AoMessageResult>} The result of the interaction.
515
515
  * @example
516
516
  * ```ts
517
- * ant.reassignName({ name: "ardrive", arioProcessId: ARIO_TESTNET_PROCESS_ID, antProcessId: NEW_ANT_PROCESS_ID });
517
+ * ant.reassignName({ name: "ardrive", arioProcessId: ARIO_MAINNET_PROCESS_ID, antProcessId: NEW_ANT_PROCESS_ID });
518
518
  * ```
519
519
  */
520
520
  async reassignName({ name, arioProcessId, antProcessId, }, options) {
@@ -539,7 +539,7 @@ class AoANTWriteable extends AoANTReadable {
539
539
  * @returns {Promise<AoMessageResult>} The result of the interaction.
540
540
  * @example
541
541
  * ```ts
542
- * ant.approvePrimaryNameRequest({ name: "ardrive", address: "U7RXcpaVShG4u9nIcPVmm2FJSM5Gru9gQCIiRaIPV7f", arioProcessId: ARIO_TESTNET_PROCESS_ID }); // approves the request for ardrive.ar.io to be registered by the address
542
+ * ant.approvePrimaryNameRequest({ name: "ardrive", address: "U7RXcpaVShG4u9nIcPVmm2FJSM5Gru9gQCIiRaIPV7f", arioProcessId: ARIO_MAINNET_PROCESS_ID }); // approves the request for ardrive.ar.io to be registered by the address
543
543
  * ```
544
544
  */
545
545
  async approvePrimaryNameRequest({ name, address, arioProcessId, }, options) {
@@ -564,7 +564,7 @@ class AoANTWriteable extends AoANTReadable {
564
564
  * @returns {Promise<AoMessageResult>} The result of the interaction.
565
565
  * @example
566
566
  * ```ts
567
- * ant.removePrimaryNames({ names: ["ardrive", "dapp_ardrive"], arioProcessId: ARIO_TESTNET_PROCESS_ID, notifyOwners: true }); // removes the primary names and associated wallet addresses assigned to "ardrive" and "dapp_ardrive"
567
+ * ant.removePrimaryNames({ names: ["ardrive", "dapp_ardrive"], arioProcessId: ARIO_MAINNET_PROCESS_ID, notifyOwners: true }); // removes the primary names and associated wallet addresses assigned to "ardrive" and "dapp_ardrive"
568
568
  * ```
569
569
  */
570
570
  async removePrimaryNames({ names, arioProcessId, notifyOwners = false, }, options) {
@@ -39,46 +39,25 @@ class AOProcess {
39
39
  messageData === null);
40
40
  }
41
41
  async read({ tags, retries = 3, fromAddress, }) {
42
+ this.logger.debug(`Evaluating read interaction on process`, {
43
+ tags,
44
+ processId: this.processId,
45
+ });
46
+ // map tags to inputs
47
+ const dryRunInput = {
48
+ process: this.processId,
49
+ tags,
50
+ };
51
+ if (fromAddress !== undefined) {
52
+ dryRunInput['Owner'] = fromAddress;
53
+ }
42
54
  let attempts = 0;
43
- let lastError;
55
+ let result = undefined;
44
56
  while (attempts < retries) {
45
57
  try {
46
- this.logger.debug(`Evaluating read interaction on process`, {
47
- tags,
48
- processId: this.processId,
49
- });
50
- // map tags to inputs
51
- const dryRunInput = {
52
- process: this.processId,
53
- tags,
54
- };
55
- if (fromAddress !== undefined) {
56
- dryRunInput['Owner'] = fromAddress;
57
- }
58
- const result = await this.ao.dryrun(dryRunInput);
59
- this.logger.debug(`Read interaction result`, {
60
- result,
61
- processId: this.processId,
62
- });
63
- const error = (0, index_js_1.errorMessageFromOutput)(result);
64
- if (error !== undefined) {
65
- throw new Error(error);
66
- }
67
- if (result.Messages === undefined || result.Messages.length === 0) {
68
- this.logger.debug(`Process ${this.processId} does not support provided action.`, {
69
- result,
70
- tags,
71
- processId: this.processId,
72
- });
73
- throw new Error(`Process ${this.processId} does not support provided action.`);
74
- }
75
- const messageData = result.Messages?.[0]?.Data;
76
- // return undefined if no data is returned
77
- if (this.isMessageDataEmpty(messageData)) {
78
- return undefined;
79
- }
80
- const response = (0, json_js_1.safeDecode)(messageData);
81
- return response;
58
+ result = await this.ao.dryrun(dryRunInput);
59
+ // break on successful return of result
60
+ break;
82
61
  }
83
62
  catch (error) {
84
63
  attempts++;
@@ -88,17 +67,45 @@ class AOProcess {
88
67
  tags,
89
68
  processId: this.processId,
90
69
  });
91
- lastError = error;
70
+ if (attempts >= retries) {
71
+ throw error;
72
+ }
92
73
  // exponential backoff
93
74
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 1000));
94
75
  }
95
76
  }
96
- throw lastError;
77
+ if (result === undefined) {
78
+ throw new Error('Unexpected error when evaluating read interaction');
79
+ }
80
+ this.logger.debug(`Read interaction result`, {
81
+ result,
82
+ processId: this.processId,
83
+ });
84
+ const error = (0, index_js_1.errorMessageFromOutput)(result);
85
+ if (error !== undefined) {
86
+ throw new Error(error);
87
+ }
88
+ if (result.Messages === undefined || result.Messages.length === 0) {
89
+ this.logger.debug(`Process ${this.processId} does not support provided action.`, {
90
+ result,
91
+ tags,
92
+ processId: this.processId,
93
+ });
94
+ throw new Error(`Process ${this.processId} does not support provided action.`);
95
+ }
96
+ const messageData = result.Messages?.[0]?.Data;
97
+ // return undefined if no data is returned
98
+ if (this.isMessageDataEmpty(messageData)) {
99
+ return undefined;
100
+ }
101
+ const response = (0, json_js_1.safeDecode)(messageData);
102
+ return response;
97
103
  }
98
104
  async send({ tags, data, signer, retries = 3, }) {
99
105
  // main purpose of retries is to handle network errors/new process delays
100
106
  let attempts = 0;
101
- let lastError;
107
+ let messageId;
108
+ let result = undefined;
102
109
  while (attempts < retries) {
103
110
  try {
104
111
  this.logger.debug(`Evaluating send interaction on contract`, {
@@ -109,7 +116,7 @@ class AOProcess {
109
116
  // TODO: do a read as a dry run to check if the process supports the action
110
117
  // anchor is a random text produce non-deterministic messages IDs when deterministic signers are provided (ETH)
111
118
  const anchor = (0, base64_js_1.getRandomText)(32);
112
- const messageId = await this.ao.message({
119
+ messageId = await this.ao.message({
113
120
  process: this.processId,
114
121
  // TODO: any other default tags we want to add?
115
122
  tags: [...tags, { name: 'AR-IO-SDK', value: version_js_1.version }],
@@ -123,36 +130,16 @@ class AOProcess {
123
130
  anchor,
124
131
  });
125
132
  // check the result of the send interaction
126
- const output = await this.ao.result({
133
+ result = await this.ao.result({
127
134
  message: messageId,
128
135
  process: this.processId,
129
136
  });
130
137
  this.logger.debug('Message result', {
131
- output,
132
- messageId,
133
- processId: this.processId,
134
- });
135
- const error = (0, index_js_1.errorMessageFromOutput)(output);
136
- if (error !== undefined) {
137
- throw new error_js_1.WriteInteractionError(error);
138
- }
139
- // check if there are any Messages in the output
140
- if (output.Messages?.length === 0 || output.Messages === undefined) {
141
- return { id: messageId };
142
- }
143
- if (output.Messages.length === 0) {
144
- throw new Error(`Process ${this.processId} does not support provided action.`);
145
- }
146
- if (this.isMessageDataEmpty(output.Messages[0].Data)) {
147
- return { id: messageId };
148
- }
149
- const resultData = (0, json_js_1.safeDecode)(output.Messages[0].Data);
150
- this.logger.debug('Message result data', {
151
- resultData,
138
+ result,
152
139
  messageId,
153
140
  processId: this.processId,
154
141
  });
155
- return { id: messageId, result: resultData };
142
+ break;
156
143
  }
157
144
  catch (error) {
158
145
  this.logger.error('Error sending message to process', {
@@ -161,24 +148,44 @@ class AOProcess {
161
148
  processId: this.processId,
162
149
  tags,
163
150
  });
164
- // throw on write interaction errors. No point retrying write interactions, waste of gas.
165
- if (error.message.includes('500')) {
166
- this.logger.debug('Retrying send interaction', {
167
- attempts,
168
- retries,
169
- error: error?.message,
170
- processId: this.processId,
171
- });
172
- // exponential backoff
173
- await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 2000));
174
- attempts++;
175
- lastError = error;
176
- }
177
- else
151
+ attempts++;
152
+ this.logger.debug('Retrying send interaction', {
153
+ attempts,
154
+ retries,
155
+ error: error?.message,
156
+ processId: this.processId,
157
+ });
158
+ if (attempts >= retries) {
178
159
  throw error;
160
+ }
161
+ // exponential backoff
162
+ await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 2000));
179
163
  }
180
164
  }
181
- throw lastError;
165
+ if (result === undefined || messageId === undefined) {
166
+ throw new Error('Unexpected error when evaluating write interaction');
167
+ }
168
+ const error = (0, index_js_1.errorMessageFromOutput)(result);
169
+ if (error !== undefined) {
170
+ throw new error_js_1.WriteInteractionError(error);
171
+ }
172
+ // check if there are any Messages in the output
173
+ if (result.Messages?.length === 0 || result.Messages === undefined) {
174
+ return { id: messageId };
175
+ }
176
+ if (result.Messages.length === 0) {
177
+ throw new Error(`Process ${this.processId} does not support provided action.`);
178
+ }
179
+ if (this.isMessageDataEmpty(result.Messages[0].Data)) {
180
+ return { id: messageId };
181
+ }
182
+ const resultData = (0, json_js_1.safeDecode)(result.Messages[0].Data);
183
+ this.logger.debug('Message result data', {
184
+ resultData,
185
+ messageId,
186
+ processId: this.processId,
187
+ });
188
+ return { id: messageId, result: resultData };
182
189
  }
183
190
  }
184
191
  exports.AOProcess = AOProcess;
@@ -26,7 +26,7 @@ class ARIOReadable {
26
26
  this.arweave = config?.arweave ?? arweave_js_2.defaultArweave;
27
27
  if (config === undefined || Object.keys(config).length === 0) {
28
28
  this.process = new ao_process_js_1.AOProcess({
29
- processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
29
+ processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
30
30
  });
31
31
  }
32
32
  else if ((0, io_js_1.isProcessConfiguration)(config)) {
@@ -522,7 +522,7 @@ class ARIOWriteable extends ARIOReadable {
522
522
  if (config === undefined) {
523
523
  super({
524
524
  process: new ao_process_js_1.AOProcess({
525
- processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
525
+ processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
526
526
  }),
527
527
  });
528
528
  }
@@ -36,7 +36,7 @@ exports.paginationParamsToTags = paginationParamsToTags;
36
36
  * @param arweave - The Arweave instance
37
37
  * @returns The epoch with distribution data
38
38
  */
39
- const getEpochDataFromGql = async ({ arweave, epochIndex, processId = constants_js_1.ARIO_TESTNET_PROCESS_ID, retries = 3, gqlUrl = 'https://arweave-search.goldsky.com/graphql', }) => {
39
+ const getEpochDataFromGql = async ({ arweave, epochIndex, processId = constants_js_1.ARIO_MAINNET_PROCESS_ID, retries = 3, gqlUrl = 'https://arweave-search.goldsky.com/graphql', }) => {
40
40
  // fetch from gql
41
41
  const query = (0, exports.epochDistributionNoticeGqlQuery)({ epochIndex, processId });
42
42
  // add three retries with exponential backoff
@@ -73,10 +73,10 @@ exports.getEpochDataFromGql = getEpochDataFromGql;
73
73
  * Get the epoch with distribution data for the current epoch
74
74
  * @param arweave - The Arweave instance
75
75
  * @param epochIndex - The index of the epoch
76
- * @param processId - The process ID (optional, defaults to ARIO_TESTNET_PROCESS_ID)
76
+ * @param processId - The process ID (optional, defaults to ARIO_MAINNET_PROCESS_ID)
77
77
  * @returns string - The stringified GQL query
78
78
  */
79
- const epochDistributionNoticeGqlQuery = ({ epochIndex, processId = constants_js_1.ARIO_TESTNET_PROCESS_ID, authorities = ['fcoN_xJeisVsPXA-trzVAuIiqO3ydLQxM-L4XbrQKzY'], }) => {
79
+ const epochDistributionNoticeGqlQuery = ({ epochIndex, processId = constants_js_1.ARIO_MAINNET_PROCESS_ID, authorities = ['fcoN_xJeisVsPXA-trzVAuIiqO3ydLQxM-L4XbrQKzY'], }) => {
80
80
  // write the query
81
81
  const gqlQuery = JSON.stringify({
82
82
  query: `
@@ -57,7 +57,7 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
57
57
  strict;
58
58
  antAoClient;
59
59
  constructor({ contract = io_js_1.ARIO.init({
60
- processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
60
+ processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
61
61
  }), timeoutMs = 60_000, concurrency = 30, logger = logger_js_1.Logger.default, strict = false, antAoClient = (0, aoconnect_1.connect)(), } = {}) {
62
62
  super();
63
63
  this.contract = contract;
@@ -125,7 +125,7 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
125
125
  }
126
126
  exports.ArNSEventEmitter = ArNSEventEmitter;
127
127
  const fetchAllArNSRecords = async ({ contract = io_js_1.ARIO.init({
128
- processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
128
+ processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
129
129
  }), emitter, logger = logger_js_1.Logger.default, pageSize = 1000, }) => {
130
130
  let cursor;
131
131
  const startTimestamp = Date.now();
@@ -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.8.0';
20
+ exports.version = '3.8.2-alpha.1';
@@ -65,7 +65,7 @@ export function makeCommand({ description, name, options = [], action, }) {
65
65
  }
66
66
  return appliedCommand;
67
67
  }
68
- export function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, mainnet, }) {
68
+ export function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
69
69
  if (arioProcessId !== undefined) {
70
70
  return arioProcessId;
71
71
  }
@@ -75,10 +75,7 @@ export function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, mainn
75
75
  if (testnet) {
76
76
  return ARIO_TESTNET_PROCESS_ID;
77
77
  }
78
- if (mainnet) {
79
- return ARIO_MAINNET_PROCESS_ID;
80
- }
81
- return ARIO_TESTNET_PROCESS_ID; // TODO(4.0): move to mainnet
78
+ return ARIO_MAINNET_PROCESS_ID;
82
79
  }
83
80
  function jwkFromOptions({ privateKey, walletFile, }) {
84
81
  if (privateKey !== undefined) {
@@ -485,7 +485,7 @@ export class AoANTWriteable extends AoANTReadable {
485
485
  * @returns {Promise<AoMessageResult>} The result of the interaction.
486
486
  * @example
487
487
  * ```ts
488
- * ant.releaseName({ name: "ardrive", arioProcessId: AR_TESTNET_PROCESS_ID });
488
+ * ant.releaseName({ name: "ardrive", arioProcessId: ARIO_MAINNET_PROCESS_ID });
489
489
  * ```
490
490
  */
491
491
  async releaseName({ name, arioProcessId }, options) {
@@ -509,7 +509,7 @@ export class AoANTWriteable extends AoANTReadable {
509
509
  * @returns {Promise<AoMessageResult>} The result of the interaction.
510
510
  * @example
511
511
  * ```ts
512
- * ant.reassignName({ name: "ardrive", arioProcessId: ARIO_TESTNET_PROCESS_ID, antProcessId: NEW_ANT_PROCESS_ID });
512
+ * ant.reassignName({ name: "ardrive", arioProcessId: ARIO_MAINNET_PROCESS_ID, antProcessId: NEW_ANT_PROCESS_ID });
513
513
  * ```
514
514
  */
515
515
  async reassignName({ name, arioProcessId, antProcessId, }, options) {
@@ -534,7 +534,7 @@ export class AoANTWriteable extends AoANTReadable {
534
534
  * @returns {Promise<AoMessageResult>} The result of the interaction.
535
535
  * @example
536
536
  * ```ts
537
- * ant.approvePrimaryNameRequest({ name: "ardrive", address: "U7RXcpaVShG4u9nIcPVmm2FJSM5Gru9gQCIiRaIPV7f", arioProcessId: ARIO_TESTNET_PROCESS_ID }); // approves the request for ardrive.ar.io to be registered by the address
537
+ * ant.approvePrimaryNameRequest({ name: "ardrive", address: "U7RXcpaVShG4u9nIcPVmm2FJSM5Gru9gQCIiRaIPV7f", arioProcessId: ARIO_MAINNET_PROCESS_ID }); // approves the request for ardrive.ar.io to be registered by the address
538
538
  * ```
539
539
  */
540
540
  async approvePrimaryNameRequest({ name, address, arioProcessId, }, options) {
@@ -559,7 +559,7 @@ export class AoANTWriteable extends AoANTReadable {
559
559
  * @returns {Promise<AoMessageResult>} The result of the interaction.
560
560
  * @example
561
561
  * ```ts
562
- * ant.removePrimaryNames({ names: ["ardrive", "dapp_ardrive"], arioProcessId: ARIO_TESTNET_PROCESS_ID, notifyOwners: true }); // removes the primary names and associated wallet addresses assigned to "ardrive" and "dapp_ardrive"
562
+ * ant.removePrimaryNames({ names: ["ardrive", "dapp_ardrive"], arioProcessId: ARIO_MAINNET_PROCESS_ID, notifyOwners: true }); // removes the primary names and associated wallet addresses assigned to "ardrive" and "dapp_ardrive"
563
563
  * ```
564
564
  */
565
565
  async removePrimaryNames({ names, arioProcessId, notifyOwners = false, }, options) {
@@ -36,46 +36,25 @@ export class AOProcess {
36
36
  messageData === null);
37
37
  }
38
38
  async read({ tags, retries = 3, fromAddress, }) {
39
+ this.logger.debug(`Evaluating read interaction on process`, {
40
+ tags,
41
+ processId: this.processId,
42
+ });
43
+ // map tags to inputs
44
+ const dryRunInput = {
45
+ process: this.processId,
46
+ tags,
47
+ };
48
+ if (fromAddress !== undefined) {
49
+ dryRunInput['Owner'] = fromAddress;
50
+ }
39
51
  let attempts = 0;
40
- let lastError;
52
+ let result = undefined;
41
53
  while (attempts < retries) {
42
54
  try {
43
- this.logger.debug(`Evaluating read interaction on process`, {
44
- tags,
45
- processId: this.processId,
46
- });
47
- // map tags to inputs
48
- const dryRunInput = {
49
- process: this.processId,
50
- tags,
51
- };
52
- if (fromAddress !== undefined) {
53
- dryRunInput['Owner'] = fromAddress;
54
- }
55
- const result = await this.ao.dryrun(dryRunInput);
56
- this.logger.debug(`Read interaction result`, {
57
- result,
58
- processId: this.processId,
59
- });
60
- const error = errorMessageFromOutput(result);
61
- if (error !== undefined) {
62
- throw new Error(error);
63
- }
64
- if (result.Messages === undefined || result.Messages.length === 0) {
65
- this.logger.debug(`Process ${this.processId} does not support provided action.`, {
66
- result,
67
- tags,
68
- processId: this.processId,
69
- });
70
- throw new Error(`Process ${this.processId} does not support provided action.`);
71
- }
72
- const messageData = result.Messages?.[0]?.Data;
73
- // return undefined if no data is returned
74
- if (this.isMessageDataEmpty(messageData)) {
75
- return undefined;
76
- }
77
- const response = safeDecode(messageData);
78
- return response;
55
+ result = await this.ao.dryrun(dryRunInput);
56
+ // break on successful return of result
57
+ break;
79
58
  }
80
59
  catch (error) {
81
60
  attempts++;
@@ -85,17 +64,45 @@ export class AOProcess {
85
64
  tags,
86
65
  processId: this.processId,
87
66
  });
88
- lastError = error;
67
+ if (attempts >= retries) {
68
+ throw error;
69
+ }
89
70
  // exponential backoff
90
71
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 1000));
91
72
  }
92
73
  }
93
- throw lastError;
74
+ if (result === undefined) {
75
+ throw new Error('Unexpected error when evaluating read interaction');
76
+ }
77
+ this.logger.debug(`Read interaction result`, {
78
+ result,
79
+ processId: this.processId,
80
+ });
81
+ const error = errorMessageFromOutput(result);
82
+ if (error !== undefined) {
83
+ throw new Error(error);
84
+ }
85
+ if (result.Messages === undefined || result.Messages.length === 0) {
86
+ this.logger.debug(`Process ${this.processId} does not support provided action.`, {
87
+ result,
88
+ tags,
89
+ processId: this.processId,
90
+ });
91
+ throw new Error(`Process ${this.processId} does not support provided action.`);
92
+ }
93
+ const messageData = result.Messages?.[0]?.Data;
94
+ // return undefined if no data is returned
95
+ if (this.isMessageDataEmpty(messageData)) {
96
+ return undefined;
97
+ }
98
+ const response = safeDecode(messageData);
99
+ return response;
94
100
  }
95
101
  async send({ tags, data, signer, retries = 3, }) {
96
102
  // main purpose of retries is to handle network errors/new process delays
97
103
  let attempts = 0;
98
- let lastError;
104
+ let messageId;
105
+ let result = undefined;
99
106
  while (attempts < retries) {
100
107
  try {
101
108
  this.logger.debug(`Evaluating send interaction on contract`, {
@@ -106,7 +113,7 @@ export class AOProcess {
106
113
  // TODO: do a read as a dry run to check if the process supports the action
107
114
  // anchor is a random text produce non-deterministic messages IDs when deterministic signers are provided (ETH)
108
115
  const anchor = getRandomText(32);
109
- const messageId = await this.ao.message({
116
+ messageId = await this.ao.message({
110
117
  process: this.processId,
111
118
  // TODO: any other default tags we want to add?
112
119
  tags: [...tags, { name: 'AR-IO-SDK', value: version }],
@@ -120,36 +127,16 @@ export class AOProcess {
120
127
  anchor,
121
128
  });
122
129
  // check the result of the send interaction
123
- const output = await this.ao.result({
130
+ result = await this.ao.result({
124
131
  message: messageId,
125
132
  process: this.processId,
126
133
  });
127
134
  this.logger.debug('Message result', {
128
- output,
129
- messageId,
130
- processId: this.processId,
131
- });
132
- const error = errorMessageFromOutput(output);
133
- if (error !== undefined) {
134
- throw new WriteInteractionError(error);
135
- }
136
- // check if there are any Messages in the output
137
- if (output.Messages?.length === 0 || output.Messages === undefined) {
138
- return { id: messageId };
139
- }
140
- if (output.Messages.length === 0) {
141
- throw new Error(`Process ${this.processId} does not support provided action.`);
142
- }
143
- if (this.isMessageDataEmpty(output.Messages[0].Data)) {
144
- return { id: messageId };
145
- }
146
- const resultData = safeDecode(output.Messages[0].Data);
147
- this.logger.debug('Message result data', {
148
- resultData,
135
+ result,
149
136
  messageId,
150
137
  processId: this.processId,
151
138
  });
152
- return { id: messageId, result: resultData };
139
+ break;
153
140
  }
154
141
  catch (error) {
155
142
  this.logger.error('Error sending message to process', {
@@ -158,23 +145,43 @@ export class AOProcess {
158
145
  processId: this.processId,
159
146
  tags,
160
147
  });
161
- // throw on write interaction errors. No point retrying write interactions, waste of gas.
162
- if (error.message.includes('500')) {
163
- this.logger.debug('Retrying send interaction', {
164
- attempts,
165
- retries,
166
- error: error?.message,
167
- processId: this.processId,
168
- });
169
- // exponential backoff
170
- await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 2000));
171
- attempts++;
172
- lastError = error;
173
- }
174
- else
148
+ attempts++;
149
+ this.logger.debug('Retrying send interaction', {
150
+ attempts,
151
+ retries,
152
+ error: error?.message,
153
+ processId: this.processId,
154
+ });
155
+ if (attempts >= retries) {
175
156
  throw error;
157
+ }
158
+ // exponential backoff
159
+ await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 2000));
176
160
  }
177
161
  }
178
- throw lastError;
162
+ if (result === undefined || messageId === undefined) {
163
+ throw new Error('Unexpected error when evaluating write interaction');
164
+ }
165
+ const error = errorMessageFromOutput(result);
166
+ if (error !== undefined) {
167
+ throw new WriteInteractionError(error);
168
+ }
169
+ // check if there are any Messages in the output
170
+ if (result.Messages?.length === 0 || result.Messages === undefined) {
171
+ return { id: messageId };
172
+ }
173
+ if (result.Messages.length === 0) {
174
+ throw new Error(`Process ${this.processId} does not support provided action.`);
175
+ }
176
+ if (this.isMessageDataEmpty(result.Messages[0].Data)) {
177
+ return { id: messageId };
178
+ }
179
+ const resultData = safeDecode(result.Messages[0].Data);
180
+ this.logger.debug('Message result data', {
181
+ resultData,
182
+ messageId,
183
+ processId: this.processId,
184
+ });
185
+ return { id: messageId, result: resultData };
179
186
  }
180
187
  }
@@ -1,4 +1,4 @@
1
- import { ARIO_TESTNET_PROCESS_ID } from '../constants.js';
1
+ import { ARIO_MAINNET_PROCESS_ID } from '../constants.js';
2
2
  import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/io.js';
3
3
  import { createAoSigner } from '../utils/ao.js';
4
4
  import { getEpochDataFromGql, paginationParamsToTags, pruneTags, removeEligibleRewardsFromEpochData, sortAndPaginateEpochDataIntoEligibleDistributions, } from '../utils/arweave.js';
@@ -22,7 +22,7 @@ export class ARIOReadable {
22
22
  this.arweave = config?.arweave ?? defaultArweave;
23
23
  if (config === undefined || Object.keys(config).length === 0) {
24
24
  this.process = new AOProcess({
25
- processId: ARIO_TESTNET_PROCESS_ID,
25
+ processId: ARIO_MAINNET_PROCESS_ID,
26
26
  });
27
27
  }
28
28
  else if (isProcessConfiguration(config)) {
@@ -517,7 +517,7 @@ export class ARIOWriteable extends ARIOReadable {
517
517
  if (config === undefined) {
518
518
  super({
519
519
  process: new AOProcess({
520
- processId: ARIO_TESTNET_PROCESS_ID,
520
+ processId: ARIO_MAINNET_PROCESS_ID,
521
521
  }),
522
522
  });
523
523
  }