-
-
Save gabrielnic/865ca122861880770f12e678f5a179b7 to your computer and use it in GitHub Desktop.
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
import Nat "mo:base/Nat"; | |
import Map "mo:base/RBTree"; | |
actor Bucket { | |
type Key = Nat; | |
type Value = Text; | |
let map = Map.RBTree<Key, Value>(Nat.compare); | |
public func get(k : Key) : async ?Value { | |
// assert((k % n) == i); | |
map.get(k); | |
}; | |
public func put(k : Key, v : Value) : async () { | |
// assert((k % n) == i); | |
map.put(k,v); | |
}; | |
}; |
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
import Array "mo:base/Array"; | |
import Cycles "mo:base/ExperimentalCycles"; | |
import Debug "mo:base/Debug"; | |
import Principal "mo:base/Principal"; | |
import Nat "mo:base/Nat"; | |
import Bucket "canister:bucket"; | |
shared ({caller = owner}) actor class Container() { | |
type canister_settings = { | |
controller : ?Principal; | |
compute_allocation: ?Nat; | |
memory_allocation: ?Nat; | |
freezing_threshold: ?Nat; | |
}; | |
type definite_canister_settings = { | |
controller : Principal; | |
freezing_threshold : Nat; | |
memory_allocation : Nat; | |
compute_allocation : Nat; | |
}; | |
type wasm_module = [Nat8]; | |
let IC = | |
actor "aaaaa-aa" : actor { | |
update_settings : { | |
canister_id : Principal; settings : canister_settings; | |
} -> async (); | |
create_canister : { | |
settings : ?canister_settings | |
} -> async { canister_id : Principal }; | |
install_code : shared { | |
arg : [Nat8]; | |
wasm_module : wasm_module; | |
mode : { #reinstall; #upgrade; #install }; | |
canister_id : Principal; | |
} -> async (); | |
canister_status : { canister_id : Principal } -> | |
async { // richer in ic.did | |
status : { #stopped; #stopping; #running }; | |
memory_size : Nat; | |
cycles : Nat; | |
settings : definite_canister_settings; | |
module_hash : ?[Nat8]; | |
}; | |
stop_canister : { canister_id : Principal } -> async (); | |
delete_canister : { canister_id : Principal } -> async (); | |
}; | |
// // Burn half of this actor's cycle balance by provisioning, | |
// // creating, stopping and deleting a fresh canister | |
// // (without ever installing any code) | |
public shared({caller}) func test() : async () { | |
Debug.print("balance before: " # Nat.toText(Cycles.balance())); | |
Cycles.add(Cycles.balance()/2); | |
Debug.print(debug_show("caller")); | |
Debug.print(debug_show(caller)); | |
Debug.print(debug_show("owner")); | |
Debug.print(debug_show(owner)); | |
let cid = await IC.create_canister( { | |
settings = ?{controller = ?(owner); compute_allocation = null; memory_allocation = ?(4194304); freezing_threshold = null; } } ); | |
let status = await IC.canister_status(cid); | |
Debug.print(debug_show(status)); | |
Debug.print(debug_show(cid.canister_id)); | |
// Debug.print(debug_show(Principal.fromActor(Container))); | |
await (IC.update_settings( { | |
canister_id = owner; | |
settings = {controller = ?(caller); compute_allocation = null; memory_allocation = ?(4194304); freezing_threshold = null;} })); | |
let status2 = await IC.canister_status(cid); | |
Debug.print(debug_show(status2)); | |
// await IC.stop_canister(cid); | |
// await IC.delete_canister(cid); | |
// Debug.print("balance after: " # Nat.toText(Cycles.balance())); | |
}; | |
public func getStatus(a: { canister_id : Principal }) : async () { | |
let status = await IC.canister_status(a); | |
Debug.print(debug_show(status)); | |
}; | |
}; | |
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
dfx canister status --all | |
Canister status call result for bucket. | |
Status: Running | |
Controller: rwlgt-iiaaa-aaaaa-aaaaa-cai | |
Memory allocation: 0 | |
Compute allocation: 0 | |
Freezing threshold: 2_592_000 | |
Memory Size: Nat(BigUint { data: [366506] }) | |
Balance: 4_000_000_000_000 Cycles | |
Module hash: 0xc464c1cba938ce1d195601965875b29b1508968ee56a68ef9535643e6b435cf6 | |
Canister status call result for container. | |
Status: Running | |
Controller: rwlgt-iiaaa-aaaaa-aaaaa-cai | |
Memory allocation: 0 | |
Compute allocation: 0 | |
Freezing threshold: 2_592_000 | |
Memory Size: Nat(BigUint { data: [387070] }) | |
Balance: 4_000_000_000_000 Cycles | |
Module hash: 0x7db5a5243da79688addf5f4499b36d8f2f7dd159178667590321b075dccf366b | |
Debug: | |
[Canister ryjl3-tyaaa-aaaaa-aaaba-cai] balance before: 4000000000000 | |
[Canister ryjl3-tyaaa-aaaaa-aaaba-cai] "caller" | |
[Canister ryjl3-tyaaa-aaaaa-aaaba-cai] vy65w-2bqg5-afoyp-2yo5l-ev2hc-te5gr-y2bxq-vxcqi-jqg6t-pz3rw-oae | |
[Canister ryjl3-tyaaa-aaaaa-aaaba-cai] "owner" | |
[Canister ryjl3-tyaaa-aaaaa-aaaba-cai] rwlgt-iiaaa-aaaaa-aaaaa-cai | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment