rocklabs-io / ic-py

Python Agent Library for the DFINITY Internet Computer
MIT License
127 stars 26 forks source link

Update candid.py #18

Closed jim3333 closed 2 years ago

jim3333 commented 2 years ago

fix Null decode & encode failed.

jfb commented 2 years ago

from ic.candid import decode, Types, encode

if __name__ == '__main__':
    a = encode([{"type": Types.Null, "value": None}])
    Prin = Types.Null
    param = None
    res = encode([{'type': Prin, 'value': param}])
    print('current :', res.hex())
    print('decode Null:', decode(res, Prin))

test code

ccyanxyz commented 2 years ago

test code.

It is best to use unittest to automatically test with github actions after committing.

from ic.candid import decode, Types, encode

if __name__ == '__main__':
    a = encode([{"type": Types.Null, "value": None}])
    Prin = Types.Null
    param = None
    res = encode([{'type': Prin, 'value': param}])
    print('current :', res.hex())
    print('decode Null:', decode(res, Prin))

Great idea! we'll look into it

mircial commented 2 years ago

@jim3333 @jfb

Hi, guys. Thanks for your code. Today, I am going to write an example to demostrate how to using candid Types and fix some potencial bug.

BTW, 'Prin' in code represents principal, not a standard use for each Type.