Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow matching with regex for stacks print_event #380

Merged
merged 3 commits into from
Aug 15, 2023

Conversation

MicaiahReid
Copy link
Contributor

@MicaiahReid MicaiahReid commented Aug 11, 2023

Description

This PR introduces the ability to match on a print_event's values with a regex string rather than just with the previous contains field.

Fixes #348

Example

This allows the following new if_this condition for a stacks predicate:

{
  "scope": "print_event",
  "contract_identifier": "ST3AXH4EBHD63FCFPTZ8GR29TNTVWDYPGY0KDY5E5.loan-data",
  "regex": "... some regex to match on the event data"
}

Checklist

  • All tests pass
  • Tests added in this PR (if applicable)

pub contract_identifier: String,
pub contains: String,
#[serde(untagged)]
pub enum StacksPrintEventBasedPredicate {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like that we have to duplicate the definition of contract_identifier here. If anyone knows a way around this, that would be sick. That's what lead me down the path of the breaking change PR (#379), but I guess it's probably worth it to not break the API so soon after releasing v1.

Copy link
Contributor

@lgalabru lgalabru Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. After toying with serde, it does not look like something supported - which sounds reasonable, as this could lead to one json payload resulting to multiple different struct.
If we really wanted to avoid the repetition, we could move to something like this:

struct Predicate {
   contract_identifier: T,
   contains: Option<U>,
   matches: Option<V>
}

and associate a method to that struct to make it more usable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that is an option.

In this case I guess we could treat this as an "OR", so we match any that contain or regex match if both values are provided. I think it maybe sets a weird precedence for how we do this in the future - it would feel clunky to have a predicate type with many Options that are only really intended to be used alone, but the user can specify all of them. And if we ever need to make them mutually exclusive (you can have fieldA OR fieldB specified in the predicate, but not both), we wouldn't be able to represent this in an openapi spec.

All of that makes me lean toward the current solution, but no particularly strongly. Do you have a preference, @lgalabru?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of that makes me lean toward the current solution

Agreed!

@MicaiahReid MicaiahReid marked this pull request as ready for review August 11, 2023 01:22
@aulneau
Copy link

aulneau commented Aug 13, 2023

awesome, this looks great. will make use of it as soon as it can be released/deployed :~)

Copy link
Contributor

@lgalabru lgalabru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great, thanks Micaiah!
With this addition, we should probably start thinking about a way to measure predicate evaluation performance.

@MicaiahReid MicaiahReid force-pushed the regex-contains-print_event-non-breaking branch from bf9bdb6 to e8f869d Compare August 15, 2023 14:32
@MicaiahReid MicaiahReid merged commit 131809e into develop Aug 15, 2023
@MicaiahReid MicaiahReid deleted the regex-contains-print_event-non-breaking branch August 15, 2023 14:56
github-actions bot pushed a commit that referenced this pull request Oct 10, 2023
## [1.1.0](v1.0.0...v1.1.0) (2023-10-10)

### Features

* allow matching with regex for stacks print_event ([#380](#380)) ([131809e](131809e)), closes [#348](#348)
* augment predicate status returned by GET/LIST endpoints ([#397](#397)) ([a100263](a100263)), closes [#396](#396) [#324](#324) [#390](#390) [#402](#402) [#403](#403)
* introduce "data_handler_tx" ([ee486f3](ee486f3))

### Bug Fixes

* build error ([85d4d91](85d4d91))
* build errors ([b9ff1aa](b9ff1aa))
* build errro ([be0c229](be0c229))
* bump retries and delays ([aff3690](aff3690))
* chainhook not being registered ([5a809c6](5a809c6))
* ensure that the parent block was previously received. else, fetch it ([2755266](2755266))
* migrate to finer zmq lib ([4eb5a07](4eb5a07))
* prevent panic when scanning from genesis block ([#408](#408)) ([1868a06](1868a06))
* remove event_handlers ([6fecfd2](6fecfd2))
* retrieve blocks until tip ([5213f5f](5213f5f))
* revisit approach ([67a34dc](67a34dc))
* use crossbeam channels ([ea33553](ea33553))
* workflow ([d434c93](d434c93))
@github-actions
Copy link

🎉 This PR is included in version 1.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

MicaiahReid pushed a commit that referenced this pull request Oct 10, 2023
## [1.1.0](v1.0.0...v1.1.0) (2023-10-10)

### Features

* allow matching with regex for stacks print_event ([#380](#380)) ([131809e](131809e)), closes [#348](#348)
* augment predicate status returned by GET/LIST endpoints ([#397](#397)) ([a100263](a100263)), closes [#396](#396) [#324](#324) [#390](#390) [#402](#402) [#403](#403)
* introduce "data_handler_tx" ([ee486f3](ee486f3))

### Bug Fixes

* build error ([85d4d91](85d4d91))
* build errors ([b9ff1aa](b9ff1aa))
* build errro ([be0c229](be0c229))
* bump retries and delays ([aff3690](aff3690))
* chainhook not being registered ([5a809c6](5a809c6))
* ensure that the parent block was previously received. else, fetch it ([2755266](2755266))
* migrate to finer zmq lib ([4eb5a07](4eb5a07))
* prevent panic when scanning from genesis block ([#408](#408)) ([1868a06](1868a06))
* remove event_handlers ([6fecfd2](6fecfd2))
* retrieve blocks until tip ([5213f5f](5213f5f))
* revisit approach ([67a34dc](67a34dc))
* use crossbeam channels ([ea33553](ea33553))
* workflow ([d434c93](d434c93))
vabanaerytk added a commit to vabanaerytk/chainhook that referenced this pull request Aug 7, 2024
## [1.1.0](hirosystems/chainhook@v1.0.0...v1.1.0) (2023-10-10)

### Features

* allow matching with regex for stacks print_event ([#380](hirosystems/chainhook#380)) ([af0fcad](hirosystems/chainhook@af0fcad)), closes [#348](hirosystems/chainhook#348)
* augment predicate status returned by GET/LIST endpoints ([#397](hirosystems/chainhook#397)) ([0f32704](hirosystems/chainhook@0f32704)), closes [#396](hirosystems/chainhook#396) [#324](hirosystems/chainhook#324) [#390](hirosystems/chainhook#390) [#402](hirosystems/chainhook#402) [#403](hirosystems/chainhook#403)
* introduce "data_handler_tx" ([a7704d8](hirosystems/chainhook@a7704d8))

### Bug Fixes

* build error ([9d47f87](hirosystems/chainhook@9d47f87))
* build errors ([27b0ae4](hirosystems/chainhook@27b0ae4))
* build errro ([6363fad](hirosystems/chainhook@6363fad))
* bump retries and delays ([483663c](hirosystems/chainhook@483663c))
* chainhook not being registered ([7d2b156](hirosystems/chainhook@7d2b156))
* ensure that the parent block was previously received. else, fetch it ([79561c8](hirosystems/chainhook@79561c8))
* migrate to finer zmq lib ([2e55a20](hirosystems/chainhook@2e55a20))
* prevent panic when scanning from genesis block ([#408](hirosystems/chainhook#408)) ([4ab8dd8](hirosystems/chainhook@4ab8dd8))
* remove event_handlers ([e3664d2](hirosystems/chainhook@e3664d2))
* retrieve blocks until tip ([d21cacc](hirosystems/chainhook@d21cacc))
* revisit approach ([47d2ef6](hirosystems/chainhook@47d2ef6))
* use crossbeam channels ([50595ab](hirosystems/chainhook@50595ab))
* workflow ([84c4ec9](hirosystems/chainhook@84c4ec9))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Allow regex for contains based chainhooks
3 participants