def saveTxDetailToDB(tx_hash): #print baseUrl + tx_hash data = getContent(baseUrl + tx_hash) #print data jsonResponse = json.loads(data) #print jsonResponse inputs = jsonResponse["data"]["inputs"] outputs = jsonResponse["data"]["outputs"] #set tx_idx = 0 because we do not have the data in the onion explorer tx_idx = 0 #print inputs vin_count = 0 for input in inputs: #increment vin_count = vin_count + 1 vout_count = 0 for output in outputs: #increment vout_count = vout_count + 1 s = "INSERT INTO tx_io (tx_hash, numinputs, numoutputs) VALUES (%s, %s, %s)" s = s % (QuotedStr(tx_hash), vin_count, vout_count) cnx = mysql.connector.connect(**mysqlconfig) cur = cnx.cursor() try: cur.execute(s) cnx.commit() except: cnx.rollback() #close the connection cnx.close()
def saveAllToDB(): #firstBlock = dbGetLastTxHeight() #lastBlock = moneroGetLastHeight() firstBlock = 1417223 lastBlock = 1417223 #lastBlock = dbGetFinalTxHeight() #firstBlock = 400000 #lastBlock = 500000 print "First block: ", str(firstBlock) print "Last BLock: ", str(lastBlock) #firstBlock = 1014786 #lastBlock = 1014787 height = firstBlock while height <= lastBlock: #data from onion blockData = getContent(blockUrl + str(height)) blockJsonResponse = json.loads(blockData) txs = blockJsonResponse["data"]["txs"] for tx in txs: #saveTxDetailToDB(tx) isCoinbase = tx["coinbase"] if not isCoinbase: tx_hash = tx["tx_hash"] saveTxDetailToDB(str(tx_hash)) print "Block height " + str(height) + " processed." #increment height = height + 1
def saveAHeaderToDB(height): #get tx_hash s = "SELECT tx_hash, tx_idx FROM header_tx WHERE header_height = %s ORDER BY tx_idx ASC" s = s % (height) cnx = mysql.connector.connect(**mysqlconfig) cur = cnx.cursor() cur.execute(s) results = cur.fetchall() #close the connection cnx.close() for result in results: tx_hash = result[0] tx_idx = result[1] #print baseUrl + tx_hash data = getContent(baseUrl + tx_hash) #print data jsonResponse = json.loads(data) #print jsonResponse inputs = jsonResponse["data"]["inputs"] #print inputs vin_idx = 0 for input in inputs: amount = input["amount"] k_image = input["key_image"] #print "key image: ", k_image , "(amount: " , amount , ")" mixins = input["mixins"] mixin_idx = 0 for mixin in mixins: public_key = mixin["public_key"] block_no = mixin["block_no"] #print "- public key: ", public_key, " (" , block_no , ")" headerVinMixin = "INSERT INTO tx_vin_mixin (header_height, k_image, tx_hash, tx_idx, vin_idx, mixin_idx, vout_header_height, vout_key) VALUES " dataVinMixin = "" dataVinMixin = "(%s, %s, %s, %s, %s, %s, %s, %s)" dataVinMixin = dataVinMixin % ( height, QuotedStr(k_image), QuotedStr(tx_hash), tx_idx, vin_idx, mixin_idx, block_no, QuotedStr(public_key)) s = headerVinMixin + dataVinMixin cnx = mysql.connector.connect(**mysqlconfig) cur = cnx.cursor() try: cur.execute(s) cnx.commit() except: cnx.rollback() #close the connection cnx.close() #print s time.sleep(0.01) #increment mixin_idx = mixin_idx + 1 #increment vin_idx = vin_idx + 1
def saveTxDetailToDB(tx_hash): #print baseUrl + tx_hash data = getContent(baseUrl + tx_hash) #print data jsonResponse = json.loads(data) #print jsonResponse inputs = jsonResponse["data"]["inputs"] height = jsonResponse["data"]["block_height"] #set tx_idx = 0 because we do not have the data in the onion explorer tx_idx = 0 #print inputs vin_idx = 0 for input in inputs: amount = input["amount"] k_image = input["key_image"] #print "key image: ", k_image , "(amount: " , amount , ")" mixins = input["mixins"] mixin_idx = 0 for mixin in mixins: public_key = mixin["public_key"] block_no = mixin["block_no"] #print "- public key: ", public_key, " (" , block_no , ")" headerVinMixin = "INSERT INTO tx_vin_mixin (header_height, k_image, tx_hash, tx_idx, vin_idx, mixin_idx, vout_header_height, vout_key) VALUES " dataVinMixin = "(%s, %s, %s, %s, %s, %s, %s, %s)" dataVinMixin = dataVinMixin % ( height, QuotedStr(k_image), QuotedStr(tx_hash), tx_idx, vin_idx, mixin_idx, block_no, QuotedStr(public_key)) s = "" s = headerVinMixin + dataVinMixin cnx = mysql.connector.connect(**mysqlconfig) cur = cnx.cursor() try: cur.execute(s) cnx.commit() except: cnx.rollback() #close the connection cnx.close() #print s #time.sleep(0.01) #increment mixin_idx = mixin_idx + 1 #increment vin_idx = vin_idx + 1 # print "Transaction hash", tx_hash, " has been saved"
def getTxData(tx_hash): data = getContent(baseUrl + tx_hash) #print data jsonResponse = json.loads(data) #print jsonResponse["data"]["inputs"] inputs = jsonResponse["data"]["inputs"] #print inputs for input in inputs: amount = input["amount"] k_image = input["key_image"] #print "key image: ", k_image , "(amount: " , amount , ")" mixins = input["mixins"] for mixin in mixins: public_key = mixin["public_key"] block_no = mixin["block_no"]
def saveAHeaderToDB(height): #data from onion blockData = getContent(blockUrl + str(height)) blockJsonResponse = json.loads(blockData) txs = blockJsonResponse["data"]["txs"] for tx in txs: #saveTxDetailToDB(tx) isCoinbase = tx["coinbase"] if not isCoinbase: tx_hash = tx["tx_hash"] saveTxDetailToDB(str(tx_hash)) print "Block height " + str(height) + " processed." #increment height = height + 1
def saveTxDetailToDB(): firstBlock = dbGetLastTxHeight() #lastBlock = dbGetFinalTxHeight() #firstBlock = 71250 lastBlock = 100000 print "First block: ", str(firstBlock) print "Last BLock: ", str(lastBlock) #firstBlock = 1014786 #lastBlock = 1014787 height = firstBlock while height < lastBlock: #get tx_hash s = "SELECT tx_hash, tx_idx FROM header_tx WHERE header_height = %s ORDER BY tx_idx ASC" s = s % (height) cnx = mysql.connector.connect(**mysqlconfig) cur = cnx.cursor() cur.execute(s) results = cur.fetchall() #close the connection cnx.close() headerVinMixin = "INSERT INTO tx_vin_mixin (header_height, k_image, tx_hash, tx_idx, vin_idx, mixin_idx, vout_header_height, vout_key) VALUES " dataVinMixin = "" for result in results: tx_hash = result[0] tx_idx = result[1] #print baseUrl + tx_hash data = getContent(baseUrl + tx_hash) #print data #print baseUrl + tx_hash jsonResponse = json.loads(data) #print jsonResponse inputs = jsonResponse["data"]["inputs"] #print inputs vin_idx = 0 for input in inputs: amount = input["amount"] k_image = input["key_image"] #print "key image: ", k_image , "(amount: " , amount , ")" mixins = input["mixins"] mixin_idx = 0 for mixin in mixins: public_key = mixin["public_key"] block_no = mixin["block_no"] #print "- public key: ", public_key, " (" , block_no , ")" singleVinMixin = "(%s, %s, %s, %s, %s, %s, %s, %s)" singleVinMixin = singleVinMixin % ( height, QuotedStr(k_image), QuotedStr(tx_hash), tx_idx, vin_idx, mixin_idx, block_no, QuotedStr(public_key)) if dataVinMixin == "": dataVinMixin = singleVinMixin else: dataVinMixin = str(dataVinMixin) + "," + str( singleVinMixin) #increment mixin_idx = mixin_idx + 1 #increment vin_idx = vin_idx + 1 #compile the result s = "" if dataVinMixin <> "": s = headerVinMixin + dataVinMixin cnx = mysql.connector.connect(**mysqlconfig) cur = cnx.cursor() try: cur.execute(s) cnx.commit() except: cnx.rollback() #close the connection cnx.close() #print s time.sleep(0.01) print "Block height " + str(height) + " processed." #increment height = height + 1