Closed letmejustputthishere closed 1 year ago
ok, i solved the issue! because of this type
type Account = variant {
account_id : text;
"principal" : principal;
extensible : CandyValue;
};
i have to call
ogy = Canister(agent=agent, canister_id=canister_id,
candid=ogy_candid)
result = ogy.balance_of_nft_origyn({ # type: ignore
'"principal"': principal,
})
(note the extra double quotes)
imo opinion this is extremely inconvenient and shouldnt be necessary to do ...
oh, and also i can't call the canister anymore. it errors out with
ogy IC0503: Canister s32s7-zqaaa-aaaaj-afksa-cai trapped explicitly: IDL error: unexpected variant tag
i was able to work around it like this
types = Types.Variant({'principal': Types.Principal}) # type: ignore
val = {'principal': principal}
params = [
{
'type': types,
'value': val
},
]
result = agent.query_raw(
canister_id, "balance_of_nft_origyn", encode(params))
but ideally i would be able to create the Canister
with the provided did
file instead ...
I think the key '"principal"' should be 'principal'.
In candid 'principal' conflict with keyword principal
, so it adds a quotation.
But in python, principal is not a reserved word. Now you can remove the quotes and try again.
We will fix the problem in the near future.
removing the quotes doesnt work :(
Traceback (most recent call last):
File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/discord/ext/tasks/__init__.py", line 239, in _loop
await self.coro(*args, **kwargs)
File "/Users/moritz/projects/ic/glue-org/glue-bot/glue/discord_bot/bot.py", line 47, in check_ownership
await verify_ownership_for_guild(guild)
File "/Users/moritz/projects/ic/glue-org/glue-bot/glue/discord_bot/helpers.py", line 32, in verify_ownership_for_guild
if user_has_tokens(
File "/Users/moritz/projects/ic/glue-org/glue-bot/glue/discord_bot/helpers.py", line 66, in user_has_tokens
result = ogy.balance_of_nft_origyn({ # type: ignore
File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/ic/canister.py", line 60, in __call__
encode(arguments),
File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/ic/candid.py", line 1263, in encode
vals += t.encodeValue(args[i])
File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/ic/candid.py", line 770, in encodeValue
raise ValueError("Variant has no data: {}".format(val))
ValueError: Variant has no data: {'principal': 'ci6uj-i7ujw-wrp3j-6nfh6-ux3y4-hym5t-ruodk-flgjh-salcu-6nxa2-cae'}
@Myse1f calling the canister with only principal
doesnt work, see the above error
i was able to work around it like this
types = Types.Variant({'principal': Types.Principal}) # type: ignore val = {'principal': principal} params = [ { 'type': types, 'value': val }, ] result = agent.query_raw( canister_id, "balance_of_nft_origyn", encode(params))
but ideally i would be able to create the
Canister
with the provideddid
file instead ...
@Myse1f how can I add the correct keys
to the result
dictonary? right now it looks like this
[{'type': 'rec_4', 'value': {'_24860': {'_1224950711': [], '_2005185548': [], '_2215341626': [], '_2839967725': [], '_3672582405': []}}}]
any way to decode the result to have the correct keys
? or are the numbers like _1224950711
constant and never change, so i can rely on hardcoding them?
When using query_raw
, you can pass the return type as last parameter.
e.g
return_type = Types.record({
"ok": ...
“err”: ...
})
agent.query_raw(canister_id, "balance_of_nft_origyn", encode(params), return_type)
Besides, the number never change unless it change the key, as it is something like hash.
awesome, many thanks! looking forward to the fix :)
even though this issue is closed, it's not resolved on my end. both calls with '"principal"'
and 'principal'
still fail with the same error messages as before. i'm using the main branch in my application.
can this be reopened?
Fix in #77. Now it should work
i can confirm this works by just specifying 'principal'
! thank you so much
I have the following
ogy.did
candid:I call the canister the following way:
My call fails with the following error
What am I doing wrong?