This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Added support for signer #33
Merged
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
083cc74
Signer support
exp-table c2356ec
stringified all command items
exp-table de03e6e
loading pkeys from .env
exp-table 4719c5c
added accounts.json management
exp-table 69da9f0
updated readme'
exp-table 5f8925e
Added nile send
exp-table 10ab0af
fixed comments spacing
exp-table 33f51e5
passing tox linting
exp-table cb261c3
renamed the proxy commands and added examples
exp-table bb31eeb
import module instead of cli commands
exp-table dfc6e4e
fixed README typo
exp-table 6e6b56f
fixed another readme typo
exp-table fc280fd
fixed import path issues + functions arguments
exp-table 75beda4
shipping Account artifacts + fixed setup file
exp-table cdeecc6
try/catch starkware import + readme typo fixed
exp-table a1330bf
forgot to run tox format
exp-table 7835e43
passing network to signer
exp-table File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include LICENSE | ||
recursive-include src/nile/artifacts/ * | ||
recursive-include src/nile/base_project/ * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
```sh | ||
nile setup PKEY1 | ||
|
||
🚀 Deploying Account | ||
🌕 artifacts/Account.json successfully deployed to 0x07db6b52c8ab888183277bc6411c400136fe566c0eebfb96fffa559b2e60e794 | ||
📦 Registering deployment as account-0 in localhost.deployments.txt | ||
Invoke transaction was sent. | ||
Contract address: 0x07db6b52c8ab888183277bc6411c400136fe566c0eebfb96fffa559b2e60e794 | ||
Transaction hash: 0x17 | ||
``` | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's no |
||
2. This created a `localhost.accounts.json` file storing all data related to accounts management | ||
|
||
### `raw-execute` | ||
Execute a transaction through the `Account` associated with the private key used. The syntax is: | ||
|
||
```sh | ||
nile raw-execute <env_signer> <contract_address> <contract_method> <args> | ||
``` | ||
|
||
```sh | ||
nile raw-execute PKEY1 0x0342e...4de4e0 transfer_ownership 0x07db6...60e794 | ||
|
||
Invoke transaction was sent. | ||
Contract address: 0x03420417e09260947e3412d48952858a376f2d3ddde4e49f5981a2e41f4de4e0 | ||
Transaction hash: 0x1c | ||
``` | ||
|
||
### `send` | ||
Acts like `raw-execute` with the exception you can use it like you would use `nile invoke`. | ||
Execute a transaction through the `Account` associated with the private key used. The syntax is: | ||
|
||
```sh | ||
nile send <env_signer> <contract_identifier> <contract_method> [PARAM_1, PARAM2...] | ||
``` | ||
|
||
```sh | ||
nile send PKEY1 ownable0 transfer_ownership 0x07db6...60e794 | ||
|
||
Invoke transaction was sent. | ||
Contract address: 0x07db6b52c8ab888183277bc6411c400136fe566c0eebfb96fffa559b2e60e794 | ||
Transaction hash: 0x1c | ||
``` | ||
|
||
### `call` and `invoke` | ||
Using `call` and `invoke`, we can perform read and write operations against our local node (or public one using the `--network mainnet` parameter). The syntax is: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PKEY1=1234 | ||
PKEY2=5678 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""nile common module.""" | ||
import json | ||
import os | ||
|
||
from nile.common import ACCOUNTS_FILENAME | ||
|
||
|
||
def register(pubkey, address, index, network): | ||
"""Register a new account.""" | ||
file = f"{network}.{ACCOUNTS_FILENAME}" | ||
|
||
if exists(pubkey, network): | ||
raise Exception(f"account-{index} already exists in {file}") | ||
|
||
with open(file, "r") as fp: | ||
accounts = json.load(fp) | ||
accounts[pubkey] = {"address": address, "index": index} | ||
with open(file, "w") as file: | ||
json.dump(accounts, file) | ||
|
||
|
||
def exists(pubkey, network): | ||
"""Return whether an account exists or not.""" | ||
foo = next(load(pubkey, network), None) | ||
return foo is not None | ||
|
||
|
||
def load(pubkey, network): | ||
"""Load account that matches a pubkey.""" | ||
file = f"{network}.{ACCOUNTS_FILENAME}" | ||
|
||
if not os.path.exists(file): | ||
with open(file, "w") as fp: | ||
json.dump({}, fp) | ||
|
||
with open(file) as fp: | ||
accounts = json.load(fp) | ||
if pubkey in accounts: | ||
yield accounts[pubkey] | ||
|
||
|
||
def current_index(network): | ||
"""Return the length of the accounts. Used as the next index.""" | ||
file = f"{network}.{ACCOUNTS_FILENAME}" | ||
|
||
with open(file) as fp: | ||
accounts = json.load(fp) | ||
return len(accounts.keys()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
exemple
->example