citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

walletemail.nix (1906B)


      1 { pkgs, private, bcli, nostril }:
      2 
      3 pkgs.writeScript "walletemail" ''
      4 #!${pkgs.bash}/bin/bash
      5 
      6 set -e
      7 
      8 txid="$1"
      9 wallet="$2"
     10 
     11 from="Bitcoin Wallet <bitcoind@monad>"
     12 to="William Casarin <jb55@jb55.com>"
     13 subject="Wallet notification"
     14 keys="-r 0xC5D732336E9DC2C7F9D9D91CAC3CB14001216D67"
     15 
     16 tx="$(${bcli} -rpcwallet=$wallet gettransaction "$txid" true)"
     17 address="$(${pkgs.jq}/bin/jq -r '.details[0].address' <<<"$tx")"
     18 details="$(${pkgs.jq}/bin/jq -r '.details[] | [.address, .category, .amount, .label] | @csv' <<<"$tx")"
     19 keypath="$(${bcli} -rpcwallet=$wallet getaddressinfo "$address" | ${pkgs.jq}/bin/jq -r .hdkeypath)"
     20 
     21 amount="$(${pkgs.jq}/bin/jq -r '.amount' <<<"$tx")"
     22 confs="$(${pkgs.jq}/bin/jq -r '.confirmations' <<<"$tx")"
     23 
     24 time="$(date -d @$(${pkgs.jq}/bin/jq -r '.time' <<<"$tx"))"
     25 received="$(date -d @$(${pkgs.jq}/bin/jq -r '.timereceived' <<<"$tx"))"
     26 
     27 export GNUPGHOME=/zbig/bitcoin/gpg
     28 
     29 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" \
     30               "$txid" "$address" "$amount" "$confs" "$wallet" "$time" "$received" "$keypath" "$details" )"
     31 
     32 ${nostril}/bin/nostril --sec ${private.wallet-nostr} --envelope -p 32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245 --content "$msg" | ${pkgs.websocat}/bin/websocat ws://127.0.0.1:8080
     33 
     34 enctx="$(printf "Content-Type: text/plain\n\n%s\n" "$msg" | ${pkgs.gnupg}/bin/gpg --yes --always-trust --encrypt --armor $keys)"
     35 
     36 {
     37 cat <<EOF
     38 From: $from
     39 To: $to
     40 Subject: $subject
     41 MIME-Version: 1.0
     42 Content-Type: multipart/encrypted; boundary="=-=-=";
     43   protocol="application/pgp-encrypted"
     44 
     45 --=-=-=
     46 Content-Type: application/pgp-encrypted
     47 
     48 Version: 1
     49 
     50 --=-=-=
     51 Content-Type: application/octet-stream
     52 
     53 $enctx
     54 --=-=-=--
     55 EOF
     56 } | /run/current-system/sw/bin/sendmail --file /zbig/bitcoin/gpg/.msmtprc -oi -t
     57 
     58 printf "sent walletnotify email for %s\n" "$txid"
     59 ''