def hasMarkerOutput(vout): hasMarkerOutput = False marker_output_index = -1 num = 0 payload = "" for i, o in enumerate(vout): if "4f41" == o["scriptPubKey"]["hex"][4:8]: marker_output_index = i # print("OA Version:" + o["scriptPubKey"]["hex"][8:12]) payload = o["scriptPubKey"]["hex"][12:] num, payload = oautil.leb128(payload) hasMarkerOutput = True break return hasMarkerOutput, marker_output_index, num, payload
def getTransactionAssetAmount(conn, txid, index): # print("txid: " + txid) # print("vout: " + str(index)) tx = conn.getrawtransaction(txid, 1) vout = tx["vout"] # 色付けされてるかを確認 hasMO, marker_output_index, num, payload = hasMarkerOutput(vout) if not hasMO: return False, 0, tx # print(len(vout)) # print(marker_output_index) # 指定したvoutのasset量を取得する for i in range(len(vout)): if i is marker_output_index: continue amount, payload = oautil.leb128(payload) if vout[i]["n"] is index: return True, amount, tx print("指定されたvoutが見つかりませんでした") return False, 0, tx
def getTransactionAssetAmount(conn, txid, index): # print("txid: " + txid) # print("vout: " + str(index)) tx = conn.getrawtransaction(txid, 1) vout = tx["vout"] # Verifique se é token hasMO, marker_output_index, num, payload = hasMarkerOutput(vout) if not hasMO: return False, 0, tx # print(len(vout)) # print(marker_output_index) # Obter o valor do ativo do vout especificado for i in range(len(vout)): if i is marker_output_index: continue amount, payload = oautil.leb128(payload) if vout[i]["n"] is index: return True, amount, tx print("O vout especificado nao foi encontrado") return False, 0, tx
def parseTx(conn, txid): block = conn.getrawtransaction(txid, 1) vout = block["vout"] marker_output_index = 0 num = 0 payload = "" dbconn = MySQLdb.connect( user=config["dbuser"]["name"], passwd=config["dbuser"]["pass"], host=config["db"]["host"], db=config["db"]["dbname"]) c = dbconn.cursor() hasMO, marker_output_index, num, payload = hasMarkerOutput(vout) if not hasMO: return addressFrom = getAddressFrom(conn, block) for i in range(num): if i is marker_output_index: continue try: amount, payload = oautil.leb128(payload) if amount == 0: continue o = vout[i] if "scriptPubKey" not in o: continue scriptPubKey = o["scriptPubKey"] if "addresses" not in scriptPubKey or "hex" not in scriptPubKey: continue addresses = scriptPubKey["addresses"] assetId, issueTxid = searchIssuranceTx(conn, dbconn, i, block, amount) isIssuranceTx = True if block["txid"] is issueTxid else False print("txid: {0}".format(block["txid"])) print("出力{0}:".format(i)) print("送信元: %s" % addressFrom) print("送信先: {0}".format(addresses)) print("アセットID: {0}".format(assetId)) print("送金量: {0}".format(amount)) print("時刻: {0}".format( datetime.datetime.fromtimestamp(int(block["time"])))) print("") table = config["db"]["tablename"] sql = 'insert into ' + table + ' values (0, %s, %s, %s, %s, %s, %s, %s, %s, %s)' c.execute(sql, (block["txid"], addresses[0], addressFrom[0], assetId, i, amount, issueTxid, block["time"], "1" if isIssuranceTx else "0")) except Exception as e: print('== エラー内容 ==') print('type:' + str(type(e))) print('args:' + str(e.args)) print('e自身:' + str(e)) dbconn.commit() c.close() dbconn.close()