-
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathgetAccount.tsx
More file actions
130 lines (114 loc) · 3.19 KB
/
Copy pathgetAccount.tsx
File metadata and controls
130 lines (114 loc) · 3.19 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
import type { GetAccountParams, GetAccountResult } from '@tevm/actions'
import { option } from 'pastel'
import { z } from 'zod'
import CliAction from '../components/CliAction.js'
import { envVar, useAction } from '../hooks/useAction.js'
// Add command description for help output
export const description = 'Get account information including balance and nonce'
// Options definitions and descriptions
const optionDescriptions = {
address: 'Ethereum address of the account to get (env: TEVM_ADDRESS)',
rpc: 'RPC endpoint (env: TEVM_RPC)',
returnStorage: 'Return account storage (can be expensive) (env: TEVM_RETURN_STORAGE)',
blockTag: 'Block tag to fetch account from (latest, earliest, pending, etc.) (env: TEVM_BLOCK_TAG)',
}
// Empty args tuple
export const args = z.tuple([])
export const options = z.object({
// Required address
address: z.string().describe(
option({
description: optionDescriptions.address,
}),
),
// Interactive mode flag (run directly without interactive editor)
run: z
.boolean()
.default(false)
.describe(
option({
description: 'Run directly without interactive parameter editing (env: TEVM_RUN)',
alias: 'r',
}),
),
// Transport options
rpc: z
.string()
.default(envVar('rpc') || 'http://localhost:8545')
.describe(
option({
description: optionDescriptions.rpc,
defaultValueDescription: 'http://localhost:8545',
}),
),
// Account retrieval options
returnStorage: z
.boolean()
.default(false)
.describe(
option({
description: optionDescriptions.returnStorage,
}),
),
blockTag: z
.string()
.optional()
.describe(
option({
description: optionDescriptions.blockTag,
}),
),
// Output formatting
formatJson: z
.boolean()
.default(envVar('format_json') !== 'false')
.describe(
option({
description: 'Format output as JSON (env: TEVM_FORMAT_JSON)',
defaultValueDescription: 'true',
}),
),
})
type Props = {
args: z.infer<typeof args>
options: z.infer<typeof options>
}
// Default values for all parameters
const defaultValues: Record<string, any> = {
rpc: 'http://localhost:8545',
returnStorage: false,
blockTag: 'latest',
}
export default function GetAccount({ options }: Props) {
// Use the action hook with inlined createParams and executeAction
const actionResult = useAction<GetAccountParams, GetAccountResult>({
actionName: 'get-account',
options,
defaultValues,
optionDescriptions,
// Inlined createParams function
createParams: (enhancedOptions: Record<string, any>): GetAccountParams => {
const targetAddress = enhancedOptions['address'] as `0x${string}`
if (!targetAddress) {
throw new Error('Address is required')
}
return {
address: targetAddress,
returnStorage: enhancedOptions['returnStorage'] ?? false,
blockTag: enhancedOptions['blockTag'] ?? undefined,
}
},
// Inlined executeAction function
executeAction: async (client: any, params: GetAccountParams): Promise<GetAccountResult> => {
return await client.tevmGetAccount(params)
},
})
// Render the action UI
return (
<CliAction
{...actionResult}
targetName={`account ${actionResult.options['address']}`}
successMessage="Account retrieved successfully!"
/>
)
}