38
38
from mnemonic import Mnemonic
39
39
from autobahn .xbr ._mnemonic import mnemonic_to_private_key
40
40
41
+ # monkey patch eth_abi for master branch (which we need for python 3.11)
42
+ # https://github.com/ethereum/eth-abi/blob/master/docs/release_notes.rst#breaking-changes
43
+ # https://github.com/ethereum/eth-abi/pull/161
44
+ # ImportError: cannot import name 'encode_single' from 'eth_abi' (/home/oberstet/cpy311_2/lib/python3.11/site-packages/eth_abi/__init__.py)
45
+ import eth_abi
46
+
47
+ if not hasattr (eth_abi , 'encode_abi' ) and hasattr (eth_abi , 'encode' ):
48
+ eth_abi .encode_abi = eth_abi .encode
49
+ if not hasattr (eth_abi , 'encode_single' ) and hasattr (eth_abi , 'encode' ):
50
+ eth_abi .encode_single = lambda typ , val : eth_abi .encode ([typ ], [val ])
51
+
41
52
# monkey patch, see:
42
53
# https://github.com/ethereum/web3.py/issues/1201
43
54
# https://github.com/ethereum/eth-abi/pull/88
44
- from eth_abi import abi
45
-
46
- import eth_account
47
-
48
- from autobahn .xbr ._abi import XBR_TOKEN_ABI , XBR_NETWORK_ABI , XBR_MARKET_ABI , XBR_CATALOG_ABI , XBR_CHANNEL_ABI # noqa
49
- from autobahn .xbr ._abi import XBR_DEBUG_TOKEN_ADDR , XBR_DEBUG_NETWORK_ADDR , XBR_DEBUG_MARKET_ADDR , XBR_DEBUG_CATALOG_ADDR , XBR_DEBUG_CHANNEL_ADDR # noqa
50
- from autobahn .xbr ._abi import XBR_DEBUG_TOKEN_ADDR_SRC , XBR_DEBUG_NETWORK_ADDR_SRC , XBR_DEBUG_MARKET_ADDR_SRC , XBR_DEBUG_CATALOG_ADDR_SRC , XBR_DEBUG_CHANNEL_ADDR_SRC # noqa
51
- from autobahn .xbr ._interfaces import IMarketMaker , IProvider , IConsumer , ISeller , IBuyer , IDelegate # noqa
52
- from autobahn .xbr ._util import make_w3 , pack_uint256 , unpack_uint256 # noqa
53
- from autobahn .xbr ._eip712_certificate import EIP712Certificate # noqa
54
- from autobahn .xbr ._eip712_certificate_chain import parse_certificate_chain # noqa
55
- from autobahn .xbr ._eip712_authority_certificate import sign_eip712_authority_certificate , \
56
- recover_eip712_authority_certificate , create_eip712_authority_certificate , EIP712AuthorityCertificate # noqa
57
- from autobahn .xbr ._eip712_delegate_certificate import sign_eip712_delegate_certificate , \
58
- recover_eip712_delegate_certificate , create_eip712_delegate_certificate , EIP712DelegateCertificate # noqa
59
- from autobahn .xbr ._eip712_member_register import sign_eip712_member_register , recover_eip712_member_register # noqa
60
- from autobahn .xbr ._eip712_member_login import sign_eip712_member_login , recover_eip712_member_login # noqa
61
- from autobahn .xbr ._eip712_market_create import sign_eip712_market_create , recover_eip712_market_create # noqa
62
- from autobahn .xbr ._eip712_market_join import sign_eip712_market_join , recover_eip712_market_join # noqa
63
- from autobahn .xbr ._eip712_catalog_create import sign_eip712_catalog_create , recover_eip712_catalog_create # noqa
64
- from autobahn .xbr ._eip712_api_publish import sign_eip712_api_publish , recover_eip712_api_publish # noqa
65
- from autobahn .xbr ._eip712_consent import sign_eip712_consent , recover_eip712_consent # noqa
66
- from autobahn .xbr ._eip712_channel_open import sign_eip712_channel_open , recover_eip712_channel_open # noqa
67
- from autobahn .xbr ._eip712_channel_close import sign_eip712_channel_close , recover_eip712_channel_close # noqa
68
- from autobahn .xbr ._eip712_market_member_login import sign_eip712_market_member_login , \
69
- recover_eip712_market_member_login # noqa
70
- from autobahn .xbr ._eip712_base import is_address , is_chain_id , is_block_number , is_signature , \
71
- is_cs_pubkey , is_bytes16 , is_eth_privkey # noqa
72
- from autobahn .xbr ._blockchain import SimpleBlockchain # noqa
73
- from autobahn .xbr ._seller import SimpleSeller , KeySeries # noqa
74
- from autobahn .xbr ._buyer import SimpleBuyer # noqa
75
- from autobahn .xbr ._config import load_or_create_profile , UserConfig , Profile # noqa
76
- from autobahn .xbr ._schema import FbsSchema , FbsObject , FbsType , FbsRPCCall , FbsEnum , FbsService , FbsEnumValue , \
77
- FbsAttribute , FbsField , FbsRepository # noqa
78
- from autobahn .xbr ._wallet import stretch_argon2_secret , expand_argon2_secret , pkm_from_argon2_secret # noqa
79
- from autobahn .xbr ._frealm import FederatedRealm , Seeder # noqa
80
- from autobahn .xbr ._secmod import EthereumKey , SecurityModuleMemory # noqa
81
- from autobahn .xbr ._userkey import UserKey # noqa
82
-
83
- HAS_XBR = True
84
-
85
- if not hasattr (abi , 'collapse_type' ):
55
+ if not hasattr (eth_abi , 'collapse_type' ):
86
56
87
57
def collapse_type (base , sub , arrlist ):
88
58
return base + sub + '' .join (map (repr , arrlist ))
89
59
90
- abi .collapse_type = collapse_type
60
+ eth_abi .collapse_type = collapse_type
91
61
92
- if not hasattr (abi , 'process_type' ):
62
+ if not hasattr (eth_abi , 'process_type' ):
93
63
from eth_abi .grammar import (
94
64
TupleType ,
95
65
normalize ,
@@ -128,7 +98,62 @@ def process_type(type_str):
128
98
129
99
return abi_type .base , sub , arrlist
130
100
131
- abi .process_type = process_type
101
+ eth_abi .process_type = process_type
102
+
103
+ # monkey patch web3 for master branch / upcoming v6 (which we need for python 3.11)
104
+ # AttributeError: type object 'Web3' has no attribute 'toChecksumAddress'. Did you mean: 'to_checksum_address'?
105
+ import web3
106
+ if not hasattr (web3 .Web3 , 'toChecksumAddress' ) and hasattr (web3 .Web3 , 'to_checksum_address' ):
107
+ web3 .Web3 .toChecksumAddress = web3 .Web3 .to_checksum_address
108
+ if not hasattr (web3 .Web3 , 'isChecksumAddress' ) and hasattr (web3 .Web3 , 'is_checksum_address' ):
109
+ web3 .Web3 .isChecksumAddress = web3 .Web3 .is_checksum_address
110
+ if not hasattr (web3 .Web3 , 'isConnected' ) and hasattr (web3 .Web3 , 'is_connected' ):
111
+ web3 .Web3 .isConnected = web3 .Web3 .is_connected
112
+ if not hasattr (web3 .Web3 , 'privateKeyToAccount' ) and hasattr (web3 .middleware .signing , 'private_key_to_account' ):
113
+ web3 .Web3 .privateKeyToAccount = web3 .middleware .signing .private_key_to_account
114
+
115
+ import ens
116
+ if not hasattr (ens , 'main' ) and hasattr (ens , 'ens' ):
117
+ ens .main = ens .ens
118
+
119
+ import eth_account
120
+
121
+ from autobahn .xbr ._abi import XBR_TOKEN_ABI , XBR_NETWORK_ABI , XBR_MARKET_ABI , XBR_CATALOG_ABI , XBR_CHANNEL_ABI # noqa
122
+ from autobahn .xbr ._abi import XBR_DEBUG_TOKEN_ADDR , XBR_DEBUG_NETWORK_ADDR , XBR_DEBUG_MARKET_ADDR , XBR_DEBUG_CATALOG_ADDR , XBR_DEBUG_CHANNEL_ADDR # noqa
123
+ from autobahn .xbr ._abi import XBR_DEBUG_TOKEN_ADDR_SRC , XBR_DEBUG_NETWORK_ADDR_SRC , XBR_DEBUG_MARKET_ADDR_SRC , XBR_DEBUG_CATALOG_ADDR_SRC , XBR_DEBUG_CHANNEL_ADDR_SRC # noqa
124
+ from autobahn .xbr ._interfaces import IMarketMaker , IProvider , IConsumer , ISeller , IBuyer , IDelegate # noqa
125
+ from autobahn .xbr ._util import make_w3 , pack_uint256 , unpack_uint256 # noqa
126
+ from autobahn .xbr ._eip712_certificate import EIP712Certificate # noqa
127
+ from autobahn .xbr ._eip712_certificate_chain import parse_certificate_chain # noqa
128
+ from autobahn .xbr ._eip712_authority_certificate import sign_eip712_authority_certificate , \
129
+ recover_eip712_authority_certificate , create_eip712_authority_certificate , EIP712AuthorityCertificate # noqa
130
+ from autobahn .xbr ._eip712_delegate_certificate import sign_eip712_delegate_certificate , \
131
+ recover_eip712_delegate_certificate , create_eip712_delegate_certificate , EIP712DelegateCertificate # noqa
132
+ from autobahn .xbr ._eip712_member_register import sign_eip712_member_register , recover_eip712_member_register # noqa
133
+ from autobahn .xbr ._eip712_member_login import sign_eip712_member_login , recover_eip712_member_login # noqa
134
+ from autobahn .xbr ._eip712_market_create import sign_eip712_market_create , recover_eip712_market_create # noqa
135
+ from autobahn .xbr ._eip712_market_join import sign_eip712_market_join , recover_eip712_market_join # noqa
136
+ from autobahn .xbr ._eip712_catalog_create import sign_eip712_catalog_create , recover_eip712_catalog_create # noqa
137
+ from autobahn .xbr ._eip712_api_publish import sign_eip712_api_publish , recover_eip712_api_publish # noqa
138
+ from autobahn .xbr ._eip712_consent import sign_eip712_consent , recover_eip712_consent # noqa
139
+ from autobahn .xbr ._eip712_channel_open import sign_eip712_channel_open , recover_eip712_channel_open # noqa
140
+ from autobahn .xbr ._eip712_channel_close import sign_eip712_channel_close , recover_eip712_channel_close # noqa
141
+ from autobahn .xbr ._eip712_market_member_login import sign_eip712_market_member_login , \
142
+ recover_eip712_market_member_login # noqa
143
+ from autobahn .xbr ._eip712_base import is_address , is_chain_id , is_block_number , is_signature , \
144
+ is_cs_pubkey , is_bytes16 , is_eth_privkey # noqa
145
+ from autobahn .xbr ._blockchain import SimpleBlockchain # noqa
146
+ from autobahn .xbr ._seller import SimpleSeller , KeySeries # noqa
147
+ from autobahn .xbr ._buyer import SimpleBuyer # noqa
148
+ from autobahn .xbr ._config import load_or_create_profile , UserConfig , Profile # noqa
149
+ from autobahn .xbr ._schema import FbsSchema , FbsObject , FbsType , FbsRPCCall , FbsEnum , FbsService , FbsEnumValue , \
150
+ FbsAttribute , FbsField , FbsRepository # noqa
151
+ from autobahn .xbr ._wallet import stretch_argon2_secret , expand_argon2_secret , pkm_from_argon2_secret # noqa
152
+ from autobahn .xbr ._frealm import FederatedRealm , Seeder # noqa
153
+ from autobahn .xbr ._secmod import EthereumKey , SecurityModuleMemory # noqa
154
+ from autobahn .xbr ._userkey import UserKey # noqa
155
+
156
+ HAS_XBR = True
132
157
133
158
xbrtoken = None
134
159
"""
@@ -279,11 +304,11 @@ def account_from_seedphrase(seedphrase: str, index: int = 0) -> eth_account.acco
279
304
:param index: The account index in account hierarchy defined by the seedphrase.
280
305
:return: The new Eth account object
281
306
"""
282
- from web3 .auto import w3
307
+ from web3 .middleware . signing import private_key_to_account
283
308
284
309
derivation_path = "m/44'/60'/0'/0/{}" .format (index )
285
310
key = mnemonic_to_private_key (seedphrase , str_derivation_path = derivation_path )
286
- account = w3 . eth . account . privateKeyToAccount (key )
311
+ account = private_key_to_account (key )
287
312
return account
288
313
289
314
def account_from_ethkey (ethkey : bytes ) -> eth_account .account .Account :
@@ -293,10 +318,10 @@ def account_from_ethkey(ethkey: bytes) -> eth_account.account.Account:
293
318
:param ethkey: The Ethereum private key seed (32 octets).
294
319
:return: The new Eth account object
295
320
"""
296
- from web3 .auto import w3
321
+ from web3 .middleware . signing import private_key_to_account
297
322
298
323
assert len (ethkey ) == 32
299
- account = w3 . eth . account . privateKeyToAccount (ethkey )
324
+ account = private_key_to_account (ethkey )
300
325
return account
301
326
302
327
ASCII_BOMB = r"""
0 commit comments