nerva-py 1.0.0b1__py3-none-any.whl → 1.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.
nerva/__init__.py CHANGED
@@ -11,12 +11,35 @@ class VersionInfo(NamedTuple):
11
11
  major: int
12
12
  minor: int
13
13
  micro: int
14
- releaselevel: Literal["alpha", "beta", "final"]
14
+ releaselevel: Literal[
15
+ "alpha", "beta", "release-candidate", "post", "dev", "final"
16
+ ]
15
17
  serial: int
16
18
 
19
+ def __str__(self) -> str:
20
+ v = f"{version_info.major}.{version_info.minor}.{version_info.micro}"
21
+
22
+ if version_info.releaselevel != "final":
23
+ if version_info.releaselevel == "alpha":
24
+ v += "a"
25
+ elif version_info.releaselevel == "beta":
26
+ v += "b"
27
+ elif version_info.releaselevel == "release-candidate":
28
+ v += "rc"
29
+ elif version_info.releaselevel == "post":
30
+ v += "post"
31
+ elif version_info.releaselevel == "dev":
32
+ v += "dev"
33
+
34
+ v += str(version_info.serial)
35
+
36
+ return v
37
+
17
38
 
18
39
  version_info: VersionInfo = VersionInfo(
19
- major=1, minor=0, micro=0, releaselevel="beta", serial=1
40
+ major=1, minor=1, micro=0, releaselevel="final", serial=0
20
41
  )
21
42
 
43
+ __version__ = str(version_info)
44
+
22
45
  del NamedTuple, Literal, VersionInfo
nerva/__main__.py CHANGED
@@ -2,7 +2,7 @@ import sys
2
2
  import argparse
3
3
  import platform
4
4
 
5
- import aiohttp
5
+ import httpx
6
6
 
7
7
  import nerva
8
8
 
@@ -13,16 +13,12 @@ def show_version() -> None:
13
13
  v = sys.version_info
14
14
  entries.append(
15
15
  f"- Python v{v.major}.{v.minor}.{v.micro}"
16
- + (f"-{v.releaselevel}" if v.releaselevel != "final" else "")
16
+ + (f"-{v.releaselevel}{v.serial}" if v.releaselevel != "final" else "")
17
17
  )
18
18
 
19
- v = nerva.version_info
20
- entries.append(
21
- f"- pyxnv v{v.major}.{v.minor}.{v.micro}"
22
- + (f"{v.releaselevel[0]}{v.serial}" if v.releaselevel != "final" else "")
23
- )
19
+ entries.append(f"- nerva-py v{nerva.__version__}")
24
20
 
25
- entries.append(f"- aiohttp v{aiohttp.__version__}")
21
+ entries.append(f"- httpx v{httpx.__version__}")
26
22
 
27
23
  uname = platform.uname()
28
24
  entries.append(f"- System Info: {uname.system} {uname.release} {uname.version}")
nerva/daemon.py CHANGED
@@ -2,12 +2,12 @@ from __future__ import annotations
2
2
 
3
3
  from typing import Any, Dict, List, Optional
4
4
 
5
- import aiohttp
5
+ import httpx
6
6
 
7
- __all__ = ["DaemonJSONRPC", "DaemonOther"]
7
+ __all__ = ["Daemon", "DaemonLegacy"]
8
8
 
9
9
 
10
- class DaemonJSONRPC:
10
+ class Daemon:
11
11
  """
12
12
  A class to interact with the Nerva daemon's JSON-RPC interface.
13
13
 
@@ -32,7 +32,7 @@ class DaemonJSONRPC:
32
32
  The headers for the request.
33
33
  """
34
34
 
35
- __slots__ = ["url", "timeout", "headers"]
35
+ __slots__ = ["url", "timeout", "headers", "auth"]
36
36
 
37
37
  def __init__(
38
38
  self,
@@ -40,20 +40,26 @@ class DaemonJSONRPC:
40
40
  port: Optional[int] = 17566,
41
41
  ssl: Optional[bool] = False,
42
42
  timeout: Optional[float] = 10.0,
43
+ username: Optional[str] = None,
44
+ password: Optional[str] = None,
43
45
  ) -> None:
44
46
  self.url: str = f"{'https' if ssl else 'http'}://{host}:{port}"
45
47
  self.timeout: float = timeout
46
48
  self.headers: Dict[str, str] = {"Content-Type": "application/json"}
49
+ self.auth: Optional[httpx.DigestAuth] = (
50
+ httpx.DigestAuth(username, password) if username and password else None
51
+ )
47
52
 
48
53
  async def _request(self, method: str, params: Dict[str, Any]) -> Dict[str, Any]:
