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
This commit is contained in:
@@ -1,59 +1,85 @@
|
||||
# Production Smart Contracts
|
||||
# Smart contracts
|
||||
|
||||
DChain поставляется с четырьмя production-контрактами, задеплоенными из genesis-кошелька.
|
||||
DChain поддерживает **два типа** контрактов — native Go (запечены в
|
||||
бинарь ноды) и WASM (деплоятся on-chain через `DEPLOY_CONTRACT` tx).
|
||||
|
||||
## Обзор
|
||||
## Native (Go, скомпилированы в бинарь)
|
||||
|
||||
| Контракт | Назначение | Ключевые фичи |
|
||||
|---------|-----------|--------------|
|
||||
| [username_registry](username_registry.md) | Username ↔ адрес | Тарифная сетка, treasury fees, reverse lookup |
|
||||
Живут в `blockchain/native*.go`. Видны как `native:<name>`, работают на
|
||||
каждой ноде идентично (тот же Go-код — нет WASM-drift'а).
|
||||
|
||||
| Контракт | ID | Назначение |
|
||||
|----------|----|-----------|
|
||||
| [username_registry](username_registry.md) | `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](governance.md) | On-chain параметры | Propose/approve workflow, admin role |
|
||||
| [auction](auction.md) | English auction | Token escrow, автоматический refund, settle |
|
||||
| [escrow](escrow.md) | Двусторонний escrow | Dispute/resolve, admin arbitration |
|
||||
|
||||
## Деплой
|
||||
Исходники + WASM-артефакты — в `contracts/<name>/`. SDK для написания
|
||||
новых контрактов — [../development/README.md](../development/README.md).
|
||||
|
||||
## Деплой WASM
|
||||
|
||||
Контракты **не деплоятся автоматически** — это выбор оператора.
|
||||
Скрипт-хелпер:
|
||||
|
||||
```bash
|
||||
docker compose --profile deploy run --rm deploy
|
||||
./scripts/deploy_contracts.sh # деплоит auction + escrow + governance из CWD
|
||||
```
|
||||
|
||||
Все 4 контракта деплоятся автоматически. ID сохраняются в `/tmp/contracts.env`.
|
||||
|
||||
## Вызов контракта
|
||||
Или вручную:
|
||||
|
||||
```bash
|
||||
docker exec node1 client call-contract \
|
||||
--key /keys/node1.json \
|
||||
--contract <CONTRACT_ID> \
|
||||
--method <METHOD> \
|
||||
--arg <STRING_ARG> # строковый аргумент (можно несколько)
|
||||
--arg64 <UINT64_ARG> # числовой аргумент uint64
|
||||
--gas <GAS_LIMIT> # рекомендуется 20000 для записи, 5000 для чтения
|
||||
--node http://node1:8080
|
||||
client deploy-contract \
|
||||
--key node.json \
|
||||
--wasm contracts/auction/auction.wasm \
|
||||
--abi contracts/auction/auction_abi.json \
|
||||
--node http://localhost:8080
|
||||
```
|
||||
|
||||
## Contract Treasury
|
||||
После деплоя `contract_id` печатается в stdout — сохраните его.
|
||||
|
||||
У каждого контракта есть **ownerless treasury address** — `hex(sha256(contractID + ":treasury"))`.
|
||||
Это эскроу-адрес без private key. Только сам контракт может снять с него деньги через host function `transfer`.
|
||||
|
||||
Используется в `auction` и `escrow` для хранения заблокированных токенов.
|
||||
|
||||
## Просмотр состояния
|
||||
## Вызов контракта (любой типа)
|
||||
|
||||
```bash
|
||||
# Через REST API
|
||||
curl http://localhost:8081/api/contracts/<ID>/state/<key>
|
||||
|
||||
# Через Explorer
|
||||
open http://localhost:8081/contract?id=<ID>
|
||||
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 / логов
|
||||
|
||||
```bash
|
||||
# REST
|
||||
curl "http://localhost:8081/api/contracts/<ID>/logs?limit=20"
|
||||
# Конкретный ключ state
|
||||
curl -s http://localhost:8080/api/contracts/<id>/state/<key>
|
||||
|
||||
# Explorer → вкладка Logs
|
||||
# Последние N логов контракта
|
||||
curl -s "http://localhost:8080/api/contracts/<id>/logs?limit=20" | jq .
|
||||
|
||||
# Или через Explorer UI
|
||||
open http://localhost:8080/contract?id=<id>
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user