Skip to content

Commit c519f80

Browse files
committed
Adds chifra abis --list_funcs and --list_events
1 parent fff01f3 commit c519f80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+937
-54
lines changed

docs/content/api/openapi.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,16 @@ paths:
10101010
explode: true
10111011
schema:
10121012
type: boolean
1013-
- name: listItems
1014-
description: a list of the downloaded functions and events in all abi files
1013+
- name: listFuncs
1014+
description: a list of the functions in all abi files
1015+
required: false
1016+
style: form
1017+
in: query
1018+
explode: true
1019+
schema:
1020+
type: boolean
1021+
- name: listEvents
1022+
description: a list of the events in all abi files
10151023
required: false
10161024
style: form
10171025
in: query

docs/content/chifra/accounts.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ Flags:
342342
-k, --known load common 'known' ABIs from cache
343343
-r, --proxy_for string redirects the query to this implementation
344344
-l, --list a list of downloaded abi files
345-
-i, --list_items a list of the downloaded functions and events in all abi files
345+
-i, --list_funcs a list of the functions in all abi files
346+
-I, --list_events a list of the events in all abi files
346347
-c, --count show the number of abis downloaded
347348
-f, --find strings search for function or event declarations given a four- or 32-byte code(s)
348349
-n, --hint strings for the --find option only, provide hints to speed up the search

