Skip to content

Instantly share code, notes, and snippets.

@jasny
Last active October 12, 2022 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasny/1bdacc967d90f37b75a275b340a1f0d6 to your computer and use it in GitHub Desktop.
Save jasny/1bdacc967d90f37b75a275b340a1f0d6 to your computer and use it in GitHub Desktop.
LTO get transactions of address as CSV
#!/bin/bash
ADDRESS="$1"
TOTAL=$(curl -s -I "https://nodes.lto.network/index/transactions/addresses/$ADDRESS" | grep x-total | awk '{printf "%d",$2}')
seq -w 00000 100 $TOTAL | xargs -P 10 -I'{}' curl -s "https://nodes.lto.network/index/transactions/addresses/$ADDRESS?limit=100&offset={}" -o "$ADDRESS.{}.json"
jq -s add $ADDRESS.*.json > "$ADDRESS.json"
rm $ADDRESS.*.json
jq -r 'reverse | .[] | [.type, .version, .id, (.timestamp / 1000 | todateiso8601), .sender, .recipient, (if .type == 4 then .amount else 0 end) + (if .type == 11 and .sender == "'$ADDRESS'" then (.transfers | ([.[].amount] | add)) else 0 end) + (if .type == 11 and .sender != "'$ADDRESS'" then (.transfers | ([.[] | select(.recipient == "'$ADDRESS'") | .amount] | add)) else 0 end), .effectiveFee] | join(",")' < "$ADDRESS.json" > "$ADDRESS.csv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment