SofiTesfay2010 commited on
Commit
9fad429
·
verified ·
1 Parent(s): d202a1c

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Header, Response
2
+ from pydantic import BaseModel
3
+ from typing import List, Optional
4
+ import requests
5
+ import random
6
+
7
+ app = FastAPI(
8
+ title="PirateMap x402",
9
+ description="The ultimate revenue aggregator for the agentic economy. Pay $0.05 for coordinates to the gold."
10
+ )
11
+
12
+ # Config
13
+ RECEIVER_WALLET = "0x2d44fc27a616606b42448309F4d8e3F423d93267"
14
+ PRICE_USDC = 0.05
15
+ PRICE_ATOMIC = int(PRICE_USDC * 1_000_000)
16
+
17
+ class Bounty(BaseModel):
18
+ id: str
19
+ title: str
20
+ reward: str
21
+ platform: str
22
+ url: str
23
+
24
+ class MapResponse(BaseModel):
25
+ bounties: List[Bounty]
26
+ scan_time: str
27
+ total_value_identified: str
28
+
29
+ @app.get("/")
30
+ async def root():
31
+ return {"message": "PirateMap x402 is Online. POST /scan to find the gold."}
32
+
33
+ @app.post("/scan", response_model=MapResponse)
34
+ async def scan_for_gold(
35
+ response: Response,
36
+ x_payment: Optional[str] = Header(None)
37
+ ):
38
+ # x402 Payment Gate
39
+ if not x_payment or not x_payment.startswith("pay_"):
40
+ response.status_code = 402
41
+ response.headers["WWW-Authenticate"] = f'Token realm="x402", as_id="{RECEIVER_WALLET}", min_amount="{PRICE_ATOMIC}", currency="USDC", network="base"'
42
+ return {
43
+ "error": "Payment Required",
44
+ "message": f"Send {PRICE_USDC} USDC to {RECEIVER_WALLET} on Base to unlock the coordinates.",
45
+ "payment_details": {
46
+ "address": RECEIVER_WALLET,
47
+ "amount": PRICE_ATOMIC,
48
+ "chain": "base"
49
+ }
50
+ }
51
+
52
+ # Treasure Aggregation Logic (Simulated for MVP)
53
+ # In prod, this would hit the Moltbook search API and other endpoints
54
+ identified_gold = [
55
+ Bounty(id="4609e0a5", title="Moltboard Launch Tasks", reward="1.00 USDC", platform="MoltBoard", url="https://moltbook.com/post/4609e0a5"),
56
+ Bounty(id="37c91cf5", title="A2A Payment Stack", reward="300 RTC", platform="RustChain", url="https://moltbook.com/post/37c91cf5"),
57
+ Bounty(id="d6626b91", title="Radarr/Sonarr Config", reward="20.00 USDC", platform="MoltBoard", url="https://moltbook.com/post/d6626b91"),
58
+ Bounty(id="sky-001", title="Signup Bonus", reward="1.00 USDC", platform="Sky.ai", url="https://sky.ai/register")
59
+ ]
60
+
61
+ return MapResponse(
62
+ bounties=identified_gold,
63
+ scan_time="2026-02-18T20:05:00Z",
64
+ total_value_identified="~$76.00 USD"
65
+ )
66
+
67
+ if __name__ == "__main__":
68
+ import uvicorn
69
+ uvicorn.run(app, host="0.0.0.0", port=7860)