src/apps/chifra/cmd/abis.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func init() {
5959
abisCmd.Flags().BoolVarP(&abisPkg.GetOptions().Known, "known", "k", false, `load common 'known' ABIs from cache`)
6060
abisCmd.Flags().StringVarP(&abisPkg.GetOptions().ProxyFor, "proxy_for", "r", "", `redirects the query to this implementation`)
6161
abisCmd.Flags().BoolVarP(&abisPkg.GetOptions().List, "list", "l", false, `a list of downloaded abi files`)
62-
abisCmd.Flags().BoolVarP(&abisPkg.GetOptions().ListItems, "list_items", "i", false, `a list of the downloaded functions and events in all abi files`)
62+
abisCmd.Flags().BoolVarP(&abisPkg.GetOptions().ListFuncs, "list_funcs", "i", false, `a list of the functions in all abi files`)
63+
abisCmd.Flags().BoolVarP(&abisPkg.GetOptions().ListEvents, "list_events", "I", false, `a list of the events in all abi files`)
6364
abisCmd.Flags().BoolVarP(&abisPkg.GetOptions().Count, "count", "c", false, `show the number of abis downloaded`)
6465
abisCmd.Flags().StringSliceVarP(&abisPkg.GetOptions().Find, "find", "f", nil, `search for function or event declarations given a four- or 32-byte code(s)`)
6566
abisCmd.Flags().StringSliceVarP(&abisPkg.GetOptions().Hint, "hint", "n", nil, `for the --find option only, provide hints to speed up the search`)

src/apps/chifra/internal/abis/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Flags:
3737
-k, --known load common 'known' ABIs from cache
3838
-r, --proxy_for string redirects the query to this implementation
3939
-l, --list a list of downloaded abi files
40-
-i, --list_items a list of the downloaded functions and events in all abi files
40+
-i, --list_funcs a list of the functions in all abi files
41+
-I, --list_events a list of the events in all abi files
4142
-c, --count show the number of abis downloaded
4243
-f, --find strings search for function or event declarations given a four- or 32-byte code(s)
4344
-n, --hint strings for the --find option only, provide hints to speed up the search

src/apps/chifra/internal/abis/handle_list.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ func (opts *AbisOptions) HandleList(rCtx *output.RenderCtx) error {
2525
abiArray := make([]types.Abi, 0, 100)
2626
vFunc := func(fn string, vP any) (bool, error) {
2727
_ = vP
28+
isKnown := strings.Contains(fn, "known")
29+
if opts.Known && !isKnown {
30+
return true, nil
31+
}
32+
2833
if strings.HasSuffix(fn, ".json") {
2934
info, _ := os.Stat(fn)
3035
abi := types.Abi{
3136
FileSize: file.FileSize(fn),
3237
LastModDate: info.ModTime().Format("2006-01-02 15:04:05"),
33-
IsKnown: strings.Contains(fn, "known"),
38+
IsKnown: isKnown,
3439
}
3540
abi.Path, abi.Name = filepath.Split(fn)
3641
if len(abi.Name) > 0 {

src/apps/chifra/internal/abis/handle_listitems.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ import (
99
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
1010
)
1111

12-
func (opts *AbisOptions) HandleListItems(rCtx *output.RenderCtx) (err error) {
12+
func (opts *AbisOptions) HandleListFuncs(rCtx *output.RenderCtx) (err error) {
13+
return opts.HandleListItems(rCtx, "function")
14+
}
15+
16+
func (opts *AbisOptions) HandleListEvents(rCtx *output.RenderCtx) (err error) {
17+
return opts.HandleListItems(rCtx, "event")
18+
}
19+
20+
func (opts *AbisOptions) HandleListItems(rCtx *output.RenderCtx, filter string) (err error) {
1321
fetchData := func(modelChan chan types.Modeler, errorChan chan error) {
1422
for _, addr := range opts.Addrs {
1523
functions, which, err := opts.LoadAbis([]string{addr}, false /* known */)
@@ -28,7 +36,9 @@ func (opts *AbisOptions) HandleListItems(rCtx *output.RenderCtx) (err error) {
2836
}
2937

3038
for _, f := range functions {
31-
modelChan <- f
39+
if filter == "" || filter == f.FunctionType {
40+
modelChan <- f
41+
}
3242
}
3343
}
3444
}

src/apps/chifra/internal/abis/options.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@ import (
2828

2929
// AbisOptions provides all command options for the chifra abis command.
3030
type AbisOptions struct {
31-
Addrs []string `json:"addrs,omitempty"` // A list of one or more smart contracts whose ABIs to display
32-
Known bool `json:"known,omitempty"` // Load common 'known' ABIs from cache
33-
ProxyFor string `json:"proxyFor,omitempty"` // Redirects the query to this implementation
34-
List bool `json:"list,omitempty"` // A list of downloaded abi files
35-
ListItems bool `json:"listItems,omitempty"` // A list of the downloaded functions and events in all abi files
36-
Count bool `json:"count,omitempty"` // Show the number of abis downloaded
37-
Find []string `json:"find,omitempty"` // Search for function or event declarations given a four- or 32-byte code(s)
38-
Hint []string `json:"hint,omitempty"` // For the --find option only, provide hints to speed up the search
39-
Encode string `json:"encode,omitempty"` // Generate the 32-byte encoding for a given canonical function or event signature
40-
Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options
41-
Conn *rpc.Connection `json:"conn,omitempty"` // The connection to the RPC server
42-
BadFlag error `json:"badFlag,omitempty"` // An error flag if needed
31+
Addrs []string `json:"addrs,omitempty"` // A list of one or more smart contracts whose ABIs to display
32+
Known bool `json:"known,omitempty"` // Load common 'known' ABIs from cache
33+
ProxyFor string `json:"proxyFor,omitempty"` // Redirects the query to this implementation
34+
List bool `json:"list,omitempty"` // A list of downloaded abi files
35+
ListFuncs bool `json:"listFuncs,omitempty"` // A list of the functions in all abi files
36+
ListEvents bool `json:"listEvents,omitempty"` // A list of the events in all abi files
37+
Count bool `json:"count,omitempty"` // Show the number of abis downloaded
38+
Find []string `json:"find,omitempty"` // Search for function or event declarations given a four- or 32-byte code(s)
39+
Hint []string `json:"hint,omitempty"` // For the --find option only, provide hints to speed up the search
40+
Encode string `json:"encode,omitempty"` // Generate the 32-byte encoding for a given canonical function or event signature
41+
Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options
42+
Conn *rpc.Connection `json:"conn,omitempty"` // The connection to the RPC server
43+
BadFlag error `json:"badFlag,omitempty"` // An error flag if needed
4344
// EXISTING_CODE
4445
ProxyForAddr base.Address `json:"-"`
4546
// EXISTING_CODE
@@ -53,7 +54,8 @@ func (opts *AbisOptions) testLog() {
5354
logger.TestLog(opts.Known, "Known: ", opts.Known)
5455
logger.TestLog(len(opts.ProxyFor) > 0, "ProxyFor: ", opts.ProxyFor)
5556
logger.TestLog(opts.List, "List: ", opts.List)
56-
logger.TestLog(opts.ListItems, "ListItems: ", opts.ListItems)
57+
logger.TestLog(opts.ListFuncs, "ListFuncs: ", opts.ListFuncs)
58+
logger.TestLog(opts.ListEvents, "ListEvents: ", opts.ListEvents)
5759
logger.TestLog(opts.Count, "Count: ", opts.Count)
5860
logger.TestLog(len(opts.Find) > 0, "Find: ", opts.Find)
5961
logger.TestLog(len(opts.Hint) > 0, "Hint: ", opts.Hint)
@@ -94,8 +96,10 @@ func AbisFinishParseInternal(w io.Writer, values url.Values) *AbisOptions {
9496
opts.ProxyFor = value[0]
9597
case "list":
9698
opts.List = true
97-
case "listItems":
98-
opts.ListItems = true
99+
case "listFuncs":
100+
opts.ListFuncs = true
101+
case "listEvents":
102+
opts.ListEvents = true
99103
case "count":
100104
opts.Count = true
101105
case "find":

src/apps/chifra/internal/abis/output.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ func (opts *AbisOptions) AbisInternal(rCtx *output.RenderCtx) error {
6363
err = opts.HandleCount(rCtx)
6464
} else if opts.List {
6565
err = opts.HandleList(rCtx)
66-
} else if opts.ListItems {
67-
err = opts.HandleListItems(rCtx)
66+
} else if opts.ListFuncs {
67+
err = opts.HandleListFuncs(rCtx)
68+
} else if opts.ListEvents {
69+
err = opts.HandleListEvents(rCtx)
6870
} else if len(opts.Encode) > 0 {
6971
err = opts.HandleEncode(rCtx)
7072
} else {

src/dev_tools/goMaker/templates/cmd-line-options.csv

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,16 @@ num,folder,group,route,tool,longName,hotKey,def_val,attributes,handler,option_ty
9797
15200,tools,Accounts,names,ethNames,n2,,,,,note,,,,,,The `--match_case` option enables case sensitive matching.
9898
#
9999
16000,tools,Accounts,abis,grabABI,,,,visible|docs,,command,,,Manage Abi files,[flags] <address> [address...],default|caching|names|,Fetches the ABI for a smart contract.
100-
16020,tools,Accounts,abis,grabABI,addrs,,,required|visible|docs,6,positional,list<addr>,function,,,,a list of one or more smart contracts whose ABIs to display
100+
16020,tools,Accounts,abis,grabABI,addrs,,,required|visible|docs,7,positional,list<addr>,function,,,,a list of one or more smart contracts whose ABIs to display
101101
16030,tools,Accounts,abis,grabABI,known,k,,visible|docs,,switch,<boolean>,,,,,load common 'known' ABIs from cache
102102
16040,tools,Accounts,abis,grabABI,proxy_for,r,,visible|docs,,flag,<address>,,,,,redirects the query to this implementation
103103
16050,tools,Accounts,abis,grabABI,list,l,,visible|docs,3,switch,<boolean>,abi,,,,a list of downloaded abi files
104-
16055,tools,Accounts,abis,grabABI,list_items,i,,visible|docs,4,switch,<boolean>,function,,,,a list of the downloaded functions and events in all abi files
104+
16055,tools,Accounts,abis,grabABI,list_funcs,i,,visible|docs,4,switch,<boolean>,function,,,,a list of the functions in all abi files
105+
16055,tools,Accounts,abis,grabABI,list_events,I,,visible|docs,5,switch,<boolean>,function,,,,a list of the events in all abi files
105106
16060,tools,Accounts,abis,grabABI,count,c,,visible|docs,2,switch,<boolean>,count,,,,show the number of abis downloaded
106107
16070,tools,Accounts,abis,grabABI,find,f,,visible|docs,1,flag,list<string>,function,,,,search for function or event declarations given a four- or 32-byte code(s)
107108
16080,tools,Accounts,abis,grabABI,hint,n,,visible|docs,,flag,list<string>,,,,,for the --find option only&#44; provide hints to speed up the search
108-
16090,tools,Accounts,abis,grabABI,encode,e,,visible|docs,5,flag,<string>,function,,,,generate the 32-byte encoding for a given canonical function or event signature
109+
16090,tools,Accounts,abis,grabABI,encode,e,,visible|docs,6,flag,<string>,function,,,,generate the 32-byte encoding for a given canonical function or event signature
109110
16100,tools,Accounts,abis,grabABI,n1,,,,,note,,,,,,Search for either four byte signatures or event signatures with the --find option.
110111
#
111112
21000,,Chain Data,,,,,,,,group,,,,,,Access and cache blockchain-related data

src/dev_tools/sdkFuzzer/abis.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,21 @@ func TestAbis(which, value, fn string, opts *sdk.AbisOptions) {
135135
ReportOkay(fn)
136136
}
137137
}
138-
case "listitems":
139-
if listitems, _, err := opts.AbisListItems(); err != nil {
138+
case "listfuncs":
139+
if listfuncs, _, err := opts.AbisListFuncs(); err != nil {
140140
ReportError(fn, opts, err)
141141
} else {
142-
if err := SaveToFile(fn, listitems); err != nil {
142+
if err := SaveToFile(fn, listfuncs); err != nil {
143+
ReportError2(fn, err)
144+
} else {
145+
ReportOkay(fn)
146+
}
147+
}
148+
case "listevents":
149+
if listevents, _, err := opts.AbisListEvents(); err != nil {
150+
ReportError(fn, opts, err)
151+
} else {
152+
if err := SaveToFile(fn, listevents); err != nil {
143153
ReportError2(fn, err)
144154
} else {
145155
ReportOkay(fn)

src/dev_tools/testRunner/testCases/abis.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ on ,both ,fast ,abis ,tools ,grabABI ,no_abi_found_2 ,y ,addrs =
6565
on ,both ,fast ,abis ,tools ,grabABI ,clean_alone ,y ,decache
6666

6767
on ,both ,fast ,abis ,tools ,grabABI ,list ,y ,list
68+
on ,both ,fast ,abis ,tools ,grabABI ,list_known ,y ,list & known
6869
on ,both ,fast ,abis ,tools ,grabABI ,list_verbose ,y ,list & verbose
70+
on ,both ,fast ,abis ,tools ,grabABI ,list_funcs ,y ,list_funcs & addrs = 0xe94327d07fc17907b4db788e5adf2ed424addff6
71+
on ,both ,fast ,abis ,tools ,grabABI ,list_events ,y ,list_events & addrs = 0xe94327d07fc17907b4db788e5adf2ed424addff6
6972
on ,both ,fast ,abis ,tools ,grabABI ,count ,y ,count
7073
on ,both ,fast ,abis ,tools ,grabABI ,count_v ,y ,count & no_header
7174
on ,both ,fast ,abis ,tools ,grabABI ,count_list ,y ,count & list

tests/gold/apps/chifra/chifra_help_abis.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Flags:
1212
-k, --known load common 'known' ABIs from cache
1313
-r, --proxy_for string redirects the query to this implementation
1414
-l, --list a list of downloaded abi files
15-
-i, --list_items a list of the downloaded functions and events in all abi files
15+
-i, --list_funcs a list of the functions in all abi files
16+
-I, --list_events a list of the events in all abi files
1617
-c, --count show the number of abis downloaded
1718
-f, --find strings search for function or event declarations given a four- or 32-byte code(s)
1819
-n, --hint strings for the --find option only, provide hints to speed up the search
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
abis?listEvents&addrs=0xe94327d07fc17907b4db788e5adf2ed424addff6
2+
{
3+
"data": [
4+
{
5+
"encoding": "0x6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff625",
6+
"name": "Pause",
7+
"signature": "Pause()",
8+
"type": "event"
9+
},
10+
{
11+
"encoding": "0x7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b33",
12+
"name": "Unpause",
13+
"signature": "Unpause()",
14+
"type": "event"
15+
},
16+
{
17+
"encoding": "0x8b80bd19aea7b735bc6d75db8d6adbe18b28c30d62b3555245eb67b2340caedc",
18+
"name": "Migrated",
19+
"signature": "Migrated(address,uint256)",
20+
"type": "event"
21+
},
22+
{
23+
"encoding": "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925",
24+
"name": "Approval",
25+
"signature": "Approval(address,address,uint256)",
26+
"type": "event"
27+
},
28+
{
29+
"encoding": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
30+
"name": "Transfer",
31+
"signature": "Transfer(address,address,uint256)",
32+
"type": "event"
33+
}
34+
],
35+
"meta": {
36+
"client": "0xdeadbeef",
37+
"finalized": "0xdeadbeef",
38+
"staging": "0xdeadbeef",
39+
"ripe": "0xdeadbeef",
40+
"unripe": "0xdeadbeef",
41+
"chainId": 1,
42+
"networkId": 1,
43+
"chain": "mainnet"
44+
}
45+
}

0 commit comments

Comments
 (0)