TES-Coin v42 - install and setup
================================

What you need
-------------
- Ubuntu 20.04 / 22.04 / 24.04 / 26.04, x86-64 or arm64
- About 2 GB RAM, a few GB of free disk
- A user that can use sudo


1. Install
----------
Copy tes-coin-v42.tar.gz to the server, then:

    sudo true
    tar xzf tes-coin-v42.tar.gz
    cd tes
    sudo ./install.sh                 # node + pool + website
  or
    sudo ./install.sh --node-only     # node + wallet only (no pool)

The installer builds everything, tests it, installs it and starts it.
When it finishes it prints a summary (ports, addresses, log commands).
It deletes the unpacked folder and the .tar.gz afterwards
(add --keep-source to keep them).

Useful options (also work when you run it again later):
    --addnode HOST:PORT     an extra TES node to connect to
    --p2p-port N            node-to-node port   (default 18180)
    --wallet-port N|off     public wallet port  (default 18182)
    --fee-address 0x...|off where this node's fees go (see section 3)

Running the installer again is safe: it upgrades the programs and
keeps your wallets, chain data and settings.


2. Check it works
-----------------
    sudo -H tes-wallet info           # height, peers, network
    journalctl -u tesd -f             # node log   (Ctrl+C to stop)
    journalctl -u tespool -f          # pool log   (pool installs)
    tesd -version


3. The settings file: /etc/tes/tes.env
--------------------------------------
All settings for the node AND the pool are in one file:

    sudo nano /etc/tes/tes.env

After saving (Ctrl+O, Enter, Ctrl+X), restart:

    sudo systemctl restart tesd                 # node-only install
    sudo systemctl restart tesd tespool         # node + pool install

Node settings
    NETWORK=mainnet
    P2P_LISTEN=0.0.0.0:18180        port other nodes connect to
    RPC_LISTEN=127.0.0.1:18181      local control port - keep it on 127.0.0.1
    ADDNODE=                        extra nodes, comma separated (optional)

Node income (what your node earns)
    NODE_NAME="New TES Pool"        name wallets show for your node
    NODE_FEE_ADDRESS=0x4e5de478d3936b53cd505138a537a9ee47c0de02
                                    the TES address that receives BOTH node fees.
                                    Default = the TES project address.
                                    PUT YOUR OWN ADDRESS HERE to get the fees
                                    yourself. Empty = your node charges nothing.
    NODE_BLOCK_FEE_PERCENT=0.2      % of each block reward a pool pays your node
                                    when that pool mines through it
                                    (0.2% of 50 TES = 0.1 TES per block)
    NODE_TX_FEE=0.1                 TES a wallet pays you per send through
                                    your node (0 = none; smallest 0.00000001,
                                    largest 10). Restart tesd after changing.
    WALLET_LISTEN=0.0.0.0:18182     public wallet port. Empty = off.

    Notes:
    - The block fee is only earned if a pool gets its work from your node.
    - Wallets v40+ pay the tx fee that getnodeinfo reports on every send,
      on any port. The node itself only refuses unpaid sends on the public
      wallet port (18182), so pool payouts through 127.0.0.1 keep working.

Pool settings (ignored on a --node-only install)
    POOL_NAME="TES pool"            YOUR POOL'S NAME - shown on the website
    STRATUM_LISTEN=0.0.0.0:4334     MINING PORT - miners connect here
    POOL_WEB_LISTEN=0.0.0.0:8090    pool website port
    POOL_FEE_ADDRESS=0x4e5de478d3936b53cd505138a537a9ee47c0de02
                                    address that receives the pool fee.
                                    Default = the TES project (donate) address.
                                    PUT YOUR OWN ADDRESS HERE to get the fee.
    POOL_FEE_PERCENT=1.0            pool fee in %
    POOL_START_DIFF=5000            starting share difficulty
    POOL_PAYOUT=pplns               pplns (shared) or solo (finder takes all)
    PUBLIC_HOST=                    name people reach your server by (optional)
    POOL_THEME=ledger               website look (section 7)

    To change the mining port, e.g. to 3333:
        STRATUM_LISTEN=0.0.0.0:3333
    then restart tespool and open that port (section 4).

    After any change in this file:
        sudo systemctl restart tespool

Your own wallet address
    tes-wallet new                    # make a wallet (choose a passphrase)
    tes-wallet address                # show its address
    Back up the wallet file (~/.tes/wallet.json) somewhere safe.
    Never give the file or passphrase to anyone.


4. Open the ports
-----------------
| Port  | What                          | Open to internet?          |
|-------|-------------------------------|----------------------------|
| 18180 | node-to-node (P2P)            | YES - needed               |
| 18182 | public wallet port (tx fees)  | YES, if you want wallets   |
|       |                               | to use your node           |
| 18181 | local control (RPC)           | NO - never                 |
| 4334  | pool mining (stratum)         | YES, pool installs         |
| 8090  | pool website                  | YES, pool installs         |

