walletemail (1563B)
1 #!${pkgs.bash}/bin/bash 2 3 set -e 4 5 txid="$1" 6 wallet="$2" 7 8 from="Bitcoin Wallet <bitcoind@monad>" 9 to="William Casarin <jb55@jb55.com>" 10 subject="Wallet notification" 11 keys="-r 0x8860420C3C135662EABEADF96342E010C44A6337 -r 0x5B2B1E4F62216BC74362AC61D4FBA2FC4535A2A9 -r 0xE02D3FD4EB4585A63531C1D0E1BFCB90A1FF7A1C" 12 13 tx="$(bitcoin-cli -rpcwallet=$wallet gettransaction "$txid" true)" 14 address="$(jq -r '.details[0].address' <<<"$tx")" 15 details="$(jq -r '.details[] | [.address, .category, .amount, .label] | @csv' <<<"$tx")" 16 keypath="$(bitcoin-cli -rpcwallet=$wallet getaddressinfo "$address" | jq -r .hdkeypath)" 17 18 amount="$(jq -r '.amount' <<<"$tx")" 19 confs="$(jq -r '.confirmations' <<<"$tx")" 20 21 time="$(date -d @$(jq -r '.time' <<<"$tx"))" 22 received="$(date -d @$(jq -r '.timereceived' <<<"$tx"))" 23 24 export GNUPGHOME=/zbig/bitcoin/gpg 25 26 msg="$(printf "txid: %s\n\naddress: %s\n\namount: %s\n\nconfirmations: %d\n\nwallet: %s\n\ntime: %s\n\nreceived: %s\n\nkeypath: %s\n\n%s\n\n\n%s" \ 27 "$txid" "$address" "$amount" "$confs" "$wallet" "$time" "$received" "$keypath" "$details" "$tx" )" 28 29 enctx="$(printf "Content-Type: text/plain\n\n%s\n" "$msg" | gpg --yes --always-trust --encrypt --armor $keys)" 30 31 { 32 cat <<EOF 33 From: $from 34 To: $to 35 Subject: $subject 36 MIME-Version: 1.0 37 Content-Type: multipart/encrypted; boundary="=-=-="; 38 protocol="application/pgp-encrypted" 39 40 --=-=-= 41 Content-Type: application/pgp-encrypted 42 43 Version: 1 44 45 --=-=-= 46 Content-Type: application/octet-stream 47 48 $enctx 49 --=-=-=-- 50 EOF 51 } | sendmail -oi -t 52 53 printf "sent walletnotify email for %s\n" "$txid" 54 ''