-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathgetEnsText.tsx
More file actions
175 lines (153 loc) · 4.05 KB
/
Copy pathgetEnsText.tsx
File metadata and controls
175 lines (153 loc) · 4.05 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { option } from 'pastel'
import { z } from 'zod'
import CliAction from '../components/CliAction.js'
import { useAction } from '../hooks/useAction.js'
// Add command description for help output
export const description =
'Get an ENS text record\nExample: tevm get-ens-text --name vitalik.eth --key url --rpc https://eth.llamarpc.com --run'
// Options definitions and descriptions
const optionDescriptions = {
name: 'ENS name to lookup (env: TEVM_NAME)',
key: 'Text record key to retrieve (env: TEVM_KEY)',
rpc: 'RPC endpoint (env: TEVM_RPC)',
blockTag: 'Block tag (latest, pending, etc.) (env: TEVM_BLOCK_TAG)',
blockNumber: 'Block number to query at (env: TEVM_BLOCK_NUMBER)',
universalResolverAddress: 'Address of ENS Universal Resolver (env: TEVM_UNIVERSAL_RESOLVER_ADDRESS)',
}
// Empty args tuple
export const args = z.tuple([])
export const options = z.object({
// ALL PARAMETERS OPTIONAL
name: z
.string()
.optional()
.describe(
option({
description: optionDescriptions.name,
}),
),
key: z
.string()
.optional()
.describe(
option({
description: optionDescriptions.key,
}),
),
blockTag: z
.string()
.optional()
.describe(
option({
description: optionDescriptions.blockTag,
}),
),
blockNumber: z
.string()
.optional()
.describe(
option({
description: optionDescriptions.blockNumber,
}),
),
universalResolverAddress: z
.string()
.optional()
.describe(
option({
description: optionDescriptions.universalResolverAddress,
}),
),
// Interactive mode flag
run: z
.boolean()
.default(false)
.describe(
option({
description: 'Run directly without interactive parameter editing (env: TEVM_RUN)',
alias: 'r',
}),
),
// Transport options
rpc: z
.string()
.optional()
.describe(
option({
description: optionDescriptions.rpc,
defaultValueDescription: 'https://eth-mainnet.g.alchemy.com/v2/demo',
}),
),
// Output formatting
json: z
.boolean()
.optional()
.describe(
option({
description: 'Emit the stable machine-readable JSON envelope (env: TEVM_JSON)',
defaultValueDescription: 'false',
}),
),
})
type Props = {
args: z.infer<typeof args>
options: z.infer<typeof options>
}
// COMPREHENSIVE DEFAULTS
const defaultValues: Record<string, any> = {
name: 'vitalik.eth',
key: 'url',
blockTag: 'latest',
rpc: 'https://eth-mainnet.g.alchemy.com/v2/demo', // ENS is only on mainnet
}
// Helper function to safely parse block number
const parseBlockNumber = (blockNumber?: string): bigint | undefined => {
if (!blockNumber) return undefined
try {
return BigInt(blockNumber)
} catch (_e) {
throw new Error(`Invalid block number "${blockNumber}"`)
}
}
export default function GetEnsText({ options }: Props) {
// Use the action hook
const actionResult = useAction({
actionName: 'getEnsText',
options,
defaultValues,
optionDescriptions,
// Create params
createParams: (enhancedOptions: Record<string, any>) => {
const params: Record<string, any> = {
name: enhancedOptions['name'] || defaultValues['name'],
key: enhancedOptions['key'] || defaultValues['key'],
}
// Add block identifier - only one should be used
if (enhancedOptions['blockNumber']) {
params['blockNumber'] = parseBlockNumber(enhancedOptions['blockNumber'])
} else if (enhancedOptions['blockTag']) {
params['blockTag'] = enhancedOptions['blockTag']
}
// Add universal resolver address if specified
if (enhancedOptions['universalResolverAddress']) {
params['universalResolverAddress'] = enhancedOptions['universalResolverAddress']
}
return params
},
// Execute the action
executeAction: async (client: any, params: any): Promise<any> => {
return await client.getEnsText(params)
},
})
// If editor is active, render nothing
if (actionResult.editorActive) {
return null
}
return (
<CliAction
{...actionResult}
targetName={`${actionResult.options['key'] || 'url'} record for ${actionResult.options['name'] || 'vitalik.eth'}`}
successMessage="ENS text record retrieved successfully!"
/>
)
}