49
- async with aiohttp.ClientSession() as session:
50
- async with session.post(
54
+ async with httpx.AsyncClient() as client:
55
+ response = await client.post(
51
56
  f"{self.url}/json_rpc",
52
57
  json={"jsonrpc": "2.0", "id": 0, "method": method, "params": params},
53
58
  headers=self.headers,
54
59
  timeout=self.timeout,
55
- ) as response:
56
- return await response.json(content_type=None)
60
+ auth=self.auth,
61
+ )
62
+ return response.json()
57
63
 
58
64
  async def get_block_count(self) -> Dict[str, Any]:
59
65
  """
@@ -634,7 +640,7 @@ class DaemonJSONRPC:
634
640
  return await self._request("add_peer", {"host": host})
635
641
 
636
642
 
637
- class DaemonOther:
643
+ class DaemonLegacy:
638
644
  """
639
645
  A class to interact with the Nerva daemon's independent endpoint methods.
640
646
 
@@ -660,7 +666,7 @@ class DaemonOther:
660
666
 
661
667
  """
662
668
 
663
- __slots__ = ["url", "timeout", "headers"]
669
+ __slots__ = ["url", "timeout", "headers", "auth"]
664
670
 
665
671
  def __init__(
666
672
  self,
@@ -668,23 +674,28 @@ class DaemonOther:
668
674
  port: Optional[int] = 17566,
669
675
  ssl: Optional[bool] = False,
670
676
  timeout: Optional[float] = 10.0,
677
+ username: Optional[str] = None,
678
+ password: Optional[str] = None,
671
679
  ):
672
680
  self.url = f"{'https' if ssl else 'http'}://{host}:{port}"
673
681
  self.timeout = timeout
674
-
675
682
  self.headers = {"Content-Type": "application/json"}
683
+ self.auth = (
684
+ httpx.DigestAuth(username, password) if username and password else None
685
+ )
676
686
 
677
687
  async def _request(
678
688
  self, endpoint: str, params: Dict[str, Any]
679
689
  ) -> Dict[str, Any]:
680
- async with aiohttp.ClientSession() as session:
681
- async with session.post(
690
+ async with httpx.AsyncClient() as client:
691
+ response = await client.post(
682
692
  f"{self.url}/{endpoint}",
683
693
  json=params,
684
694
  headers=self.headers,
685
695
  timeout=self.timeout,
686
- ) as response:
687
- return await response.json(content_type=None)
696
+ auth=self.auth,
697
+ )
698
+ return response.json()
688
699
 
689
700
  async def get_height(self) -> Dict[str, Any]:
690
701
  """
nerva/wallet.py CHANGED
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  from typing import Any, Dict, List, Optional
4
4
 
5
- import aiohttp
5
+ import httpx
6
6
 
7
7
  __all__ = ["Wallet"]
8
8
 
@@ -56,23 +56,22 @@ class Wallet:
56
56
  password: str = "",
57
57
  ) -> None:
58
58
  self.url: str = f"http{'s' if ssl else ''}://{host}:{port}"
59
- self.auth: Optional[aiohttp.BasicAuth] = (
60
- aiohttp.BasicAuth(username, password) if username and password else None
61
- )
62
59
  self.timeout: float = timeout
63
-
64
60
  self.headers: Dict[str, str] = {"Content-Type": "application/json"}
61
+ self.auth: Optional[httpx.DigestAuth] = (
62
+ httpx.DigestAuth(username, password) if username and password else None
63
+ )
65
64
 
66
65
  async def _request(self, method: str, params: Dict[str, Any]) -> Dict[str, Any]:
67
- async with aiohttp.ClientSession() as session:
68
- async with session.post(
66
+ async with httpx.AsyncClient() as client:
67
+ response = await client.post(
69
68
  f"{self.url}/json_rpc",
70
69
  json={"jsonrpc": "2.0", "id": 0, "method": method, "params": params},
71
70
  headers=self.headers,
72
71
  auth=self.auth,
73
72
  timeout=self.timeout,
74
- ) as response:
75
- return await response.json(content_type=None)
73
+ )
74
+ return response.json()
76
75
 
