def getCoinValue(self): """ Process 'Start' command """ global value cv = db_handler() value = cv.calulateCoinsValue() # self.topBar.columnconfigure(0, weight=0) self.l2.configure(text=str(value) + "$ ")
def LoadTable(self): dbh = db_handler() t_deatail = dbh.getAllMinerDetails() self.rows = t_deatail.count() #print t_deatail, self.rows for document in t_deatail: #print document["NO_COIN"], document["S_ID"], document["M_S_ID"], document["date"] self.treeview.insert('', 'end', text=document["date"], values=( document["M_S_ID"], document["S_ID"] ,document["S_PARA"],document["NO_COIN"]))
def LoadTable(self): dbh = db_handler() t_deatail = dbh.getAllTransactionDetails() self.rows = t_deatail.count() #print t_deatail, self.rows for document in t_deatail: #only mining details are printed in table.no p2p transactions #print document["NO_COIN"], document["S_ID"], document["TRANSACTION"][0]["DATE"], document["TRANSACTION"][0]["MINER"] self.treeview.insert('', 'end', text=document["TRANSACTION"][0]["DATE"].date(), values=(document["NO_COIN"], document["S_ID"], document["TRANSACTION"][0]["MINER"]))
def LoadTable(self): dbh = db_handler() t_deatail = dbh.getAllBlockChainDetail() self.rows = t_deatail.count() #print t_deatail, self.rows for document in t_deatail: #only moninig details are printed in table.no p2p transactions #print document["NO_COIN"], document["S_ID"], document["TRANSACTION"][0]["DATE"], document["TRANSACTION"][0]["MINER"] self.treeview.insert('', 'end', text=document["TRANSACTION"][0]["DATE"].date(), values=(document["NO_COIN"], document["S_ID"], document["TRANSACTION"][0]["MINER"]))
def LoadTable(self): dbh = db_handler() t_deatail = dbh.getAllMinerDetails() self.rows = t_deatail.count() #print t_deatail, self.rows for document in t_deatail: #print document["NO_COIN"], document["S_ID"], document["M_S_ID"], document["date"] self.treeview.insert('', 'end', text=document["date"], values=(document["M_S_ID"], document["S_ID"], document["S_PARA"], document["NO_COIN"]))
def checkCoinOrigin(self, coin): #print "verify_coincoin origin check" dbh = db_handler() r_deatail = dbh.getRootBlockChainDetail(coin) print r_deatail for document in r_deatail: #print document["TRANSACTION"][0]["MINER"] m1 = document["TRANSACTION"][0]["MINER"] if (m1 == "M_1"): dbh.delectCoinDetail(coin) return True else: #print "Store coin" return False
def handleSenz(self, senz): """ Handle differennt types of senz from here. This function will be called asynchronously. Whenc senz message receives this function will be called by twisted thread(thread safe mode via twisted library) """ #print "Hanlder ", senz.attributes, senz.type, senz.receiver, senz.sender logger.info('senz received %s' % senz.type) dbh = db_handler() if (senz.type == 'PUT'): #print "Coin value :", senz.attributes["#COIN_VALUE"] senze = 'UNSHARE #COIN_VALUE ' senz = str(senze) + "@%s ^%s" % (senz.sender, clientname) signed_senz = sign_senz(senz) logger.info('read senz: %s' % signed_senz) self.transport.write(signed_senz) elif (senz.type == "SHARE"): flag = senz.attributes["#f"] if (flag == "cc"): format_date =datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S").replace(" ", "") cah = minning_algo() coin = cah.getCoin(senz.attributes["#S_PARA"]+""+format_date+""+senz.sender) senze_c = 'PUT #COIN %s #TIME %s ' % (coin,format_date) senz_c = str(senze_c) + "@%s ^%s" % (senz.sender, clientname) signed_senzc = sign_senz(senz_c) dbh.addMinerDetail(senz.attributes, coin ,format_date) # add_detail_to_block_chain dbh.addCoinWiseTransaction(senz, coin, format_date) logger.info('Auto Excute: %s' % signed_senzc) self.transport.write(signed_senzc) self.sendTDetailsToBase(senz,coin,format_date) self.sendTDetailsToMiners(senz, coin, format_date) if (flag == "ccb"): logger.info('Recived New new coin Mining COin detail::%s' % senz) coin = senz.attributes["#COIN"] format_date = senz.attributes["#FORMAT_DATE"] verify_state = self.verifyCoin(coin, senz.attributes["#S_PARA"], format_date,senz.attributes["#RECIVER"]) if (verify_state == True): dbh.addCoinWiseTransaction(senz, coin, format_date) else: dbh.faildVerification(senz, coin, format_date) if (flag == "b_vct"): logger.info('Recived tranaction block verification request ::%s' % senz) coin = senz.attributes["#COIN"] coin_sender = senz.attributes["#COIN_SENDER"] #check coin privious sender and reciver - privous block #if valied update probability value self.updateProbabilityState(senz); #App to Miner Trasaction request accept if (flag == "ctr"): logger.info('Request Massage p2p Transaction :: %s' % senz) senze_c = 'PUT #MSG %s ' % ("ShareDone") senz_c = str(senze_c) + "@%s ^%s" % (senz.sender, clientname) signed_senzc = sign_senz(senz_c) self.transport.write(signed_senzc) if (flag == "b_ct_ack"): logger.info('Transaction fail ACK:: %s' % senz) #detail should remove from db coin = senz.attributes["#COIN"]; coin_sender = senz.attributes["#COIN_SENDER"] coin_reciver = senz.attributes["#COIN_RECIVER"] dbh.removeNotVerificationBlock(senz,coin,coin_sender,coin_reciver) dbh.faildVerification(senz, coin, "") # print senz.type=="DATA" and senz.receiver !=None elif (senz.type == "DATA" and senz.receiver != None): flag = senz.attributes["#f"] coin = senz.attributes["#COIN"] time = senz.attributes["#time"] reciver = senz.attributes["#RECIVER"]; #print "Reciver (Data)",reciver if (reciver != ""): if (flag == "b_ct"): logger.info('Doing p2p Transaction ::%s' % senz) dbh.addCoinWiseTransaction(senz,coin,time) #recived Coin if(flag == "ct"): if (reciver == "node1"): logger.info('Recived Coin ::%s' % senz) #check valitdity (final block check) #if ok senze_c = 'PUT #MSG %s ' % ("Transaction_Success") senz_c = str(senze_c) + "@%s ^%s" % (senz.sender, clientname) signed_senzc = sign_senz(senz_c) self.transport.write(signed_senzc) #check coin own coin or not coin_origin = self.checkCoinOrigin(coin) if(coin_origin == True): #delect coin and broadcast it senze_c = 'DELETE #MSG %s #COIN %s ' % ("DELETE COIN" , str(coin)) senz_c = str(senze_c) + "@%s @%s ^%s" % ("node3","baseNode", clientname) signed_senzc = sign_senz(senz_c) self.transport.write(signed_senzc) else: #if not own coin store folder and update block chain dbh.addCoinWiseTransaction(senz, coin, time) self.creatCoinScript(senz, coin) else: dbh.addCoinWiseTransaction(senz, coin, time) elif (senz.type == "DELETE"): coin = senz.attributes["#COIN"] dbh.delectCoinDetail(coin) elif (senz.type=="UNSHARE"): pass
def handleSenz(self, senz): """ Handle differennt types of senz from here. This function will be called asynchronously. Whenc senz message receives this function will be called by twisted thread(thread safe mode via twisted library) """ #print "Hanlder ", senz.attributes, senz.type, senz.receiver, senz.sender logger.info('senz received %s' % senz.type) dbh = db_handler() if (senz.type == 'PUT'): #print "Coin value :", senz.attributes["#COIN_VALUE"] senze = 'UNSHARE #COIN_VALUE ' senz = str(senze) + "@%s ^%s" % (senz.sender, clientname) signed_senz = sign_senz(senz) logger.info('read senz: %s' % signed_senz) self.transport.write(signed_senz) elif (senz.type == "SHARE"): flag = senz.attributes["#f"] if (flag == "cc"): format_date = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S").replace(" ", "") cah = minning_algo() coin = cah.getCoin(senz.attributes["#S_PARA"] + "" + format_date + "" + senz.sender) senze_c = 'PUT #COIN %s #TIME %s ' % (coin, format_date) senz_c = str(senze_c) + "@%s ^%s" % (senz.sender, clientname) signed_senzc = sign_senz(senz_c) dbh.addMinerDetail(senz.attributes, coin, format_date) # add_detail_to_block_chain dbh.addCoinWiseTransaction(senz, coin, format_date) logger.info('Auto Excute: %s' % signed_senzc) self.transport.write(signed_senzc) self.sendTDetailsToBase(senz, coin, format_date) self.sendTDetailsToMiners(senz, coin, format_date) if (flag == "ccb"): logger.info('Recived New new coin Mining COin detail::%s' % senz) coin = senz.attributes["#COIN"] format_date = senz.attributes["#FORMAT_DATE"] verify_state = self.verifyCoin(coin, senz.attributes["#S_PARA"], format_date, senz.attributes["#RECIVER"]) if (verify_state == True): dbh.addCoinWiseTransaction(senz, coin, format_date) else: dbh.faildVerification(senz, coin, format_date) if (flag == "b_vct"): logger.info( 'Recived tranaction block verification request ::%s' % senz) coin = senz.attributes["#COIN"] coin_sender = senz.attributes["#COIN_SENDER"] #check coin privious sender and reciver - privous block #if valied update probability value self.updateProbabilityState(senz) #App to Miner Trasaction request accept if (flag == "ctr"): logger.info('Request Massage p2p Transaction :: %s' % senz) senze_c = 'PUT #MSG %s ' % ("ShareDone") senz_c = str(senze_c) + "@%s ^%s" % (senz.sender, clientname) signed_senzc = sign_senz(senz_c) self.transport.write(signed_senzc) if (flag == "b_ct_ack"): logger.info('Transaction fail ACK:: %s' % senz) #detail should remove from db coin = senz.attributes["#COIN"] coin_sender = senz.attributes["#COIN_SENDER"] coin_reciver = senz.attributes["#COIN_RECIVER"] dbh.removeNotVerificationBlock(senz, coin, coin_sender, coin_reciver) dbh.faildVerification(senz, coin, "") # print senz.type=="DATA" and senz.receiver !=None elif (senz.type == "DATA" and senz.receiver != None): flag = senz.attributes["#f"] coin = senz.attributes["#COIN"] time = senz.attributes["#time"] reciver = senz.attributes["#RECIVER"] #print "Reciver (Data)",reciver if (reciver != ""): if (flag == "b_ct"): logger.info('Doing p2p Transaction ::%s' % senz) dbh.addCoinWiseTransaction(senz, coin, time) #recived Coin if (flag == "ct"): if (reciver == "node1"): logger.info('Recived Coin ::%s' % senz) #check valitdity (final block check) #if ok senze_c = 'PUT #MSG %s ' % ("Transaction_Success") senz_c = str(senze_c) + "@%s ^%s" % (senz.sender, clientname) signed_senzc = sign_senz(senz_c) self.transport.write(signed_senzc) #check coin own coin or not coin_origin = self.checkCoinOrigin(coin) if (coin_origin == True): #delect coin and broadcast it senze_c = 'DELETE #MSG %s #COIN %s ' % ( "DELETE COIN", str(coin)) senz_c = str(senze_c) + "@%s @%s ^%s" % ( "node3", "baseNode", clientname) signed_senzc = sign_senz(senz_c) self.transport.write(signed_senzc) else: #if not own coin store folder and update block chain dbh.addCoinWiseTransaction(senz, coin, time) self.creatCoinScript(senz, coin) else: dbh.addCoinWiseTransaction(senz, coin, time) elif (senz.type == "DELETE"): coin = senz.attributes["#COIN"] dbh.delectCoinDetail(coin) elif (senz.type == "UNSHARE"): pass