Skip to content

Commit

Permalink
testnet script (#241)
Browse files Browse the repository at this point in the history
* add deploy script

* fix

* fix

* fix

* works

* work with non-verbose mode

* build motoko

* WIP: frontend bindgen

* bindgen

* everything works

* fix

* fix

* revert testnet code, keep it somewhere else
  • Loading branch information
chenyan-dfinity authored Jul 29, 2024
1 parent f6681cd commit 4bc023f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
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

0 comments on commit 4bc023f

Please sign in to comment.