bitcoinwatcher 0.2.0__tar.gz → 1.0.1__tar.gz
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.
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/PKG-INFO +2 -1
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/address_listener/address_listener.py +15 -5
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/address_listener/simple_address_listener.py +4 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/tests/test_address_listener.py +9 -2
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/tx_listener/zmq_listener.py +1 -3
- bitcoinwatcher-1.0.1/bitcoin/utils/constants.py +2 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoinwatcher.egg-info/PKG-INFO +2 -1
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoinwatcher.egg-info/SOURCES.txt +1 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoinwatcher.egg-info/requires.txt +1 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/pyproject.toml +3 -2
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/LICENSE +0 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/README.md +0 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/__init__.py +0 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/address_listener/__init__.py +0 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/tests/__init__.py +0 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/tx_listener/__init__.py +0 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/tx_listener/abstract_tx_listener.py +0 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/utils/__init__.py +0 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/utils/bitcoin_utils.py +0 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/utils/inscription_utils.py +0 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoinwatcher.egg-info/dependency_links.txt +0 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoinwatcher.egg-info/top_level.txt +0 -0
- {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: bitcoinwatcher
|
3
|
-
Version: 0.
|
3
|
+
Version: 1.0.1
|
4
4
|
Summary: bitcoinwatcher is a Python library that implements a ZMQ subscriber and provides abstractions to build custom address watchers. This library is designed to make it easy for developers to monitor Bitcoin addresses and react to changes in their state.
|
5
5
|
Author: twosatsmaxi
|
6
6
|
License: Apache License
|
@@ -226,6 +226,7 @@ Requires-Dist: requests==2.31.0
|
|
226
226
|
Requires-Dist: six==1.16.0
|
227
227
|
Requires-Dist: urllib3==2.2.1
|
228
228
|
Requires-Dist: bitcoinlib==0.6.14
|
229
|
+
Requires-Dist: ordipool==1.2.0
|
229
230
|
|
230
231
|
# bitcoinwatcher
|
231
232
|
|
@@ -1,10 +1,13 @@
|
|
1
1
|
import dataclasses
|
2
|
+
import os
|
2
3
|
from abc import ABC, abstractmethod
|
3
4
|
from enum import Enum
|
4
5
|
|
5
6
|
from bitcoinlib.transactions import Transaction
|
7
|
+
from ordipool.ordipool.mempoolio import Mempool
|
6
8
|
|
7
9
|
from bitcoin.tx_listener.abstract_tx_listener import AbstractTxListener
|
10
|
+
from bitcoin.utils.constants import default_host
|
8
11
|
|
9
12
|
|
10
13
|
class AddressTxType(Enum):
|
@@ -21,8 +24,6 @@ class AddressTxData:
|
|
21
24
|
_amount: int = 0
|
22
25
|
|
23
26
|
def get_amount(self):
|
24
|
-
if self.type == AddressTxType.INPUT:
|
25
|
-
return "Amount is not supported for input type, yet"
|
26
27
|
return self._amount
|
27
28
|
|
28
29
|
def amount_in_btc(self):
|
@@ -33,6 +34,9 @@ class AddressTxData:
|
|
33
34
|
|
34
35
|
class AbstractAddressListener(AbstractTxListener, ABC):
|
35
36
|
DECIMAL_SCALE = 5
|
37
|
+
host = os.environ.get("RPC_HOST", default_host)
|
38
|
+
base_url = f"http://{host}:3006/api"
|
39
|
+
mempool = Mempool(base_url=base_url)
|
36
40
|
|
37
41
|
def __init__(self, addresses_to_listen: {str}):
|
38
42
|
self.addresses_to_listen = addresses_to_listen
|
@@ -49,14 +53,20 @@ class AbstractAddressListener(AbstractTxListener, ABC):
|
|
49
53
|
|
50
54
|
def on_tx(self, tx: Transaction):
|
51
55
|
# get all address in the inputs and outputs along with the amount
|
52
|
-
|
56
|
+
if tx.coinbase:
|
57
|
+
return
|
53
58
|
outputs = tx.outputs
|
54
59
|
tx_id = tx.txid
|
60
|
+
tx = self.mempool.get_transaction(tx_id)
|
55
61
|
address_tx_data = []
|
56
|
-
|
57
|
-
|
62
|
+
# getting inputs data separately from mempool
|
63
|
+
# as current library doesn't provide rich data like previous outputs and its value
|
64
|
+
for input in tx.vins:
|
65
|
+
address = input.prev_out.address
|
66
|
+
amount = input.prev_out.value
|
58
67
|
address_tx_data.append(AddressTxData(address=address,
|
59
68
|
type=AddressTxType.INPUT,
|
69
|
+
_amount=amount,
|
60
70
|
tx_id=tx_id))
|
61
71
|
for output in outputs:
|
62
72
|
amount = output.value
|
{bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.1}/bitcoin/address_listener/simple_address_listener.py
RENAMED
@@ -7,9 +7,13 @@ class SimpleAddressListener(AbstractAddressListener):
|
|
7
7
|
all_output = list(filter(lambda x: x.type == AddressTxType.OUTPUT and x.address == subscribed_address,
|
8
8
|
address_tx_data))
|
9
9
|
total_amount_in_output = sum(map(lambda x: x.amount_in_btc(), all_output))
|
10
|
+
all_input = list(filter(lambda x: x.type == AddressTxType.INPUT and x.address == subscribed_address,
|
11
|
+
address_tx_data))
|
12
|
+
total_amount_in_input = sum(map(lambda x: x.amount_in_btc(), all_input))
|
10
13
|
# scale ito 4 decimal places
|
11
14
|
total_amount_in_output = round(total_amount_in_output, self.DECIMAL_SCALE)
|
12
15
|
print(f"Address {subscribed_address} received {total_amount_in_output} BTC in tx {address_tx_data[0].tx_id}")
|
16
|
+
print(f"Address {subscribed_address} spent {total_amount_in_input} BTC in tx {address_tx_data[0].tx_id}")
|
13
17
|
|
14
18
|
def __init__(self, addresses_to_listen: {str}):
|
15
19
|
self.addresses = address
|
@@ -26,7 +26,7 @@ class TestAbstractAddressListener(TestCase):
|
|
26
26
|
address_tx_data = address_listener.filter_address_tx_data(input_tx_data)
|
27
27
|
self.assertEqual(len(address_tx_data), 2)
|
28
28
|
self.assertListEqual(sorted(address_tx_data), ["3P4WqXDbSL", "3P4WqXDbSL2"])
|
29
|
-
self.
|
29
|
+
self.assertNotEqual(len(address_tx_data), len(input_tx_data))
|
30
30
|
|
31
31
|
def test_filter_address_tx_data_empty_address_in_input(self):
|
32
32
|
address_listener = DummyAddressListener("3P4WqXDbSL")
|
@@ -41,4 +41,11 @@ class TestAbstractAddressListener(TestCase):
|
|
41
41
|
address_tx_data = address_listener.filter_address_tx_data(output_tx_data)
|
42
42
|
self.assertEqual(len(address_tx_data), 1)
|
43
43
|
self.assertEqual(address_tx_data[0], "3P4WqXDbSL")
|
44
|
-
self.
|
44
|
+
self.assertNotEqual(len(address_tx_data), len(output_tx_data))
|
45
|
+
|
46
|
+
def test_filter_where_its_in_input(self):
|
47
|
+
address_listener = DummyAddressListener("3P4WqXDbSL")
|
48
|
+
input_tx_data = [AddressTxData(tx_id="tx id", address="3P4WqXDbSL", type=AddressTxType.INPUT, _amount=1000)]
|
49
|
+
output_tx_data = [AddressTxData(tx_id="tx id", address="3P4WqXDbSLD", type=AddressTxType.OUTPUT, _amount=1000)]
|
50
|
+
address_tx_data = address_listener.filter_address_tx_data(input_tx_data + output_tx_data)
|
51
|
+
self.assertEqual(len(address_tx_data), 1)
|
@@ -4,9 +4,7 @@ import zmq
|
|
4
4
|
from bitcoinlib.transactions import Transaction
|
5
5
|
|
6
6
|
from bitcoin.tx_listener.abstract_tx_listener import AbstractTxListener
|
7
|
-
|
8
|
-
default_host = "192.168.29.108"
|
9
|
-
default_port = 28333
|
7
|
+
from bitcoin.utils.constants import default_host, default_port
|
10
8
|
|
11
9
|
|
12
10
|
class ZMQTXListener:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: bitcoinwatcher
|
3
|
-
Version: 0.
|
3
|
+
Version: 1.0.1
|
4
4
|
Summary: bitcoinwatcher is a Python library that implements a ZMQ subscriber and provides abstractions to build custom address watchers. This library is designed to make it easy for developers to monitor Bitcoin addresses and react to changes in their state.
|
5
5
|
Author: twosatsmaxi
|
6
6
|
License: Apache License
|
@@ -226,6 +226,7 @@ Requires-Dist: requests==2.31.0
|
|
226
226
|
Requires-Dist: six==1.16.0
|
227
227
|
Requires-Dist: urllib3==2.2.1
|
228
228
|
Requires-Dist: bitcoinlib==0.6.14
|
229
|
+
Requires-Dist: ordipool==1.2.0
|
229
230
|
|
230
231
|
# bitcoinwatcher
|
231
232
|
|
@@ -12,6 +12,7 @@ bitcoin/tx_listener/abstract_tx_listener.py
|
|
12
12
|
bitcoin/tx_listener/zmq_listener.py
|
13
13
|
bitcoin/utils/__init__.py
|
14
14
|
bitcoin/utils/bitcoin_utils.py
|
15
|
+
bitcoin/utils/constants.py
|
15
16
|
bitcoin/utils/inscription_utils.py
|
16
17
|
bitcoinwatcher.egg-info/PKG-INFO
|
17
18
|
bitcoinwatcher.egg-info/SOURCES.txt
|
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
|
5
5
|
|
6
6
|
[project]
|
7
7
|
name = "bitcoinwatcher"
|
8
|
-
version = "0.
|
8
|
+
version = "1.0.1"
|
9
9
|
description = "bitcoinwatcher is a Python library that implements a ZMQ subscriber and provides abstractions to build custom address watchers. This library is designed to make it easy for developers to monitor Bitcoin addresses and react to changes in their state."
|
10
10
|
readme = "README.md"
|
11
11
|
authors = [{name = "twosatsmaxi"}]
|
@@ -31,7 +31,8 @@ dependencies = [
|
|
31
31
|
"requests==2.31.0",
|
32
32
|
"six==1.16.0",
|
33
33
|
"urllib3==2.2.1",
|
34
|
-
"bitcoinlib==0.6.14"
|
34
|
+
"bitcoinlib==0.6.14",
|
35
|
+
"ordipool==1.2.0"
|
35
36
|
]
|
36
37
|
requires-python = ">=3.10"
|
37
38
|
[project.urls]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|