bitcoinwatcher 1.0.1__tar.gz → 1.2.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 (33) hide show
  1. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/PKG-INFO +2 -1
  2. bitcoinwatcher-1.2.0/bitcoin/address_listener/address_listener.py +51 -0
  3. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoin/address_listener/simple_address_listener.py +3 -1
  4. bitcoinwatcher-1.2.0/bitcoin/models/address_tx_data.py +36 -0
  5. bitcoinwatcher-1.2.0/bitcoin/tests/data/transactions.py +5 -0
  6. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoin/tests/test_address_listener.py +4 -2
  7. bitcoinwatcher-1.2.0/bitcoin/tests/test_bitcoin_utils.py +32 -0
  8. bitcoinwatcher-1.2.0/bitcoin/tx_listener/__init__.py +0 -0
  9. bitcoinwatcher-1.2.0/bitcoin/utils/__init__.py +0 -0
  10. bitcoinwatcher-1.2.0/bitcoin/utils/benchmark.py +33 -0
  11. bitcoinwatcher-1.2.0/bitcoin/utils/bitcoin_rpc.py +31 -0
  12. bitcoinwatcher-1.2.0/bitcoin/utils/bitcoin_utils.py +18 -0
  13. bitcoinwatcher-1.2.0/bitcoin/utils/tx_address_data_extractor.py +76 -0
  14. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoinwatcher.egg-info/PKG-INFO +2 -1
  15. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoinwatcher.egg-info/SOURCES.txt +8 -0
  16. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoinwatcher.egg-info/requires.txt +1 -0
  17. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/pyproject.toml +3 -2
  18. bitcoinwatcher-1.0.1/bitcoin/address_listener/address_listener.py +0 -81
  19. bitcoinwatcher-1.0.1/bitcoin/utils/bitcoin_utils.py +0 -16
  20. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/LICENSE +0 -0
  21. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/README.md +0 -0
  22. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoin/__init__.py +0 -0
  23. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoin/address_listener/__init__.py +0 -0
  24. {bitcoinwatcher-1.0.1/bitcoin/tests → bitcoinwatcher-1.2.0/bitcoin/models}/__init__.py +0 -0
  25. {bitcoinwatcher-1.0.1/bitcoin/tx_listener → bitcoinwatcher-1.2.0/bitcoin/tests}/__init__.py +0 -0
  26. {bitcoinwatcher-1.0.1/bitcoin/utils → bitcoinwatcher-1.2.0/bitcoin/tests/data}/__init__.py +0 -0
  27. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoin/tx_listener/abstract_tx_listener.py +0 -0
  28. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoin/tx_listener/zmq_listener.py +0 -0
  29. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoin/utils/constants.py +0 -0
  30. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoin/utils/inscription_utils.py +0 -0
  31. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoinwatcher.egg-info/dependency_links.txt +0 -0
  32. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/bitcoinwatcher.egg-info/top_level.txt +0 -0
  33. {bitcoinwatcher-1.0.1 → bitcoinwatcher-1.2.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bitcoinwatcher
3
- Version: 1.0.1
3
+ Version: 1.2.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
@@ -227,6 +227,7 @@ Requires-Dist: six==1.16.0
227
227
  Requires-Dist: urllib3==2.2.1
228
228
  Requires-Dist: bitcoinlib==0.6.14
229
229
  Requires-Dist: ordipool==1.2.0
230
+ Requires-Dist: python-bitcoinrpc==1.0
230
231
 
231
232
  # bitcoinwatcher
232
233
 
@@ -0,0 +1,51 @@
1
+ import os
2
+ from abc import ABC, abstractmethod
3
+
4
+ from bitcoinlib.transactions import Transaction
5
+ from ordipool.ordipool.mempoolio import Mempool
6
+
7
+ from bitcoin.models.address_tx_data import AddressTxData
8
+ from bitcoin.tx_listener.abstract_tx_listener import AbstractTxListener
9
+ from bitcoin.utils.constants import default_host
10
+ from bitcoin.utils.tx_address_data_extractor import DefaultTxAddressDataExtractor, MempoolTxAddressDataExtractor
11
+
12
+
13
+ class AbstractAddressListener(AbstractTxListener, ABC):
14
+ DECIMAL_SCALE = 5
15
+ host = os.environ.get("RPC_HOST", default_host)
16
+ base_url = f"http://{host}:3006/api"
17
+ mempool = Mempool(base_url=base_url)
18
+ default_tx_extractor = DefaultTxAddressDataExtractor()
19
+ mempool_tx_extractor = MempoolTxAddressDataExtractor(mempool)
20
+
21
+ def __init__(self, addresses_to_listen: {str}):
22
+ self.addresses_to_listen = addresses_to_listen
23
+
24
+ @abstractmethod
25
+ def consume(self, subscribed_address, address_tx_data: [AddressTxData]):
26
+ pass
27
+
28
+ def filter_address_tx_data(self, address_tx_data: [AddressTxData]) -> [str]:
29
+ filtered_address_tx_data = list(filter(lambda x: x.address in self.addresses_to_listen and x.address != "",
30
+ address_tx_data))
31
+ # get all address
32
+ return list(set((map(lambda x: x.address, filtered_address_tx_data))))
33
+
34
+ def on_tx(self, tx: Transaction):
35
+ # get all address in the inputs and outputs along with the amount
36
+ if tx.coinbase:
37
+ return
38
+ address_tx_data = self.default_tx_extractor.extract(tx)
39
+ # filter the address we are interested in
40
+ addresses_for_events = self.filter_address_tx_data(address_tx_data)
41
+ if len(addresses_for_events) == 0:
42
+ return
43
+ # get the address tx data from mempool for full details if any address matches
44
+ try:
45
+ address_tx_data = self.mempool_tx_extractor.extract(tx)
46
+ except Exception as e:
47
+ print(f"Error in getting mempool tx data, taking defaults: {e}")
48
+ address_tx_data = address_tx_data
49
+
50
+ for address in addresses_for_events:
51
+ self.consume(subscribed_address=address, address_tx_data=address_tx_data)
@@ -1,4 +1,5 @@
1
- from bitcoin.address_listener.address_listener import AbstractAddressListener, AddressTxData, AddressTxType
1
+ from bitcoin.address_listener.address_listener import AbstractAddressListener, AddressTxData
2
+ from bitcoin.models.address_tx_data import AddressTxType
2
3
  from bitcoin.tx_listener.zmq_listener import ZMQTXListener
3
4
 
4
5
 
@@ -11,6 +12,7 @@ class SimpleAddressListener(AbstractAddressListener):
11
12
  address_tx_data))
