-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtx_generator.py
36 lines (26 loc) · 920 Bytes
/
tx_generator.py
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
import logging
import os
from random import randint
from time import sleep
from kafka import KafkaProducer
from entry import hash_transactions
from poh_recorder import Record, Transaction
def start(producer):
while True:
txs = [generate_random_tx() for i in range(randint(1, 10))]
txs_hash = hash_transactions(txs)
record = Record(txs_hash, txs, 1)
producer.send("record", record.to_json().encode())
producer.flush()
logging.info(f"Sent: {record}")
sleep(randint(1, 20) / 10)
def generate_random_tx():
return Transaction(
[f"sig{randint(0, 1000)}" for _ in range(randint(1, 7))],
f"msg{randint(0, 100)}",
)
if __name__ == "__main__":
sleep(int(os.environ["WAIT_TIME"]))
logging.basicConfig(level=logging.INFO)
producer = KafkaProducer(bootstrap_servers=os.getenv("KAFKA_SERVER", "kafka:9093"))
start(producer)