Files
dchain/docs/api/README.md
vsecoder 1a8731f479 docs: update README + api docs + architecture for v2.0.0 feed
README
  - Mention social feed in the one-line description and feature bullets
  - Add relay + feed endpoint tables to the API overview (was
    previously empty on messaging)
  - List media/ package in the repo structure

docs/api/
  - New docs/api/feed.md: full reference for /feed/publish, fetch,
    stats, view, author, timeline, trending, foryou, hashtag; all
    on-chain CREATE_POST / DELETE_POST / FOLLOW / LIKE payloads;
    fee economics; server-side scrubbing contract.
  - docs/api/relay.md rewritten: /relay/broadcast is now the primary
    E2E path with a complete envelope schema; /relay/send kept but
    flagged ⚠ NOT E2E; DELETE /relay/inbox/{id} documented with the
    new Ed25519 signed-auth body.
  - docs/api/README.md index: added feed.md row.

docs/architecture.md
  - L2 Transport layer description updated to include the feed
    mailbox alongside the 1:1 relay mailbox.
  - New "Социальная лента (v2.0.0)" section right after the 1:1
    message flow: ASCII diagram of publish + on-chain commit +
    timeline fetch, economic summary, metadata-scrub summary.

docs/node/README.md
  - Removed stale chan:/chan-member: keys from the BadgerDB schema
    reference; replaced with the v2.0.0 feed keys (post:,
    postbyauthor:, follow:, followin:, like:, likecount:).

docs/update-system.md
  - Example features[] array updated to match the actual node output
    (channels_v1 removed, feed_v2 / media_scrub / relay_broadcast added).

Node feature flags
  - api_well_known_version.go: dropped channels_v1 tag (the
    /api/channels/:id endpoint was removed in the feed refactor);
    added feed_v2, media_scrub, relay_broadcast so clients can
    feature-detect the v2.0.0 surface.
  - Comment example updated channels_v2/v1 → feed_v3/v2.

Client
  - CLIENT_REQUIRED_FEATURES expanded to include the v2.0.0 feature
    flags the client now depends on (feed_v2, media_scrub,
    relay_broadcast); checkNodeVersion() will flag older nodes as
    unsupported and surface an upgrade prompt.

All 7 Go test packages green; tsc --noEmit clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 22:06:06 +03:00

3.6 KiB
Raw Blame History

REST + WebSocket API

DChain-нода обслуживает HTTP + WebSocket на --stats-addr (по умолчанию :8080). JSON везде; ошибки в формате {"error": "описание"}, с 4xx для клиентских проблем и 5xx для серверных.

Полная OpenAPI-спека живёт в бинаре (/swagger/openapi.json) и рендерится Swagger UI на /swagger. Эти два эндпоинта можно выключить через DCHAIN_DISABLE_SWAGGER=true — см. deploy/single/README.md.

Разделы

Документ Эндпоинты
chain.md Блоки, транзакции, балансы, адреса, netstats, validators
contracts.md Деплой, вызов, state, логи контрактов
relay.md Relay-mailbox: 1:1 E2E-шифрованные envelopes
feed.md Социальная лента: публикация постов, лайки, подписки, рекомендации, хэштеги (v2.0.0)

Discovery / metadata (always on)

Endpoint Возврат
GET /api/netstats height, total_txs, supply, validator_count
GET /api/network-info chain_id, genesis_hash, peers[], validators[], contracts
GET /api/well-known-version node_version, build{}, protocol_version, features[], chain_id
GET /api/well-known-contracts canonical contract_id → name mapping
GET /api/update-check comparison with upstream Gitea release (см. ../update-system.md)
GET /api/peers connected peer IDs + их версии (из gossip dchain/version/v1)
GET /api/validators active validator set
GET /metrics Prometheus exposition

Real-time (push)

  • GET /api/ws — WebSocket, рекомендованный транспорт. Поддерживает submit_tx, subscribe, unsubscribe, typing, ping. Push-события: block, tx, inbox, typing, submit_ack.
  • GET /api/events — SSE, legacy одностороннее streaming (для старых клиентов).

Protocol reference — node/ws.go + ../architecture.md.

Аутентификация

По умолчанию API публичен. Три режима access-control настраиваются через env:

Режим DCHAIN_API_TOKEN DCHAIN_API_PRIVATE Эффект
Public не задан Все могут читать и submit'ить tx
Token writes задан false Читать — любой; POST /api/tx и WS submit_tx — только с Authorization: Bearer <token>
Fully private задан true Все эндпоинты требуют token (включая /api/netstats)

WebSocket: токен передаётся query-параметром ?token=<...>.

Примеры

# Базовый health
curl -s http://localhost:8080/api/netstats | jq .

# Версия ноды
curl -s http://localhost:8080/api/well-known-version | jq '{tag: .build.tag, features: .features}'

# Список пиров с их версиями
curl -s http://localhost:8080/api/peers | jq '.peers[].version'

# С токеном (private-режим)
curl -s -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/netstats

# Submit tx (public-режим)
curl -s -X POST -H "Content-Type: application/json" \
  -d @tx.json http://localhost:8080/api/tx