Firewall on the server (ufw):
    sudo ufw allow 18180/tcp
    sudo ufw allow 18182/tcp
    sudo ufw allow 4334/tcp           # pool only
    sudo ufw allow 8090/tcp           # pool only

Home router: forward the same ports (TCP) to this server's LAN IP.
If you changed a port in tes.env, open the new number instead.
Several nodes behind one public IP need different port numbers
(e.g. 28180/28182 for the second node: --p2p-port 28180 --wallet-port 28182).

Test from OUTSIDE your network (e.g. a phone on mobile data):
    nc -vz YOUR_PUBLIC_IP 18180


5. Miners
---------
    xmrig -a rx/0 -o YOUR_SERVER:4334 -u YOUR_TES_ADDRESS.rig1 -p x


6. Uninstall / stop
-------------------
    sudo systemctl disable --now tespool tesd
Chain data is in /var/lib/tes, settings in /etc/tes, wallets in ~/.tes.


7. Your pool's website
----------------------
The pool serves its own website on port 8090 (POOL_WEB_LISTEN).
Open http://YOUR-SERVER:8090 to see it.

Change the pool's name
    sudo nano /etc/tes/tes.env
    change the line, keep the quotes:
        POOL_NAME="My TES Pool"
    sudo systemctl restart tespool
The name then shows in the top-left corner, the big heading on the
dashboard and the browser tab, on every page. The pool fee, fee address
and payout type on the dashboard also come from tes.env, so they are
always right - you never edit them in the web pages.

Pick the website's look
    sudo nano /etc/tes/tes.env      ->   POOL_THEME=aurora
    sudo systemctl restart tespool
    Then reload the page (Ctrl+Shift+R).
        ledger     light paper, black ink, square boxes, typewriter letters
        dark       dark grey with green, rounded (the original TES look)
        terminal   black screen, green glowing text, like an old computer
        aurora     night sky with violet/blue glow, see-through cards
        clean      bright white, soft shadows, blue - plain and businesslike
        sunset     warm plum background, pink and gold, round buttons
    Make your own: copy one, e.g.
        sudo cp /var/www/tescoin/themes/dark.css /var/www/tescoin/themes/mine.css
    edit the colours at the top, and set POOL_THEME=mine.

Change the text or look of the pages
    The pages are in WWW_DIR (default /var/www/tescoin):
        index.html  about.html  download.html  wallet.html
        tespools.html  xdagpools.html  eticapools.html
        app.css (layout)   themes/ (the looks above)
        app.js (dashboard) favicon.svg (tab icon)
    Edit them with   sudo nano /var/www/tescoin/about.html
    Changes show on the next page reload, no restart needed.
    A file you delete comes back as the built-in copy.
    Tip: copy a file before you edit it, e.g.
        sudo cp /var/www/tescoin/about.html /var/www/tescoin/about.html.bak
    Upgrading keeps any page you edited; the new version's copy is put
    in /var/www/tescoin/.updates/ and the installer tells you which.

Download page
    The Download page is the same on every TES pool: its buttons always
    point to the official copies at
        https://tescoin.xdagreef.org/download/   (main)
        https://www.tescoin.org/download/        (Mirror button)
    so you never need to put wallet files on your own server.

Change the mining address in the "Connect" box
    The box shows  PUBLIC_HOST : mining port (from STRATUM_LISTEN).
    sudo nano /etc/tes/tes.env
        PUBLIC_HOST=pool.example.com          name only, port from STRATUM_LISTEN
      or
        PUBLIC_HOST=pool.example.com:3333     name and port, if your router
                                              forwards a different outside port
    sudo systemctl restart tespool
    Empty PUBLIC_HOST = the name the visitor typed in their browser.
    The same address is used on the Getting started page and in the
    xmrig / SRBMiner commands everywhere on the site.
    For https (a padlock), put a web server such as Caddy in front of
    port 8090.

8. The wallet menu
------------------
The wallet now has a menu built in. Run `tescoinwallet` (or `tes-wallet`
with no arguments) for balance, send, receive with QR, history, address
book, wallets, node settings and a live block ticker. The installer links
/usr/local/bin/tescoinwallet to tes-wallet, and the download folder offers
the same one-file wallet as tescoin-wallet-linux-x64 / -arm64.
Settings per user: ~/.tes/wallet.conf (NODE, BACKUP_NODE, WALLET).
Defaults: NODE=http://tescoin.xdagreef.org:18182,
BACKUP_NODE=http://wnode1.russ-office.com:18182.
