rocklabs-io / ic-py

Python Agent Library for the DFINITY Internet Computer
MIT License
128 stars 27 forks source link

ValueError: Not an option type #85

Closed letmejustputthishere closed 1 year ago

letmejustputthishere commented 1 year ago

It's not possible to read the response from the ledger archive due to a bug when decoding the response. Minimum example:

from ic.client import Client
from ic.agent import Agent
from ic.identity import Identity
from ic.common.ledger import Ledger
from ic import Canister

# Identity and Client are dependencies of Agent
iden = Identity()  # creates a random keypair
client = Client()  # creates a client to talk to the IC
# creates an agent, combination of client and identity
agent = Agent(iden, client)
# creates the ledger canister with the matching interface provided
ledger = Ledger(agent)

ledger_archive_did = open("archive.did").read()
ledger_archive = Canister(agent=agent,
                          canister_id="qjdve-lqaaa-aaaaa-aaaeq-cai",
                          candid=ledger_archive_did)

res = ledger_archive.get_blocks({"start": 10, "length": 10})

More info can be found in this thread

https://forum.dfinity.org/t/how-to-use-dfx-to-query-the-balance-of-an-account-identifier/15929/5?u=cryptoschindler

Myse1f commented 1 year ago
type Transaction = record {
    memo : Memo;
    // Optional to support potential future variant extensions.
    operation : opt Operation;
    created_at_time : Timestamp;
};

For operation, it should be operation: Operation, without opt. You can refer to archive implmentation to check the type of GetBlocksResult.

But don't know why dfx still can parse it.

roman-kashitsyn commented 1 year ago

For operation, it should be operation: Operation, without opt. You can refer to archive implmentation to check the type of GetBlocksResult.

No, the opt part is intentional. We don't want to break all clients when we add new transaction types.

But don't know why dfx still can parse it.

Because T <: opt T according to the Candid spec.

not (null <: <datatype'>)
<datatype> <: <datatype'>
-----------------------------
<datatype> <: opt <datatype'>

My hunch is that the custom candid parser you use for Python does not handle subtype checks. Consider testing it for compliance against the Candid test suite: https://github.com/dfinity/candid/tree/master/test.

Myse1f commented 1 year ago

My hunch is that the custom candid parser you use for Python does not handle subtype checks.

Correct, we haven't handle subtype checks so far. So I suggest that to use the fully matched candid file first to get the result of query or async call.

At least for this case, remove the opt would get the correct result.

Consider testing it for compliance against the Candid test suite: https://github.com/dfinity/candid/tree/master/test.

Thanks for suggestion.