Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/dfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 15 additions & 18 deletions src/distributed/assetstorage.mo
Original file line number Diff line number Diff line change
@@ -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<Path, Contents> = List.nil();
let initializer : Principal = creator;

func eq(a: Path, b: Path): Bool {
return a == b;
};
let db: Tree.RBTree<Path, Contents> = 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<Path, Contents>(db, path, eq, ?contents).0;
db.put(path, contents);
};
};

public query func retrieve(path : Path) : async Contents {
let result = AssocList.find<Path, Contents>(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)
};
};