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

Enable contract listeners with multiple filters #1418

Merged
merged 32 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
25c32e3
Enable contract listeners with multiple filters
nguyer Oct 12, 2023
135cfb0
WIP: More work on multiple filters
nguyer Feb 28, 2024
7f233a0
Fixes for multiple filters
nguyer Mar 6, 2024
5a73d6f
New contract listener Hash API
EnriqueL8 Jun 7, 2024
ad9cca2
Review comments
EnriqueL8 Jun 12, 2024
0ddb3d1
revert this
EnriqueL8 Jun 12, 2024
e5b91e7
More review comments
EnriqueL8 Jun 12, 2024
d004e15
check filters in blockchain plugins
EnriqueL8 Jun 12, 2024
230d707
more fixes and test
EnriqueL8 Jun 12, 2024
3cb7f78
Merge remote-tracking branch 'origin/main' into filters
EnriqueL8 Jun 12, 2024
1d37c4c
fix mocks and tests
EnriqueL8 Jun 12, 2024
165bfa1
New implementation of filters for contract listeners
EnriqueL8 Jun 21, 2024
d713123
Add indexed position to ABI event signature
EnriqueL8 Jun 21, 2024
0ea504f
more fixes and 100% test coverage
EnriqueL8 Jul 2, 2024
5ba07f8
fix filters in evmconnect
EnriqueL8 Jul 2, 2024
1d86f95
fix migration
EnriqueL8 Jul 3, 2024
1d6ae91
more fixes and migrations
EnriqueL8 Jul 3, 2024
c83c6be
Move migrations to startup
EnriqueL8 Jul 3, 2024
69fd561
do not migrate the signature
EnriqueL8 Jul 3, 2024
ef8edb9
fix collection event
EnriqueL8 Jul 3, 2024
0b61f86
fix previous signature lookup and location
EnriqueL8 Jul 4, 2024
8320273
fix PSQL migration
EnriqueL8 Jul 4, 2024
26efff4
fix ethconnect subscriptions
EnriqueL8 Jul 4, 2024
66436d3
a few more tweaks
EnriqueL8 Jul 8, 2024
4ac0235
finally got to 100% coverage
EnriqueL8 Jul 8, 2024
12e018b
Move the signature with location to the blockchain plugins
EnriqueL8 Jul 11, 2024
d6cfa8f
Merge remote-tracking branch 'origin/main' into filters
EnriqueL8 Jul 11, 2024
e43809c
fix test after conflicts
EnriqueL8 Jul 11, 2024
c85c247
fix coverage for sqlcommon
EnriqueL8 Jul 11, 2024
9777588
Update internal/blockchain/ethereum/ethereum.go
EnriqueL8 Jul 11, 2024
a468891
fix linting
EnriqueL8 Jul 11, 2024
fc18b63
move to VARCHAR for postgres
EnriqueL8 Jul 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"program": "${workspaceFolder}/main.go",
"args": [
"-f",
"${env:HOME}/.firefly/stacks/dev/runtime/config/firefly_core_0.yml"
"${env:HOME}/.firefly/stacks/listeners/runtime/config/firefly_core_0.yml"
EnriqueL8 marked this conversation as resolved.
Show resolved Hide resolved
]
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN;
ALTER TABLE contractlisteners DROP COLUMN filters;
DROP INDEX contractlisteners_filter_hash;
ALTER TABLE contractlisteners DROP COLUMN filter_hash;
COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BEGIN;
ALTER TABLE contractlisteners ADD COLUMN filters TEXT;
peterbroadhurst marked this conversation as resolved.
Show resolved Hide resolved
ALTER TABLE contractlisteners ALTER COLUMN event DROP NOT NULL;
ALTER TABLE contractlisteners ALTER COLUMN location DROP NOT NULL;
ALTER TABLE contractlisteners ALTER COLUMN signature DROP NOT NULL;
ALTER TABLE contractlisteners ADD COLUMN filter_hash CHAR(64);
CREATE INDEX contractlisteners_filter_hash ON contractlisteners(filter_hash);
EnriqueL8 marked this conversation as resolved.
Show resolved Hide resolved
COMMIT:
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE contractlisteners DROP COLUMN filters;
DROP INDEX contractlisteners_filter_hash;
ALTER TABLE contractlisteners DROP COLUMN filter_hash;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALTER TABLE contractlisteners ADD COLUMN filters TEXT;
ALTER TABLE contractlisteners ADD COLUMN filter_hash CHAR(64);
CREATE INDEX contractlisteners_filter_hash ON contractlisteners(filter_hash);

