oasisprotocol / sapphire-paratime

Oasis Sapphire - the confidential EVM-compatible ParaTime for the Oasis Network
https://oasisprotocol.org/sapphire
Apache License 2.0
37 stars 27 forks source link

clients/python #218

Closed CedarMist closed 11 months ago

CedarMist commented 1 year ago

Closes: #63

Example usage:

from sapphirepy import sapphire
w3 = Web3(Web3.HTTPProvider('http://localhost:8545/'))
w3.middleware_onion.add(construct_sign_and_send_raw_middleware(account))
w3 = sapphire.wrap(w3)

The sapphire.wrap call must be added after any construct_sign_and_send_raw_middleware or similar signing middleware.

It uses the epoch flag for encrypted envelopes, and handles re-fetching the calldata keypair if the epoch is too old. This isn't optimal behavior as if the client runs for any amount of time it will end up using an old keypair for calldata encryption as it doesn't know when the validity expires without first receiving an error.

matevz commented 12 months ago

Is there a library to generate python bindings for your solidity contract (similar to ethers for javascript) so you could do something like:

greeter = Greeter()
greeter.deploy().wait()
print(greeter.address)

Then, we could actually make a practical example and add it to our official documentation.

matevz commented 12 months ago

Is there a library to generate python bindings for your solidity contract (similar to ethers for javascript) so you could do something like:

greeter = Greeter()
greeter.deploy().wait()
print(greeter.address)

Then, we could actually make a practical example and add it to our official documentation.

Ah, it's ethers for python duh https://pypi.org/project/ethers/

CedarMist commented 12 months ago

web3.py allows a similar pattern: https://github.com/oasisprotocol/sapphire-paratime/pull/218/files#diff-00b5c90060622faf7d475f14961a2a6b11a9d4d8f1d316ab3c3408864bab5635R45

x = self.greeter.functions.blah().transact({'gasPrice': w3.eth.gas_price})
y = w3.eth.wait_for_transaction_receipt(x)
z = greeter.events.Greeting().process_receipt(y)

To support ethers-py we'd either have to add support for ethers-rs or add a wrapper for ethers-py, most people in Python land seem to use web3.py and ethers-py doesn't have much usage.

aefhm commented 11 months ago

This PR also relates to https://github.com/oasisprotocol/sapphire-paratime/issues/63