예제 #1
0
class Geth():
    def __init__(self, ipc_path):
        self.provider = IPCProvider(ipc_path, timeout=60)

    def last_block(self):
        pass

    def get_block(self, block_num):
        """Get a specific block from the blockchain and filter the data."""
        data = self.provider.make_request("eth_getBlockByNumber", [hex(block_num), True])["result"]
        return GethBlock(data)

    def get_blocks(self, start_num, end_num):
        for n in range(start_num, end_num):
            yield self.get_block(n)
예제 #2
0
    def connect_to_clef(self, uri: str = None, timeout: int = 120) -> None:
        """
        Connect to Clef and import open accounts.

        Clef is an account signing utility packaged with Geth, which can be
        used to interact with HW wallets in Brownie. Before calling this
        function, Clef must be running in another command prompt.

        Arguments
        ---------
        uri : str
            IPC path or http url to use to connect to clef. If None is given,
            uses the default IPC path on Unix systems or localhost on Windows.
        timeout : int
            The number of seconds to wait on a clef request before raising a
            timeout exception.
        """
        provider = None
        if uri is None:
            if sys.platform == "win32":
                uri = "http://localhost:8550/"
            else:
                uri = Path.home().joinpath(".clef/clef.ipc").as_posix()
        try:
            if Path(uri).exists():
                provider = IPCProvider(uri, timeout=timeout)
        except OSError:
            if uri is not None and uri.startswith("http"):
                provider = HTTPProvider(uri, {"timeout": timeout})
        if provider is None:
            raise ValueError(
                "Unknown URI, must be IPC socket path or URL starting with 'http'"
            )

        response = provider.make_request("account_list", [])
        if "error" in response:
            raise ValueError(response["error"]["message"])

        for address in response["result"]:
            if to_address(address) not in self._accounts:
                self._accounts.append(ClefAccount(address, provider))