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 integrateCertificate(): settings.initMultichainNode() # to verify if I can do it params = request.get_json() # creating the certificate key = params['pass'] if key not in settings.actors.keys(): return "Wrong pass" fin = open('res/' + settings.actors[key]['file'], 'rb') myData = fin.read() fin.close() if 'txid' in settings.actors[key].keys(): retval = { 'cert': myData, 'txid': settings.actors[params['pass']]['txid'] } return Response(json.dumps(retval)) # hashing the certificate sha256 = hashlib.sha256() sha256.update(myData) myHash = sha256.hexdigest() multisigAddress = settings.actors[params['pass']]['multisig'] settings.multichainNode.issuemorefrom(settings.myAddress, multisigAddress, settings.diplomaName, 1) recipient = {settings.subscriptionMultisig: {settings.diplomaName: 1}} hexBloc = settings.multichainNode.createrawsendfrom( multisigAddress, recipient, [myHash]) retval = {'cert': myData, 'transaction': hexBloc} return Response(json.dumps(retval))
def delActor(): settings.initMultichainNode() parameter = request.get_json() actorAddress = parameter['address'] settings.multichainNode.revokefrom( settings.myAddress, actorAddress, 'send,receive,mine,create,admin,activate,issue') return 'Address ' + actorAddress + ' permissions were deleted'
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 publishTransaction(): settings.initMultichainNode() params = request.get_json() hexBloc = settings.multichainNode.signrawtransaction(params['hex']) if hexBloc['complete']: txid = settings.multichainNode.sendrawtransaction(hexBloc['hex']) settings.actors[params['pass']]['txid'] = txid settings.saveActors() print settings.actors return Response(txid) else: print "Something went wrong" return Response("error")
def addActor(): settings.initMultichainNode() subscriptionForm = request.get_json() #create the permision list based on actor's role print subscriptionForm print "-----------------------------------" key = subscriptionForm['pass'] if key not in settings.actors.keys(): return '' permissionsList = validateActorData(settings.actors[key]['rank']) #grant actor permissions if permissionsList: rsp = {'pubkey': settings.myPubKey} #creating multisig multisigAddress = settings.multichainNode.addmultisigaddress( 2, [settings.myPubKey, subscriptionForm['pubKey']]) settings.multichainNode.importaddress(multisigAddress, 'false') settings.multichainNode.grantfrom(settings.myAddress, multisigAddress, 'send,receive') #granting permissions if settings.actors[key]['rank'] == 2: titleName = createLicence(subscriptionForm['name']) settings.multichainNode.grantfrom(settings.myAddress, subscriptionForm['address'], titleName + '.issue') rsp['diploma'] = titleName settings.multichainNode.grantfrom(settings.myAddress, subscriptionForm['address'], permissionsList) #saving actor settings.actors[key]['multisig'] = multisigAddress settings.actors[key]['identity'] = subscriptionForm['name'] settings.saveActors() print subscriptionForm['name'] + ' was accepted' print rsp return Response(json.dumps(rsp)) else: return ''
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'])