@@ -24,6 +24,7 @@ import java.io.File
2424import java.net.InetSocketAddress
2525import java.nio.file.Files
2626import java.nio.file.Paths
27+ import java.text.SimpleDateFormat
2728import java.util.*
2829
2930
@@ -962,52 +963,9 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
962963 channelManager.list_channels() else
963964 arrayOf<ChannelDetails >()
964965
965- val result = Arguments .createArray()
966966
967- chainMonitor.get_claimable_balances(ignoredChannels).iterator().forEach { balance ->
968- val map = Arguments .createMap()
969- // Defaults if all castings for balance fail
970- map.putInt(" amount_satoshis" , 0 )
971- map.putString(" type" , " Unknown" )
972-
973- (balance as ? Balance .ClaimableAwaitingConfirmations )?.let { claimableAwaitingConfirmations ->
974- map.putInt(" amount_satoshis" , claimableAwaitingConfirmations.amount_satoshis.toInt())
975- map.putInt(" confirmation_height" , claimableAwaitingConfirmations.confirmation_height)
976- map.putString(" type" , " ClaimableAwaitingConfirmations" )
977- }
978-
979- (balance as ? Balance .ClaimableOnChannelClose )?.let { claimableOnChannelClose ->
980- map.putInt(" amount_satoshis" , claimableOnChannelClose.amount_satoshis.toInt())
981- map.putString(" type" , " ClaimableOnChannelClose" )
982- }
983-
984- (balance as ? Balance .ContentiousClaimable )?.let { contentiousClaimable ->
985- map.putInt(" amount_satoshis" , contentiousClaimable.amount_satoshis.toInt())
986- map.putInt(" timeout_height" , contentiousClaimable.timeout_height)
987- map.putString(" type" , " ContentiousClaimable" )
988- }
989-
990- (balance as ? Balance .CounterpartyRevokedOutputClaimable )?.let { counterpartyRevokedOutputClaimable ->
991- map.putInt(" amount_satoshis" , counterpartyRevokedOutputClaimable.amount_satoshis.toInt())
992- map.putString(" type" , " CounterpartyRevokedOutputClaimable" )
993- }
994-
995- (balance as ? Balance .MaybePreimageClaimableHTLC )?.let { maybePreimageClaimableHTLC ->
996- map.putInt(" amount_satoshis" , maybePreimageClaimableHTLC.amount_satoshis.toInt())
997- map.putInt(" expiry_height" , maybePreimageClaimableHTLC.expiry_height)
998- map.putString(" type" , " MaybePreimageClaimableHTLC" )
999- }
1000967
1001- (balance as ? Balance .MaybeTimeoutClaimableHTLC )?.let { maybeTimeoutClaimableHTLC ->
1002- map.putInt(" amount_satoshis" , maybeTimeoutClaimableHTLC.amount_satoshis.toInt())
1003- map.putInt(" claimable_height" , maybeTimeoutClaimableHTLC.claimable_height)
1004- map.putString(" type" , " MaybeTimeoutClaimableHTLC" )
1005- }
1006-
1007- result.pushMap(map)
1008- }
1009-
1010- promise.resolve(result)
968+ promise.resolve(chainMonitor.getClaimableBalancesAsJson(ignoredChannels))
1011969 }
1012970
1013971 // MARK: Misc methods
@@ -1121,6 +1079,70 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
11211079 promise.resolve((res as Result_StringErrorZ_OK ).res)
11221080 }
11231081
1082+ @ReactMethod
1083+ fun nodeStateDump (promise : Promise ) {
1084+ val logDump: MutableList <String > = mutableListOf ()
1085+
1086+ keysManager?.as_NodeSigner()?.get_node_id(Recipient .LDKRecipient_Node )?.let { pubKeyRes ->
1087+ if (pubKeyRes.is_ok) {
1088+ logDump.add(" NodeID: ${(pubKeyRes as Result_PublicKeyNoneZ_OK ).res.hexEncodedString()} " )
1089+ }
1090+ }
1091+
1092+ channelManager?.list_channels()?.forEach { channel ->
1093+ logDump.add(" Open channel:" )
1094+
1095+ channel._funding_txo ?._txid ?.let { txId ->
1096+ logDump.add(" Funding txid: ${txId.hexEncodedString()} " )
1097+ }
1098+
1099+ logDump.add(" Ready: ${if (channel._is_channel_ready ) " YES" else " NO" } " )
1100+ logDump.add(" Usable: ${if (channel._is_usable ) " YES" else " NO" } " )
1101+ logDump.add(" Balance: ${channel._balance_msat / 1000 } sats" )
1102+ }
1103+
1104+ chainMonitor?.getClaimableBalancesAsJson(arrayOf())?.let { claimableBalances ->
1105+ logDump.add(" All claimable balances:\n $claimableBalances " )
1106+ } ? : run {
1107+ logDump.add(" Claimable balances unavailable. Chain monitor not set yet" )
1108+ }
1109+
1110+ networkGraph?._last_rapid_gossip_sync_timestamp ?.let { res ->
1111+ val syncTimestamp = if (res is Option_u32Z .Some ) (res as Option_u32Z .Some ).some.toLong() else 0
1112+ if (syncTimestamp == 0L ) {
1113+ logDump.add(" Last rapid gossip sync time: NEVER" )
1114+ } else {
1115+ val date = Date (syncTimestamp * 1000 )
1116+ val dateFormatter = SimpleDateFormat (" yyyy-MM-dd HH:mm:ss" )
1117+ logDump.add(" Last rapid gossip sync time: ${dateFormatter.format(date)} " )
1118+ }
1119+ } ? : run {
1120+ logDump.add(" RGS last sync time unavailable." )
1121+ }
1122+
1123+ peerManager?._peer_node_ids ?.let { peers ->
1124+ if (peers.isNotEmpty()) {
1125+ peers.forEach { peer ->
1126+ logDump.add(" Connected peer: ${peer._a .hexEncodedString()} " )
1127+ }
1128+ } else {
1129+ logDump.add(" No connected peers" )
1130+ }
1131+ } ? : run {
1132+ logDump.add(" Connected peers unavailable. Peer manager not set." )
1133+ }
1134+
1135+ logDump.add(" Storage: ${accountStoragePath} " )
1136+
1137+ logDump.add(" BackupClient setup: ${if (BackupClient .requiresSetup) " NO" else " YES" } " )
1138+ logDump.add(" Skip remote backups: ${if (BackupClient .skipRemoteBackup) " YES" else " NO" } " )
1139+
1140+ val logString = " ********NODE STATE********\n " + logDump.joinToString(" \n " ) + " \n ****************"
1141+ LogFile .write(logString)
1142+
1143+ promise.resolve(logString)
1144+ }
1145+
11241146 // Backup methods
11251147 @ReactMethod
11261148 fun backupSetup (seed : String , network : String , server : String , serverPubKey : String , promise : Promise ) {
0 commit comments