-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement RPC calls in Jupyter/Colab #124
Conversation
- push + pull_request always triggers two builds - the secret is not available for non-contributors, resulting in bad builds every time
boa/rpc.py
Outdated
@@ -54,7 +55,24 @@ def from_json(cls, data): | |||
return cls(message=data["message"], code=data["code"]) | |||
|
|||
|
|||
class EthereumRPC: | |||
class RPC(ABC): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have some bad memories about ABC / abstractmethod performance. can we make it simpler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove the abc or remove the base class completely for duck typing
cc4b11b
to
1528a3e
Compare
boa/integrations/jupyter/browser.py
Outdated
Create a BrowserSigner instance. | ||
:param address: The account address. If not provided, it will be requested from the browser. | ||
""" | ||
if address: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if address: | |
if address is not None: |
boa/integrations/jupyter/browser.py
Outdated
if method == "eth_getTransactionReceipt": | ||
# we do the polling in the browser to avoid too many callbacks | ||
# each callback generates currently 10px empty space in the frontend | ||
timeout_ms = CALLBACK_TOKEN_TIMEOUT.total_seconds() * 1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use a separate constant for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g., WAIT_TRANSACTION_RECEIPT_TIMEOUT
boa/integrations/jupyter/jupyter.js
Outdated
console.log(`Callback ${token} => ${responseText}`); | ||
const body = stringify(await parsePromise(func(...args))); | ||
// console.log(`Boa: ${func.name}(${args.map(a => JSON.stringify(a)).join(',')}) = ${body};`); | ||
return colab ? body : callbackAPI(token, body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we shouldn't return anything, since the return values of the two branches mean different things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm except slight refactoring of handleCallback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. thank you!
Fixes #119
Depends on #132
What I did
Extended the interface with the browser to support RPC calls.
How I did it
It includes two new classes on the python side:
BrowserRpc
calls the browser when a RPC call is madeboa.set_browser()
combinesBrowserRpc
andBrowserSigner
together to allow the environment to be used in boaboa.set_network(url)
works as an alternative toboa.set_env(NetworkEnv(url))
The JavaScript uses this method from ethers.js.
Tests are included, but unfortunately I had to mock all jupyter and tornado dependencies - they aren't installed in boa normally.
How to verify it
Install this branch and then run in Jupyter or Google Colab:
boa.env.eoa
should return your wallet address.boa.env.get_gas_price()
returns the current gas price.Description for the changelog
boa.set_browser()
interface to interact with the browser wallet RPC in JupyterLabCute Animal Picture