<reponame>QuantumMeme/coincurve<gh_stars>0
import sys
import json
import bluetooth
import time
import rfcomm

'''
TODO:
    - replace bad while loop thing with async
    - rewrite in terms of async for when this grows
'''


def qgenerate(numsize):
    
    print("Creating server to recieve nums")
    server = rfcomm.openServer("c96eeb08-56b7-11ec-bf63-0242ac130002")


    print("connecting to QRNG...") 
    while True:
        try: # B8:27:EB:CF:AD:38
            client = rfcomm.openClient("B8:27:EB:CF:AD:38", "573ef5ec-0e34-4182-bf1e-18a9b36364f2")
        except Exception as e:
            print(e)
            pass
        else:
            break
        time.sleep(1)


    msg = {
        "key":1,
        "size":numsize
        }
    
    msgjson = json.dumps(msg).encode("utf-8")
    print("sending request for number...")
    rfcomm.sendOne(client, msgjson)

    
    time.sleep(3)
    
    num = rfcomm.serverConnect(server)
    
    return bytes(int(num))
import sys
import json
import bluetooth
import time
import rfcomm

'''
TODO:
    - replace bad while loop thing with async
    - rewrite in terms of async for when this grows
'''


def qgenerate(numsize):
    
    print("Creating server to recieve nums")
    server = rfcomm.openServer("c96eeb08-56b7-11ec-bf63-0242ac130002")


    print("connecting to QRNG...") 
    while True:
        try: # B8:27:EB:CF:AD:38
            client = rfcomm.openClient("B8:27:EB:CF:AD:38", "573ef5ec-0e34-4182-bf1e-18a9b36364f2")
        except Exception as e:
            print(e)
            pass
        else:
            break
        time.sleep(1)


    msg = {
        "key":1,
        "size":numsize
        }
    
    msgjson = json.dumps(msg).encode("utf-8")
    print("sending request for number...")
    rfcomm.sendOne(client, msgjson)

    
    time.sleep(3)
    
    num = rfcomm.serverConnect(server)
    
    return bytes(int(num))
TODO:     - replace bad while loop thing with async     - rewrite in terms of async for when this grows # B8:27:EB:CF:AD:38