@ar.io/sdk 3.19.0-alpha.1 → 3.19.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.
- package/README.md +52 -0
- package/bundles/web.bundle.min.js +88 -72
- package/lib/cjs/cli/cli.js +6 -0
- package/lib/cjs/cli/commands/antCommands.js +50 -0
- package/lib/cjs/cli/options.js +12 -1
- package/lib/cjs/cli/utils.js +11 -11
- package/lib/cjs/common/ant.js +383 -1
- package/lib/cjs/common/io.js +2 -2
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/utils/ant.js +4 -0
- package/lib/cjs/utils/ao.js +3 -1
- package/lib/cjs/utils/processes.js +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +8 -2
- package/lib/esm/cli/commands/antCommands.js +50 -1
- package/lib/esm/cli/options.js +11 -0
- package/lib/esm/cli/utils.js +11 -11
- package/lib/esm/common/ant.js +384 -2
- package/lib/esm/common/io.js +2 -2
- package/lib/esm/constants.js +1 -0
- package/lib/esm/utils/ant.js +4 -0
- package/lib/esm/utils/ao.js +3 -1
- package/lib/esm/utils/processes.js +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/antCommands.d.ts +8 -0
- package/lib/types/cli/options.d.ts +9 -0
- package/lib/types/cli/utils.d.ts +2 -2
- package/lib/types/common/ant.d.ts +134 -3
- package/lib/types/common/io.d.ts +1 -1
- package/lib/types/constants.d.ts +1 -0
- package/lib/types/types/ant.d.ts +34 -1
- package/lib/types/types/common.d.ts +31 -0
- package/lib/types/utils/ant.d.ts +4 -0
- package/lib/types/utils/ao.d.ts +2 -1
- package/lib/types/utils/processes.d.ts +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/cli/cli.js
CHANGED
|
@@ -634,6 +634,12 @@ const utils_js_1 = require("./utils.js");
|
|
|
634
634
|
options: options_js_1.setAntUndernameOptions,
|
|
635
635
|
action: antCommands_js_1.setAntRecordCLICommand,
|
|
636
636
|
});
|
|
637
|
+
(0, utils_js_1.makeCommand)({
|
|
638
|
+
name: 'upgrade-ant',
|
|
639
|
+
description: 'Upgrade an ANT by forking it to the latest version and reassigning names',
|
|
640
|
+
options: options_js_1.upgradeAntOptions,
|
|
641
|
+
action: antCommands_js_1.upgradeAntCLICommand,
|
|
642
|
+
});
|
|
637
643
|
(0, utils_js_1.makeCommand)({
|
|
638
644
|
name: 'set-ant-ticker',
|
|
639
645
|
description: 'Set the ticker of an ANT process',
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setAntRecordCLICommand = setAntRecordCLICommand;
|
|
4
4
|
exports.setAntBaseNameCLICommand = setAntBaseNameCLICommand;
|
|
5
5
|
exports.setAntUndernameCLICommand = setAntUndernameCLICommand;
|
|
6
|
+
exports.upgradeAntCLICommand = upgradeAntCLICommand;
|
|
6
7
|
const utils_js_1 = require("../utils.js");
|
|
7
8
|
/** @deprecated -- use set-ant-base-name and set-ant-undername */
|
|
8
9
|
async function setAntRecordCLICommand(o) {
|
|
@@ -45,3 +46,52 @@ async function setAntUndernameCLICommand(o) {
|
|
|
45
46
|
ttlSeconds,
|
|
46
47
|
}, (0, utils_js_1.customTagsFromOptions)(o));
|
|
47
48
|
}
|
|
49
|
+
async function upgradeAntCLICommand(o) {
|
|
50
|
+
const writeAnt = (0, utils_js_1.writeANTFromOptions)(o);
|
|
51
|
+
const arioProcessId = (0, utils_js_1.arioProcessIdFromOptions)(o);
|
|
52
|
+
const ario = (0, utils_js_1.readARIOFromOptions)(o);
|
|
53
|
+
const reassignAffiliatedNames = (0, utils_js_1.booleanFromOptions)(o, 'reassignAffiliatedNames');
|
|
54
|
+
const names = (0, utils_js_1.stringArrayFromOptions)(o, 'names') || [];
|
|
55
|
+
if (reassignAffiliatedNames) {
|
|
56
|
+
// Fetch all ArNS records that point to this ANT process
|
|
57
|
+
const allRecords = await ario.getArNSRecords({
|
|
58
|
+
filters: {
|
|
59
|
+
processId: writeAnt.processId,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
// Filter records that belong to this ANT
|
|
63
|
+
const affiliatedNames = allRecords.items.map((record) => record.name);
|
|
64
|
+
names.push(...affiliatedNames);
|
|
65
|
+
}
|
|
66
|
+
if (names.length === 0) {
|
|
67
|
+
throw new Error('No names to reassign');
|
|
68
|
+
}
|
|
69
|
+
if (!o.skipConfirmation) {
|
|
70
|
+
await (0, utils_js_1.assertConfirmationPrompt)(`Upgrade all names affiliated with this ANT on ARIO process?\n` +
|
|
71
|
+
`ARIO Process ID: ${arioProcessId}\n` +
|
|
72
|
+
`ANT Process ID: ${writeAnt.processId}\n` +
|
|
73
|
+
`Names that will be reassigned (${names.length}): ${names.join(', ')}`, o);
|
|
74
|
+
}
|
|
75
|
+
const result = reassignAffiliatedNames
|
|
76
|
+
? await (0, utils_js_1.writeANTFromOptions)(o).upgrade({
|
|
77
|
+
reassignAffiliatedNames,
|
|
78
|
+
arioProcessId,
|
|
79
|
+
})
|
|
80
|
+
: await (0, utils_js_1.writeANTFromOptions)(o).upgrade({
|
|
81
|
+
names,
|
|
82
|
+
arioProcessId,
|
|
83
|
+
});
|
|
84
|
+
// Serialize error objects for JSON compatibility
|
|
85
|
+
const serializedFailedReassignedNames = {};
|
|
86
|
+
for (const [name, failure] of Object.entries(result.failedReassignedNames)) {
|
|
87
|
+
serializedFailedReassignedNames[name] = {
|
|
88
|
+
id: failure.id,
|
|
89
|
+
error: failure.error.message,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
forkedProcessId: result.forkedProcessId,
|
|
94
|
+
reassignedNames: result.reassignedNames,
|
|
95
|
+
failedReassignedNames: serializedFailedReassignedNames,
|
|
96
|
+
};
|
|
97
|
+
}
|
package/lib/cjs/cli/options.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.setAntUndernameOptions = exports.setAntBaseNameOptions = exports.antStateOptions = exports.buyRecordOptions = exports.joinNetworkOptions = exports.updateGatewaySettingsOptions = exports.decreaseDelegateStakeOptions = exports.delegateStakeOptions = exports.redelegateStakeOptions = exports.operatorStakeOptions = exports.vaultedTransferOptions = exports.transferOptions = exports.tokenCostOptions = exports.getVaultOptions = exports.paginationAddressOptions = exports.paginationOptions = exports.nameWriteOptions = exports.addressAndVaultIdOptions = exports.epochOptions = exports.arnsPurchaseOptions = exports.writeActionOptions = exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
|
|
18
|
+
exports.upgradeAntOptions = exports.setAntUndernameOptions = exports.setAntBaseNameOptions = exports.antStateOptions = exports.buyRecordOptions = exports.joinNetworkOptions = exports.updateGatewaySettingsOptions = exports.decreaseDelegateStakeOptions = exports.delegateStakeOptions = exports.redelegateStakeOptions = exports.operatorStakeOptions = exports.vaultedTransferOptions = exports.transferOptions = exports.tokenCostOptions = exports.getVaultOptions = exports.paginationAddressOptions = exports.paginationOptions = exports.nameWriteOptions = exports.addressAndVaultIdOptions = exports.epochOptions = exports.arnsPurchaseOptions = exports.writeActionOptions = exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
|
|
19
19
|
exports.optionMap = {
|
|
20
20
|
walletFile: {
|
|
21
21
|
alias: '-w, --wallet-file <walletFilePath>',
|
|
@@ -303,6 +303,11 @@ exports.optionMap = {
|
|
|
303
303
|
alias: '--referrer <referrer>',
|
|
304
304
|
description: 'The referrer for ArNS purchase tracking',
|
|
305
305
|
},
|
|
306
|
+
reassignAffiliatedNames: {
|
|
307
|
+
alias: '--reassign-affiliated-names',
|
|
308
|
+
description: 'Reassign all affiliated names to the new process',
|
|
309
|
+
type: 'boolean',
|
|
310
|
+
},
|
|
306
311
|
};
|
|
307
312
|
exports.walletOptions = [
|
|
308
313
|
exports.optionMap.walletFile,
|
|
@@ -422,3 +427,9 @@ exports.setAntUndernameOptions = [
|
|
|
422
427
|
...exports.setAntBaseNameOptions,
|
|
423
428
|
exports.optionMap.undername,
|
|
424
429
|
];
|
|
430
|
+
exports.upgradeAntOptions = [
|
|
431
|
+
exports.optionMap.processId,
|
|
432
|
+
exports.optionMap.names,
|
|
433
|
+
exports.optionMap.reassignAffiliatedNames,
|
|
434
|
+
...exports.writeActionOptions,
|
|
435
|
+
];
|
package/lib/cjs/cli/utils.js
CHANGED
|
@@ -9,11 +9,11 @@ exports.runCommand = runCommand;
|
|
|
9
9
|
exports.applyOptions = applyOptions;
|
|
10
10
|
exports.makeCommand = makeCommand;
|
|
11
11
|
exports.arioProcessIdFromOptions = arioProcessIdFromOptions;
|
|
12
|
+
exports.antRegistryIdFromOptions = antRegistryIdFromOptions;
|
|
12
13
|
exports.requiredJwkFromOptions = requiredJwkFromOptions;
|
|
13
14
|
exports.jwkToAddress = jwkToAddress;
|
|
14
15
|
exports.getLoggerFromOptions = getLoggerFromOptions;
|
|
15
16
|
exports.readARIOFromOptions = readARIOFromOptions;
|
|
16
|
-
exports.ANTRegistryProcessFromOptions = ANTRegistryProcessFromOptions;
|
|
17
17
|
exports.readANTRegistryFromOptions = readANTRegistryFromOptions;
|
|
18
18
|
exports.contractSignerFromOptions = contractSignerFromOptions;
|
|
19
19
|
exports.requiredContractSignerFromOptions = requiredContractSignerFromOptions;
|
|
@@ -130,6 +130,15 @@ function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
|
|
|
130
130
|
}
|
|
131
131
|
return index_js_1.ARIO_MAINNET_PROCESS_ID;
|
|
132
132
|
}
|
|
133
|
+
function antRegistryIdFromOptions({ antRegistryProcessId, testnet, }) {
|
|
134
|
+
if (antRegistryProcessId !== undefined) {
|
|
135
|
+
return antRegistryProcessId;
|
|
136
|
+
}
|
|
137
|
+
if (testnet) {
|
|
138
|
+
return index_js_1.ANT_REGISTRY_TESTNET_ID;
|
|
139
|
+
}
|
|
140
|
+
return index_js_1.ANT_REGISTRY_ID;
|
|
141
|
+
}
|
|
133
142
|
function walletFromOptions({ privateKey, walletFile, }) {
|
|
134
143
|
if (privateKey !== undefined) {
|
|
135
144
|
return JSON.parse(privateKey);
|
|
@@ -177,18 +186,9 @@ function readARIOFromOptions(options) {
|
|
|
177
186
|
paymentUrl: options.paymentUrl,
|
|
178
187
|
});
|
|
179
188
|
}
|
|
180
|
-
function ANTRegistryProcessFromOptions(options) {
|
|
181
|
-
return new index_js_1.AOProcess({
|
|
182
|
-
processId: options.antRegistryProcessId ?? index_js_1.ANT_REGISTRY_ID,
|
|
183
|
-
ao: (0, aoconnect_1.connect)({
|
|
184
|
-
MODE: 'legacy',
|
|
185
|
-
CU_URL: options.cuUrl,
|
|
186
|
-
}),
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
189
|
function readANTRegistryFromOptions(options) {
|
|
190
190
|
return index_js_1.ANTRegistry.init({
|
|
191
|
-
process:
|
|
191
|
+
process: aoProcessFromOptions(options),
|
|
192
192
|
hyperbeamUrl: options.hyperbeamUrl,
|
|
193
193
|
});
|
|
194
194
|
}
|
package/lib/cjs/common/ant.js
CHANGED
|
@@ -17,6 +17,8 @@ exports.AoANTWriteable = exports.AoANTReadable = exports.ANT = void 0;
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
const zod_1 = require("zod");
|
|
20
|
+
const constants_js_1 = require("../constants.js");
|
|
21
|
+
const constants_js_2 = require("../constants.js");
|
|
20
22
|
const ant_js_1 = require("../types/ant.js");
|
|
21
23
|
const index_js_1 = require("../types/index.js");
|
|
22
24
|
const ant_js_2 = require("../utils/ant.js");
|
|
@@ -43,6 +45,149 @@ class ANT {
|
|
|
43
45
|
* @param config
|
|
44
46
|
*/
|
|
45
47
|
static fork = ao_js_1.forkANT;
|
|
48
|
+
/**
|
|
49
|
+
* Upgrade an ANT by forking it to the latest version and reassigning names.
|
|
50
|
+
*
|
|
51
|
+
*
|
|
52
|
+
* @param config Configuration object for the upgrade process
|
|
53
|
+
* @returns Promise resolving to the forked process ID and successfully reassigned names
|
|
54
|
+
*/
|
|
55
|
+
static async upgrade({ signer, antProcessId, reassignAffiliatedNames = true, names, arioProcessId = constants_js_1.ARIO_MAINNET_PROCESS_ID, antRegistryId = constants_js_2.ANT_REGISTRY_ID, ao, logger = index_js_2.Logger.default, skipVersionCheck = false, onSigningProgress, hyperbeamUrl, }) {
|
|
56
|
+
// run time check if names is not empty but reassignAffiliatedNames it true, throw
|
|
57
|
+
if (names !== undefined &&
|
|
58
|
+
names.length > 0 &&
|
|
59
|
+
reassignAffiliatedNames !== undefined &&
|
|
60
|
+
reassignAffiliatedNames !== false) {
|
|
61
|
+
throw new Error('Cannot reassign all affiliated names and provide specific names');
|
|
62
|
+
}
|
|
63
|
+
let namesToReassign = names !== undefined && names.length > 0 ? new Set(names) : new Set();
|
|
64
|
+
// use reassignAffiliatedNames if names is empty
|
|
65
|
+
const shouldReassignAll = names === undefined || names.length === 0
|
|
66
|
+
? (reassignAffiliatedNames ?? true)
|
|
67
|
+
: false;
|
|
68
|
+
const ario = index_js_2.ARIO.init({
|
|
69
|
+
process: new index_js_2.AOProcess({ processId: arioProcessId, ao }),
|
|
70
|
+
});
|
|
71
|
+
const getAllAffiliatedNames = async () => {
|
|
72
|
+
let cursor = undefined;
|
|
73
|
+
let hasMore = true;
|
|
74
|
+
const affiliatedNames = new Set();
|
|
75
|
+
while (hasMore) {
|
|
76
|
+
const page = await ario.getArNSRecords({
|
|
77
|
+
filters: { processId: antProcessId },
|
|
78
|
+
cursor,
|
|
79
|
+
limit: 100,
|
|
80
|
+
});
|
|
81
|
+
page.items.forEach((r) => {
|
|
82
|
+
affiliatedNames.add(r.name);
|
|
83
|
+
});
|
|
84
|
+
cursor = page.nextCursor;
|
|
85
|
+
hasMore = page.hasMore;
|
|
86
|
+
}
|
|
87
|
+
return affiliatedNames;
|
|
88
|
+
};
|
|
89
|
+
// get all the affiliated names if reassign all affiliated names is true
|
|
90
|
+
if (shouldReassignAll) {
|
|
91
|
+
onSigningProgress?.('fetching-affiliated-names', {
|
|
92
|
+
arioProcessId,
|
|
93
|
+
antProcessId,
|
|
94
|
+
});
|
|
95
|
+
namesToReassign = await getAllAffiliatedNames();
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
if (names === undefined || names.length === 0) {
|
|
99
|
+
throw new Error('Names are required when reassignAffiliatedNames is false.');
|
|
100
|
+
}
|
|
101
|
+
onSigningProgress?.('validating-names', {
|
|
102
|
+
arioProcessId,
|
|
103
|
+
antProcessId,
|
|
104
|
+
names,
|
|
105
|
+
});
|
|
106
|
+
// confirm all names are affiliated with the ANT
|
|
107
|
+
const allAffiliatedNames = await getAllAffiliatedNames();
|
|
108
|
+
if (!names.every((name) => allAffiliatedNames.has(name))) {
|
|
109
|
+
// find any that are not affiliated with the ANT
|
|
110
|
+
const notAffiliatedNames = names.filter((name) => !allAffiliatedNames.has(name));
|
|
111
|
+
throw new Error(`All names must be affiliated with the ANT on the provided ARIO process. The following names are not affiliated to this ANT: ${notAffiliatedNames.join(', ')}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// if names is empty and reassign all affiliated names is false, throw an error
|
|
115
|
+
if (namesToReassign.size === 0) {
|
|
116
|
+
throw new Error('There are no names to reassign for this ANT.');
|
|
117
|
+
}
|
|
118
|
+
const existingAntProcess = ANT.init({
|
|
119
|
+
process: new index_js_2.AOProcess({
|
|
120
|
+
processId: antProcessId,
|
|
121
|
+
ao,
|
|
122
|
+
logger,
|
|
123
|
+
}),
|
|
124
|
+
hyperbeamUrl,
|
|
125
|
+
signer,
|
|
126
|
+
});
|
|
127
|
+
if (!skipVersionCheck) {
|
|
128
|
+
onSigningProgress?.('checking-version', {
|
|
129
|
+
antProcessId,
|
|
130
|
+
antRegistryId,
|
|
131
|
+
});
|
|
132
|
+
const isLatestVersion = await existingAntProcess.isLatestVersion({
|
|
133
|
+
antRegistryId,
|
|
134
|
+
});
|
|
135
|
+
if (isLatestVersion) {
|
|
136
|
+
return {
|
|
137
|
+
forkedProcessId: antProcessId,
|
|
138
|
+
reassignedNames: {},
|
|
139
|
+
failedReassignedNames: {},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const forkedProcessId = await ANT.fork({
|
|
144
|
+
signer,
|
|
145
|
+
antProcessId,
|
|
146
|
+
ao,
|
|
147
|
+
logger,
|
|
148
|
+
antRegistryId,
|
|
149
|
+
onSigningProgress,
|
|
150
|
+
});
|
|
151
|
+
// we could parallelize this, but then signing progress would be harder to track
|
|
152
|
+
const reassignedNames = {};
|
|
153
|
+
const failedReassignedNames = {};
|
|
154
|
+
for (const name of namesToReassign) {
|
|
155
|
+
let reassignmentResult;
|
|
156
|
+
try {
|
|
157
|
+
onSigningProgress?.('reassigning-name', {
|
|
158
|
+
name,
|
|
159
|
+
arioProcessId,
|
|
160
|
+
antProcessId: forkedProcessId,
|
|
161
|
+
});
|
|
162
|
+
reassignmentResult = await existingAntProcess.reassignName({
|
|
163
|
+
name,
|
|
164
|
+
arioProcessId,
|
|
165
|
+
antProcessId: forkedProcessId,
|
|
166
|
+
});
|
|
167
|
+
onSigningProgress?.('successfully-reassigned-name', {
|
|
168
|
+
name,
|
|
169
|
+
arioProcessId,
|
|
170
|
+
antProcessId: forkedProcessId,
|
|
171
|
+
});
|
|
172
|
+
reassignedNames[name] = reassignmentResult;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
logger.error(`Failed to reassign name ${name}:`, { error });
|
|
176
|
+
onSigningProgress?.('failed-to-reassign-name', {
|
|
177
|
+
name,
|
|
178
|
+
arioProcessId,
|
|
179
|
+
antProcessId: forkedProcessId,
|
|
180
|
+
error,
|
|
181
|
+
});
|
|
182
|
+
// Continue with other names rather than failing completely
|
|
183
|
+
failedReassignedNames[name] = {
|
|
184
|
+
id: reassignmentResult?.id,
|
|
185
|
+
error,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return { forkedProcessId, reassignedNames, failedReassignedNames };
|
|
190
|
+
}
|
|
46
191
|
static init(config) {
|
|
47
192
|
if (config !== undefined && 'signer' in config) {
|
|
48
193
|
return new AoANTWriteable(config);
|
|
@@ -54,9 +199,11 @@ exports.ANT = ANT;
|
|
|
54
199
|
class AoANTReadable {
|
|
55
200
|
process;
|
|
56
201
|
processId;
|
|
57
|
-
strict;
|
|
58
202
|
hyperbeamUrl;
|
|
203
|
+
strict;
|
|
59
204
|
checkHyperBeamPromise;
|
|
205
|
+
moduleId;
|
|
206
|
+
moduleIdPromise;
|
|
60
207
|
logger = index_js_2.Logger.default;
|
|
61
208
|
constructor(config) {
|
|
62
209
|
this.strict = config.strict || false;
|
|
@@ -189,6 +336,185 @@ class AoANTReadable {
|
|
|
189
336
|
const info = await this.getInfo();
|
|
190
337
|
return info.Logo;
|
|
191
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Gets the module ID of the current ANT process by querying its spawn transaction tags.
|
|
341
|
+
* Results are cached after the first successful fetch.
|
|
342
|
+
*
|
|
343
|
+
* @param graphqlUrl The GraphQL endpoint URL (defaults to Arweave's GraphQL endpoint)
|
|
344
|
+
* @param retries Number of retry attempts (defaults to 3)
|
|
345
|
+
* @returns Promise<string> The module ID used to spawn this ANT process
|
|
346
|
+
* @example
|
|
347
|
+
* ```ts
|
|
348
|
+
* const moduleId = await ant.getModuleId();
|
|
349
|
+
* console.log(`ANT was spawned with module: ${moduleId}`);
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
async getModuleId({
|
|
353
|
+
// TODO: we could use wayfinder for this
|
|
354
|
+
graphqlUrl = 'https://arweave.net/graphql', retries = 3, } = {}) {
|
|
355
|
+
// Return cached result if available
|
|
356
|
+
if (this.moduleId !== undefined) {
|
|
357
|
+
this.logger.debug('Returning cached module ID', {
|
|
358
|
+
processId: this.processId,
|
|
359
|
+
moduleId: this.moduleId,
|
|
360
|
+
});
|
|
361
|
+
return this.moduleId;
|
|
362
|
+
}
|
|
363
|
+
// Return existing promise if already in flight
|
|
364
|
+
if (this.moduleIdPromise) {
|
|
365
|
+
this.logger.debug('Returning in-flight module ID promise', {
|
|
366
|
+
processId: this.processId,
|
|
367
|
+
});
|
|
368
|
+
return this.moduleIdPromise;
|
|
369
|
+
}
|
|
370
|
+
// Create and cache the promise to prevent multiple concurrent requests
|
|
371
|
+
this.moduleIdPromise = this.fetchModuleId({ graphqlUrl, retries });
|
|
372
|
+
try {
|
|
373
|
+
const moduleId = await this.moduleIdPromise;
|
|
374
|
+
this.moduleId = moduleId;
|
|
375
|
+
this.logger.debug('Successfully fetched and cached module ID', {
|
|
376
|
+
processId: this.processId,
|
|
377
|
+
moduleId,
|
|
378
|
+
});
|
|
379
|
+
return moduleId;
|
|
380
|
+
}
|
|
381
|
+
finally {
|
|
382
|
+
// Clear the promise so future calls can retry if this one failed
|
|
383
|
+
this.moduleIdPromise = undefined;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Internal method to fetch the module ID from GraphQL.
|
|
388
|
+
*
|
|
389
|
+
* TODO: this could be more like get process headers/metadata and fetch additional details.
|
|
390
|
+
*
|
|
391
|
+
* It seems like module is the only relevant one, but scheduler and authority are also available.
|
|
392
|
+
*/
|
|
393
|
+
async fetchModuleId({ graphqlUrl, retries, }) {
|
|
394
|
+
const query = JSON.stringify({
|
|
395
|
+
query: `
|
|
396
|
+
query {
|
|
397
|
+
transactions(
|
|
398
|
+
ids: ["${this.processId}"]
|
|
399
|
+
first: 1
|
|
400
|
+
) {
|
|
401
|
+
edges {
|
|
402
|
+
node {
|
|
403
|
+
tags {
|
|
404
|
+
name
|
|
405
|
+
value
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
`,
|
|
412
|
+
});
|
|
413
|
+
for (let i = 0; i < retries; i++) {
|
|
414
|
+
try {
|
|
415
|
+
const response = await fetch(graphqlUrl, {
|
|
416
|
+
method: 'POST',
|
|
417
|
+
body: query,
|
|
418
|
+
headers: {
|
|
419
|
+
'Content-Type': 'application/json',
|
|
420
|
+
},
|
|
421
|
+
signal: AbortSignal.timeout(10_000), // 10 second timeout
|
|
422
|
+
});
|
|
423
|
+
if (!response.ok) {
|
|
424
|
+
throw new Error(`GraphQL request failed: ${response.statusText}`);
|
|
425
|
+
}
|
|
426
|
+
const result = (await response.json());
|
|
427
|
+
if (result.errors) {
|
|
428
|
+
throw new Error(`GraphQL errors: ${result.errors.map((e) => e.message).join(', ')}`);
|
|
429
|
+
}
|
|
430
|
+
const edges = result.data?.transactions?.edges;
|
|
431
|
+
if (!edges || edges.length === 0) {
|
|
432
|
+
throw new Error(`No transaction found for process ID: ${this.processId}`);
|
|
433
|
+
}
|
|
434
|
+
const tags = edges[0].node.tags;
|
|
435
|
+
const moduleTag = tags.find((tag) => tag.name === 'Module');
|
|
436
|
+
if (!moduleTag) {
|
|
437
|
+
throw new Error(`No Module tag found for process ID: ${this.processId}`);
|
|
438
|
+
}
|
|
439
|
+
return moduleTag.value;
|
|
440
|
+
}
|
|
441
|
+
catch (error) {
|
|
442
|
+
if (i === retries - 1) {
|
|
443
|
+
// Final attempt failed
|
|
444
|
+
this.logger.error('Failed to get ANT module ID after all retries:', {
|
|
445
|
+
error,
|
|
446
|
+
});
|
|
447
|
+
throw new Error(`Unable to determine module ID for ANT process ${this.processId}: ${error.message}`);
|
|
448
|
+
}
|
|
449
|
+
// Exponential backoff
|
|
450
|
+
await new Promise((resolve) => setTimeout(resolve, Math.pow(2, i) * 1000));
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
throw new Error(`Unexpected error getting module ID for process ${this.processId}`);
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Gets the version string of the current ANT by matching its module ID
|
|
457
|
+
* with versions from the ANT registry.
|
|
458
|
+
*
|
|
459
|
+
* @param antRegistryId The ANT registry process ID (defaults to mainnet registry)
|
|
460
|
+
* @param graphqlUrl The GraphQL endpoint URL for getModuleId (defaults to Arweave's GraphQL endpoint)
|
|
461
|
+
* @param retries Number of retry attempts for getModuleId (defaults to 3)
|
|
462
|
+
* @returns Promise<string> The version string (e.g., "1.0.15") or "unknown" if not found
|
|
463
|
+
* @example
|
|
464
|
+
* ```ts
|
|
465
|
+
* const version = await ant.getVersion();
|
|
466
|
+
* console.log(`ANT is running version: ${version}`);
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
469
|
+
async getVersion({ antRegistryId = constants_js_2.ANT_REGISTRY_ID, graphqlUrl = 'https://arweave.net/graphql', retries = 3, } = {}) {
|
|
470
|
+
// Get the current ANT's module ID
|
|
471
|
+
const currentModuleId = await this.getModuleId({ graphqlUrl, retries });
|
|
472
|
+
// Get all versions from the ANT registry
|
|
473
|
+
const antVersions = ant_versions_js_1.ANTVersions.init({
|
|
474
|
+
processId: antRegistryId,
|
|
475
|
+
});
|
|
476
|
+
const versions = await antVersions.getANTVersions();
|
|
477
|
+
// Find the version that matches our module ID
|
|
478
|
+
for (const [version, versionInfo] of Object.entries(versions)) {
|
|
479
|
+
if (versionInfo.moduleId === currentModuleId) {
|
|
480
|
+
this.logger.debug('Found matching ANT version', {
|
|
481
|
+
processId: this.processId,
|
|
482
|
+
moduleId: currentModuleId,
|
|
483
|
+
version,
|
|
484
|
+
});
|
|
485
|
+
return version;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
const versionForModuleId = Object.entries(versions)
|
|
489
|
+
.map(([version, versionInfo]) => ({
|
|
490
|
+
version,
|
|
491
|
+
...versionInfo,
|
|
492
|
+
}))
|
|
493
|
+
.find((obj) => obj.moduleId === currentModuleId);
|
|
494
|
+
return versionForModuleId?.version ?? 'unknown';
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Checks if the current ANT version is the latest according to the ANT registry.
|
|
498
|
+
*
|
|
499
|
+
* @param antRegistryId Optional ANT registry process ID. Defaults to mainnet ANT registry.
|
|
500
|
+
* @param graphqlUrl Optional GraphQL endpoint. Defaults to https://arweave.net/graphql.
|
|
501
|
+
* @param retries Optional number of retries for fetching module ID. Defaults to 3.
|
|
502
|
+
* @returns {Promise<boolean>} True if current ANT version is the latest, false otherwise.
|
|
503
|
+
*/
|
|
504
|
+
async isLatestVersion({ antRegistryId = constants_js_2.ANT_REGISTRY_ID, graphqlUrl = 'https://arweave.net/graphql', retries = 3, } = {}) {
|
|
505
|
+
// Get the current ANT's version
|
|
506
|
+
const currentVersion = await this.getVersion({
|
|
507
|
+
antRegistryId,
|
|
508
|
+
graphqlUrl,
|
|
509
|
+
retries,
|
|
510
|
+
});
|
|
511
|
+
// Get all versions from the ANT registry
|
|
512
|
+
const antVersions = ant_versions_js_1.ANTVersions.init({
|
|
513
|
+
processId: antRegistryId,
|
|
514
|
+
});
|
|
515
|
+
const latestVersion = await antVersions.getLatestANTVersion();
|
|
516
|
+
return currentVersion === latestVersion.version;
|
|
517
|
+
}
|
|
192
518
|
/**
|
|
193
519
|
* @param undername @type {string} The domain name.
|
|
194
520
|
* @returns {Promise<ANTRecord>} The record of the undername domain.
|
|
@@ -721,5 +1047,61 @@ class AoANTWriteable extends AoANTReadable {
|
|
|
721
1047
|
signer: this.signer,
|
|
722
1048
|
});
|
|
723
1049
|
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Upgrade this ANT by forking it to the latest version and reassigning names.
|
|
1052
|
+
*
|
|
1053
|
+
* This is a convenience method that calls the static ANT.upgrade() method
|
|
1054
|
+
* using this instance's process ID and signer.
|
|
1055
|
+
*
|
|
1056
|
+
* current version with latest ANT registry version and skip if already up to date.
|
|
1057
|
+
*
|
|
1058
|
+
* @param names @type {string[]} The ArNS names to reassign to the upgraded ANT.
|
|
1059
|
+
* @param arioProcessId @type {string} The processId of the ARIO contract.
|
|
1060
|
+
* @param antRegistryId @type {string} Optional ANT registry ID.
|
|
1061
|
+
* @param onSigningProgress Progress callback function.
|
|
1062
|
+
* @returns {Promise} The upgrade results.
|
|
1063
|
+
* @example
|
|
1064
|
+
* ```ts
|
|
1065
|
+
* const result = await ant.upgrade({
|
|
1066
|
+
* names: ["example", "test"],
|
|
1067
|
+
* arioProcessId: ARIO_MAINNET_PROCESS_ID
|
|
1068
|
+
* });
|
|
1069
|
+
* console.log(`Upgraded to process: ${result.forkedProcessId}`);
|
|
1070
|
+
* ```
|
|
1071
|
+
*/
|
|
1072
|
+
async upgrade(params) {
|
|
1073
|
+
const { names, reassignAffiliatedNames, arioProcessId, antRegistryId, skipVersionCheck, onSigningProgress, } = params ?? {};
|
|
1074
|
+
// Determine if we should reassign all names or specific names
|
|
1075
|
+
const shouldReassignAll = names === undefined || names.length === 0
|
|
1076
|
+
? (reassignAffiliatedNames ?? true)
|
|
1077
|
+
: false;
|
|
1078
|
+
if (shouldReassignAll) {
|
|
1079
|
+
return ANT.upgrade({
|
|
1080
|
+
signer: this.signer,
|
|
1081
|
+
antProcessId: this.processId,
|
|
1082
|
+
ao: this.process.ao,
|
|
1083
|
+
hyperbeamUrl: this.hyperbeamUrl?.toString(),
|
|
1084
|
+
reassignAffiliatedNames: true,
|
|
1085
|
+
arioProcessId: arioProcessId,
|
|
1086
|
+
antRegistryId: antRegistryId,
|
|
1087
|
+
onSigningProgress: onSigningProgress,
|
|
1088
|
+
skipVersionCheck: skipVersionCheck,
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
else {
|
|
1092
|
+
return ANT.upgrade({
|
|
1093
|
+
signer: this.signer,
|
|
1094
|
+
antProcessId: this.processId,
|
|
1095
|
+
ao: this.process.ao,
|
|
1096
|
+
hyperbeamUrl: this.hyperbeamUrl?.toString(),
|
|
1097
|
+
names: names,
|
|
1098
|
+
reassignAffiliatedNames: false,
|
|
1099
|
+
arioProcessId: arioProcessId,
|
|
1100
|
+
antRegistryId: antRegistryId,
|
|
1101
|
+
onSigningProgress: onSigningProgress,
|
|
1102
|
+
skipVersionCheck: skipVersionCheck,
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
724
1106
|
}
|
|
725
1107
|
exports.AoANTWriteable = AoANTWriteable;
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -684,12 +684,12 @@ class ARIOReadable {
|
|
|
684
684
|
* @returns {Promise<AoArNSNameData[]>} The ARNS names associated with the address
|
|
685
685
|
*/
|
|
686
686
|
async getArNSRecordsForAddress(params) {
|
|
687
|
-
const {
|
|
687
|
+
const { antRegistryProcessId = constants_js_1.ANT_REGISTRY_ID, address } = params;
|
|
688
688
|
const antRegistry = ant_registry_js_1.ANTRegistry.init({
|
|
689
689
|
hyperbeamUrl: this.hyperbeamUrl,
|
|
690
690
|
process: new ao_process_js_1.AOProcess({
|
|
691
691
|
ao: this.process.ao,
|
|
692
|
-
processId:
|
|
692
|
+
processId: antRegistryProcessId,
|
|
693
693
|
}),
|
|
694
694
|
});
|
|
695
695
|
// Note: there could be a race condition here if the ACL changes during pagination requests, resulting in different results from the `getArNSRecords`.
|
package/lib/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_SCHEDULER_ID = exports.AO_AUTHORITY = exports.ANT_LUA_ID = exports.AOS_MODULE_ID = exports.MARIO_PER_ARIO = exports.ANT_REGISTRY_ID = exports.ARIO_MAINNET_PROCESS_ID = exports.ARIO_TESTNET_PROCESS_ID = exports.arioDevnetProcessId = exports.ARIO_DEVNET_PROCESS_ID = exports.FQDN_REGEX = exports.ARWEAVE_TX_REGEX = void 0;
|
|
3
|
+
exports.DEFAULT_SCHEDULER_ID = exports.AO_AUTHORITY = exports.ANT_LUA_ID = exports.AOS_MODULE_ID = exports.MARIO_PER_ARIO = exports.ANT_REGISTRY_ID = exports.ANT_REGISTRY_TESTNET_ID = exports.ARIO_MAINNET_PROCESS_ID = exports.ARIO_TESTNET_PROCESS_ID = exports.arioDevnetProcessId = exports.ARIO_DEVNET_PROCESS_ID = exports.FQDN_REGEX = exports.ARWEAVE_TX_REGEX = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
6
|
*
|
|
@@ -24,6 +24,7 @@ exports.ARIO_DEVNET_PROCESS_ID = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc';
|
|
|
24
24
|
exports.arioDevnetProcessId = exports.ARIO_DEVNET_PROCESS_ID;
|
|
25
25
|
exports.ARIO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
|
|
26
26
|
exports.ARIO_MAINNET_PROCESS_ID = 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE';
|
|
27
|
+
exports.ANT_REGISTRY_TESTNET_ID = 'RR0vheYqtsKuJCWh6xj0beE35tjaEug5cejMw9n2aa8';
|
|
27
28
|
exports.ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc';
|
|
28
29
|
exports.MARIO_PER_ARIO = 1_000_000;
|
|
29
30
|
/**
|
package/lib/cjs/utils/ant.js
CHANGED
|
@@ -41,6 +41,9 @@ const sortANTRecords = (antRecords) => {
|
|
|
41
41
|
return Object.fromEntries(sortedEntries.map(([a, aRecord], index) => [a, { ...aRecord, index }]));
|
|
42
42
|
};
|
|
43
43
|
exports.sortANTRecords = sortANTRecords;
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated - this is no longer necessary because HyperBeam now uses the AoANTState type
|
|
46
|
+
*/
|
|
44
47
|
const isHyperBeamANTState = (state) => {
|
|
45
48
|
return ('name' in state &&
|
|
46
49
|
'ticker' in state &&
|
|
@@ -59,6 +62,7 @@ exports.isHyperBeamANTState = isHyperBeamANTState;
|
|
|
59
62
|
/**
|
|
60
63
|
* Convert HyperBeam serialized ANT state to backwards compatible format.
|
|
61
64
|
*
|
|
65
|
+
* @deprecated - this is no longer necessary because HyperBeam now uses the AOANTState type
|
|
62
66
|
* @param state - The HyperBeam serialized ANT state.
|
|
63
67
|
*/
|
|
64
68
|
const convertHyperBeamStateToAoANTState = (initialState) => {
|
package/lib/cjs/utils/ao.js
CHANGED
|
@@ -223,7 +223,7 @@ async function spawnANT({ signer, module, ao = (0, aoconnect_1.connect)({
|
|
|
223
223
|
}
|
|
224
224
|
return processId;
|
|
225
225
|
}
|
|
226
|
-
async function forkANT({ signer, antProcessId, logger = index_js_1.Logger.default, ao, antRegistryId = constants_js_1.ANT_REGISTRY_ID, onSigningProgress = (name, payload) => {
|
|
226
|
+
async function forkANT({ signer, antProcessId, logger = index_js_1.Logger.default, ao, moduleId, antRegistryId = constants_js_1.ANT_REGISTRY_ID, onSigningProgress = (name, payload) => {
|
|
227
227
|
logger.debug('Forking ANT', { name, payload });
|
|
228
228
|
}, }) {
|
|
229
229
|
// get the state of the current ANT and use it to spawn a new ANT
|
|
@@ -241,7 +241,9 @@ async function forkANT({ signer, antProcessId, logger = index_js_1.Logger.defaul
|
|
|
241
241
|
const forkedProcessId = await spawnANT({
|
|
242
242
|
signer,
|
|
243
243
|
antRegistryId,
|
|
244
|
+
ao,
|
|
244
245
|
logger,
|
|
246
|
+
module: moduleId,
|
|
245
247
|
onSigningProgress,
|
|
246
248
|
state: {
|
|
247
249
|
owner: state.Owner,
|
|
@@ -26,7 +26,7 @@ const io_js_1 = require("../common/io.js");
|
|
|
26
26
|
const logger_js_1 = require("../common/logger.js");
|
|
27
27
|
const constants_js_1 = require("../constants.js");
|
|
28
28
|
/**
|
|
29
|
-
* @
|
|
29
|
+
* @deprecated Use getArNSRecordsForAddress instead
|
|
30
30
|
*/
|
|
31
31
|
const getANTProcessesOwnedByWallet = async ({ address, registry = ant_registry_js_1.ANTRegistry.init(), }) => {
|
|
32
32
|
const res = await registry.accessControlList({ address });
|
package/lib/cjs/version.js
CHANGED