|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Required parameters: |
| 4 | +# @raycast.schemaVersion 1 |
| 5 | +# @raycast.title Open in Solana Inspector |
| 6 | +# @raycast.mode silent |
| 7 | +# @raycast.packageName Solana |
| 8 | + |
| 9 | +# Optional parameters: |
| 10 | +# @raycast.icon ./images/solana-logo.png |
| 11 | +# @raycast.argument1 { "type": "text", "placeholder": "Signed transaction (base64)" } |
| 12 | + |
| 13 | +# Documentation: |
| 14 | +# @raycast.description Extracts the message from a signed Solana transaction and opens Explorer's Inspector with it. |
| 15 | +# @raycast.author bjoerndotsol |
| 16 | +# @raycast.authorURL https://github.com/bjoerndotsol |
| 17 | + |
| 18 | +# This script decodes a full signed Solana transaction (base64) |
| 19 | +# and reconstructs a Solana Explorer Inspector link. |
| 20 | +# Supports both legacy and versioned transactions. |
| 21 | + |
| 22 | +TX_BASE64=$(printf "%s" "$1" | tr -d '[:space:]') |
| 23 | + |
| 24 | +if [[ -z "$TX_BASE64" ]]; then |
| 25 | + echo "❌ Please provide a base64-encoded transaction." |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +# Use Python to extract the message portion (skip signatures) |
| 30 | +MESSAGE_BASE64=$(python3 - "$TX_BASE64" <<'PY' |
| 31 | +import sys, base64, binascii, urllib.parse |
| 32 | +
|
| 33 | +try: |
| 34 | + tx_b64 = sys.argv[1] |
| 35 | + b = base64.b64decode(tx_b64) |
| 36 | +except (binascii.Error, ValueError) as e: |
| 37 | + print(f"Error decoding base64: {e}", file=sys.stderr) |
| 38 | + sys.exit(1) |
| 39 | +
|
| 40 | +# Transaction format: |
| 41 | +# [u8: num_signatures] [signatures * 64 bytes] [message...] |
| 42 | +# The message may start with a version byte (0x80 | version) for versioned transactions |
| 43 | +if not b or len(b) < 2: |
| 44 | + print("Transaction too short", file=sys.stderr) |
| 45 | + sys.exit(1) |
| 46 | +
|
| 47 | +num_signatures = b[0] |
| 48 | +offset = 1 + num_signatures * 64 |
| 49 | +
|
| 50 | +if offset >= len(b): |
| 51 | + print(f"Invalid transaction: offset {offset} >= length {len(b)}", file=sys.stderr) |
| 52 | + sys.exit(1) |
| 53 | +
|
| 54 | +# Extract message (includes version byte if present) |
| 55 | +msg = b[offset:] |
| 56 | +msg_b64 = base64.b64encode(msg).decode() |
| 57 | +
|
| 58 | +# URL encode (double encoding for Explorer) |
| 59 | +encoded = urllib.parse.quote(msg_b64, safe='') |
| 60 | +print(encoded) |
| 61 | +PY |
| 62 | +) |
| 63 | + |
| 64 | +# Check if extraction failed |
| 65 | +if [[ $? -ne 0 ]] || [[ -z "$MESSAGE_BASE64" ]]; then |
| 66 | + echo "❌ Could not extract transaction message." |
| 67 | + exit 1 |
| 68 | +fi |
| 69 | + |
| 70 | +# Dummy signature array for Inspector (Explorer only needs valid JSON) |
| 71 | +DUMMY_SIGS='["1111111111111111111111111111111111111111111111111111111111111111"]' |
| 72 | +ENCODED_SIGS=$(python3 -c "import urllib.parse,sys;print(urllib.parse.quote(sys.argv[1]))" "$DUMMY_SIGS") |
| 73 | + |
| 74 | +URL="https://explorer.solana.com/tx/inspector?signatures=${ENCODED_SIGS}&message=${MESSAGE_BASE64}" |
| 75 | + |
| 76 | +open "$URL" |
| 77 | +echo "✅ Opening Solana Explorer Inspector" |
0 commit comments