- Notifications
You must be signed in to change notification settings - Fork0
icp-hackathons/event_hub
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This repository contains the implementation of theEvent Hub inMotoko programming language forInternet Computer.
In the IC ecosystem, with its diverse set of decentralized applications (canisters), there's a critical need for an efficient mechanism to manage and disseminate events to multiple stakeholders.
Event Hub is a node for managing events, subscribers, and sending events to subscribers.
This canister provides methods for subscribing to events, unsubscribing from events, viewing and clearing event logs, and generating and sending events to subscribers.
Event Hub also provides interoperability with Ethereum RPC methods and uses flexible event types and custom filters.
- Subscriber Management: Functions for subscribing (subscribe) and unsubscribing (unsubscribe) actors to events are implemented, as well as functions for getting a list of all subscribers (getAllSubscribers) and subscribers with certain filters (getSubscribers).
- Generating and sending events: Includes functions to generate events (emitEvent, emitEventGeneral) and send them to subscribers. Events are filtered according to the set subscriber filters.
- Ethereum Interaction: Functions are provided for calling Ethereum RPC methods (callEthgetLogs, callEthgetBlockByNumber, callEthsendRawTransaction).
- Canister Update: The state of the hub is stable and is not lost when the canister is updated.
- Logging: The code provides a logging system to track events and operations within an actor.
Event Hub is a complete solution for event management in the context of Internet Computer, supporting both intra-network and Ethereum blockchain interactions.
Wallets subscribe to the canister event of the ICRC-7 standard in the hub, and when a new canister starts issuing NFTs of that standard and sends an event about it to the hub, all subscribers receive a new NFT source canister ID and can search for NFTs there by address or number.
The canister subscribes to an event in the Ethereum network. The hub periodically checks for the occurrence of this event using the evm_rpc call and notifies the subscriber when it occurs.
Online school issues a digital certificate as NFT for graduatee and create special event.
aVa Reputation canister gets this event notification with token and some reputation points add to certificate.
User received certificate with reputation.Online school issues digital certificate as NFT for graduate and creates special event.
aVa reputation canister gets this event notification with token and some reputation points added to certificate.
User gets certificate with reputation.
Develop full version ofEvent Hub and get it into production
Gather and implement the community's wishes for the events they want
Create a decentralised autonomous organisation (DAO) and hand over the management ofEvent Hub to it.
Event management: TheEvent Hub can emit events to all subscribed subscribers and return the result.
Subscription management: TheEvent Hub can manage subscribers, allowing them to subscribe and unsubscribe.
Ethereum RPC methods: TheEvent Hub can interact with Ethereum RPC methods viaevm_rpc canister.
type Value = variant { Blob : blob; Bool : bool; Text : text; Nat : nat; Nat8 : nat8; Int : int; Array : vec Value; Map : vec record { text; Value }; }; type EventName = variant { #NewCanisterEvent; #EthEvent; #CreateEvent; #BurnEvent; #CollectionCreatedEvent; #CollectionUpdatedEvent; #CollectionDeletedEvent; #AddToCollectionEvent; #RemoveFromCollectionEvent; #InstantReputationUpdateEvent; #AwaitingReputationUpdateEvent; #NewRegistrationEvent; #FeedbackSubmissionEvent; #Unknown; };
Subscribers can subscribe to the Event Hub using the subscribe function. The function takes a Subscriber as input and returns a boolean indicating the success of the operation.
type Subscriber = { callback : Principal; // subscriber's canister_id filter : EventFilter; }; type EventFilter = { eventType : ?EventName; fieldFilters : [EventField]; }; type EventField = { name : Text; value : Blob; };
subscribe : (Subscriber) -> (Bool)
Subscribers can unsubscribe from the Hub using the unsubscribe function. The function takes a Principal as input.
unsubscribe: (Principal) -> ();
Events can be emitted to all subscribed subscribers using the emitEvent function. The function takes an Event as input and returns a Result indicating the success or failure of the operation.
type CanisterId = principal; type EmitEventResult = variant { #SubscribersNotified : SubscribersNotifiedResult; #Answers : AnswersResult; }; type SubscribersNotifiedResult = { successful : [Success]; errors : [SendError]; }; type Success = { canisterId : CanisterId; result : (nat, nat); }; type SendError = { canisterId : CanisterId; error : ErrorType; }; type ErrorType = variant { #CommunicationError; #ProcessingError; #Timeout; #CustomError : text; }; type Answer = { canisterId : CanisterId; result : [(text, Value)]; }; type AnswersResult = { successful : [Answer]; errors : [SendError]; };
emitEventGeneral: (Event) -> EmitEventResult;
The Event Hub provides functions for interacting with Ethereum RPC methods. These functions include callEthgetLogs, callEthgetBlockByNumber, and callEthsendRawTransaction.
This project depends onevm_rpc canister.
cd event_hubdfx deploy --ic
dfx start --background
dfx deps pulldfx deps init evm_rpc --argument'(record { nodesInSubnet = 28 })'dfx deps deploydfx deploy
Contributions are welcome. Please submit a pull request or open an issue to discuss your ideas.
This project is licensed under the terms of the MIT license.