def clientTranSubmit():
    content = request.json
    try:
        uid = decryptData(PRIVATE_KEY, content['uid'])
        status = decryptData(PRIVATE_KEY, content['status'])
        if status == "1":
            setVoteCount(uid, getVoteCount(uid) + 1)
        if calScore(uid) == True and str(getFlag(uid)) == "0":
            addToBlockChain(uid)

        #call others here
        ll = retrieveNodeList()
        for i in ll:
            try:
                TEMP_KEY = "keys/tempKey.pem"
                saveKeyinFile(TEMP_KEY, i.publicKey)
                data = {}
                data["uid"] = encryptData(TEMP_KEY, uid)
                data["status"] = encryptData(TEMP_KEY, status)
                rr = requests.post(i.ip + BASE_API + '/nodeTranSubmit',
                                   json=data)
            except Exception as e:
                print(e)
        return jsonify({"code": 0, "status": "OK Got IT"})
    except Exception as e:
        print(e)
        return jsonify({"code": 1, "status": "Something Went Wrong"})
Exemplo n.º 2
0
def voteTransaction(uid):
    data = {}
    data["uid"] = encryptData(PUBLIC_KEY, uid)
    data["status"] = encryptData(PUBLIC_KEY, "1")
    r = requests.post(url=API_ENDPOINT + "/clientTranSubmit", json=data)

    print(r.json())
def submitTransaction():
    content = request.json
    try:
        transaction = decryptData(PRIVATE_KEY, content['transaction'])
        proposingNode = getName()
        blockindex = getLastIndex()
        timeStamp = str(datetime.datetime.now())
        uid = str(uuid.uuid4())
        addPendingTransaction(uid, proposingNode, transaction, blockindex,
                              timeStamp)
        ll = retrieveNodeList()
        for i in ll:
            try:
                TEMP_KEY = "keys/tempKey.pem"
                saveKeyinFile(TEMP_KEY, i.publicKey)
                data = {}
                data["transaction"] = encryptData(TEMP_KEY, transaction)
                data["proposingNode"] = encryptData(TEMP_KEY, proposingNode)
                data["blockindex"] = encryptData(TEMP_KEY, blockindex)
                data["timeStamp"] = encryptData(TEMP_KEY, timeStamp)
                data["uid"] = encryptData(TEMP_KEY, uid)
                rr = requests.post(i.ip + BASE_API + '/getTransaction',
                                   json=data)
            except Exception as e:
                print(e)
        return jsonify({
            "code": 0,
            "status": "Transaction is submitted to client",
            "uid": uid
        })
    except Exception as e:
        print(e)
        return jsonify({"code": 1, "status": "Something Went Wrong"})
def addNodeRequest():
    content = request.json
    try:
        print("in request")
        name = decryptData(PRIVATE_KEY, content['name'])
        ipaddr = decryptData(PRIVATE_KEY, content['ipaddr'])
        publicKey = content['publicKey']
        companyName = decryptData(PRIVATE_KEY, content['companyName'])
        companyID = decryptData(PRIVATE_KEY, content['companyID'])
        #verify if the node doesn't exist?
        addNodes(name, ipaddr, publicKey)
        ll = getAllClients()
        for i in ll:
            try:
                TEMP_KEY = "keys/tempKey.pem"
                saveKeyinFile(TEMP_KEY, i.publicKey)
                data = {}
                data["name"] = encryptData(TEMP_KEY, name)
                data["companyName"] = encryptData(TEMP_KEY, companyName)
                data["companyID"] = encryptData(TEMP_KEY, companyID)
                try:
                    rr = requests.post(i.callback_URL + '/addNode', json=data)
                except Exception as e:
                    print(e)
            except Exception as e:
                print(e)
        return jsonify({"code": 0, "status": "Node added"})
    except:
        return jsonify({"code": 1, "status": "Something Went Wrong here"})
Exemplo n.º 5
0
def submit_vote(uid, status):
    data = {}
    trans = {}
    data["uid"]  = encryptData(nodePublicKey_path, uid)
    data["status"]  = encryptData(nodePublicKey_path, str(status))
    response = requests.post(url=BASE_URL + "/clientTranSubmit", json=data)
    response = response.json()
    return response["code"], response["status"]
