@ar.io/sdk 2.0.0-alpha.8 → 2.0.0
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 +211 -128
- package/bundles/web.bundle.min.js +79 -79
- package/lib/cjs/common/io.js +78 -14
- package/lib/cjs/utils/index.js +1 -1
- package/lib/cjs/utils/{graphql/processes.js → processes.js} +40 -10
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/io.js +78 -14
- package/lib/esm/utils/index.js +1 -1
- package/lib/esm/utils/{graphql/processes.js → processes.js} +38 -9
- package/lib/esm/version.js +1 -1
- package/lib/types/common/ant.d.ts +0 -24
- package/lib/types/common/io.d.ts +4 -4
- package/lib/types/io.d.ts +27 -3
- package/lib/types/utils/index.d.ts +1 -1
- package/lib/types/utils/{graphql/processes.d.ts → processes.d.ts} +6 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/lib/cjs/utils/graphql/index.js +0 -33
- package/lib/esm/utils/graphql/index.js +0 -17
- package/lib/types/utils/graphql/index.d.ts +0 -17
package/lib/cjs/common/io.js
CHANGED
|
@@ -52,7 +52,12 @@ class IOReadable {
|
|
|
52
52
|
{
|
|
53
53
|
name: 'Timestamp',
|
|
54
54
|
value: params?.timestamp?.toString() ??
|
|
55
|
-
(await this.arweave.blocks
|
|
55
|
+
(await this.arweave.blocks
|
|
56
|
+
.getCurrent()
|
|
57
|
+
.then((block) => {
|
|
58
|
+
return { timestamp: block.timestamp * 1000 };
|
|
59
|
+
})
|
|
60
|
+
.catch(() => {
|
|
56
61
|
return { timestamp: Date.now() }; // fallback to current time
|
|
57
62
|
})).timestamp.toString(),
|
|
58
63
|
},
|
|
@@ -72,7 +77,12 @@ class IOReadable {
|
|
|
72
77
|
{
|
|
73
78
|
name: 'Timestamp',
|
|
74
79
|
value: epoch?.timestamp?.toString() ??
|
|
75
|
-
(await this.arweave.blocks
|
|
80
|
+
(await this.arweave.blocks
|
|
81
|
+
.getCurrent()
|
|
82
|
+
.then((block) => {
|
|
83
|
+
return { timestamp: block.timestamp * 1000 };
|
|
84
|
+
})
|
|
85
|
+
.catch(() => {
|
|
76
86
|
return { timestamp: Date.now() }; // fallback to current time
|
|
77
87
|
})).timestamp.toString(),
|
|
78
88
|
},
|
|
@@ -94,9 +104,17 @@ class IOReadable {
|
|
|
94
104
|
],
|
|
95
105
|
});
|
|
96
106
|
}
|
|
97
|
-
async getArNSRecords() {
|
|
107
|
+
async getArNSRecords(pageParams) {
|
|
108
|
+
const allTags = [
|
|
109
|
+
{ name: 'Action', value: 'Paginated-Records' },
|
|
110
|
+
{ name: 'Cursor', value: pageParams?.cursor?.toString() },
|
|
111
|
+
{ name: 'Limit', value: pageParams?.limit?.toString() },
|
|
112
|
+
{ name: 'Sort-By', value: pageParams?.sortBy },
|
|
113
|
+
{ name: 'Sort-Order', value: pageParams?.sortOrder },
|
|
114
|
+
];
|
|
115
|
+
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
98
116
|
return this.process.read({
|
|
99
|
-
tags:
|
|
117
|
+
tags: prunedTags,
|
|
100
118
|
});
|
|
101
119
|
}
|
|
102
120
|
async getArNSReservedNames() {
|
|
@@ -120,9 +138,17 @@ class IOReadable {
|
|
|
120
138
|
],
|
|
121
139
|
});
|
|
122
140
|
}
|
|
123
|
-
async getBalances() {
|
|
141
|
+
async getBalances(pageParams) {
|
|
142
|
+
const allTags = [
|
|
143
|
+
{ name: 'Action', value: 'Paginated-Balances' },
|
|
144
|
+
{ name: 'Cursor', value: pageParams?.cursor?.toString() },
|
|
145
|
+
{ name: 'Limit', value: pageParams?.limit?.toString() },
|
|
146
|
+
{ name: 'Sort-By', value: pageParams?.sortBy },
|
|
147
|
+
{ name: 'Sort-Order', value: pageParams?.sortOrder },
|
|
148
|
+
];
|
|
149
|
+
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
124
150
|
return this.process.read({
|
|
125
|
-
tags:
|
|
151
|
+
tags: prunedTags,
|
|
126
152
|
});
|
|
127
153
|
}
|
|
128
154
|
async getGateway({ address, }) {
|
|
@@ -133,9 +159,17 @@ class IOReadable {
|
|
|
133
159
|
],
|
|
134
160
|
});
|
|
135
161
|
}
|
|
136
|
-
async getGateways() {
|
|
162
|
+
async getGateways(pageParams) {
|
|
163
|
+
const allTags = [
|
|
164
|
+
{ name: 'Action', value: 'Paginated-Gateways' },
|
|
165
|
+
{ name: 'Cursor', value: pageParams?.cursor?.toString() },
|
|
166
|
+
{ name: 'Limit', value: pageParams?.limit?.toString() },
|
|
167
|
+
{ name: 'Sort-By', value: pageParams?.sortBy },
|
|
168
|
+
{ name: 'Sort-Order', value: pageParams?.sortOrder },
|
|
169
|
+
];
|
|
170
|
+
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
137
171
|
return this.process.read({
|
|
138
|
-
tags:
|
|
172
|
+
tags: prunedTags,
|
|
139
173
|
});
|
|
140
174
|
}
|
|
141
175
|
async getCurrentEpoch() {
|
|
@@ -144,7 +178,12 @@ class IOReadable {
|
|
|
144
178
|
{ name: 'Action', value: 'Epoch' },
|
|
145
179
|
{
|
|
146
180
|
name: 'Timestamp',
|
|
147
|
-
value: (await this.arweave.blocks
|
|
181
|
+
value: (await this.arweave.blocks
|
|
182
|
+
.getCurrent()
|
|
183
|
+
.then((block) => {
|
|
184
|
+
return { timestamp: block.timestamp * 1000 };
|
|
185
|
+
})
|
|
186
|
+
.catch(() => {
|
|
148
187
|
return { timestamp: Date.now() }; // fallback to current time
|
|
149
188
|
})).timestamp.toString(),
|
|
150
189
|
},
|
|
@@ -157,7 +196,12 @@ class IOReadable {
|
|
|
157
196
|
{
|
|
158
197
|
name: 'Timestamp',
|
|
159
198
|
value: epoch?.timestamp?.toString() ??
|
|
160
|
-
(await this.arweave.blocks
|
|
199
|
+
(await this.arweave.blocks
|
|
200
|
+
.getCurrent()
|
|
201
|
+
.then((block) => {
|
|
202
|
+
return { timestamp: block.timestamp * 1000 };
|
|
203
|
+
})
|
|
204
|
+
.catch(() => {
|
|
161
205
|
return { timestamp: Date.now() }; // fallback to current time
|
|
162
206
|
})).timestamp.toString(),
|
|
163
207
|
},
|
|
@@ -177,7 +221,12 @@ class IOReadable {
|
|
|
177
221
|
{
|
|
178
222
|
name: 'Timestamp',
|
|
179
223
|
value: epoch?.timestamp?.toString() ??
|
|
180
|
-
(await this.arweave.blocks
|
|
224
|
+
(await this.arweave.blocks
|
|
225
|
+
.getCurrent()
|
|
226
|
+
.then((block) => {
|
|
227
|
+
return { timestamp: block.timestamp * 1000 };
|
|
228
|
+
})
|
|
229
|
+
.catch(() => {
|
|
181
230
|
return { timestamp: Date.now() }; // fallback to current time
|
|
182
231
|
})).timestamp.toString(),
|
|
183
232
|
},
|
|
@@ -197,7 +246,12 @@ class IOReadable {
|
|
|
197
246
|
{
|
|
198
247
|
name: 'Timestamp',
|
|
199
248
|
value: epoch?.timestamp?.toString() ??
|
|
200
|
-
(await this.arweave.blocks
|
|
249
|
+
(await this.arweave.blocks
|
|
250
|
+
.getCurrent()
|
|
251
|
+
.then((block) => {
|
|
252
|
+
return { timestamp: block.timestamp * 1000 };
|
|
253
|
+
})
|
|
254
|
+
.catch(() => {
|
|
201
255
|
return { timestamp: `${Date.now()}` }; // fallback to current time
|
|
202
256
|
})).timestamp.toString(),
|
|
203
257
|
},
|
|
@@ -217,7 +271,12 @@ class IOReadable {
|
|
|
217
271
|
{
|
|
218
272
|
name: 'Timestamp',
|
|
219
273
|
value: epoch?.timestamp?.toString() ??
|
|
220
|
-
(await this.arweave.blocks
|
|
274
|
+
(await this.arweave.blocks
|
|
275
|
+
.getCurrent()
|
|
276
|
+
.then((block) => {
|
|
277
|
+
return { timestamp: block.timestamp * 1000 };
|
|
278
|
+
})
|
|
279
|
+
.catch(() => {
|
|
221
280
|
return { timestamp: Date.now() }; // fallback to current time
|
|
222
281
|
})).timestamp.toString(),
|
|
223
282
|
},
|
|
@@ -256,7 +315,12 @@ class IOReadable {
|
|
|
256
315
|
},
|
|
257
316
|
{
|
|
258
317
|
name: 'Timestamp',
|
|
259
|
-
value: (await this.arweave.blocks
|
|
318
|
+
value: (await this.arweave.blocks
|
|
319
|
+
.getCurrent()
|
|
320
|
+
.then((block) => {
|
|
321
|
+
return { timestamp: block.timestamp * 1000 };
|
|
322
|
+
})
|
|
323
|
+
.catch(() => {
|
|
260
324
|
return { timestamp: Date.now() }; // fallback to current time
|
|
261
325
|
})).timestamp.toString(),
|
|
262
326
|
},
|
package/lib/cjs/utils/index.js
CHANGED
|
@@ -32,6 +32,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
*/
|
|
33
33
|
__exportStar(require("./arweave.js"), exports);
|
|
34
34
|
__exportStar(require("./http-client.js"), exports);
|
|
35
|
-
__exportStar(require("./graphql/index.js"), exports);
|
|
36
35
|
__exportStar(require("./ao.js"), exports);
|
|
37
36
|
__exportStar(require("./json.js"), exports);
|
|
37
|
+
__exportStar(require("./processes.js"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ArNSEventEmitter = exports.getANTProcessesOwnedByWallet = void 0;
|
|
3
|
+
exports.fetchAllArNSRecords = exports.ArNSEventEmitter = exports.getANTProcessesOwnedByWallet = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
6
6
|
*
|
|
@@ -19,19 +19,20 @@ exports.ArNSEventEmitter = exports.getANTProcessesOwnedByWallet = void 0;
|
|
|
19
19
|
*/
|
|
20
20
|
const eventemitter3_1 = require("eventemitter3");
|
|
21
21
|
const plimit_lit_1 = require("plimit-lit");
|
|
22
|
-
const ant_js_1 = require("
|
|
23
|
-
const io_js_1 = require("
|
|
24
|
-
const constants_js_1 = require("
|
|
22
|
+
const ant_js_1 = require("../common/ant.js");
|
|
23
|
+
const io_js_1 = require("../common/io.js");
|
|
24
|
+
const constants_js_1 = require("../constants.js");
|
|
25
25
|
const getANTProcessesOwnedByWallet = async ({ address, contract = io_js_1.IO.init({
|
|
26
26
|
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
27
27
|
}), }) => {
|
|
28
28
|
const throttle = (0, plimit_lit_1.pLimit)(50);
|
|
29
29
|
// get the record names of the registry - TODO: this may need to be paginated
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const records = await (0, exports.fetchAllArNSRecords)({
|
|
31
|
+
contract: contract,
|
|
32
|
+
});
|
|
33
|
+
const uniqueContractProcessIds = Object.values(records)
|
|
33
34
|
.filter((record) => record.processId !== undefined)
|
|
34
|
-
.map((record) => record.processId)
|
|
35
|
+
.map((record) => record.processId);
|
|
35
36
|
// check the contract owner and controllers
|
|
36
37
|
const ownedOrControlledByWallet = await Promise.all(uniqueContractProcessIds.map(async (processId) => throttle(async () => {
|
|
37
38
|
const ant = ant_js_1.ANT.init({
|
|
@@ -80,10 +81,12 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
80
81
|
}
|
|
81
82
|
async fetchProcessesOwnedByWallet({ address }) {
|
|
82
83
|
const uniqueContractProcessIds = {};
|
|
83
|
-
await timeout(this.timeoutMs, this.contract
|
|
84
|
+
await timeout(this.timeoutMs, (0, exports.fetchAllArNSRecords)({ contract: this.contract }))
|
|
85
|
+
.catch((e) => {
|
|
84
86
|
this.emit('error', `Error getting ArNS records: ${e}`);
|
|
85
87
|
return {};
|
|
86
|
-
})
|
|
88
|
+
})
|
|
89
|
+
.then((records) => {
|
|
87
90
|
if (!records)
|
|
88
91
|
return;
|
|
89
92
|
Object.entries(records).forEach(([name, record]) => {
|
|
@@ -125,3 +128,30 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
130
|
exports.ArNSEventEmitter = ArNSEventEmitter;
|
|
131
|
+
const fetchAllArNSRecords = async ({ contract = io_js_1.IO.init({
|
|
132
|
+
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
133
|
+
}), logger, }) => {
|
|
134
|
+
let cursor;
|
|
135
|
+
const records = {};
|
|
136
|
+
do {
|
|
137
|
+
const pageResult = await contract
|
|
138
|
+
.getArNSRecords({ cursor })
|
|
139
|
+
.catch((e) => {
|
|
140
|
+
logger?.error(`Error getting ArNS records`, {
|
|
141
|
+
message: e?.message,
|
|
142
|
+
stack: e?.stack,
|
|
143
|
+
});
|
|
144
|
+
return undefined;
|
|
145
|
+
});
|
|
146
|
+
if (!pageResult) {
|
|
147
|
+
return {};
|
|
148
|
+
}
|
|
149
|
+
pageResult.items.forEach((record) => {
|
|
150
|
+
const { name, ...recordDetails } = record;
|
|
151
|
+
records[name] = recordDetails;
|
|
152
|
+
});
|
|
153
|
+
cursor = pageResult.nextCursor;
|
|
154
|
+
} while (cursor !== undefined);
|
|
155
|
+
return records;
|
|
156
|
+
};
|
|
157
|
+
exports.fetchAllArNSRecords = fetchAllArNSRecords;
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/common/io.js
CHANGED
|
@@ -48,7 +48,12 @@ export class IOReadable {
|
|
|
48
48
|
{
|
|
49
49
|
name: 'Timestamp',
|
|
50
50
|
value: params?.timestamp?.toString() ??
|
|
51
|
-
(await this.arweave.blocks
|
|
51
|
+
(await this.arweave.blocks
|
|
52
|
+
.getCurrent()
|
|
53
|
+
.then((block) => {
|
|
54
|
+
return { timestamp: block.timestamp * 1000 };
|
|
55
|
+
})
|
|
56
|
+
.catch(() => {
|
|
52
57
|
return { timestamp: Date.now() }; // fallback to current time
|
|
53
58
|
})).timestamp.toString(),
|
|
54
59
|
},
|
|
@@ -68,7 +73,12 @@ export class IOReadable {
|
|
|
68
73
|
{
|
|
69
74
|
name: 'Timestamp',
|
|
70
75
|
value: epoch?.timestamp?.toString() ??
|
|
71
|
-
(await this.arweave.blocks
|
|
76
|
+
(await this.arweave.blocks
|
|
77
|
+
.getCurrent()
|
|
78
|
+
.then((block) => {
|
|
79
|
+
return { timestamp: block.timestamp * 1000 };
|
|
80
|
+
})
|
|
81
|
+
.catch(() => {
|
|
72
82
|
return { timestamp: Date.now() }; // fallback to current time
|
|
73
83
|
})).timestamp.toString(),
|
|
74
84
|
},
|
|
@@ -90,9 +100,17 @@ export class IOReadable {
|
|
|
90
100
|
],
|
|
91
101
|
});
|
|
92
102
|
}
|
|
93
|
-
async getArNSRecords() {
|
|
103
|
+
async getArNSRecords(pageParams) {
|
|
104
|
+
const allTags = [
|
|
105
|
+
{ name: 'Action', value: 'Paginated-Records' },
|
|
106
|
+
{ name: 'Cursor', value: pageParams?.cursor?.toString() },
|
|
107
|
+
{ name: 'Limit', value: pageParams?.limit?.toString() },
|
|
108
|
+
{ name: 'Sort-By', value: pageParams?.sortBy },
|
|
109
|
+
{ name: 'Sort-Order', value: pageParams?.sortOrder },
|
|
110
|
+
];
|
|
111
|
+
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
94
112
|
return this.process.read({
|
|
95
|
-
tags:
|
|
113
|
+
tags: prunedTags,
|
|
96
114
|
});
|
|
97
115
|
}
|
|
98
116
|
async getArNSReservedNames() {
|
|
@@ -116,9 +134,17 @@ export class IOReadable {
|
|
|
116
134
|
],
|
|
117
135
|
});
|
|
118
136
|
}
|
|
119
|
-
async getBalances() {
|
|
137
|
+
async getBalances(pageParams) {
|
|
138
|
+
const allTags = [
|
|
139
|
+
{ name: 'Action', value: 'Paginated-Balances' },
|
|
140
|
+
{ name: 'Cursor', value: pageParams?.cursor?.toString() },
|
|
141
|
+
{ name: 'Limit', value: pageParams?.limit?.toString() },
|
|
142
|
+
{ name: 'Sort-By', value: pageParams?.sortBy },
|
|
143
|
+
{ name: 'Sort-Order', value: pageParams?.sortOrder },
|
|
144
|
+
];
|
|
145
|
+
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
120
146
|
return this.process.read({
|
|
121
|
-
tags:
|
|
147
|
+
tags: prunedTags,
|
|
122
148
|
});
|
|
123
149
|
}
|
|
124
150
|
async getGateway({ address, }) {
|
|
@@ -129,9 +155,17 @@ export class IOReadable {
|
|
|
129
155
|
],
|
|
130
156
|
});
|
|
131
157
|
}
|
|
132
|
-
async getGateways() {
|
|
158
|
+
async getGateways(pageParams) {
|
|
159
|
+
const allTags = [
|
|
160
|
+
{ name: 'Action', value: 'Paginated-Gateways' },
|
|
161
|
+
{ name: 'Cursor', value: pageParams?.cursor?.toString() },
|
|
162
|
+
{ name: 'Limit', value: pageParams?.limit?.toString() },
|
|
163
|
+
{ name: 'Sort-By', value: pageParams?.sortBy },
|
|
164
|
+
{ name: 'Sort-Order', value: pageParams?.sortOrder },
|
|
165
|
+
];
|
|
166
|
+
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
133
167
|
return this.process.read({
|
|
134
|
-
tags:
|
|
168
|
+
tags: prunedTags,
|
|
135
169
|
});
|
|
136
170
|
}
|
|
137
171
|
async getCurrentEpoch() {
|
|
@@ -140,7 +174,12 @@ export class IOReadable {
|
|
|
140
174
|
{ name: 'Action', value: 'Epoch' },
|
|
141
175
|
{
|
|
142
176
|
name: 'Timestamp',
|
|
143
|
-
value: (await this.arweave.blocks
|
|
177
|
+
value: (await this.arweave.blocks
|
|
178
|
+
.getCurrent()
|
|
179
|
+
.then((block) => {
|
|
180
|
+
return { timestamp: block.timestamp * 1000 };
|
|
181
|
+
})
|
|
182
|
+
.catch(() => {
|
|
144
183
|
return { timestamp: Date.now() }; // fallback to current time
|
|
145
184
|
})).timestamp.toString(),
|
|
146
185
|
},
|
|
@@ -153,7 +192,12 @@ export class IOReadable {
|
|
|
153
192
|
{
|
|
154
193
|
name: 'Timestamp',
|
|
155
194
|
value: epoch?.timestamp?.toString() ??
|
|
156
|
-
(await this.arweave.blocks
|
|
195
|
+
(await this.arweave.blocks
|
|
196
|
+
.getCurrent()
|
|
197
|
+
.then((block) => {
|
|
198
|
+
return { timestamp: block.timestamp * 1000 };
|
|
199
|
+
})
|
|
200
|
+
.catch(() => {
|
|
157
201
|
return { timestamp: Date.now() }; // fallback to current time
|
|
158
202
|
})).timestamp.toString(),
|
|
159
203
|
},
|
|
@@ -173,7 +217,12 @@ export class IOReadable {
|
|
|
173
217
|
{
|
|
174
218
|
name: 'Timestamp',
|
|
175
219
|
value: epoch?.timestamp?.toString() ??
|
|
176
|
-
(await this.arweave.blocks
|
|
220
|
+
(await this.arweave.blocks
|
|
221
|
+
.getCurrent()
|
|
222
|
+
.then((block) => {
|
|
223
|
+
return { timestamp: block.timestamp * 1000 };
|
|
224
|
+
})
|
|
225
|
+
.catch(() => {
|
|
177
226
|
return { timestamp: Date.now() }; // fallback to current time
|
|
178
227
|
})).timestamp.toString(),
|
|
179
228
|
},
|
|
@@ -193,7 +242,12 @@ export class IOReadable {
|
|
|
193
242
|
{
|
|
194
243
|
name: 'Timestamp',
|
|
195
244
|
value: epoch?.timestamp?.toString() ??
|
|
196
|
-
(await this.arweave.blocks
|
|
245
|
+
(await this.arweave.blocks
|
|
246
|
+
.getCurrent()
|
|
247
|
+
.then((block) => {
|
|
248
|
+
return { timestamp: block.timestamp * 1000 };
|
|
249
|
+
})
|
|
250
|
+
.catch(() => {
|
|
197
251
|
return { timestamp: `${Date.now()}` }; // fallback to current time
|
|
198
252
|
})).timestamp.toString(),
|
|
199
253
|
},
|
|
@@ -213,7 +267,12 @@ export class IOReadable {
|
|
|
213
267
|
{
|
|
214
268
|
name: 'Timestamp',
|
|
215
269
|
value: epoch?.timestamp?.toString() ??
|
|
216
|
-
(await this.arweave.blocks
|
|
270
|
+
(await this.arweave.blocks
|
|
271
|
+
.getCurrent()
|
|
272
|
+
.then((block) => {
|
|
273
|
+
return { timestamp: block.timestamp * 1000 };
|
|
274
|
+
})
|
|
275
|
+
.catch(() => {
|
|
217
276
|
return { timestamp: Date.now() }; // fallback to current time
|
|
218
277
|
})).timestamp.toString(),
|
|
219
278
|
},
|
|
@@ -252,7 +311,12 @@ export class IOReadable {
|
|
|
252
311
|
},
|
|
253
312
|
{
|
|
254
313
|
name: 'Timestamp',
|
|
255
|
-
value: (await this.arweave.blocks
|
|
314
|
+
value: (await this.arweave.blocks
|
|
315
|
+
.getCurrent()
|
|
316
|
+
.then((block) => {
|
|
317
|
+
return { timestamp: block.timestamp * 1000 };
|
|
318
|
+
})
|
|
319
|
+
.catch(() => {
|
|
256
320
|
return { timestamp: Date.now() }; // fallback to current time
|
|
257
321
|
})).timestamp.toString(),
|
|
258
322
|
},
|
package/lib/esm/utils/index.js
CHANGED
|
@@ -16,19 +16,20 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { EventEmitter } from 'eventemitter3';
|
|
18
18
|
import { pLimit } from 'plimit-lit';
|
|
19
|
-
import { ANT } from '
|
|
20
|
-
import { IO } from '
|
|
21
|
-
import { IO_TESTNET_PROCESS_ID } from '
|
|
19
|
+
import { ANT } from '../common/ant.js';
|
|
20
|
+
import { IO } from '../common/io.js';
|
|
21
|
+
import { IO_TESTNET_PROCESS_ID } from '../constants.js';
|
|
22
22
|
export const getANTProcessesOwnedByWallet = async ({ address, contract = IO.init({
|
|
23
23
|
processId: IO_TESTNET_PROCESS_ID,
|
|
24
24
|
}), }) => {
|
|
25
25
|
const throttle = pLimit(50);
|
|
26
26
|
// get the record names of the registry - TODO: this may need to be paginated
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const records = await fetchAllArNSRecords({
|
|
28
|
+
contract: contract,
|
|
29
|
+
});
|
|
30
|
+
const uniqueContractProcessIds = Object.values(records)
|
|
30
31
|
.filter((record) => record.processId !== undefined)
|
|
31
|
-
.map((record) => record.processId)
|
|
32
|
+
.map((record) => record.processId);
|
|
32
33
|
// check the contract owner and controllers
|
|
33
34
|
const ownedOrControlledByWallet = await Promise.all(uniqueContractProcessIds.map(async (processId) => throttle(async () => {
|
|
34
35
|
const ant = ANT.init({
|
|
@@ -76,10 +77,12 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
76
77
|
}
|
|
77
78
|
async fetchProcessesOwnedByWallet({ address }) {
|
|
78
79
|
const uniqueContractProcessIds = {};
|
|
79
|
-
await timeout(this.timeoutMs, this.contract
|
|
80
|
+
await timeout(this.timeoutMs, fetchAllArNSRecords({ contract: this.contract }))
|
|
81
|
+
.catch((e) => {
|
|
80
82
|
this.emit('error', `Error getting ArNS records: ${e}`);
|
|
81
83
|
return {};
|
|
82
|
-
})
|
|
84
|
+
})
|
|
85
|
+
.then((records) => {
|
|
83
86
|
if (!records)
|
|
84
87
|
return;
|
|
85
88
|
Object.entries(records).forEach(([name, record]) => {
|
|
@@ -120,3 +123,29 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
120
123
|
this.emit('end', uniqueContractProcessIds);
|
|
121
124
|
}
|
|
122
125
|
}
|
|
126
|
+
export const fetchAllArNSRecords = async ({ contract = IO.init({
|
|
127
|
+
processId: IO_TESTNET_PROCESS_ID,
|
|
128
|
+
}), logger, }) => {
|
|
129
|
+
let cursor;
|
|
130
|
+
const records = {};
|
|
131
|
+
do {
|
|
132
|
+
const pageResult = await contract
|
|
133
|
+
.getArNSRecords({ cursor })
|
|
134
|
+
.catch((e) => {
|
|
135
|
+
logger?.error(`Error getting ArNS records`, {
|
|
136
|
+
message: e?.message,
|
|
137
|
+
stack: e?.stack,
|
|
138
|
+
});
|
|
139
|
+
return undefined;
|
|
140
|
+
});
|
|
141
|
+
if (!pageResult) {
|
|
142
|
+
return {};
|
|
143
|
+
}
|
|
144
|
+
pageResult.items.forEach((record) => {
|
|
145
|
+
const { name, ...recordDetails } = record;
|
|
146
|
+
records[name] = recordDetails;
|
|
147
|
+
});
|
|
148
|
+
cursor = pageResult.nextCursor;
|
|
149
|
+
} while (cursor !== undefined);
|
|
150
|
+
return records;
|
|
151
|
+
};
|
package/lib/esm/version.js
CHANGED
|
@@ -17,30 +17,6 @@
|
|
|
17
17
|
import { ANTRecord, AoANTRead, AoANTState, AoANTWrite, AoMessageResult, ProcessConfiguration, WalletAddress, WithSigner } from '../types.js';
|
|
18
18
|
import { AOProcess } from './index.js';
|
|
19
19
|
export declare class ANT {
|
|
20
|
-
/**
|
|
21
|
-
* Initializes an ANT instance.
|
|
22
|
-
*
|
|
23
|
-
* There are two overloads for this function:
|
|
24
|
-
* 1. When a signer is provided in the configuration, it returns an instance of ANTWritable.
|
|
25
|
-
* 2. When a signer is NOT provided in the configuration, it returns an instance of ANTReadable.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @param {ContractConfiguration & WithSigner} config - The configuration object.
|
|
29
|
-
* If a signer is provided, it should be an object that implements the ContractSigner interface.
|
|
30
|
-
*
|
|
31
|
-
* @returns {ANTWritable | ANTReadable} - An instance of ANTWritable if a signer is provided, otherwise an instance of ANTReadable.
|
|
32
|
-
* @throws {Error} - Throws an error if the configuration is invalid.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* Overload 1: When signer is provided
|
|
36
|
-
* ```ts
|
|
37
|
-
* const writable = ANT.init({ signer: mySigner, contract: myContract });
|
|
38
|
-
*```
|
|
39
|
-
* Overload 2: When signer is not provided
|
|
40
|
-
* ```ts
|
|
41
|
-
* const readable = ANT.init({ contract: myContract });
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
20
|
static init(config: Required<ProcessConfiguration> & {
|
|
45
21
|
signer?: undefined;
|
|
46
22
|
}): AoANTRead;
|
package/lib/types/common/io.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import Arweave from 'arweave';
|
|
|
18
18
|
import { ArNSReservedNameData, EpochDistributionData, EpochObservations, WeightedObserver } from '../contract-state.js';
|
|
19
19
|
import { AoArNSNameData, AoEpochData, AoEpochSettings, AoGateway, AoIORead, AoIOWrite, EpochInput } from '../io.js';
|
|
20
20
|
import { mIOToken } from '../token.js';
|
|
21
|
-
import { AoMessageResult, ContractSigner, JoinNetworkParams, ProcessConfiguration, TransactionId, UpdateGatewaySettingsParams, WalletAddress, WithSigner, WriteOptions } from '../types.js';
|
|
21
|
+
import { AoArNSNameDataWithName, AoBalanceWithAddress, AoGatewayWithAddress, AoMessageResult, ContractSigner, JoinNetworkParams, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, UpdateGatewaySettingsParams, WalletAddress, WithSigner, WriteOptions } from '../types.js';
|
|
22
22
|
import { AOProcess } from './contracts/ao-process.js';
|
|
23
23
|
export declare class IO {
|
|
24
24
|
static init(): AoIORead;
|
|
@@ -54,7 +54,7 @@ export declare class IOReadable implements AoIORead {
|
|
|
54
54
|
getArNSRecord({ name, }: {
|
|
55
55
|
name: string;
|
|
56
56
|
}): Promise<AoArNSNameData | undefined>;
|
|
57
|
-
getArNSRecords(): Promise<
|
|
57
|
+
getArNSRecords(pageParams?: PaginationParams): Promise<PaginationResult<AoArNSNameDataWithName>>;
|
|
58
58
|
getArNSReservedNames(): Promise<Record<string, ArNSReservedNameData> | Record<string, never>>;
|
|
59
59
|
getArNSReservedName({ name, }: {
|
|
60
60
|
name: string;
|
|
@@ -62,11 +62,11 @@ export declare class IOReadable implements AoIORead {
|
|
|
62
62
|
getBalance({ address }: {
|
|
63
63
|
address: WalletAddress;
|
|
64
64
|
}): Promise<number>;
|
|
65
|
-
getBalances(): Promise<
|
|
65
|
+
getBalances(pageParams?: PaginationParams): Promise<PaginationResult<AoBalanceWithAddress>>;
|
|
66
66
|
getGateway({ address, }: {
|
|
67
67
|
address: WalletAddress;
|
|
68
68
|
}): Promise<AoGateway | undefined>;
|
|
69
|
-
getGateways(): Promise<
|
|
69
|
+
getGateways(pageParams?: PaginationParams): Promise<PaginationResult<AoGatewayWithAddress>>;
|
|
70
70
|
getCurrentEpoch(): Promise<AoEpochData>;
|
|
71
71
|
getPrescribedObservers(epoch?: EpochInput): Promise<WeightedObserver[]>;
|
|
72
72
|
getPrescribedNames(epoch?: EpochInput): Promise<string[]>;
|
package/lib/types/io.d.ts
CHANGED
|
@@ -25,6 +25,20 @@ export declare function isProcessIdConfiguration(config: object): config is {
|
|
|
25
25
|
processId: string;
|
|
26
26
|
};
|
|
27
27
|
export declare function isLeasedArNSRecord(record: AoArNSNameData): record is AoArNSLeaseData;
|
|
28
|
+
export type PaginationParams = {
|
|
29
|
+
cursor?: string;
|
|
30
|
+
limit?: number;
|
|
31
|
+
sortBy?: string;
|
|
32
|
+
sortOrder?: 'asc' | 'desc';
|
|
33
|
+
};
|
|
34
|
+
export type PaginationResult<T> = {
|
|
35
|
+
items: T[];
|
|
36
|
+
nextCursor: string | undefined;
|
|
37
|
+
totalItems: number;
|
|
38
|
+
sortBy: keyof T;
|
|
39
|
+
sortOrder: 'asc' | 'desc';
|
|
40
|
+
hasMore: boolean;
|
|
41
|
+
};
|
|
28
42
|
export type ProcessConfiguration = {
|
|
29
43
|
process?: AOProcess;
|
|
30
44
|
} | {
|
|
@@ -66,15 +80,15 @@ export interface AoIORead {
|
|
|
66
80
|
getGateway({ address, }: {
|
|
67
81
|
address: WalletAddress;
|
|
68
82
|
}): Promise<AoGateway | undefined>;
|
|
69
|
-
getGateways(): Promise<
|
|
83
|
+
getGateways(params?: PaginationParams): Promise<PaginationResult<AoGatewayWithAddress>>;
|
|
70
84
|
getBalance(params: {
|
|
71
85
|
address: WalletAddress;
|
|
72
86
|
}): Promise<number>;
|
|
73
|
-
getBalances(): Promise<
|
|
87
|
+
getBalances(params?: PaginationParams): Promise<PaginationResult<AoBalanceWithAddress>>;
|
|
74
88
|
getArNSRecord({ name, }: {
|
|
75
89
|
name: string;
|
|
76
90
|
}): Promise<AoArNSNameData | undefined>;
|
|
77
|
-
getArNSRecords(): Promise<
|
|
91
|
+
getArNSRecords(params?: PaginationParams): Promise<PaginationResult<AoArNSNameDataWithName>>;
|
|
78
92
|
getArNSReservedNames(): Promise<Record<string, AoArNSReservedNameData> | Record<string, never>>;
|
|
79
93
|
getArNSReservedName({ name, }: {
|
|
80
94
|
name: string;
|
|
@@ -201,6 +215,9 @@ export interface AoIOState {
|
|
|
201
215
|
export type AoEpochIndex = number;
|
|
202
216
|
export type AoArNSReservedNameData = ArNSReservedNameData;
|
|
203
217
|
export type AoArNSNameData = AoArNSPermabuyData | AoArNSLeaseData;
|
|
218
|
+
export type AoArNSNameDataWithName = AoArNSNameData & {
|
|
219
|
+
name: string;
|
|
220
|
+
};
|
|
204
221
|
export type AoArNSBaseNameData = {
|
|
205
222
|
processId: ProcessId;
|
|
206
223
|
startTimestamp: number;
|
|
@@ -259,6 +276,13 @@ export type AoGateway = {
|
|
|
259
276
|
operatorStake: number;
|
|
260
277
|
status: 'joined' | 'leaving';
|
|
261
278
|
};
|
|
279
|
+
export type AoBalanceWithAddress = {
|
|
280
|
+
address: WalletAddress;
|
|
281
|
+
balance: number;
|
|
282
|
+
};
|
|
283
|
+
export type AoGatewayWithAddress = AoGateway & {
|
|
284
|
+
gatewayAddress: WalletAddress;
|
|
285
|
+
};
|
|
262
286
|
export type AoANTState = {
|
|
263
287
|
Name: string;
|
|
264
288
|
Ticker: string;
|