|
| 1 | +// |
| 2 | +// Created by Arik Sosman on 5/13/20. |
| 3 | +// Copyright (c) 2020 Arik Sosman. All rights reserved. |
| 4 | +// |
| 5 | + |
| 6 | +import Foundation |
| 7 | + |
| 8 | +class ChannelMessageHandler { |
| 9 | + |
| 10 | + var cMessageHandler: LDKChannelMessageHandler? |
| 11 | + |
| 12 | + init(){ |
| 13 | + |
| 14 | + let instance = RawLDKTypes.instanceToPointer(instance: self); |
| 15 | + |
| 16 | + func handleOpenChannel(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, initFeatures: LDKInitFeatures, openChannel: UnsafePointer<LDKOpenChannel>?) -> Void { |
| 17 | + print("opened channel"); |
| 18 | + } |
| 19 | + func handleAcceptChannel(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, initFeatures: LDKInitFeatures, acceptChannel: UnsafePointer<LDKAcceptChannel>?) -> Void { |
| 20 | + print("accepted channel"); |
| 21 | + } |
| 22 | + func handleFundingCreated(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, fundingCreated: UnsafePointer<LDKFundingCreated>?) -> Void { |
| 23 | + print("funding created"); |
| 24 | + } |
| 25 | + func handleFundingSigned(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, fundingSigned: UnsafePointer<LDKFundingSigned>?) -> Void { |
| 26 | + print("funding signed"); |
| 27 | + } |
| 28 | + func handleFundingLocked(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, fundingLocked: UnsafePointer<LDKFundingLocked>?) -> Void { |
| 29 | + print("funding locked"); |
| 30 | + } |
| 31 | + func handleShutdown(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, shutdown: UnsafePointer<LDKShutdown>?) -> Void { |
| 32 | + print("shut down"); |
| 33 | + } |
| 34 | + func handleClosingSigned(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, closingSigned: UnsafePointer<LDKClosingSigned>?) -> Void { |
| 35 | + print("closing signed"); |
| 36 | + } |
| 37 | + func handleUpdateAddHTLC(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, updateAddHTLC: UnsafePointer<LDKUpdateAddHTLC>?) -> Void { |
| 38 | + print("added HTLC"); |
| 39 | + } |
| 40 | + func handleUpdateFulfillHTLC(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, updateFulfillHTLC: UnsafePointer<LDKUpdateFulfillHTLC>?) -> Void { |
| 41 | + print("fulfilled HTLC"); |
| 42 | + } |
| 43 | + func handleUpdateFailHTLC(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, updateFailHTLC: UnsafePointer<LDKUpdateFailHTLC>?) -> Void { |
| 44 | + print("failed HTLC"); |
| 45 | + } |
| 46 | + func handleUpdateFailMalformedHTLC(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, updateFailMalformedHTLC: UnsafePointer<LDKUpdateFailMalformedHTLC>?) -> Void { |
| 47 | + print("failed malformed HTLC"); |
| 48 | + } |
| 49 | + func handleCommitmentSigned(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, commitmentSigned: UnsafePointer<LDKCommitmentSigned>?) -> Void { |
| 50 | + print("commitment signed"); |
| 51 | + } |
| 52 | + func handleRevokeAndAck(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, revokeAndAck: UnsafePointer<LDKRevokeAndACK>?) -> Void { |
| 53 | + print("revoked and acked"); |
| 54 | + } |
| 55 | + func handleUpdateFee(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, updateFee: UnsafePointer<LDKUpdateFee>?) -> Void { |
| 56 | + print("updated fee"); |
| 57 | + } |
| 58 | + func handleAnnouncementSignatures(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, announcementSignatures: UnsafePointer<LDKAnnouncementSignatures>?) -> Void { |
| 59 | + print("announcement signatures"); |
| 60 | + } |
| 61 | + |
| 62 | + func peerDisconnected(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, no_connection_possible: Bool) -> Void { |
| 63 | + print("peer disconnected"); |
| 64 | + } |
| 65 | + func peerConnected(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, init: UnsafePointer<LDKInit>?) -> Void { |
| 66 | + print("peer connected"); |
| 67 | + } |
| 68 | + |
| 69 | + func handleChannelReestablish(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, channelReestablish: UnsafePointer<LDKChannelReestablish>?) -> Void { |
| 70 | + print("channel reestablished"); |
| 71 | + } |
| 72 | + func handleError(instancePointer: UnsafeRawPointer?, publicKey: LDKPublicKey, error: UnsafePointer<LDKErrorMessage>?) -> Void { |
| 73 | + print("some sort of error"); |
| 74 | + } |
| 75 | + |
| 76 | + let eventsProvider = LDKMessageSendEventsProvider(this_arg: instance) |
| 77 | + |
| 78 | + self.cMessageHandler = LDKChannelMessageHandler( |
| 79 | + this_arg: instance, |
| 80 | + handle_open_channel: handleOpenChannel, |
| 81 | + handle_accept_channel: handleAcceptChannel, |
| 82 | + handle_funding_created: handleFundingCreated, |
| 83 | + handle_funding_signed: handleFundingSigned, |
| 84 | + handle_funding_locked: handleFundingLocked, |
| 85 | + handle_shutdown: handleShutdown, |
| 86 | + handle_closing_signed: handleClosingSigned, |
| 87 | + handle_update_add_htlc: handleUpdateAddHTLC, |
| 88 | + handle_update_fulfill_htlc: handleUpdateFulfillHTLC, |
| 89 | + handle_update_fail_htlc: handleUpdateFailHTLC, |
| 90 | + handle_update_fail_malformed_htlc: handleUpdateFailMalformedHTLC, |
| 91 | + handle_commitment_signed: handleCommitmentSigned, |
| 92 | + handle_revoke_and_ack: handleRevokeAndAck, |
| 93 | + handle_update_fee: handleUpdateFee, |
| 94 | + handle_announcement_signatures: handleAnnouncementSignatures, |
| 95 | + peer_disconnected: peerDisconnected, |
| 96 | + peer_connected: peerConnected, |
| 97 | + handle_channel_reestablish: handleChannelReestablish, |
| 98 | + handle_error: handleError, |
| 99 | + MessageSendEventsProvider: eventsProvider) |
| 100 | + |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments