rocklabs-io / ic-py

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

Any abstraction available to handle interactions with the ledger canister? #17

Closed bodily11 closed 2 years ago

bodily11 commented 2 years ago

I've seen code in JavaScript use a send_dfx method that will allow you to pass in text account addresses and other default values and then will wrap them up and send to the ledger canister to facilitate ICP transfers.

Is this on your roadmap at all?

I'm working on implementing an ICP transfer with the Python Agent and am trying to figure out if I should just interact with the raw canister (encoding all values to appropriate types myself) or if you had any plans to make it really easy. :)

bodily11 commented 2 years ago

When I try to do it myself, the timestamp argument is an Opt with a Record and then Nat64. See ledger candid here: https://k7gat-daaaa-aaaae-qaahq-cai.ic0.app/listing/nns-ledger-10244/ryjl3-tyaaa-aaaaa-aaaba-cai

type TransferArgs = record { memo: Memo; amount: ICP; fee: ICP; from_subaccount: opt SubAccount; to: Address; created_at_time: opt TimeStamp; };

type TimeStamp = record { timestamp_nanos: nat64; };

Which I am interpreting to mean I should form my request something like this:

params = [
    {'type': Types.Nat64, 'value':0}, #memo
    {'type': Types.Nat64, 'value': price}, #amount
    {'type': Types.Nat64, 'value': int(0.0001E8)}, #fee
    {'type': Types.Text, 'value': purchasing_wallet_address}, #from_subaccount
    {'type': Types.Text, 'value': wallet_address_to_send_ICP}, #to_address
    {'type': Types.Opt, 'value': {'type':Types.Nat64,'value':timestamp}} #created_at_time
]

But it looks like Opt isn't supported as I'm getting the "buildTypeTable" error just like the vec error from earlier.

Is my syntax just wrong? I confess I don't really understand the "Opt" datatype right now anyway... so it could be I'm just doing something wrong.

Thanks!

bodily11 commented 2 years ago

Although it looks like from_subaccount is also an Opt, so not sure if I need to change types on that one too. But then specifically it is listed as Blob.

bodily11 commented 2 years ago

Final comment. Even if I just pretend the "Opts" don't exist (which kind of makes sense if it is just indicating some optional values), I would have to use Types.Record for the timestamp, which gives me the same 'buildTypeTable' error.

jfb commented 2 years ago

@bodily11

https://github.com/rocklabs-io/ic-py/blob/main/ic/candid.py#L1261

Take a look at the example of opt above

ccyanxyz commented 2 years ago

we'll add common canister interfaces like ledger canister class and management canister class

Myse1f commented 2 years ago

Common canisters have been implemented.