Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import subprocess
  4. import json
  5. import sys
  6.  
  7. date = subprocess.check_output(["date", "+%Y-%M-%dT%H:%M:%S%z"]).decode("utf-8").strip() # shows local Timezone
  8. wallet_balance = json.loads(subprocess.check_output(["lncli", "walletbalance"]).decode("utf-8"))
  9. channel_balance = json.loads(subprocess.check_output(["lncli", "channelbalance"]).decode("utf-8"))
  10. pendingchannels = json.loads(subprocess.check_output(["lncli", "pendingchannels"]).decode("utf-8"))
  11. chain_txns = json.loads(subprocess.check_output(["lncli", "listchaintxns"]).decode("utf-8"))["transactions"]
  12.  
  13. wallet = int(wallet_balance["confirmed_balance"])
  14. wallet_unconfirmed = int(wallet_balance["unconfirmed_balance"])
  15. channel = int(channel_balance["balance"])
  16. chain_fees = sum([int(i["total_fees"]) for i in chain_txns])
  17. fees = chain_fees # TODO: add Lightning relay fees
  18.  
  19. limbo_balance = int(pendingchannels['total_limbo_balance']) # The balance in satoshis encumbered in pending channels
  20. pending = int(channel_balance["pending_open_balance"]) + limbo_balance
  21. balance = wallet + wallet_unconfirmed + pending + channel
  22.  
  23. if len(sys.argv) < 2 or sys.argv[1] != '--no-header':
  24. print(
  25. "Time\t\t\t"
  26.  
  27. "Wallet\t\t"
  28. "Pending\t\t"
  29. "Channel\t\t"
  30. "Fees\t\t"
  31. "Balance\t\t"
  32. "Balance+Fees"
  33. )
  34.  
  35. print(
  36. date + \
  37. "\t{:,}".format(wallet) + \
  38. "\t{:,}".format(pending) + \
  39. "\t{:,}".format(channel) + \
  40. "\t{:,}".format(fees) + \
  41. "\t{:,}".format(balance) + \
  42. "\t{:,}".format(balance + fees)
  43. )
  44.  
  45. # Setup:
  46. '''
  47. chmod +x ~/lnd-e2e-testing/get_balance_report.py
  48. ~/lnd-e2e-testing/get_balance_report.py > ~/balance_history.tab
  49. crontab -e
  50. '''
  51. ## Text-editor will open, paste the following, save, and exit:
  52. '''
  53. SHELL=/bin/bash
  54. # m h dom mon dow command
  55. 0 * * * * (source ~/.profile; ~/lnd-e2e-testing/get_balance_report.py --no-header >> ~/balance_history.tab) 2> /tmp/stderr_cron_get_balance_report
  56. '''
  57.  
  58. # Check balance:
  59. '''
  60. while :; do (cat ~/balance_history.tab; ~/lnd-e2e-testing/get_balance_report.py) | column -t; sleep 60; done
  61. '''
  62. # Example Output:
  63. # Time Wallet Pending Channel Fees Balance Balance+Fees
  64. # 2018-07-15T13:00:01-07:00 1,599,749 208,344,076 150,652,120 248,117 360,595,945 360,844,062
  65. # 2018-00-15T19:00:01-0700 18,113,811 208,312,757 134,928,908 248,117 361,355,476 361,603,593
  66. # 2018-00-15T20:00:01-0700 18,113,811 208,312,757 134,611,917 248,117 361,038,485 361,286,602
  67. # 2018-26-15T20:26:36-0700 18,113,811 208,312,757 134,007,409 248,117 360,433,977 360,682,094
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement