Upload 1111.txt
Browse files
1111.txt
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import base64
|
| 2 |
+
|
| 3 |
+
import uvicorn
|
| 4 |
+
|
| 5 |
+
from fastapi.staticfiles import StaticFiles
|
| 6 |
+
from fastapi import FastAPI
|
| 7 |
+
from fastapi.responses import FileResponse
|
| 8 |
+
|
| 9 |
+
app = FastAPI()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def add_base32_padding(encoded_text):
|
| 13 |
+
padding_needed = 8 - (len(encoded_text) % 8)
|
| 14 |
+
return encoded_text + '=' * padding_needed
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def remove_f4_prefix(encoded_text):
|
| 18 |
+
prefix = "f410f"
|
| 19 |
+
if encoded_text.startswith(prefix):
|
| 20 |
+
return encoded_text[len(prefix):]
|
| 21 |
+
else:
|
| 22 |
+
return None
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@app.get("/", response_class=FileResponse)
|
| 26 |
+
def read_root():
|
| 27 |
+
return "./static/index.html"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@app.get("/convert_address_f4_0X")
|
| 31 |
+
def convert_address_f4_0X(f4Address: str):
|
| 32 |
+
print(f4Address)
|
| 33 |
+
if f4Address is not None and len(f4Address) == 44:
|
| 34 |
+
encoded_text = remove_f4_prefix(f4Address)
|
| 35 |
+
encoded_text_with_padding = add_base32_padding(encoded_text.upper())
|
| 36 |
+
decoded_bytes = base64.b32decode(encoded_text_with_padding)
|
| 37 |
+
|
| 38 |
+
# Discard the last 4 bytes
|
| 39 |
+
decoded_bytes = decoded_bytes[:-4]
|
| 40 |
+
|
| 41 |
+
hex_string = "0x" + decoded_bytes.hex()
|
| 42 |
+
|
| 43 |
+
return {"fevm address": hex_string}
|
| 44 |
+
else:
|
| 45 |
+
return {"error": "Incorrect f4 address format"}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
app.mount("/", StaticFiles(directory="static"), name="static")
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|