mm-btc 0.0.5__py3-none-any.whl → 0.0.6__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 +57 -29
- mm_btc/cli/cli.py +20 -1
- mm_btc/cli/cmd/address_cmd.py +3 -3
- mm_btc/cli/cmd/create_tx_cmd.py +27 -0
- mm_btc/cli/cmd/decode_tx_cmd.py +8 -0
- mm_btc/cli/cmd/utxo_cmd.py +11 -0
- mm_btc/tx.py +5 -0
- {mm_btc-0.0.5.dist-info → mm_btc-0.0.6.dist-info}/METADATA +3 -1
- mm_btc-0.0.6.dist-info/RECORD +19 -0
- mm_btc-0.0.5.dist-info/RECORD +0 -15
- {mm_btc-0.0.5.dist-info → mm_btc-0.0.6.dist-info}/WHEEL +0 -0
- {mm_btc-0.0.5.dist-info → mm_btc-0.0.6.dist-info}/entry_points.txt +0 -0
- {mm_btc-0.0.5.dist-info → mm_btc-0.0.6.dist-info}/top_level.txt +0 -0
mm_btc/blockstream.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from collections.abc import Sequence
|
|
2
2
|
from typing import TypeAlias
|
|
3
3
|
|
|
4
|
-
from mm_std import Err, Ok, Result, hr
|
|
4
|
+
from mm_std import Err, HResponse, Ok, Result, hr
|
|
5
5
|
from mm_std.random_ import random_str_choice
|
|
6
6
|
from pydantic import BaseModel
|
|
7
7
|
|
|
@@ -33,31 +33,59 @@ class Address(BaseModel):
|
|
|
33
33
|
mempool_stats: MempoolStats
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
36
|
+
class Utxo(BaseModel):
|
|
37
|
+
class Status(BaseModel):
|
|
38
|
+
confirmed: bool
|
|
39
|
+
block_height: int
|
|
40
|
+
block_hash: str
|
|
41
|
+
block_time: int
|
|
42
|
+
|
|
43
|
+
txid: str
|
|
44
|
+
vout: int
|
|
45
|
+
status: Status
|
|
46
|
+
value: int
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class BlockstreamClient:
|
|
50
|
+
def __init__(self, testnet: bool = False, timeout: int = 10, proxies: Proxy = None, attempts: int = 1):
|
|
51
|
+
self.testnet = testnet
|
|
52
|
+
self.timeout = timeout
|
|
53
|
+
self.proxies = proxies
|
|
54
|
+
self.attempts = attempts
|
|
55
|
+
self.base_url = TESTNET_BASE_URL if testnet else MAINNET_BASE_URL
|
|
56
|
+
|
|
57
|
+
def get_address(self, address: str) -> Result[Address]:
|
|
58
|
+
result: Result[Address] = Err("not started yet")
|
|
59
|
+
data = None
|
|
60
|
+
for _ in range(self.attempts):
|
|
61
|
+
try:
|
|
62
|
+
res = self._request(f"/address/{address}")
|
|
63
|
+
data = res.to_dict()
|
|
64
|
+
if res.code == 400 and (
|
|
65
|
+
"invalid bitcoin address" in res.body.lower() or "bech32 segwit decoding error" in res.body.lower()
|
|
66
|
+
):
|
|
67
|
+
return Err(ERROR_INVALID_ADDRESS, data=data)
|
|
68
|
+
elif res.code == 400 and "invalid network" in res.body.lower():
|
|
69
|
+
return Err(ERROR_INVALID_NETWORK, data=data)
|
|
70
|
+
return Ok(Address(**res.json), data=data)
|
|
71
|
+
except Exception as err:
|
|
72
|
+
result = Err(err, data=data)
|
|
73
|
+
return result
|
|
74
|
+
|
|
75
|
+
def get_confirmed_balance(self, address: str) -> Result[int]:
|
|
76
|
+
return self.get_address(address).and_then(lambda a: Ok(a.chain_stats.funded_txo_sum - a.chain_stats.spent_txo_sum))
|
|
77
|
+
|
|
78
|
+
def get_utxo(self, address: str) -> Result[list[Utxo]]:
|
|
79
|
+
result: Result[list[Utxo]] = Err("not started yet")
|
|
80
|
+
data = None
|
|
81
|
+
for _ in range(self.attempts):
|
|
82
|
+
try:
|
|
83
|
+
res = self._request(f"/address/{address}/utxo")
|
|
84
|
+
data = res.to_dict()
|
|
85
|
+
return Ok([Utxo(**out) for out in res.json], data=data)
|
|
86
|
+
except Exception as err:
|
|
87
|
+
result = Err(err, data=data)
|
|
88
|
+
return result
|
|
89
|
+
|
|
90
|
+
def _request(self, url: str) -> HResponse:
|
|
91
|
+
return hr(f"{self.base_url}{url}", timeout=self.timeout, proxy=random_str_choice(self.proxies))
|
mm_btc/cli/cli.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from pathlib import Path
|
|
1
2
|
from typing import Annotated
|
|
2
3
|
|
|
3
4
|
import typer
|
|
@@ -5,7 +6,7 @@ import typer.core
|
|
|
5
6
|
from mm_std import print_plain
|
|
6
7
|
|
|
7
8
|
from mm_btc.cli import cli_utils
|
|
8
|
-
from mm_btc.cli.cmd import address_cmd, mnemonic_cmd
|
|
9
|
+
from mm_btc.cli.cmd import address_cmd, create_tx_cmd, decode_tx_cmd, mnemonic_cmd, utxo_cmd
|
|
9
10
|
|
|
10
11
|
app = typer.Typer(no_args_is_help=True, pretty_exceptions_enable=False, add_completion=False)
|
|
11
12
|
|
|
@@ -42,6 +43,24 @@ def address_command(address: str) -> None:
|
|
|
42
43
|
address_cmd.run(address)
|
|
43
44
|
|
|
44
45
|
|
|
46
|
+
@app.command("create-tx")
|
|
47
|
+
def create_tx_command(config_path: Annotated[Path, typer.Argument(exists=True)]) -> None:
|
|
48
|
+
"""Create a transaction"""
|
|
49
|
+
create_tx_cmd.run(config_path)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@app.command("decode-tx")
|
|
53
|
+
def decode_tx_command(tx_hex: str, testnet: Annotated[bool, typer.Option("--testnet", "-t")] = False) -> None:
|
|
54
|
+
"""Decode a transaction"""
|
|
55
|
+
decode_tx_cmd.run(tx_hex, testnet)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@app.command("utxo")
|
|
59
|
+
def utxo_command(address: str) -> None:
|
|
60
|
+
"""Get UTXOs from Blockstream API"""
|
|
61
|
+
utxo_cmd.run(address)
|
|
62
|
+
|
|
63
|
+
|
|
45
64
|
def version_callback(value: bool) -> None:
|
|
46
65
|
if value:
|
|
47
66
|
print_plain(f"mm-btc: v{cli_utils.get_version()}")
|
mm_btc/cli/cmd/address_cmd.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from mm_std import print_json
|
|
2
2
|
|
|
3
|
-
from mm_btc import
|
|
3
|
+
from mm_btc.blockstream import BlockstreamClient
|
|
4
4
|
from mm_btc.wallet import is_testnet_address
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
def run(address: str) -> None:
|
|
8
|
-
|
|
9
|
-
res =
|
|
8
|
+
client = BlockstreamClient(testnet=is_testnet_address(address))
|
|
9
|
+
res = client.get_address(address)
|
|
10
10
|
print_json(res)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from bit import PrivateKey, PrivateKeyTestnet
|
|
4
|
+
from mm_std import BaseConfig, print_console
|
|
5
|
+
|
|
6
|
+
from mm_btc.wallet import is_testnet_address
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Config(BaseConfig):
|
|
10
|
+
class Output(BaseConfig):
|
|
11
|
+
address: str
|
|
12
|
+
amount: int
|
|
13
|
+
|
|
14
|
+
from_address: str
|
|
15
|
+
private: str
|
|
16
|
+
outputs: list[Output]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def run(config_path: Path) -> None:
|
|
20
|
+
config = Config.read_config(config_path)
|
|
21
|
+
testnet = is_testnet_address(config.from_address)
|
|
22
|
+
key = PrivateKeyTestnet(config.private) if testnet else PrivateKey(config.private)
|
|
23
|
+
|
|
24
|
+
outputs = [(o.address, o.amount, "satoshi") for o in config.outputs]
|
|
25
|
+
|
|
26
|
+
tx = key.create_transaction(outputs)
|
|
27
|
+
print_console(tx)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from mm_std import print_json
|
|
2
|
+
|
|
3
|
+
from mm_btc.blockstream import BlockstreamClient
|
|
4
|
+
from mm_btc.wallet import is_testnet_address
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def run(address: str) -> None:
|
|
8
|
+
client = BlockstreamClient(testnet=is_testnet_address(address))
|
|
9
|
+
res = client.get_utxo(address)
|
|
10
|
+
|
|
11
|
+
print_json(res.ok_or_err())
|
mm_btc/tx.py
ADDED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mm-btc
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
4
4
|
Requires-Python: >=3.12
|
|
5
5
|
Requires-Dist: mm-std ~=0.1.0
|
|
6
6
|
Requires-Dist: hdwallet ~=2.2.1
|
|
7
|
+
Requires-Dist: bit ~=0.8.0
|
|
8
|
+
Requires-Dist: bitcoinlib ~=0.6.15
|
|
7
9
|
Requires-Dist: typer ~=0.12.3
|
|
8
10
|
Provides-Extra: dev
|
|
9
11
|
Requires-Dist: build ~=1.2.1 ; extra == 'dev'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
mm_btc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
mm_btc/blockstream.py,sha256=kz8TdbCYdQKFU9gNY6mFkTgAnUsleyI5ZEL1Pxe6oCU,3073
|
|
3
|
+
mm_btc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
mm_btc/tx.py,sha256=7KTMNuL1n8rRj_245BV1bH9M2_PctNvlvPsLEsRTYx4,245
|
|
5
|
+
mm_btc/wallet.py,sha256=0ejOIl5gbm1oMO4WY3AsQRiF3PCrB4WC2LknaYPmMfY,1838
|
|
6
|
+
mm_btc/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
mm_btc/cli/cli.py,sha256=D_yQ_L7oBY9aJ3_TKeJOQmXFsx8yK3lmARTAsmMXjO8,2413
|
|
8
|
+
mm_btc/cli/cli_utils.py,sha256=g2o5ySLu-Tw8dZm84ZAsx8862yHij4sDfz4z6uLS2hw,102
|
|
9
|
+
mm_btc/cli/cmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
mm_btc/cli/cmd/address_cmd.py,sha256=fipX9FiQ2EgCEq8nVN6ELnDMoR5KTIX7bpAaRK3t_yg,284
|
|
11
|
+
mm_btc/cli/cmd/create_tx_cmd.py,sha256=dIuQBTOqTSefC6aMbrBN6Pq0EwV2G2ESM1tLU4WyFoU,690
|
|
12
|
+
mm_btc/cli/cmd/decode_tx_cmd.py,sha256=0jGlUjnA1X2Q2aYwSBeAjqVNZIBsW5X2lEwIpSfWJsU,175
|
|
13
|
+
mm_btc/cli/cmd/mnemonic_cmd.py,sha256=zAAHr9j0SLJX5BXoiMTZj8pIzTPX26aJEOUi7IN40Ug,1192
|
|
14
|
+
mm_btc/cli/cmd/utxo_cmd.py,sha256=mp-lVLURpXFqO3IeBIEwnHusEvT5tFjUKxnRYC-rFqQ,294
|
|
15
|
+
mm_btc-0.0.6.dist-info/METADATA,sha256=DJ-RvWkc3GP9SzETkhD1BCK7vkmngd9qEcu1O38Jg6g,920
|
|
16
|
+
mm_btc-0.0.6.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
|
17
|
+
mm_btc-0.0.6.dist-info/entry_points.txt,sha256=KphzLNE9eb9H1DO-L0gvBQaQT5ImedyVCN4a6svfiRg,46
|
|
18
|
+
mm_btc-0.0.6.dist-info/top_level.txt,sha256=0X0Ppv_QY0ulzgCB5HNezpaHfQ4wvih_B72hn5hHTUE,7
|
|
19
|
+
mm_btc-0.0.6.dist-info/RECORD,,
|
mm_btc-0.0.5.dist-info/RECORD
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
mm_btc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
mm_btc/blockstream.py,sha256=HllRQBO1Ezl0ArVH8b-CPRi0f5zdRNXJT_K3oCpAtgg,2159
|
|
3
|
-
mm_btc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
mm_btc/wallet.py,sha256=0ejOIl5gbm1oMO4WY3AsQRiF3PCrB4WC2LknaYPmMfY,1838
|
|
5
|
-
mm_btc/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
mm_btc/cli/cli.py,sha256=5UWUzlJvaV8qq2hZ_XptkaLPf81EbwlYFNcT-_xmQ_U,1825
|
|
7
|
-
mm_btc/cli/cli_utils.py,sha256=g2o5ySLu-Tw8dZm84ZAsx8862yHij4sDfz4z6uLS2hw,102
|
|
8
|
-
mm_btc/cli/cmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
mm_btc/cli/cmd/address_cmd.py,sha256=vOjPgK9D91w2YWyCvbRO1_dWfuRDxpjNzOUpJYvYEVE,262
|
|
10
|
-
mm_btc/cli/cmd/mnemonic_cmd.py,sha256=zAAHr9j0SLJX5BXoiMTZj8pIzTPX26aJEOUi7IN40Ug,1192
|
|
11
|
-
mm_btc-0.0.5.dist-info/METADATA,sha256=28ask6JTpLCaDXE_gNWlatFVY88mgZbovq3CvdMvg84,858
|
|
12
|
-
mm_btc-0.0.5.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
|
13
|
-
mm_btc-0.0.5.dist-info/entry_points.txt,sha256=KphzLNE9eb9H1DO-L0gvBQaQT5ImedyVCN4a6svfiRg,46
|
|
14
|
-
mm_btc-0.0.5.dist-info/top_level.txt,sha256=0X0Ppv_QY0ulzgCB5HNezpaHfQ4wvih_B72hn5hHTUE,7
|
|
15
|
-
mm_btc-0.0.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|