chainhound 0.1.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.
chainhound/__init__.py
ADDED
chainhound/blockchain.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from logging import getLogger
|
|
5
|
+
|
|
6
|
+
from returns.result import Failure, Result, Success
|
|
7
|
+
from web3 import AsyncBaseProvider, AsyncHTTPProvider, AsyncWeb3
|
|
8
|
+
|
|
9
|
+
logger = getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BlockchainError(Exception):
|
|
13
|
+
def __init__(self, message: str = "") -> None:
|
|
14
|
+
self.message = message
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True, slots=True)
|
|
18
|
+
class Blockchain:
|
|
19
|
+
web3: AsyncWeb3[AsyncBaseProvider]
|
|
20
|
+
|
|
21
|
+
@classmethod
|
|
22
|
+
def build(cls, endpoint: str) -> Blockchain:
|
|
23
|
+
if not endpoint:
|
|
24
|
+
raise ValueError(f"Incorrect endpoint: {endpoint}")
|
|
25
|
+
|
|
26
|
+
return cls(web3=AsyncWeb3(AsyncHTTPProvider(endpoint)))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
async def is_connected(blockchain: Blockchain) -> bool:
|
|
30
|
+
return await blockchain.web3.provider.is_connected()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
async def close_connection(blockchain: Blockchain) -> None:
|
|
34
|
+
assert blockchain is not None, "Must pass a valid blockchain"
|
|
35
|
+
|
|
36
|
+
logger.info("Closing blockchain connection")
|
|
37
|
+
await blockchain.web3.provider.disconnect()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
async def get_last_block_number(blockchain: Blockchain) -> Result[int, BlockchainError]:
|
|
41
|
+
if not await is_connected(blockchain):
|
|
42
|
+
return Failure(
|
|
43
|
+
BlockchainError("The given blockchain instance is not connected")
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
return Success(await blockchain.web3.eth.block_number)
|
chainhound/config.py
ADDED
chainhound/entrypoint.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: chainhound
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Author: spin3l
|
|
6
|
+
Author-email: spin3l <dev.christianlopezgarcia@gmail.com>
|
|
7
|
+
Requires-Dist: anyio>=4.13.0
|
|
8
|
+
Requires-Dist: pydantic-settings>=2.14.1
|
|
9
|
+
Requires-Dist: returns[compatible-mypy,mypy-compatible]>=0.28.0
|
|
10
|
+
Requires-Dist: web3>=7.16.0
|
|
11
|
+
Requires-Python: >=3.14
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
chainhound/__init__.py,sha256=Tss2VDS-l8OEp-wlZwg5K63o7vFOHifMLmPriNbnlR4,78
|
|
2
|
+
chainhound/blockchain.py,sha256=GyVHHh--1W_PWfYFBNCdlJ2kuLL1yfbWuEqN5y7sKeo,1375
|
|
3
|
+
chainhound/config.py,sha256=05qZtEna8VXGpaGK4wQo-NI30jaUEv-NvzIcnX78BXc,243
|
|
4
|
+
chainhound/entrypoint.py,sha256=s4u77UySp-WFoFhsakbICYr3t-5VzUjn9H890_dl0OU,59
|
|
5
|
+
chainhound-0.1.0.dist-info/WHEEL,sha256=ZyFSCYkV2BrxH6-HRVRg3R9Fo7MALzer9KiPYqNxSbo,79
|
|
6
|
+
chainhound-0.1.0.dist-info/entry_points.txt,sha256=e2WQV4-MU8mNqaTAs-ANxPY4Lt_RIJXrmgHnI7bz6-w,48
|
|
7
|
+
chainhound-0.1.0.dist-info/METADATA,sha256=9Rn_Tzzl8QYkXf6rfqLrFBc2KWWFp_uWkAey7NduWtI,389
|
|
8
|
+
chainhound-0.1.0.dist-info/RECORD,,
|