-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ability to filter incoming events for subscription, added abili…
…ty to have multiple listener canisters
- Loading branch information
1 parent
e0e839d
commit 32138af
Showing
16 changed files
with
571 additions
and
171 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
[ | ||
{ name = "base", repo = "https://github.com/dfinity/motoko-base.git", version = "c174fc4", dependencies = []: List Text }, | ||
{ name = "base", repo = "https://github.com/dfinity/motoko-base.git", version = "moc-0.7.0", dependencies = []: List Text }, | ||
{ name = "candy_0_1_9", repo = "https://github.com/aramakme/candy_library.git", version = "v0.1.9", dependencies = ["base"] }, | ||
{ name = "candy", repo = "https://github.com/aramakme/candy_library.git", version = "v0.1.9", dependencies = ["base"] }, | ||
{ name = "map_4_0_0", repo = "https://github.com/ZhenyaUsenko/motoko-hash-map.git", version = "v4.0.0", dependencies = ["base"] }, | ||
{ name = "map_8_0_0_alpha_5", repo = "https://github.com/ZhenyaUsenko/motoko-hash-map.git", version = "v8.0.0-alpha.5", dependencies = ["base"] }, | ||
{ name = "map", repo = "https://github.com/ZhenyaUsenko/motoko-hash-map.git", version = "v8.0.0-alpha.5", dependencies = ["base"] }, | ||
{ name = "candy_utils_0_2_0", repo = "https://github.com/ZhenyaUsenko/motoko-candy-utils.git", version = "v0.2.0", dependencies = ["base"] }, | ||
{ name = "candy_utils", repo = "https://github.com/ZhenyaUsenko/motoko-candy-utils.git", version = "v0.2.0", dependencies = ["base"] }, | ||
] |
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,100 @@ | ||
import Debug "mo:base/Debug"; | ||
import Iter "mo:base/Iter"; | ||
import Map "mo:map_8_0_0_alpha_5/Map"; | ||
import Option "mo:base/Option"; | ||
import Set "mo:map_8_0_0_alpha_5/Set"; | ||
import MigrationTypes "../types"; | ||
import PrevTypes "../00-02-00-publisher-entities/types"; | ||
import Prim "mo:prim"; | ||
import Types "./types"; | ||
|
||
module { | ||
public func upgrade(migrationState: MigrationTypes.State, args: MigrationTypes.Args): MigrationTypes.State { | ||
let state = switch (migrationState) { case (#v0_2_0(#data(state))) state; case (_) Debug.trap("Unexpected migration state") }; | ||
|
||
let subscribers = Map.map<Principal, PrevTypes.Subscriber, Types.Subscriber>(state.subscribers, func(key, subscriber) = { | ||
id = subscriber.id; | ||
createdAt = subscriber.createdAt; | ||
var activeSubscriptions = subscriber.activeSubscriptions; | ||
listeners = Set.fromIter([subscriber.id].vals(), Map.phash); | ||
confirmedListeners = Set.fromIter([subscriber.id].vals(), Map.phash); | ||
subscriptions = subscriber.subscriptions; | ||
}); | ||
|
||
let subscriptions = Map.map<Text, PrevTypes.SubscriptionGroup, Types.SubscriptionGroup>(state.subscriptions, func(key, subscriptionGroup) { | ||
return Map.map<Principal, PrevTypes.Subscription, Types.Subscription>(subscriptionGroup, func(key, subscription) = { | ||
eventName = subscription.eventName; | ||
subscriberId = subscription.subscriberId; | ||
createdAt = subscription.createdAt; | ||
var skip = subscription.skip; | ||
var skipped = subscription.skipped; | ||
var active = subscription.active; | ||
var stopped = subscription.stopped; | ||
var filter = null; | ||
var filterPath = null; | ||
var numberOfEvents = subscription.numberOfEvents; | ||
var numberOfNotifications = subscription.numberOfNotifications; | ||
var numberOfResendNotifications = subscription.numberOfResendNotifications; | ||
var numberOfRequestedNotifications = subscription.numberOfRequestedNotifications; | ||
var numberOfConfirmations = subscription.numberOfConfirmations; | ||
events = subscription.events; | ||
}) | ||
}); | ||
|
||
return #v0_3_0(#data({ | ||
var eventId = state.eventId; | ||
var broadcastActive = state.broadcastActive; | ||
var nextBroadcastTime = state.nextBroadcastTime; | ||
admins = state.admins; | ||
publishers = state.publishers; | ||
publications = state.publications; | ||
subscribers = subscribers; | ||
subscriptions = subscriptions; | ||
confirmedListeners = Map.new(Map.phash); | ||
events = state.events; | ||
})); | ||
}; | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
public func downgrade(migrationState: MigrationTypes.State, args: MigrationTypes.Args): MigrationTypes.State { | ||
let state = switch (migrationState) { case (#v0_3_0(#data(state))) state; case (_) Debug.trap("Unexpected migration state") }; | ||
|
||
let subscribers = Map.map<Principal, Types.Subscriber, PrevTypes.Subscriber>(state.subscribers, func((key, subscriber)) = { | ||
id = subscriber.id; | ||
createdAt = subscriber.createdAt; | ||
var activeSubscriptions = subscriber.activeSubscriptions; | ||
subscriptions = subscriber.subscriptions; | ||
}); | ||
|
||
let subscriptions = Map.map<Text, Types.SubscriptionGroup, PrevTypes.SubscriptionGroup>(state.subscriptions, func(key, subscriptionGroup) { | ||
return Map.map<Principal, Types.Subscription, PrevTypes.Subscription>(subscriptionGroup, func(key, subscription) = { | ||
eventName = subscription.eventName; | ||
subscriberId = subscription.subscriberId; | ||
createdAt = subscription.createdAt; | ||
var skip = subscription.skip; | ||
var skipped = subscription.skipped; | ||
var active = subscription.active; | ||
var stopped = subscription.stopped; | ||
var numberOfEvents = subscription.numberOfEvents; | ||
var numberOfNotifications = subscription.numberOfNotifications; | ||
var numberOfResendNotifications = subscription.numberOfResendNotifications; | ||
var numberOfRequestedNotifications = subscription.numberOfRequestedNotifications; | ||
var numberOfConfirmations = subscription.numberOfConfirmations; | ||
events = subscription.events; | ||
}) | ||
}); | ||
|
||
return #v0_2_0(#data({ | ||
var eventId = state.eventId; | ||
var broadcastActive = state.broadcastActive; | ||
var nextBroadcastTime = state.nextBroadcastTime; | ||
admins = state.admins; | ||
publishers = state.publishers; | ||
publications = state.publications; | ||
subscribers = subscribers; | ||
subscriptions = subscriptions; | ||
events = state.events; | ||
})); | ||
}; | ||
}; |
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,84 @@ | ||
import Candy "mo:candy_0_1_9/types"; | ||
import CandyUtils "mo:candy_utils_0_2_0/CandyUtils"; | ||
import Map "mo:map_8_0_0_alpha_5/Map"; | ||
import Set "mo:map_8_0_0_alpha_5/Set"; | ||
|
||
module { | ||
public type Publisher = { | ||
id: Principal; | ||
createdAt: Nat64; | ||
var activePublications: Nat8; | ||
publications: Set.Set<Text>; | ||
}; | ||
|
||
public type Publication = { | ||
eventName: Text; | ||
publisherId: Principal; | ||
createdAt: Nat64; | ||
var active: Bool; | ||
var numberOfEvents: Nat64; | ||
var numberOfNotifications: Nat64; | ||
var numberOfResendNotifications: Nat64; | ||
var numberOfRequestedNotifications: Nat64; | ||
var numberOfConfirmations: Nat64; | ||
whitelist: Set.Set<Principal>; | ||
}; | ||
|
||
public type Subscriber = { | ||
id: Principal; | ||
createdAt: Nat64; | ||
var activeSubscriptions: Nat8; | ||
listeners: Set.Set<Principal>; | ||
confirmedListeners: Set.Set<Principal>; | ||
subscriptions: Set.Set<Text>; | ||
}; | ||
|
||
public type Subscription = { | ||
eventName: Text; | ||
subscriberId: Principal; | ||
createdAt: Nat64; | ||
var skip: Nat8; | ||
var skipped: Nat8; | ||
var active: Bool; | ||
var stopped: Bool; | ||
var filter: ?Text; | ||
var filterPath: ?CandyUtils.Path; | ||
var numberOfEvents: Nat64; | ||
var numberOfNotifications: Nat64; | ||
var numberOfResendNotifications: Nat64; | ||
var numberOfRequestedNotifications: Nat64; | ||
var numberOfConfirmations: Nat64; | ||
events: Set.Set<Nat>; | ||
}; | ||
|
||
public type Event = { | ||
id: Nat; | ||
eventName: Text; | ||
publisherId: Principal; | ||
payload: Candy.CandyValue; | ||
createdAt: Nat64; | ||
var nextBroadcastTime: Nat64; | ||
var numberOfAttempts: Nat8; | ||
resendRequests: Set.Set<Principal>; | ||
subscribers: Map.Map<Principal, Nat8>; | ||
}; | ||
|
||
public type PublicationGroup = Map.Map<Principal, Publication>; | ||
|
||
public type SubscriptionGroup = Map.Map<Principal, Subscription>; | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
public type State = { | ||
var eventId: Nat; | ||
var broadcastActive: Bool; | ||
var nextBroadcastTime: Nat64; | ||
admins: Set.Set<Principal>; | ||
publishers: Map.Map<Principal, Publisher>; | ||
publications: Map.Map<Text, PublicationGroup>; | ||
subscribers: Map.Map<Principal, Subscriber>; | ||
subscriptions: Map.Map<Text, SubscriptionGroup>; | ||
confirmedListeners: Map.Map<Principal, Principal>; | ||
events: Map.Map<Nat, Event>; | ||
}; | ||
}; |
Oops, something went wrong.