Skip to content

Commit c21000c

Browse files
authored
Merge pull request #9 from lightningdevkit/v0.0.101
Update to v0.0.101
2 parents 65f616c + 4438a62 commit c21000c

File tree

89 files changed

+4572
-466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+4572
-466
lines changed

.github/workflows/swift.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ jobs:
2020
cd rust-lightning
2121
# git checkout origin/2021-03-java-bindings-base
2222
# git checkout v0.0.100
23-
git checkout dba15b73610e4f54378782e55874fc694bf8bda9
23+
git checkout e9c4fa6c6959f2cdba29b4a3b47088053fb4822e
2424
echo "rust-lightning commit hash:"
2525
git rev-parse HEAD
2626
cd ..
27-
git clone https://github.com/lightningdevkit/ldk-c-bindings
27+
# git clone https://github.com/lightningdevkit/ldk-c-bindings
28+
git clone https://github.com/TheBlueMatt/ldk-c-bindings
2829
cd ldk-c-bindings
29-
git checkout v0.0.100.1
30+
git checkout 9e501cbbcde7b6624ec03372452e915967e84064
3031
echo "ldk-c-bindings commit hash:"
3132
git rev-parse HEAD
3233
cd ..

bindings/LDK/Bindings.swift

Lines changed: 226 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,108 @@ public class Bindings {
729729
}
730730

731731

