From 1fa1074d9520109711915928d3ff1b11cec77ed7 Mon Sep 17 00:00:00 2001 From: C-B-Elite Date: Sun, 22 May 2022 10:52:02 +0800 Subject: [PATCH] update ican canister --- src/Lib/Bucket.mo | 5 +++++ src/iCAN.mo | 24 +++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Lib/Bucket.mo b/src/Lib/Bucket.mo index e1eafeb..e04c811 100644 --- a/src/Lib/Bucket.mo +++ b/src/Lib/Bucket.mo @@ -49,6 +49,11 @@ module { ) }; + public func clear(){ + offset := 0; + assets := TrieMap.TrieMap(Nat.equal, Hash.hash); + }; + // return entries public func preupgrade(): (Nat, [(Nat, (Nat64, Nat))]) { var index = 0; diff --git a/src/iCAN.mo b/src/iCAN.mo index 412760b..92e4908 100644 --- a/src/iCAN.mo +++ b/src/iCAN.mo @@ -156,15 +156,19 @@ actor iCAN{ switch(hubs.get(caller)){ case null { #err(#Invalid_Caller) }; case(?ps){ - let res = Array.init<(Text, Principal)>(ps.size() - 1, ("", Principal.fromActor(iCAN))); - var _index = 0; - for(p in ps.vals()){ - if(p.1 != hub_id){ - res[_index] := p; - _index += 1; + if(ps.size() > 1){ + let res = Array.init<(Text, Principal)>(ps.size() - 1, ("", Principal.fromActor(iCAN))); + var _index = 0; + for(p in ps.vals()){ + if(p.1 != hub_id){ + res[_index] := p; + _index += 1; + }; }; + hubs.put(caller, Array.freeze<(Text, Principal)>(res)); + }else{ + hubs.delete(caller); }; - hubs.put(caller, Array.freeze<(Text, Principal)>(res)); #ok(()) } } @@ -229,6 +233,12 @@ actor iCAN{ } }; + public shared({caller}) func clearLog() : async (){ + assert(TrieSet.mem(administrators, caller, Principal.hash(caller), Principal.equal)); + log_index := 0; + logs.clear(); + }; + private func _addHub(owner : Principal, args : (Text, Principal)){ switch(hubs.get(owner)){ case(null) { hubs.put(owner,[args]) };