def destroyChain(): if settings.nodePid == 0: command = ["rm", "-r" , settings.pathToHiddenMultichain + "/" + settings.chainName] subprocess.call(command) return settings.corsResponse(settings.chainName + " deleted.") else: return settings.corsResponse("Stop the connection before deleting the chain!")
def revokeCertificate(): revocationForm = request.get_json() if revocationForm['txid'] != '': revocationTransaction = settings.multichainNode.createrawtransaction( [{ "txid": revocationForm['txid'], "vout": 0 }], { "1XXXXXXXCuXXXXXXdqXXXXXXV5XXXXXXZFb4eK": { settings.diplomaName: 1 } }, [], 'sign') print revocationTransaction revocationForm['hex'] = revocationTransaction['hex'] revocationForm['txid'] = '' revocationResponse = requests.delete(revocationForm['url'], json=revocationForm).content return settings.corsResponse(json.dumps(revocationResponse)) if revocationForm['hex']: signedRevocationTransaction = settings.multichainNode.signrawtransaction( revocationForm['hex']) if signedRevocationTransaction['complete'] == True: publish = settings.multichainNode.sendrawtransaction( signedRevocationTransaction['hex']) return settings.corsResponse('Certificate succesfuly revoked') else: return settings.corsResponse('Error') return settings.corsResponse('Error')
def verifyCertificate(): verificationForm = request.get_json() transaction = verificationForm['txid'] transactionOutput = settings.multichainNode.gettxout(transaction,0) plainCertificate = verificationForm['cert'] sha256 = hashlib.sha256() sha256.update(plainCertificate) myHashedCertificate = sha256.hexdigest() if transactionOutput: hashedCertificate = settings.multichainNode.gettxoutdata(transaction,1) if hashedCertificate == myHashedCertificate: transactionData = settings.multichainNode.getrawtransaction(transaction,1) transactionDetails = {} transactionDetails['Message'] = 'The certificate is valid' transactionDetails['Owner'] = transactionData['vout'][0]['scriptPubKey']['addresses'] transactionDetails['Sender'] = transactionData['vout'][2]['scriptPubKey']['addresses'] transactionDetails['HashedCertificate'] = hashedCertificate return settings.corsResponse(json.dumps(transactionDetails)) else: return settings.corsResponse('The certificates do not match') else: return settings.corsResponse('The certificate was revoked')
def requestCertificate(): settings.initMultichainNode() requestForm = request.get_json() url = 'http://' + requestForm['ip'] + '/v1.1/offchain/certificate' requestCertResponse = requests.get(url, json=requestForm).content requestCertResponse = json.loads(requestCertResponse) #extract the hash of the cetificate from transaction if 'txid' in requestCertResponse.keys(): return settings.corsResponse(json.dumps(requestCertResponse)) decodedTransaction = settings.multichainNode.decoderawtransaction( requestCertResponse['transaction']) hashedCertificate = decodedTransaction['vout'][1]['data'][0] #validate certificate plainCertificate = requestCertResponse['cert'] sha256 = hashlib.sha256() sha256.update(plainCertificate) myHashedCertificate = sha256.hexdigest() if myHashedCertificate == hashedCertificate: return settings.corsResponse(json.dumps(requestCertResponse)) else: return settings.corsResponse("The certificates do not match")
def startChain(): if settings.nodePid == 0: command = [ settings.pathToMultichain + "/multichaind", "-daemon", settings.nodeAddress ] proc = subprocess.Popen(command) settings.nodePid = proc.pid if settings.nodePid == 0: return settings.corsResponse( "Something went wrong when trying to start the chain!") else: return settings.corsResponse("Node running.") else: return settings.corsResponse(settings.killNode())
def createChain(): parameter = request.get_json() settings.updateChainName(parameter['chainName']) # to verify if some of the params received are in the default params command = ( [settings.pathToMultichain + "/multichain-util"] + [ "create" , settings.chainName] + parameter['params'] + settings.defaultBlockchainParamsList ) output = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0] return settings.corsResponse(output)
def publishCertificate(): settings.initMultichainNode() publishForm = request.get_json() signedTransaction = settings.multichainNode.signrawtransaction( publishForm['transaction'])['hex'] url = 'http://' + publishForm['ip'] + '/v1.1/offchain/certificate' publishResponse = requests.post(url, json={ 'hex': signedTransaction, 'pass': publishForm['pass'] }).content return settings.corsResponse(publishResponse)
def createSubscripton(): settings.initMultichainNode() subscriptionForm = request.get_json() subscriptionForm['address'] = settings.myAddress subscriptionForm['pubKey'] = settings.myPubKey url = 'http://' + subscriptionForm['ip'] + '/v1.1/actor' subscriptionResponse = requests.post(url, json=subscriptionForm).content subscriptionResponse = json.loads(subscriptionResponse) print subscriptionResponse if 'diploma' in subscriptionResponse.keys(): settings.diplomaName = subscriptionResponse['diploma'] multisigAddress = settings.multichainNode.addmultisigaddress( 2, [subscriptionResponse['pubkey'], settings.myPubKey]) settings.multichainNode.importaddress(multisigAddress, 'false') settings.subscriptionMultisig = multisigAddress return settings.corsResponse('You were accepted. Your multisig: ' + multisigAddress)
def getNodeAddress(): settings.initMultichainNode() return settings.corsResponse( settings.multichainNode.getinfo()['nodeaddress'])
def connectToExistingChain(): parameter = request.get_json() settings.nodeAddress = parameter settings.chainName = parameter.split("@")[0] return settings.corsResponse(parameter)