Advertisement
Guest User

Untitled

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