bitcoinwatcher 0.1.3__tar.gz → 0.1.6__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.
Files changed (23) hide show
  1. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/PKG-INFO +1 -3
  2. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoin/address_listener/address_listener.py +14 -5
  3. bitcoinwatcher-0.1.6/bitcoin/address_listener/simple_address_listener.py +23 -0
  4. bitcoinwatcher-0.1.6/bitcoin/tests/test_address_listener.py +36 -0
  5. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoinwatcher.egg-info/PKG-INFO +1 -3
  6. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoinwatcher.egg-info/SOURCES.txt +1 -0
  7. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoinwatcher.egg-info/requires.txt +0 -2
  8. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/pyproject.toml +1 -3
  9. bitcoinwatcher-0.1.3/bitcoin/address_listener/simple_address_listener.py +0 -13
  10. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/LICENSE +0 -0
  11. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/README.md +0 -0
  12. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoin/__init__.py +0 -0
  13. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoin/address_listener/__init__.py +0 -0
  14. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoin/tests/__init__.py +0 -0
  15. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoin/tx_listener/__init__.py +0 -0
  16. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoin/tx_listener/abstract_tx_listener.py +0 -0
  17. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoin/tx_listener/zmq_listener.py +0 -0
  18. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoin/utils/__init__.py +0 -0
  19. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoin/utils/bitcoin_utils.py +0 -0
  20. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoin/utils/inscription_utils.py +0 -0
  21. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoinwatcher.egg-info/dependency_links.txt +0 -0
  22. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/bitcoinwatcher.egg-info/top_level.txt +0 -0
  23. {bitcoinwatcher-0.1.3 → bitcoinwatcher-0.1.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bitcoinwatcher
3
- Version: 0.1.3
3
+ Version: 0.1.6
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
@@ -221,8 +221,6 @@ Requires-Dist: requests~=2.31.0
221
221
  Requires-Dist: certifi==2024.2.2
222
222
  Requires-Dist: charset-normalizer==3.3.2
223
223
  Requires-Dist: idna==3.6
224
- Requires-Dist: ordipool==1.1.1
225
- Requires-Dist: PyGObject==3.46.0
226
224
  Requires-Dist: pyzmq==25.1.2
227
225
  Requires-Dist: requests==2.31.0
228
226
  Requires-Dist: six==1.16.0
@@ -32,13 +32,21 @@ class AddressTxData:
32
32
 
33
33
 
34
34
  class AbstractAddressListener(AbstractTxListener, ABC):
35
- def __init__(self, address_to_listen: [str]):
36
- self.address_to_listen = address_to_listen
35
+ DECIMAL_SCALE = 5
36
+
37
+ def __init__(self, addresses_to_listen: {str}):
38
+ self.addresses_to_listen = addresses_to_listen
37
39
 
38
40
  @abstractmethod
39
- def consume(self, address_tx_data: [AddressTxData]):
41
+ def consume(self, subscribed_address, address_tx_data: [AddressTxData]):
40
42
  pass
41
43
 
44
+ def filter_address_tx_data(self, address_tx_data: [AddressTxData]) -> [str]:
45
+ filtered_address_tx_data = list(filter(lambda x: x.address in self.addresses_to_listen and x.address != "",
46
+ address_tx_data))
47
+ # get all address
48
+ return list(map(lambda x: x.address, filtered_address_tx_data))
49
+
42
50
  def on_tx(self, tx: Transaction):
43
51
  # get all address in the inputs and outputs along with the amount
44
52
  inputs = tx.inputs
@@ -58,5 +66,6 @@ class AbstractAddressListener(AbstractTxListener, ABC):
58
66
  tx_id=tx_id))
59
67
 
60
68
  # filter the address we are interested in
