rocklabs-io / ic-py

Python Agent Library for the DFINITY Internet Computer
MIT License
125 stars 25 forks source link

Can't handle None #99

Closed yugocabrio closed 1 year ago

yugocabrio commented 1 year ago

This is the correct candid. It was indicated in the error result. My problem is how to handle None. I wrote params, but I am unsure how to write None in params.

record {
    quoted_resource : variant {
        Article : nat64;
        None;                # This is the point. 
        Post : nat64;
        Comment : nat64;
    };

    extension : opt variant {
        Poll : record {
        votes_per_user : nat8;
        poll_duration_in_minutes : nat16;
        options : vec text;
        };
    };
}

I used this empty string ' ' as a key for the variable name of type "Types.Null"(None) for the first, but it was not allowed. I have no idea. Could you tell me what key should be set for Types.Null? Tentatively set to 'Null', but it dose not work now.

types = Types.Record({
    'quoted_resource':Types.Variant({
        'Article':Types.Nat64,
        'Null': Types.Null,        # This is the point. 
        'Post' :Types.Nat64,
        'Comment':Types.Nat64,
    }),

    'extension':Types.Opt(Types.Variant({
        'Poll':Types.Record({
            'votes_per_user' :Types.Nat8,
            'poll_duration_in_minutes' :Types.Nat16,
            'options': Types.Vec(Types.Text),
        })
    }))
})

values = {
    'quoted_resource': {'Null':None},      # This is the point. 
    'extension': []
}

params = [
    {'type': types, 'value': values}
]
Myse1f commented 1 year ago

The quoted_source in candid is the same as

variant {
        Article : nat64;
        None: null;
        Post : nat64;
        Comment : nat64;
}

The key is 'None' and the type of value is null.

Thus the types in ic-py is

'quoted_resource':Types.Variant({
        'Article':Types.Nat64,
        'None': Types.Null,
        'Post' :Types.Nat64,
        'Comment':Types.Nat64,
    }),

The value is

'quoted_resource': {'None':None},
yugocabrio commented 1 year ago

Thank you for the information!