77
76
  async def get_balance(
78
77
  self, account_index: int, address_indices: Optional[List[int]] = None
@@ -1,12 +1,11 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nerva-py
3
- Version: 1.0.0b1
3
+ Version: 1.1.0
4
4
  Summary: Python bindings for the JSON RPC interface of the Nerva cryptocurrency.
5
5
  Author-email: Sayan Bhattacharyya <sayan@sn1f3rt.dev>
6
- License-Expression: MIT
7
- License-File: LICENSE
6
+ License: MIT
8
7
  Keywords: bindings,cryptocurrency,json-rpc,nerva,python
9
- Classifier: Development Status :: 4 - Beta
8
+ Classifier: Development Status :: 5 - Production/Stable
10
9
  Classifier: Intended Audience :: Developers
11
10
  Classifier: License :: OSI Approved :: MIT License
12
11
  Classifier: Operating System :: OS Independent
@@ -19,12 +18,13 @@ Classifier: Programming Language :: Python :: 3.12
19
18
  Classifier: Programming Language :: Python :: 3.13
20
19
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
20
  Requires-Python: >=3.8
22
- Requires-Dist: aiohttp>=3.10.10
21
+ Requires-Dist: httpx>=0.27.2
23
22
  Description-Content-Type: text/markdown
24
23
 
25
24
  # Nerva Python Library
26
25
 
27
26
  [![Ruff](https://github.com/Sn1F3rt/nerva-py/actions/workflows/ruff.yml/badge.svg)](https://github.com/Sn1F3rt/nerva-py/actions/workflows/ruff.yml)
27
+ [![Build](https://github.com/Sn1F3rt/nerva-py/actions/workflows/build.yml/badge.svg)](https://github.com/Sn1F3rt/nerva-py/actions/workflows/build.yml)
28
28
  [![License](https://img.shields.io/github/license/Sn1F3rt/nerva-py)](LICENSE)
29
29
 
30
30
  ## Table of Contents
@@ -69,12 +69,16 @@ Here is a simple example to get you started:
69
69
  ```python
70
70
  import asyncio
71
71
 
72
- from nerva.daemon import DaemonJSONRPC
72
+ from nerva.daemon import Daemon
73
73
 
74
74
 
75
75
  async def main():
76
- daemon = DaemonJSONRPC(
77
- host="x.y.z.w",
76
+ daemon = Daemon(
77
+ host="localhost",
78
+ port=17566,
79
+ ssl=False,
80
+ username="rpcuser", # omit if daemon was not started with the rpc-login flag
81
+ password="rpcpassword" # omit if daemon was not started with the rpc-login flag
78
82
  )
79
83
 
80
84
  print(await daemon.get_info())
@@ -0,0 +1,9 @@
1
+ nerva/__init__.py,sha256=uuerw1FTJ5CGL7NvOwKsp_-oTmN87MfSsfI7LYqNCUU,1128
2
+ nerva/__main__.py,sha256=vcuFqUiFv6xclYd1ME59lNH_d_E429SwMV-ShxmXCsg,1219
3
+ nerva/daemon.py,sha256=zMq1LUuJ1tggvVHTZGVGRksrqnHjnCNZ2AVogG6Vi9s,33573
4
+ nerva/utils.py,sha256=UzyhRTE2w7_H2YCz50ospggApyFbTOnrB92fuED9laQ,999
5
+ nerva/wallet.py,sha256=aomyDwd-a2kadX3v9FKHvhswFjYZOnELX95wQhxGkUo,59289
6
+ nerva_py-1.1.0.dist-info/METADATA,sha256=v0_5mR_OVkmaU8RdjPFZFxqk2yYul1_jtQb4PcTfFgc,2873
7
+ nerva_py-1.1.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
8
+ nerva_py-1.1.0.dist-info/licenses/LICENSE,sha256=OB3n91B4pOwIG9kD-nL-INDB0A7ma5fL9q32FGyoIQ4,1086
9
+ nerva_py-1.1.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.25.0
2
+ Generator: hatchling 1.26.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,9 +0,0 @@
1
- nerva/__init__.py,sha256=BR2PGu54C7y7F9NpvUqhLZY0itVlQHcFDmudd-ebM_4,412
2
- nerva/__main__.py,sha256=n4QOXzSwV07Sqr2_Ow0sPwg1PNrbbtDqo6URlaWuaFI,1345
3
- nerva/daemon.py,sha256=unffqyBt0qYL2Z3JpNGqJRMGZBG8hTbfDCIsbb2qkFk,33168
4
- nerva/utils.py,sha256=UzyhRTE2w7_H2YCz50ospggApyFbTOnrB92fuED9laQ,999
5
- nerva/wallet.py,sha256=EhQBS9PNq9QZdiP5I8y_jTPr_PtRHCf81dNwRdblDZA,59334
6
- nerva_py-1.0.0b1.dist-info/METADATA,sha256=iuuzuy8wPGnSgfuAWa5Z5Eo9Gog_uxdjYiAJc3ASBKs,2547
7
- nerva_py-1.0.0b1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
8
- nerva_py-1.0.0b1.dist-info/licenses/LICENSE,sha256=OB3n91B4pOwIG9kD-nL-INDB0A7ma5fL9q32FGyoIQ4,1086
9
- nerva_py-1.0.0b1.dist-info/RECORD,,