mm-btc 0.1.3__py3-none-any.whl → 0.2.1__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.
mm_btc/blockstream.py CHANGED
@@ -1,5 +1,4 @@
1
1
  from collections.abc import Sequence
2
- from typing import TypeAlias
3
2
 
4
3
  from mm_std import Err, HResponse, Ok, Result, hr
5
4
  from mm_std.random_ import random_str_choice
@@ -11,7 +10,7 @@ TESTNET_BASE_URL = "https://blockstream.info/testnet/api"
11
10
  ERROR_INVALID_ADDRESS = "INVALID_ADDRESS"
12
11
  ERROR_INVALID_NETWORK = "INVALID_NETWORK"
13
12
 
14
- Proxy: TypeAlias = str | Sequence[str] | None
13
+ type Proxy = str | Sequence[str] | None
15
14
 
16
15
 
17
16
  class Mempool(BaseModel):
@@ -54,7 +53,7 @@ class Utxo(BaseModel):
54
53
 
55
54
 
56
55
  class BlockstreamClient:
57
- def __init__(self, testnet: bool = False, timeout: int = 10, proxies: Proxy = None, attempts: int = 1):
56
+ def __init__(self, testnet: bool = False, timeout: int = 10, proxies: Proxy = None, attempts: int = 1) -> None:
58
57
  self.testnet = testnet
59
58
  self.timeout = timeout
60
59
  self.proxies = proxies
@@ -72,7 +71,7 @@ class BlockstreamClient:
72
71
  "invalid bitcoin address" in res.body.lower() or "bech32 segwit decoding error" in res.body.lower()
73
72
  ):
74
73
  return Err(ERROR_INVALID_ADDRESS, data=data)
75
- elif res.code == 400 and "invalid network" in res.body.lower():
74
+ if res.code == 400 and "invalid network" in res.body.lower():
76
75
  return Err(ERROR_INVALID_NETWORK, data=data)
77
76
  return Ok(Address(**res.json), data=data)
78
77
  except Exception as err:
mm_btc/cli/cli.py CHANGED
@@ -5,10 +5,11 @@ import typer
5
5
  import typer.core
6
6
  from mm_std import print_plain
7
7
 
8
- from mm_btc.cli import cli_utils
9
- from mm_btc.cli.cmd import address_cmd, create_tx_cmd, decode_tx_cmd, mnemonic_cmd, utxo_cmd
10
8
  from mm_btc.wallet import AddressType
11
9
 
10
+ from . import cli_utils
11
+ from .cmd import address_cmd, create_tx_cmd, decode_tx_cmd, mnemonic_cmd, utxo_cmd
12
+
12
13
  app = typer.Typer(no_args_is_help=True, pretty_exceptions_enable=False, add_completion=False)
13
14
 
14
15
 
@@ -67,7 +68,7 @@ def utxo_command(address: str) -> None:
67
68
  def version_callback(value: bool) -> None:
68
69
  if value:
69
70
  print_plain(f"mm-btc: v{cli_utils.get_version()}")
70
- raise typer.Exit()
71
+ raise typer.Exit
71
72
 
72
73
 
73
74
  @app.callback()
mm_btc/cli/cli_utils.py CHANGED
@@ -1,5 +1,19 @@
1
1
  import importlib.metadata
2
+ import sys
3
+ from pathlib import Path
4
+
5
+ from mm_std import BaseConfig
6
+ from rich import print_json
2
7
 
3
8
 
4
9
  def get_version() -> str:
5
10
  return importlib.metadata.version("mm-btc")
11
+
12
+
13
+ def read_config[T: BaseConfig](config_type: type[T], config_path: Path) -> T:
14
+ res = config_type.read_config(config_path)
15
+ if res.is_ok():
16
+ return res.unwrap()
17
+
18
+ print_json(res.err)
19
+ sys.exit(1)
@@ -3,6 +3,7 @@ from pathlib import Path
3
3
  from bit import PrivateKey, PrivateKeyTestnet
4
4
  from mm_std import BaseConfig, print_console
5
5
 
6
+ from mm_btc.cli.cli_utils import read_config
6
7
  from mm_btc.wallet import is_testnet_address
7
8
 
8
9
 
@@ -17,7 +18,7 @@ class Config(BaseConfig):
17
18
 
18
19
 
19
20
  def run(config_path: Path) -> None:
20
- config = Config.read_config(config_path)
21
+ config = read_config(Config, config_path)
21
22
  testnet = is_testnet_address(config.from_address)
22
23
  key = PrivateKeyTestnet(config.private) if testnet else PrivateKey(config.private)
23
24
 
mm_btc/wallet.py CHANGED
@@ -39,13 +39,9 @@ def generate_mnemonic(language: str = "english", words: int = 12) -> str:
39
39
 
40
40
  def derive_accounts(mnemonic: str, passphrase: str, path_prefix: str, address_type: AddressType, limit: int) -> list[Account]:
41
41
  coin = Bitcoin
42
- if path_prefix.startswith("m/84'/1'"):
42
+ if path_prefix.startswith(("m/84'/1'", "m/44'/1'")):
43
43
  network = coin.NETWORKS.TESTNET
