diff --git a/Cargo.lock b/Cargo.lock index 879c9d6a89..e1bce963f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -642,9 +642,9 @@ dependencies = [ [[package]] name = "candid" -version = "0.6.4" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27809afd71dc33263f06d5c0cd30d498710954adb8c6e4ae8330a818c644a32b" +checksum = "3ccf4490c14ff64cac64a3b7dabc3cd7270ebc096eae12c745c3ad6882385198" dependencies = [ "byteorder", "candid_derive", diff --git a/src/dfx/Cargo.toml b/src/dfx/Cargo.toml index b4c11fb253..f2f10e5a9e 100644 --- a/src/dfx/Cargo.toml +++ b/src/dfx/Cargo.toml @@ -21,7 +21,7 @@ actix-server = "1.0.3" actix-web = { version = "2.0.0", features = [ "default", "openssl", "rustls" ] } atty = "0.2.13" base64 = "0.11.0" -candid = "0.6.4" +candid = "0.6.6" chrono = "0.4.9" clap = "2.33.0" console = "0.7.7" diff --git a/src/distributed/assetstorage.mo b/src/distributed/assetstorage.mo index eb6fa747e3..73c2f73ed3 100644 --- a/src/distributed/assetstorage.mo +++ b/src/distributed/assetstorage.mo @@ -1,37 +1,34 @@ -import AssocList "mo:base/AssocList"; import Error "mo:base/Error"; -import List "mo:base/List"; -import Prim "mo:prim"; +import Tree "mo:base/RBTree"; +import Text "mo:base/Text"; +import Iter "mo:base/Iter"; -actor { +shared {caller = creator} actor class () { public type Path = Text; - public type Contents = Blob; - private let initializer : Principal = Prim.caller(); - - private stable var db: AssocList.AssocList = List.nil(); + let initializer : Principal = creator; - func eq(a: Path, b: Path): Bool { - return a == b; - }; + let db: Tree.RBTree = Tree.RBTree(Text.compare); public shared { caller } func store(path : Path, contents : Contents) : async () { if (caller != initializer) { throw Error.reject("not authorized"); } else { - db := AssocList.replace(db, path, eq, ?contents).0; + db.put(path, contents); }; }; public query func retrieve(path : Path) : async Contents { - let result = AssocList.find(db, path, eq); - switch result { - case null { - throw Error.reject("not found"); - }; - case (?contents) contents; + switch (db.get(path)) { + case null throw Error.reject("not found"); + case (?contents) contents; }; }; + + public query func list() : async [Path] { + let iter = Iter.map<(Path, Contents), Path>(db.entries(), func (path, _) = path); + Iter.toArray(iter) + }; };