Skip to content

Commit

Permalink
Merge pull request #22 from icdevsorg/0.3.0-alpha
Browse files Browse the repository at this point in the history
0.3.0 alpha
  • Loading branch information
skilesare authored Nov 17, 2023
2 parents f98c191 + 24197f1 commit 907a4e7
Show file tree
Hide file tree
Showing 22 changed files with 2,128 additions and 263 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
node-version: 14
- uses: aviate-labs/[email protected]
with:
dfx-version: 0.13.1
dfx-version: 0.15.1

- name: "install Motoko binaries"
run: |
Expand All @@ -31,19 +31,12 @@ jobs:
tar -xzf motoko-linux64-${{ env.moc_version }}.tar.gz -C /home/runner/bin
echo "/home/runner/bin" >> $GITHUB_PATH
- name: "install vessel"
run: |
wget --output-document /home/runner/bin/vessel https://github.com/kritzcreek/vessel/releases/download/${{ env.vessel_version }}/vessel-linux64
chmod +x /home/runner/bin/vessel
- name: "install mops"
run: |
npm --yes -g i ic-mops
mops i
- name: "check"
run: make check

- name: "check-mops"
run: make check-mops

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
v0.3.0

- Added the ValueShared type for dumping a Candy and CandyShared to an ICRC3 style Value type.
- Added many tests.
2 changes: 1 addition & 1 deletion dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"packtool": "mops sources"
}
},
"dfx": "0.14.0",
"dfx": "0.15.1",
"networks": {
"local": {
"bind": "127.0.0.1:8000",
Expand Down
27 changes: 18 additions & 9 deletions mops.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
[dependencies]
base = "https://github.com/dfinity/motoko-base#moc-0.8.1"
matchers = "https://github.com/kritzcreek/motoko-matchers#v1.3.0"
candid = "https://github.com/gekctek/motoko_candid#v1.0.1"
xtendedNumbers = "https://github.com/gekctek/motoko_numbers#v1.0.2"
stablebuffer = "https://github.com/skilesare/StableBuffer#v0.2.0"
map = "https://github.com/ZhenyaUsenko/motoko-hash-map#v7.0.0"
candy_0_1_12 = "https://github.com/icdevs/candy_library#v0.1.12"
base = "https://github.com/dfinity/motoko-base#moc-0.10.0@a15ca7cd26335505e103288654f480a44463d844"
matchers = "https://github.com/kritzcreek/motoko-matchers#v1.3.0@3dac8a071b69e4e651b25a7d9683fe831eb7cffd"
candid = "https://github.com/gekctek/motoko_candid#v1.0.1@4f0c445a4f998d4d07b616fafd463eea8f52e4bc"
xtendedNumbers = "https://github.com/gekctek/motoko_numbers#v1.0.2@775995c49c55f7c53e5c9e5a52dc3536201064b2"
stablebuffer = "https://github.com/skilesare/StableBuffer#v0.2.0@110660769d11ba93c618dc4712525d20503bdc37"
stablebuffer_1_3_0 = "https://github.com/canscale/StableBuffer#v1.3.0@acdde6bb5b939227997cebdbb8919d2e6da8691c"
map7 = "https://github.com/ZhenyaUsenko/motoko-hash-map#v7.0.0@f0e25632e5da80118274e78ceeb5bec95f3c2b81"
map9 = "https://github.com/ZhenyaUsenko/motoko-hash-map#v9.0.1@10b68f6ea8df5e72dfa4c07a50c8bb60a916c233"
candy_0_1_12 = "https://github.com/icdevs/candy_library#v0.1.12@20db7a8a74258bb07c7d354ea477bf95121747a3"
candy_0_2_0 = "https://github.com/icdevs/candy_library#0.2.0@4fc5aebec44355da94a4d3ebef87623e4545d89a"
encoding_0_4_1 = "https://github.com/aviate-labs/encoding.mo#v0.4.1@2711d18727e954b11afc0d37945608512b5fbce2"
vector = "0.2.0"

[package]
name = "candy"
version = "0.2.0"
version = "0.3.0"
description = "Library for Converting Types and Creating Workable Motoko Collections"
repository = "https://github.com/icdevs/candy_library"
repository = "https://github.com/icdevs/candy_library"

[dev-dependencies]
test = "1.1.0"
fuzz = "0.1.1"
2 changes: 1 addition & 1 deletion old_package-set.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let
, dependencies = [ "base"]
},
{ name = "base", repo = "https://github.com/dfinity/motoko-base.git", version = "moc-0.8.1", dependencies = []: List Text },
{ name = "map"
{ name = "map7"
, repo = "https://github.com/ZhenyaUsenko/motoko-hash-map"
, version = "v7.0.0"
, dependencies = [ "base"]
Expand Down
2 changes: 1 addition & 1 deletion old_vessel.dhall
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
dependencies = [ "base", "matchers", "candid", "xtendedNumbers", "stablebuffer", "map","candy_0_1_12"],
dependencies = [ "base", "matchers", "candid", "xtendedNumbers", "stablebuffer", "map7","candy_0_1_12"],
compiler = Some "0.8.1",
}
86 changes: 55 additions & 31 deletions src/candid.mo
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import Blob "mo:base/Blob";
import Principal "mo:base/Principal";
import Text "mo:base/Text";

import Map "mo:map/Map";
import Map "mo:map9/Map";

import Types "types";
import CandyHex "hex";

import CandidTypes "mo:candid/Type";
import Arg "mo:candid/Arg";
Expand Down Expand Up @@ -174,66 +173,91 @@ module {
case(#Int32(val))buffer.add({_type = #int32; value = #int32(val)});
case(#Int16(val))buffer.add({_type = #int16; value = #int16(val)});
case(#Int8(val))buffer.add({_type = #int8; value = #int8(val)});

case(#Map(val)){
let list = val;

var bFoundMultipleKeyTypes = false;
var bFoundMultipleValueTypes = false;
var lastKeyType : ?CandidTypes.Type = null;
var lastValueType : ?CandidTypes.Type = null;

let values: Buffer.Buffer<Value.Value> = Buffer.Buffer<Value.Value>(list.size());

let types: Buffer.Buffer<CandidTypes.RecordFieldType> = Buffer.Buffer<CandidTypes.RecordFieldType>(list.size());

let localValues: Buffer.Buffer<Value.Value> = Buffer.Buffer<Value.Value>(2);
let localTypes: Buffer.Buffer<CandidTypes.RecordFieldType> = Buffer.Buffer<CandidTypes.RecordFieldType>(2);



let body: Buffer.Buffer<Value.RecordFieldValue> = Buffer.Buffer<Value.RecordFieldValue>(list.size());



var tracker : Nat32 = 0;
let localTypes: Buffer.Buffer<CandidTypes.RecordFieldType> = Buffer.Buffer<CandidTypes.RecordFieldType>(2);
let localBody: Buffer.Buffer<Value.RecordFieldValue> = Buffer.Buffer<Value.RecordFieldValue>(2);
for(this_item in list.vals()){
let key = (this_item.0);
let value = (value_to_candid(this_item.1))[0];



localTypes.add({_type = value._type; tag = #name(key)});

localBody.add({tag = #name(key); value = value.value});



//buffer.add(thisItem);

//types.add({_type = thisItem._type; tag = #hash(tracker)});
//body.add({tag = #hash(tracker); value = thisItem.value});
//values.add(thisItem.value);
tracker += 1;
};


buffer.add({_type=#record(Buffer.toArray(localTypes)); value = #record(Buffer.toArray(localBody))})

};

case(#ValueMap(val)){
let list = val;

let values: Buffer.Buffer<Value.Value> = Buffer.Buffer<Value.Value>(list.size());

let types: Buffer.Buffer<CandidTypes.RecordFieldType> = Buffer.Buffer<CandidTypes.RecordFieldType>(list.size());

let localValues: Buffer.Buffer<Value.Value> = Buffer.Buffer<Value.Value>(2);



let body: Buffer.Buffer<Value.RecordFieldValue> = Buffer.Buffer<Value.RecordFieldValue>(list.size());



var tracker : Nat32 = 0;
for(this_item in list.vals()){
let key = (value_to_candid(this_item.0))[0];
let value = (value_to_candid(this_item.1))[0];
switch(lastKeyType){
case(null) lastKeyType := ?key._type;
case(?lastKeyType){
if(CandidTypes.equal(lastKeyType, key._type)){

} else {
bFoundMultipleKeyTypes := true;
};
};
};
switch(lastValueType){
case(null) lastValueType := ?value._type;
case(?lastValueType){
if(CandidTypes.equal(lastValueType, value._type)){

} else {
bFoundMultipleValueTypes := true;
};
};
};
let localTypes: Buffer.Buffer<CandidTypes.RecordFieldType> = Buffer.Buffer<CandidTypes.RecordFieldType>(2);
let localBody: Buffer.Buffer<Value.RecordFieldValue> = Buffer.Buffer<Value.RecordFieldValue>(2);


localTypes.add({_type = key._type; tag = #hash(0)});
localTypes.add({_type = value._type; tag = #hash(1)});


localBody.add({tag = #hash(0); value = key.value});
localBody.add({tag = #hash(1); value = value.value});

let thisItem = {_type=#record(Buffer.toArray(localTypes)); value = #record(Buffer.toArray(localBody))};

types.add({_type = thisItem._type; tag = #hash(tracker)});
body.add({tag = #hash(tracker); value = thisItem.value});
values.add(thisItem.value);
types.add({_type = #record(Buffer.toArray(localTypes)); tag = #hash(tracker)});
body.add({tag = #hash(tracker); value = #record(Buffer.toArray(localBody))});

tracker += 1;
};


buffer.add({_type=#record(Buffer.toArray(types)); value = #record(Buffer.toArray(body))})
//buffer.add({_type=#record(Buffer.toArray(types)); value = #record(Buffer.toArray(body))})

};
//array
Expand Down
8 changes: 4 additions & 4 deletions src/clone.mo
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import Types "types";
import Array "mo:base/Array";
import StableBuffer "mo:stablebuffer/StableBuffer";
import Map "mo:map/Map";
import Set "mo:map/Set";
import StableBuffer "mo:stablebuffer_1_3_0/StableBuffer";
import Map "mo:map9/Map";
import Set "mo:map9/Set";

module {

Expand Down Expand Up @@ -46,7 +46,7 @@ module {
case(#Ints(val)){#Ints(StableBuffer.clone(val))};
case(#Floats(val)){#Floats(StableBuffer.clone(val))};
case(#Array(val)){#Array(StableBuffer.clone(val))};
case(#Map(val)){#Map(Map.fromIter<Candy,Candy>(Map.entries(val), Types.candyMapHashTool))};
case(#ValueMap(val)){#ValueMap(Map.fromIter<Candy,Candy>(Map.entries(val), Types.candyMapHashTool))};
case(#Set(val)){#Set(Set.fromIter<Candy>(Set.keys(val), Types.candyMapHashTool))};
case(_) val;
};
Expand Down
Loading

0 comments on commit 907a4e7

Please sign in to comment.