diff --git a/Example_Aramakme_License/example_lib.mo b/Example_Aramakme_License/example_lib.mo index 9bc69a6..dc32531 100644 --- a/Example_Aramakme_License/example_lib.mo +++ b/Example_Aramakme_License/example_lib.mo @@ -243,6 +243,7 @@ module { public type UpdateMode = { #Set : CandyValue; + #Lock : CandyValue; #Next : [Update]; }; diff --git a/dfx.json b/dfx.json index 8b7b8fe..4d4a0df 100644 --- a/dfx.json +++ b/dfx.json @@ -12,7 +12,7 @@ "packtool": "vessel sources" } }, - "dfx": "0.9.2", + "dfx": "0.9.3", "networks": { "local": { "bind": "127.0.0.1:8000", diff --git a/src/conversion.mo b/src/conversion.mo index e5534b7..c92e460 100644 --- a/src/conversion.mo +++ b/src/conversion.mo @@ -1124,6 +1124,22 @@ module { return textToByteBuffer(_text).toArray(); }; + public func textToNat(phrase : Text) : ?Nat { + var theSum : Nat = 0; + Iter.iterate(Text.toIter(phrase), func (x : Char, n : Nat){ + //todo: check for digits + theSum := theSum + ((Nat32.toNat(Char.toNat32(x)) - 48) * 10 ** (phrase.size()-n-1)); + }); + return ?theSum; + }; + + public func valueToProperties(val : CandyValue) : Types.Properties { + switch(val){ + case(#Class(val)){ val}; + case(_){assert(false);/*unreachable*/[];}; + }; + }; + public func bytesToText(_bytes : [Nat8]) : Text{ var result : Text = ""; @@ -1182,8 +1198,10 @@ module { bytes := List.push(a, bytes); test := b > 0; }; - - Array.append([c],List.toArray(bytes)); + let result = toBuffer([c]); + result.append(toBuffer(List.toArray(bytes))); + result.toArray(); + //Array.append([c],List.toArray(bytes)); }; public func bytesToInt(_bytes : [Nat8]) : Int{ diff --git a/src/properties.mo b/src/properties.mo index 8c10e7e..d762474 100644 --- a/src/properties.mo +++ b/src/properties.mo @@ -38,12 +38,11 @@ module { }; private func fromPropertyUnstableMap(m : HashMap.HashMap) : PropertiesUnstable { - - var ps : PropertiesUnstable = []; + var ps : Buffer.Buffer = Buffer.Buffer(m.size()); for ((_, p) in m.entries()) { - ps := Array.append(ps, [p]); + ps.add(p); }; - ps; + ps.toArray(); }; @@ -51,7 +50,7 @@ module { // NOTE: ignores unknown properties. public func getPropertiesUnstable(properties : PropertiesUnstable, qs : [Query]) : Result.Result { let m = toPropertyUnstableMap(properties); - var ps : PropertiesUnstable = []; + var ps : Buffer.Buffer = Buffer.Buffer(m.size()); for (q in qs.vals()) { switch (m.get(q.name)) { case (null) { @@ -63,18 +62,18 @@ module { case (#Class(c)) { if (q.next.size() == 0) { // Return every sub-attribute attribute. - ps := Array.append(ps, [p]); + ps.add(p); } else { let sps = switch (getPropertiesUnstable(c, q.next)) { case (#err(e)) { return #err(e); }; case (#ok(v)) { v; }; }; - ps := Array.append(ps, [{ + ps.add({ name = p.name; value = #Class(sps); immutable = p.immutable; - }]); + }); }; }; case (other) { @@ -82,13 +81,13 @@ module { if (q.next.size() != 0) { return #err(#NotFound); }; - ps := Array.append(ps, [p]); + ps.add(p); }; } }; }; }; - #ok(ps); + #ok(ps.toArray()); }; // Updates the given properties based on the given update query. @@ -119,6 +118,13 @@ module { immutable = false; }); }; + case (#Lock(v)) { + m.put(u.name, { + name = u.name; + value = v; + immutable = true; + }); + }; }; }; case (? p) { @@ -155,6 +161,13 @@ module { immutable = false; }); }; + case (#Lock(v)) { + m.put(u.name, { + name = p.name; + value = v; + immutable = true; + }); + }; }; }; }; @@ -212,18 +225,18 @@ module { private func fromPropertyMap(m : HashMap.HashMap) : Properties { - var ps : Properties = []; + var ps : Buffer.Buffer = Buffer.Buffer(m.size()); for ((_, p) in m.entries()) { - ps := Array.append(ps, [p]); + ps.add(p); }; - ps; + ps.toArray(); }; // Returns a subset of from properties based on the given query. // NOTE: ignores unknown properties. public func getProperties(properties : Properties, qs : [Query]) : Result.Result { let m = toPropertyMap(properties); - var ps : Properties = []; + var ps : Buffer.Buffer = Buffer.Buffer(m.size()); for (q in qs.vals()) { switch (m.get(q.name)) { case (null) { @@ -236,18 +249,18 @@ module { case (#Class(c)) { if (q.next.size() == 0) { // Return every sub-attribute attribute. - ps := Array.append(ps, [p]); + ps.add(p); } else { let sps = switch (getProperties(c, q.next)) { case (#err(e)) { return #err(e); }; case (#ok(v)) { v; }; }; - ps := Array.append(ps, [{ + ps.add({ name = p.name; value = #Class(sps); immutable = p.immutable; - }]); + }); }; }; case (other) { @@ -255,13 +268,13 @@ module { if (q.next.size() != 0) { return #err(#NotFound); }; - ps := Array.append(ps, [p]); + ps.add(p); }; } }; }; }; - #ok(ps); + #ok(ps.toArray()); }; // Updates the given properties based on the given update query. @@ -292,6 +305,13 @@ module { immutable = false; }); }; + case (#Lock(v)) { + m.put(u.name, { + name = u.name; + value = v; + immutable = true; + }); + }; }; }; case (? p) { @@ -328,6 +348,13 @@ module { immutable = false; }); }; + case (#Lock(v)) { + m.put(u.name, { + name = p.name; + value = v; + immutable = true; + }); + }; }; }; }; diff --git a/src/types.mo b/src/types.mo index 14d06cb..10beb2a 100644 --- a/src/types.mo +++ b/src/types.mo @@ -30,6 +30,7 @@ module { public type UpdateModeUnstable = { #Set : CandyValueUnstable; + #Lock : CandyValueUnstable; #Next : [UpdateUnstable]; }; @@ -78,6 +79,7 @@ module { public type UpdateMode = { #Set : CandyValue; + #Lock : CandyValue; #Next : [Update]; };