Bridging Scala (XLA) to Hive Engine

We’ve been building a bridge between Scala (XLA) — a CPU-mined privacy coin — and the Hive Engine DEX. The goal is to make it possible for miners and holders of XLA to swap directly into Hive Engine tokens, creating liquidity, access, and new use cases.

🐍 The Python Swap Monitor

Here’s the full code for swap_monitor.py. This script talks to a running Scala wallet RPC, creates subaddresses for swap requests, and monitors for confirmed deposits. Once a deposit is confirmed, it’s logged and can later trigger Hive Engine token issuance.

import requests
import time
import json
import os
from datetime import datetime, timedelta

# CONFIGURATION
WALLET_RPC_URL = "http://localhost:11898/json_rpc"  # Scala wallet RPC endpoint
ACCOUNT_INDEX = 0
CONFIRMATIONS_REQUIRED = 10
SWAP_DB = "swap_requests.json"

# --- Helpers ---
def call_wallet_rpc(method, params=None):
    payload = {
        "jsonrpc": "2.0",
        "id": "0",
        "method": method,
        "params": params or {}
    }
    try:
        response = requests.post(WALLET_RPC_URL, json=payload)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        print(f"Wallet RPC error: {e}")
        return None

def load_db():
    if os.path.exists(SWAP_DB):
        with open(SWAP_DB, "r") as f:
            return json.load(f)
    return {}

def save_db(db):
    with open(SWAP_DB, "w") as f:
        json.dump(db, f, indent=2)

# --- Persistent Subaddress Assignment ---
def get_or_create_user_subaddress(dest_chain, dest_account):
    db = load_db()
    # Use a key based on dest_chain and dest_account
    user_key = f"{dest_chain}:{dest_account}"
    # Check if subaddress already exists for this user
    for req in db.values():
        if req.get("user_key") == user_key:
            return {"subaddr_index": req["subaddr_index"], "subaddr": req["subaddr"]}
    # If not, create a new subaddress
    label = user_key
    params = {"account_index": ACCOUNT_INDEX, "label": label}
    result = call_wallet_rpc("create_address", params)
    if not result or "result" not in result:
        print("Failed to create subaddress")
        return None
    subaddr_index = result["result"]["address_index"]
    subaddr = result["result"]["address"]
    # Store mapping for future reuse
    db[f"user_{user_key}"] = {
        "user_key": user_key,
        "subaddr_index": subaddr_index,
        "subaddr": subaddr,
        "dest_chain": dest_chain,
        "dest_account": dest_account
    }
    save_db(db)
    return {"subaddr_index": subaddr_index, "subaddr": subaddr}

# --- Swap Request Creation ---
def create_swap_request(dest_chain, dest_account, min_amount, expiry_minutes=30):
    # Get persistent subaddress for user/account
    user_subaddr = get_or_create_user_subaddress(dest_chain, dest_account)
    if not user_subaddr:
        return None
    subaddr_index = user_subaddr["subaddr_index"]
    subaddr = user_subaddr["subaddr"]
    request_id = f"swap_{int(time.time())}_{subaddr_index}"
    expiry = (datetime.utcnow() + timedelta(minutes=expiry_minutes)).isoformat()
    # Store mapping
    db = load_db()
    db[request_id] = {
        "subaddr_index": subaddr_index,
        "subaddr": subaddr,
        "dest_chain": dest_chain,
        "dest_account": dest_account,
        "min_amount": min_amount,
        "expiry": expiry,
        "confirmed": False,
        "in_txid": None,
        "in_amount": None,
        "out_txid": None,
        "out_amount": None
    }
    save_db(db)
    return {"request_id": request_id, "deposit_address": subaddr, "expiry": expiry}

# --- Monitor for Confirmed Deposits ---
def monitor_swaps():
    db = load_db()
    # Get all subaddress indices to watch
    subaddr_indices = [v["subaddr_index"] for v in db.values() if not v["confirmed"]]
    if not subaddr_indices:
        print("No pending swaps.")
        return
    params = {"account_index": ACCOUNT_INDEX, "in": True, "filter_by_height": False}
    result = call_wallet_rpc("get_transfers", params)
    if not result or "result" not in result:
        print("No transfers found.")
        return
    for tx in result["result"].get("in", []):
        if tx.get("confirmations", 0) < CONFIRMATIONS_REQUIRED:
            continue
        subaddr_index = tx.get("subaddr_index")
        for req_id, req in db.items():
            if req["subaddr_index"] == subaddr_index and not req["confirmed"]:
                req["confirmed"] = True
                req["in_txid"] = tx["txid"]
                req["in_amount"] = tx["amount"]
                print(f"Swap {req_id} funded: {tx['amount']} XLA received.")
    save_db(db)

if __name__ == "__main__":
    # Example usage: create a swap request
    # swap = create_swap_request("hive", "paulmoon410", min_amount=1)
    # print(swap)

    # Monitor swaps (run in a loop or scheduler)
    while True:
        monitor_swaps()
        time.sleep(30)

⚙️ How It Works

Each swap request creates a unique subaddress for the user.

Deposits into that subaddress are tied to the destination chain + account (for example, Hive paulmoon410).

Once confirmed, the script records the transaction as “funded.”

Later, this will be tied into Hive Engine to issue an equivalent token.

⛏️ How to Mine Scala (XLA)

Scala is designed to be CPU-mined. You don’t need expensive GPUs or ASICs — even low-power devices can contribute.

Steps to start mining:

  1. Download the Scala miner (XMRig fork) from the official Scala GitHub or https://play.google.com/store/apps/details?id=io.scalaproject.vault&hl=en_US or Scala Vault in Google Store (includes miner)
  2. Configure your pool connection:
{
  "url": "pool.scalaproject.io:3333",
  "user": "your_xla_wallet_address",
  "pass": "x"
}

3- Run the miner and watch your shares accumulate. XLA is CPU-minable; it’s a perfect fit for hobbyists, Raspberry Pis, and home labs.

📱 Scala Vault Wallet

To hold and manage your Scala (XLA), use the official Scala Vault wallet:
👉 Scala Vault on Google Play

The Vault supports sending, receiving, and payment IDs/memos — essential for swaps and bridging.

@thecrazygm - Have you dabbled here?

Always big thanks to @enginewitty @txracer @neoxian @ecency



0
0
0.000
2 comments
avatar

Can't say that I have, but I do like that it's cpu minable on a phone / Raspberry Pi etc. Might look into it later.

0
0
0.000