@ -567,54 +567,50 @@ fn readWPACtrlMsg(self: *Daemon) !void {
}
}
fn sendOnchainReport ( self : * Daemon ) ! void {
fn sendOnchainReport ( self : * Daemon ) ! void {
var client = bitcoindrpc . Client {
const stats = self . fetchOnchainStats ( ) catch | err | {
. allocator = self . allocator ,
switch ( err ) {
. cookiepath = " /ssd/bitcoind/mainnet/.cookie " ,
error . FileNotFound , / / cookie file might not exist yet
} ;
error . RpcInWarmup ,
const bcinfo = try client . call ( . getblockchaininfo , { } ) ;
/ / bitcoind is still starting up : pretend the repost is sent .
defer bcinfo . deinit ( ) ;
/ / TODO : report actual startup ptogress to the UI
const netinfo = try client . call ( . getnetworkinfo , { } ) ;
/ / https : / / git . qcode . ch / nakamochi / ndg / issues / 30
defer netinfo . deinit ( ) ;
= > return ,
const mempool = try client . call ( . getmempoolinfo , { } ) ;
/ / otherwise , propagate the error to the caller .
defer mempool . deinit ( ) ;
else = > return err ,
}
const balance : ? lndhttp . Client . Result ( . walletbalance ) = blk : { / / lndhttp . WalletBalance
var lndc = lndhttp . Client . init ( . {
. allocator = self . allocator ,
. tlscert_path = " /home/lnd/.lnd/tls.cert " ,
. macaroon_ro_path = " /ssd/lnd/data/chain/bitcoin/mainnet/readonly.macaroon " ,
} ) catch break : blk null ;
defer lndc . deinit ( ) ;
const res = lndc . call ( . walletbalance , { } ) catch break : blk null ;
break : blk res ;
} ;
} ;
defer if ( balance ) | bal | bal . deinit ( ) ;
defer {
stats . bcinfo . deinit ( ) ;
stats . netinfo . deinit ( ) ;
stats . mempool . deinit ( ) ;
if ( stats . balance ) | bal | bal . deinit ( ) ;
}
const btcrep : comm . Message . OnchainReport = . {
const btcrep : comm . Message . OnchainReport = . {
. blocks = bcinfo . value . blocks ,
. blocks = stats. bcinfo. value . blocks ,
. headers = bcinfo . value . headers ,
. headers = stats. bcinfo. value . headers ,
. timestamp = bcinfo . value . time ,
. timestamp = stats. bcinfo. value . time ,
. hash = bcinfo. value . bestblockhash ,
. hash = stats. bcinfo. value . bestblockhash ,
. ibd = bcinfo. value . initialblockdownload ,
. ibd = stats. bcinfo. value . initialblockdownload ,
. diskusage = bcinfo. value . size_on_disk ,
. diskusage = stats. bcinfo. value . size_on_disk ,
. version = netinfo. value . subversion ,
. version = stats. netinfo. value . subversion ,
. conn_in = netinfo. value . connections_in ,
. conn_in = stats. netinfo. value . connections_in ,
. conn_out = netinfo. value . connections_out ,
. conn_out = stats. netinfo. value . connections_out ,
. warnings = bcinfo. value . warnings , / / TODO : netinfo . result . warnings
. warnings = stats. bcinfo. value . warnings , / / TODO : netinfo . result . warnings
. localaddr = & . { } , / / TODO : populate
. localaddr = & . { } , / / TODO : populate
/ / something similar to this :
/ / something similar to this :
/ / @round ( bcinfo . verificationprogress * 100 )
/ / @round ( bcinfo . verificationprogress * 100 )
. verifyprogress = 0 ,
. verifyprogress = 0 ,
. mempool = . {
. mempool = . {
. loaded = mempool. value . loaded ,
. loaded = stats. mempool. value . loaded ,
. txcount = mempool. value . size ,
. txcount = stats. mempool. value . size ,
. usage = mempool. value . usage ,
. usage = stats. mempool. value . usage ,
. max = mempool. value . maxmempool ,
. max = stats. mempool. value . maxmempool ,
. totalfee = mempool. value . total_fee ,
. totalfee = stats. mempool. value . total_fee ,
. minfee = mempool. value . mempoolminfee ,
. minfee = stats. mempool. value . mempoolminfee ,
. fullrbf = mempool. value . fullrbf ,
. fullrbf = stats. mempool. value . fullrbf ,
} ,
} ,
. balance = if ( balance) | bal | . {
. balance = if ( stats. balance) | bal | . {
. source = . lnd ,
. source = . lnd ,
. total = bal . value . total_balance ,
. total = bal . value . total_balance ,
. confirmed = bal . value . confirmed_balance ,
. confirmed = bal . value . confirmed_balance ,
@ -627,6 +623,42 @@ fn sendOnchainReport(self: *Daemon) !void {
try comm . write ( self . allocator , self . uiwriter , . { . onchain_report = btcrep } ) ;
try comm . write ( self . allocator , self . uiwriter , . { . onchain_report = btcrep } ) ;
}
}
const OnchainStats = struct {
bcinfo : bitcoindrpc . Client . Result ( . getblockchaininfo ) ,
netinfo : bitcoindrpc . Client . Result ( . getnetworkinfo ) ,
mempool : bitcoindrpc . Client . Result ( . getmempoolinfo ) ,
/ / lnd wallet may be uninitialized
balance : ? lndhttp . Client . Result ( . walletbalance ) ,
} ;
/ / / callers own returned value .
fn fetchOnchainStats ( self : * Daemon ) ! OnchainStats {
var client = bitcoindrpc . Client {
. allocator = self . allocator ,
. cookiepath = " /ssd/bitcoind/mainnet/.cookie " ,
} ;
const bcinfo = try client . call ( . getblockchaininfo , { } ) ;
const netinfo = try client . call ( . getnetworkinfo , { } ) ;
const mempool = try client . call ( . getmempoolinfo , { } ) ;
const balance : ? lndhttp . Client . Result ( . walletbalance ) = blk : { / / lndhttp . WalletBalance
var lndc = lndhttp . Client . init ( . {
. allocator = self . allocator ,
. tlscert_path = " /home/lnd/.lnd/tls.cert " ,
. macaroon_ro_path = " /ssd/lnd/data/chain/bitcoin/mainnet/readonly.macaroon " ,
} ) catch break : blk null ;
defer lndc . deinit ( ) ;
const res = lndc . call ( . walletbalance , { } ) catch break : blk null ;
break : blk res ;
} ;
return . {
. bcinfo = bcinfo ,
. netinfo = netinfo ,
. mempool = mempool ,
. balance = balance ,
} ;
}
fn sendLightningReport ( self : * Daemon ) ! void {
fn sendLightningReport ( self : * Daemon ) ! void {
var client = try lndhttp . Client . init ( . {
var client = try lndhttp . Client . init ( . {
. allocator = self . allocator ,
. allocator = self . allocator ,