-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto web3 #344
Auto web3 #344
Changes from all commits
facd755
52e9151
51d5abb
7726190
49e0d10
12c23d8
26de091
daed896
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import importlib | ||
|
||
for connector in ('ipc', 'http'): | ||
connection = importlib.import_module('web3.auto.' + connector) | ||
if connection.w3: | ||
w3 = connection.w3 | ||
|
||
if w3.isConnected(): | ||
break |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from web3 import ( | ||
HTTPProvider, | ||
Web3 | ||
) | ||
import os | ||
|
||
|
||
def connect(): | ||
|
||
w3 = Web3(HTTPProvider( | ||
os.environ.get('WEB3_HTTP_PROVIDER_URI', 'http://localhost:8545') | ||
)) | ||
if w3.isConnected(): | ||
return w3 | ||
else: | ||
return False | ||
|
||
|
||
w3 = connect() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from web3.providers.ipc import get_default_ipc_path | ||
from web3 import ( | ||
IPCProvider, | ||
Web3 | ||
) | ||
|
||
|
||
def connect(): | ||
w3 = Web3(IPCProvider(get_default_ipc_path())) | ||
if w3.isConnected(): | ||
return w3 | ||
|
||
return False | ||
|
||
|
||
w3 = connect() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,22 +42,65 @@ def get_default_ipc_path(testnet=False): | |
testnet = "" | ||
|
||
if sys.platform == 'darwin': | ||
return os.path.expanduser(os.path.join( | ||
ipc_path = os.path.expanduser(os.path.join( | ||
"~", | ||
"Library", | ||
"Ethereum", | ||
testnet, | ||
"geth.ipc", | ||
"geth.ipc" | ||
)) | ||
if os.path.exists(ipc_path): | ||
return ipc_path | ||
|
||
ipc_path = os.path.expanduser(os.path.join( | ||
"~", | ||
"Library", | ||
"Application Support", | ||
"io.parity.ethereum", | ||
"jsonrpc.ipc" | ||
)) | ||
if os.path.exists(ipc_path): | ||
return ipc_path | ||
|
||
elif sys.platform.startswith('linux'): | ||
return os.path.expanduser(os.path.join( | ||
ipc_path = os.path.expanduser(os.path.join( | ||
"~", | ||
".ethereum", | ||
testnet, | ||
"geth.ipc", | ||
"geth.ipc" | ||
)) | ||
if os.path.exists(ipc_path): | ||
return ipc_path | ||
|
||
ipc_path = os.path.expanduser(os.path.join( | ||
"~", | ||
".local", | ||
"share", | ||
"io.parity.ethereum", | ||
"jsonrpc.ipc" | ||
)) | ||
if os.path.exists(ipc_path): | ||
return ipc_path | ||
|
||
elif sys.platform == 'win32': | ||
return "\\\\.\\pipe\\geth.ipc" | ||
ipc_path = os.path.join( | ||
"\\\\", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I so wish we had windows CI to know that this works.... 😢 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tagging #166 for motivation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested it on my windows machine if it is of some consolation to you. I couldn' get seperated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also had geth and parity running while doing my in house testing, but I agree a more thourough test would be comforting. |
||
".", | ||
"pipe", | ||
"geth.ipc" | ||
) | ||
if os.path.exists(ipc_path): | ||
return ipc_path | ||
|
||
ipc_path = os.path.join( | ||
"\\\\", | ||
".", | ||
"pipe", | ||
"jsonrpc.ipc" | ||
) | ||
if os.path.exists(ipc_path): | ||
return ipc_path | ||
|
||
else: | ||
raise ValueError( | ||
"Unsupported platform '{0}'. Only darwin/linux2/win32 are " | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check looks redundant: if w3 is set, then
isConnected()
is True