Skip to content

Commit

Permalink
feat: android lsp log hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasonvdb committed Apr 25, 2024
1 parent 5ce205d commit 85b6938
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
3 changes: 2 additions & 1 deletion lib/android/src/main/java/com/reactnativeldk/LdkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ enum class EventTypes {
new_channel,
network_graph_updated,
channel_manager_restarted,
backup_state_update
backup_state_update,
lsp_log
}
//*****************************************************************

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import com.facebook.react.bridge.WritableMap
import com.reactnativeldk.*
import org.json.JSONArray
import org.ldk.batteries.ChannelManagerConstructor
import org.ldk.structs.BumpTransactionEvent
import org.ldk.structs.ClosureReason
import org.ldk.structs.Event
import org.ldk.structs.Event.BumpTransaction
import org.ldk.structs.Option_ThirtyTwoBytesZ
import org.ldk.structs.Option_u64Z
import org.ldk.structs.PaymentPurpose
Expand Down Expand Up @@ -190,6 +192,18 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {

(event as? Event.ChannelPending)?.let { channelPending ->
}

(event as? Event.BumpTransaction)?.let { bumpTransaction ->
LdkEventEmitter.send(EventTypes.native_log, "BumpTransaction request")

(bumpTransaction.bump_transaction as? BumpTransactionEvent.ChannelClose)?.let { channelClose ->
val body = Arguments.createMap()
body.putString("commitment_tx", channelClose.commitment_tx.hexEncodedString())
body.putInt("commitment_tx_fee", channelClose.commitment_tx_fee_satoshis.toInt())
body.putInt("pending_htlcs_count", channelClose.pending_htlcs.size)
return LdkEventEmitter.send(EventTypes.lsp_log, body)
}
}
}

override fun persist_manager(channel_manager_bytes: ByteArray?) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ios/Classes/LdkChannelManagerPersister.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {

if let channelClose = bumpTransaction.getValueAsChannelClose() {
let body: [String: Encodable] = [
"commitment_txid": Data(channelClose.getCommitmentTx()).hexEncodedString(),
"commitment_tx": Data(channelClose.getCommitmentTx()).hexEncodedString(),
"commitment_tx_fee": channelClose.getCommitmentTxFeeSatoshis(),
"pending_htlcs_count": channelClose.getPendingHtlcs().count
]
Expand Down
17 changes: 0 additions & 17 deletions lib/ios/Ldk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ class Ldk: NSObject {
}

Logfile.log.setFilePath(logFile)
print("log file: \(path)")
return handleResolve(resolve, .log_path_updated)
}

Expand Down Expand Up @@ -495,22 +494,6 @@ class Ldk: NSObject {
currentBlockchainTipHash = blockHash
currentBlockchainHeight = blockHeight
addForegroundObserver()





///TODO DELETE
let body: [String: Encodable] = [
"commitment_txid": "Data(channelClose.getCommitmentTx()).hexEncodedString()",
"commitment_tx_fee": "channelClose.getCommitmentTxFeeSatoshis()",
"pending_htlcs_count": 69
]

LdkEventEmitter.shared.send(withEvent: .lsp_log, body: body)
///



return handleResolve(resolve, .channel_manager_init_success)
}
Expand Down

0 comments on commit 85b6938

Please sign in to comment.