Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2. $balance = 0;
  3. $fund_json = json_decode(shell_exec('/home/bitcoin/lightning/cli/lightning-cli listfunds'), true);
  4. if(!empty($fund_json['outputs'])){
  5.         foreach($fund_json['outputs'] as $output){
  6.                 $balance += $output['value'];
  7.         }
  8. }
  9. $json = json_decode(shell_exec('/home/bitcoin/lightning/cli/lightning-cli listpeers'), true);
  10.  
  11. $channels = 0;
  12. if(!empty($json['peers'])){
  13.         foreach($json['peers'] as $peer){
  14.                 if(!empty($peer['channels'])){
  15.                         foreach($peer['channels'] as $channel){
  16.                                 if(isset($channel['msatoshi_to_us']) && $channel['msatoshi_to_us'] > 0){
  17.                                         $balance += floor($channel['msatoshi_to_us']/1000);
  18.                                         $channels++;
  19.                                 }
  20.                         }
  21.                 }
  22.         }
  23. }
  24.  
  25. echo "Balance: ".($balance/100000000)." BTC\n";
  26. echo "Open Channels: ".$channels."\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement