# On-chain TX verification for BSC service bots (stdlib only)

Recipe used by buyer-facing bots to verify what a customer claims. Uses plain
`urllib` against a public BSC RPC (`https://bsc-dataseed.binance.org`), no
web3 dependency needed.

## JSON-RPC helper

```python
def bsc(method, params):
    req = urllib.request.Request(RPC,
        data=json.dumps({"jsonrpc": "2.0", "id": 1, "method": method,
                          "params": params}).encode(),
        headers={"Content-Type": "application/json"})
    return json.loads(urllib.request.urlopen(req, timeout=30).read())
```

`bsc-dataseed.binance.org` rate-limits at high frequency; for watch loops
alternate seeds or use a fallback RPC. Public nodes return `result: null`
while a TX is pending — tell the user "birkaç saniye sonra tekrar dene".

## Parse a transaction

- `eth_getTransactionReceipt` → `status` must be `0x1`, else failed.
- `eth_getTransactionByHash` → `value` (hex wei / 1e18) = BNB spent by the
  sender — use this as the payout basis, never a user-typed amount.
- Transfer logs: `log.address == token contract`; ERC-20 Transfer signature
  is a `topics[0]` starting with `0xddf252ad` with 3 topics:
  - from = `"0x" + topics[1][-40:]`
  - to   = `"0x" + topics[2][-40:]`
  - amount = `int(log["data"], 16) / 10**decimals`

## Direction rules for a buyback wizard

- **Buy step:** valid = token transfer FROM the PancakeSwap pair address TO
  the buyer. The `to` of that transfer is the buyer's wallet — remember it in
  the user state; the payout goes exactly there.
- **Sell-back step:** valid = token transfer TO the program's buyback wallet
  from anywhere. From this, ledger entry: buyer, buy TX, sell TX, token
  amount, BNB spent (from buy TX), `payout = bnb_spent * 1.10`.
- Route TX-hash messages by the user's current wizard step — the same `0x…`
  string means buy-proof in step 2 and sell-proof in step 3.
