mirror of
https://github.com/ben-grande/qusal.git
synced 2025-01-02 11:26:11 -05:00
011a71a36d
Editorconfig can only act based on file extension and path, not attributes, it remains a mean only for multiple collaborators to use the same configuration on their editor. When it is too restrictive, such as not considering the file syntax, use a lint tool for the specific file type instead of trusting editorconfig. Changes were made to increase readability.
98 lines
2.2 KiB
Bash
Executable File
98 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
## SPDX-FileCopyrightText: 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
|
##
|
|
## SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
set -eu
|
|
|
|
#date_mined="20130604"
|
|
#block_number="230009"
|
|
block_hash="00000000000000ecbbff6bafb7efa2f7df05b227d5c73dca8f2635af32a2e949"
|
|
txid="54e48e5f5c656b26c3bca14a8c95aa583d07ebe84dde3b7dd4a78f4e4186e713"
|
|
dir="${HOME}"
|
|
file="bitcoin.pdf"
|
|
|
|
has(){
|
|
cmd="$(command -v "${1}" 2>/dev/null)" || return 1
|
|
test -x "${cmd}" || return 1
|
|
}
|
|
|
|
check_installed(){
|
|
missing_programs=0
|
|
for prog in "${@}"; do
|
|
if ! has "${prog}"; then
|
|
echo "Missing program: ${prog}" >&2
|
|
missing_programs=1
|
|
fi
|
|
done
|
|
if test "${missing_programs}" = "1"; then
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
validate_dir(){
|
|
if ! test -d "${dir}"; then
|
|
echo "Directory '${dir}' does not exist" >&2
|
|
exit 1
|
|
fi
|
|
if ! test -w "${dir}"; then
|
|
echo "Directory '${dir}' is not writable" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
getblock(){
|
|
check_installed bitcoin-cli xxd
|
|
bitcoin-cli getblock "${block_hash}" 0 \
|
|
| tail -c+92167 \
|
|
| for ((o=0;o<946;++o)); do \
|
|
read -rN420 x; \
|
|
echo -n "${x::130}${x:132:130}${x:264:130}"; \
|
|
done \
|
|
| xxd -r -p \
|
|
| tail -c+9 \
|
|
| head -c184292 \
|
|
| tee "${output_file}" >/dev/null
|
|
}
|
|
|
|
getrawtransaction(){
|
|
check_installed bitcoin-cli xxd
|
|
bitcoin-cli getrawtransaction "${txid}" 0 "${block_hash}" \
|
|
| sed 's/0100000000000000/\n/g' \
|
|
| tail -n +2 \
|
|
| cut -c7-136,139-268,271-400 \
|
|
| tr -d '\n' \
|
|
| cut -c17-368600 \
|
|
| xxd -p -r \
|
|
| tee "${output_file}" >/dev/null
|
|
}
|
|
|
|
gettxout(){
|
|
check_installed bitcoin-cli jq xxd seq
|
|
seq 0 947 \
|
|
| (while read -r n; do bitcoin-cli gettxout "${txid}" "${n}" \
|
|
| jq -r '.scriptPubKey.asm' \
|
|
| awk '{ print $2 $3 $4 }'; done) \
|
|
| tr -d '\n' \
|
|
| cut -c 17-368600 \
|
|
| xxd -r -p \
|
|
| tee "${output_file}" >/dev/null
|
|
}
|
|
|
|
usage(){
|
|
echo "Usage: ${0##*/} getblock|getrawtransaction|gettxout [DIR]"
|
|
echo "Note: gettxout works with pruned node"
|
|
echo "Note: DIR defaults to \$HOME"
|
|
exit 1
|
|
}
|
|
|
|
case "${1:-}" in
|
|
"getblock"|"getrawtransaction"|"gettxout")
|
|
test -z "${2-}" || dir="${2}"
|
|
validate_dir "${dir}"
|
|
output_file="${dir}/${file}"
|
|
"${1}"
|
|
;;
|
|
*) usage;;
|
|
esac
|