bitcoinwatcher 0.2.0__tar.gz → 1.0.0__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.2.0 → bitcoinwatcher-1.0.0}/PKG-INFO +2 -1
  2. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoin/address_listener/address_listener.py +15 -3
  3. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoin/address_listener/simple_address_listener.py +4 -0
  4. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoin/tests/test_address_listener.py +9 -2
  5. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoin/tx_listener/zmq_listener.py +1 -3
  6. bitcoinwatcher-1.0.0/bitcoin/utils/constants.py +2 -0
  7. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoinwatcher.egg-info/PKG-INFO +2 -1
  8. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoinwatcher.egg-info/SOURCES.txt +1 -0
  9. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoinwatcher.egg-info/requires.txt +1 -0
  10. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/pyproject.toml +3 -2
  11. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/LICENSE +0 -0
  12. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/README.md +0 -0
  13. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoin/__init__.py +0 -0
  14. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoin/address_listener/__init__.py +0 -0
  15. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoin/tests/__init__.py +0 -0
  16. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoin/tx_listener/__init__.py +0 -0
  17. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoin/tx_listener/abstract_tx_listener.py +0 -0
  18. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoin/utils/__init__.py +0 -0
  19. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoin/utils/bitcoin_utils.py +0 -0
  20. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoin/utils/inscription_utils.py +0 -0
  21. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoinwatcher.egg-info/dependency_links.txt +0 -0
  22. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/bitcoinwatcher.egg-info/top_level.txt +0 -0
  23. {bitcoinwatcher-0.2.0 → bitcoinwatcher-1.0.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bitcoinwatcher
3
- Version: 0.2.0
3
+ Version: 1.0.0
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):
@@ -33,6 +36,9 @@ class AddressTxData:
33
36
 
34
37
  class AbstractAddressListener(AbstractTxListener, ABC):
35
38
  DECIMAL_SCALE = 5
39
+ host = os.environ.get("RPC_HOST", default_host)
40
+ base_url = f"http://{host}:3006/api"
41
+ mempool = Mempool(base_url=base_url)
36
42
 
37
43
  def __init__(self, addresses_to_listen: {str}):
38
44
  self.addresses_to_listen = addresses_to_listen
@@ -49,14 +55,20 @@ class AbstractAddressListener(AbstractTxListener, ABC):
49
55
 
50
56
  def on_tx(self, tx: Transaction):
51
57
  # get all address in the inputs and outputs along with the amount
52
- inputs = tx.inputs
58
+ if tx.coinbase:
59
+ return
53
60
  outputs = tx.outputs
54
61
  tx_id = tx.txid
62
+ tx = self.mempool.get_transaction(tx_id)
55
63
  address_tx_data = []
56
- for input in inputs:
57
- address = input.address
64
+ # getting inputs data separately from mempool
65
+ # as current library doesn't provide rich data like previous outputs and its value
66
+ for input in tx.vins:
67
+ address = input.prev_out.address
68
+ amount = input.prev_out.value
58
69
  address_tx_data.append(AddressTxData(address=address,
59
70
  type=AddressTxType.INPUT,
71
+ _amount=amount,
60
72
  tx_id=tx_id))
61
73
  for output in outputs:
62
74
  amount = output.value
@@ -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.assertNotEquals(len(address_tx_data), len(input_tx_data))
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.assertNotEquals(len(address_tx_data), len(output_tx_data))
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:
@@ -0,0 +1,2 @@
1
+ default_host = "192.168.29.108"
2
+ default_port = 28333
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bitcoinwatcher
3
- Version: 0.2.0
3
+ Version: 1.0.0
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
@@ -7,3 +7,4 @@ requests==2.31.0
7
7
  six==1.16.0
8
8
  urllib3==2.2.1
9
9
  bitcoinlib==0.6.14
10
+ ordipool==1.2.0
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "bitcoinwatcher"
8
- version = "0.2.0"
8
+ version = "1.0.0"
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