fastweb3-console 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastweb3_console-0.1.0/LICENSE +21 -0
- fastweb3_console-0.1.0/PKG-INFO +98 -0
- fastweb3_console-0.1.0/README.md +68 -0
- fastweb3_console-0.1.0/pyproject.toml +66 -0
- fastweb3_console-0.1.0/setup.cfg +4 -0
- fastweb3_console-0.1.0/src/fastweb3_console.egg-info/PKG-INFO +98 -0
- fastweb3_console-0.1.0/src/fastweb3_console.egg-info/SOURCES.txt +26 -0
- fastweb3_console-0.1.0/src/fastweb3_console.egg-info/dependency_links.txt +1 -0
- fastweb3_console-0.1.0/src/fastweb3_console.egg-info/entry_points.txt +2 -0
- fastweb3_console-0.1.0/src/fastweb3_console.egg-info/requires.txt +19 -0
- fastweb3_console-0.1.0/src/fastweb3_console.egg-info/top_level.txt +1 -0
- fastweb3_console-0.1.0/src/fw3_console/__init__.py +0 -0
- fastweb3_console-0.1.0/src/fw3_console/autosuggest.py +63 -0
- fastweb3_console-0.1.0/src/fw3_console/cli.py +104 -0
- fastweb3_console-0.1.0/src/fw3_console/completion.py +163 -0
- fastweb3_console-0.1.0/src/fw3_console/contracts.py +155 -0
- fastweb3_console-0.1.0/src/fw3_console/display.py +71 -0
- fastweb3_console-0.1.0/src/fw3_console/history.py +114 -0
- fastweb3_console-0.1.0/src/fw3_console/parser.py +114 -0
- fastweb3_console-0.1.0/src/fw3_console/proxy_warnings.py +76 -0
- fastweb3_console-0.1.0/src/fw3_console/resolver.py +158 -0
- fastweb3_console-0.1.0/tests/test_autosuggest.py +114 -0
- fastweb3_console-0.1.0/tests/test_branches.py +219 -0
- fastweb3_console-0.1.0/tests/test_completion.py +193 -0
- fastweb3_console-0.1.0/tests/test_displayhook.py +74 -0
- fastweb3_console-0.1.0/tests/test_history.py +80 -0
- fastweb3_console-0.1.0/tests/test_parser.py +20 -0
- fastweb3_console-0.1.0/tests/test_proxy_warnings.py +45 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 iamdefinitelyahuman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastweb3-console
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Interactive console and script runner for working with EVM blockchains.
|
|
5
|
+
Author: iamdefinitelyahuman
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/iamdefinitelyahuman/fastweb3-console
|
|
8
|
+
Project-URL: Repository, https://github.com/iamdefinitelyahuman/fastweb3-console
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: fastweb3-objects<0.2.0,>=0.1.3
|
|
13
|
+
Requires-Dist: lazy-object-proxy>=1.12.0
|
|
14
|
+
Requires-Dist: platformdirs>=4.0
|
|
15
|
+
Requires-Dist: prompt-toolkit<4.0.0,>=3.0.52
|
|
16
|
+
Requires-Dist: pygments>=2.18
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
19
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
20
|
+
Requires-Dist: ruff>=0.9; extra == "dev"
|
|
21
|
+
Requires-Dist: pre-commit>=3; extra == "dev"
|
|
22
|
+
Requires-Dist: build; extra == "dev"
|
|
23
|
+
Requires-Dist: twine; extra == "dev"
|
|
24
|
+
Requires-Dist: mkdocs>=1.6; extra == "dev"
|
|
25
|
+
Requires-Dist: mkdocs-material>=9.5; extra == "dev"
|
|
26
|
+
Provides-Extra: docs
|
|
27
|
+
Requires-Dist: mkdocs>=1.6; extra == "docs"
|
|
28
|
+
Requires-Dist: mkdocs-material>=9.5; extra == "docs"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# fastweb3-console
|
|
32
|
+
|
|
33
|
+
Interactive console and script runner for working with EVM blockchains.
|
|
34
|
+
|
|
35
|
+
**NOTE**: This library is still in early alpha development. Prior to a `v1.0.0` (which may never come), expect breaking changes and no backward compatibility between versions.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
You can install the latest release via `pip`:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install fastweb3-console
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Or clone the repository for the most up-to-date version:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
git clone https://github.com/iamdefinitelyahuman/fastweb3-console.git
|
|
49
|
+
cd fastweb3-console
|
|
50
|
+
pip install -e .
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
Launch the console with:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
fw3
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The console starts as a normal Python REPL with the main [`fastweb3-objects`](https://github.com/iamdefinitelyahuman/fastweb3-objects) entry points already available:
|
|
62
|
+
|
|
63
|
+
```py
|
|
64
|
+
>>> accounts
|
|
65
|
+
<Accounts ...>
|
|
66
|
+
>>> Chain
|
|
67
|
+
<class 'fw3_objects.chain.Chain'>
|
|
68
|
+
>>> Contract
|
|
69
|
+
<class 'fw3_objects.contract.Contract'>
|
|
70
|
+
>>> Transaction
|
|
71
|
+
<class 'fw3_objects.transaction.Transaction'>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Users familiar with the Brownie console should feel right at home.
|
|
75
|
+
|
|
76
|
+
## Development
|
|
77
|
+
|
|
78
|
+
First, install the dev dependencies:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install -e ".[dev]"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Run the test suite with:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pytest
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Run linting with:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
ruff check .
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
This project is licensed under the MIT license.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# fastweb3-console
|
|
2
|
+
|
|
3
|
+
Interactive console and script runner for working with EVM blockchains.
|
|
4
|
+
|
|
5
|
+
**NOTE**: This library is still in early alpha development. Prior to a `v1.0.0` (which may never come), expect breaking changes and no backward compatibility between versions.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
You can install the latest release via `pip`:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install fastweb3-console
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or clone the repository for the most up-to-date version:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/iamdefinitelyahuman/fastweb3-console.git
|
|
19
|
+
cd fastweb3-console
|
|
20
|
+
pip install -e .
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Launch the console with:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
fw3
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The console starts as a normal Python REPL with the main [`fastweb3-objects`](https://github.com/iamdefinitelyahuman/fastweb3-objects) entry points already available:
|
|
32
|
+
|
|
33
|
+
```py
|
|
34
|
+
>>> accounts
|
|
35
|
+
<Accounts ...>
|
|
36
|
+
>>> Chain
|
|
37
|
+
<class 'fw3_objects.chain.Chain'>
|
|
38
|
+
>>> Contract
|
|
39
|
+
<class 'fw3_objects.contract.Contract'>
|
|
40
|
+
>>> Transaction
|
|
41
|
+
<class 'fw3_objects.transaction.Transaction'>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Users familiar with the Brownie console should feel right at home.
|
|
45
|
+
|
|
46
|
+
## Development
|
|
47
|
+
|
|
48
|
+
First, install the dev dependencies:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install -e ".[dev]"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Run the test suite with:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pytest
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Run linting with:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
ruff check .
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
This project is licensed under the MIT license.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fastweb3-console"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Interactive console and script runner for working with EVM blockchains."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "iamdefinitelyahuman" }
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
dependencies = [
|
|
17
|
+
"fastweb3-objects>=0.1.3,<0.2.0",
|
|
18
|
+
"lazy-object-proxy>=1.12.0",
|
|
19
|
+
"platformdirs>=4.0",
|
|
20
|
+
"prompt-toolkit>=3.0.52,<4.0.0",
|
|
21
|
+
"pygments>=2.18",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
dev = [
|
|
26
|
+
"pytest>=8",
|
|
27
|
+
"pytest-cov>=5",
|
|
28
|
+
"ruff>=0.9",
|
|
29
|
+
"pre-commit>=3",
|
|
30
|
+
"build",
|
|
31
|
+
"twine",
|
|
32
|
+
"mkdocs>=1.6",
|
|
33
|
+
"mkdocs-material>=9.5",
|
|
34
|
+
]
|
|
35
|
+
docs = [
|
|
36
|
+
"mkdocs>=1.6",
|
|
37
|
+
"mkdocs-material>=9.5",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.scripts]
|
|
41
|
+
fw3 = "fw3_console.cli:main"
|
|
42
|
+
|
|
43
|
+
[project.urls]
|
|
44
|
+
Homepage = "https://github.com/iamdefinitelyahuman/fastweb3-console"
|
|
45
|
+
Repository = "https://github.com/iamdefinitelyahuman/fastweb3-console"
|
|
46
|
+
|
|
47
|
+
[tool.setuptools]
|
|
48
|
+
package-dir = {"" = "src"}
|
|
49
|
+
|
|
50
|
+
[tool.setuptools.packages.find]
|
|
51
|
+
where = ["src"]
|
|
52
|
+
|
|
53
|
+
[tool.ruff]
|
|
54
|
+
line-length = 100
|
|
55
|
+
target-version = "py312"
|
|
56
|
+
|
|
57
|
+
[tool.ruff.lint]
|
|
58
|
+
select = ["E", "F", "I"]
|
|
59
|
+
|
|
60
|
+
[tool.pytest.ini_options]
|
|
61
|
+
addopts = [
|
|
62
|
+
"--cov=fw3_console",
|
|
63
|
+
"--cov-report=term-missing",
|
|
64
|
+
"--cov-report=xml",
|
|
65
|
+
]
|
|
66
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastweb3-console
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Interactive console and script runner for working with EVM blockchains.
|
|
5
|
+
Author: iamdefinitelyahuman
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/iamdefinitelyahuman/fastweb3-console
|
|
8
|
+
Project-URL: Repository, https://github.com/iamdefinitelyahuman/fastweb3-console
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: fastweb3-objects<0.2.0,>=0.1.3
|
|
13
|
+
Requires-Dist: lazy-object-proxy>=1.12.0
|
|
14
|
+
Requires-Dist: platformdirs>=4.0
|
|
15
|
+
Requires-Dist: prompt-toolkit<4.0.0,>=3.0.52
|
|
16
|
+
Requires-Dist: pygments>=2.18
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
19
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
20
|
+
Requires-Dist: ruff>=0.9; extra == "dev"
|
|
21
|
+
Requires-Dist: pre-commit>=3; extra == "dev"
|
|
22
|
+
Requires-Dist: build; extra == "dev"
|
|
23
|
+
Requires-Dist: twine; extra == "dev"
|
|
24
|
+
Requires-Dist: mkdocs>=1.6; extra == "dev"
|
|
25
|
+
Requires-Dist: mkdocs-material>=9.5; extra == "dev"
|
|
26
|
+
Provides-Extra: docs
|
|
27
|
+
Requires-Dist: mkdocs>=1.6; extra == "docs"
|
|
28
|
+
Requires-Dist: mkdocs-material>=9.5; extra == "docs"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# fastweb3-console
|
|
32
|
+
|
|
33
|
+
Interactive console and script runner for working with EVM blockchains.
|
|
34
|
+
|
|
35
|
+
**NOTE**: This library is still in early alpha development. Prior to a `v1.0.0` (which may never come), expect breaking changes and no backward compatibility between versions.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
You can install the latest release via `pip`:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install fastweb3-console
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Or clone the repository for the most up-to-date version:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
git clone https://github.com/iamdefinitelyahuman/fastweb3-console.git
|
|
49
|
+
cd fastweb3-console
|
|
50
|
+
pip install -e .
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
Launch the console with:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
fw3
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The console starts as a normal Python REPL with the main [`fastweb3-objects`](https://github.com/iamdefinitelyahuman/fastweb3-objects) entry points already available:
|
|
62
|
+
|
|
63
|
+
```py
|
|
64
|
+
>>> accounts
|
|
65
|
+
<Accounts ...>
|
|
66
|
+
>>> Chain
|
|
67
|
+
<class 'fw3_objects.chain.Chain'>
|
|
68
|
+
>>> Contract
|
|
69
|
+
<class 'fw3_objects.contract.Contract'>
|
|
70
|
+
>>> Transaction
|
|
71
|
+
<class 'fw3_objects.transaction.Transaction'>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Users familiar with the Brownie console should feel right at home.
|
|
75
|
+
|
|
76
|
+
## Development
|
|
77
|
+
|
|
78
|
+
First, install the dev dependencies:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install -e ".[dev]"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Run the test suite with:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pytest
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Run linting with:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
ruff check .
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
This project is licensed under the MIT license.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/fastweb3_console.egg-info/PKG-INFO
|
|
5
|
+
src/fastweb3_console.egg-info/SOURCES.txt
|
|
6
|
+
src/fastweb3_console.egg-info/dependency_links.txt
|
|
7
|
+
src/fastweb3_console.egg-info/entry_points.txt
|
|
8
|
+
src/fastweb3_console.egg-info/requires.txt
|
|
9
|
+
src/fastweb3_console.egg-info/top_level.txt
|
|
10
|
+
src/fw3_console/__init__.py
|
|
11
|
+
src/fw3_console/autosuggest.py
|
|
12
|
+
src/fw3_console/cli.py
|
|
13
|
+
src/fw3_console/completion.py
|
|
14
|
+
src/fw3_console/contracts.py
|
|
15
|
+
src/fw3_console/display.py
|
|
16
|
+
src/fw3_console/history.py
|
|
17
|
+
src/fw3_console/parser.py
|
|
18
|
+
src/fw3_console/proxy_warnings.py
|
|
19
|
+
src/fw3_console/resolver.py
|
|
20
|
+
tests/test_autosuggest.py
|
|
21
|
+
tests/test_branches.py
|
|
22
|
+
tests/test_completion.py
|
|
23
|
+
tests/test_displayhook.py
|
|
24
|
+
tests/test_history.py
|
|
25
|
+
tests/test_parser.py
|
|
26
|
+
tests/test_proxy_warnings.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
fastweb3-objects<0.2.0,>=0.1.3
|
|
2
|
+
lazy-object-proxy>=1.12.0
|
|
3
|
+
platformdirs>=4.0
|
|
4
|
+
prompt-toolkit<4.0.0,>=3.0.52
|
|
5
|
+
pygments>=2.18
|
|
6
|
+
|
|
7
|
+
[dev]
|
|
8
|
+
pytest>=8
|
|
9
|
+
pytest-cov>=5
|
|
10
|
+
ruff>=0.9
|
|
11
|
+
pre-commit>=3
|
|
12
|
+
build
|
|
13
|
+
twine
|
|
14
|
+
mkdocs>=1.6
|
|
15
|
+
mkdocs-material>=9.5
|
|
16
|
+
|
|
17
|
+
[docs]
|
|
18
|
+
mkdocs>=1.6
|
|
19
|
+
mkdocs-material>=9.5
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fw3_console
|
|
File without changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
"""Ghost-text call suggestions for the interactive console."""
|
|
4
|
+
|
|
5
|
+
from prompt_toolkit.auto_suggest import AutoSuggest, Suggestion
|
|
6
|
+
|
|
7
|
+
from .contracts import call_suggestion_parts
|
|
8
|
+
from .parser import active_call_context
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def make_call_suggestion(method, arg_index, current_arg, bound_receiver=False, invocation=None):
|
|
12
|
+
"""Build the visible ghost text for the active call, if it is unambiguous."""
|
|
13
|
+
parts = call_suggestion_parts(method, bound_receiver, invocation)
|
|
14
|
+
if parts is None:
|
|
15
|
+
return None
|
|
16
|
+
|
|
17
|
+
if parts and isinstance(parts[0], list):
|
|
18
|
+
matches = [item for item in parts if len(item) > arg_index or (not item and arg_index == 0)]
|
|
19
|
+
if len(matches) != 1:
|
|
20
|
+
return None
|
|
21
|
+
parts = matches[0]
|
|
22
|
+
|
|
23
|
+
if arg_index >= len(parts):
|
|
24
|
+
return Suggestion(")")
|
|
25
|
+
|
|
26
|
+
current_part = parts[arg_index]
|
|
27
|
+
next_parts = parts[arg_index + 1 :]
|
|
28
|
+
typed = current_arg.lstrip()
|
|
29
|
+
|
|
30
|
+
if typed:
|
|
31
|
+
if len(typed) < len(current_part):
|
|
32
|
+
suggestion = current_part[len(typed) :]
|
|
33
|
+
if next_parts:
|
|
34
|
+
suggestion += ", " + ", ".join(next_parts)
|
|
35
|
+
else:
|
|
36
|
+
suggestion = ", ".join(next_parts)
|
|
37
|
+
if suggestion:
|
|
38
|
+
suggestion = ", " + suggestion
|
|
39
|
+
return Suggestion(suggestion + ")")
|
|
40
|
+
|
|
41
|
+
remaining = ", ".join(parts[arg_index:])
|
|
42
|
+
prefix = " " if current_arg else ""
|
|
43
|
+
return Suggestion(prefix + remaining + ")")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ConsoleAutoSuggest(AutoSuggest):
|
|
47
|
+
"""Prompt-toolkit autosuggest adapter backed by call-context parsing."""
|
|
48
|
+
|
|
49
|
+
def __init__(self, namespace):
|
|
50
|
+
self.namespace = namespace
|
|
51
|
+
|
|
52
|
+
def get_suggestion(self, buffer, document):
|
|
53
|
+
context = active_call_context(document.text_before_cursor, self.namespace)
|
|
54
|
+
if context is None:
|
|
55
|
+
return None
|
|
56
|
+
|
|
57
|
+
return make_call_suggestion(
|
|
58
|
+
context.obj,
|
|
59
|
+
context.arg_index,
|
|
60
|
+
context.current_arg,
|
|
61
|
+
context.bound_receiver,
|
|
62
|
+
context.invocation,
|
|
63
|
+
)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
"""Interactive console entry point and prompt-toolkit wiring."""
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from code import InteractiveConsole
|
|
7
|
+
from importlib.metadata import version
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from fw3_objects import Accounts, Chain, Contract, Transaction
|
|
11
|
+
from platformdirs import user_cache_dir
|
|
12
|
+
from prompt_toolkit import PromptSession
|
|
13
|
+
from prompt_toolkit.key_binding import KeyBindings
|
|
14
|
+
from prompt_toolkit.lexers import PygmentsLexer
|
|
15
|
+
from prompt_toolkit.styles import style_from_pygments_cls
|
|
16
|
+
from pygments.lexers import PythonLexer
|
|
17
|
+
|
|
18
|
+
from .autosuggest import ConsoleAutoSuggest
|
|
19
|
+
from .completion import ConsoleCompleter
|
|
20
|
+
from .display import PYGMENTS_STYLE, displayhook, write_highlighted
|
|
21
|
+
from .history import SafeFileHistory
|
|
22
|
+
from .proxy_warnings import warn_proxy_identity_comparisons
|
|
23
|
+
|
|
24
|
+
_CONSOLE_STYLE = style_from_pygments_cls(PYGMENTS_STYLE)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _console_key_bindings():
|
|
28
|
+
"""Return console key bindings that override awkward prompt defaults."""
|
|
29
|
+
key_bindings = KeyBindings()
|
|
30
|
+
|
|
31
|
+
@key_bindings.add("right")
|
|
32
|
+
def _(event):
|
|
33
|
+
event.current_buffer.cursor_right(count=event.arg)
|
|
34
|
+
|
|
35
|
+
return key_bindings
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Console(InteractiveConsole):
|
|
39
|
+
"""Interactive fastweb3 console.
|
|
40
|
+
|
|
41
|
+
This class owns the small amount of glue that makes the shell feel different
|
|
42
|
+
from a plain Python REPL: prompt-toolkit completions/autosuggest, sanitized
|
|
43
|
+
history, highlighted output, and warnings for proxy identity comparisons.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(self):
|
|
47
|
+
history_path = Path(user_cache_dir("fw3-console")) / "history"
|
|
48
|
+
history_path.parent.mkdir(parents=True, exist_ok=True)
|
|
49
|
+
|
|
50
|
+
namespace = {
|
|
51
|
+
"accounts": Accounts(unlock=False),
|
|
52
|
+
"Contract": Contract,
|
|
53
|
+
"Chain": Chain,
|
|
54
|
+
"Transaction": Transaction,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
self.prompt_session = PromptSession(
|
|
58
|
+
completer=ConsoleCompleter(namespace),
|
|
59
|
+
lexer=PygmentsLexer(PythonLexer),
|
|
60
|
+
auto_suggest=ConsoleAutoSuggest(namespace),
|
|
61
|
+
key_bindings=_console_key_bindings(),
|
|
62
|
+
history=SafeFileHistory(history_path, namespace),
|
|
63
|
+
style=_CONSOLE_STYLE,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
super().__init__(namespace)
|
|
67
|
+
|
|
68
|
+
def raw_input(self, prompt=""):
|
|
69
|
+
return self.prompt_session.prompt(prompt)
|
|
70
|
+
|
|
71
|
+
def runsource(self, source, filename="<input>", symbol="single"):
|
|
72
|
+
"""Compile and run one input block with pre-execution console checks."""
|
|
73
|
+
try:
|
|
74
|
+
code = self.compile(source, filename, symbol)
|
|
75
|
+
except (OverflowError, SyntaxError, ValueError):
|
|
76
|
+
self.showsyntaxerror(filename)
|
|
77
|
+
return False
|
|
78
|
+
|
|
79
|
+
if code is None:
|
|
80
|
+
return True
|
|
81
|
+
|
|
82
|
+
warn_proxy_identity_comparisons(source, self.locals)
|
|
83
|
+
self.runcode(code)
|
|
84
|
+
return False
|
|
85
|
+
|
|
86
|
+
def runcode(self, code):
|
|
87
|
+
"""Run code with the console displayhook installed temporarily."""
|
|
88
|
+
old_displayhook = sys.displayhook
|
|
89
|
+
sys.displayhook = displayhook
|
|
90
|
+
try:
|
|
91
|
+
super().runcode(code)
|
|
92
|
+
finally:
|
|
93
|
+
sys.displayhook = old_displayhook
|
|
94
|
+
|
|
95
|
+
def write(self, data):
|
|
96
|
+
write_highlighted(data)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def main():
|
|
100
|
+
"""Start the interactive console."""
|
|
101
|
+
ver = version("fastweb3-console")
|
|
102
|
+
print(f"fastweb3-console v{ver}: interactive console for EVM blockchains")
|
|
103
|
+
console = Console()
|
|
104
|
+
console.interact(banner="")
|