chainhook icon indicating copy to clipboard operation
chainhook copied to clipboard

Add sub-commands to "list" and "create" hooks for the observable events in a given contract

Open sabbyanandan opened this issue 2 years ago • 0 comments

As a developer, I would like to list all the possible observable events in my contract so that I can review and, as a next step, create hook(s) automatically instead of manually interpreting, analyzing what is supported, and creating them.

Currently, clarity-events as a binary provides the list of the possible events observable for a given contract.

Current behavior:

╰─$ clarity-events --version clarity-events 1.0.0

╭─sabbyanandan ~/hiro/clarinet/components/clarity-events ‹ruby-2.7.6› ‹develop●› ╰─$ clarity-events scan ./../clarinet-cli/examples/billboard/contracts/billboard.clar set-message {"event_type":"transfer_stx_event"}

We could add the additional subcommands in Chainhooks CLI:

╰─$ chainhook list-contract-events --contract-path=./test.clar

Furthermore, if I want to create hooks from the available events, I could review the list and choose one of the following events through the CLI navigation. By submitting the selection against chainhooks, the new hooks definition can be generated automatically:

╰─$ chainhook predicates new token.json --contract-path=./test.clar [0] {"event_type":"print","print":{"data_type":{"value":"hello","type":"string"}}} [1] ...

While we are exploring these options, I would suggest improving the response payload and description. For instance,

╭─sabbyanandan ~/hiro/clarinet/components/clarity-events ‹ruby-2.7.6› ‹develop●› ╰─$ clarity-events scan ./../clarinet-cli/examples/simple-nft/contracts/simple-nft.clar Error path: [Diagnostic { level: Error, message: "use of undeclared trait ", spans: [], suggestion: Some("traits should be either defined, with define-trait, or imported, with use-trait.") }]

It'd be helpful for me as a developer as to understand what I need to do to get around this error.

sabbyanandan avatar Jun 06 '23 18:06 sabbyanandan