fix: verify-deposit blockchain verification and wallet-based auth

- Drop auth.users FK constraints for wallet-based authentication
- Fix deferrable unique constraint on blockchain_tx_hash (ON CONFLICT compat)
- Rewrite block search: HTTP RPC + blake2b instead of WS-only @pezkuwi/api
- Add blockNumber hint for faster verification of older transactions
- Normalize SS58/hex addresses via base58 for reliable comparison
- DepositModal captures approximate block number after tx submission
This commit is contained in:
2026-02-23 12:16:15 +03:00
parent 7183e659c6
commit cbf98e4dc9
4 changed files with 297 additions and 84 deletions
@@ -0,0 +1,46 @@
-- Migration: Drop auth.users FK constraints for wallet-based authentication
-- Since we moved from Supabase Auth to on-chain wallet verification,
-- user_id is now a deterministic UUID derived from wallet address (UUID v5)
-- and no longer corresponds to auth.users entries.
-- 1. Drop FK on p2p_deposit_withdraw_requests.user_id
ALTER TABLE public.p2p_deposit_withdraw_requests
DROP CONSTRAINT IF EXISTS p2p_deposit_withdraw_requests_user_id_fkey;
-- 2. Drop FK on p2p_deposit_withdraw_requests.processed_by
ALTER TABLE public.p2p_deposit_withdraw_requests
DROP CONSTRAINT IF EXISTS p2p_deposit_withdraw_requests_processed_by_fkey;
-- 3. Drop FK on user_internal_balances.user_id
ALTER TABLE public.user_internal_balances
DROP CONSTRAINT IF EXISTS user_internal_balances_user_id_fkey;
-- 4. Drop FK on p2p_balance_transactions.user_id (if table exists)
DO $$ BEGIN
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'p2p_balance_transactions') THEN
ALTER TABLE public.p2p_balance_transactions DROP CONSTRAINT IF EXISTS p2p_balance_transactions_user_id_fkey;
END IF;
END $$;
-- 5. Drop FK on p2p_escrow_transactions (if table exists)
DO $$ BEGIN
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'p2p_escrow_transactions') THEN
ALTER TABLE public.p2p_escrow_transactions DROP CONSTRAINT IF EXISTS p2p_escrow_transactions_buyer_id_fkey;
ALTER TABLE public.p2p_escrow_transactions DROP CONSTRAINT IF EXISTS p2p_escrow_transactions_seller_id_fkey;
END IF;
END $$;
-- 6. Drop FK on p2p_orders (if table exists)
DO $$ BEGIN
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'p2p_orders') THEN
ALTER TABLE public.p2p_orders DROP CONSTRAINT IF EXISTS p2p_orders_user_id_fkey;
ALTER TABLE public.p2p_orders DROP CONSTRAINT IF EXISTS p2p_orders_merchant_id_fkey;
END IF;
END $$;
-- 7. Drop FK on p2p_ads (if table exists)
DO $$ BEGIN
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'p2p_ads') THEN
ALTER TABLE public.p2p_ads DROP CONSTRAINT IF EXISTS p2p_ads_merchant_id_fkey;
END IF;
END $$;
@@ -0,0 +1,18 @@
-- Fix: Make blockchain_tx_hash unique constraint non-deferrable
-- PostgreSQL ON CONFLICT does not support deferrable constraints as arbiters
-- Drop the deferrable constraint (actual name from migration 016)
ALTER TABLE public.p2p_deposit_withdraw_requests
DROP CONSTRAINT IF EXISTS p2p_deposit_withdraw_requests_tx_hash_unique;
-- Also try the auto-generated name pattern
ALTER TABLE public.p2p_deposit_withdraw_requests
DROP CONSTRAINT IF EXISTS unique_blockchain_tx_hash;
-- Also try the default PostgreSQL naming convention
ALTER TABLE public.p2p_deposit_withdraw_requests
DROP CONSTRAINT IF EXISTS p2p_deposit_withdraw_requests_blockchain_tx_hash_key;
-- Recreate as non-deferrable (standard UNIQUE)
ALTER TABLE public.p2p_deposit_withdraw_requests
ADD CONSTRAINT p2p_deposit_withdraw_requests_tx_hash_unique UNIQUE (blockchain_tx_hash);