Exemplo n.º 6
0
def testCode1(uid):
    data = {}
    trans = {}
    trans["name"] = "amey"
    data["uid"] = encryptData(PUBLIC_KEY, uid)
    data["status"] = encryptData(PUBLIC_KEY, "1")
    r = requests.post(url=API_ENDPOINT + "/clientTranSubmit", json=data)

    print(r.json())
def setCredential():
    data = {}
    # data['name'] = encryptData(PUBLIC_KEY, input("Set A Name To Node : "))
    data['username'] = encryptData(PUBLIC_KEY, input("Set username : "******"Set password : "******"confirm password : "******"createUser", json=data)
        print(newR.json())
    else:
        print("Password Mismatch try again")
def joinBlockchain():
    content = request.form
    f = request.files['file']
    f.save(secure_filename(f.filename))
    json_data = open(f.filename, 'r').read()
    # json_data = json.dumps(json_data)
    json_data = eval(json_data)
    print(type(json_data))
    try:
        print(content)
        nodes = json_data['nodes']
        print(nodes)
        # new_content = content["new_node_data"]
        # name = decryptData(PRIVATE_KEY, new_content['name'])
        # ipaddr = decryptData(PRIVATE_KEY, new_content['ipaddr'])
        # info = decryptData(PRIVATE_KEY, new_content['info'])
        # companyName = decryptData(PRIVATE_KEY, new_content['companyName'])
        # companyID = decryptData(PRIVATE_KEY, new_content['companyID'])
        name = content["name"]
        ipaddr = content["ipaddr"]
        info = content["info"]
        companyName = content["companyName"]
        companyID = content["companyID"]

        publicKey = str(open(PUBLIC_KEY, 'r').read())
        setBlockChain(name, ipaddr, info)
        print(nodes)
        z = 0
        for i in nodes:
            TEMP_KEY = "keys/tempKey.pem"
            saveKeyinFile(TEMP_KEY, i["publicKey"])
            data = {}
            addNodes(i["name"], i["ipaddr"], i["publicKey"])
            z = z + 1
            data["name"] = encryptData(TEMP_KEY, name)
            data["ipaddr"] = encryptData(TEMP_KEY, ipaddr)
            data["publicKey"] = publicKey
            data["companyName"] = encryptData(TEMP_KEY, companyName)
            data["companyID"] = encryptData(TEMP_KEY, companyID)
            URL = "http://" + str(i["ipaddr"]) + BASE_API + "/nodeRequest"
            print(URL)
            try:
                rr = requests.post(URL, json=data)
                print(rr.json())
            except Exception as e:
                print(e)
        setInit()
        return jsonify({"code": 0, "status": "Joined to blockchain"})
    except Exception as e:
        print(e)
        return jsonify({"code": 1, "status": "Something Went Wrong"})
Exemplo n.º 9
0
def testCode():
    data = {}
    trans = {}
    trans["name"] = "amey"
    data["transaction"] = encryptData(PUBLIC_KEY, json.dumps(trans))

    r = requests.post(url=API_ENDPOINT + "/submitTransaction", json=data)

    print(r.json())
def getTransaction():
    content = request.json
    try:
        proposingNode = decryptData(PRIVATE_KEY, content['proposingNode'])
        transaction = decryptData(PRIVATE_KEY, content['transaction'])
        blockindex = decryptData(PRIVATE_KEY, content['blockindex'])
        timeStamp = decryptData(PRIVATE_KEY, content['timeStamp'])
        uid = decryptData(PRIVATE_KEY, content['uid'])
        addPendingTransaction(uid, proposingNode, transaction, blockindex,
                              timeStamp)
        #call client for transaction strucutre check
        ll = getAllClients()
        for i in ll:
            try:
                TEMP_KEY = "keys/tempKey.pem"
                saveKeyinFile(TEMP_KEY, i.publicKey)
                data = {}
                data["transaction"] = encryptData(TEMP_KEY, transaction)
                data["proposingNode"] = encryptData(TEMP_KEY, proposingNode)
                data["blockindex"] = encryptData(TEMP_KEY, blockindex)
                data["uid"] = encryptData(TEMP_KEY, uid)
                rr = requests.post(i.callback_URL + '/addTransaction',
                                   json=data)
            except Exception as e:
                print(e)
        ##
        #save in pending db

        #call client for verify
        return jsonify({
            "code": 0,
            "status": "Transaction is submitted to client"
        })
    except Exception as e:
        print(e)
        return jsonify({"code": 1, "status": "Something Went Wrong"})
Exemplo n.º 11
0
def addTransaction():
    data = {}
    global ll
    trans = {}
    key = str(input("Enter Key : "))
    val = str(input("Enter Value : "))
    trans[key] = val
    data["transaction"] = encryptData(PUBLIC_KEY, json.dumps(trans))

    r = requests.post(url=API_ENDPOINT + "/submitTransaction", json=data)

    print(r.json())
    r = r.json()
    ll.append(r["uid"])
    return r["uid"]
Exemplo n.º 12
0
def addTransaction():
    #home page basically add transaction
    #implement both get and post method
    if request.method == 'POST':
        content = request.form
        save_node_publicKey()
        print(content)
        data = {}
        trans = {}
        trans = content
        print(trans)
        data["transaction"]  = encryptData(PUBLIC_KEY, json.dumps(trans))
        try:
            r = requests.post(url=BASE_URL + "/submitTransaction", json=data)
            print(r.json())
        except Exception as e:
            print(e)
        return redirect('/pending')
    else:
        return render_template('addTransaction.html')
def setBlockChain():
    new = input("1. Set a new Blockchain\n2. Join Existing\n")
    if str(new) == "1":
        data = {}
        data['nodeName'] = encryptData(PUBLIC_KEY,
                                       input("Set A Name To Node : "))
        data['name'] = encryptData(PUBLIC_KEY,
                                   input("Set A Name To BlockChain : "))
        data['ipaddr'] = encryptData(PUBLIC_KEY, input("IPAddr With Port : "))
        data['info'] = encryptData(PUBLIC_KEY,
                                   input("Info about Blockchain : "))
        data["companyName"] = encryptData(PUBLIC_KEY,
                                          input("Enter Company name : "))
        data["companyID"] = encryptData(PUBLIC_KEY,
                                        input("Enter Company ID : "))
        try:
            rr = requests.post(BASE_URL + 'createBlockchain', json=data)
            val = rr.json()
            with open('blockchainCard.json', 'w') as outfile:
                json.dump(val['blockchain'], outfile, indent=2)
            # print(rr.json())
        except:
            print("something went wrong")
    elif str(new) == "2":
        path = input("Enter full path to the blockchain.json file : ")
        json_data = {}
        json_data = json.loads(open(path, 'r').read())
        data = {}
        data["name"] = encryptData(PUBLIC_KEY, input("Enter name for node : "))
        data["ipaddr"] = encryptData(PUBLIC_KEY,
                                     input("Enter node's IP address : "))
        data["companyName"] = encryptData(PUBLIC_KEY,
                                          input("Enter Company name : "))
        data["companyID"] = encryptData(PUBLIC_KEY,
                                        input("Enter Company ID : "))
        data['info'] = encryptData(PUBLIC_KEY,
                                   input("Info about Blockchain : "))
        json_data["new_node_data"] = data
        print(json_data)
        try:
            rr = requests.post(BASE_URL + 'joinBlockchain', json=json_data)
            val = rr.json()
        except:
            print("something went wrong")
Exemplo n.º 14
0
import requests
from cipherOperations import encryptData

PUBLIC_KEY = "keys/public.pem"

API_ENDPOINT = "http://0.0.0.0:5000/api/v1/createUser"

username = input("Enter username : "******"Enter password : ")

username = encryptData(PUBLIC_KEY, username)
password = encryptData(PUBLIC_KEY, password)

data ={ 'username' : username,
		'password' : password }

r = requests.post(url=API_ENDPOINT, data=data)

print(r)