12
13
  total_amount_in_input = sum(map(lambda x: x.amount_in_btc(), all_input))
13
14
  # scale ito 4 decimal places
15
+ print("Transaction status: ", address_tx_data[0].tx_status)
14
16
  total_amount_in_output = round(total_amount_in_output, self.DECIMAL_SCALE)
15
17
  print(f"Address {subscribed_address} received {total_amount_in_output} BTC in tx {address_tx_data[0].tx_id}")
16
18
  print(f"Address {subscribed_address} spent {total_amount_in_input} BTC in tx {address_tx_data[0].tx_id}")
@@ -0,0 +1,36 @@
1
+ import dataclasses
2
+ from enum import Enum
3
+
4
+
5
+ class AddressTxType(Enum):
6
+ INPUT = "input"
7
+ OUTPUT = "output"
8
+
9
+
10
+ class AddressTxSource(Enum):
11
+ MEMPOOL = "mempool"
12
+ DEFAULT = "default"
13
+
14
+
15
+ class TransactionStatus(Enum):
16
+ UNCONFIRMED = "unconfirmed"
17
+ CONFIRMED = "confirmed"
18
+
19
+
20
+ @dataclasses.dataclass
21
+ class AddressTxData:
22
+ tx_id: str
23
+ address: str
24
+ type: AddressTxType
25
+ # figure out the way to get amount in vin
26
+ _amount: int = 0
27
+ tx_status: str = "unconfirmed"
28
+ is_reveal_tx: bool = False
29
+
30
+ def get_amount(self):
31
+ return self._amount
32
+
33
+ def amount_in_btc(self):
34
+ if self.type == AddressTxType.INPUT:
35
+ return "Amount is not supported for input type, yet"
36
+ return self._amount / 100000000