Minecraft - Hive Engine - Backend

This currently isn't up and running... I'm trying. I'm just one man. If you build anything within the game, please share what you've made.

I'm here with this at the moment. I'm sure I'll have to update this once I start testing it. I'm also trying to find a way to implement Hive earnings for completing tasks as well.

Everything helps. I currently have to pay $2 a month for the server it's running on. If users start to help me with building, we may need to upgrade where it's at.


import json
import os
from http.server import BaseHTTPRequestHandler, HTTPServer

# Optional dependency: beem (pip install beem)
try:
    from beem import Hive
    from beem.transactionbuilder import TransactionBuilder
except Exception:  # pragma: no cover
    Hive = None
    TransactionBuilder = None

HOST = "127.0.0.1"
PORT = int(os.getenv("HIVE_BRIDGE_PORT", "8787"))
AUTH_TOKEN = os.getenv("HIVE_BRIDGE_TOKEN", "")
HIVE_NODE = os.getenv("HIVE_NODE", "https://api.hive.blog")
ACTIVE_WIF = os.getenv("HIVE_ACTIVE_WIF", "")


def build_custom_json(action: str, account: str, symbol: str, price: str, quantity: str):
    payload = {
        "contractName": "market",
        "contractAction": action,
        "contractPayload": {
            "symbol": symbol,
            "price": price,
            "quantity": quantity,
        },
    }
    return {
        "id": "ssc-mainnet-hive",
        "json": json.dumps(payload, separators=(",", ":")),
        "required_auths": [account],
        "required_posting_auths": [],
    }


def submit_trade(action: str, account: str, symbol: str, price: str, quantity: str):
    if not Hive or not TransactionBuilder:
        return False, "beem not installed"
    if not ACTIVE_WIF:
        return False, "HIVE_ACTIVE_WIF not set"

    hive = Hive(node=HIVE_NODE, keys=[ACTIVE_WIF])
    tx = TransactionBuilder(blockchain_instance=hive)
    op = ["custom_json", build_custom_json(action, account, symbol, price, quantity)]
    tx.appendOps(op)
    tx.appendSigner(account, "active")
    tx.sign()
    tx.broadcast()
    return True, tx.get("id")


class Handler(BaseHTTPRequestHandler):
    def _send(self, code, body):
        data = json.dumps(body).encode("utf-8")
        self.send_response(code)
        self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(data)))
        self.end_headers()
        self.wfile.write(data)

    def do_POST(self):
        if self.path != "/trade":
            self._send(404, {"ok": False, "error": "not found"})
            return

        if AUTH_TOKEN:
            auth = self.headers.get("Authorization", "")
            if auth != f"Bearer {AUTH_TOKEN}":
                self._send(401, {"ok": False, "error": "unauthorized"})
                return

        length = int(self.headers.get("Content-Length", "0"))
        body = self.rfile.read(length).decode("utf-8")
        try:
            payload = json.loads(body)
        except json.JSONDecodeError:
            self._send(400, {"ok": False, "error": "invalid json"})
            return

        action = payload.get("action")
        account = payload.get("account")
        symbol = payload.get("symbol")
        price = payload.get("price")
        quantity = payload.get("quantity")

        if action not in ("buy", "sell"):
            self._send(400, {"ok": False, "error": "invalid action"})
            return
        if not all([account, symbol, price, quantity]):
            self._send(400, {"ok": False, "error": "missing fields"})
            return

        ok, result = submit_trade(action, account, symbol, price, quantity)
        if ok:
            self._send(200, {"ok": True, "txid": result})
        else:
            self._send(500, {"ok": False, "error": result})


if __name__ == "__main__":
    server = HTTPServer((HOST, PORT), Handler)
    print(f"Hive bridge listening on http://{HOST}:{PORT}")
    server.serve_forever()

🪙 PeakeCoin Ecosystem

💱 PeakeCoin USDT Bridge (Hive ↔ Polygon/MATIC)
Bridge SWAP.USDT from Hive Engine to USDT on Polygon (MATIC).
Whitelist access, documentation, and bridge status updates:
👉 https://geocities.ws/peakecoin


⚙️ HiveP.I.M.P. — PeakeCoin Intelligent Market Protector
Operated by @hivepimp, P.I.M.P. focuses on stabilizing PEK markets and strengthening liquidity on Hive Engine.
Community participation supports long-term ecosystem health.


🤖 PeakeBot — Autonomous Trading System
Independent multi-token trading bot with RC-awareness, adaptive delay logic, and smart cycle control.
📊 Trading bot documentation:
👉 https://geocities.ws/p/e/peakecoin/trading-bot/peakebot_v0_01.html
💻 Open-source repositories:
👉 https://github.com/paulmoon410


🎰 PeakeSino — The PeakeCoin Casino (Beta)
Blockchain-powered games using PEK as the native in-game currency.
Built on Hive with a focus on provable fairness and community-driven growth.
🃏 Play the beta games here:
👉 https://geocities.ws/peakecoin/pek_casino/beta_games/index.html


🙏 Acknowledgements

Thanks to and please follow:
@enginewitty @ecoinstant @neoxian @txracer @thecrazygm @holdonia @aggroed

For their continued support, guidance, and help expanding the PeakeCoin ecosystem.




0
0
0.000
0 comments