-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.ts
62 lines (54 loc) · 1.52 KB
/
json.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { getAddress, getText, getContenthash } from './query';
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
const EMPTY_CONTENT_HASH = '0x';
const ttl = 300;
export async function addr(name: string, coinType: number) {
try {
let addresses = await getAddress(name);
// @ts-ignore
addresses = addresses?.address;
let addr = ZERO_ADDRESS;
// @ts-ignore
if (addresses && addresses[coinType]) {
// @ts-ignore
addr = '' + addresses[coinType];
}
return { addr, ttl };
} catch (e) {
return { addr: ZERO_ADDRESS, ttl };
}
}
export async function text(name: string, key: string) {
try {
const texts = await getText(name);
// @ts-ignore
const text = texts?.text;
// @ts-ignore
if (text && text[key]) { // @ts-ignore
return { value: text[key], ttl };
} else {
return { value: '', ttl };
}
} catch (e) {
return { value: '', ttl };
}
}
export async function contenthash(name: string) {
try {
const contenthashRes = await getContenthash(name);
// @ts-ignore
const contenthash = contenthashRes?.contenthash;
if (contenthash) {
return { contenthash: contenthash, ttl };
} else {
return { contenthash: EMPTY_CONTENT_HASH, ttl };
}
} catch (e) {
return { contenthash: EMPTY_CONTENT_HASH, ttl };
}
}
// ~(async function () {
// const address = await getAddress('ethpaymaster.eth');
// const address1 = await addr('ethpaymaster.eth', 60);
// console.log(address, address1, 'address 11');
// }())