-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move event listener to blocks/eventManager
- Loading branch information
Showing
19 changed files
with
306 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from './eventListeners'; | ||
export * from './types'; | ||
export * from './colony'; | ||
export * from './network'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { EventManager } from '@joincolony/blocks'; | ||
|
||
const eventManager = new EventManager(); | ||
|
||
export default eventManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@joincolony/blocks", | ||
"main": "src/index.ts", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"@joincolony/utils": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { verbose } from '@joincolony/utils'; | ||
import { EventListener } from './types'; | ||
|
||
export class EventManager { | ||
private listeners: EventListener[] = []; | ||
|
||
public getEventListeners(): EventListener[] { | ||
return this.listeners; | ||
} | ||
|
||
public setEventListeners(newListeners: EventListener[]): void { | ||
this.listeners = newListeners; | ||
} | ||
|
||
public addEventListener(listener: EventListener): void { | ||
verbose( | ||
`Added listener for event ${listener.eventSignature}`, | ||
listener.address ? `filtering address ${listener.address}` : '', | ||
); | ||
this.listeners.push(listener); | ||
} | ||
|
||
public getMatchingListeners( | ||
logTopics: string[], | ||
logAddress: string, | ||
): EventListener[] { | ||
return this.listeners.filter((listener) => { | ||
if (listener.address && logAddress !== listener.address) { | ||
return false; | ||
} | ||
|
||
if (listener.topics.length > logTopics.length) { | ||
return false; | ||
} | ||
|
||
return listener.topics.every((topic, index) => { | ||
return ( | ||
topic === null || | ||
topic.toLowerCase() === logTopics[index].toLowerCase() | ||
); | ||
}); | ||
}); | ||
} | ||
|
||
public getListenersStats(): string { | ||
return JSON.stringify(this.listeners); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './eventManager'; | ||
export * from './types'; |
Oops, something went wrong.