61
- address_tx_data = list(filter(lambda x: x.address in self.address_to_listen, address_tx_data))
62
- self.consume(address_tx_data)
69
+ addresses_for_events = self.filter_address_tx_data(address_tx_data)
70
+ for address in addresses_for_events:
71
+ self.consume(subscribed_address=address, address_tx_data=address_tx_data)
@@ -0,0 +1,23 @@
1
+ from bitcoin.address_listener.address_listener import AbstractAddressListener, AddressTxData, AddressTxType
2
+ from bitcoin.tx_listener.zmq_listener import ZMQTXListener
3
+
4
+
5
+ class SimpleAddressListener(AbstractAddressListener):
6
+ def consume(self, subscribed_address, address_tx_data: [AddressTxData]):
7
+ all_output = list(filter(lambda x: x.type == AddressTxType.OUTPUT and x.address == subscribed_address,
8
+ address_tx_data))
9
+ total_amount_in_output = sum(map(lambda x: x.amount_in_btc(), all_output))
10
+ # scale ito 4 decimal places
11
+ total_amount_in_output = round(total_amount_in_output, self.DECIMAL_SCALE)
12
+ print(f"Address {subscribed_address} received {total_amount_in_output} BTC in tx {address_tx_data[0].tx_id}")
13
+
14
+ def __init__(self, addresses_to_listen: {str}):
15
+ self.addresses = address
16
+ super().__init__(addresses_to_listen=addresses_to_listen)
17
+
18
+
19
+ if __name__ == '__main__':
20
+ address = ["3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ"]
21
+ address_watcher = SimpleAddressListener(address)
22
+ zmq_listener = ZMQTXListener(address_watcher)
23
+ zmq_listener.start()
@@ -0,0 +1,36 @@
1
+ from unittest import TestCase
2
+
3
+ from bitcoin.address_listener.address_listener import AbstractAddressListener, AddressTxData, AddressTxType
4
+
5
+
6
+ class DummyAddressListener(AbstractAddressListener):
7
+ def consume(self, address_tx_data):
8
+ pass
9
+
10
+ def __init__(self, address_to_listen: [str]):
11
+ super().__init__(address_to_listen)
12
+
13
+
14
+ class TestAbstractAddressListener(TestCase):
15
+ def test_filter_address_tx_data_one_address(self):
16
+ address_listener = DummyAddressListener("3P4WqXDbSL")
17
+ input_tx_data = [AddressTxData(tx_id="tx id", address="3P4WqXDbSL", type= AddressTxType.OUTPUT, _amount=1000)]
18
+ address_tx_data = address_listener.filter_address_tx_data(input_tx_data)
19
+ self.assertEqual(len(address_tx_data), len(input_tx_data))
20
+
21
+ def test_filter_address_tx_data_multiple_addresses(self):
22
+ address_listener = DummyAddressListener(["3P4WqXDbSL", "3P4WqXDbSL2"])
23
+ input_tx_data = [AddressTxData(tx_id="tx id", address="3P4WqXDbSL", type= AddressTxType.OUTPUT, _amount=1000),
24
+ AddressTxData(tx_id="tx id", address="3P4WqXDbSL2", type= AddressTxType.OUTPUT, _amount=1000),
25
+ AddressTxData(tx_id="tx id", address="3P4WqXDbSL3", type= AddressTxType.OUTPUT, _amount=1000)]
26
+ address_tx_data = address_listener.filter_address_tx_data(input_tx_data)
27
+ self.assertEqual(len(address_tx_data), 2)
28
+ self.assertEqual(address_tx_data[0], "3P4WqXDbSL")
29
+ self.assertEqual(address_tx_data[1], "3P4WqXDbSL2")
30
+ self.assertNotEquals(len(address_tx_data), len(input_tx_data))
31
+
32
+ def test_filter_address_tx_data_empty_address_in_input(self):
33
+ address_listener = DummyAddressListener("3P4WqXDbSL")
34
+ input_tx_data = [AddressTxData(tx_id="tx id", address="", type= AddressTxType.OUTPUT, _amount=1000)]
35
+ address_tx_data = address_listener.filter_address_tx_data(input_tx_data)
36
+ self.assertEqual(len(address_tx_data), 0)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bitcoinwatcher
3
- Version: 0.1.3
3
+ Version: 0.1.6
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
@@ -221,8 +221,6 @@ Requires-Dist: requests~=2.31.0
221
221
  Requires-Dist: certifi==2024.2.2
222
222
  Requires-Dist: charset-normalizer==3.3.2
223
223
  Requires-Dist: idna==3.6
224
- Requires-Dist: ordipool==1.1.1
225
- Requires-Dist: PyGObject==3.46.0
226
224
  Requires-Dist: pyzmq==25.1.2
227
225
  Requires-Dist: requests==2.31.0
228
226
  Requires-Dist: six==1.16.0
@@ -6,6 +6,7 @@ bitcoin/address_listener/__init__.py
6
6
  bitcoin/address_listener/address_listener.py
7
7
  bitcoin/address_listener/simple_address_listener.py
8
8
  bitcoin/tests/__init__.py
9
+ bitcoin/tests/test_address_listener.py
9
10
  bitcoin/tx_listener/__init__.py
10
11
  bitcoin/tx_listener/abstract_tx_listener.py
11
12
  bitcoin/tx_listener/zmq_listener.py
@@ -2,8 +2,6 @@ requests~=2.31.0
2
2
  certifi==2024.2.2
3
3
  charset-normalizer==3.3.2
4
4
  idna==3.6
5
- ordipool==1.1.1
6
- PyGObject==3.46.0
7
5
  pyzmq==25.1.2
8
6
  requests==2.31.0
9
7
  six==1.16.0
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "bitcoinwatcher"
8
- version = "0.1.3"
8
+ version = "0.1.6"
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"}]
@@ -27,8 +27,6 @@ dependencies = [
27
27
  "certifi==2024.2.2",
28
28
  "charset-normalizer==3.3.2",
29
29
  "idna==3.6",
30
- "ordipool==1.1.1",
31
- "PyGObject==3.46.0",
32
30
  "pyzmq==25.1.2",
33
31
  "requests==2.31.0",
34
32
  "six==1.16.0",
@@ -1,13 +0,0 @@
1
- from bitcoin.address_listener.address_listener import AbstractAddressListener, AddressTxData, AddressTxType
2
-
3
-
4
- class SimpleAddressListener(AbstractAddressListener):
5
- def consume(self, address_tx_data: [AddressTxData]):
6
- for address_tx in address_tx_data:
7
- if address_tx.type == AddressTxType.OUTPUT:
8
- print(
9
- f"Address {address_tx.address} received {address_tx.amount_in_btc()} BTC in tx {address_tx.tx_id}")
10
-
11
- def __init__(self, address):
12
- self.address = address
13
- super().__init__(address_to_listen=[address])
File without changes
File without changes
File without changes