web3 7.1.0__py3-none-any.whl → 7.3.0__py3-none-any.whl
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.
- web3/_utils/async_transactions.py +27 -16
- web3/_utils/caching/__init__.py +12 -0
- web3/_utils/{caching.py → caching/caching_utils.py} +121 -36
- web3/_utils/caching/request_caching_validation.py +129 -0
- web3/_utils/contract_sources/contract_data/arrays_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/bytes_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/constructor_contracts.py +7 -7
- web3/_utils/contract_sources/contract_data/contract_caller_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/emitter_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/event_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/extended_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/fallback_function_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/function_name_tester_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/math_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_lookup.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/panic_errors_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/payable_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/receive_function_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/reflector_contracts.py +3 -3
- web3/_utils/contract_sources/contract_data/revert_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/simple_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/storage_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/string_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/tuple_contracts.py +5 -5
- web3/_utils/http.py +5 -2
- web3/_utils/module_testing/eth_module.py +40 -0
- web3/_utils/transactions.py +14 -13
- web3/exceptions.py +14 -1
- web3/main.py +23 -0
- web3/middleware/signing.py +2 -2
- web3/providers/async_base.py +12 -0
- web3/providers/base.py +11 -0
- web3/providers/persistent/async_ipc.py +26 -26
- web3/providers/rpc/async_rpc.py +10 -2
- web3/providers/rpc/rpc.py +11 -2
- web3/utils/__init__.py +2 -0
- web3/utils/caching.py +8 -0
- {web3-7.1.0.dist-info → web3-7.3.0.dist-info}/METADATA +19 -12
- {web3-7.1.0.dist-info → web3-7.3.0.dist-info}/RECORD +43 -46
- {web3-7.1.0.dist-info → web3-7.3.0.dist-info}/WHEEL +1 -1
- web3/tools/benchmark/__init__.py +0 -0
- web3/tools/benchmark/main.py +0 -190
- web3/tools/benchmark/node.py +0 -120
- web3/tools/benchmark/reporting.py +0 -39
- web3/tools/benchmark/utils.py +0 -69
- {web3-7.1.0.dist-info → web3-7.3.0.dist-info}/LICENSE +0 -0
- {web3-7.1.0.dist-info → web3-7.3.0.dist-info}/top_level.txt +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Generated by `compile_contracts.py` script.
|
|
3
|
-
Compiled with Solidity v0.8.
|
|
3
|
+
Compiled with Solidity v0.8.27.
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
# source: web3/_utils/contract_sources/TupleContracts.sol:TupleContract
|
|
7
|
-
TUPLE_CONTRACT_BYTECODE = "
|
|
8
|
-
TUPLE_CONTRACT_RUNTIME = "
|
|
7
|
+
TUPLE_CONTRACT_BYTECODE = "0x6080604052348015600e575f5ffd5b50610a688061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c80638e1ae3c71461002d575b5f5ffd5b6100476004803603810190610042919061064d565b61005d565b6040516100549190610a12565b60405180910390f35b61006561006d565b819050919050565b60405180606001604052805f815260200160608152602001606081525090565b5f604051905090565b5f5ffd5b5f5ffd5b5f5ffd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6100e8826100a2565b810181811067ffffffffffffffff82111715610107576101066100b2565b5b80604052505050565b5f61011961008d565b905061012582826100df565b919050565b5f5ffd5b5f819050919050565b6101408161012e565b811461014a575f5ffd5b50565b5f8135905061015b81610137565b92915050565b5f5ffd5b5f67ffffffffffffffff82111561017f5761017e6100b2565b5b602082029050602081019050919050565b5f5ffd5b5f6101a66101a184610165565b610110565b905080838252602082019050602084028301858111156101c9576101c8610190565b5b835b818110156101f257806101de888261014d565b8452602084019350506020810190506101cb565b5050509392505050565b5f82601f8301126102105761020f610161565b5b8135610220848260208601610194565b91505092915050565b5f67ffffffffffffffff821115610243576102426100b2565b5b602082029050602081019050919050565b5f819050919050565b61026681610254565b8114610270575f5ffd5b50565b5f813590506102818161025d565b92915050565b5f67ffffffffffffffff8211156102a1576102a06100b2565b5b602082029050919050565b5f8115159050919050565b6102c0816102ac565b81146102ca575f5ffd5b50565b5f813590506102db816102b7565b92915050565b5f6102f36102ee84610287565b610110565b9050806020840283018581111561030d5761030c610190565b5b835b81811015610336578061032288826102cd565b84526020840193505060208101905061030f565b5050509392505050565b5f82601f83011261035457610353610161565b5b60026103618482856102e1565b91505092915050565b5f67ffffffffffffffff821115610384576103836100b2565b5b602082029050602081019050919050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6103be82610395565b9050919050565b6103ce816103b4565b81146103d8575f5ffd5b50565b5f813590506103e9816103c5565b92915050565b5f6104016103fc8461036a565b610110565b9050808382526020820190506020840283018581111561042457610423610190565b5b835b8181101561044d578061043988826103db565b845260208401935050602081019050610426565b5050509392505050565b5f82601f83011261046b5761046a610161565b5b813561047b8482602086016103ef565b91505092915050565b5f608082840312156104995761049861009e565b5b6104a36060610110565b90505f6104b284828501610273565b5f8301525060206104c584828501610340565b602083015250606082013567ffffffffffffffff8111156104e9576104e861012a565b5b6104f584828501610457565b60408301525092915050565b5f61051361050e84610229565b610110565b9050808382526020820190506020840283018581111561053657610535610190565b5b835b8181101561057d57803567ffffffffffffffff81111561055b5761055a610161565b5b8086016105688982610484565b85526020850194505050602081019050610538565b5050509392505050565b5f82601f83011261059b5761059a610161565b5b81356105ab848260208601610501565b91505092915050565b5f606082840312156105c9576105c861009e565b5b6105d36060610110565b90505f6105e28482850161014d565b5f83015250602082013567ffffffffffffffff8111156106055761060461012a565b5b610611848285016101fc565b602083015250604082013567ffffffffffffffff8111156106355761063461012a565b5b61064184828501610587565b60408301525092915050565b5f6020828403121561066257610661610096565b5b5f82013567ffffffffffffffff81111561067f5761067e61009a565b5b61068b848285016105b4565b91505092915050565b61069d8161012e565b82525050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f6106d78383610694565b60208301905092915050565b5f602082019050919050565b5f6106f9826106a3565b61070381856106ad565b935061070e836106bd565b805f5b8381101561073e57815161072588826106cc565b9750610730836106e3565b925050600181019050610711565b5085935050505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b61077d81610254565b82525050565b5f60029050919050565b5f81905092915050565b5f819050919050565b6107a9816102ac565b82525050565b5f6107ba83836107a0565b60208301905092915050565b5f602082019050919050565b6107db81610783565b6107e5818461078d565b92506107f082610797565b805f5b8381101561082057815161080787826107af565b9650610812836107c6565b9250506001810190506107f3565b505050505050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b61085a816103b4565b82525050565b5f61086b8383610851565b60208301905092915050565b5f602082019050919050565b5f61088d82610828565b6108978185610832565b93506108a283610842565b805f5b838110156108d25781516108b98882610860565b97506108c483610877565b9250506001810190506108a5565b5085935050505092915050565b5f608083015f8301516108f45f860182610774565b50602083015161090760208601826107d2565b506040830151848203606086015261091f8282610883565b9150508091505092915050565b5f61093783836108df565b905092915050565b5f602082019050919050565b5f6109558261074b565b61095f8185610755565b93508360208202850161097185610765565b805f5b858110156109ac578484038952815161098d858261092c565b94506109988361093f565b925060208a01995050600181019050610974565b50829750879550505050505092915050565b5f606083015f8301516109d35f860182610694565b50602083015184820360208601526109eb82826106ef565b91505060408301518482036040860152610a05828261094b565b9150508091505092915050565b5f6020820190508181035f830152610a2a81846109be565b90509291505056fea26469706673582212207adaf59879d665fddbe536da6fd004def309fc6d78a3a894ecf546ec9fea5e1564736f6c634300081b0033" # noqa: E501
|
|
8
|
+
TUPLE_CONTRACT_RUNTIME = "0x608060405234801561000f575f5ffd5b5060043610610029575f3560e01c80638e1ae3c71461002d575b5f5ffd5b6100476004803603810190610042919061064d565b61005d565b6040516100549190610a12565b60405180910390f35b61006561006d565b819050919050565b60405180606001604052805f815260200160608152602001606081525090565b5f604051905090565b5f5ffd5b5f5ffd5b5f5ffd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6100e8826100a2565b810181811067ffffffffffffffff82111715610107576101066100b2565b5b80604052505050565b5f61011961008d565b905061012582826100df565b919050565b5f5ffd5b5f819050919050565b6101408161012e565b811461014a575f5ffd5b50565b5f8135905061015b81610137565b92915050565b5f5ffd5b5f67ffffffffffffffff82111561017f5761017e6100b2565b5b602082029050602081019050919050565b5f5ffd5b5f6101a66101a184610165565b610110565b905080838252602082019050602084028301858111156101c9576101c8610190565b5b835b818110156101f257806101de888261014d565b8452602084019350506020810190506101cb565b5050509392505050565b5f82601f8301126102105761020f610161565b5b8135610220848260208601610194565b91505092915050565b5f67ffffffffffffffff821115610243576102426100b2565b5b602082029050602081019050919050565b5f819050919050565b61026681610254565b8114610270575f5ffd5b50565b5f813590506102818161025d565b92915050565b5f67ffffffffffffffff8211156102a1576102a06100b2565b5b602082029050919050565b5f8115159050919050565b6102c0816102ac565b81146102ca575f5ffd5b50565b5f813590506102db816102b7565b92915050565b5f6102f36102ee84610287565b610110565b9050806020840283018581111561030d5761030c610190565b5b835b81811015610336578061032288826102cd565b84526020840193505060208101905061030f565b5050509392505050565b5f82601f83011261035457610353610161565b5b60026103618482856102e1565b91505092915050565b5f67ffffffffffffffff821115610384576103836100b2565b5b602082029050602081019050919050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6103be82610395565b9050919050565b6103ce816103b4565b81146103d8575f5ffd5b50565b5f813590506103e9816103c5565b92915050565b5f6104016103fc8461036a565b610110565b9050808382526020820190506020840283018581111561042457610423610190565b5b835b8181101561044d578061043988826103db565b845260208401935050602081019050610426565b5050509392505050565b5f82601f83011261046b5761046a610161565b5b813561047b8482602086016103ef565b91505092915050565b5f608082840312156104995761049861009e565b5b6104a36060610110565b90505f6104b284828501610273565b5f8301525060206104c584828501610340565b602083015250606082013567ffffffffffffffff8111156104e9576104e861012a565b5b6104f584828501610457565b60408301525092915050565b5f61051361050e84610229565b610110565b9050808382526020820190506020840283018581111561053657610535610190565b5b835b8181101561057d57803567ffffffffffffffff81111561055b5761055a610161565b5b8086016105688982610484565b85526020850194505050602081019050610538565b5050509392505050565b5f82601f83011261059b5761059a610161565b5b81356105ab848260208601610501565b91505092915050565b5f606082840312156105c9576105c861009e565b5b6105d36060610110565b90505f6105e28482850161014d565b5f83015250602082013567ffffffffffffffff8111156106055761060461012a565b5b610611848285016101fc565b602083015250604082013567ffffffffffffffff8111156106355761063461012a565b5b61064184828501610587565b60408301525092915050565b5f6020828403121561066257610661610096565b5b5f82013567ffffffffffffffff81111561067f5761067e61009a565b5b61068b848285016105b4565b91505092915050565b61069d8161012e565b82525050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f6106d78383610694565b60208301905092915050565b5f602082019050919050565b5f6106f9826106a3565b61070381856106ad565b935061070e836106bd565b805f5b8381101561073e57815161072588826106cc565b9750610730836106e3565b925050600181019050610711565b5085935050505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b61077d81610254565b82525050565b5f60029050919050565b5f81905092915050565b5f819050919050565b6107a9816102ac565b82525050565b5f6107ba83836107a0565b60208301905092915050565b5f602082019050919050565b6107db81610783565b6107e5818461078d565b92506107f082610797565b805f5b8381101561082057815161080787826107af565b9650610812836107c6565b9250506001810190506107f3565b505050505050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b61085a816103b4565b82525050565b5f61086b8383610851565b60208301905092915050565b5f602082019050919050565b5f61088d82610828565b6108978185610832565b93506108a283610842565b805f5b838110156108d25781516108b98882610860565b97506108c483610877565b9250506001810190506108a5565b5085935050505092915050565b5f608083015f8301516108f45f860182610774565b50602083015161090760208601826107d2565b506040830151848203606086015261091f8282610883565b9150508091505092915050565b5f61093783836108df565b905092915050565b5f602082019050919050565b5f6109558261074b565b61095f8185610755565b93508360208202850161097185610765565b805f5b858110156109ac578484038952815161098d858261092c565b94506109988361093f565b925060208a01995050600181019050610974565b50829750879550505050505092915050565b5f606083015f8301516109d35f860182610694565b50602083015184820360208601526109eb82826106ef565b91505060408301518482036040860152610a05828261094b565b9150508091505092915050565b5f6020820190508181035f830152610a2a81846109be565b90509291505056fea26469706673582212207adaf59879d665fddbe536da6fd004def309fc6d78a3a894ecf546ec9fea5e1564736f6c634300081b0033" # noqa: E501
|
|
9
9
|
TUPLE_CONTRACT_ABI = [
|
|
10
10
|
{
|
|
11
11
|
"inputs": [
|
|
@@ -71,8 +71,8 @@ TUPLE_CONTRACT_DATA = {
|
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
# source: web3/_utils/contract_sources/TupleContracts.sol:NestedTupleContract
|
|
74
|
-
NESTED_TUPLE_CONTRACT_BYTECODE = "
|
|
75
|
-
NESTED_TUPLE_CONTRACT_RUNTIME = "
|
|
74
|
+
NESTED_TUPLE_CONTRACT_BYTECODE = "0x6080604052348015600e575f5ffd5b5061067b8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c80632655aef11461002d575b5f5ffd5b610047600480360381019061004291906103f1565b61005d565b6040516100549190610625565b60405180910390f35b61006561006d565b819050919050565b6040518060200160405280606081525090565b5f604051905090565b5f5ffd5b5f5ffd5b5f5ffd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6100db82610095565b810181811067ffffffffffffffff821117156100fa576100f96100a5565b5b80604052505050565b5f61010c610080565b905061011882826100d2565b919050565b5f5ffd5b5f5ffd5b5f67ffffffffffffffff82111561013f5761013e6100a5565b5b602082029050602081019050919050565b5f5ffd5b5f67ffffffffffffffff82111561016e5761016d6100a5565b5b602082029050602081019050919050565b5f819050919050565b6101918161017f565b811461019b575f5ffd5b50565b5f813590506101ac81610188565b92915050565b5f604082840312156101c7576101c6610091565b5b6101d16040610103565b90505f6101e08482850161019e565b5f8301525060206101f38482850161019e565b60208301525092915050565b5f61021161020c84610154565b610103565b9050808382526020820190506040840283018581111561023457610233610150565b5b835b8181101561025d578061024988826101b2565b845260208401935050604081019050610236565b5050509392505050565b5f82601f83011261027b5761027a610121565b5b813561028b8482602086016101ff565b91505092915050565b5f602082840312156102a9576102a8610091565b5b6102b36020610103565b90505f82013567ffffffffffffffff8111156102d2576102d161011d565b5b6102de84828501610267565b5f8301525092915050565b5f6102fb6102f684610125565b610103565b9050808382526020820190506020840283018581111561031e5761031d610150565b5b835b8181101561036557803567ffffffffffffffff81111561034357610342610121565b5b8086016103508982610294565b85526020850194505050602081019050610320565b5050509392505050565b5f82601f83011261038357610382610121565b5b81356103938482602086016102e9565b91505092915050565b5f602082840312156103b1576103b0610091565b5b6103bb6020610103565b90505f82013567ffffffffffffffff8111156103da576103d961011d565b5b6103e68482850161036f565b5f8301525092915050565b5f6020828403121561040657610405610089565b5b5f82013567ffffffffffffffff8111156104235761042261008d565b5b61042f8482850161039c565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b6104938161017f565b82525050565b604082015f8201516104ad5f85018261048a565b5060208201516104c0602085018261048a565b50505050565b5f6104d18383610499565b60408301905092915050565b5f602082019050919050565b5f6104f382610461565b6104fd818561046b565b93506105088361047b565b805f5b8381101561053857815161051f88826104c6565b975061052a836104dd565b92505060018101905061050b565b5085935050505092915050565b5f602083015f8301518482035f86015261055f82826104e9565b9150508091505092915050565b5f6105778383610545565b905092915050565b5f602082019050919050565b5f61059582610438565b61059f8185610442565b9350836020820285016105b185610452565b805f5b858110156105ec57848403895281516105cd858261056c565b94506105d88361057f565b925060208a019950506001810190506105b4565b50829750879550505050505092915050565b5f602083015f8301518482035f860152610618828261058b565b9150508091505092915050565b5f6020820190508181035f83015261063d81846105fe565b90509291505056fea2646970667358221220b10a40d79c5187ac06501cc4ac82657a3a637162a094a455f80d765c59f270a964736f6c634300081b0033" # noqa: E501
|
|
75
|
+
NESTED_TUPLE_CONTRACT_RUNTIME = "0x608060405234801561000f575f5ffd5b5060043610610029575f3560e01c80632655aef11461002d575b5f5ffd5b610047600480360381019061004291906103f1565b61005d565b6040516100549190610625565b60405180910390f35b61006561006d565b819050919050565b6040518060200160405280606081525090565b5f604051905090565b5f5ffd5b5f5ffd5b5f5ffd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6100db82610095565b810181811067ffffffffffffffff821117156100fa576100f96100a5565b5b80604052505050565b5f61010c610080565b905061011882826100d2565b919050565b5f5ffd5b5f5ffd5b5f67ffffffffffffffff82111561013f5761013e6100a5565b5b602082029050602081019050919050565b5f5ffd5b5f67ffffffffffffffff82111561016e5761016d6100a5565b5b602082029050602081019050919050565b5f819050919050565b6101918161017f565b811461019b575f5ffd5b50565b5f813590506101ac81610188565b92915050565b5f604082840312156101c7576101c6610091565b5b6101d16040610103565b90505f6101e08482850161019e565b5f8301525060206101f38482850161019e565b60208301525092915050565b5f61021161020c84610154565b610103565b9050808382526020820190506040840283018581111561023457610233610150565b5b835b8181101561025d578061024988826101b2565b845260208401935050604081019050610236565b5050509392505050565b5f82601f83011261027b5761027a610121565b5b813561028b8482602086016101ff565b91505092915050565b5f602082840312156102a9576102a8610091565b5b6102b36020610103565b90505f82013567ffffffffffffffff8111156102d2576102d161011d565b5b6102de84828501610267565b5f8301525092915050565b5f6102fb6102f684610125565b610103565b9050808382526020820190506020840283018581111561031e5761031d610150565b5b835b8181101561036557803567ffffffffffffffff81111561034357610342610121565b5b8086016103508982610294565b85526020850194505050602081019050610320565b5050509392505050565b5f82601f83011261038357610382610121565b5b81356103938482602086016102e9565b91505092915050565b5f602082840312156103b1576103b0610091565b5b6103bb6020610103565b90505f82013567ffffffffffffffff8111156103da576103d961011d565b5b6103e68482850161036f565b5f8301525092915050565b5f6020828403121561040657610405610089565b5b5f82013567ffffffffffffffff8111156104235761042261008d565b5b61042f8482850161039c565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b6104938161017f565b82525050565b604082015f8201516104ad5f85018261048a565b5060208201516104c0602085018261048a565b50505050565b5f6104d18383610499565b60408301905092915050565b5f602082019050919050565b5f6104f382610461565b6104fd818561046b565b93506105088361047b565b805f5b8381101561053857815161051f88826104c6565b975061052a836104dd565b92505060018101905061050b565b5085935050505092915050565b5f602083015f8301518482035f86015261055f82826104e9565b9150508091505092915050565b5f6105778383610545565b905092915050565b5f602082019050919050565b5f61059582610438565b61059f8185610442565b9350836020820285016105b185610452565b805f5b858110156105ec57848403895281516105cd858261056c565b94506105d88361057f565b925060208a019950506001810190506105b4565b50829750879550505050505092915050565b5f602083015f8301518482035f860152610618828261058b565b9150508091505092915050565b5f6020820190508181035f83015261063d81846105fe565b90509291505056fea2646970667358221220b10a40d79c5187ac06501cc4ac82657a3a637162a094a455f80d765c59f270a964736f6c634300081b0033" # noqa: E501
|
|
76
76
|
NESTED_TUPLE_CONTRACT_ABI = [
|
|
77
77
|
{
|
|
78
78
|
"inputs": [
|
web3/_utils/http.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
DEFAULT_HTTP_TIMEOUT = 30.0
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
def construct_user_agent(
|
|
4
|
+
def construct_user_agent(
|
|
5
|
+
module: str,
|
|
6
|
+
class_name: str,
|
|
7
|
+
) -> str:
|
|
5
8
|
from web3 import (
|
|
6
9
|
__version__ as web3_version,
|
|
7
10
|
)
|
|
8
11
|
|
|
9
|
-
return f"web3.py/{web3_version}/{
|
|
12
|
+
return f"web3.py/{web3_version}/{module}.{class_name}"
|
|
@@ -88,6 +88,7 @@ from web3.exceptions import (
|
|
|
88
88
|
)
|
|
89
89
|
from web3.middleware import (
|
|
90
90
|
ExtraDataToPOAMiddleware,
|
|
91
|
+
SignAndSendRawMiddlewareBuilder,
|
|
91
92
|
)
|
|
92
93
|
from web3.types import (
|
|
93
94
|
ENS,
|
|
@@ -725,6 +726,26 @@ class AsyncEthModuleTest:
|
|
|
725
726
|
txn_hash = await async_w3.eth.send_raw_transaction(signed.raw_transaction)
|
|
726
727
|
assert txn_hash == HexBytes(signed.hash)
|
|
727
728
|
|
|
729
|
+
@pytest.mark.asyncio
|
|
730
|
+
async def test_async_sign_and_send_raw_middleware(
|
|
731
|
+
self, async_w3: "AsyncWeb3", keyfile_account_pkey: HexStr
|
|
732
|
+
) -> None:
|
|
733
|
+
keyfile_account = async_w3.eth.account.from_key(keyfile_account_pkey)
|
|
734
|
+
txn: TxParams = {
|
|
735
|
+
"from": keyfile_account.address,
|
|
736
|
+
"to": keyfile_account.address,
|
|
737
|
+
"value": Wei(0),
|
|
738
|
+
"gas": 21000,
|
|
739
|
+
}
|
|
740
|
+
async_w3.middleware_onion.inject(
|
|
741
|
+
SignAndSendRawMiddlewareBuilder.build(keyfile_account), "signing", layer=0
|
|
742
|
+
)
|
|
743
|
+
txn_hash = await async_w3.eth.send_transaction(txn)
|
|
744
|
+
assert isinstance(txn_hash, HexBytes)
|
|
745
|
+
|
|
746
|
+
# clean up
|
|
747
|
+
async_w3.middleware_onion.remove("signing")
|
|
748
|
+
|
|
728
749
|
@pytest.mark.asyncio
|
|
729
750
|
async def test_GasPriceStrategyMiddleware(
|
|
730
751
|
self,
|
|
@@ -3716,6 +3737,25 @@ class EthModuleTest:
|
|
|
3716
3737
|
txn_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
|
|
3717
3738
|
assert txn_hash == HexBytes(signed.hash)
|
|
3718
3739
|
|
|
3740
|
+
def test_sign_and_send_raw_middleware(
|
|
3741
|
+
self, w3: "Web3", keyfile_account_pkey: HexStr
|
|
3742
|
+
) -> None:
|
|
3743
|
+
keyfile_account = w3.eth.account.from_key(keyfile_account_pkey)
|
|
3744
|
+
txn: TxParams = {
|
|
3745
|
+
"from": keyfile_account.address,
|
|
3746
|
+
"to": keyfile_account.address,
|
|
3747
|
+
"value": Wei(0),
|
|
3748
|
+
"gas": 21000,
|
|
3749
|
+
}
|
|
3750
|
+
w3.middleware_onion.inject(
|
|
3751
|
+
SignAndSendRawMiddlewareBuilder.build(keyfile_account), "signing", layer=0
|
|
3752
|
+
)
|
|
3753
|
+
txn_hash = w3.eth.send_transaction(txn)
|
|
3754
|
+
assert isinstance(txn_hash, HexBytes)
|
|
3755
|
+
|
|
3756
|
+
# cleanup
|
|
3757
|
+
w3.middleware_onion.remove("signing")
|
|
3758
|
+
|
|
3719
3759
|
def test_eth_call(self, w3: "Web3", math_contract: "Contract") -> None:
|
|
3720
3760
|
txn_params = math_contract._prepare_transaction(
|
|
3721
3761
|
abi_element_identifier="add",
|
web3/_utils/transactions.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import math
|
|
2
2
|
from typing import (
|
|
3
3
|
TYPE_CHECKING,
|
|
4
|
+
Dict,
|
|
4
5
|
List,
|
|
5
6
|
Literal,
|
|
6
7
|
Optional,
|
|
@@ -75,14 +76,16 @@ VALID_TRANSACTION_PARAMS: List[TX_PARAM_LITERALS] = [
|
|
|
75
76
|
TRANSACTION_DEFAULTS = {
|
|
76
77
|
"value": 0,
|
|
77
78
|
"data": b"",
|
|
78
|
-
"gas": lambda w3, tx: w3.eth.estimate_gas(tx),
|
|
79
|
-
"gasPrice": lambda w3, tx: w3.eth.generate_gas_price(tx),
|
|
79
|
+
"gas": lambda w3, tx, _defaults: w3.eth.estimate_gas(tx),
|
|
80
|
+
"gasPrice": lambda w3, tx, _defaults: w3.eth.generate_gas_price(tx),
|
|
81
|
+
"maxPriorityFeePerGas": lambda w3, _tx, _defaults: w3.eth.max_priority_fee,
|
|
80
82
|
"maxFeePerGas": (
|
|
81
|
-
lambda w3, tx:
|
|
82
|
-
|
|
83
|
+
lambda w3, tx, defaults: (
|
|
84
|
+
tx.get("maxPriorityFeePerGas", defaults.get("maxPriorityFeePerGas"))
|
|
85
|
+
+ (2 * w3.eth.get_block("latest")["baseFeePerGas"])
|
|
86
|
+
)
|
|
83
87
|
),
|
|
84
|
-
"
|
|
85
|
-
"chainId": lambda w3, tx: w3.eth.chain_id,
|
|
88
|
+
"chainId": lambda w3, _tx, _defaults: w3.eth.chain_id,
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
if TYPE_CHECKING:
|
|
@@ -117,7 +120,7 @@ def fill_transaction_defaults(w3: "Web3", transaction: TxParams) -> TxParams:
|
|
|
117
120
|
or any_in_dict(DYNAMIC_FEE_TXN_PARAMS, transaction)
|
|
118
121
|
)
|
|
119
122
|
|
|
120
|
-
defaults = {}
|
|
123
|
+
defaults: Dict[str, Union[bytes, int]] = {}
|
|
121
124
|
for key, default_getter in TRANSACTION_DEFAULTS.items():
|
|
122
125
|
if key not in transaction:
|
|
123
126
|
if (
|
|
@@ -135,7 +138,7 @@ def fill_transaction_defaults(w3: "Web3", transaction: TxParams) -> TxParams:
|
|
|
135
138
|
raise Web3ValueError(
|
|
136
139
|
f"You must specify a '{key}' value in the transaction"
|
|
137
140
|
)
|
|
138
|
-
default_val = default_getter(w3, transaction)
|
|
141
|
+
default_val = default_getter(w3, transaction, defaults)
|
|
139
142
|
else:
|
|
140
143
|
default_val = default_getter
|
|
141
144
|
|
|
@@ -146,9 +149,7 @@ def fill_transaction_defaults(w3: "Web3", transaction: TxParams) -> TxParams:
|
|
|
146
149
|
def get_block_gas_limit(
|
|
147
150
|
w3: "Web3", block_identifier: Optional[BlockIdentifier] = None
|
|
148
151
|
) -> int:
|
|
149
|
-
|
|
150
|
-
block_identifier = w3.eth.block_number
|
|
151
|
-
block = w3.eth.get_block(block_identifier)
|
|
152
|
+
block = w3.eth.get_block(block_identifier or "latest")
|
|
152
153
|
return block["gasLimit"]
|
|
153
154
|
|
|
154
155
|
|
|
@@ -163,8 +164,8 @@ def get_buffered_gas_estimate(
|
|
|
163
164
|
|
|
164
165
|
if gas_estimate > gas_limit:
|
|
165
166
|
raise Web3ValueError(
|
|
166
|
-
"
|
|
167
|
-
f"
|
|
167
|
+
"Gas estimate for transaction is higher than current network gas limits. "
|
|
168
|
+
f"Transaction could not be sent. Estimated: {gas_estimate}. "
|
|
168
169
|
f"Current gas limit: {gas_limit}"
|
|
169
170
|
)
|
|
170
171
|
|
web3/exceptions.py
CHANGED
|
@@ -334,7 +334,20 @@ class TaskNotRunning(Web3Exception):
|
|
|
334
334
|
super().__init__(message)
|
|
335
335
|
|
|
336
336
|
|
|
337
|
-
class
|
|
337
|
+
class PersistentConnectionError(Web3Exception):
|
|
338
|
+
"""
|
|
339
|
+
Raised when a persistent connection encounters an error.
|
|
340
|
+
"""
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
class ReadBufferLimitReached(PersistentConnectionError, Web3ValueError):
|
|
344
|
+
"""
|
|
345
|
+
Raised when the read buffer limit is reached while reading data from a persistent
|
|
346
|
+
connection.
|
|
347
|
+
"""
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
class PersistentConnectionClosedOK(PersistentConnectionError):
|
|
338
351
|
"""
|
|
339
352
|
Raised when a persistent connection is closed gracefully by the server.
|
|
340
353
|
"""
|
web3/main.py
CHANGED
|
@@ -87,6 +87,7 @@ from web3.eth import (
|
|
|
87
87
|
)
|
|
88
88
|
from web3.exceptions import (
|
|
89
89
|
Web3TypeError,
|
|
90
|
+
Web3ValidationError,
|
|
90
91
|
Web3ValueError,
|
|
91
92
|
)
|
|
92
93
|
from web3.geth import (
|
|
@@ -350,6 +351,24 @@ class BaseWeb3:
|
|
|
350
351
|
return self.manager._batch_requests()
|
|
351
352
|
|
|
352
353
|
|
|
354
|
+
def _validate_provider(
|
|
355
|
+
w3: Union["Web3", "AsyncWeb3"],
|
|
356
|
+
provider: Optional[Union[BaseProvider, AsyncBaseProvider]],
|
|
357
|
+
) -> None:
|
|
358
|
+
if provider is not None:
|
|
359
|
+
if isinstance(w3, AsyncWeb3) and not isinstance(provider, AsyncBaseProvider):
|
|
360
|
+
raise Web3ValidationError(
|
|
361
|
+
"Provider must be an instance of `AsyncBaseProvider` for "
|
|
362
|
+
f"`AsyncWeb3`, got {type(provider)}."
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
if isinstance(w3, Web3) and not isinstance(provider, BaseProvider):
|
|
366
|
+
raise Web3ValidationError(
|
|
367
|
+
"Provider must be an instance of `BaseProvider` for `Web3`, "
|
|
368
|
+
f"got {type(provider)}."
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
|
|
353
372
|
class Web3(BaseWeb3):
|
|
354
373
|
# mypy types
|
|
355
374
|
eth: Eth
|
|
@@ -372,6 +391,8 @@ class Web3(BaseWeb3):
|
|
|
372
391
|
] = None,
|
|
373
392
|
ens: Union[ENS, "Empty"] = empty,
|
|
374
393
|
) -> None:
|
|
394
|
+
_validate_provider(self, provider)
|
|
395
|
+
|
|
375
396
|
self.manager = self.RequestManager(self, provider, middleware)
|
|
376
397
|
self.codec = ABICodec(build_strict_registry())
|
|
377
398
|
|
|
@@ -440,6 +461,8 @@ class AsyncWeb3(BaseWeb3):
|
|
|
440
461
|
] = None,
|
|
441
462
|
ens: Union[AsyncENS, "Empty"] = empty,
|
|
442
463
|
) -> None:
|
|
464
|
+
_validate_provider(self, provider)
|
|
465
|
+
|
|
443
466
|
self.manager = self.RequestManager(self, provider, middleware)
|
|
444
467
|
self.codec = ABICodec(build_strict_registry())
|
|
445
468
|
|
web3/middleware/signing.py
CHANGED
|
@@ -189,7 +189,7 @@ class SignAndSendRawMiddlewareBuilder(Web3MiddlewareBuilder):
|
|
|
189
189
|
|
|
190
190
|
return (
|
|
191
191
|
RPCEndpoint("eth_sendRawTransaction"),
|
|
192
|
-
[raw_tx.
|
|
192
|
+
[raw_tx.to_0x_hex()],
|
|
193
193
|
)
|
|
194
194
|
|
|
195
195
|
# -- async -- #
|
|
@@ -220,5 +220,5 @@ class SignAndSendRawMiddlewareBuilder(Web3MiddlewareBuilder):
|
|
|
220
220
|
|
|
221
221
|
return (
|
|
222
222
|
RPCEndpoint("eth_sendRawTransaction"),
|
|
223
|
-
[raw_tx.
|
|
223
|
+
[raw_tx.to_0x_hex()],
|
|
224
224
|
)
|
web3/providers/async_base.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import itertools
|
|
3
|
+
import logging
|
|
3
4
|
from typing import (
|
|
4
5
|
TYPE_CHECKING,
|
|
5
6
|
Any,
|
|
@@ -41,6 +42,7 @@ from web3.types import (
|
|
|
41
42
|
RPCResponse,
|
|
42
43
|
)
|
|
43
44
|
from web3.utils import (
|
|
45
|
+
RequestCacheValidationThreshold,
|
|
44
46
|
SimpleCache,
|
|
45
47
|
)
|
|
46
48
|
|
|
@@ -59,6 +61,10 @@ if TYPE_CHECKING:
|
|
|
59
61
|
|
|
60
62
|
|
|
61
63
|
class AsyncBaseProvider:
|
|
64
|
+
# Set generic logger for the provider. Override in subclasses for more specificity.
|
|
65
|
+
logger: logging.Logger = logging.getLogger(
|
|
66
|
+
"web3.providers.async_base.AsyncBaseProvider"
|
|
67
|
+
)
|
|
62
68
|
_request_func_cache: Tuple[
|
|
63
69
|
Tuple[Middleware, ...], Callable[..., Coroutine[Any, Any, RPCResponse]]
|
|
64
70
|
] = (None, None)
|
|
@@ -81,10 +87,14 @@ class AsyncBaseProvider:
|
|
|
81
87
|
self,
|
|
82
88
|
cache_allowed_requests: bool = False,
|
|
83
89
|
cacheable_requests: Set[RPCEndpoint] = None,
|
|
90
|
+
request_cache_validation_threshold: Optional[
|
|
91
|
+
RequestCacheValidationThreshold
|
|
92
|
+
] = RequestCacheValidationThreshold.FINALIZED,
|
|
84
93
|
) -> None:
|
|
85
94
|
self._request_cache = SimpleCache(1000)
|
|
86
95
|
self.cache_allowed_requests = cache_allowed_requests
|
|
87
96
|
self.cacheable_requests = cacheable_requests or CACHEABLE_REQUESTS
|
|
97
|
+
self.request_cache_validation_threshold = request_cache_validation_threshold
|
|
88
98
|
|
|
89
99
|
async def request_func(
|
|
90
100
|
self, async_w3: "AsyncWeb3", middleware_onion: MiddlewareOnion
|
|
@@ -159,6 +169,8 @@ class AsyncBaseProvider:
|
|
|
159
169
|
|
|
160
170
|
|
|
161
171
|
class AsyncJSONBaseProvider(AsyncBaseProvider):
|
|
172
|
+
logger = logging.getLogger("web3.providers.async_base.AsyncJSONBaseProvider")
|
|
173
|
+
|
|
162
174
|
def __init__(self, **kwargs: Any) -> None:
|
|
163
175
|
self.request_counter = itertools.count()
|
|
164
176
|
super().__init__(**kwargs)
|
web3/providers/base.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import itertools
|
|
2
|
+
import logging
|
|
2
3
|
import threading
|
|
3
4
|
from typing import (
|
|
4
5
|
TYPE_CHECKING,
|
|
5
6
|
Any,
|
|
6
7
|
Callable,
|
|
7
8
|
List,
|
|
9
|
+
Optional,
|
|
8
10
|
Set,
|
|
9
11
|
Tuple,
|
|
10
12
|
cast,
|
|
@@ -38,6 +40,7 @@ from web3.types import (
|
|
|
38
40
|
RPCResponse,
|
|
39
41
|
)
|
|
40
42
|
from web3.utils import (
|
|
43
|
+
RequestCacheValidationThreshold,
|
|
41
44
|
SimpleCache,
|
|
42
45
|
)
|
|
43
46
|
|
|
@@ -46,6 +49,8 @@ if TYPE_CHECKING:
|
|
|
46
49
|
|
|
47
50
|
|
|
48
51
|
class BaseProvider:
|
|
52
|
+
# Set generic logger for the provider. Override in subclasses for more specificity.
|
|
53
|
+
logger: logging.Logger = logging.getLogger("web3.providers.base.BaseProvider")
|
|
49
54
|
# a tuple of (middleware, request_func)
|
|
50
55
|
_request_func_cache: Tuple[Tuple[Middleware, ...], Callable[..., RPCResponse]] = (
|
|
51
56
|
None,
|
|
@@ -65,10 +70,14 @@ class BaseProvider:
|
|
|
65
70
|
self,
|
|
66
71
|
cache_allowed_requests: bool = False,
|
|
67
72
|
cacheable_requests: Set[RPCEndpoint] = None,
|
|
73
|
+
request_cache_validation_threshold: Optional[
|
|
74
|
+
RequestCacheValidationThreshold
|
|
75
|
+
] = RequestCacheValidationThreshold.FINALIZED,
|
|
68
76
|
) -> None:
|
|
69
77
|
self._request_cache = SimpleCache(1000)
|
|
70
78
|
self.cache_allowed_requests = cache_allowed_requests
|
|
71
79
|
self.cacheable_requests = cacheable_requests or CACHEABLE_REQUESTS
|
|
80
|
+
self.request_cache_validation_threshold = request_cache_validation_threshold
|
|
72
81
|
|
|
73
82
|
def request_func(
|
|
74
83
|
self, w3: "Web3", middleware_onion: MiddlewareOnion
|
|
@@ -104,6 +113,8 @@ class BaseProvider:
|
|
|
104
113
|
|
|
105
114
|
|
|
106
115
|
class JSONBaseProvider(BaseProvider):
|
|
116
|
+
logger = logging.getLogger("web3.providers.base.JSONBaseProvider")
|
|
117
|
+
|
|
107
118
|
_is_batching: bool = False
|
|
108
119
|
_batch_request_func_cache: Tuple[
|
|
109
120
|
Tuple[Middleware, ...], Callable[..., List[RPCResponse]]
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import errno
|
|
3
3
|
import json
|
|
4
|
-
from json import (
|
|
5
|
-
JSONDecodeError,
|
|
6
|
-
)
|
|
7
4
|
import logging
|
|
8
5
|
from pathlib import (
|
|
9
6
|
Path,
|
|
@@ -16,10 +13,6 @@ from typing import (
|
|
|
16
13
|
Union,
|
|
17
14
|
)
|
|
18
15
|
|
|
19
|
-
from eth_utils import (
|
|
20
|
-
to_text,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
16
|
from web3.types import (
|
|
24
17
|
RPCResponse,
|
|
25
18
|
)
|
|
@@ -28,7 +21,9 @@ from . import (
|
|
|
28
21
|
PersistentConnectionProvider,
|
|
29
22
|
)
|
|
30
23
|
from ...exceptions import (
|
|
24
|
+
PersistentConnectionClosedOK,
|
|
31
25
|
ProviderConnectionError,
|
|
26
|
+
ReadBufferLimitReached,
|
|
32
27
|
Web3TypeError,
|
|
33
28
|
)
|
|
34
29
|
from ..ipc import (
|
|
@@ -37,7 +32,7 @@ from ..ipc import (
|
|
|
37
32
|
|
|
38
33
|
|
|
39
34
|
async def async_get_ipc_socket(
|
|
40
|
-
ipc_path: str,
|
|
35
|
+
ipc_path: str, read_buffer_limit: int
|
|
41
36
|
) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]:
|
|
42
37
|
if sys.platform == "win32":
|
|
43
38
|
# On Windows named pipe is used. Simulate socket with it.
|
|
@@ -47,7 +42,7 @@ async def async_get_ipc_socket(
|
|
|
47
42
|
|
|
48
43
|
return NamedPipe(ipc_path)
|
|
49
44
|
else:
|
|
50
|
-
return await asyncio.open_unix_connection(ipc_path)
|
|
45
|
+
return await asyncio.open_unix_connection(ipc_path, limit=read_buffer_limit)
|
|
51
46
|
|
|
52
47
|
|
|
53
48
|
class AsyncIPCProvider(PersistentConnectionProvider):
|
|
@@ -56,11 +51,11 @@ class AsyncIPCProvider(PersistentConnectionProvider):
|
|
|
56
51
|
_reader: Optional[asyncio.StreamReader] = None
|
|
57
52
|
_writer: Optional[asyncio.StreamWriter] = None
|
|
58
53
|
_decoder: json.JSONDecoder = json.JSONDecoder()
|
|
59
|
-
_raw_message: str = ""
|
|
60
54
|
|
|
61
55
|
def __init__(
|
|
62
56
|
self,
|
|
63
57
|
ipc_path: Optional[Union[str, Path]] = None,
|
|
58
|
+
read_buffer_limit: int = 20 * 1024 * 1024, # 20 MB
|
|
64
59
|
# `PersistentConnectionProvider` kwargs can be passed through
|
|
65
60
|
**kwargs: Any,
|
|
66
61
|
) -> None:
|
|
@@ -71,6 +66,7 @@ class AsyncIPCProvider(PersistentConnectionProvider):
|
|
|
71
66
|
else:
|
|
72
67
|
raise Web3TypeError("ipc_path must be of type string or pathlib.Path")
|
|
73
68
|
|
|
69
|
+
self.read_buffer_limit = read_buffer_limit
|
|
74
70
|
super().__init__(**kwargs)
|
|
75
71
|
|
|
76
72
|
def __str__(self) -> str:
|
|
@@ -101,18 +97,20 @@ class AsyncIPCProvider(PersistentConnectionProvider):
|
|
|
101
97
|
)
|
|
102
98
|
|
|
103
99
|
async def socket_recv(self) -> RPCResponse:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
100
|
+
try:
|
|
101
|
+
data = await self._reader.readline()
|
|
102
|
+
except ValueError as e:
|
|
103
|
+
if all(kw in str(e) for kw in ("limit", "chunk")):
|
|
104
|
+
raise ReadBufferLimitReached(
|
|
105
|
+
f"Read buffer limit of `{self.read_buffer_limit}` bytes was "
|
|
106
|
+
"reached. Consider increasing the ``read_buffer_limit`` on the "
|
|
107
|
+
"AsyncIPCProvider."
|
|
108
|
+
) from e
|
|
109
|
+
raise
|
|
110
|
+
|
|
111
|
+
if not data:
|
|
112
|
+
raise PersistentConnectionClosedOK("Socket reader received end of stream.")
|
|
113
|
+
return self.decode_rpc_response(data)
|
|
116
114
|
|
|
117
115
|
# -- private methods -- #
|
|
118
116
|
|
|
@@ -131,10 +129,14 @@ class AsyncIPCProvider(PersistentConnectionProvider):
|
|
|
131
129
|
async def _reset_socket(self) -> None:
|
|
132
130
|
self._writer.close()
|
|
133
131
|
await self._writer.wait_closed()
|
|
134
|
-
self._reader, self._writer = await async_get_ipc_socket(
|
|
132
|
+
self._reader, self._writer = await async_get_ipc_socket(
|
|
133
|
+
self.ipc_path, self.read_buffer_limit
|
|
134
|
+
)
|
|
135
135
|
|
|
136
136
|
async def _provider_specific_connect(self) -> None:
|
|
137
|
-
self._reader, self._writer = await async_get_ipc_socket(
|
|
137
|
+
self._reader, self._writer = await async_get_ipc_socket(
|
|
138
|
+
self.ipc_path, self.read_buffer_limit
|
|
139
|
+
)
|
|
138
140
|
|
|
139
141
|
async def _provider_specific_disconnect(self) -> None:
|
|
140
142
|
if self._writer and not self._writer.is_closing():
|
|
@@ -149,5 +151,3 @@ class AsyncIPCProvider(PersistentConnectionProvider):
|
|
|
149
151
|
|
|
150
152
|
def _error_log_listener_task_exception(self, e: Exception) -> None:
|
|
151
153
|
super()._error_log_listener_task_exception(e)
|
|
152
|
-
# reset the raw message buffer on exception when error logging
|
|
153
|
-
self._raw_message = ""
|
web3/providers/rpc/async_rpc.py
CHANGED
|
@@ -19,6 +19,7 @@ from eth_typing import (
|
|
|
19
19
|
URI,
|
|
20
20
|
)
|
|
21
21
|
from eth_utils import (
|
|
22
|
+
combomethod,
|
|
22
23
|
to_dict,
|
|
23
24
|
)
|
|
24
25
|
|
|
@@ -108,10 +109,17 @@ class AsyncHTTPProvider(AsyncJSONBaseProvider):
|
|
|
108
109
|
yield "headers", self.get_request_headers()
|
|
109
110
|
yield from self._request_kwargs.items()
|
|
110
111
|
|
|
111
|
-
|
|
112
|
+
@combomethod
|
|
113
|
+
def get_request_headers(cls) -> Dict[str, str]:
|
|
114
|
+
if isinstance(cls, AsyncHTTPProvider):
|
|
115
|
+
cls_name = cls.__class__.__name__
|
|
116
|
+
else:
|
|
117
|
+
cls_name = cls.__name__
|
|
118
|
+
module = cls.__module__
|
|
119
|
+
|
|
112
120
|
return {
|
|
113
121
|
"Content-Type": "application/json",
|
|
114
|
-
"User-Agent": construct_user_agent(
|
|
122
|
+
"User-Agent": construct_user_agent(module, cls_name),
|
|
115
123
|
}
|
|
116
124
|
|
|
117
125
|
async def _make_request(self, method: RPCEndpoint, request_data: bytes) -> bytes:
|
web3/providers/rpc/rpc.py
CHANGED
|
@@ -16,6 +16,7 @@ from eth_typing import (
|
|
|
16
16
|
URI,
|
|
17
17
|
)
|
|
18
18
|
from eth_utils import (
|
|
19
|
+
combomethod,
|
|
19
20
|
to_dict,
|
|
20
21
|
)
|
|
21
22
|
import requests
|
|
@@ -116,10 +117,18 @@ class HTTPProvider(JSONBaseProvider):
|
|
|
116
117
|
yield "headers", self.get_request_headers()
|
|
117
118
|
yield from self._request_kwargs.items()
|
|
118
119
|
|
|
119
|
-
|
|
120
|
+
@combomethod
|
|
121
|
+
def get_request_headers(cls) -> Dict[str, str]:
|
|
122
|
+
if isinstance(cls, HTTPProvider):
|
|
123
|
+
cls_name = cls.__class__.__name__
|
|
124
|
+
else:
|
|
125
|
+
cls_name = cls.__name__
|
|
126
|
+
|
|
127
|
+
module = cls.__module__
|
|
128
|
+
|
|
120
129
|
return {
|
|
121
130
|
"Content-Type": "application/json",
|
|
122
|
-
"User-Agent": construct_user_agent(
|
|
131
|
+
"User-Agent": construct_user_agent(module, cls_name),
|
|
123
132
|
}
|
|
124
133
|
|
|
125
134
|
def _make_request(self, method: RPCEndpoint, request_data: bytes) -> bytes:
|
web3/utils/__init__.py
CHANGED
|
@@ -36,6 +36,7 @@ from .async_exception_handling import (
|
|
|
36
36
|
async_handle_offchain_lookup,
|
|
37
37
|
)
|
|
38
38
|
from .caching import (
|
|
39
|
+
RequestCacheValidationThreshold,
|
|
39
40
|
SimpleCache,
|
|
40
41
|
)
|
|
41
42
|
from .exception_handling import (
|
|
@@ -67,6 +68,7 @@ __all__ = [
|
|
|
67
68
|
"log_topic_to_bytes",
|
|
68
69
|
"get_create_address",
|
|
69
70
|
"async_handle_offchain_lookup",
|
|
71
|
+
"RequestCacheValidationThreshold",
|
|
70
72
|
"SimpleCache",
|
|
71
73
|
"handle_offchain_lookup",
|
|
72
74
|
]
|
web3/utils/caching.py
CHANGED
|
@@ -2,6 +2,9 @@ import asyncio
|
|
|
2
2
|
from collections import (
|
|
3
3
|
OrderedDict,
|
|
4
4
|
)
|
|
5
|
+
from enum import (
|
|
6
|
+
Enum,
|
|
7
|
+
)
|
|
5
8
|
import time
|
|
6
9
|
from typing import (
|
|
7
10
|
Any,
|
|
@@ -12,6 +15,11 @@ from typing import (
|
|
|
12
15
|
)
|
|
13
16
|
|
|
14
17
|
|
|
18
|
+
class RequestCacheValidationThreshold(Enum):
|
|
19
|
+
FINALIZED = "finalized"
|
|
20
|
+
SAFE = "safe"
|
|
21
|
+
|
|
22
|
+
|
|
15
23
|
class SimpleCache:
|
|
16
24
|
def __init__(self, size: int = 100):
|
|
17
25
|
self._size = size
|