@ar.io/sdk 2.0.2 → 2.1.0-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.
- package/bundles/web.bundle.min.js +74 -74
- package/lib/cjs/constants.js +1 -1
- package/lib/cjs/utils/ao.js +23 -1
- package/lib/cjs/utils/processes.js +29 -4
- package/lib/cjs/version.js +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/utils/ao.js +21 -0
- package/lib/esm/utils/processes.js +29 -4
- package/lib/esm/version.js +1 -1
- package/lib/types/common/ant.d.ts +1 -0
- package/lib/types/constants.d.ts +1 -1
- package/lib/types/io.d.ts +1 -0
- package/lib/types/utils/ao.d.ts +6 -0
- package/lib/types/utils/processes.d.ts +5 -2
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/constants.js
CHANGED
|
@@ -30,5 +30,5 @@ exports.ioDevnetProcessId = exports.IO_DEVNET_PROCESS_ID;
|
|
|
30
30
|
exports.IO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
|
|
31
31
|
exports.MIO_PER_IO = 1_000_000;
|
|
32
32
|
exports.AOS_MODULE_ID = 'cbn0KKrBZH7hdNkNokuXLtGryrWM--PjSTBqIzw9Kkk';
|
|
33
|
-
exports.ANT_LUA_ID = '
|
|
33
|
+
exports.ANT_LUA_ID = 'Flwio4Lr08g6s6uim6lEJNnVGD9ylvz0_aafvpiL8FI';
|
|
34
34
|
exports.DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
|
package/lib/cjs/utils/ao.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.spawnANT = void 0;
|
|
3
|
+
exports.evolveANT = exports.spawnANT = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
6
6
|
*
|
|
@@ -60,3 +60,25 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
|
|
|
60
60
|
return processId;
|
|
61
61
|
}
|
|
62
62
|
exports.spawnANT = spawnANT;
|
|
63
|
+
async function evolveANT({ signer, processId, luaCodeTxId = constants_js_1.ANT_LUA_ID, ao = (0, aoconnect_1.connect)(), }) {
|
|
64
|
+
const aosClient = new index_js_1.AOProcess({
|
|
65
|
+
processId,
|
|
66
|
+
ao,
|
|
67
|
+
});
|
|
68
|
+
//TODO: cache locally and only fetch if not cached
|
|
69
|
+
const luaString = (await arweave_js_1.defaultArweave.transactions.getData(luaCodeTxId, {
|
|
70
|
+
decode: true,
|
|
71
|
+
string: true,
|
|
72
|
+
}));
|
|
73
|
+
const { id } = await aosClient.send({
|
|
74
|
+
tags: [
|
|
75
|
+
{ name: 'Action', value: 'Eval' },
|
|
76
|
+
{ name: 'App-Name', value: 'ArNS-ANT' },
|
|
77
|
+
{ name: 'Source-Code-TX-ID', value: luaCodeTxId },
|
|
78
|
+
],
|
|
79
|
+
data: luaString,
|
|
80
|
+
signer,
|
|
81
|
+
});
|
|
82
|
+
return id;
|
|
83
|
+
}
|
|
84
|
+
exports.evolveANT = evolveANT;
|
|
@@ -21,6 +21,7 @@ const eventemitter3_1 = require("eventemitter3");
|
|
|
21
21
|
const plimit_lit_1 = require("plimit-lit");
|
|
22
22
|
const ant_js_1 = require("../common/ant.js");
|
|
23
23
|
const io_js_1 = require("../common/io.js");
|
|
24
|
+
const logger_js_1 = require("../common/logger.js");
|
|
24
25
|
const constants_js_1 = require("../constants.js");
|
|
25
26
|
const getANTProcessesOwnedByWallet = async ({ address, contract = io_js_1.IO.init({
|
|
26
27
|
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
@@ -71,19 +72,25 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
71
72
|
contract;
|
|
72
73
|
timeoutMs; // timeout for each request to 3 seconds
|
|
73
74
|
throttle;
|
|
75
|
+
logger;
|
|
74
76
|
constructor({ contract = io_js_1.IO.init({
|
|
75
77
|
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
76
|
-
}), timeoutMs = 60_000, concurrency = 30, }) {
|
|
78
|
+
}), timeoutMs = 60_000, concurrency = 30, logger = logger_js_1.Logger.default, } = {}) {
|
|
77
79
|
super();
|
|
78
80
|
this.contract = contract;
|
|
79
81
|
this.timeoutMs = timeoutMs;
|
|
80
82
|
this.throttle = (0, plimit_lit_1.pLimit)(concurrency);
|
|
83
|
+
this.logger = logger;
|
|
81
84
|
}
|
|
82
85
|
async fetchProcessesOwnedByWallet({ address }) {
|
|
83
86
|
const uniqueContractProcessIds = {};
|
|
84
|
-
await timeout(this.timeoutMs, (0, exports.fetchAllArNSRecords)({ contract: this.contract }))
|
|
87
|
+
await timeout(this.timeoutMs, (0, exports.fetchAllArNSRecords)({ contract: this.contract, emitter: this }))
|
|
85
88
|
.catch((e) => {
|
|
86
89
|
this.emit('error', `Error getting ArNS records: ${e}`);
|
|
90
|
+
this.logger.error(`Error getting ArNS records`, {
|
|
91
|
+
message: e?.message,
|
|
92
|
+
stack: e?.stack,
|
|
93
|
+
});
|
|
87
94
|
return {};
|
|
88
95
|
})
|
|
89
96
|
.then((records) => {
|
|
@@ -103,8 +110,8 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
103
110
|
});
|
|
104
111
|
});
|
|
105
112
|
const idCount = Object.keys(uniqueContractProcessIds).length;
|
|
106
|
-
// check the contract owner and controllers
|
|
107
113
|
this.emit('progress', 0, idCount);
|
|
114
|
+
// check the contract owner and controllers
|
|
108
115
|
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) => this.throttle(async () => {
|
|
109
116
|
if (uniqueContractProcessIds[processId].state !== undefined) {
|
|
110
117
|
this.emit('progress', i + 1, idCount);
|
|
@@ -130,8 +137,9 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
130
137
|
exports.ArNSEventEmitter = ArNSEventEmitter;
|
|
131
138
|
const fetchAllArNSRecords = async ({ contract = io_js_1.IO.init({
|
|
132
139
|
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
133
|
-
}), logger, }) => {
|
|
140
|
+
}), emitter, logger = logger_js_1.Logger.default, }) => {
|
|
134
141
|
let cursor;
|
|
142
|
+
const startTimestamp = Date.now();
|
|
135
143
|
const records = {};
|
|
136
144
|
do {
|
|
137
145
|
const pageResult = await contract
|
|
@@ -141,6 +149,7 @@ const fetchAllArNSRecords = async ({ contract = io_js_1.IO.init({
|
|
|
141
149
|
message: e?.message,
|
|
142
150
|
stack: e?.stack,
|
|
143
151
|
});
|
|
152
|
+
emitter?.emit('arns:error', `Error getting ArNS records: ${e}`);
|
|
144
153
|
return undefined;
|
|
145
154
|
});
|
|
146
155
|
if (!pageResult) {
|
|
@@ -150,8 +159,24 @@ const fetchAllArNSRecords = async ({ contract = io_js_1.IO.init({
|
|
|
150
159
|
const { name, ...recordDetails } = record;
|
|
151
160
|
records[name] = recordDetails;
|
|
152
161
|
});
|
|
162
|
+
logger.debug('Fetched page of ArNS records', {
|
|
163
|
+
totalRecordCount: pageResult.totalItems,
|
|
164
|
+
fetchedRecordCount: Object.keys(records).length,
|
|
165
|
+
cursor: pageResult.nextCursor,
|
|
166
|
+
});
|
|
167
|
+
emitter?.emit('arns:pageLoaded', {
|
|
168
|
+
totalRecordCount: pageResult.totalItems,
|
|
169
|
+
fetchedRecordCount: Object.keys(records).length,
|
|
170
|
+
records: pageResult.items,
|
|
171
|
+
cursor: pageResult.nextCursor,
|
|
172
|
+
});
|
|
153
173
|
cursor = pageResult.nextCursor;
|
|
154
174
|
} while (cursor !== undefined);
|
|
175
|
+
emitter?.emit('arns:end', records);
|
|
176
|
+
logger.debug('Fetched all ArNS records', {
|
|
177
|
+
totalRecordCount: Object.keys(records).length,
|
|
178
|
+
durationMs: Date.now() - startTimestamp,
|
|
179
|
+
});
|
|
155
180
|
return records;
|
|
156
181
|
};
|
|
157
182
|
exports.fetchAllArNSRecords = fetchAllArNSRecords;
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/constants.js
CHANGED
|
@@ -27,5 +27,5 @@ export const ioDevnetProcessId = IO_DEVNET_PROCESS_ID;
|
|
|
27
27
|
export const IO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
|
|
28
28
|
export const MIO_PER_IO = 1_000_000;
|
|
29
29
|
export const AOS_MODULE_ID = 'cbn0KKrBZH7hdNkNokuXLtGryrWM--PjSTBqIzw9Kkk';
|
|
30
|
-
export const ANT_LUA_ID = '
|
|
30
|
+
export const ANT_LUA_ID = 'Flwio4Lr08g6s6uim6lEJNnVGD9ylvz0_aafvpiL8FI';
|
|
31
31
|
export const DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
|
package/lib/esm/utils/ao.js
CHANGED
|
@@ -56,3 +56,24 @@ export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = A
|
|
|
56
56
|
}
|
|
57
57
|
return processId;
|
|
58
58
|
}
|
|
59
|
+
export async function evolveANT({ signer, processId, luaCodeTxId = ANT_LUA_ID, ao = connect(), }) {
|
|
60
|
+
const aosClient = new AOProcess({
|
|
61
|
+
processId,
|
|
62
|
+
ao,
|
|
63
|
+
});
|
|
64
|
+
//TODO: cache locally and only fetch if not cached
|
|
65
|
+
const luaString = (await defaultArweave.transactions.getData(luaCodeTxId, {
|
|
66
|
+
decode: true,
|
|
67
|
+
string: true,
|
|
68
|
+
}));
|
|
69
|
+
const { id } = await aosClient.send({
|
|
70
|
+
tags: [
|
|
71
|
+
{ name: 'Action', value: 'Eval' },
|
|
72
|
+
{ name: 'App-Name', value: 'ArNS-ANT' },
|
|
73
|
+
{ name: 'Source-Code-TX-ID', value: luaCodeTxId },
|
|
74
|
+
],
|
|
75
|
+
data: luaString,
|
|
76
|
+
signer,
|
|
77
|
+
});
|
|
78
|
+
return id;
|
|
79
|
+
}
|
|
@@ -18,6 +18,7 @@ import { EventEmitter } from 'eventemitter3';
|
|
|
18
18
|
import { pLimit } from 'plimit-lit';
|
|
19
19
|
import { ANT } from '../common/ant.js';
|
|
20
20
|
import { IO } from '../common/io.js';
|
|
21
|
+
import { Logger } from '../common/logger.js';
|
|
21
22
|
import { IO_TESTNET_PROCESS_ID } from '../constants.js';
|
|
22
23
|
export const getANTProcessesOwnedByWallet = async ({ address, contract = IO.init({
|
|
23
24
|
processId: IO_TESTNET_PROCESS_ID,
|
|
@@ -67,19 +68,25 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
67
68
|
contract;
|
|
68
69
|
timeoutMs; // timeout for each request to 3 seconds
|
|
69
70
|
throttle;
|
|
71
|
+
logger;
|
|
70
72
|
constructor({ contract = IO.init({
|
|
71
73
|
processId: IO_TESTNET_PROCESS_ID,
|
|
72
|
-
}), timeoutMs = 60_000, concurrency = 30, }) {
|
|
74
|
+
}), timeoutMs = 60_000, concurrency = 30, logger = Logger.default, } = {}) {
|
|
73
75
|
super();
|
|
74
76
|
this.contract = contract;
|
|
75
77
|
this.timeoutMs = timeoutMs;
|
|
76
78
|
this.throttle = pLimit(concurrency);
|
|
79
|
+
this.logger = logger;
|
|
77
80
|
}
|
|
78
81
|
async fetchProcessesOwnedByWallet({ address }) {
|
|
79
82
|
const uniqueContractProcessIds = {};
|
|
80
|
-
await timeout(this.timeoutMs, fetchAllArNSRecords({ contract: this.contract }))
|
|
83
|
+
await timeout(this.timeoutMs, fetchAllArNSRecords({ contract: this.contract, emitter: this }))
|
|
81
84
|
.catch((e) => {
|
|
82
85
|
this.emit('error', `Error getting ArNS records: ${e}`);
|
|
86
|
+
this.logger.error(`Error getting ArNS records`, {
|
|
87
|
+
message: e?.message,
|
|
88
|
+
stack: e?.stack,
|
|
89
|
+
});
|
|
83
90
|
return {};
|
|
84
91
|
})
|
|
85
92
|
.then((records) => {
|
|
@@ -99,8 +106,8 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
99
106
|
});
|
|
100
107
|
});
|
|
101
108
|
const idCount = Object.keys(uniqueContractProcessIds).length;
|
|
102
|
-
// check the contract owner and controllers
|
|
103
109
|
this.emit('progress', 0, idCount);
|
|
110
|
+
// check the contract owner and controllers
|
|
104
111
|
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) => this.throttle(async () => {
|
|
105
112
|
if (uniqueContractProcessIds[processId].state !== undefined) {
|
|
106
113
|
this.emit('progress', i + 1, idCount);
|
|
@@ -125,8 +132,9 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
125
132
|
}
|
|
126
133
|
export const fetchAllArNSRecords = async ({ contract = IO.init({
|
|
127
134
|
processId: IO_TESTNET_PROCESS_ID,
|
|
128
|
-
}), logger, }) => {
|
|
135
|
+
}), emitter, logger = Logger.default, }) => {
|
|
129
136
|
let cursor;
|
|
137
|
+
const startTimestamp = Date.now();
|
|
130
138
|
const records = {};
|
|
131
139
|
do {
|
|
132
140
|
const pageResult = await contract
|
|
@@ -136,6 +144,7 @@ export const fetchAllArNSRecords = async ({ contract = IO.init({
|
|
|
136
144
|
message: e?.message,
|
|
137
145
|
stack: e?.stack,
|
|
138
146
|
});
|
|
147
|
+
emitter?.emit('arns:error', `Error getting ArNS records: ${e}`);
|
|
139
148
|
return undefined;
|
|
140
149
|
});
|
|
141
150
|
if (!pageResult) {
|
|
@@ -145,7 +154,23 @@ export const fetchAllArNSRecords = async ({ contract = IO.init({
|
|
|
145
154
|
const { name, ...recordDetails } = record;
|
|
146
155
|
records[name] = recordDetails;
|
|
147
156
|
});
|
|
157
|
+
logger.debug('Fetched page of ArNS records', {
|
|
158
|
+
totalRecordCount: pageResult.totalItems,
|
|
159
|
+
fetchedRecordCount: Object.keys(records).length,
|
|
160
|
+
cursor: pageResult.nextCursor,
|
|
161
|
+
});
|
|
162
|
+
emitter?.emit('arns:pageLoaded', {
|
|
163
|
+
totalRecordCount: pageResult.totalItems,
|
|
164
|
+
fetchedRecordCount: Object.keys(records).length,
|
|
165
|
+
records: pageResult.items,
|
|
166
|
+
cursor: pageResult.nextCursor,
|
|
167
|
+
});
|
|
148
168
|
cursor = pageResult.nextCursor;
|
|
149
169
|
} while (cursor !== undefined);
|
|
170
|
+
emitter?.emit('arns:end', records);
|
|
171
|
+
logger.debug('Fetched all ArNS records', {
|
|
172
|
+
totalRecordCount: Object.keys(records).length,
|
|
173
|
+
durationMs: Date.now() - startTimestamp,
|
|
174
|
+
});
|
|
150
175
|
return records;
|
|
151
176
|
};
|
package/lib/esm/version.js
CHANGED
package/lib/types/constants.d.ts
CHANGED
|
@@ -25,5 +25,5 @@ export declare const ioDevnetProcessId = "GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6Gc
|
|
|
25
25
|
export declare const IO_TESTNET_PROCESS_ID = "agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA";
|
|
26
26
|
export declare const MIO_PER_IO = 1000000;
|
|
27
27
|
export declare const AOS_MODULE_ID = "cbn0KKrBZH7hdNkNokuXLtGryrWM--PjSTBqIzw9Kkk";
|
|
28
|
-
export declare const ANT_LUA_ID = "
|
|
28
|
+
export declare const ANT_LUA_ID = "Flwio4Lr08g6s6uim6lEJNnVGD9ylvz0_aafvpiL8FI";
|
|
29
29
|
export declare const DEFAULT_SCHEDULER_ID = "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA";
|
package/lib/types/io.d.ts
CHANGED
package/lib/types/utils/ao.d.ts
CHANGED
|
@@ -9,3 +9,9 @@ export declare function spawnANT({ signer, module, luaCodeTxId, ao, scheduler, s
|
|
|
9
9
|
state?: ANTState;
|
|
10
10
|
stateContractTxId?: string;
|
|
11
11
|
}): Promise<string>;
|
|
12
|
+
export declare function evolveANT({ signer, processId, luaCodeTxId, ao, }: {
|
|
13
|
+
signer: ContractSigner;
|
|
14
|
+
processId: string;
|
|
15
|
+
luaCodeTxId?: string;
|
|
16
|
+
ao?: AoClient;
|
|
17
|
+
}): Promise<string>;
|
|
@@ -25,16 +25,19 @@ export declare class ArNSEventEmitter extends EventEmitter {
|
|
|
25
25
|
protected contract: AoIORead;
|
|
26
26
|
private timeoutMs;
|
|
27
27
|
private throttle;
|
|
28
|
-
|
|
28
|
+
private logger;
|
|
29
|
+
constructor({ contract, timeoutMs, concurrency, logger, }?: {
|
|
29
30
|
contract?: AoIORead;
|
|
30
31
|
timeoutMs?: number;
|
|
31
32
|
concurrency?: number;
|
|
33
|
+
logger?: ILogger;
|
|
32
34
|
});
|
|
33
35
|
fetchProcessesOwnedByWallet({ address }: {
|
|
34
36
|
address: WalletAddress;
|
|
35
37
|
}): Promise<void>;
|
|
36
38
|
}
|
|
37
|
-
export declare const fetchAllArNSRecords: ({ contract, logger, }: {
|
|
39
|
+
export declare const fetchAllArNSRecords: ({ contract, emitter, logger, }: {
|
|
38
40
|
contract?: AoIORead;
|
|
41
|
+
emitter?: EventEmitter;
|
|
39
42
|
logger?: ILogger;
|
|
40
43
|
}) => Promise<Record<string, AoArNSNameData>>;
|
package/lib/types/version.d.ts
CHANGED