Recupera info base + metadati avanzati (timestamp, controparti top, metrica rischio).
(self, address, name, ticker)
| 17885 | return out |
| 17886 | |
| 17887 | def get_crypto_data(self, address, name, ticker): |
| 17888 | """ |
| 17889 | Recupera info base + metadati avanzati (timestamp, controparti top, metrica rischio). |
| 17890 | """ |
| 17891 | info = { |
| 17892 | "Status": " Trovato", |
| 17893 | "Indirizzo": address, |
| 17894 | "Rete": name |
| 17895 | } |
| 17896 | graph_data = [] |
| 17897 | |
| 17898 | headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"} |
| 17899 | |
| 17900 | try: |
| 17901 | peer_counter = {} |
| 17902 | tx_count = None |
| 17903 | timestamps = [] |
| 17904 | balance = 0 |
| 17905 | |
| 17906 | def _commit_tx_window(): |
| 17907 | first_utc, last_utc, age_days = self._crypto_ts_window(timestamps) |
| 17908 | if first_utc: |
| 17909 | info["Prima transazione UTC"] = first_utc |
| 17910 | info["Ultima transazione UTC"] = last_utc |
| 17911 | if age_days is not None: |
| 17912 | info["Età prima tx (giorni)"] = str(age_days) |
| 17913 | |
| 17914 | # --- BITCOIN --- |
| 17915 | if ticker == "BTC": |
| 17916 | r = requests.get(f"https://mempool.space/api/address/{address}", headers=headers, timeout=8) |
| 17917 | if r.status_code == 200: |
| 17918 | data = r.json() |
| 17919 | stats = data.get("chain_stats", {}) |
| 17920 | funded = stats.get("funded_txo_sum", 0) / 100_000_000 |
| 17921 | spent = stats.get("spent_txo_sum", 0) / 100_000_000 |
| 17922 | tx_count = stats.get("tx_count", 0) |
| 17923 | balance = funded - spent |
| 17924 | info[f"Bilancio Attuale ({ticker})"] = f"{balance:.8f}" |
| 17925 | info[f"Totale Ricevuto ({ticker})"] = f"{funded:.8f}" |
| 17926 | info["Transazioni Totali"] = str(tx_count) |
| 17927 | if data.get("mempool_stats") and isinstance(data["mempool_stats"], dict): |
| 17928 | info["Mempool tx"] = str(data["mempool_stats"].get("count", "N/D")) |
| 17929 | |
| 17930 | r_txs = requests.get(f"https://mempool.space/api/address/{address}/txs/chain", headers=headers, timeout=10) |
| 17931 | txs = r_txs.json() if r_txs.status_code == 200 else [] |
| 17932 | if isinstance(txs, list): |
| 17933 | for tx in txs[:80]: |
| 17934 | ts = tx.get("status", {}).get("block_time") |
| 17935 | if ts: |
| 17936 | timestamps.append(int(ts)) |
| 17937 | for vin in tx.get("vin", []) or []: |
| 17938 | p = (vin.get("prevout") or {}).get("scriptpubkey_address") |
| 17939 | if p and p != address: |
| 17940 | peer_counter[p] = peer_counter.get(p, 0) + 1 |
| 17941 | for vout in tx.get("vout", []) or []: |
| 17942 | p = vout.get("scriptpubkey_address") |
| 17943 | if p and p != address: |
| 17944 | peer_counter[p] = peer_counter.get(p, 0) + 1 |
no test coverage detected