Skip to content

Commit

Permalink
Merge pull request #356 from forta-network/ali/forta-1364-add-sdk-sup…
Browse files Browse the repository at this point in the history
…port-to-label-unique-keys

Add label unique key support to sdk
  • Loading branch information
haseebrabbani authored Nov 1, 2023
2 parents bf510f7 + c19dcf1 commit b35aaa3
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions cli/commands/run/server/agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions cli/commands/run/server/alert.proto
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ message Label {
bool remove = 6;
string label = 7;
repeated string metadata = 8;
string uniqueKey = 9;
}

message Source {
Expand Down
1 change: 1 addition & 0 deletions python-sdk/src/forta_agent/alerts_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def get_query(self):
entityType
remove
metadata
uniqueKey
}
addressBloomFilter {
bitset
Expand Down
2 changes: 2 additions & 0 deletions python-sdk/src/forta_agent/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('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
Expand All @@ -34,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}

Expand Down
1 change: 1 addition & 0 deletions python-sdk/src/forta_agent/labels_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get_query(self):
label
metadata
remove
uniqueKey
}
source {
alertHash
Expand Down
1 change: 1 addition & 0 deletions sdk/alerts.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ const getQueryFromAlertOptions = (options: AlertQueryOptions) => {
entityType
remove
metadata
uniqueKey
}
addressBloomFilter {
bitset
Expand Down
8 changes: 6 additions & 2 deletions sdk/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type LabelInput = {
source?: LabelSource;
createdAt?: string;
id?: string;
uniqueKey?: string;
};

export class Label {
Expand All @@ -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) {
Expand All @@ -66,6 +68,7 @@ export class Label {
source,
id,
createdAt,
uniqueKey
}: LabelInput) {
if (typeof entityType == "string") {
entityType = ENTITY_TYPE_STRING_TO_ENUM[entityType];
Expand All @@ -91,7 +94,8 @@ export class Label {
metadata,
source,
id,
createdAt
createdAt,
uniqueKey
);
}
}
1 change: 1 addition & 0 deletions sdk/labels.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const getQueryFromLabelOptions = (options: LabelQueryOptions) => {
label
metadata
remove
uniqueKey
}
source {
alertHash
Expand Down

0 comments on commit b35aaa3

Please sign in to comment.