Files
dchain/docs/contracts
vsecoder 546d2c503f chore(release): clean up repo for v0.0.1 release
Excluded from release bundle:
- CONTEXT.md, CHANGELOG.md (agent/project working notes)
- client-app/ (React Native messenger — tracked separately)
- contracts/hello_go/ (unused standalone example)

Kept contracts/counter/ and contracts/name_registry/ as vm-test fixtures
(referenced by vm/vm_test.go; NOT production contracts).

Docs refactor:
- docs/README.md — new top-level index with cross-references
- docs/quickstart.md — rewrite around single-node as primary path
- docs/node/README.md — full rewrite, all CLI flags, schema table
- docs/api/README.md — add /api/well-known-version, /api/update-check
- docs/contracts/README.md — split native (Go) vs WASM (user-deployable)
- docs/update-system.md — new, full 5-layer update system design
- README.md — link into docs/, drop CHANGELOG/client-app references

Build-time version system (inherited from earlier commits this branch):
- node --version / client --version with ldflags-injected metadata
- /api/well-known-version with {build, protocol_version, features[]}
- Peer-version gossip on dchain/version/v1
- /api/update-check against Gitea release API
- deploy/single/update.sh with semver guard + 15-min systemd jitter
2026-04-17 14:37:00 +03:00
..
2026-04-17 14:16:44 +03:00
2026-04-17 14:16:44 +03:00
2026-04-17 14:16:44 +03:00

Smart contracts

DChain поддерживает два типа контрактов — native Go (запечены в бинарь ноды) и WASM (деплоятся on-chain через DEPLOY_CONTRACT tx).

Native (Go, скомпилированы в бинарь)

Живут в blockchain/native*.go. Видны как native:<name>, работают на каждой ноде идентично (тот же Go-код — нет WASM-drift'а).

Контракт ID Назначение
username_registry native:username_registry @username ↔ pubkey, плата 10_000 µT, min 4 символа

Клиент находит native:username_registry автоматически через /api/well-known-contracts — без конфигурирования.

WASM (user-deployable)

Деплоятся любым обладателем баланса через client deploy-contract. Исполняются в wazero runtime с gas limit и set'ом host-функций.

Контракт Назначение Key features
governance On-chain параметры Propose/approve workflow, admin role
auction English auction Token escrow, автоматический refund, settle
escrow Двусторонний escrow Dispute/resolve, admin arbitration

Исходники + WASM-артефакты — в contracts/<name>/. SDK для написания новых контрактов — ../development/README.md.

Деплой WASM

Контракты не деплоятся автоматически — это выбор оператора. Скрипт-хелпер:

./scripts/deploy_contracts.sh     # деплоит auction + escrow + governance из CWD

Или вручную:

client deploy-contract \
  --key node.json \
  --wasm contracts/auction/auction.wasm \
  --abi  contracts/auction/auction_abi.json \
  --node http://localhost:8080

После деплоя contract_id печатается в stdout — сохраните его.

Вызов контракта (любой типа)

client call-contract \
  --key      node.json \
  --contract <contract_id_or_native:name> \
  --method   <method> \
  --arg      <string_arg>     # можно повторять
  --arg64    <uint64_arg>     # числовые аргументы
  --gas      20000             # reasonable default; read-only методы: 5000
  --amount   0                 # tx.Amount (для методов с платой — см. username_registry)
  --node     http://localhost:8080

Contract treasury

У каждого WASM-контракта есть ownerless treasury по адресу hex(sha256(contractID + ":treasury")). Private-key не существует, списывать можно только через host function transfer из самого контракта. Используется auction (escrow bids) и escrow (held amount).

Просмотр state / логов

# Конкретный ключ state
curl -s http://localhost:8080/api/contracts/<id>/state/<key>

# Последние N логов контракта
curl -s "http://localhost:8080/api/contracts/<id>/logs?limit=20" | jq .

# Или через Explorer UI
open http://localhost:8080/contract?id=<id>