-- SQLite doesn't support dropping NOT NULL constraints so we have to move
-- everything to a temp colum, create a new column, then copy the data back
ALTER TABLE contractlisteners RENAME COLUMN event TO event_tmp;
ALTER TABLE contractlisteners RENAME COLUMN location TO location_tmp;
ALTER TABLE contractlisteners ADD COLUMN event TEXT;
ALTER TABLE contractlisteners ADD LOCATION event TEXT;
UPDATE contractlisteners SET event = event_tmp;
UPDATE contractlisteners SET location = location_tmp;
ALTER TABLE contractlisteners DROP COLUMN event_tmp;
ALTER TABLE contractlisteners DROP COLUMN location_tmp;
18 changes: 15 additions & 3 deletions docs/reference/types/contractlistener.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,18 @@ nav_order: 10
| Field Name | Description | Type |
|------------|-------------|------|
| `id` | The UUID of the smart contract listener | [`UUID`](simpletypes#uuid) |
| `interface` | A reference to an existing FFI, containing pre-registered type information for the event | [`FFIReference`](#ffireference) |
| `interface` | Deprecated: Please use 'interface' in the array of 'filters' instead | [`FFIReference`](#ffireference) |
| `namespace` | The namespace of the listener, which defines the namespace of all blockchain events detected by this listener | `string` |
| `name` | A descriptive name for the listener | `string` |
| `backendId` | An ID assigned by the blockchain connector to this listener | `string` |
| `location` | A blockchain specific contract identifier. For example an Ethereum contract address, or a Fabric chaincode name and channel | [`JSONAny`](simpletypes#jsonany) |
| `location` | Deprecated: Please use 'location' in the array of 'filters' instead | [`JSONAny`](simpletypes#jsonany) |
| `created` | The creation time of the listener | [`FFTime`](simpletypes#fftime) |
| `event` | The definition of the event, either provided in-line when creating the listener, or extracted from the referenced FFI | [`FFISerializedEvent`](#ffiserializedevent) |
| `event` | Deprecated: Please use 'event' in the array of 'filters' instead | [`FFISerializedEvent`](#ffiserializedevent) |
| `signature` | The stringified signature of the event, as computed by the blockchain plugin | `string` |
| `topic` | A topic to set on the FireFly event that is emitted each time a blockchain event is detected from the blockchain. Setting this topic on a number of listeners allows applications to easily subscribe to all events they need | `string` |
| `options` | Options that control how the listener subscribes to events from the underlying blockchain | [`ContractListenerOptions`](#contractlisteneroptions) |
| `filters` | A list of filters for the contract listener. Each filter is made up of an Event and an optional Location. Events matching these filters will always be emitted in the order determined by the blockchain. | [`ListenerFilter[]`](#listenerfilter) |
| `filterHash` | This is the hash of the filters provided, useful to be able to retrieve a unique contract listener. | `Bytes32` |

## FFIReference

Expand Down Expand Up @@ -109,3 +111,13 @@ nav_order: 10
| `firstEvent` | A blockchain specific string, such as a block number, to start listening from. The special strings 'oldest' and 'newest' are supported by all blockchain connectors. Default is 'newest' | `string` |


## ListenerFilter

| Field Name | Description | Type |
|------------|-------------|------|
| `event` | The definition of the event, either provided in-line when creating the listener, or extracted from the referenced FFI | [`FFISerializedEvent`](#ffiserializedevent) |
| `location` | A blockchain specific contract identifier. For example an Ethereum contract address, or a Fabric chaincode name and channel | [`JSONAny`](simpletypes#jsonany) |
| `interface` | A reference to an existing FFI, containing pre-registered type information for the event | [`FFIReference`](#ffireference) |
| `signature` | The stringified signature of the event, as computed by the blockchain plugin | `string` |


Loading