Files
ad75fe706f store: sell and register SimpleX names (#7979)
* core: add prepaid name codes and length bounds

* store: run the names migration after badges

* store: issue and revoke prepaid name codes

* store: document issuing prepaid name codes

* store: move the ABI helpers to Names.Abi

* store: read the [names] and [chain] settings

* store: add the names chain client and reads

* store: refuse group name codes while names are off

* store: search names and preview links

* store: serve each site on its own port

* scripts: deploy the badges and names sites

* store: document search and the two sites

* store: add the drop_taken_codes migration

* store: read the names codes_only setting

* store: add the names store and order signatures

* store: take name orders by card, crypto or code

* store: document name orders and codes-only

* store: add the names transaction sender

* store: commit and register queued orders

* store: reveal and retry an owner's order

* store: document the gas key

* store: add the name balance migrations

* store: read crypto units, rates and confirmations

* store: keep a taken order's money as a balance

* store: spend a balance on another name

* store: record refunds with //refund

* store: document balances and refunds

* store: add the agreed terms migration

* store: read the terms and community names

* store: answer community and terms in search

* store: sign and store the agreed terms

* store: document the terms and community names

* store: add the invoiced units migration

* store: read the crypto an invoice asks

* store: credit late and overpaid crypto by share

* store: document crediting late crypto by share

* store: add the record changes migration

* store: find an owner's orders and move one

* store: relay owners' link edits on chain

* store: document link edits

* store: move isLoopbackHost to Config

* store: trust dev issuer keys on the local chain

* scripts: build the names site from a submodule

* scripts: add the dev setup and contract run

* store: document the dev setup and names image

* store: send a Stripe idempotency key for names

* tests: wait until a relay lets go of its edit

* store: refuse a link edit deadline under 10 min

* store: count reverted link edits in the year limit

* store: require https for a remote chain node

* store: refuse zero chain confirmations

* store: set up the dev stack from the names branch

* store: rerun a failed unpaid cleanup next pass

* store: never replace a succeeded Stripe intent

* store: refuse an ini setting written as key: value

* store: note the webapp submodule's pinned branch

* store: document confirmLanded judging by ownerOf

* store: update the names webapp submodule

* store-service: register names under the name policy, every name accepting its terms on chain (#7889)

* store: accept each name's terms on chain under the name policy

* ci: run the reduced build on sh/names-deploy

* store: address review: policy re-read, terms reads and startup log

* store: never credit an unconfirmed extra

* store: alert money sent to a paid name invoice

* store: refuse to start on another chain's node

* store: keep orders while the allowance is used up

* store: replace a stalled transaction after 3 blocks

* store: judge a name taken at confirmation depth

* store: bind the template's listener to loopback

* store: scan only the ids of active name orders

* store: refuse unknown [names] and [chain] settings

* store: fetch the webapp submodule in upgrade steps

* store: delete definitions only tests use

* store: lock only name invoices at settlement

* store: retry an unexpired commitment as usual

* store: share the helpers defined twice

* store: test route limits on the running service

* store: fix tests that could not fail

* ci: test the store service on Postgres

* store: count IPv6 clients by their /64

* store: sweep invoices read alone past a list cap

* store: cap checkouts of all clients together

* store: cap the long polls held at once

* store: stop the old badge project at upgrade

* store: keep search lookups free of previews

* store: read the ini as UTF-8 in any locale

* ci: run Postgres store tests in a UTF-8 locale

* store: cap the transactions one order sends

* store: cancel a card intent after three declines

* store: refuse a name price under a cent

* store: send each transaction with gas headroom

* store: cap searches and read terms once per block

* store: never log the group join link

* store: mask the database password at startup

* store: run one instance per database

* store: limit name codes to admins, 100 a day

* store: refuse HighSpeed settlement with names

* store: no unverified receipts with a trusted key

* store: cap the log lines of refused webhooks

* store: check Apple certificates at the signed date

* store: refuse a malformed Stripe publishable key

* store: check the owner before a refund

* store: fold the names migrations into one

* store: read onion name links through the proxy

* store: refund money after paid once confirmed

* store: limit the allowance wait to a dry run

* store: bind loopback when upgrading

* ci: cache and widen the store Postgres job

* store: fix stale and duplicate names tests

* store: fix the submodule path in the upgrade

* store: refuse unpaid name codes on the CLI

* store: apply the review's names test list

* store: finish the review's names test list

* store: restore the base registration tests

* store: pass link hosts that do not resolve here

* store: refuse a move once its sends are used up

* store: take the shared checkout at the provider

* store: hold a search slot for chain reads only

* store: state which refunds are safe on a reference

* store: check a failed order's name before refusing its move (#8060)

* store: test and document the shared checkout cap for name orders

* store: check a failed order's name on chain before refusing its move

* store: test name links whose host lookup fails

* store: test that a search holds its slot through the chain reads only

* store: restore the signed transaction check in the chain tests

* store: remove the chain tests' copy of the signed transaction check

* store: correct the search slot texts and the README's balance endpoints

* docs: system and sequence diagrams of the names service (#8068)

---------

Co-authored-by: sh-agents <350651734+sh-agents@users.noreply.github.com>
Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
Co-authored-by: brenzi-agent <brenzi-agent@brenzi.ch>
Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
2026-11-07 10:45:19 +00:00

157 lines
5.3 KiB
Bash
Executable File

#!/bin/sh
# The local chain of compose.dev.yml. Runs in the webapp's dev image, which has anvil, node, the deploy script and the
# compiled contracts.
# chain.sh anvil with its state kept in $CHAIN_DIR, the names contracts deployed on the first start,
# the texts of their terms' links in $CHAIN_DIR/terms served on 127.0.0.1:8098,
# and $CONFIG_DIR/store_service.ini written for them unless it exists
# chain.sh topup [address] [eth] sets an account's balance, by default the service key's account to 10000 ETH
set -eu
CHAIN_DIR="${CHAIN_DIR:-/chain}"
RPC_PORT="${RPC_PORT:-8545}"
ANVIL="${ANVIL:-anvil}"
WEBAPP_DIR="${WEBAPP_DIR:-/repo/webapp}"
RPC_URL="http://127.0.0.1:$RPC_PORT"
DEPLOYMENT="$CHAIN_DIR/deployment.json"
CONFIG_DIR="${CONFIG_DIR:-/config}"
CONFIG="$CONFIG_DIR/store_service.ini"
# the store service's user, which must own its config
USER_UID="${USER_UID:-1000}"
USER_GID="${USER_GID:-1000}"
# A public test key, like anvil's: made once with `simplex-chat badge keygen`. The service trusts it only through
# [issuer] dev_keys, which it accepts only on chain 31337, and refuses it at an index clients trust (1 to 8).
DEV_ISSUER_INDEX=999
DEV_ISSUER_SECRET=Grc_c1bKCSa3U8mMwRy6XNTJNwSveJi332wAqyyCy2o=
export TERMS_DIR="$CHAIN_DIR/terms"
# compose's healthcheck waits for this file, written once the contracts are on the running chain
READY="$CHAIN_DIR/ready"
# the dumps are taken this often and on exit, so a restart keeps the contracts and every name registered on them
STATE_INTERVAL_SECONDS=10
# only a few recent states stay in memory; without this anvil writes every old state under ~/.foundry
MEMORY_STATES=8
rpc() {
curl -fs -X POST -H 'content-type: application/json' --data "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"$1\",\"params\":$2}" "$RPC_URL"
}
if [ "${1:-}" = topup ]; then
address="${2:-$(node -p "require('$DEPLOYMENT').registrar")}"
eth="${3:-10000}"
wei=$(node -p "'0x' + (BigInt('$eth') * 10n ** 18n).toString(16)")
rpc anvil_setBalance "[\"$address\", \"$wei\"]" > /dev/null
echo "$address now has $eth ETH"
exit
fi
STATE="$CHAIN_DIR/state.json"
# anvil rewrites its dump in place, so a kill during a write leaves it cut short. The good copy, taken at each start and
# clean stop, replaces it; with no good copy the chain starts over, and the contracts deploy again at the same addresses.
GOOD_STATE="$STATE.good"
parses() {
node -e 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"))' "$1" 2> /dev/null
}
rm -f "$READY"
if [ -e "$STATE" ] && ! parses "$STATE"; then
mv "$STATE" "$STATE.broken"
if [ -e "$GOOD_STATE" ] && parses "$GOOD_STATE"; then
cp "$GOOD_STATE" "$STATE"
echo "the chain's state was cut short; restored its last good copy (cut file: $STATE.broken)"
else
echo "the chain's state was cut short and there is no good copy; starting a fresh chain (cut file: $STATE.broken)"
fi
fi
if [ -e "$STATE" ]; then cp "$STATE" "$GOOD_STATE"; fi
"$ANVIL" --chain-id 31337 --host 127.0.0.1 --port "$RPC_PORT" --block-time 1 --prune-history "$MEMORY_STATES" \
--state "$STATE" --state-interval "$STATE_INTERVAL_SECONDS" --silent &
anvil_pid=$!
# anvil writes its last dump when it stops, so a stop or a failed deploy stops it, waits for it, and keeps the dump as
# the good copy once it parses
stop() {
kill "$anvil_pid" 2> /dev/null
wait "$anvil_pid" || true
if [ -e "$STATE" ] && parses "$STATE"; then cp "$STATE" "$GOOD_STATE"; fi
}
trap stop EXIT INT TERM
until rpc eth_chainId '[]' > /dev/null; do sleep 0.2; done
(cd "$WEBAPP_DIR" && node dev/serve-terms.ts) &
deployed() {
[ -s "$DEPLOYMENT" ] || return 1
controller=$(node -p "require('$DEPLOYMENT').controller")
! rpc eth_getCode "[\"$controller\", \"latest\"]" | grep -q '"result":"0x"'
}
if deployed; then
echo "the contracts are already on the chain ($DEPLOYMENT)"
else
(cd "$WEBAPP_DIR" && RPC_URL="$RPC_URL" LOCAL_CHAIN_OUT="$DEPLOYMENT" node dev/deploy.ts)
fi
field() {
node -p "require('$DEPLOYMENT').$1"
}
write_config() {
tmp="$CONFIG.tmp"
rm -f "$tmp"
(umask 077 && cat > "$tmp" <<INI)
; written by dev/chain.sh for the local chain on its first start, and never rewritten
[listener]
host = 127.0.0.1
badges_port = 8080
names_port = 8081
serve_webapp = on
trust_forwarded_for = on
[poll]
waiting_seconds = 3
idle_seconds = 60
[issuer]
index = $DEV_ISSUER_INDEX
private_key = $DEV_ISSUER_SECRET
dev_keys = $DEV_ISSUER_INDEX:$DEV_ISSUER_SECRET
[names]
tld = $(field tld)
[chain]
rpc_url = $(field rpcUrl)
chain_id = $(field chainId)
controller = $(field controller)
sponsor = $(field sponsor)
base_registrar = $(field baseRegistrar)
resolver = $(field resolver)
service_key = $(field registrarKey)
confirmations = 1
[dev]
accept_unverified_store_receipts = off
; dev_keys accepts only Stripe test keys: sk_test_ or rk_test_, and pk_test_
;[stripe]
;secret_key = rk_test_replace-me
;publishable_key = pk_test_replace-me
;webhook_secret = whsec_replace-me
; dev_keys accepts only a BTCPay on loopback: 127.0.0.1, ::1 or localhost
;[btcpay]
;host = https://127.0.0.1
;api_key = replace-me
;store_id = replace-me
;webhook_secret = replace-me
INI
chown "$USER_UID:$USER_GID" "$CONFIG_DIR" "$tmp"
chmod 700 "$CONFIG_DIR"
mv "$tmp" "$CONFIG"
echo "wrote $CONFIG"
}
if [ -e "$CONFIG" ]; then
echo "kept $CONFIG"
else
write_config
fi
touch "$READY"
wait "$anvil_pid"