From 70669a42f896d7e485bc815374813afba640b303 Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 1 Nov 2023 17:43:42 +0300 Subject: [PATCH 1/3] add unique key support to sdk --- cli/commands/run/server/agent.proto | 6 +++--- python-sdk/src/forta_agent/label.py | 1 + python-sdk/src/forta_agent/labels_api.py | 1 + sdk/label.ts | 8 ++++++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cli/commands/run/server/agent.proto b/cli/commands/run/server/agent.proto index 41c0e37..346a046 100644 --- a/cli/commands/run/server/agent.proto +++ b/cli/commands/run/server/agent.proto @@ -296,16 +296,16 @@ message AlertEvent { message SourceAlertEvent { string botId = 1; - string hash = 2; + string alertHash = 2; string timestamp = 3; - uint64 chainId = 4; + string chainId = 4; } message Source { string transactionHash = 1; Bot bot = 2; Block block = 3; - SourceAlertEvent sourceAlert = 4; + SourceAlertEvent sourceEvent = 4; } message Label { diff --git a/python-sdk/src/forta_agent/label.py b/python-sdk/src/forta_agent/label.py index e6acbb0..30493bf 100644 --- a/python-sdk/src/forta_agent/label.py +++ b/python-sdk/src/forta_agent/label.py @@ -21,6 +21,7 @@ def __init__(self, dict): self.confidence = dict['confidence'] self.label = dict['label'] self.remove = dict.get('remove', False) + self.unique_key = dict.get('uniqueKey', False) self.metadata = dict.get('metadata') if dict.get( 'metadata') is not None else {} # if metadata is array, convert to map diff --git a/python-sdk/src/forta_agent/labels_api.py b/python-sdk/src/forta_agent/labels_api.py index ad50359..aab463b 100644 --- a/python-sdk/src/forta_agent/labels_api.py +++ b/python-sdk/src/forta_agent/labels_api.py @@ -54,6 +54,7 @@ def get_query(self): label metadata remove + uniqueKey } source { alertHash diff --git a/sdk/label.ts b/sdk/label.ts index 340b9af..256f2b5 100644 --- a/sdk/label.ts +++ b/sdk/label.ts @@ -37,6 +37,7 @@ type LabelInput = { source?: LabelSource; createdAt?: string; id?: string; + uniqueKey?: string; }; export class Label { @@ -49,7 +50,8 @@ export class Label { readonly metadata: { [key: string]: string }, readonly source?: LabelSource, readonly id?: string, - readonly createdAt?: string + readonly createdAt?: string, + readonly uniqueKey?: string ) {} static from(labelInput: LabelInput) { @@ -66,6 +68,7 @@ export class Label { source, id, createdAt, + uniqueKey }: LabelInput) { if (typeof entityType == "string") { entityType = ENTITY_TYPE_STRING_TO_ENUM[entityType]; @@ -91,7 +94,8 @@ export class Label { metadata, source, id, - createdAt + createdAt, + uniqueKey ); } } From 149bc7d9b7e5367500d7484c090d2aba887688be Mon Sep 17 00:00:00 2001 From: Haseeb Rabbani Date: Wed, 1 Nov 2023 16:46:05 -0400 Subject: [PATCH 2/3] adjustments --- cli/commands/run/server/agent.proto | 7 ++++--- python-sdk/src/forta_agent/alerts_api.py | 1 + python-sdk/src/forta_agent/label.py | 3 ++- sdk/alerts.api.ts | 1 + sdk/labels.api.ts | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cli/commands/run/server/agent.proto b/cli/commands/run/server/agent.proto index 346a046..95b9af4 100644 --- a/cli/commands/run/server/agent.proto +++ b/cli/commands/run/server/agent.proto @@ -296,16 +296,16 @@ message AlertEvent { message SourceAlertEvent { string botId = 1; - string alertHash = 2; + string hash = 2; string timestamp = 3; - string chainId = 4; + uint64 chainId = 4; } message Source { string transactionHash = 1; Bot bot = 2; Block block = 3; - SourceAlertEvent sourceEvent = 4; + SourceAlertEvent sourceAlert = 4; } message Label { @@ -315,6 +315,7 @@ message AlertEvent { string entityType = 4; bool remove = 5; repeated string metadata = 6; + string uniqueKey = 7; } // Unique string to identify this class of finding, diff --git a/python-sdk/src/forta_agent/alerts_api.py b/python-sdk/src/forta_agent/alerts_api.py index 2846a59..6956b77 100644 --- a/python-sdk/src/forta_agent/alerts_api.py +++ b/python-sdk/src/forta_agent/alerts_api.py @@ -182,6 +182,7 @@ def get_query(self): entityType remove metadata + uniqueKey } addressBloomFilter { bitset diff --git a/python-sdk/src/forta_agent/label.py b/python-sdk/src/forta_agent/label.py index 30493bf..37239b3 100644 --- a/python-sdk/src/forta_agent/label.py +++ b/python-sdk/src/forta_agent/label.py @@ -21,7 +21,7 @@ def __init__(self, dict): self.confidence = dict['confidence'] self.label = dict['label'] self.remove = dict.get('remove', False) - self.unique_key = dict.get('uniqueKey', False) + self.unique_key = dict.get('unique_key', dict.get('uniqueKey')) self.metadata = dict.get('metadata') if dict.get( 'metadata') is not None else {} # if metadata is array, convert to map @@ -35,6 +35,7 @@ def __init__(self, dict): def toDict(self): d = dict(self.__dict__, **{ 'entityType': self.entity_type, + 'uniqueKey': self.unique_key, }) return {k: v for k, v in d.items() if v is not None} diff --git a/sdk/alerts.api.ts b/sdk/alerts.api.ts index 910a424..d869669 100644 --- a/sdk/alerts.api.ts +++ b/sdk/alerts.api.ts @@ -233,6 +233,7 @@ const getQueryFromAlertOptions = (options: AlertQueryOptions) => { entityType remove metadata + uniqueKey } addressBloomFilter { bitset diff --git a/sdk/labels.api.ts b/sdk/labels.api.ts index fe15bf6..083ff59 100644 --- a/sdk/labels.api.ts +++ b/sdk/labels.api.ts @@ -131,6 +131,7 @@ export const getQueryFromLabelOptions = (options: LabelQueryOptions) => { label metadata remove + uniqueKey } source { alertHash From c19dcf101db22e99c165a57cdd813ec3ffe17556 Mon Sep 17 00:00:00 2001 From: Haseeb Rabbani Date: Wed, 1 Nov 2023 16:50:23 -0400 Subject: [PATCH 3/3] update alert.proto --- cli/commands/run/server/alert.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/commands/run/server/alert.proto b/cli/commands/run/server/alert.proto index ff80c85..16c0899 100644 --- a/cli/commands/run/server/alert.proto +++ b/cli/commands/run/server/alert.proto @@ -90,6 +90,7 @@ message Label { bool remove = 6; string label = 7; repeated string metadata = 8; + string uniqueKey = 9; } message Source {