Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $path_to_lightning = '/home/bitcoin/lightning/cli/lightning-cli';
- $balance = 0;
- $fund_json = json_decode(shell_exec($path_to_lightning.' listfunds'), true);
- if(!empty($fund_json['outputs'])){
- foreach($fund_json['outputs'] as $output){
- $balance += $output['value'];
- }
- }
- $json = json_decode(shell_exec($path_to_lightning.' listpeers'), true);
- $channels = 0;
- if(!empty($json['peers'])){
- foreach($json['peers'] as $peer){
- if(!empty($peer['channels'])){
- foreach($peer['channels'] as $channel){
- if(isset($channel['msatoshi_to_us']) && $channel['msatoshi_to_us'] > 0){
- $balance += floor($channel['msatoshi_to_us']/1000);
- $channels++;
- }
- }
- }
- }
- }
- echo "Balance: ".($balance/100000000)." BTC\n";
- echo "Open Channels: ".$channels."\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement