Skip to content

Commit

Permalink
♻️ Remove 'db' prefix for crud commands
Browse files Browse the repository at this point in the history
  • Loading branch information
coccoinomane committed Mar 25, 2023
1 parent 629ed16 commit d4cd6d7
Show file tree
Hide file tree
Showing 26 changed files with 168 additions and 153 deletions.
57 changes: 45 additions & 12 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,104 @@
"request": "launch",
"module": "pytest",
"justMyCode": true,
"args": ["tests"]
"args": [
"tests"
]
},
{
"name": "tests - only db",
"type": "python",
"request": "launch",
"module": "pytest",
"justMyCode": true,
"args": ["tests", "-k", "test_db_base"]
"args": [
"tests",
"-k",
"test_db_base"
]
},
{
"name": "tests - only transact",
"type": "python",
"request": "launch",
"module": "pytest",
"justMyCode": true,
"args": ["tests", "-k", "test_transact"]
"args": [
"tests",
"-k",
"test_transact"
]
},
{
"name": "w3 block",
"type": "python",
"request": "launch",
"module": "web3cli.main",
"justMyCode": true,
"args": ["block"]
"args": [
"block"
]
},
{
"name": "w3 db chain get",
"name": "w3 chain get",
"type": "python",
"request": "launch",
"module": "web3cli.main",
"justMyCode": true,
"args": ["db", "chain", "get"]
"args": [
"chain",
"get"
]
},
{
"name": "w3 db chain list",
"name": "w3 chain list",
"type": "python",
"request": "launch",
"module": "web3cli.main",
"justMyCode": true,
"args": ["db", "chain", "list"]
"args": [
"chain",
"list"
]
},
{
"name": "w3 db signer list",
"name": "w3 signer list",
"type": "python",
"request": "launch",
"module": "web3cli.main",
"justMyCode": true,
"args": ["db", "signer", "list"]
"args": [
"signer",
"list"
]
},
{
"name": "getAmountsOut",
"type": "python",
"request": "launch",
"module": "web3cli.main",
"justMyCode": false,
"args": ["call", "uniswap_v2", "getAmountsOut", "100e6", "usdc,usdt"]
"args": [
"call",
"uniswap_v2",
"getAmountsOut",
"100e6",
"usdc,usdt"
]
},
{
"name": "getAmountsOut",
"type": "python",
"request": "launch",
"module": "web3cli.main",
"justMyCode": false,
"args": ["call", "uniswap_v2", "getAmountsOut", "100e6", "usdc,usdt"]
"args": [
"call",
"uniswap_v2",
"getAmountsOut",
"100e6",
"usdc,usdt"
]
}
]
}
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ The rule is simple: `pdm w3` runs against your working `web3cli` folder, while `
If you want to have a separate DB for your working `web3cli` folder, run:

```bash
pdm w3 config set db_file db --no-global
pdm w3 config set db_file newdb --no-global
```

This will create a `db` file in the current folder, which will be used by `web3cli` instead of the global one.
This will create a `newdb` file in the current folder, which will be used by `web3cli` instead of the global one.

# 5. Run tests

Expand Down
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ Windows user? [Here's a tutorial for you](https://github.com/coccoinomane/web3cl

- Save addresses with easy-to-rember tags:
```
w3 db address add unicef 0xa59b29d7dbc9794d1e7f45123c48b2b8d0a34636
w3 address add unicef 0xa59b29d7dbc9794d1e7f45123c48b2b8d0a34636
w3 address add unicef 0xa59b29d7dbc9794d1e7f45123c48b2b8d0a34636
```
then use the tag in any command:
```
Expand Down Expand Up @@ -116,17 +117,22 @@ Windows user? [Here's a tutorial for you](https://github.com/coccoinomane/web3cl

`web3cli` comes preloaded with some popular smart contracts, including ERC20 tokens and Uniswap clones.

See the available contracts with `w3 db contract list`:
See the available contracts with `w3 contract list`:
See the available contracts with `w3 contract list`:

```
w3 db contract list # contracts on Ethereum
w3 --chain bnb db contract list # contracts on BNB chain
w3 contract list # contracts on Ethereum
w3 contract list # contracts on Ethereum
w3 --chain bnb contract list # contracts on BNB chain
w3 --chain bnb contract list # contracts on BNB chain
```

You can also add custom contracts with `w3 db contract add`:
You can also add custom contracts with `w3 contract add`:
You can also add custom contracts with `w3 contract add`:

```
w3 db contract add weth 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 --type erc20
w3 contract add weth 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 --type erc20
w3 contract add weth 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 --type erc20
```

See available functions and events on a contract with `w3 abi functions` and `w3 abi events`:
Expand Down Expand Up @@ -203,20 +209,24 @@ w3 --chain eth balance 0x8894e0a0c962cb723c1976a4421c95949be2d4e3 # eth chain

# Add custom RPCs

Add custom RPCs to any existing chain with `w3 db rpc add`:
Add custom RPCs to any existing chain with `w3 rpc add`:
Add custom RPCs to any existing chain with `w3 rpc add`:

```
w3 db rpc add eth https://eth-mainnet.g.alchemy.com/v2/{YOUR API KEY}
w3 rpc add eth https://eth-mainnet.g.alchemy.com/v2/{YOUR API KEY}
w3 rpc add eth https://eth-mainnet.g.alchemy.com/v2/{YOUR API KEY}
```

List existing RPCs with `w3 db rpc list`, and delete them with `w3 db rpc delete`.
List existing RPCs with `w3 rpc list`, and delete them with `w3 rpc delete`.
List existing RPCs with `w3 rpc list`, and delete them with `w3 rpc delete`.
List existing RPCs with `w3 rpc list`, and delete them with `w3 rpc delete`.

# Add custom chains

Add new chains with `w3 db chain add`:
Add new chains with `w3 chain add`:

```
w3 db chain add cronos 25 CRO --tx-type 2 --rpc https://evm.cronos.org
w3 chain add cronos 25 CRO --tx-type 2 --rpc https://evm.cronos.org
```

Use the custom chain with `--chain`:
Expand All @@ -225,16 +235,16 @@ Use the custom chain with `--chain`:
w3 --chain cronos balance 0x7de9ab1e6a60ac7a70ce96d1d95a0dfcecf7bfb7
```

List existing chains with `w3 db chain list`, and delete them with `w3 db chain delete`.
List existing chains with `w3 chain list`, and delete them with `w3 chain delete`.


# Address book

`w3` can store tags just like you would do on etherscan.io or bscscan.com:

```bash
w3 db address add ethereum_foundation 0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae
w3 db address add binance_hot_wallet 0x8894e0a0c962cb723c1976a4421c95949be2d4e3
w3 address add ethereum_foundation 0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae
w3 address add binance_hot_wallet 0x8894e0a0c962cb723c1976a4421c95949be2d4e3
```

You can use these tags instead of the actual addresses:
Expand All @@ -244,27 +254,27 @@ w3 balance ethereum_foundation
w3 --chain bnb balance binance_hot_wallet
```

To see the list of saved addresses, run `w3 db address list`, to delete an address use `w3 db address delete`.
To see the list of saved addresses, run `w3 address list`, to delete an address use `w3 address delete`.

# Wallet management

Commands such as `w3 send` and `w3 sign` require that you add a signer first:

```bash
w3 db signer add my_signer
w3 signer add my_signer
```

You will be prompted to insert a private key, which will be encrypted and stored in the database.

You can also create a brand new wallet on the go, without the need to provide a key:

```
w3 db signer add my-wallet --create
w3 signer add my-wallet --create
```

### Multiple signers

Add more signers with `w3 db signer add` and select which one to use with the `--signer` flag:
Add more signers with `w3 signer add` and select which one to use with the `--signer` flag:

```bash
w3 --signer my_signer <command>
Expand Down
10 changes: 5 additions & 5 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@
- Use pipx to install web3cli (https://pypa.github.io/pipx/)
- Should be able to run `config get` and `config set` without a database
- Make web3cli extensible
- Use memory db for dev environment
- Use memory DB for dev environment
- Test ABI controller
- Make contract.type a foreign key to ContractType?
- Launch local block explorer after tests
- Enforce lowercase for all model names (at the db level?)
- Enforce lowercase for all model names (at the DB level?)
- Reset local chain between tests
- Fix setting boolean variables via env, e.g. `WEB3CLI_POPULATE_DB=0 w3 db chain list` or `WEB3CLI_POPULATE_DB=false w3 db chain list` should work as intended
- Define command shortcuts using argparse aliases, e.g. `w3 add-chain` instead of `w3 db chain add`
- Fix setting boolean variables via env, e.g. `WEB3CLI_POPULATE_DB=0 w3 chain list` or `WEB3CLI_POPULATE_DB=false w3 chain list` should work as intended
- Define command shortcuts using argparse aliases, e.g. `w3 add-chain` instead of `w3 chain add`
- Tests: use london hardfork instead of istanbul?
- Config: non-string support in `config set`
- Record all transactions in Txs table
- Fix usage message (still refers to `web3cli`)
- Make alphabetical order case insensitive for `w3 db contract list`
- Make alphabetical order case insensitive for `w3 contract list`
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from web3core.models.address import Address


class DbAddressController(Controller):
"""Handler of the `w3 db address` commands"""
class AddressController(Controller):
"""Handler of the `w3 address` CRUD commands"""

class Meta:
label = "address"
help = "add, list or delete addresses"
help = "add, edit, list or delete addresses"
stacked_type = "nested"
stacked_on = "db"
stacked_on = "base"

@ex(help="list address")
def list(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from web3core.seeds import chain_seeds


class DbChainController(Controller):
"""Handler of the `w3 db chain` commands"""
class ChainController(Controller):
"""Handler of the `w3 chain` CRUD commands"""

class Meta:
label = "chain"
help = "add, list or delete chains"
stacked_type = "nested"
stacked_on = "db"
stacked_on = "base"

@ex(
help="add a new chain",
Expand Down Expand Up @@ -118,5 +118,5 @@ def delete(self) -> None:
def seed(self) -> None:
chains = Chain.seed(chain_seeds.all, self.app.log.info)
self.app.log.info(
f"Imported {len(chains)} chains, run `w3 db chain list` to show them"
f"Imported {len(chains)} chains, run `w3 chain list` to show them"
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from web3core.seeds import contract_seeds


class DbContractController(Controller):
"""Handler of the `w3 db contract` commands"""
class ContractController(Controller):
"""Handler of the `w3 contract` CRUD commands"""

class Meta:
label = "contract"
help = "add, list or delete contracts"
stacked_type = "nested"
stacked_on = "db"
stacked_on = "base"

@ex(
help="list contracts",
Expand Down Expand Up @@ -138,5 +138,5 @@ def delete(self) -> None:
def seed(self) -> None:
seed_contracts(contract_seeds.all)
self.app.log.info(
f"Imported {len(contract_seeds.all)} contracts, run `w3 db contract list` to show them"
f"Imported {len(contract_seeds.all)} contracts, run `w3 contract list` to show them"
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
from web3core.models.tx import Tx


class DbTxController(Controller):
"""Handler of the `w3 db tx` commands"""
class HistoryController(Controller):
"""Handler of the `w3 history` CRUD commands"""

class Meta:
label = "trx" # trx instead of tx to avoid conflict with TxController
help = "add, list or delete transactions"
label = "history"
help = "add, list or delete transactions to the transaction history"
stacked_type = "nested"
stacked_on = "db"
aliases = ["tx"]
stacked_on = "base"

@ex(help="list transactions")
@ex(help="list transactions in the history")
def list(self) -> None:
render_table(
self.app,
Expand All @@ -31,7 +30,7 @@ def list(self) -> None:
)

@ex(
help="show details of the given transaction",
help="show details of the given transaction in the history",
arguments=[
(["hash"], {"help": "hash of the transaction"}),
],
Expand All @@ -41,7 +40,7 @@ def get(self) -> None:
self.app.render(model_to_dict(tx), indent=4, handler="json")

@ex(
help="add a new transaction to the database",
help="add a new transaction to the history",
arguments=[
(["hash"], {"help": "hash of the transaction"}),
(
Expand Down Expand Up @@ -80,7 +79,7 @@ def add(self) -> None:
)

@ex(
help="delete a transaction",
help="delete a transaction from the history",
arguments=[
(["hash"], {"help": "hash of the tx to delete"}),
],
Expand Down
Loading

0 comments on commit d4cd6d7

Please sign in to comment.