@ensdomains/ensjs 3.0.0-alpha.11 → 3.0.0-alpha.12
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/dist/cjs/functions/getHistory.d.ts +0 -30
- package/dist/cjs/functions/getHistory.js +3 -99
- package/dist/cjs/functions/getName.d.ts +2 -2
- package/dist/cjs/functions/getName.js +1 -1
- package/dist/cjs/index.d.ts +2 -32
- package/dist/cjs/index.js +0 -2
- package/dist/esm/functions/getHistory.d.ts +0 -30
- package/dist/esm/functions/getHistory.js +2 -96
- package/dist/esm/functions/getName.d.ts +2 -2
- package/dist/esm/functions/getName.js +1 -1
- package/dist/esm/index.d.ts +2 -32
- package/dist/esm/index.js +0 -2
- package/package.json +2 -2
- package/src/functions/getHistory.test.ts +0 -84
- package/src/functions/getHistory.ts +2 -127
- package/src/functions/getName.test.ts +1 -1
- package/src/functions/getName.ts +1 -1
- package/src/index.ts +1 -21
- package/src/tests/setup.ts +0 -1
|
@@ -22,33 +22,3 @@ export declare function getHistory({ gqlInstance }: ENSArgs<'gqlInstance'>, name
|
|
|
22
22
|
data: Record<string, any>;
|
|
23
23
|
}[];
|
|
24
24
|
} | undefined>;
|
|
25
|
-
export declare function getHistoryWithDetail({ contracts, gqlInstance, provider, }: ENSArgs<'contracts' | 'gqlInstance' | 'provider'>, name: string): Promise<{
|
|
26
|
-
domain: {
|
|
27
|
-
type: any;
|
|
28
|
-
blockNumber: any;
|
|
29
|
-
transactionHash: any;
|
|
30
|
-
id: any;
|
|
31
|
-
data: Record<string, any>;
|
|
32
|
-
}[];
|
|
33
|
-
registration: {
|
|
34
|
-
type: any;
|
|
35
|
-
blockNumber: any;
|
|
36
|
-
transactionHash: any;
|
|
37
|
-
id: any;
|
|
38
|
-
data: Record<string, any>;
|
|
39
|
-
}[];
|
|
40
|
-
resolver: {
|
|
41
|
-
type: any;
|
|
42
|
-
blockNumber: any;
|
|
43
|
-
transactionHash: any;
|
|
44
|
-
id: any;
|
|
45
|
-
data: Record<string, any>;
|
|
46
|
-
}[];
|
|
47
|
-
} | undefined>;
|
|
48
|
-
export declare function getHistoryDetailForTransactionHash({ contracts, provider }: ENSArgs<'contracts' | 'provider'>, hash: string, indexInTransaction?: number): Promise<({
|
|
49
|
-
key: any;
|
|
50
|
-
value: any;
|
|
51
|
-
} | undefined)[] | {
|
|
52
|
-
key: any;
|
|
53
|
-
value: any;
|
|
54
|
-
} | undefined>;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getHistory = void 0;
|
|
4
4
|
const address_encoder_1 = require("@ensdomains/address-encoder");
|
|
5
5
|
const ethers_1 = require("ethers");
|
|
6
6
|
const contentHash_1 = require("../utils/contentHash");
|
|
7
|
-
const makeHashIndexes_1 = require("../utils/makeHashIndexes");
|
|
8
7
|
const eventFormat = {
|
|
9
8
|
Domain: {
|
|
10
9
|
NewOwner: (args) => ({ owner: args.owner.id }),
|
|
@@ -46,7 +45,7 @@ const eventFormat = {
|
|
|
46
45
|
NameChanged: (args) => ({ name: args.name }),
|
|
47
46
|
AbiChanged: (args) => ({ contentType: args.contentType }),
|
|
48
47
|
PubkeyChanged: (args) => ({ x: args.x, y: args.y }),
|
|
49
|
-
TextChanged: (args) => ({ key: args.key }),
|
|
48
|
+
TextChanged: (args) => ({ key: args.key, value: args.value }),
|
|
50
49
|
ContenthashChanged: (args) => ({ hash: (0, contentHash_1.decodeContenthash)(args.hash) }),
|
|
51
50
|
InterfaceChanged: (args) => ({
|
|
52
51
|
interfaceId: args.interfaceId,
|
|
@@ -66,31 +65,6 @@ const mapEvents = (eventArray, type) => eventArray.map((event) => ({
|
|
|
66
65
|
id: event.id,
|
|
67
66
|
data: eventFormat[type][event.__typename](event),
|
|
68
67
|
}));
|
|
69
|
-
const mapResultDetailDecode = (publicResolver) => (result) => {
|
|
70
|
-
const hashIndexes = (0, makeHashIndexes_1.makeOtherIndexes)(result.input, '10f13a8c');
|
|
71
|
-
const abiLengths = hashIndexes.map((x) => ({
|
|
72
|
-
index: x,
|
|
73
|
-
length: x === 0
|
|
74
|
-
? ethers_1.ethers.utils.hexDataLength(result.input)
|
|
75
|
-
: parseInt(ethers_1.ethers.utils.hexDataSlice(result.input, x - 32, x), 16),
|
|
76
|
-
}));
|
|
77
|
-
const ABIs = abiLengths.map(({ index, length }) => ethers_1.ethers.utils.hexDataSlice(result.input, index, index + length));
|
|
78
|
-
return ABIs.map((abi) => {
|
|
79
|
-
try {
|
|
80
|
-
return publicResolver.interface.decodeFunctionData('setText(bytes32,string,string)', abi);
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
const expandDecode = (prev, curr) => {
|
|
88
|
-
if (!curr)
|
|
89
|
-
return [...prev, { value: null }];
|
|
90
|
-
if (!curr.length)
|
|
91
|
-
return [...prev, curr];
|
|
92
|
-
return [...prev, ...curr];
|
|
93
|
-
};
|
|
94
68
|
async function getHistory({ gqlInstance }, name) {
|
|
95
69
|
const client = gqlInstance.client;
|
|
96
70
|
const query = gqlInstance.gql `
|
|
@@ -171,6 +145,7 @@ async function getHistory({ gqlInstance }, name) {
|
|
|
171
145
|
}
|
|
172
146
|
...on TextChanged {
|
|
173
147
|
key
|
|
148
|
+
value
|
|
174
149
|
}
|
|
175
150
|
...on ContenthashChanged {
|
|
176
151
|
hash
|
|
@@ -206,74 +181,3 @@ async function getHistory({ gqlInstance }, name) {
|
|
|
206
181
|
};
|
|
207
182
|
}
|
|
208
183
|
exports.getHistory = getHistory;
|
|
209
|
-
async function getHistoryWithDetail({ contracts, gqlInstance, provider, }, name) {
|
|
210
|
-
const historyRes = await getHistory({ gqlInstance }, name);
|
|
211
|
-
if (!historyRes)
|
|
212
|
-
return;
|
|
213
|
-
const { domain, registration, resolver: resolverHistory } = historyRes;
|
|
214
|
-
const textEvents = resolverHistory.filter((event) => event.type === 'TextChanged');
|
|
215
|
-
const transactions = textEvents.reduce((prev, curr) => {
|
|
216
|
-
if (prev.includes(curr.transactionHash)) {
|
|
217
|
-
return prev;
|
|
218
|
-
}
|
|
219
|
-
return [...prev, curr.transactionHash];
|
|
220
|
-
}, []);
|
|
221
|
-
const publicResolver = await contracts?.getPublicResolver();
|
|
222
|
-
const fetchResult = (await ethers_1.ethers.utils.fetchJson(provider.connection, JSON.stringify(transactions.map((tx, i) => ({
|
|
223
|
-
jsonrpc: '2.0',
|
|
224
|
-
id: i,
|
|
225
|
-
method: 'eth_getTransactionByHash',
|
|
226
|
-
params: [tx],
|
|
227
|
-
})))))
|
|
228
|
-
.map((result) => result.result)
|
|
229
|
-
.map(mapResultDetailDecode(publicResolver))
|
|
230
|
-
.reduce(expandDecode, []);
|
|
231
|
-
const detailedResolverHistory = resolverHistory.map((event) => {
|
|
232
|
-
if (event.type !== 'TextChanged')
|
|
233
|
-
return event;
|
|
234
|
-
const { id } = event;
|
|
235
|
-
const matchedTextInx = textEvents.findIndex((x) => x.id === id);
|
|
236
|
-
return {
|
|
237
|
-
...event,
|
|
238
|
-
data: {
|
|
239
|
-
...event.data,
|
|
240
|
-
value: fetchResult[matchedTextInx] && fetchResult[matchedTextInx].value,
|
|
241
|
-
},
|
|
242
|
-
};
|
|
243
|
-
});
|
|
244
|
-
return {
|
|
245
|
-
domain,
|
|
246
|
-
registration,
|
|
247
|
-
resolver: detailedResolverHistory,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
exports.getHistoryWithDetail = getHistoryWithDetail;
|
|
251
|
-
async function getHistoryDetailForTransactionHash({ contracts, provider }, hash, indexInTransaction) {
|
|
252
|
-
const publicResolver = await contracts?.getPublicResolver();
|
|
253
|
-
const transaction = await provider.getTransaction(hash);
|
|
254
|
-
if (!transaction)
|
|
255
|
-
return;
|
|
256
|
-
const result = mapResultDetailDecode(publicResolver)({
|
|
257
|
-
input: transaction.data,
|
|
258
|
-
});
|
|
259
|
-
if (!result || !result.length)
|
|
260
|
-
return;
|
|
261
|
-
if (typeof indexInTransaction === 'number') {
|
|
262
|
-
if (indexInTransaction + 1 > result.length)
|
|
263
|
-
return;
|
|
264
|
-
const resultItem = result[indexInTransaction];
|
|
265
|
-
if (!resultItem ||
|
|
266
|
-
!resultItem.key ||
|
|
267
|
-
(!resultItem.value && resultItem.value !== ''))
|
|
268
|
-
return;
|
|
269
|
-
return { key: resultItem.key, value: resultItem.value };
|
|
270
|
-
}
|
|
271
|
-
return result.map((item) => {
|
|
272
|
-
if (!item.key)
|
|
273
|
-
return;
|
|
274
|
-
if (!item.value && item.value !== '')
|
|
275
|
-
return { key: item.key, value: null };
|
|
276
|
-
return { key: item.key, value: item.value };
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
exports.getHistoryDetailForTransactionHash = getHistoryDetailForTransactionHash;
|
|
@@ -10,8 +10,8 @@ declare const _default: {
|
|
|
10
10
|
reverseResolverAddress: any;
|
|
11
11
|
resolverAddress: any;
|
|
12
12
|
} | {
|
|
13
|
-
name:
|
|
14
|
-
match
|
|
13
|
+
name: undefined;
|
|
14
|
+
match?: undefined;
|
|
15
15
|
reverseResolverAddress?: undefined;
|
|
16
16
|
resolverAddress?: undefined;
|
|
17
17
|
} | undefined>;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -206,8 +206,8 @@ export declare class ENS {
|
|
|
206
206
|
reverseResolverAddress: any;
|
|
207
207
|
resolverAddress: any;
|
|
208
208
|
} | {
|
|
209
|
-
name:
|
|
210
|
-
match
|
|
209
|
+
name: undefined;
|
|
210
|
+
match?: undefined;
|
|
211
211
|
reverseResolverAddress?: undefined;
|
|
212
212
|
resolverAddress?: undefined;
|
|
213
213
|
} | undefined>;
|
|
@@ -255,36 +255,6 @@ export declare class ENS {
|
|
|
255
255
|
data: Record<string, any>;
|
|
256
256
|
}[];
|
|
257
257
|
} | undefined>;
|
|
258
|
-
getHistoryWithDetail: (name: string) => Promise<{
|
|
259
|
-
domain: {
|
|
260
|
-
type: any;
|
|
261
|
-
blockNumber: any;
|
|
262
|
-
transactionHash: any;
|
|
263
|
-
id: any;
|
|
264
|
-
data: Record<string, any>;
|
|
265
|
-
}[];
|
|
266
|
-
registration: {
|
|
267
|
-
type: any;
|
|
268
|
-
blockNumber: any;
|
|
269
|
-
transactionHash: any;
|
|
270
|
-
id: any;
|
|
271
|
-
data: Record<string, any>;
|
|
272
|
-
}[];
|
|
273
|
-
resolver: {
|
|
274
|
-
type: any;
|
|
275
|
-
blockNumber: any;
|
|
276
|
-
transactionHash: any;
|
|
277
|
-
id: any;
|
|
278
|
-
data: Record<string, any>;
|
|
279
|
-
}[];
|
|
280
|
-
} | undefined>;
|
|
281
|
-
getHistoryDetailForTransactionHash: (hash: string, indexInTransaction?: number | undefined) => Promise<({
|
|
282
|
-
key: any;
|
|
283
|
-
value: any;
|
|
284
|
-
} | undefined)[] | {
|
|
285
|
-
key: any;
|
|
286
|
-
value: any;
|
|
287
|
-
} | undefined>;
|
|
288
258
|
getContentHash: GeneratedRawFunction<{
|
|
289
259
|
raw: ({ contracts, universalWrapper }: ENSArgs<"contracts" | "universalWrapper">, name: string) => Promise<{
|
|
290
260
|
to: string;
|
package/dist/cjs/index.js
CHANGED
|
@@ -205,8 +205,6 @@ class ENS {
|
|
|
205
205
|
'contracts',
|
|
206
206
|
]);
|
|
207
207
|
getHistory = this.generateFunction('getHistory', ['gqlInstance'], 'getHistory');
|
|
208
|
-
getHistoryWithDetail = this.generateFunction('getHistory', ['contracts', 'gqlInstance', 'provider'], 'getHistoryWithDetail');
|
|
209
|
-
getHistoryDetailForTransactionHash = this.generateFunction('getHistory', ['contracts', 'provider'], 'getHistoryDetailForTransactionHash');
|
|
210
208
|
getContentHash = this.generateRawFunction('initialGetters', ['contracts', 'universalWrapper'], 'getContentHash');
|
|
211
209
|
_getContentHash = this.generateRawFunction('initialGetters', ['contracts'], '_getContentHash');
|
|
212
210
|
getAddr = this.generateRawFunction('initialGetters', ['contracts', 'universalWrapper'], 'getAddr');
|
|
@@ -22,33 +22,3 @@ export declare function getHistory({ gqlInstance }: ENSArgs<'gqlInstance'>, name
|
|
|
22
22
|
data: Record<string, any>;
|
|
23
23
|
}[];
|
|
24
24
|
} | undefined>;
|
|
25
|
-
export declare function getHistoryWithDetail({ contracts, gqlInstance, provider, }: ENSArgs<'contracts' | 'gqlInstance' | 'provider'>, name: string): Promise<{
|
|
26
|
-
domain: {
|
|
27
|
-
type: any;
|
|
28
|
-
blockNumber: any;
|
|
29
|
-
transactionHash: any;
|
|
30
|
-
id: any;
|
|
31
|
-
data: Record<string, any>;
|
|
32
|
-
}[];
|
|
33
|
-
registration: {
|
|
34
|
-
type: any;
|
|
35
|
-
blockNumber: any;
|
|
36
|
-
transactionHash: any;
|
|
37
|
-
id: any;
|
|
38
|
-
data: Record<string, any>;
|
|
39
|
-
}[];
|
|
40
|
-
resolver: {
|
|
41
|
-
type: any;
|
|
42
|
-
blockNumber: any;
|
|
43
|
-
transactionHash: any;
|
|
44
|
-
id: any;
|
|
45
|
-
data: Record<string, any>;
|
|
46
|
-
}[];
|
|
47
|
-
} | undefined>;
|
|
48
|
-
export declare function getHistoryDetailForTransactionHash({ contracts, provider }: ENSArgs<'contracts' | 'provider'>, hash: string, indexInTransaction?: number): Promise<({
|
|
49
|
-
key: any;
|
|
50
|
-
value: any;
|
|
51
|
-
} | undefined)[] | {
|
|
52
|
-
key: any;
|
|
53
|
-
value: any;
|
|
54
|
-
} | undefined>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { formatsByCoinType } from '@ensdomains/address-encoder';
|
|
2
2
|
import { ethers } from 'ethers';
|
|
3
3
|
import { decodeContenthash } from '../utils/contentHash';
|
|
4
|
-
import { makeOtherIndexes } from '../utils/makeHashIndexes';
|
|
5
4
|
const eventFormat = {
|
|
6
5
|
Domain: {
|
|
7
6
|
NewOwner: (args) => ({ owner: args.owner.id }),
|
|
@@ -43,7 +42,7 @@ const eventFormat = {
|
|
|
43
42
|
NameChanged: (args) => ({ name: args.name }),
|
|
44
43
|
AbiChanged: (args) => ({ contentType: args.contentType }),
|
|
45
44
|
PubkeyChanged: (args) => ({ x: args.x, y: args.y }),
|
|
46
|
-
TextChanged: (args) => ({ key: args.key }),
|
|
45
|
+
TextChanged: (args) => ({ key: args.key, value: args.value }),
|
|
47
46
|
ContenthashChanged: (args) => ({ hash: decodeContenthash(args.hash) }),
|
|
48
47
|
InterfaceChanged: (args) => ({
|
|
49
48
|
interfaceId: args.interfaceId,
|
|
@@ -63,31 +62,6 @@ const mapEvents = (eventArray, type) => eventArray.map((event) => ({
|
|
|
63
62
|
id: event.id,
|
|
64
63
|
data: eventFormat[type][event.__typename](event),
|
|
65
64
|
}));
|
|
66
|
-
const mapResultDetailDecode = (publicResolver) => (result) => {
|
|
67
|
-
const hashIndexes = makeOtherIndexes(result.input, '10f13a8c');
|
|
68
|
-
const abiLengths = hashIndexes.map((x) => ({
|
|
69
|
-
index: x,
|
|
70
|
-
length: x === 0
|
|
71
|
-
? ethers.utils.hexDataLength(result.input)
|
|
72
|
-
: parseInt(ethers.utils.hexDataSlice(result.input, x - 32, x), 16),
|
|
73
|
-
}));
|
|
74
|
-
const ABIs = abiLengths.map(({ index, length }) => ethers.utils.hexDataSlice(result.input, index, index + length));
|
|
75
|
-
return ABIs.map((abi) => {
|
|
76
|
-
try {
|
|
77
|
-
return publicResolver.interface.decodeFunctionData('setText(bytes32,string,string)', abi);
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
const expandDecode = (prev, curr) => {
|
|
85
|
-
if (!curr)
|
|
86
|
-
return [...prev, { value: null }];
|
|
87
|
-
if (!curr.length)
|
|
88
|
-
return [...prev, curr];
|
|
89
|
-
return [...prev, ...curr];
|
|
90
|
-
};
|
|
91
65
|
export async function getHistory({ gqlInstance }, name) {
|
|
92
66
|
const client = gqlInstance.client;
|
|
93
67
|
const query = gqlInstance.gql `
|
|
@@ -168,6 +142,7 @@ export async function getHistory({ gqlInstance }, name) {
|
|
|
168
142
|
}
|
|
169
143
|
...on TextChanged {
|
|
170
144
|
key
|
|
145
|
+
value
|
|
171
146
|
}
|
|
172
147
|
...on ContenthashChanged {
|
|
173
148
|
hash
|
|
@@ -202,72 +177,3 @@ export async function getHistory({ gqlInstance }, name) {
|
|
|
202
177
|
resolver: resolverHistory,
|
|
203
178
|
};
|
|
204
179
|
}
|
|
205
|
-
export async function getHistoryWithDetail({ contracts, gqlInstance, provider, }, name) {
|
|
206
|
-
const historyRes = await getHistory({ gqlInstance }, name);
|
|
207
|
-
if (!historyRes)
|
|
208
|
-
return;
|
|
209
|
-
const { domain, registration, resolver: resolverHistory } = historyRes;
|
|
210
|
-
const textEvents = resolverHistory.filter((event) => event.type === 'TextChanged');
|
|
211
|
-
const transactions = textEvents.reduce((prev, curr) => {
|
|
212
|
-
if (prev.includes(curr.transactionHash)) {
|
|
213
|
-
return prev;
|
|
214
|
-
}
|
|
215
|
-
return [...prev, curr.transactionHash];
|
|
216
|
-
}, []);
|
|
217
|
-
const publicResolver = await contracts?.getPublicResolver();
|
|
218
|
-
const fetchResult = (await ethers.utils.fetchJson(provider.connection, JSON.stringify(transactions.map((tx, i) => ({
|
|
219
|
-
jsonrpc: '2.0',
|
|
220
|
-
id: i,
|
|
221
|
-
method: 'eth_getTransactionByHash',
|
|
222
|
-
params: [tx],
|
|
223
|
-
})))))
|
|
224
|
-
.map((result) => result.result)
|
|
225
|
-
.map(mapResultDetailDecode(publicResolver))
|
|
226
|
-
.reduce(expandDecode, []);
|
|
227
|
-
const detailedResolverHistory = resolverHistory.map((event) => {
|
|
228
|
-
if (event.type !== 'TextChanged')
|
|
229
|
-
return event;
|
|
230
|
-
const { id } = event;
|
|
231
|
-
const matchedTextInx = textEvents.findIndex((x) => x.id === id);
|
|
232
|
-
return {
|
|
233
|
-
...event,
|
|
234
|
-
data: {
|
|
235
|
-
...event.data,
|
|
236
|
-
value: fetchResult[matchedTextInx] && fetchResult[matchedTextInx].value,
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
});
|
|
240
|
-
return {
|
|
241
|
-
domain,
|
|
242
|
-
registration,
|
|
243
|
-
resolver: detailedResolverHistory,
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
export async function getHistoryDetailForTransactionHash({ contracts, provider }, hash, indexInTransaction) {
|
|
247
|
-
const publicResolver = await contracts?.getPublicResolver();
|
|
248
|
-
const transaction = await provider.getTransaction(hash);
|
|
249
|
-
if (!transaction)
|
|
250
|
-
return;
|
|
251
|
-
const result = mapResultDetailDecode(publicResolver)({
|
|
252
|
-
input: transaction.data,
|
|
253
|
-
});
|
|
254
|
-
if (!result || !result.length)
|
|
255
|
-
return;
|
|
256
|
-
if (typeof indexInTransaction === 'number') {
|
|
257
|
-
if (indexInTransaction + 1 > result.length)
|
|
258
|
-
return;
|
|
259
|
-
const resultItem = result[indexInTransaction];
|
|
260
|
-
if (!resultItem ||
|
|
261
|
-
!resultItem.key ||
|
|
262
|
-
(!resultItem.value && resultItem.value !== ''))
|
|
263
|
-
return;
|
|
264
|
-
return { key: resultItem.key, value: resultItem.value };
|
|
265
|
-
}
|
|
266
|
-
return result.map((item) => {
|
|
267
|
-
if (!item.key)
|
|
268
|
-
return;
|
|
269
|
-
if (!item.value && item.value !== '')
|
|
270
|
-
return { key: item.key, value: null };
|
|
271
|
-
return { key: item.key, value: item.value };
|
|
272
|
-
});
|
|
273
|
-
}
|
|
@@ -10,8 +10,8 @@ declare const _default: {
|
|
|
10
10
|
reverseResolverAddress: any;
|
|
11
11
|
resolverAddress: any;
|
|
12
12
|
} | {
|
|
13
|
-
name:
|
|
14
|
-
match
|
|
13
|
+
name: undefined;
|
|
14
|
+
match?: undefined;
|
|
15
15
|
reverseResolverAddress?: undefined;
|
|
16
16
|
resolverAddress?: undefined;
|
|
17
17
|
} | undefined>;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -206,8 +206,8 @@ export declare class ENS {
|
|
|
206
206
|
reverseResolverAddress: any;
|
|
207
207
|
resolverAddress: any;
|
|
208
208
|
} | {
|
|
209
|
-
name:
|
|
210
|
-
match
|
|
209
|
+
name: undefined;
|
|
210
|
+
match?: undefined;
|
|
211
211
|
reverseResolverAddress?: undefined;
|
|
212
212
|
resolverAddress?: undefined;
|
|
213
213
|
} | undefined>;
|
|
@@ -255,36 +255,6 @@ export declare class ENS {
|
|
|
255
255
|
data: Record<string, any>;
|
|
256
256
|
}[];
|
|
257
257
|
} | undefined>;
|
|
258
|
-
getHistoryWithDetail: (name: string) => Promise<{
|
|
259
|
-
domain: {
|
|
260
|
-
type: any;
|
|
261
|
-
blockNumber: any;
|
|
262
|
-
transactionHash: any;
|
|
263
|
-
id: any;
|
|
264
|
-
data: Record<string, any>;
|
|
265
|
-
}[];
|
|
266
|
-
registration: {
|
|
267
|
-
type: any;
|
|
268
|
-
blockNumber: any;
|
|
269
|
-
transactionHash: any;
|
|
270
|
-
id: any;
|
|
271
|
-
data: Record<string, any>;
|
|
272
|
-
}[];
|
|
273
|
-
resolver: {
|
|
274
|
-
type: any;
|
|
275
|
-
blockNumber: any;
|
|
276
|
-
transactionHash: any;
|
|
277
|
-
id: any;
|
|
278
|
-
data: Record<string, any>;
|
|
279
|
-
}[];
|
|
280
|
-
} | undefined>;
|
|
281
|
-
getHistoryDetailForTransactionHash: (hash: string, indexInTransaction?: number | undefined) => Promise<({
|
|
282
|
-
key: any;
|
|
283
|
-
value: any;
|
|
284
|
-
} | undefined)[] | {
|
|
285
|
-
key: any;
|
|
286
|
-
value: any;
|
|
287
|
-
} | undefined>;
|
|
288
258
|
getContentHash: GeneratedRawFunction<{
|
|
289
259
|
raw: ({ contracts, universalWrapper }: ENSArgs<"contracts" | "universalWrapper">, name: string) => Promise<{
|
|
290
260
|
to: string;
|
package/dist/esm/index.js
CHANGED
|
@@ -168,8 +168,6 @@ export class ENS {
|
|
|
168
168
|
'contracts',
|
|
169
169
|
]);
|
|
170
170
|
this.getHistory = this.generateFunction('getHistory', ['gqlInstance'], 'getHistory');
|
|
171
|
-
this.getHistoryWithDetail = this.generateFunction('getHistory', ['contracts', 'gqlInstance', 'provider'], 'getHistoryWithDetail');
|
|
172
|
-
this.getHistoryDetailForTransactionHash = this.generateFunction('getHistory', ['contracts', 'provider'], 'getHistoryDetailForTransactionHash');
|
|
173
171
|
this.getContentHash = this.generateRawFunction('initialGetters', ['contracts', 'universalWrapper'], 'getContentHash');
|
|
174
172
|
this._getContentHash = this.generateRawFunction('initialGetters', ['contracts'], '_getContentHash');
|
|
175
173
|
this.getAddr = this.generateRawFunction('initialGetters', ['contracts', 'universalWrapper'], 'getAddr');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ensdomains/ensjs",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.12",
|
|
4
4
|
"description": "ENS javascript library for contract interaction",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"types": "./dist/cjs/index.d.ts",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"ethers": "*"
|
|
87
87
|
},
|
|
88
|
-
"stableVersion": "3.0.0-alpha.
|
|
88
|
+
"stableVersion": "3.0.0-alpha.11"
|
|
89
89
|
}
|
|
@@ -13,8 +13,6 @@ afterAll(async () => {
|
|
|
13
13
|
})
|
|
14
14
|
|
|
15
15
|
describe('getHistory', () => {
|
|
16
|
-
let textEventsWithValue: any[]
|
|
17
|
-
|
|
18
16
|
it('should return null for a non-existent name', async () => {
|
|
19
17
|
const result = await ENSInstance.getHistory('test123123cool.eth')
|
|
20
18
|
expect(result).toBeUndefined()
|
|
@@ -28,86 +26,4 @@ describe('getHistory', () => {
|
|
|
28
26
|
expect(result).toHaveProperty('registration')
|
|
29
27
|
}
|
|
30
28
|
})
|
|
31
|
-
describe('getHistoryWithDetail', () => {
|
|
32
|
-
it('should return null for a non-existent name', async () => {
|
|
33
|
-
const result = await ENSInstance.getHistoryWithDetail(
|
|
34
|
-
'test123123cool.eth',
|
|
35
|
-
)
|
|
36
|
-
expect(result).toBeUndefined()
|
|
37
|
-
})
|
|
38
|
-
it('should return the history of a name with TextChanged event detail', async () => {
|
|
39
|
-
const result = await ENSInstance.getHistoryWithDetail('with-profile.eth')
|
|
40
|
-
expect(result).toBeTruthy()
|
|
41
|
-
if (result) {
|
|
42
|
-
const textEvents = result.resolver.filter(
|
|
43
|
-
(x) => x.type === 'TextChanged',
|
|
44
|
-
)
|
|
45
|
-
textEvents.forEach((event) =>
|
|
46
|
-
expect(event.data).toHaveProperty('value'),
|
|
47
|
-
)
|
|
48
|
-
textEventsWithValue = textEvents
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
describe('getHistoryDetailForTransactionHash', () => {
|
|
53
|
-
it('should throw an error for an invalid transaction hash', async () => {
|
|
54
|
-
try {
|
|
55
|
-
await ENSInstance.getHistoryDetailForTransactionHash('0x234')
|
|
56
|
-
expect(false).toBeTruthy()
|
|
57
|
-
} catch (error) {
|
|
58
|
-
expect((error as any).message).toContain('invalid hash')
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
it('should return null for a transaction hash with no text events', async () => {
|
|
62
|
-
const result = await ENSInstance.getHistoryDetailForTransactionHash(
|
|
63
|
-
'0x0fd7b555e3076ef38dbbe2e40deefe44c9a0530d43f6b3f60dbed4ba49d229b7',
|
|
64
|
-
)
|
|
65
|
-
expect(result).toBeUndefined()
|
|
66
|
-
})
|
|
67
|
-
it('should return single item for a given transaction hash with one event', async () => {
|
|
68
|
-
const eventToUse = textEventsWithValue[0]
|
|
69
|
-
const result = (await ENSInstance.getHistoryDetailForTransactionHash(
|
|
70
|
-
eventToUse.transactionHash,
|
|
71
|
-
)) as { key: any; value: any }[]
|
|
72
|
-
expect(result).toHaveLength(1)
|
|
73
|
-
if (result) {
|
|
74
|
-
expect(result[0]).toMatchObject(eventToUse.data)
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
let hash: string = ''
|
|
78
|
-
it('should return multiple items for a given transaction hash with multiple events', async () => {
|
|
79
|
-
const dataArr = [
|
|
80
|
-
{ key: 'foo', value: 'bar' },
|
|
81
|
-
{ key: 'swag', value: 'cool' },
|
|
82
|
-
]
|
|
83
|
-
const tx = await ENSInstance.setRecords('test123.eth', {
|
|
84
|
-
records: {
|
|
85
|
-
texts: dataArr,
|
|
86
|
-
},
|
|
87
|
-
addressOrIndex: 1,
|
|
88
|
-
})
|
|
89
|
-
await tx.wait()
|
|
90
|
-
|
|
91
|
-
hash = tx.hash
|
|
92
|
-
|
|
93
|
-
const result = (await ENSInstance.getHistoryDetailForTransactionHash(
|
|
94
|
-
hash,
|
|
95
|
-
)) as { key: any; value: any }[]
|
|
96
|
-
expect(result).toHaveLength(dataArr.length)
|
|
97
|
-
if (result) {
|
|
98
|
-
result.forEach((item, index) =>
|
|
99
|
-
expect(item).toMatchObject(dataArr[index]),
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
it('should return a single item when an index is specified for a hash', async () => {
|
|
104
|
-
const data = { key: 'swag', value: 'cool' }
|
|
105
|
-
|
|
106
|
-
const result = (await ENSInstance.getHistoryDetailForTransactionHash(
|
|
107
|
-
hash,
|
|
108
|
-
1,
|
|
109
|
-
)) as { key: any; value: any }
|
|
110
|
-
expect(result).toMatchObject(data)
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
29
|
})
|
|
@@ -2,7 +2,6 @@ import { formatsByCoinType } from '@ensdomains/address-encoder'
|
|
|
2
2
|
import { ethers } from 'ethers'
|
|
3
3
|
import { ENSArgs } from '..'
|
|
4
4
|
import { decodeContenthash } from '../utils/contentHash'
|
|
5
|
-
import { makeOtherIndexes } from '../utils/makeHashIndexes'
|
|
6
5
|
|
|
7
6
|
type DomainEvent = 'NewOwner' | 'NewResolver' | 'Transfer' | 'NewTTL'
|
|
8
7
|
type RegistrationEvent = 'NameRegistered' | 'NameRenewed' | 'NameTransferred'
|
|
@@ -63,7 +62,7 @@ const eventFormat: Record<
|
|
|
63
62
|
NameChanged: (args: any) => ({ name: args.name }),
|
|
64
63
|
AbiChanged: (args: any) => ({ contentType: args.contentType }),
|
|
65
64
|
PubkeyChanged: (args: any) => ({ x: args.x, y: args.y }),
|
|
66
|
-
TextChanged: (args: any) => ({ key: args.key }),
|
|
65
|
+
TextChanged: (args: any) => ({ key: args.key, value: args.value }),
|
|
67
66
|
ContenthashChanged: (args: any) => ({ hash: decodeContenthash(args.hash) }),
|
|
68
67
|
InterfaceChanged: (args: any) => ({
|
|
69
68
|
interfaceId: args.interfaceId,
|
|
@@ -86,37 +85,6 @@ const mapEvents = (eventArray: any[], type: EventTypes) =>
|
|
|
86
85
|
data: eventFormat[type][event.__typename](event),
|
|
87
86
|
}))
|
|
88
87
|
|
|
89
|
-
const mapResultDetailDecode =
|
|
90
|
-
(publicResolver: ethers.Contract) => (result: any) => {
|
|
91
|
-
const hashIndexes = makeOtherIndexes(result.input, '10f13a8c')
|
|
92
|
-
const abiLengths = hashIndexes.map((x: number) => ({
|
|
93
|
-
index: x,
|
|
94
|
-
length:
|
|
95
|
-
x === 0
|
|
96
|
-
? ethers.utils.hexDataLength(result.input)
|
|
97
|
-
: parseInt(ethers.utils.hexDataSlice(result.input, x - 32, x), 16),
|
|
98
|
-
}))
|
|
99
|
-
const ABIs = abiLengths.map(({ index, length }) =>
|
|
100
|
-
ethers.utils.hexDataSlice(result.input, index, index + length),
|
|
101
|
-
)
|
|
102
|
-
return ABIs.map((abi: string) => {
|
|
103
|
-
try {
|
|
104
|
-
return publicResolver.interface.decodeFunctionData(
|
|
105
|
-
'setText(bytes32,string,string)',
|
|
106
|
-
abi,
|
|
107
|
-
)
|
|
108
|
-
} catch {
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
})
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const expandDecode = (prev: any, curr: any) => {
|
|
115
|
-
if (!curr) return [...prev, { value: null }]
|
|
116
|
-
if (!curr.length) return [...prev, curr]
|
|
117
|
-
return [...prev, ...curr]
|
|
118
|
-
}
|
|
119
|
-
|
|
120
88
|
export async function getHistory(
|
|
121
89
|
{ gqlInstance }: ENSArgs<'gqlInstance'>,
|
|
122
90
|
name: string,
|
|
@@ -200,6 +168,7 @@ export async function getHistory(
|
|
|
200
168
|
}
|
|
201
169
|
...on TextChanged {
|
|
202
170
|
key
|
|
171
|
+
value
|
|
203
172
|
}
|
|
204
173
|
...on ContenthashChanged {
|
|
205
174
|
hash
|
|
@@ -251,97 +220,3 @@ export async function getHistory(
|
|
|
251
220
|
resolver: resolverHistory,
|
|
252
221
|
}
|
|
253
222
|
}
|
|
254
|
-
|
|
255
|
-
export async function getHistoryWithDetail(
|
|
256
|
-
{
|
|
257
|
-
contracts,
|
|
258
|
-
gqlInstance,
|
|
259
|
-
provider,
|
|
260
|
-
}: ENSArgs<'contracts' | 'gqlInstance' | 'provider'>,
|
|
261
|
-
name: string,
|
|
262
|
-
) {
|
|
263
|
-
const historyRes = await getHistory({ gqlInstance }, name)
|
|
264
|
-
|
|
265
|
-
if (!historyRes) return
|
|
266
|
-
|
|
267
|
-
const { domain, registration, resolver: resolverHistory } = historyRes
|
|
268
|
-
|
|
269
|
-
const textEvents = resolverHistory.filter(
|
|
270
|
-
(event) => event.type === 'TextChanged',
|
|
271
|
-
)
|
|
272
|
-
|
|
273
|
-
const transactions = textEvents.reduce((prev, curr) => {
|
|
274
|
-
if (prev.includes(curr.transactionHash)) {
|
|
275
|
-
return prev
|
|
276
|
-
}
|
|
277
|
-
return [...prev, curr.transactionHash]
|
|
278
|
-
}, [] as string[])
|
|
279
|
-
|
|
280
|
-
const publicResolver = await contracts?.getPublicResolver()!
|
|
281
|
-
|
|
282
|
-
const fetchResult = (
|
|
283
|
-
await ethers.utils.fetchJson(
|
|
284
|
-
provider!.connection,
|
|
285
|
-
JSON.stringify(
|
|
286
|
-
transactions.map((tx, i) => ({
|
|
287
|
-
jsonrpc: '2.0',
|
|
288
|
-
id: i,
|
|
289
|
-
method: 'eth_getTransactionByHash',
|
|
290
|
-
params: [tx],
|
|
291
|
-
})),
|
|
292
|
-
),
|
|
293
|
-
)
|
|
294
|
-
)
|
|
295
|
-
.map((result: any) => result.result)
|
|
296
|
-
.map(mapResultDetailDecode(publicResolver))
|
|
297
|
-
.reduce(expandDecode, [])
|
|
298
|
-
|
|
299
|
-
const detailedResolverHistory = resolverHistory.map((event) => {
|
|
300
|
-
if (event.type !== 'TextChanged') return event
|
|
301
|
-
const { id } = event
|
|
302
|
-
const matchedTextInx = textEvents.findIndex((x) => x.id === id)
|
|
303
|
-
return {
|
|
304
|
-
...event,
|
|
305
|
-
data: {
|
|
306
|
-
...event.data,
|
|
307
|
-
value: fetchResult[matchedTextInx] && fetchResult[matchedTextInx].value,
|
|
308
|
-
},
|
|
309
|
-
}
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
return {
|
|
313
|
-
domain,
|
|
314
|
-
registration,
|
|
315
|
-
resolver: detailedResolverHistory,
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
export async function getHistoryDetailForTransactionHash(
|
|
320
|
-
{ contracts, provider }: ENSArgs<'contracts' | 'provider'>,
|
|
321
|
-
hash: string,
|
|
322
|
-
indexInTransaction?: number,
|
|
323
|
-
) {
|
|
324
|
-
const publicResolver = await contracts?.getPublicResolver()!
|
|
325
|
-
const transaction = await provider!.getTransaction(hash)
|
|
326
|
-
if (!transaction) return
|
|
327
|
-
const result = mapResultDetailDecode(publicResolver)({
|
|
328
|
-
input: transaction.data,
|
|
329
|
-
})
|
|
330
|
-
if (!result || !result.length) return
|
|
331
|
-
if (typeof indexInTransaction === 'number') {
|
|
332
|
-
if (indexInTransaction + 1 > result.length) return
|
|
333
|
-
const resultItem = result[indexInTransaction]
|
|
334
|
-
if (
|
|
335
|
-
!resultItem ||
|
|
336
|
-
!resultItem.key ||
|
|
337
|
-
(!resultItem.value && resultItem.value !== '')
|
|
338
|
-
)
|
|
339
|
-
return
|
|
340
|
-
return { key: resultItem.key, value: resultItem.value }
|
|
341
|
-
}
|
|
342
|
-
return result.map((item: any) => {
|
|
343
|
-
if (!item.key) return
|
|
344
|
-
if (!item.value && item.value !== '') return { key: item.key, value: null }
|
|
345
|
-
return { key: item.key, value: item.value }
|
|
346
|
-
})
|
|
347
|
-
}
|
|
@@ -31,7 +31,7 @@ describe('getName', () => {
|
|
|
31
31
|
const result = await ENSInstance.getName(
|
|
32
32
|
'0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0',
|
|
33
33
|
)
|
|
34
|
-
expect(result).toBeUndefined()
|
|
34
|
+
expect(result?.name).toBeUndefined()
|
|
35
35
|
})
|
|
36
36
|
it('should return with a false match for a name with no forward resolution', async () => {
|
|
37
37
|
const tx = await ENSInstance.setName('with-profile.eth')
|
package/src/functions/getName.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -15,11 +15,7 @@ import type deleteSubname from './functions/deleteSubname'
|
|
|
15
15
|
import type getDNSOwner from './functions/getDNSOwner'
|
|
16
16
|
import type getExpiry from './functions/getExpiry'
|
|
17
17
|
import type getFuses from './functions/getFuses'
|
|
18
|
-
import type {
|
|
19
|
-
getHistory,
|
|
20
|
-
getHistoryDetailForTransactionHash,
|
|
21
|
-
getHistoryWithDetail,
|
|
22
|
-
} from './functions/getHistory'
|
|
18
|
+
import type { getHistory } from './functions/getHistory'
|
|
23
19
|
import type getName from './functions/getName'
|
|
24
20
|
import type getNames from './functions/getNames'
|
|
25
21
|
import type getOwner from './functions/getOwner'
|
|
@@ -437,22 +433,6 @@ export class ENS {
|
|
|
437
433
|
'getHistory',
|
|
438
434
|
)
|
|
439
435
|
|
|
440
|
-
public getHistoryWithDetail = this.generateFunction<
|
|
441
|
-
typeof getHistoryWithDetail
|
|
442
|
-
>(
|
|
443
|
-
'getHistory',
|
|
444
|
-
['contracts', 'gqlInstance', 'provider'],
|
|
445
|
-
'getHistoryWithDetail',
|
|
446
|
-
)
|
|
447
|
-
|
|
448
|
-
public getHistoryDetailForTransactionHash = this.generateFunction<
|
|
449
|
-
typeof getHistoryDetailForTransactionHash
|
|
450
|
-
>(
|
|
451
|
-
'getHistory',
|
|
452
|
-
['contracts', 'provider'],
|
|
453
|
-
'getHistoryDetailForTransactionHash',
|
|
454
|
-
)
|
|
455
|
-
|
|
456
436
|
public getContentHash = this.generateRawFunction<typeof getContentHash>(
|
|
457
437
|
'initialGetters',
|
|
458
438
|
['contracts', 'universalWrapper'],
|