@@ -10,6 +10,7 @@ import Foundation
10
10
enum InvalidSerializedDataError : Error {
11
11
case invalidSerializedChannelMonitor
12
12
case invalidSerializedChannelManager
13
+ case duplicateSerializedChannelMonitor
13
14
}
14
15
15
16
public class ChannelManagerConstructor : NativeTypeWrapper {
@@ -49,6 +50,8 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
49
50
50
51
var monitors : [ LDKChannelMonitor ] = [ ]
51
52
self . channel_monitors = [ ]
53
+
54
+ var monitorFundingSet = Set < [ UInt8 ] > ( )
52
55
53
56
for currentSerializedChannelMonitor in channel_monitors_serialized {
54
57
let channelMonitorResult : Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ = UtilMethods . constructor_BlockHashChannelMonitorZ_read ( ser: currentSerializedChannelMonitor, arg: keys_interface)
@@ -60,13 +63,19 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
60
63
let value : LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr = channelMonitorResult. cOpaqueStruct!. contents
61
64
let a : LDKThirtyTwoBytes = value. result!. pointee. a
62
65
let b : LDKChannelMonitor = value. result!. pointee. b
66
+
67
+ let nativeA = Bindings . LDKThirtyTwoBytes_to_array ( nativeType: a) ;
68
+ if monitorFundingSet. contains ( nativeA) {
69
+ throw InvalidSerializedDataError . duplicateSerializedChannelMonitor
70
+ }
71
+ monitorFundingSet. insert ( nativeA)
63
72
64
73
let clonedChannelMonitor = ChannelMonitor ( pointer: b) . dangle ( ) . clone ( )
65
74
// var clonedChannelMonitor = currentChannelMonitor.clone(orig: currentChannelMonitor)
66
75
clonedChannelMonitor. cOpaqueStruct? . is_owned = false // is_owned should never have to be modified
67
76
68
77
monitors. append ( clonedChannelMonitor. cOpaqueStruct!)
69
- self . channel_monitors. append ( ( clonedChannelMonitor, Bindings . LDKThirtyTwoBytes_to_array ( nativeType : a ) ) )
78
+ self . channel_monitors. append ( ( clonedChannelMonitor, nativeA ) )
70
79
}
71
80
72
81
print ( " Collected channel monitors, reading channel manager " )
0 commit comments