pleth 1.1.1__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.
pleth-1.1.1/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /.pytest_cache
2
+ /build
3
+ /dist
4
+ /pyeth.egg-info
pleth-1.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mohanson
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.
pleth-1.1.1/PKG-INFO ADDED
@@ -0,0 +1,137 @@
1
+ Metadata-Version: 2.3
2
+ Name: pleth
3
+ Version: 1.1.1
4
+ Summary: Python SDK for ETH
5
+ Project-URL: homepage, https://github.com/mohanson/pyeth
6
+ Author-email: Mohanson <mohanson@outlook.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2024 Mohanson
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ Requires-Dist: pycryptodome
29
+ Requires-Dist: requests
30
+ Description-Content-Type: text/markdown
31
+
32
+ # Python SDK for ETH
33
+
34
+ Python ETH is an experimental project that aims to provide human-friendly interfaces for common ETH operations. Note that Python ETH is not a complete SDK, but only implements the ETH functions that I am interested in.
35
+
36
+ ## Installation
37
+
38
+ ```sh
39
+ $ git clone https://github.com/mohanson/pyeth
40
+ $ cd pyeth
41
+ $ python -m pip install --editable .
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ **example/addr.py**
47
+
48
+ Calculate the address from a private key.
49
+
50
+ ```sh
51
+ $ python example/addr.py --prikey 0x1
52
+
53
+ # 0x7e5f4552091a69125d5dfcb7b8c2659029395bdf
54
+ ```
55
+
56
+ **example/balance.py**
57
+
58
+ Get the balance by an address.
59
+
60
+ ```sh
61
+ $ python example/balance.py --addr 0x7e5f4552091a69125d5dfcb7b8c2659029395bdf
62
+
63
+ # 39934.9989371221
64
+ ```
65
+
66
+ **example/collision.py**
67
+
68
+ Generate a random private key and check whether there are assets under the private key.
69
+
70
+ ```sh
71
+ $ python example/collision.py --net mainnet
72
+ ```
73
+
74
+ **example/scan_erc20.py**
75
+
76
+ Print all usdt transfer events in the last block.
77
+
78
+ ```sh
79
+ $ python example/scan_erc20.py
80
+
81
+ # 0x4d74d6fb5a75d121cda9f9dfbd0bd074999b43731f17140606ea57eccb5a7192
82
+ # 0x11b815efb8f581194ae79006d24e0d814b7697f6 0xa69babef1ca67a37ffaf7a485dfff3382056e78c 135241.983213
83
+ # ...
84
+ ```
85
+
86
+ **example/scan_eth.py**
87
+
88
+ Get the latest block and print out the transaction hash, sender, receiver and value(in ether).
89
+
90
+ ```sh
91
+ $ python example/scan_eth.py --net mainnet
92
+
93
+ # 0x41733e4e2b1537c9be99ad591c2e2a608dbff547ebd91acbb65e9a205aceb3ff
94
+ # 0x9ab23085cb3e847d37819a712512dfd5d60c8d88 0x429cf888dae41d589d57f6dc685707bec755fe63 1.9937829e-11
95
+ # ...
96
+ ```
97
+
98
+ **example/storage.py**
99
+
100
+ Publish a storage contract, then store a number 42 in the contract, and finally read this number.
101
+
102
+ ```sh
103
+ $ python example/storage.py --action deploy --prikey 0x1
104
+ # hash = 0xc4a663c8a867d1d6fcbb8b57794eb732baa1bf6cb4c1b0c1cee278e00c8fd644
105
+ # addr = 0x930b793f778bbf43fab1080abf1840e018831cde
106
+
107
+ $ python example/storage.py --action set --addr 0x930b793f778bbf43fab1080abf1840e018831cde --prikey 0x1
108
+ # hash = 0x95c3fab08f6f4dcac14db157c2c2936417ae528acf9637fd50f772ac617072b5
109
+
110
+ $ python example/storage.py --action get --addr 0x930b793f778bbf43fab1080abf1840e018831cde
111
+ # data = 0x000000000000000000000000000000000000000000000000000000000000002a
112
+ ```
113
+
114
+ **example/transfer.py**
115
+
116
+ Transfer ether to other.
117
+
118
+ ```sh
119
+ $ python example/transfer.py --prikey 0x1 --to 0x2b5ad5c4795c026514f8317c7a215e218dccd6cf --value 0.05
120
+ # 0xfdeb27f32a21c793562daa8fa2780546e3304620a9925337c7df5e4e9819ef3a
121
+ ```
122
+
123
+ ## Test
124
+
125
+ ```sh
126
+ $ git clone https://github.com/ethereum/go-ethereum --branch release/1.14
127
+ $ cd go-ethereum
128
+ $ make geth
129
+
130
+ $ geth --dev --http
131
+ $ geth --exec "eth.sendTransaction({from: eth.accounts[0], to: '0x7e5f4552091a69125d5dfcb7b8c2659029395bdf', value: web3.toWei(10000, 'ether')})" attach /tmp/geth.ipc
132
+ $ pytest -v
133
+ ```
134
+
135
+ ## License
136
+
137
+ MIT
pleth-1.1.1/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # Python SDK for ETH
2
+
3
+ Python ETH is an experimental project that aims to provide human-friendly interfaces for common ETH operations. Note that Python ETH is not a complete SDK, but only implements the ETH functions that I am interested in.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ $ git clone https://github.com/mohanson/pyeth
9
+ $ cd pyeth
10
+ $ python -m pip install --editable .
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ **example/addr.py**
16
+
17
+ Calculate the address from a private key.
18
+
19
+ ```sh
20
+ $ python example/addr.py --prikey 0x1
21
+
22
+ # 0x7e5f4552091a69125d5dfcb7b8c2659029395bdf
23
+ ```
24
+
25
+ **example/balance.py**
26
+
27
+ Get the balance by an address.
28
+
29
+ ```sh
30
+ $ python example/balance.py --addr 0x7e5f4552091a69125d5dfcb7b8c2659029395bdf
31
+
32
+ # 39934.9989371221
33
+ ```
34
+
35
+ **example/collision.py**
36
+
37
+ Generate a random private key and check whether there are assets under the private key.
38
+
39
+ ```sh
40
+ $ python example/collision.py --net mainnet
41
+ ```
42
+
43
+ **example/scan_erc20.py**
44
+
45
+ Print all usdt transfer events in the last block.
46
+
47
+ ```sh
48
+ $ python example/scan_erc20.py
49
+
50
+ # 0x4d74d6fb5a75d121cda9f9dfbd0bd074999b43731f17140606ea57eccb5a7192
51
+ # 0x11b815efb8f581194ae79006d24e0d814b7697f6 0xa69babef1ca67a37ffaf7a485dfff3382056e78c 135241.983213
52
+ # ...
53
+ ```
54
+
55
+ **example/scan_eth.py**
56
+
57
+ Get the latest block and print out the transaction hash, sender, receiver and value(in ether).
58
+
59
+ ```sh
60
+ $ python example/scan_eth.py --net mainnet
61
+
62
+ # 0x41733e4e2b1537c9be99ad591c2e2a608dbff547ebd91acbb65e9a205aceb3ff
63
+ # 0x9ab23085cb3e847d37819a712512dfd5d60c8d88 0x429cf888dae41d589d57f6dc685707bec755fe63 1.9937829e-11
64
+ # ...
65
+ ```
66
+
67
+ **example/storage.py**
68
+
69
+ Publish a storage contract, then store a number 42 in the contract, and finally read this number.
70
+
71
+ ```sh
72
+ $ python example/storage.py --action deploy --prikey 0x1
73
+ # hash = 0xc4a663c8a867d1d6fcbb8b57794eb732baa1bf6cb4c1b0c1cee278e00c8fd644
74
+ # addr = 0x930b793f778bbf43fab1080abf1840e018831cde
75
+
76
+ $ python example/storage.py --action set --addr 0x930b793f778bbf43fab1080abf1840e018831cde --prikey 0x1
77
+ # hash = 0x95c3fab08f6f4dcac14db157c2c2936417ae528acf9637fd50f772ac617072b5
78
+
79
+ $ python example/storage.py --action get --addr 0x930b793f778bbf43fab1080abf1840e018831cde
80
+ # data = 0x000000000000000000000000000000000000000000000000000000000000002a
81
+ ```
82
+
83
+ **example/transfer.py**
84
+
85
+ Transfer ether to other.
86
+
87
+ ```sh
88
+ $ python example/transfer.py --prikey 0x1 --to 0x2b5ad5c4795c026514f8317c7a215e218dccd6cf --value 0.05
89
+ # 0xfdeb27f32a21c793562daa8fa2780546e3304620a9925337c7df5e4e9819ef3a
90
+ ```
91
+
92
+ ## Test
93
+
94
+ ```sh
95
+ $ git clone https://github.com/ethereum/go-ethereum --branch release/1.14
96
+ $ cd go-ethereum
97
+ $ make geth
98
+
99
+ $ geth --dev --http
100
+ $ geth --exec "eth.sendTransaction({from: eth.accounts[0], to: '0x7e5f4552091a69125d5dfcb7b8c2659029395bdf', value: web3.toWei(10000, 'ether')})" attach /tmp/geth.ipc
101
+ $ pytest -v
102
+ ```
103
+
104
+ ## License
105
+
106
+ MIT
@@ -0,0 +1,9 @@
1
+ from . import abi
2
+ from . import config
3
+ from . import core
4
+ from . import denomination
5
+ from . import ecdsa
6
+ from . import rlp
7
+ from . import rpc
8
+ from . import secp256k1
9
+ from . import wallet
pleth-1.1.1/eth/abi.py ADDED
@@ -0,0 +1,41 @@
1
+ import eth.core
2
+ import typing
3
+
4
+ # The Contract Application Binary Interface (ABI) is the standard way to interact with contracts in the Ethereum
5
+ # ecosystem, both from outside the blockchain and for contract-to-contract interaction. Data is encoded according to
6
+ # its type, as described in this specification. The encoding is not self describing and thus requires a schema in order
7
+ # to decode.
8
+ #
9
+ # See: https://docs.soliditylang.org/en/latest/abi-spec.html
10
+
11
+ def encode_uint256(data: int) -> bytearray:
12
+ assert data >= 0
13
+ assert data <= 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
14
+ return bytearray(data.to_bytes(32))
15
+
16
+
17
+ def decode_uint256(data: bytearray) -> int:
18
+ assert len(data) == 32
19
+ return int.from_bytes(data)
20
+
21
+
22
+ def encode_address(data: bytearray) -> bytearray:
23
+ assert len(data) == 20
24
+ return bytearray(12) + data
25
+
26
+
27
+ def decode_address(data: bytearray) -> bytearray:
28
+ assert len(data) == 32
29
+ return data[12:]
30
+
31
+
32
+ def function_selector(name: str, args_type: typing.List[str]) -> bytearray:
33
+ s = name + '(' + ','.join(args_type) + ')'
34
+ return eth.core.hash(bytearray(s.encode()))[:4]
35
+
36
+
37
+ def argument_encoding(data: typing.List[bytearray]) -> bytearray:
38
+ s = bytearray()
39
+ for e in data:
40
+ s.extend(e)
41
+ return s
@@ -0,0 +1,46 @@
1
+ import random
2
+ import requests
3
+ import typing
4
+
5
+
6
+ class ObjectDict(dict):
7
+ def __getattr__(self, name: str) -> typing.Any:
8
+ try:
9
+ return self[name]
10
+ except KeyError:
11
+ raise AttributeError(name)
12
+
13
+ def __setattr__(self, name: str, value: typing.Any):
14
+ self[name] = value
15
+
16
+
17
+ develop = ObjectDict({
18
+ 'chain_id': 1337,
19
+ 'gas_base_fee': 21000,
20
+ 'url': 'http://127.0.0.1:8545',
21
+ })
22
+
23
+ mainnet = ObjectDict({
24
+ 'chain_id': 1,
25
+ 'gas_base_fee': 21000,
26
+ 'url': 'https://eth.drpc.org',
27
+ })
28
+
29
+ testnet = ObjectDict({
30
+ 'chain_id': 11155111,
31
+ 'gas_base_fee': 21000,
32
+ 'url': 'https://rpc.sepolia.org',
33
+ })
34
+
35
+
36
+ def upgrade(url: str):
37
+ develop.chain_id = int(requests.post(url, json={
38
+ 'id': random.randint(0x00000000, 0xffffffff),
39
+ 'jsonrpc': '2.0',
40
+ 'method': 'eth_chainId',
41
+ 'params': []
42
+ }).json()['result'], 0)
43
+ develop.url = url
44
+
45
+
46
+ current = develop