Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testnet script #241

Merged
merged 13 commits into from
Jul 29, 2024
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
node_modules
/.pnp
.pnp.js

Expand All @@ -12,6 +12,7 @@
.dfx
/build
target/
*.env

# misc
.DS_Store
Expand Down
28 changes: 21 additions & 7 deletions service/pool/Main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,11 @@ shared (creator) actor class Self(opt_params : ?Types.InitParams) = this {
return true;
};

// Combine create_canister and install_code into a single update call. If no_uninstall is set, args should be null, and returns the current available canister id.
public shared ({ caller }) func deployCanister(opt_info: ?Types.CanisterInfo, args: ?Types.DeployArgs) : async Types.CanisterInfo {
// Combine create_canister and install_code into a single update call. Returns the current available canister id.
public shared ({ caller }) func deployCanister(opt_info: ?Types.CanisterInfo, args: ?Types.DeployArgs) : async (Types.CanisterInfo, {#install; #upgrade; #reinstall}) {
if (not Principal.isController(caller)) {
throw Error.reject "Only called by controller";
};
let no_uninstall = Option.get(params.no_uninstall, false);
if (no_uninstall and Option.isSome(args)) {
throw Error.reject "Cannot specify args when no_uninstall is set";
};
let origin = { origin = "admin"; tags = [] };
let (info, mode) = switch (opt_info) {
case null { await* getExpiredCanisterInfo(origin) };
Expand All @@ -164,7 +160,13 @@ shared (creator) actor class Self(opt_params : ?Types.InitParams) = this {
};
case null {};
};
info
switch (pool.refresh(info, false)) {
case (?newInfo) {
updateTimer<system>(newInfo);
(newInfo, mode);
};
case null { throw Error.reject "Cannot find canister" };
};
};

public shared ({ caller }) func getCanisterId(nonce : PoW.Nonce, origin : Logs.Origin) : async Types.CanisterInfo {
Expand Down Expand Up @@ -280,6 +282,17 @@ shared (creator) actor class Self(opt_params : ?Types.InitParams) = this {
stats := Logs.updateStats(stats, #mismatch);
};
};
public shared({caller}) func releaseAllCanisters() : async () {
if (not Principal.isController(caller)) {
throw Error.reject "only called by controllers";
};
for (info in pool.getAllCanisters()) {
if (not Option.get(params.no_uninstall, false)) {
await IC.uninstall_code { canister_id = info.id };
};
ignore pool.retire info;
};
};

public func GCCanisters() {
for (id in pool.gcList().vals()) {
Expand Down Expand Up @@ -490,6 +503,7 @@ shared (creator) actor class Self(opt_params : ?Types.InitParams) = this {
#http_request : Any;
#installCode : Any;
#deployCanister : Any;
#releaseAllCanisters : Any;
#removeCode : Any;
#resetStats : Any;
#mergeTags : Any;
Expand Down
3 changes: 3 additions & 0 deletions service/pool/Types.mo
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ module {
};
result
};
public func getAllCanisters() : Iter.Iter<CanisterInfo> {
tree.entries();
};

public func share() : ([CanisterInfo], [(Principal, (Int, Bool))], [(Principal, [Principal])], [CanisterInfo]) {
let stableInfos = Iter.toArray(tree.entries());
Expand Down
Loading