serde icon indicating copy to clipboard operation
serde copied to clipboard

ICRC3 problems

Open infu opened this issue 5 months ago • 3 comments

The ICRC3 example from https://raw.githubusercontent.com/NatLabs/serde/main/usage.md#icrc3-value doesn't work

There is one here https://github.com/NatLabs/serde/blob/main/tests/Candid.ICRC3.Test.mo that does work, but it's not converting the object to a ICRC3 Generic Value type, it's still Candid type. I am assuming it's only using the ICRC3 fields, but the type is incompatible when we try to use it. We need it to be with this type, without all the extra Candid variations

    public type ValueMap = (Text, Value);
    public type Value = { 
        #Blob : Blob; 
        #Text : Text; 
        #Nat : Nat;
        #Int : Int;
        #Array : [Value]; 
        #Map : [ValueMap]; 
    };

Also, is it possible to not have to write down a list of fields, so it does them automatically?

 Candid.decode(blob, ["ts", "payload"], ?options) else return [];
                       ^^^^^^^^^^^^^^

Will it convert the whole nested structure recursively? Or it can only convert flat records ?

The code we are trying to write is


    public type Action = {
        ts: Nat64;
        payload : {
            #received: Received;
            #sent: Sent;
        };
    };

    func encodeBlock(b: Action): [Rechain.ValueMap] {
        let blob = to_candid(b);
        let options = { Candid.defaultOptions with use_icrc_3_value_type = true };
        let #ok(rcd) = Candid.decode(blob, ["ts", "payload"], ?options) else return [];
        rcd
    };

infu avatar Aug 31 '24 14:08 infu