bitcoinwatcher 0.1.3__py3-none-any.whl → 0.1.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.
- bitcoin/address_listener/address_listener.py +14 -5
- bitcoin/address_listener/simple_address_listener.py +19 -9
- bitcoin/tests/test_address_listener.py +36 -0
- {bitcoinwatcher-0.1.3.dist-info → bitcoinwatcher-0.1.6.dist-info}/METADATA +1 -3
- {bitcoinwatcher-0.1.3.dist-info → bitcoinwatcher-0.1.6.dist-info}/RECORD +8 -7
- {bitcoinwatcher-0.1.3.dist-info → bitcoinwatcher-0.1.6.dist-info}/LICENSE +0 -0
- {bitcoinwatcher-0.1.3.dist-info → bitcoinwatcher-0.1.6.dist-info}/WHEEL +0 -0
- {bitcoinwatcher-0.1.3.dist-info → bitcoinwatcher-0.1.6.dist-info}/top_level.txt +0 -0
@@ -32,13 +32,21 @@ class AddressTxData:
|
|
32
32
|
|
33
33
|
|
34
34
|
class AbstractAddressListener(AbstractTxListener, ABC):
|
35
|
-
|
36
|
-
|
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
|
-
|
62
|
-
|
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)
|
@@ -1,13 +1,23 @@
|
|
1
1
|
from bitcoin.address_listener.address_listener import AbstractAddressListener, AddressTxData, AddressTxType
|
2
|
+
from bitcoin.tx_listener.zmq_listener import ZMQTXListener
|
2
3
|
|
3
4
|
|
4
5
|
class SimpleAddressListener(AbstractAddressListener):
|
5
|
-
def consume(self, address_tx_data: [AddressTxData]):
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
+
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
|
@@ -1,16 +1,17 @@
|
|
1
1
|
bitcoin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
bitcoin/address_listener/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
bitcoin/address_listener/address_listener.py,sha256=
|
4
|
-
bitcoin/address_listener/simple_address_listener.py,sha256=
|
3
|
+
bitcoin/address_listener/address_listener.py,sha256=Tn-oCZrFaGdI8k9F-t3hPIKdbAV95tUysY8s7MPiDQs,2535
|
4
|
+
bitcoin/address_listener/simple_address_listener.py,sha256=fHF2HH_c1-ioQMhs5QauHyGT-eDjyxGl8hTeB39_yIs,1145
|
5
5
|
bitcoin/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
bitcoin/tests/test_address_listener.py,sha256=K9ltdDGoz60KoDimWQ4tXuQ8KxPJDkQOvHnHUtXPh6w,1966
|
6
7
|
bitcoin/tx_listener/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
8
|
bitcoin/tx_listener/abstract_tx_listener.py,sha256=rGp9na-aOSl_aPaIqf44RTZaFF3SvrxIhZBujTnWqao,189
|
8
9
|
bitcoin/tx_listener/zmq_listener.py,sha256=rKqYMPZOHq-WR0cL_Ucmwr0AfIpHbsLvOxfTpBjOyI4,990
|
9
10
|
bitcoin/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
11
|
bitcoin/utils/bitcoin_utils.py,sha256=ehzfwiuln_lPia6urtUSVE3zXC1zyZEKiNM36e7N00k,428
|
11
12
|
bitcoin/utils/inscription_utils.py,sha256=8QbOJ1o1n1bMFsPREGLzwFjnGzfuARgJCPr6ORhP44o,193
|
12
|
-
bitcoinwatcher-0.1.
|
13
|
-
bitcoinwatcher-0.1.
|
14
|
-
bitcoinwatcher-0.1.
|
15
|
-
bitcoinwatcher-0.1.
|
16
|
-
bitcoinwatcher-0.1.
|
13
|
+
bitcoinwatcher-0.1.6.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
14
|
+
bitcoinwatcher-0.1.6.dist-info/METADATA,sha256=9Rvmep2jqL6OMv5T2a1FayompiGbmyFLihrkl0xQ8cM,14869
|
15
|
+
bitcoinwatcher-0.1.6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
16
|
+
bitcoinwatcher-0.1.6.dist-info/top_level.txt,sha256=YdUgzLdCiMlrwaKyDqHA1acEd23QFko5bv7D6nBANJ0,8
|
17
|
+
bitcoinwatcher-0.1.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|