44
- elif path_prefix.startswith("m/44'/1'"):
45
- network = coin.NETWORKS.TESTNET
46
- elif path_prefix.startswith("m/84'/0'"):
47
- network = coin.NETWORKS.MAINNET
48
- elif path_prefix.startswith("m/44'/0'"):
44
+ elif path_prefix.startswith(("m/84'/0'", "m/44'/0'")):
49
45
  network = coin.NETWORKS.MAINNET
50
46
  else:
51
47
  raise ValueError("Invalid path")
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: mm-btc
3
+ Version: 0.2.1
4
+ Requires-Python: >=3.12
5
+ Requires-Dist: bitcoinlib~=0.7.1
6
+ Requires-Dist: bit~=0.8.0
7
+ Requires-Dist: hdwallet~=3.2.3
8
+ Requires-Dist: mm-std~=0.1.11
9
+ Requires-Dist: mnemonic~=0.21
10
+ Requires-Dist: typer~=0.15.1
@@ -1,18 +1,18 @@
1
1
  mm_btc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- mm_btc/blockstream.py,sha256=U2_pc6RYAkFcCvH_WrxjIm13VNavyY3WgK8ePowV-Ic,3620
2
+ mm_btc/blockstream.py,sha256=as3Rv_OsbdvclUEotxrXC8K5mwddxvznY3SuFscKkY4,3591
3
3
  mm_btc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  mm_btc/tx.py,sha256=7KTMNuL1n8rRj_245BV1bH9M2_PctNvlvPsLEsRTYx4,245
5
- mm_btc/wallet.py,sha256=E9XKZMQx48JiGRDG8ij7cbilNPVmcpmS6jAGBzXfV9U,2475
5
+ mm_btc/wallet.py,sha256=_pGTuAf6Y9KzaWTTSg_tn6WEoRsGqhxJuPof0_xyrmM,2333
6
6
  mm_btc/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- mm_btc/cli/cli.py,sha256=uD49Nek6ZuBLnNOjGghSHv5eNPS2E6hTyCyjvvMOmGU,2620
8
- mm_btc/cli/cli_utils.py,sha256=g2o5ySLu-Tw8dZm84ZAsx8862yHij4sDfz4z6uLS2hw,102
7
+ mm_btc/cli/cli.py,sha256=RleK9_widQ6OQEWU10qTRKvi7ooHKGE5JPYNOM9DfnM,2600
8
+ mm_btc/cli/cli_utils.py,sha256=vNXTicMAyUWbPmdnAcBn5cCGON75ayZ6rVK8T5McgtQ,413
9
9
  mm_btc/cli/cmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  mm_btc/cli/cmd/address_cmd.py,sha256=fipX9FiQ2EgCEq8nVN6ELnDMoR5KTIX7bpAaRK3t_yg,284
11
- mm_btc/cli/cmd/create_tx_cmd.py,sha256=dIuQBTOqTSefC6aMbrBN6Pq0EwV2G2ESM1tLU4WyFoU,690
11
+ mm_btc/cli/cmd/create_tx_cmd.py,sha256=kD3lTc7sSDconCfB-PFHiH415ABeZ86kfkDwEw2jx50,736
12
12
  mm_btc/cli/cmd/decode_tx_cmd.py,sha256=0jGlUjnA1X2Q2aYwSBeAjqVNZIBsW5X2lEwIpSfWJsU,175
13
13
  mm_btc/cli/cmd/mnemonic_cmd.py,sha256=CY6tPsqOTNfM-4WhKDhqitCi2OeqSIUMEUTFIRGHwIg,1254
14
14
  mm_btc/cli/cmd/utxo_cmd.py,sha256=mp-lVLURpXFqO3IeBIEwnHusEvT5tFjUKxnRYC-rFqQ,294
15
- mm_btc-0.1.3.dist-info/METADATA,sha256=XP2L_wEpJRZGBh2WG_hSaY6HMhkDPrqEIXf6R-z1pJE,252
16
- mm_btc-0.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
17
- mm_btc-0.1.3.dist-info/entry_points.txt,sha256=KphzLNE9eb9H1DO-L0gvBQaQT5ImedyVCN4a6svfiRg,46
18
- mm_btc-0.1.3.dist-info/RECORD,,
15
+ mm_btc-0.2.1.dist-info/METADATA,sha256=uEDpGrymap4CQcZEBzNK9devojVPZ6aW8iLFrS9fczM,253
16
+ mm_btc-0.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
17
+ mm_btc-0.2.1.dist-info/entry_points.txt,sha256=KphzLNE9eb9H1DO-L0gvBQaQT5ImedyVCN4a6svfiRg,46
18
+ mm_btc-0.2.1.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: mm-btc
3
- Version: 0.1.3
4
- Requires-Python: >=3.12
5
- Requires-Dist: bitcoinlib~=0.7.1
6
- Requires-Dist: bit~=0.8.0
7
- Requires-Dist: hdwallet~=3.2.0
8
- Requires-Dist: mm-std~=0.1.9
9
- Requires-Dist: mnemonic>=0.21
10
- Requires-Dist: typer>=0.15.1
File without changes