Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Added support for signer #33

Merged
merged 17 commits into from
Dec 5, 2021
Merged

Added support for signer #33

merged 17 commits into from
Dec 5, 2021

Conversation

exp-table
Copy link
Contributor

No description provided.

signer_data = next(accounts.load(str(signer.public_key), network))
signer.account = signer_data["address"]
signer.index = signer_data["index"]
else: #doesn't exist, havbe to deploy
Copy link
Contributor

@fracek fracek Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a space between # and doesn't. There's a typo (havbe should be have).

signer.index = accounts.current_index(network)
subprocess.run(f"nile deploy Account {signer.public_key} --alias account-{signer.index}", shell=True)
address, _ = next(deployments.load(f"account-{signer.index}", network))
#initialize account
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space between # and initialize

@fracek
Copy link
Contributor

fracek commented Nov 19, 2021

I like this! I added a couple of nitpicky comments.

@exp-table
Copy link
Contributor Author

I like this! I added a couple of nitpicky comments.

Fixed it!

@fracek
Copy link
Contributor

fracek commented Nov 19, 2021

Ok there are a couple of linting issues. My advice is to run tox -e format to automatically format everything, then tox -e lint to double check everything is formatted correctly.

@martriay
Copy link
Contributor

martriay commented Nov 20, 2021

This looks very nice! A few comments:

  • Do you think proxy could be merged into send? Or maybe I'm not understanding the different use case. In any case, I don't think that's the right name for it since it refers to a different kind of contracts which delegate execution to other contracts. Maybe raw_execute?
  • Could you expand the documentation to include an example env file and commands snippets with actual parameters? That help users a lot.

Future work could be:

  1. generating a private key, needed for 2 and generally useful
  2. auto generating a few accounts on nile node startup, use one by default or select one with --account (index or alias)
  3. pick up private keys from an env/config file automatically with aliases too, on top of the default ones. with this, the setup command could be used to exceptionally but not regularly deploy accounts -- it could be cumbersome otherwise to redeploy each time you reset the node. conversely, if we're auto-picking keys from the dotenv, the command's interface could take directly a private key or even generate one automatically.

signer.index = signer_data["index"]
else: # doesn't exist, have to deploy
signer.index = accounts.current_index(network)
subprocess.run(f"nile deploy Account {signer.public_key} --alias account-{signer.index}", shell=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not importing the module?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't even think about it when prototyping initially. Good catch, fixed it!

@exp-table
Copy link
Contributor Author

This looks very nice! A few comments:

* Do you think `proxy` could be merged into `send`? Or maybe I'm not understanding the different use case. In any case, I don't think that's the right name for it since it refers to a different kind of contracts which delegate execution to other contracts. Maybe `raw_execute`?

* Could you expand the documentation to include an example env file and commands snippets with actual parameters? That help users a lot.

I renamed them to send and raw-execute. As you said, proxy isn't the right label for what it does.
I also added an example example.env file as well as enhanced documentations for send and raw-execute.

Copy link
Contributor

@fracek fracek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. All issues have been addressed, thanks!

@exp-table exp-table requested a review from martriay November 22, 2021 09:57
"""Utility for sending signed transactions to an Account on Starknet."""
import subprocess

from starkware.cairo.common.hash_state import compute_hash_on_elements
Copy link
Contributor

@fracek fracek Dec 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be be wrapped in a try catch to avoid throwing when users don't have cairo installed yet (and want to use nile to install it).

@fracek
Copy link
Contributor

fracek commented Dec 3, 2021

One last thing before I'm ready to merge. Sorry for letting you wait so long to review this PR!

README.md Outdated

A few things to notice here:

1. `nile set <env_var>` looks for an environement variable with the same name whose value is a private key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no nile set command :)

@@ -88,6 +88,56 @@ A few things to notice here:
3. The `--alias` parameter lets me create an unique identifier for future interactions, if no alias is set then the contract's address can be used as identifier
4. By default Nile works on local, but you can pass `--network mainnet` to deploy directly to a public chain! Notice that `mainnet` refers to StarkNet main chain, that's settled on Goerli testnet of Ethereum ([mainnet deployment this month!](https://medium.com/starkware/starknet-alpha-is-coming-to-mainnet-b825829eaf32))

### `setup`
You can find an exemple `.env` file in `example.env`. These are private keys only to be used for testing and never in production.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exemple -> example

Copy link
Contributor

@fracek fracek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it works well on a local network but does not work on mainnet because the network argument is missing in the call to get the nonce.

def get_nonce(self):
"""Get the nonce for the next transaction."""
nonce = subprocess.check_output(
f"nile call account-{self.index} get_nonce", shell=True, encoding="utf-8"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it's missing a --network argument so when using a non-default network this call fails

@exp-table exp-table requested review from fracek and martriay December 4, 2021 15:37
Copy link
Contributor

@fracek fracek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run this in a fresh venv and everything is working as expected

@martriay martriay merged commit 8241b4c into OpenZeppelin:main Dec 5, 2021
@martriay
Copy link
Contributor

martriay commented Dec 5, 2021

Thanks all 🎉

milancermak pushed a commit to milancermak/nile that referenced this pull request Dec 12, 2021
* Signer support

* stringified all command items

* loading pkeys from .env

* added accounts.json management

* updated readme'

* Added nile send

* fixed comments spacing

* passing tox linting

* renamed the proxy commands and added examples

* import module instead of cli commands

* fixed README typo

* fixed another readme typo

* fixed import path issues + functions arguments

* shipping Account artifacts + fixed setup file

* try/catch starkware import + readme typo fixed

* forgot to run tox format

* passing network to signer
@martriay martriay mentioned this pull request Jan 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants