Created
September 27, 2025 00:14
-
-
Save ottosch/fb698bca50b7642331679cdb1f82a0ff to your computer and use it in GitHub Desktop.
Measure time elapsed in fulcrum or another electrum server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
host="localhost" | |
port=50001 | |
get_balance='{"jsonrpc":"2.0","method":"blockchain.scripthash.get_balance","params":["562ce1c828ab2594470ab4de2561d993d5b5cce0b55695658afb17bec0121ea5"],"id":1}' | |
get_history='{"jsonrpc":"2.0","method":"blockchain.scripthash.get_history","params":["562ce1c828ab2594470ab4de2561d993d5b5cce0b55695658afb17bec0121ea5"],"id":1}' | |
# command="$get_balance" | |
command="$get_history" | |
echo "Sending request..." | |
t0=$(date +%s%3N) | |
master=$(mktemp -u /tmp/socat.XXXX) | |
socat PTY,raw,echo=0,link="$master" TCP:"$host":"$port" 2>/tmp/socat.err & | |
socat_pid=$! | |
sleep 0.05 | |
printf '%s\n' "$command" >"$master" | |
# read a single line (newline-terminated JSON) | |
IFS= read -r output <"$master" | |
kill $socat_pid 2>/dev/null || true | |
rm -f "$master" | |
t1=$(date +%s%3N) | |
echo "${output:0:100}" | |
echo "time: $((t1-t0)) ms" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment