feat: migration Ğ1v2 — Subsquid + Cesium+ g1.data.e-is.pro
Sources de données réelles Ğ1v2 (vérifiées par introspection) : - SubsquidAdapter : https://squidv2s.syoul.fr/v1/graphql transfers(filter: timestamp >= since, orderBy: TIMESTAMP_DESC) with from.linkedIdentity.name pour jointure géo - CesiumAdapter : https://g1.data.e-is.pro (59 841 profils) recherche batch par nom d'identité (title.keyword) g1.data.duniter.fr hors ligne depuis arrêt Ğ1v1 Schémas Zod mis à jour pour Ğ1v2 : - G1v2KeySchema : SS58 "g1" + 47 chars = 49 chars (mesuré sur données réelles) - SubsquidTransferSchema : id, blockNumber, timestamp ISO, amount BigInt string - parseSubsquidAmount : BigInt string centimes → Ğ1 flottant Activation : VITE_USE_LIVE_API=true dans .env.local Badge "● live Ğ1v2 / ○ mock" ajouté dans l'UI Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,86 +4,63 @@
|
||||
* Cesium+ est la couche sociale de Ğ1 : les membres y publient
|
||||
* un profil optionnel avec pseudo, avatar, ville, et coordonnées GPS.
|
||||
*
|
||||
* API docs : https://github.com/duniter/cesium-plus-pod
|
||||
* Endpoint public : https://g1.data.duniter.fr
|
||||
* Endpoint actif : https://g1.data.e-is.pro (59 841 profils, vérifié le 2026-03-22)
|
||||
* g1.data.duniter.fr est hors ligne depuis l'arrêt de Ğ1v1.
|
||||
*
|
||||
* En Ğ1v2 les clés SS58 ont changé : la recherche se fait par nom d'identité
|
||||
* (identity.name depuis Subsquid) et non plus par clé publique.
|
||||
*/
|
||||
|
||||
import { CesiumSearchResponseSchema, type CesiumProfile } from '../../schemas/g1.schema';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const CESIUM_ENDPOINT = 'https://g1.data.duniter.fr';
|
||||
export const CESIUM_ENDPOINT = 'https://g1.data.e-is.pro';
|
||||
|
||||
export interface GeoProfile {
|
||||
pubkey: string;
|
||||
city: string;
|
||||
lat: number;
|
||||
lng: number;
|
||||
name: string; // nom d'identité Ğ1 (ex: "Anikka")
|
||||
city: string;
|
||||
lat: number;
|
||||
lng: number;
|
||||
}
|
||||
|
||||
const HitSchema = z.object({
|
||||
_source: z.object({
|
||||
title: z.string().optional(),
|
||||
city: z.string().optional(),
|
||||
geoPoint: z.object({
|
||||
lat: z.number().min(-90).max(90),
|
||||
lon: z.number().min(-180).max(180),
|
||||
}).optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
const SearchResponseSchema = z.object({
|
||||
hits: z.object({
|
||||
hits: z.array(HitSchema),
|
||||
}),
|
||||
});
|
||||
|
||||
/**
|
||||
* Résout les coordonnées géographiques d'une liste de clés publiques.
|
||||
* Les membres sans profil ou sans geoPoint sont filtrés.
|
||||
* Résout les coordonnées de plusieurs membres Ğ1 par leur nom d'identité.
|
||||
* Envoie une requête Elasticsearch multi-terms en un seul appel.
|
||||
*
|
||||
* @param pubkeys - tableau de clés publiques Ğ1 (base58)
|
||||
* @returns Map<pubkey, GeoProfile>
|
||||
* @param names - noms d'identité uniques (depuis SubsquidAdapter RawTransfer.fromName)
|
||||
* @returns Map<name, GeoProfile>
|
||||
*/
|
||||
export async function resolveGeoProfiles(
|
||||
pubkeys: string[]
|
||||
export async function resolveGeoByNames(
|
||||
names: string[]
|
||||
): Promise<Map<string, GeoProfile>> {
|
||||
if (pubkeys.length === 0) return new Map();
|
||||
const unique = [...new Set(names.filter(Boolean))];
|
||||
if (unique.length === 0) return new Map();
|
||||
|
||||
// Elasticsearch multi-get (mget) — efficace en batch
|
||||
const body = { ids: pubkeys };
|
||||
const response = await fetch(`${CESIUM_ENDPOINT}/user/profile/_mget`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Cesium+ → HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
const raw = await response.json();
|
||||
const parsed = CesiumSearchResponseSchema.parse({ hits: { hits: raw.docs ?? [] } });
|
||||
|
||||
const result = new Map<string, GeoProfile>();
|
||||
for (const hit of parsed.hits.hits) {
|
||||
const src = hit._source;
|
||||
if (src.geoPoint) {
|
||||
result.set(hit._id, {
|
||||
pubkey: hit._id,
|
||||
city: src.city ?? 'Inconnue',
|
||||
lat: src.geoPoint.lat,
|
||||
lng: src.geoPoint.lon,
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recherche des membres Ğ1 avec profil géolocalisé dans un rayon donné.
|
||||
* Utile pour initialiser la carte avec les membres actifs d'une région.
|
||||
*/
|
||||
export async function searchMembersInBoundingBox(opts: {
|
||||
topLeft: { lat: number; lng: number };
|
||||
bottomRight: { lat: number; lng: number };
|
||||
size?: number;
|
||||
}): Promise<GeoProfile[]> {
|
||||
const query = {
|
||||
size: opts.size ?? 200,
|
||||
size: unique.length,
|
||||
query: {
|
||||
bool: {
|
||||
must: [
|
||||
{ terms: { 'title.keyword': unique } },
|
||||
],
|
||||
filter: [
|
||||
{ term: { '_source.socials.type': 'member' } },
|
||||
{
|
||||
geo_bounding_box: {
|
||||
'_source.geoPoint': {
|
||||
top_left: { lat: opts.topLeft.lat, lon: opts.topLeft.lng },
|
||||
bottom_right: { lat: opts.bottomRight.lat, lon: opts.bottomRight.lng },
|
||||
},
|
||||
},
|
||||
},
|
||||
{ exists: { field: 'geoPoint' } },
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -97,20 +74,23 @@ export async function searchMembersInBoundingBox(opts: {
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Cesium+ search → HTTP ${response.status}`);
|
||||
throw new Error(`Cesium+ HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
const raw = await response.json();
|
||||
const parsed = CesiumSearchResponseSchema.parse(raw);
|
||||
const parsed = SearchResponseSchema.parse(raw);
|
||||
|
||||
return parsed.hits.hits
|
||||
.filter((h): h is CesiumProfile & { _source: { geoPoint: NonNullable<CesiumProfile['_source']['geoPoint']> } } =>
|
||||
h._source.geoPoint !== undefined
|
||||
)
|
||||
.map((h) => ({
|
||||
pubkey: h._id,
|
||||
city: h._source.city ?? 'Inconnue',
|
||||
lat: h._source.geoPoint.lat,
|
||||
lng: h._source.geoPoint.lon,
|
||||
}));
|
||||
const result = new Map<string, GeoProfile>();
|
||||
for (const hit of parsed.hits.hits) {
|
||||
const src = hit._source;
|
||||
if (src.geoPoint && src.title) {
|
||||
result.set(src.title, {
|
||||
name: src.title,
|
||||
city: src.city ?? 'Inconnue',
|
||||
lat: src.geoPoint.lat,
|
||||
lng: src.geoPoint.lon,
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user