Skip to content

Commit

Permalink
update ican canister
Browse files Browse the repository at this point in the history
  • Loading branch information
eliezhao committed May 22, 2022
1 parent 80f3dd8 commit 1fa1074
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/Lib/Bucket.mo
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ module {
)
};

public func clear(){
offset := 0;
assets := TrieMap.TrieMap<Nat, (Nat64, Nat)>(Nat.equal, Hash.hash);
};

// return entries
public func preupgrade(): (Nat, [(Nat, (Nat64, Nat))]) {
var index = 0;
Expand Down
24 changes: 17 additions & 7 deletions src/iCAN.mo
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
Expand Down Expand Up @@ -229,6 +233,12 @@ actor iCAN{
}
};

public shared({caller}) func clearLog() : async (){
assert(TrieSet.mem<Principal>(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]) };
Expand Down

0 comments on commit 1fa1074

Please sign in to comment.