Repository navigation
Expand file tree
/
Copy pathreceive.py
More file actions
62 lines (48 loc) · 1.52 KB
/
Copy pathreceive.py
File metadata and controls
62 lines (48 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python3
import aprslib
import codecs
import base64
messages = {}
max_messages = {}
def process_transaction(callsign):
if callsign not in messages:
return false
txn_base64 = ''
for i in messages[callsign]:
txn_base64 += messages[callsign][i]
txn_hex = codecs.encode(base64.standard_b64decode(txn_base64[0:-1]), 'hex')
print(txn_hex)
# TODO: submit txn to bitcoin network
del messages[callsign]
del max_messages[callsign]
return True
def callback(packet):
if set(['msgNo', 'from', 'message_text']).issubset(packet):
if packet['from'] not in messages:
messages.update({
packet['from']: {
packet['msgNo']: packet['message_text']
}
})
else:
messages[packet['from']].update({
packet['msgNo']: packet['message_text']
})
else:
return False
num_messages = len(messages[packet['from']])
if packet['message_text'].endswith('$'):
max_messages.update({
packet['from']: packet['msgNo']
})
print("Found last message: %s" % packet['msgNo'])
if packet['from'] in max_messages:
print("We have {x} of {y} messages".format(x=num_messages, y=max_messages[packet['from']]))
else:
print("We have {x} of at least {y} messages".format(x=num_messages, y=packet['msgNo']))
if packet['from'] in max_messages and num_messages == max_messages[packet['from']]:
process_transaction(packet['from'])
AIS = aprslib.IS("N0CALL", host="localhost", port=14580)
AIS.connect()
AIS.set_filter('g/BITCOIN')
AIS.consumer(callback)