732+
/* SWIFT_TO_RUST_START */
733+
public class func new_LDKCVec_BalanceZWrapper(array: [LDKBalance]) -> LDKCVec_BalanceZWrapper {
734+
/* DIMENSION_REDUCTION_PREP */
735+
736+
/*
737+
let dataContainer = array.withUnsafeBufferPointer { (pointer: UnsafeBufferPointer<LDKBalance>) -> UnsafeMutablePointer<LDKBalance> in
738+
let mutablePointer = UnsafeMutablePointer<LDKBalance>(mutating: pointer.baseAddress!)
739+
return mutablePointer
740+
}
741+
*/
742+
743+
let dataContainer = UnsafeMutablePointer<LDKBalance>.allocate(capacity: array.count)
744+
dataContainer.initialize(from: array, count: array.count)
745+
746+
let vector = LDKCVec_BalanceZ(data: dataContainer, datalen: UInt(array.count))
747+
let wrapper = LDKCVec_BalanceZWrapper(pointer: vector)
748+
return wrapper
749+
}
750+
751+
public class LDKCVec_BalanceZWrapper: NativeTypeWrapper {
752+
private static var instanceCounter: UInt = 0
753+
internal let instanceNumber: UInt
754+
755+
internal var cOpaqueStruct: LDKCVec_BalanceZ?
756+
internal var subdimensionWrapper: [AnyObject]? = nil
757+
758+
public init(pointer: LDKCVec_BalanceZ){
759+
Self.instanceCounter += 1
760+
self.instanceNumber = Self.instanceCounter
761+
self.cOpaqueStruct = pointer
762+
super.init(conflictAvoidingVariableName: 0)
763+
}
764+
765+
internal init(pointer: LDKCVec_BalanceZ, subdimensionWrapper: [AnyObject]){
766+
Self.instanceCounter += 1
767+
self.instanceNumber = Self.instanceCounter
768+
self.subdimensionWrapper = subdimensionWrapper
769+
self.cOpaqueStruct = pointer
770+
super.init(conflictAvoidingVariableName: 0)
771+
}
772+
773+
public func noOpRetain(){}
774+
775+
internal func dangle(dangleSubdimensions: Bool = true) -> LDKCVec_BalanceZWrapper {
776+
self.dangling = true
777+
/* SUBDIMENSION_DANGLE_PREP */
778+
return self
779+
}
780+
781+
deinit {
782+
if !self.dangling {
783+
print("Freeing LDKCVec_BalanceZWrapper \(self.instanceNumber).")
784+
self.cOpaqueStruct!.data.deallocate()
785+
} else {
786+
print("Not freeing LDKCVec_BalanceZWrapper \(self.instanceNumber) due to dangle.")
787+
}
788+
}
789+
}
790+
/* SWIFT_TO_RUST_END */
791+
792+
/* RUST_TO_SWIFT_START */
793+
public class func LDKCVec_BalanceZ_to_array(nativeType: LDKCVec_BalanceZ, deallocate: Bool = true) -> [LDKBalance] {
794+
var array = [LDKBalance]()
795+
for index in 0..<Int(nativeType.datalen) {
796+
let currentEntry = nativeType.data[index]
797+
/* CONVERSION_PREP */
798+
array.append(currentEntry)
799+
}
800+
801+
if deallocate && nativeType.datalen > 0 {
802+
nativeType.data.deallocate()
803+
}
804+
805+
return array
806+
}
807+
/* RUST_TO_SWIFT_END */
808+
public class func extractNativeLDKBalanceArray(array: [Balance]) -> [LDKBalance] {
809+
return array.map { entry -> LDKBalance in
810+
entry.danglingClone().cOpaqueStruct!
811+
}
812+
}
813+
814+
public class func wrapNativeLDKBalanceArray(array: [LDKBalance]) -> [Balance] {
815+
return array.map { entry -> Balance in
816+
Balance(pointer: entry)
817+
}
818+
}
819+
820+
public class func wrapDanglingNativeLDKBalanceArray(array: [LDKBalance]) -> [Balance] {
821+
return array.map { entry -> Balance in
822+
Balance(pointer: entry).dangle()
823+
}
824+
}
825+
826+
internal class func cloneNativeLDKBalanceArray(array: [LDKBalance]) -> [LDKBalance] {
827+
return array.map { entry -> LDKBalance in
828+
// create a wrapper around the native object, dangle it to make it non-destructive, clone it, and then dangle the clone
829+
Balance(pointer: entry).dangle().clone().dangle().cOpaqueStruct!
830+
}
831+
}
832+
833+
732834
/* SWIFT_TO_RUST_START */
733835
public class func new_LDKCVec_C2Tuple_BlockHashChannelMonitorZZWrapper(array: [LDKC2Tuple_BlockHashChannelMonitorZ]) -> LDKCVec_C2Tuple_BlockHashChannelMonitorZZWrapper {
734836
/* DIMENSION_REDUCTION_PREP */
@@ -824,6 +926,108 @@ public class Bindings {
824926
}
825927

826928

929+
/* SWIFT_TO_RUST_START */
930+
public class func new_LDKCVec_C2Tuple_PublicKeyTypeZZWrapper(array: [LDKC2Tuple_PublicKeyTypeZ]) -> LDKCVec_C2Tuple_PublicKeyTypeZZWrapper {
931+
/* DIMENSION_REDUCTION_PREP */
932+
933+
/*
934+
let dataContainer = array.withUnsafeBufferPointer { (pointer: UnsafeBufferPointer<LDKC2Tuple_PublicKeyTypeZ>) -> UnsafeMutablePointer<LDKC2Tuple_PublicKeyTypeZ> in
935+
let mutablePointer = UnsafeMutablePointer<LDKC2Tuple_PublicKeyTypeZ>(mutating: pointer.baseAddress!)
936+
return mutablePointer
937+
}
938+
*/
939+
940+
let dataContainer = UnsafeMutablePointer<LDKC2Tuple_PublicKeyTypeZ>.allocate(capacity: array.count)
941+
dataContainer.initialize(from: array, count: array.count)
942+
943+
let vector = LDKCVec_C2Tuple_PublicKeyTypeZZ(data: dataContainer, datalen: UInt(array.count))
944+
let wrapper = LDKCVec_C2Tuple_PublicKeyTypeZZWrapper(pointer: vector)
945+
return wrapper
946+
}
947+
948+
public class LDKCVec_C2Tuple_PublicKeyTypeZZWrapper: NativeTypeWrapper {
949+
private static var instanceCounter: UInt = 0
950+
internal let instanceNumber: UInt
951+
952+
internal var cOpaqueStruct: LDKCVec_C2Tuple_PublicKeyTypeZZ?
953+
internal var subdimensionWrapper: [AnyObject]? = nil
954+
955+
public init(pointer: LDKCVec_C2Tuple_PublicKeyTypeZZ){
956+
Self.instanceCounter += 1
957+
self.instanceNumber = Self.instanceCounter
958+
self.cOpaqueStruct = pointer
959+
super.init(conflictAvoidingVariableName: 0)
960+
}
961+
962+
internal init(pointer: LDKCVec_C2Tuple_PublicKeyTypeZZ, subdimensionWrapper: [AnyObject]){
963+
Self.instanceCounter += 1
964+
self.instanceNumber = Self.instanceCounter
965+
self.subdimensionWrapper = subdimensionWrapper
966+
self.cOpaqueStruct = pointer
967+
super.init(conflictAvoidingVariableName: 0)
968+
}
969+
970+
public func noOpRetain(){}
971+
972+
internal func dangle(dangleSubdimensions: Bool = true) -> LDKCVec_C2Tuple_PublicKeyTypeZZWrapper {
973+
self.dangling = true
974+
/* SUBDIMENSION_DANGLE_PREP */
975+
return self
976+
}
977+
978+
deinit {
979+
if !self.dangling {
980+
print("Freeing LDKCVec_C2Tuple_PublicKeyTypeZZWrapper \(self.instanceNumber).")
981+
self.cOpaqueStruct!.data.deallocate()
982+
} else {
983+
print("Not freeing LDKCVec_C2Tuple_PublicKeyTypeZZWrapper \(self.instanceNumber) due to dangle.")
984+
}
985+
}
986+
}
987+
/* SWIFT_TO_RUST_END */
988+
989+
/* RUST_TO_SWIFT_START */
990+
public class func LDKCVec_C2Tuple_PublicKeyTypeZZ_to_array(nativeType: LDKCVec_C2Tuple_PublicKeyTypeZZ, deallocate: Bool = true) -> [LDKC2Tuple_PublicKeyTypeZ] {
991+
var array = [LDKC2Tuple_PublicKeyTypeZ]()
992+
for index in 0..<Int(nativeType.datalen) {
993+
let currentEntry = nativeType.data[index]
994+
/* CONVERSION_PREP */
995+
array.append(currentEntry)
996+
}
997+
998+
if deallocate && nativeType.datalen > 0 {
999+
nativeType.data.deallocate()
1000+
}
1001+
1002+
return array
1003+
}
1004+
/* RUST_TO_SWIFT_END */
1005+
public class func extractNativeLDKC2Tuple_PublicKeyTypeZArray(array: [C2Tuple_PublicKeyTypeZ]) -> [LDKC2Tuple_PublicKeyTypeZ] {
1006+
return array.map { entry -> LDKC2Tuple_PublicKeyTypeZ in
1007+
entry.danglingClone().cOpaqueStruct!
1008+
}
1009+
}
1010+
1011+
public class func wrapNativeLDKC2Tuple_PublicKeyTypeZArray(array: [LDKC2Tuple_PublicKeyTypeZ]) -> [C2Tuple_PublicKeyTypeZ] {
1012+
return array.map { entry -> C2Tuple_PublicKeyTypeZ in
1013+
C2Tuple_PublicKeyTypeZ(pointer: entry)
1014+
}
1015+
}
1016+
1017+
public class func wrapDanglingNativeLDKC2Tuple_PublicKeyTypeZArray(array: [LDKC2Tuple_PublicKeyTypeZ]) -> [C2Tuple_PublicKeyTypeZ] {
1018+
return array.map { entry -> C2Tuple_PublicKeyTypeZ in
1019+
C2Tuple_PublicKeyTypeZ(pointer: entry).dangle()
1020+
}
1021+
}
1022+
1023+
internal class func cloneNativeLDKC2Tuple_PublicKeyTypeZArray(array: [LDKC2Tuple_PublicKeyTypeZ]) -> [LDKC2Tuple_PublicKeyTypeZ] {
1024+
return array.map { entry -> LDKC2Tuple_PublicKeyTypeZ in
1025+
// create a wrapper around the native object, dangle it to make it non-destructive, clone it, and then dangle the clone
1026+
C2Tuple_PublicKeyTypeZ(pointer: entry).dangle().clone().dangle().cOpaqueStruct!
1027+
}
1028+
}
1029+
1030+
8271031
/* SWIFT_TO_RUST_START */
8281032
public class func new_LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZZWrapper(array: [LDKC2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ]) -> LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZZWrapper {
8291033
/* DIMENSION_REDUCTION_PREP */
@@ -4035,6 +4239,24 @@ public class func swift_C2Tuple_BlockHashChannelManagerZ_read(ser: [UInt8], arg:
40354239

40364240
}
40374241

4242+
}
4243+
public class func swift_build_closing_transaction(to_holder_value_sat: UInt64, to_counterparty_value_sat: UInt64, to_holder_script: [UInt8], to_counterparty_script: [UInt8], funding_outpoint: OutPoint) -> [UInt8] {
4244+
4245+
4246+
let to_holder_scriptWrapper = Bindings.new_LDKCVec_u8ZWrapper(array: to_holder_script)
4247+
defer {
4248+
to_holder_scriptWrapper.noOpRetain()
4249+
}
4250+
4251+
let to_counterparty_scriptWrapper = Bindings.new_LDKCVec_u8ZWrapper(array: to_counterparty_script)
4252+
defer {
4253+
to_counterparty_scriptWrapper.noOpRetain()
4254+
}
4255+
4256+
return
4257+
Bindings.LDKTransaction_to_array(nativeType: build_closing_transaction(to_holder_value_sat, to_counterparty_value_sat, to_holder_scriptWrapper.dangle().cOpaqueStruct!, to_counterparty_scriptWrapper.dangle().cOpaqueStruct!, funding_outpoint.danglingClone().cOpaqueStruct!))
4258+
4259+
40384260
}
40394261
public class func swift_derive_private_key(per_commitment_point: [UInt8], base_secret: [UInt8]) -> Result_SecretKeyErrorZ {
40404262

@@ -4317,10 +4539,10 @@ withUnsafePointer(to: htlc.cOpaqueStruct!) { (htlcPointer: UnsafePointer<LDKHTLC
43174539
return UnsafePointer<UInt8>(dataMutablePointer)
43184540
}
43194541

4320-
public class func new_LDKStr(string: String) -> LDKStr {
4321-
let nativeType = Self.string_to_unsafe_uint8_pointer(string: string)
4322-
return LDKStr(chars: nativeType, len: UInt(string.count), chars_is_owned: false)
4323-
}
4542+
public class func new_LDKStr(string: String, chars_is_owned: Bool = false) -> LDKStr {
4543+
let nativeType = Self.string_to_unsafe_uint8_pointer(string: string)
4544+
return LDKStr(chars: nativeType, len: UInt(string.count), chars_is_owned: chars_is_owned)
4545+
}
43244546

43254547
public class func createInvoiceFromChannelManager(channelManager: ChannelManager, keysManager: KeysInterface, network: LDKCurrency, amountMsat: UInt64?, description: String) -> Result_InvoiceSignOrCreationErrorZ {
43264548
let nativeKeysManager = keysManager.cOpaqueStruct!

0 commit comments

Comments
 (0)