diff --git a/Package.swift b/Package.swift index d3856a9..d393f49 100644 --- a/Package.swift +++ b/Package.swift @@ -24,8 +24,8 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages this package depends on. .binaryTarget( name: "bdkFFI", - url: "https://github.com/bitcoindevkit/bdk-swift/releases/download/1.0.0-alpha.11/bdkFFI.xcframework.zip", - checksum: "730fdc77b45eefdc6a5f30824d67254f44037dd708f5287a081c68109b1609fc"), + url: "https://github.com/bitcoindevkit/bdk-swift/releases/download/1.0.0-beta.2/bdkFFI.xcframework.zip", + checksum: "255639a47a8b076163700a242f0d152911c2b689c2f18c9346764cb7645dc8b7"), .target( name: "BitcoinDevKit", dependencies: ["bdkFFI"]), diff --git a/Sources/BitcoinDevKit/Bitcoin.swift b/Sources/BitcoinDevKit/Bitcoin.swift new file mode 100644 index 0000000..4a6b79a --- /dev/null +++ b/Sources/BitcoinDevKit/Bitcoin.swift @@ -0,0 +1,1223 @@ +// This file was autogenerated by some hot garbage in the `uniffi` crate. +// Trust me, you don't want to mess with it! + +// swiftlint:disable all +import Foundation + +// Depending on the consumer's build setup, the low-level FFI code +// might be in a separate module, or it might be compiled inline into +// this module. This is a bit of light hackery to work with both. +#if canImport(BitcoinFFI) +import BitcoinFFI +#endif + +fileprivate extension RustBuffer { + // Allocate a new buffer, copying the contents of a `UInt8` array. + init(bytes: [UInt8]) { + let rbuf = bytes.withUnsafeBufferPointer { ptr in + RustBuffer.from(ptr) + } + self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data) + } + + static func empty() -> RustBuffer { + RustBuffer(capacity: 0, len:0, data: nil) + } + + static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { + try! rustCall { ffi_bitcoin_ffi_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + } + + // Frees the buffer in place. + // The buffer must not be used after this is called. + func deallocate() { + try! rustCall { ffi_bitcoin_ffi_rustbuffer_free(self, $0) } + } +} + +fileprivate extension ForeignBytes { + init(bufferPointer: UnsafeBufferPointer) { + self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress) + } +} + +// For every type used in the interface, we provide helper methods for conveniently +// lifting and lowering that type from C-compatible data, and for reading and writing +// values of that type in a buffer. + +// Helper classes/extensions that don't change. +// Someday, this will be in a library of its own. + +fileprivate extension Data { + init(rustBuffer: RustBuffer) { + // TODO: This copies the buffer. Can we read directly from a + // Rust buffer? + self.init(bytes: rustBuffer.data!, count: Int(rustBuffer.len)) + } +} + +// Define reader functionality. Normally this would be defined in a class or +// struct, but we use standalone functions instead in order to make external +// types work. +// +// With external types, one swift source file needs to be able to call the read +// method on another source file's FfiConverter, but then what visibility +// should Reader have? +// - If Reader is fileprivate, then this means the read() must also +// be fileprivate, which doesn't work with external types. +// - If Reader is internal/public, we'll get compile errors since both source +// files will try define the same type. +// +// Instead, the read() method and these helper functions input a tuple of data + +fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) { + (data: data, offset: 0) +} + +// Reads an integer at the current offset, in big-endian order, and advances +// the offset on success. Throws if reading the integer would move the +// offset past the end of the buffer. +fileprivate func readInt(_ reader: inout (data: Data, offset: Data.Index)) throws -> T { + let range = reader.offset...size + guard reader.data.count >= range.upperBound else { + throw UniffiInternalError.bufferOverflow + } + if T.self == UInt8.self { + let value = reader.data[reader.offset] + reader.offset += 1 + return value as! T + } + var value: T = 0 + let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)}) + reader.offset = range.upperBound + return value.bigEndian +} + +// Reads an arbitrary number of bytes, to be used to read +// raw bytes, this is useful when lifting strings +fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array { + let range = reader.offset..<(reader.offset+count) + guard reader.data.count >= range.upperBound else { + throw UniffiInternalError.bufferOverflow + } + var value = [UInt8](repeating: 0, count: count) + value.withUnsafeMutableBufferPointer({ buffer in + reader.data.copyBytes(to: buffer, from: range) + }) + reader.offset = range.upperBound + return value +} + +// Reads a float at the current offset. +fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float { + return Float(bitPattern: try readInt(&reader)) +} + +// Reads a float at the current offset. +fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double { + return Double(bitPattern: try readInt(&reader)) +} + +// Indicates if the offset has reached the end of the buffer. +fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool { + return reader.offset < reader.data.count +} + +// Define writer functionality. Normally this would be defined in a class or +// struct, but we use standalone functions instead in order to make external +// types work. See the above discussion on Readers for details. + +fileprivate func createWriter() -> [UInt8] { + return [] +} + +fileprivate func writeBytes(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 { + writer.append(contentsOf: byteArr) +} + +// Writes an integer in big-endian order. +// +// Warning: make sure what you are trying to write +// is in the correct type! +fileprivate func writeInt(_ writer: inout [UInt8], _ value: T) { + var value = value.bigEndian + withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) } +} + +fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) { + writeInt(&writer, value.bitPattern) +} + +fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) { + writeInt(&writer, value.bitPattern) +} + +// Protocol for types that transfer other types across the FFI. This is +// analogous to the Rust trait of the same name. +fileprivate protocol FfiConverter { + associatedtype FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType + static func write(_ value: SwiftType, into buf: inout [UInt8]) +} + +// Types conforming to `Primitive` pass themselves directly over the FFI. +fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { } + +extension FfiConverterPrimitive { + public static func lift(_ value: FfiType) throws -> SwiftType { + return value + } + + public static func lower(_ value: SwiftType) -> FfiType { + return value + } +} + +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} + +extension FfiConverterRustBuffer { + public static func lift(_ buf: RustBuffer) throws -> SwiftType { + var reader = createReader(data: Data(rustBuffer: buf)) + let value = try read(from: &reader) + if hasRemaining(reader) { + throw UniffiInternalError.incompleteData + } + buf.deallocate() + return value + } + + public static func lower(_ value: SwiftType) -> RustBuffer { + var writer = createWriter() + write(value, into: &writer) + return RustBuffer(bytes: writer) + } +} +// An error type for FFI errors. These errors occur at the UniFFI level, not +// the library level. +fileprivate enum UniffiInternalError: LocalizedError { + case bufferOverflow + case incompleteData + case unexpectedOptionalTag + case unexpectedEnumCase + case unexpectedNullPointer + case unexpectedRustCallStatusCode + case unexpectedRustCallError + case unexpectedStaleHandle + case rustPanic(_ message: String) + + public var errorDescription: String? { + switch self { + case .bufferOverflow: return "Reading the requested value would read past the end of the buffer" + case .incompleteData: return "The buffer still has data after lifting its containing value" + case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1" + case .unexpectedEnumCase: return "Raw enum value doesn't match any cases" + case .unexpectedNullPointer: return "Raw pointer value was null" + case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code" + case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified" + case .unexpectedStaleHandle: return "The object in the handle map has been dropped already" + case let .rustPanic(message): return message + } + } +} + +fileprivate extension NSLock { + func withLock(f: () throws -> T) rethrows -> T { + self.lock() + defer { self.unlock() } + return try f() + } +} + +fileprivate let CALL_SUCCESS: Int8 = 0 +fileprivate let CALL_ERROR: Int8 = 1 +fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2 +fileprivate let CALL_CANCELLED: Int8 = 3 + +fileprivate extension RustCallStatus { + init() { + self.init( + code: CALL_SUCCESS, + errorBuf: RustBuffer.init( + capacity: 0, + len: 0, + data: nil + ) + ) + } +} + +private func rustCall(_ callback: (UnsafeMutablePointer) -> T) throws -> T { + let neverThrow: ((RustBuffer) throws -> Never)? = nil + return try makeRustCall(callback, errorHandler: neverThrow) +} + +private func rustCallWithError( + _ errorHandler: @escaping (RustBuffer) throws -> E, + _ callback: (UnsafeMutablePointer) -> T) throws -> T { + try makeRustCall(callback, errorHandler: errorHandler) +} + +private func makeRustCall( + _ callback: (UnsafeMutablePointer) -> T, + errorHandler: ((RustBuffer) throws -> E)? +) throws -> T { + uniffiEnsureInitialized() + var callStatus = RustCallStatus.init() + let returnedVal = callback(&callStatus) + try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler) + return returnedVal +} + +private func uniffiCheckCallStatus( + callStatus: RustCallStatus, + errorHandler: ((RustBuffer) throws -> E)? +) throws { + switch callStatus.code { + case CALL_SUCCESS: + return + + case CALL_ERROR: + if let errorHandler = errorHandler { + throw try errorHandler(callStatus.errorBuf) + } else { + callStatus.errorBuf.deallocate() + throw UniffiInternalError.unexpectedRustCallError + } + + case CALL_UNEXPECTED_ERROR: + // When the rust code sees a panic, it tries to construct a RustBuffer + // with the message. But if that code panics, then it just sends back + // an empty buffer. + if callStatus.errorBuf.len > 0 { + throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) + } else { + callStatus.errorBuf.deallocate() + throw UniffiInternalError.rustPanic("Rust panic") + } + + case CALL_CANCELLED: + fatalError("Cancellation not supported yet") + + default: + throw UniffiInternalError.unexpectedRustCallStatusCode + } +} + +private func uniffiTraitInterfaceCall( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> () +) { + do { + try writeReturn(makeCall()) + } catch let error { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} + +private func uniffiTraitInterfaceCallWithError( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> (), + lowerError: (E) -> RustBuffer +) { + do { + try writeReturn(makeCall()) + } catch let error as E { + callStatus.pointee.code = CALL_ERROR + callStatus.pointee.errorBuf = lowerError(error) + } catch { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} +fileprivate class UniffiHandleMap { + private var map: [UInt64: T] = [:] + private let lock = NSLock() + private var currentHandle: UInt64 = 1 + + func insert(obj: T) -> UInt64 { + lock.withLock { + let handle = currentHandle + currentHandle += 1 + map[handle] = obj + return handle + } + } + + func get(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map[handle] else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + @discardableResult + func remove(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map.removeValue(forKey: handle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + var count: Int { + get { + map.count + } + } +} + + +// Public interface members begin here. + + +fileprivate struct FfiConverterUInt8: FfiConverterPrimitive { + typealias FfiType = UInt8 + typealias SwiftType = UInt8 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt8 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: UInt8, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +fileprivate struct FfiConverterUInt32: FfiConverterPrimitive { + typealias FfiType = UInt32 + typealias SwiftType = UInt32 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +fileprivate struct FfiConverterUInt64: FfiConverterPrimitive { + typealias FfiType = UInt64 + typealias SwiftType = UInt64 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +fileprivate struct FfiConverterDouble: FfiConverterPrimitive { + typealias FfiType = Double + typealias SwiftType = Double + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Double { + return try lift(readDouble(&buf)) + } + + public static func write(_ value: Double, into buf: inout [UInt8]) { + writeDouble(&buf, lower(value)) + } +} + +fileprivate struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer + + public static func lift(_ value: RustBuffer) throws -> String { + defer { + value.deallocate() + } + if value.data == nil { + return String() + } + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) + return String(bytes: bytes, encoding: String.Encoding.utf8)! + } + + public static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in + // The swift string gives us int8_t, we want uint8_t. + ptr.withMemoryRebound(to: UInt8.self) { ptr in + // The swift string gives us a trailing null byte, we don't want it. + let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1)) + return RustBuffer.from(buf) + } + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String { + let len: Int32 = try readInt(&buf) + return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)! + } + + public static func write(_ value: String, into buf: inout [UInt8]) { + let len = Int32(value.utf8.count) + writeInt(&buf, len) + writeBytes(&buf, value.utf8) + } +} + + + + +public protocol AmountProtocol : AnyObject { + + func toBtc() -> Double + + func toSat() -> UInt64 + +} + +open class Amount: + AmountProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_bitcoin_ffi_fn_clone_amount(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_bitcoin_ffi_fn_free_amount(pointer, $0) } + } + + +public static func fromBtc(fromBtc: Double)throws -> Amount { + return try FfiConverterTypeAmount.lift(try rustCallWithError(FfiConverterTypeParseAmountError.lift) { + uniffi_bitcoin_ffi_fn_constructor_amount_from_btc( + FfiConverterDouble.lower(fromBtc),$0 + ) +}) +} + +public static func fromSat(fromSat: UInt64) -> Amount { + return try! FfiConverterTypeAmount.lift(try! rustCall() { + uniffi_bitcoin_ffi_fn_constructor_amount_from_sat( + FfiConverterUInt64.lower(fromSat),$0 + ) +}) +} + + + +open func toBtc() -> Double { + return try! FfiConverterDouble.lift(try! rustCall() { + uniffi_bitcoin_ffi_fn_method_amount_to_btc(self.uniffiClonePointer(),$0 + ) +}) +} + +open func toSat() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_bitcoin_ffi_fn_method_amount_to_sat(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + +public struct FfiConverterTypeAmount: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = Amount + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Amount { + return Amount(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: Amount) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Amount { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: Amount, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + + + +public func FfiConverterTypeAmount_lift(_ pointer: UnsafeMutableRawPointer) throws -> Amount { + return try FfiConverterTypeAmount.lift(pointer) +} + +public func FfiConverterTypeAmount_lower(_ value: Amount) -> UnsafeMutableRawPointer { + return FfiConverterTypeAmount.lower(value) +} + + + + +public protocol FeeRateProtocol : AnyObject { + + func toSatPerKwu() -> UInt64 + + func toSatPerVbCeil() -> UInt64 + + func toSatPerVbFloor() -> UInt64 + +} + +open class FeeRate: + FeeRateProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_bitcoin_ffi_fn_clone_feerate(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_bitcoin_ffi_fn_free_feerate(pointer, $0) } + } + + +public static func fromSatPerKwu(satPerKwu: UInt64) -> FeeRate { + return try! FfiConverterTypeFeeRate.lift(try! rustCall() { + uniffi_bitcoin_ffi_fn_constructor_feerate_from_sat_per_kwu( + FfiConverterUInt64.lower(satPerKwu),$0 + ) +}) +} + +public static func fromSatPerVb(satPerVb: UInt64)throws -> FeeRate { + return try FfiConverterTypeFeeRate.lift(try rustCallWithError(FfiConverterTypeFeeRateError.lift) { + uniffi_bitcoin_ffi_fn_constructor_feerate_from_sat_per_vb( + FfiConverterUInt64.lower(satPerVb),$0 + ) +}) +} + + + +open func toSatPerKwu() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_bitcoin_ffi_fn_method_feerate_to_sat_per_kwu(self.uniffiClonePointer(),$0 + ) +}) +} + +open func toSatPerVbCeil() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_bitcoin_ffi_fn_method_feerate_to_sat_per_vb_ceil(self.uniffiClonePointer(),$0 + ) +}) +} + +open func toSatPerVbFloor() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_bitcoin_ffi_fn_method_feerate_to_sat_per_vb_floor(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + +public struct FfiConverterTypeFeeRate: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = FeeRate + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FeeRate { + return FeeRate(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FeeRate) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FeeRate { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: FeeRate, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + + + +public func FfiConverterTypeFeeRate_lift(_ pointer: UnsafeMutableRawPointer) throws -> FeeRate { + return try FfiConverterTypeFeeRate.lift(pointer) +} + +public func FfiConverterTypeFeeRate_lower(_ value: FeeRate) -> UnsafeMutableRawPointer { + return FfiConverterTypeFeeRate.lower(value) +} + + + + +public protocol ScriptProtocol : AnyObject { + + func toBytes() -> [UInt8] + +} + +open class Script: + ScriptProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_bitcoin_ffi_fn_clone_script(self.pointer, $0) } + } +public convenience init(rawOutputScript: [UInt8]) { + let pointer = + try! rustCall() { + uniffi_bitcoin_ffi_fn_constructor_script_new( + FfiConverterSequenceUInt8.lower(rawOutputScript),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_bitcoin_ffi_fn_free_script(pointer, $0) } + } + + + + +open func toBytes() -> [UInt8] { + return try! FfiConverterSequenceUInt8.lift(try! rustCall() { + uniffi_bitcoin_ffi_fn_method_script_to_bytes(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + +public struct FfiConverterTypeScript: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = Script + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Script { + return Script(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: Script) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Script { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: Script, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + + + +public func FfiConverterTypeScript_lift(_ pointer: UnsafeMutableRawPointer) throws -> Script { + return try FfiConverterTypeScript.lift(pointer) +} + +public func FfiConverterTypeScript_lower(_ value: Script) -> UnsafeMutableRawPointer { + return FfiConverterTypeScript.lower(value) +} + + +public struct OutPoint { + public var txid: Txid + public var vout: UInt32 + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(txid: Txid, vout: UInt32) { + self.txid = txid + self.vout = vout + } +} + + + +extension OutPoint: Equatable, Hashable { + public static func ==(lhs: OutPoint, rhs: OutPoint) -> Bool { + if lhs.txid != rhs.txid { + return false + } + if lhs.vout != rhs.vout { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(txid) + hasher.combine(vout) + } +} + + +public struct FfiConverterTypeOutPoint: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> OutPoint { + return + try OutPoint( + txid: FfiConverterTypeTxid.read(from: &buf), + vout: FfiConverterUInt32.read(from: &buf) + ) + } + + public static func write(_ value: OutPoint, into buf: inout [UInt8]) { + FfiConverterTypeTxid.write(value.txid, into: &buf) + FfiConverterUInt32.write(value.vout, into: &buf) + } +} + + +public func FfiConverterTypeOutPoint_lift(_ buf: RustBuffer) throws -> OutPoint { + return try FfiConverterTypeOutPoint.lift(buf) +} + +public func FfiConverterTypeOutPoint_lower(_ value: OutPoint) -> RustBuffer { + return FfiConverterTypeOutPoint.lower(value) +} + + +public enum FeeRateError { + + + + case ArithmeticOverflow +} + + +public struct FfiConverterTypeFeeRateError: FfiConverterRustBuffer { + typealias SwiftType = FeeRateError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FeeRateError { + let variant: Int32 = try readInt(&buf) + switch variant { + + + + + case 1: return .ArithmeticOverflow + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: FeeRateError, into buf: inout [UInt8]) { + switch value { + + + + + + case .ArithmeticOverflow: + writeInt(&buf, Int32(1)) + + } + } +} + + +extension FeeRateError: Equatable, Hashable {} + +extension FeeRateError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum Network { + + case bitcoin + case testnet + case signet + case regtest +} + + +public struct FfiConverterTypeNetwork: FfiConverterRustBuffer { + typealias SwiftType = Network + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Network { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .bitcoin + + case 2: return .testnet + + case 3: return .signet + + case 4: return .regtest + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: Network, into buf: inout [UInt8]) { + switch value { + + + case .bitcoin: + writeInt(&buf, Int32(1)) + + + case .testnet: + writeInt(&buf, Int32(2)) + + + case .signet: + writeInt(&buf, Int32(3)) + + + case .regtest: + writeInt(&buf, Int32(4)) + + } + } +} + + +public func FfiConverterTypeNetwork_lift(_ buf: RustBuffer) throws -> Network { + return try FfiConverterTypeNetwork.lift(buf) +} + +public func FfiConverterTypeNetwork_lower(_ value: Network) -> RustBuffer { + return FfiConverterTypeNetwork.lower(value) +} + + + +extension Network: Equatable, Hashable {} + + + + +public enum ParseAmountError { + + + + case OutOfRange + case TooPrecise + case MissingDigits + case InputTooLarge + case InvalidCharacter(errorMessage: String + ) + case OtherParseAmountErr +} + + +public struct FfiConverterTypeParseAmountError: FfiConverterRustBuffer { + typealias SwiftType = ParseAmountError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ParseAmountError { + let variant: Int32 = try readInt(&buf) + switch variant { + + + + + case 1: return .OutOfRange + case 2: return .TooPrecise + case 3: return .MissingDigits + case 4: return .InputTooLarge + case 5: return .InvalidCharacter( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 6: return .OtherParseAmountErr + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: ParseAmountError, into buf: inout [UInt8]) { + switch value { + + + + + + case .OutOfRange: + writeInt(&buf, Int32(1)) + + + case .TooPrecise: + writeInt(&buf, Int32(2)) + + + case .MissingDigits: + writeInt(&buf, Int32(3)) + + + case .InputTooLarge: + writeInt(&buf, Int32(4)) + + + case let .InvalidCharacter(errorMessage): + writeInt(&buf, Int32(5)) + FfiConverterString.write(errorMessage, into: &buf) + + + case .OtherParseAmountErr: + writeInt(&buf, Int32(6)) + + } + } +} + + +extension ParseAmountError: Equatable, Hashable {} + +extension ParseAmountError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} + +fileprivate struct FfiConverterSequenceUInt8: FfiConverterRustBuffer { + typealias SwiftType = [UInt8] + + public static func write(_ value: [UInt8], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterUInt8.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [UInt8] { + let len: Int32 = try readInt(&buf) + var seq = [UInt8]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterUInt8.read(from: &buf)) + } + return seq + } +} + + +/** + * Typealias from the type name used in the UDL file to the builtin type. This + * is needed because the UDL type name is used in function/method signatures. + */ +public typealias Txid = String +public struct FfiConverterTypeTxid: FfiConverter { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Txid { + return try FfiConverterString.read(from: &buf) + } + + public static func write(_ value: Txid, into buf: inout [UInt8]) { + return FfiConverterString.write(value, into: &buf) + } + + public static func lift(_ value: RustBuffer) throws -> Txid { + return try FfiConverterString.lift(value) + } + + public static func lower(_ value: Txid) -> RustBuffer { + return FfiConverterString.lower(value) + } +} + + +public func FfiConverterTypeTxid_lift(_ value: RustBuffer) throws -> Txid { + return try FfiConverterTypeTxid.lift(value) +} + +public func FfiConverterTypeTxid_lower(_ value: Txid) -> RustBuffer { + return FfiConverterTypeTxid.lower(value) +} + + +private enum InitializationResult { + case ok + case contractVersionMismatch + case apiChecksumMismatch +} +// Use a global variable to perform the versioning checks. Swift ensures that +// the code inside is only computed once. +private var initializationResult: InitializationResult = { + // Get the bindings contract version from our ComponentInterface + let bindings_contract_version = 26 + // Get the scaffolding contract version by calling the into the dylib + let scaffolding_contract_version = ffi_bitcoin_ffi_uniffi_contract_version() + if bindings_contract_version != scaffolding_contract_version { + return InitializationResult.contractVersionMismatch + } + if (uniffi_bitcoin_ffi_checksum_method_amount_to_btc() != 6538) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bitcoin_ffi_checksum_method_amount_to_sat() != 9947) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bitcoin_ffi_checksum_method_feerate_to_sat_per_kwu() != 34871) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bitcoin_ffi_checksum_method_feerate_to_sat_per_vb_ceil() != 36445) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bitcoin_ffi_checksum_method_feerate_to_sat_per_vb_floor() != 14258) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bitcoin_ffi_checksum_method_script_to_bytes() != 2169) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bitcoin_ffi_checksum_constructor_amount_from_btc() != 58031) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bitcoin_ffi_checksum_constructor_amount_from_sat() != 19356) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bitcoin_ffi_checksum_constructor_feerate_from_sat_per_kwu() != 37445) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bitcoin_ffi_checksum_constructor_feerate_from_sat_per_vb() != 13015) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bitcoin_ffi_checksum_constructor_script_new() != 5408) { + return InitializationResult.apiChecksumMismatch + } + + return InitializationResult.ok +}() + +private func uniffiEnsureInitialized() { + switch initializationResult { + case .ok: + break + case .contractVersionMismatch: + fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") + case .apiChecksumMismatch: + fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } +} + +// swiftlint:enable all \ No newline at end of file diff --git a/Sources/BitcoinDevKit/BitcoinDevKit.swift b/Sources/BitcoinDevKit/BitcoinDevKit.swift index 453ec38..325a06c 100644 --- a/Sources/BitcoinDevKit/BitcoinDevKit.swift +++ b/Sources/BitcoinDevKit/BitcoinDevKit.swift @@ -1,12 +1,14 @@ // This file was autogenerated by some hot garbage in the `uniffi` crate. // Trust me, you don't want to mess with it! + +// swiftlint:disable all import Foundation // Depending on the consumer's build setup, the low-level FFI code // might be in a separate module, or it might be compiled inline into // this module. This is a bit of light hackery to work with both. -#if canImport(bdkFFI) -import bdkFFI +#if canImport(BitcoinDevKitFFI) +import BitcoinDevKitFFI #endif fileprivate extension RustBuffer { @@ -18,6 +20,10 @@ fileprivate extension RustBuffer { self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data) } + static func empty() -> RustBuffer { + RustBuffer(capacity: 0, len:0, data: nil) + } + static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { try! rustCall { ffi_bdkffi_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } } @@ -147,7 +153,7 @@ fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) { } // Protocol for types that transfer other types across the FFI. This is -// analogous go the Rust trait of the same name. +// analogous to the Rust trait of the same name. fileprivate protocol FfiConverter { associatedtype FfiType associatedtype SwiftType @@ -220,9 +226,17 @@ fileprivate enum UniffiInternalError: LocalizedError { } } +fileprivate extension NSLock { + func withLock(f: () throws -> T) rethrows -> T { + self.lock() + defer { self.unlock() } + return try f() + } +} + fileprivate let CALL_SUCCESS: Int8 = 0 fileprivate let CALL_ERROR: Int8 = 1 -fileprivate let CALL_PANIC: Int8 = 2 +fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2 fileprivate let CALL_CANCELLED: Int8 = 3 fileprivate extension RustCallStatus { @@ -239,18 +253,19 @@ fileprivate extension RustCallStatus { } private func rustCall(_ callback: (UnsafeMutablePointer) -> T) throws -> T { - try makeRustCall(callback, errorHandler: nil) + let neverThrow: ((RustBuffer) throws -> Never)? = nil + return try makeRustCall(callback, errorHandler: neverThrow) } -private func rustCallWithError( - _ errorHandler: @escaping (RustBuffer) throws -> Error, +private func rustCallWithError( + _ errorHandler: @escaping (RustBuffer) throws -> E, _ callback: (UnsafeMutablePointer) -> T) throws -> T { try makeRustCall(callback, errorHandler: errorHandler) } -private func makeRustCall( +private func makeRustCall( _ callback: (UnsafeMutablePointer) -> T, - errorHandler: ((RustBuffer) throws -> Error)? + errorHandler: ((RustBuffer) throws -> E)? ) throws -> T { uniffiEnsureInitialized() var callStatus = RustCallStatus.init() @@ -259,9 +274,9 @@ private func makeRustCall( return returnedVal } -private func uniffiCheckCallStatus( +private func uniffiCheckCallStatus( callStatus: RustCallStatus, - errorHandler: ((RustBuffer) throws -> Error)? + errorHandler: ((RustBuffer) throws -> E)? ) throws { switch callStatus.code { case CALL_SUCCESS: @@ -275,7 +290,7 @@ private func uniffiCheckCallStatus( throw UniffiInternalError.unexpectedRustCallError } - case CALL_PANIC: + case CALL_UNEXPECTED_ERROR: // When the rust code sees a panic, it tries to construct a RustBuffer // with the message. But if that code panics, then it just sends back // an empty buffer. @@ -294,6 +309,76 @@ private func uniffiCheckCallStatus( } } +private func uniffiTraitInterfaceCall( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> () +) { + do { + try writeReturn(makeCall()) + } catch let error { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} + +private func uniffiTraitInterfaceCallWithError( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> (), + lowerError: (E) -> RustBuffer +) { + do { + try writeReturn(makeCall()) + } catch let error as E { + callStatus.pointee.code = CALL_ERROR + callStatus.pointee.errorBuf = lowerError(error) + } catch { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} +fileprivate class UniffiHandleMap { + private var map: [UInt64: T] = [:] + private let lock = NSLock() + private var currentHandle: UInt64 = 1 + + func insert(obj: T) -> UInt64 { + lock.withLock { + let handle = currentHandle + currentHandle += 1 + map[handle] = obj + return handle + } + } + + func get(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map[handle] else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + @discardableResult + func remove(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map.removeValue(forKey: handle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + var count: Int { + get { + map.count + } + } +} + + // Public interface members begin here. @@ -362,32 +447,6 @@ fileprivate struct FfiConverterUInt64: FfiConverterPrimitive { } } -fileprivate struct FfiConverterInt64: FfiConverterPrimitive { - typealias FfiType = Int64 - typealias SwiftType = Int64 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Int64 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: Int64, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - -fileprivate struct FfiConverterDouble: FfiConverterPrimitive { - typealias FfiType = Double - typealias SwiftType = Double - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Double { - return try lift(readDouble(&buf)) - } - - public static func write(_ value: Double, into buf: inout [UInt8]) { - writeDouble(&buf, lower(value)) - } -} - fileprivate struct FfiConverterBool : FfiConverter { typealias FfiType = Int8 typealias SwiftType = Bool @@ -452,95 +511,100 @@ fileprivate struct FfiConverterString: FfiConverter { public protocol AddressProtocol : AnyObject { - func asString() -> String - func isValidForNetwork(network: Network) -> Bool - func network() -> Network - func scriptPubkey() -> Script func toQrUri() -> String } -public class Address: +open class Address: + CustomStringConvertible, AddressProtocol { - fileprivate let pointer: UnsafeMutableRawPointer + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_address(self.pointer, $0) } } - public convenience init(address: String, network: Network) throws { - self.init(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeAddressError.lift) { +public convenience init(address: String, network: Network)throws { + let pointer = + try rustCallWithError(FfiConverterTypeAddressParseError.lift) { uniffi_bdkffi_fn_constructor_address_new( FfiConverterString.lower(address), - FfiConverterTypeNetwork.lower(network),$0) -}) - } + FfiConverterTypeNetwork_lower(network),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_bdkffi_fn_free_address(pointer, $0) } } - - - - public func asString() -> String { - return try! FfiConverterString.lift( - try! - rustCall() { - - uniffi_bdkffi_fn_method_address_as_string(self.uniffiClonePointer(), $0 +public static func fromScript(script: Script, network: Network)throws -> Address { + return try FfiConverterTypeAddress.lift(try rustCallWithError(FfiConverterTypeFromScriptError.lift) { + uniffi_bdkffi_fn_constructor_address_from_script( + FfiConverterTypeScript_lower(script), + FfiConverterTypeNetwork_lower(network),$0 ) +}) } - ) - } - public func isValidForNetwork(network: Network) -> Bool { - return try! FfiConverterBool.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_address_is_valid_for_network(self.uniffiClonePointer(), - FfiConverterTypeNetwork.lower(network),$0 + + +open func isValidForNetwork(network: Network) -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_bdkffi_fn_method_address_is_valid_for_network(self.uniffiClonePointer(), + FfiConverterTypeNetwork_lower(network),$0 ) +}) } - ) - } - public func network() -> Network { - return try! FfiConverterTypeNetwork.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_address_network(self.uniffiClonePointer(), $0 +open func scriptPubkey() -> Script { + return try! FfiConverterTypeScript_lift(try! rustCall() { + uniffi_bdkffi_fn_method_address_script_pubkey(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func scriptPubkey() -> Script { - return try! FfiConverterTypeScript.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_address_script_pubkey(self.uniffiClonePointer(), $0 +open func toQrUri() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_bdkffi_fn_method_address_to_qr_uri(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func toQrUri() -> String { - return try! FfiConverterString.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_address_to_qr_uri(self.uniffiClonePointer(), $0 + open var description: String { + return try! FfiConverterString.lift( + try! rustCall() { + uniffi_bdkffi_fn_method_address_uniffi_trait_display(self.uniffiClonePointer(),$0 ) } ) @@ -580,6 +644,8 @@ public struct FfiConverterTypeAddress: FfiConverter { } + + public func FfiConverterTypeAddress_lift(_ pointer: UnsafeMutableRawPointer) throws -> Address { return try FfiConverterTypeAddress.lift(pointer) } @@ -591,90 +657,106 @@ public func FfiConverterTypeAddress_lower(_ value: Address) -> UnsafeMutableRawP -public protocol AmountProtocol : AnyObject { +public protocol BumpFeeTxBuilderProtocol : AnyObject { - func toBtc() -> Double + func enableRbf() -> BumpFeeTxBuilder + + func enableRbfWithSequence(nsequence: UInt32) -> BumpFeeTxBuilder - func toSat() -> UInt64 + func finish(wallet: Wallet) throws -> Psbt } -public class Amount: - AmountProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class BumpFeeTxBuilder: + BumpFeeTxBuilderProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_bdkffi_fn_clone_amount(self.pointer, $0) } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil } - deinit { - try! rustCall { uniffi_bdkffi_fn_free_amount(pointer, $0) } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_bdkffi_fn_clone_bumpfeetxbuilder(self.pointer, $0) } } +public convenience init(txid: String, feeRate: FeeRate) { + let pointer = + try! rustCall() { + uniffi_bdkffi_fn_constructor_bumpfeetxbuilder_new( + FfiConverterString.lower(txid), + FfiConverterTypeFeeRate_lower(feeRate),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} - - public static func fromBtc(fromBtc: Double) throws -> Amount { - return Amount(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeParseAmountError.lift) { - uniffi_bdkffi_fn_constructor_amount_from_btc( - FfiConverterDouble.lower(fromBtc),$0) -}) - } + deinit { + guard let pointer = pointer else { + return + } - - public static func fromSat(fromSat: UInt64) -> Amount { - return Amount(unsafeFromRawPointer: try! rustCall() { - uniffi_bdkffi_fn_constructor_amount_from_sat( - FfiConverterUInt64.lower(fromSat),$0) -}) + try! rustCall { uniffi_bdkffi_fn_free_bumpfeetxbuilder(pointer, $0) } } +open func enableRbf() -> BumpFeeTxBuilder { + return try! FfiConverterTypeBumpFeeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_bumpfeetxbuilder_enable_rbf(self.uniffiClonePointer(),$0 + ) +}) +} - public func toBtc() -> Double { - return try! FfiConverterDouble.lift( - try! - rustCall() { - - uniffi_bdkffi_fn_method_amount_to_btc(self.uniffiClonePointer(), $0 +open func enableRbfWithSequence(nsequence: UInt32) -> BumpFeeTxBuilder { + return try! FfiConverterTypeBumpFeeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_bumpfeetxbuilder_enable_rbf_with_sequence(self.uniffiClonePointer(), + FfiConverterUInt32.lower(nsequence),$0 ) +}) } - ) - } - public func toSat() -> UInt64 { - return try! FfiConverterUInt64.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_amount_to_sat(self.uniffiClonePointer(), $0 +open func finish(wallet: Wallet)throws -> Psbt { + return try FfiConverterTypePsbt.lift(try rustCallWithError(FfiConverterTypeCreateTxError.lift) { + uniffi_bdkffi_fn_method_bumpfeetxbuilder_finish(self.uniffiClonePointer(), + FfiConverterTypeWallet.lower(wallet),$0 ) +}) } - ) - } + } -public struct FfiConverterTypeAmount: FfiConverter { +public struct FfiConverterTypeBumpFeeTxBuilder: FfiConverter { typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Amount + typealias SwiftType = BumpFeeTxBuilder - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Amount { - return Amount(unsafeFromRawPointer: pointer) + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> BumpFeeTxBuilder { + return BumpFeeTxBuilder(unsafeFromRawPointer: pointer) } - public static func lower(_ value: Amount) -> UnsafeMutableRawPointer { + public static func lower(_ value: BumpFeeTxBuilder) -> UnsafeMutableRawPointer { return value.uniffiClonePointer() } - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Amount { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> BumpFeeTxBuilder { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -685,7 +767,7 @@ public struct FfiConverterTypeAmount: FfiConverter { return try lift(ptr!) } - public static func write(_ value: Amount, into buf: inout [UInt8]) { + public static func write(_ value: BumpFeeTxBuilder, into buf: inout [UInt8]) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) @@ -693,105 +775,189 @@ public struct FfiConverterTypeAmount: FfiConverter { } -public func FfiConverterTypeAmount_lift(_ pointer: UnsafeMutableRawPointer) throws -> Amount { - return try FfiConverterTypeAmount.lift(pointer) + + +public func FfiConverterTypeBumpFeeTxBuilder_lift(_ pointer: UnsafeMutableRawPointer) throws -> BumpFeeTxBuilder { + return try FfiConverterTypeBumpFeeTxBuilder.lift(pointer) } -public func FfiConverterTypeAmount_lower(_ value: Amount) -> UnsafeMutableRawPointer { - return FfiConverterTypeAmount.lower(value) +public func FfiConverterTypeBumpFeeTxBuilder_lower(_ value: BumpFeeTxBuilder) -> UnsafeMutableRawPointer { + return FfiConverterTypeBumpFeeTxBuilder.lower(value) } -public protocol BumpFeeTxBuilderProtocol : AnyObject { - - func enableRbf() -> BumpFeeTxBuilder - - func enableRbfWithSequence(nsequence: UInt32) -> BumpFeeTxBuilder - - func finish(wallet: Wallet) throws -> Psbt +public protocol ChangeSetProtocol : AnyObject { } -public class BumpFeeTxBuilder: - BumpFeeTxBuilderProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class ChangeSet: + ChangeSetProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_bdkffi_fn_clone_bumpfeetxbuilder(self.pointer, $0) } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil } - public convenience init(txid: String, feeRate: FeeRate) { - self.init(unsafeFromRawPointer: try! rustCall() { - uniffi_bdkffi_fn_constructor_bumpfeetxbuilder_new( - FfiConverterString.lower(txid), - FfiConverterTypeFeeRate.lower(feeRate),$0) -}) + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_bdkffi_fn_clone_changeset(self.pointer, $0) } } + // No primary constructor declared for this class. deinit { - try! rustCall { uniffi_bdkffi_fn_free_bumpfeetxbuilder(pointer, $0) } + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_bdkffi_fn_free_changeset(pointer, $0) } } - - public func enableRbf() -> BumpFeeTxBuilder { - return try! FfiConverterTypeBumpFeeTxBuilder.lift( - try! - rustCall() { - - uniffi_bdkffi_fn_method_bumpfeetxbuilder_enable_rbf(self.uniffiClonePointer(), $0 - ) + } - ) + +public struct FfiConverterTypeChangeSet: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = ChangeSet + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> ChangeSet { + return ChangeSet(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: ChangeSet) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() } - public func enableRbfWithSequence(nsequence: UInt32) -> BumpFeeTxBuilder { - return try! FfiConverterTypeBumpFeeTxBuilder.lift( - try! - rustCall() { + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ChangeSet { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: ChangeSet, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + + + +public func FfiConverterTypeChangeSet_lift(_ pointer: UnsafeMutableRawPointer) throws -> ChangeSet { + return try FfiConverterTypeChangeSet.lift(pointer) +} + +public func FfiConverterTypeChangeSet_lower(_ value: ChangeSet) -> UnsafeMutableRawPointer { + return FfiConverterTypeChangeSet.lower(value) +} + + + + +public protocol ConnectionProtocol : AnyObject { - uniffi_bdkffi_fn_method_bumpfeetxbuilder_enable_rbf_with_sequence(self.uniffiClonePointer(), - FfiConverterUInt32.lower(nsequence),$0 - ) } - ) + +open class Connection: + ConnectionProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} } - public func finish(wallet: Wallet) throws -> Psbt { - return try FfiConverterTypePsbt.lift( - try - rustCallWithError(FfiConverterTypeCreateTxError.lift) { - uniffi_bdkffi_fn_method_bumpfeetxbuilder_finish(self.uniffiClonePointer(), - FfiConverterTypeWallet.lower(wallet),$0 + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_bdkffi_fn_clone_connection(self.pointer, $0) } + } +public convenience init(path: String)throws { + let pointer = + try rustCallWithError(FfiConverterTypeSqliteError.lift) { + uniffi_bdkffi_fn_constructor_connection_new( + FfiConverterString.lower(path),$0 ) } - ) + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_bdkffi_fn_free_connection(pointer, $0) } } + +public static func newInMemory()throws -> Connection { + return try FfiConverterTypeConnection.lift(try rustCallWithError(FfiConverterTypeSqliteError.lift) { + uniffi_bdkffi_fn_constructor_connection_new_in_memory($0 + ) +}) } + -public struct FfiConverterTypeBumpFeeTxBuilder: FfiConverter { + + +} + +public struct FfiConverterTypeConnection: FfiConverter { typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = BumpFeeTxBuilder + typealias SwiftType = Connection - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> BumpFeeTxBuilder { - return BumpFeeTxBuilder(unsafeFromRawPointer: pointer) + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Connection { + return Connection(unsafeFromRawPointer: pointer) } - public static func lower(_ value: BumpFeeTxBuilder) -> UnsafeMutableRawPointer { + public static func lower(_ value: Connection) -> UnsafeMutableRawPointer { return value.uniffiClonePointer() } - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> BumpFeeTxBuilder { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Connection { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -802,7 +968,7 @@ public struct FfiConverterTypeBumpFeeTxBuilder: FfiConverter { return try lift(ptr!) } - public static func write(_ value: BumpFeeTxBuilder, into buf: inout [UInt8]) { + public static func write(_ value: Connection, into buf: inout [UInt8]) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) @@ -810,12 +976,14 @@ public struct FfiConverterTypeBumpFeeTxBuilder: FfiConverter { } -public func FfiConverterTypeBumpFeeTxBuilder_lift(_ pointer: UnsafeMutableRawPointer) throws -> BumpFeeTxBuilder { - return try FfiConverterTypeBumpFeeTxBuilder.lift(pointer) + + +public func FfiConverterTypeConnection_lift(_ pointer: UnsafeMutableRawPointer) throws -> Connection { + return try FfiConverterTypeConnection.lift(pointer) } -public func FfiConverterTypeBumpFeeTxBuilder_lower(_ value: BumpFeeTxBuilder) -> UnsafeMutableRawPointer { - return FfiConverterTypeBumpFeeTxBuilder.lower(value) +public func FfiConverterTypeConnection_lower(_ value: Connection) -> UnsafeMutableRawPointer { + return FfiConverterTypeConnection.lower(value) } @@ -825,35 +993,55 @@ public protocol DerivationPathProtocol : AnyObject { } -public class DerivationPath: +open class DerivationPath: DerivationPathProtocol { - fileprivate let pointer: UnsafeMutableRawPointer + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_derivationpath(self.pointer, $0) } } - public convenience init(path: String) throws { - self.init(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeBip32Error.lift) { +public convenience init(path: String)throws { + let pointer = + try rustCallWithError(FfiConverterTypeBip32Error.lift) { uniffi_bdkffi_fn_constructor_derivationpath_new( - FfiConverterString.lower(path),$0) -}) - } + FfiConverterString.lower(path),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_bdkffi_fn_free_derivationpath(pointer, $0) } } - } @@ -889,6 +1077,8 @@ public struct FfiConverterTypeDerivationPath: FfiConverter { } + + public func FfiConverterTypeDerivationPath_lift(_ pointer: UnsafeMutableRawPointer) throws -> DerivationPath { return try FfiConverterTypeDerivationPath.lift(pointer) } @@ -902,142 +1092,156 @@ public func FfiConverterTypeDerivationPath_lower(_ value: DerivationPath) -> Uns public protocol DescriptorProtocol : AnyObject { - func asString() -> String - - func asStringPrivate() -> String + func toStringWithSecret() -> String } -public class Descriptor: +open class Descriptor: + CustomStringConvertible, DescriptorProtocol { - fileprivate let pointer: UnsafeMutableRawPointer + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_descriptor(self.pointer, $0) } } - public convenience init(descriptor: String, network: Network) throws { - self.init(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeDescriptorError.lift) { +public convenience init(descriptor: String, network: Network)throws { + let pointer = + try rustCallWithError(FfiConverterTypeDescriptorError.lift) { uniffi_bdkffi_fn_constructor_descriptor_new( FfiConverterString.lower(descriptor), - FfiConverterTypeNetwork.lower(network),$0) -}) - } - + FfiConverterTypeNetwork_lower(network),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} + deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_bdkffi_fn_free_descriptor(pointer, $0) } } - public static func newBip44(secretKey: DescriptorSecretKey, keychain: KeychainKind, network: Network) -> Descriptor { - return Descriptor(unsafeFromRawPointer: try! rustCall() { +public static func newBip44(secretKey: DescriptorSecretKey, keychain: KeychainKind, network: Network) -> Descriptor { + return try! FfiConverterTypeDescriptor.lift(try! rustCall() { uniffi_bdkffi_fn_constructor_descriptor_new_bip44( FfiConverterTypeDescriptorSecretKey.lower(secretKey), FfiConverterTypeKeychainKind.lower(keychain), - FfiConverterTypeNetwork.lower(network),$0) + FfiConverterTypeNetwork_lower(network),$0 + ) }) - } - +} - public static func newBip44Public(publicKey: DescriptorPublicKey, fingerprint: String, keychain: KeychainKind, network: Network) -> Descriptor { - return Descriptor(unsafeFromRawPointer: try! rustCall() { +public static func newBip44Public(publicKey: DescriptorPublicKey, fingerprint: String, keychain: KeychainKind, network: Network) -> Descriptor { + return try! FfiConverterTypeDescriptor.lift(try! rustCall() { uniffi_bdkffi_fn_constructor_descriptor_new_bip44_public( FfiConverterTypeDescriptorPublicKey.lower(publicKey), FfiConverterString.lower(fingerprint), FfiConverterTypeKeychainKind.lower(keychain), - FfiConverterTypeNetwork.lower(network),$0) + FfiConverterTypeNetwork_lower(network),$0 + ) }) - } - +} - public static func newBip49(secretKey: DescriptorSecretKey, keychain: KeychainKind, network: Network) -> Descriptor { - return Descriptor(unsafeFromRawPointer: try! rustCall() { +public static func newBip49(secretKey: DescriptorSecretKey, keychain: KeychainKind, network: Network) -> Descriptor { + return try! FfiConverterTypeDescriptor.lift(try! rustCall() { uniffi_bdkffi_fn_constructor_descriptor_new_bip49( FfiConverterTypeDescriptorSecretKey.lower(secretKey), FfiConverterTypeKeychainKind.lower(keychain), - FfiConverterTypeNetwork.lower(network),$0) + FfiConverterTypeNetwork_lower(network),$0 + ) }) - } - +} - public static func newBip49Public(publicKey: DescriptorPublicKey, fingerprint: String, keychain: KeychainKind, network: Network) -> Descriptor { - return Descriptor(unsafeFromRawPointer: try! rustCall() { +public static func newBip49Public(publicKey: DescriptorPublicKey, fingerprint: String, keychain: KeychainKind, network: Network) -> Descriptor { + return try! FfiConverterTypeDescriptor.lift(try! rustCall() { uniffi_bdkffi_fn_constructor_descriptor_new_bip49_public( FfiConverterTypeDescriptorPublicKey.lower(publicKey), FfiConverterString.lower(fingerprint), FfiConverterTypeKeychainKind.lower(keychain), - FfiConverterTypeNetwork.lower(network),$0) + FfiConverterTypeNetwork_lower(network),$0 + ) }) - } - +} - public static func newBip84(secretKey: DescriptorSecretKey, keychain: KeychainKind, network: Network) -> Descriptor { - return Descriptor(unsafeFromRawPointer: try! rustCall() { +public static func newBip84(secretKey: DescriptorSecretKey, keychain: KeychainKind, network: Network) -> Descriptor { + return try! FfiConverterTypeDescriptor.lift(try! rustCall() { uniffi_bdkffi_fn_constructor_descriptor_new_bip84( FfiConverterTypeDescriptorSecretKey.lower(secretKey), FfiConverterTypeKeychainKind.lower(keychain), - FfiConverterTypeNetwork.lower(network),$0) + FfiConverterTypeNetwork_lower(network),$0 + ) }) - } - +} - public static func newBip84Public(publicKey: DescriptorPublicKey, fingerprint: String, keychain: KeychainKind, network: Network) -> Descriptor { - return Descriptor(unsafeFromRawPointer: try! rustCall() { +public static func newBip84Public(publicKey: DescriptorPublicKey, fingerprint: String, keychain: KeychainKind, network: Network) -> Descriptor { + return try! FfiConverterTypeDescriptor.lift(try! rustCall() { uniffi_bdkffi_fn_constructor_descriptor_new_bip84_public( FfiConverterTypeDescriptorPublicKey.lower(publicKey), FfiConverterString.lower(fingerprint), FfiConverterTypeKeychainKind.lower(keychain), - FfiConverterTypeNetwork.lower(network),$0) + FfiConverterTypeNetwork_lower(network),$0 + ) }) - } - +} - public static func newBip86(secretKey: DescriptorSecretKey, keychain: KeychainKind, network: Network) -> Descriptor { - return Descriptor(unsafeFromRawPointer: try! rustCall() { +public static func newBip86(secretKey: DescriptorSecretKey, keychain: KeychainKind, network: Network) -> Descriptor { + return try! FfiConverterTypeDescriptor.lift(try! rustCall() { uniffi_bdkffi_fn_constructor_descriptor_new_bip86( FfiConverterTypeDescriptorSecretKey.lower(secretKey), FfiConverterTypeKeychainKind.lower(keychain), - FfiConverterTypeNetwork.lower(network),$0) + FfiConverterTypeNetwork_lower(network),$0 + ) }) - } - +} - public static func newBip86Public(publicKey: DescriptorPublicKey, fingerprint: String, keychain: KeychainKind, network: Network) -> Descriptor { - return Descriptor(unsafeFromRawPointer: try! rustCall() { +public static func newBip86Public(publicKey: DescriptorPublicKey, fingerprint: String, keychain: KeychainKind, network: Network) -> Descriptor { + return try! FfiConverterTypeDescriptor.lift(try! rustCall() { uniffi_bdkffi_fn_constructor_descriptor_new_bip86_public( FfiConverterTypeDescriptorPublicKey.lower(publicKey), FfiConverterString.lower(fingerprint), FfiConverterTypeKeychainKind.lower(keychain), - FfiConverterTypeNetwork.lower(network),$0) + FfiConverterTypeNetwork_lower(network),$0 + ) }) - } - +} - - public func asString() -> String { - return try! FfiConverterString.lift( - try! - rustCall() { - - uniffi_bdkffi_fn_method_descriptor_as_string(self.uniffiClonePointer(), $0 +open func toStringWithSecret() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_bdkffi_fn_method_descriptor_to_string_with_secret(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func asStringPrivate() -> String { - return try! FfiConverterString.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_descriptor_as_string_private(self.uniffiClonePointer(), $0 + open var description: String { + return try! FfiConverterString.lift( + try! rustCall() { + uniffi_bdkffi_fn_method_descriptor_uniffi_trait_display(self.uniffiClonePointer(),$0 ) } ) @@ -1077,6 +1281,8 @@ public struct FfiConverterTypeDescriptor: FfiConverter { } + + public func FfiConverterTypeDescriptor_lift(_ pointer: UnsafeMutableRawPointer) throws -> Descriptor { return try FfiConverterTypeDescriptor.lift(pointer) } @@ -1098,67 +1304,78 @@ public protocol DescriptorPublicKeyProtocol : AnyObject { } -public class DescriptorPublicKey: +open class DescriptorPublicKey: DescriptorPublicKeyProtocol { - fileprivate let pointer: UnsafeMutableRawPointer + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_descriptorpublickey(self.pointer, $0) } } + // No primary constructor declared for this class. deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_bdkffi_fn_free_descriptorpublickey(pointer, $0) } } - public static func fromString(publicKey: String) throws -> DescriptorPublicKey { - return DescriptorPublicKey(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { +public static func fromString(publicKey: String)throws -> DescriptorPublicKey { + return try FfiConverterTypeDescriptorPublicKey.lift(try rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { uniffi_bdkffi_fn_constructor_descriptorpublickey_from_string( - FfiConverterString.lower(publicKey),$0) + FfiConverterString.lower(publicKey),$0 + ) }) - } - +} - - public func asString() -> String { - return try! FfiConverterString.lift( - try! - rustCall() { - - uniffi_bdkffi_fn_method_descriptorpublickey_as_string(self.uniffiClonePointer(), $0 +open func asString() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_bdkffi_fn_method_descriptorpublickey_as_string(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func derive(path: DerivationPath) throws -> DescriptorPublicKey { - return try FfiConverterTypeDescriptorPublicKey.lift( - try - rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { - uniffi_bdkffi_fn_method_descriptorpublickey_derive(self.uniffiClonePointer(), + +open func derive(path: DerivationPath)throws -> DescriptorPublicKey { + return try FfiConverterTypeDescriptorPublicKey.lift(try rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { + uniffi_bdkffi_fn_method_descriptorpublickey_derive(self.uniffiClonePointer(), FfiConverterTypeDerivationPath.lower(path),$0 ) +}) } - ) - } - public func extend(path: DerivationPath) throws -> DescriptorPublicKey { - return try FfiConverterTypeDescriptorPublicKey.lift( - try - rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { - uniffi_bdkffi_fn_method_descriptorpublickey_extend(self.uniffiClonePointer(), + +open func extend(path: DerivationPath)throws -> DescriptorPublicKey { + return try FfiConverterTypeDescriptorPublicKey.lift(try rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { + uniffi_bdkffi_fn_method_descriptorpublickey_extend(self.uniffiClonePointer(), FfiConverterTypeDerivationPath.lower(path),$0 ) +}) } - ) - } + } @@ -1194,6 +1411,8 @@ public struct FfiConverterTypeDescriptorPublicKey: FfiConverter { } + + public func FfiConverterTypeDescriptorPublicKey_lift(_ pointer: UnsafeMutableRawPointer) throws -> DescriptorPublicKey { return try FfiConverterTypeDescriptorPublicKey.lift(pointer) } @@ -1219,95 +1438,102 @@ public protocol DescriptorSecretKeyProtocol : AnyObject { } -public class DescriptorSecretKey: +open class DescriptorSecretKey: DescriptorSecretKeyProtocol { - fileprivate let pointer: UnsafeMutableRawPointer + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_descriptorsecretkey(self.pointer, $0) } } - public convenience init(network: Network, mnemonic: Mnemonic, password: String?) { - self.init(unsafeFromRawPointer: try! rustCall() { +public convenience init(network: Network, mnemonic: Mnemonic, password: String?) { + let pointer = + try! rustCall() { uniffi_bdkffi_fn_constructor_descriptorsecretkey_new( - FfiConverterTypeNetwork.lower(network), + FfiConverterTypeNetwork_lower(network), FfiConverterTypeMnemonic.lower(mnemonic), - FfiConverterOptionString.lower(password),$0) -}) - } + FfiConverterOptionString.lower(password),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_bdkffi_fn_free_descriptorsecretkey(pointer, $0) } } - public static func fromString(secretKey: String) throws -> DescriptorSecretKey { - return DescriptorSecretKey(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { +public static func fromString(secretKey: String)throws -> DescriptorSecretKey { + return try FfiConverterTypeDescriptorSecretKey.lift(try rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { uniffi_bdkffi_fn_constructor_descriptorsecretkey_from_string( - FfiConverterString.lower(secretKey),$0) + FfiConverterString.lower(secretKey),$0 + ) }) - } - +} - - public func asPublic() -> DescriptorPublicKey { - return try! FfiConverterTypeDescriptorPublicKey.lift( - try! - rustCall() { - - uniffi_bdkffi_fn_method_descriptorsecretkey_as_public(self.uniffiClonePointer(), $0 +open func asPublic() -> DescriptorPublicKey { + return try! FfiConverterTypeDescriptorPublicKey.lift(try! rustCall() { + uniffi_bdkffi_fn_method_descriptorsecretkey_as_public(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func asString() -> String { - return try! FfiConverterString.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_descriptorsecretkey_as_string(self.uniffiClonePointer(), $0 +open func asString() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_bdkffi_fn_method_descriptorsecretkey_as_string(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func derive(path: DerivationPath) throws -> DescriptorSecretKey { - return try FfiConverterTypeDescriptorSecretKey.lift( - try - rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { - uniffi_bdkffi_fn_method_descriptorsecretkey_derive(self.uniffiClonePointer(), + +open func derive(path: DerivationPath)throws -> DescriptorSecretKey { + return try FfiConverterTypeDescriptorSecretKey.lift(try rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { + uniffi_bdkffi_fn_method_descriptorsecretkey_derive(self.uniffiClonePointer(), FfiConverterTypeDerivationPath.lower(path),$0 ) +}) } - ) - } - public func extend(path: DerivationPath) throws -> DescriptorSecretKey { - return try FfiConverterTypeDescriptorSecretKey.lift( - try - rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { - uniffi_bdkffi_fn_method_descriptorsecretkey_extend(self.uniffiClonePointer(), + +open func extend(path: DerivationPath)throws -> DescriptorSecretKey { + return try FfiConverterTypeDescriptorSecretKey.lift(try rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { + uniffi_bdkffi_fn_method_descriptorsecretkey_extend(self.uniffiClonePointer(), FfiConverterTypeDerivationPath.lower(path),$0 ) +}) } - ) - } - public func secretBytes() -> [UInt8] { - return try! FfiConverterSequenceUInt8.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_descriptorsecretkey_secret_bytes(self.uniffiClonePointer(), $0 +open func secretBytes() -> [UInt8] { + return try! FfiConverterSequenceUInt8.lift(try! rustCall() { + uniffi_bdkffi_fn_method_descriptorsecretkey_secret_bytes(self.uniffiClonePointer(),$0 ) +}) } - ) - } + } @@ -1343,6 +1569,8 @@ public struct FfiConverterTypeDescriptorSecretKey: FfiConverter { } + + public func FfiConverterTypeDescriptorSecretKey_lift(_ pointer: UnsafeMutableRawPointer) throws -> DescriptorSecretKey { return try FfiConverterTypeDescriptorSecretKey.lift(pointer) } @@ -1364,70 +1592,84 @@ public protocol ElectrumClientProtocol : AnyObject { } -public class ElectrumClient: +open class ElectrumClient: ElectrumClientProtocol { - fileprivate let pointer: UnsafeMutableRawPointer + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_electrumclient(self.pointer, $0) } } - public convenience init(url: String) throws { - self.init(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeElectrumError.lift) { +public convenience init(url: String)throws { + let pointer = + try rustCallWithError(FfiConverterTypeElectrumError.lift) { uniffi_bdkffi_fn_constructor_electrumclient_new( - FfiConverterString.lower(url),$0) -}) - } + FfiConverterString.lower(url),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_bdkffi_fn_free_electrumclient(pointer, $0) } } - - public func broadcast(transaction: Transaction) throws -> String { - return try FfiConverterString.lift( - try - rustCallWithError(FfiConverterTypeElectrumError.lift) { - uniffi_bdkffi_fn_method_electrumclient_broadcast(self.uniffiClonePointer(), +open func broadcast(transaction: Transaction)throws -> String { + return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeElectrumError.lift) { + uniffi_bdkffi_fn_method_electrumclient_broadcast(self.uniffiClonePointer(), FfiConverterTypeTransaction.lower(transaction),$0 ) +}) } - ) - } - public func fullScan(fullScanRequest: FullScanRequest, stopGap: UInt64, batchSize: UInt64, fetchPrevTxouts: Bool) throws -> Update { - return try FfiConverterTypeUpdate.lift( - try - rustCallWithError(FfiConverterTypeElectrumError.lift) { - uniffi_bdkffi_fn_method_electrumclient_full_scan(self.uniffiClonePointer(), + +open func fullScan(fullScanRequest: FullScanRequest, stopGap: UInt64, batchSize: UInt64, fetchPrevTxouts: Bool)throws -> Update { + return try FfiConverterTypeUpdate.lift(try rustCallWithError(FfiConverterTypeElectrumError.lift) { + uniffi_bdkffi_fn_method_electrumclient_full_scan(self.uniffiClonePointer(), FfiConverterTypeFullScanRequest.lower(fullScanRequest), FfiConverterUInt64.lower(stopGap), FfiConverterUInt64.lower(batchSize), FfiConverterBool.lower(fetchPrevTxouts),$0 ) +}) } - ) - } - public func sync(syncRequest: SyncRequest, batchSize: UInt64, fetchPrevTxouts: Bool) throws -> Update { - return try FfiConverterTypeUpdate.lift( - try - rustCallWithError(FfiConverterTypeElectrumError.lift) { - uniffi_bdkffi_fn_method_electrumclient_sync(self.uniffiClonePointer(), + +open func sync(syncRequest: SyncRequest, batchSize: UInt64, fetchPrevTxouts: Bool)throws -> Update { + return try FfiConverterTypeUpdate.lift(try rustCallWithError(FfiConverterTypeElectrumError.lift) { + uniffi_bdkffi_fn_method_electrumclient_sync(self.uniffiClonePointer(), FfiConverterTypeSyncRequest.lower(syncRequest), FfiConverterUInt64.lower(batchSize), FfiConverterBool.lower(fetchPrevTxouts),$0 ) +}) } - ) - } + } @@ -1463,6 +1705,8 @@ public struct FfiConverterTypeElectrumClient: FfiConverter { } + + public func FfiConverterTypeElectrumClient_lift(_ pointer: UnsafeMutableRawPointer) throws -> ElectrumClient { return try FfiConverterTypeElectrumClient.lift(pointer) } @@ -1484,66 +1728,81 @@ public protocol EsploraClientProtocol : AnyObject { } -public class EsploraClient: +open class EsploraClient: EsploraClientProtocol { - fileprivate let pointer: UnsafeMutableRawPointer + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_esploraclient(self.pointer, $0) } } - public convenience init(url: String) { - self.init(unsafeFromRawPointer: try! rustCall() { +public convenience init(url: String) { + let pointer = + try! rustCall() { uniffi_bdkffi_fn_constructor_esploraclient_new( - FfiConverterString.lower(url),$0) -}) - } + FfiConverterString.lower(url),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_bdkffi_fn_free_esploraclient(pointer, $0) } } - - public func broadcast(transaction: Transaction) throws { - try - rustCallWithError(FfiConverterTypeEsploraError.lift) { - uniffi_bdkffi_fn_method_esploraclient_broadcast(self.uniffiClonePointer(), +open func broadcast(transaction: Transaction)throws {try rustCallWithError(FfiConverterTypeEsploraError.lift) { + uniffi_bdkffi_fn_method_esploraclient_broadcast(self.uniffiClonePointer(), FfiConverterTypeTransaction.lower(transaction),$0 ) } - } - public func fullScan(fullScanRequest: FullScanRequest, stopGap: UInt64, parallelRequests: UInt64) throws -> Update { - return try FfiConverterTypeUpdate.lift( - try - rustCallWithError(FfiConverterTypeEsploraError.lift) { - uniffi_bdkffi_fn_method_esploraclient_full_scan(self.uniffiClonePointer(), +} + +open func fullScan(fullScanRequest: FullScanRequest, stopGap: UInt64, parallelRequests: UInt64)throws -> Update { + return try FfiConverterTypeUpdate.lift(try rustCallWithError(FfiConverterTypeEsploraError.lift) { + uniffi_bdkffi_fn_method_esploraclient_full_scan(self.uniffiClonePointer(), FfiConverterTypeFullScanRequest.lower(fullScanRequest), FfiConverterUInt64.lower(stopGap), FfiConverterUInt64.lower(parallelRequests),$0 ) +}) } - ) - } - public func sync(syncRequest: SyncRequest, parallelRequests: UInt64) throws -> Update { - return try FfiConverterTypeUpdate.lift( - try - rustCallWithError(FfiConverterTypeEsploraError.lift) { - uniffi_bdkffi_fn_method_esploraclient_sync(self.uniffiClonePointer(), + +open func sync(syncRequest: SyncRequest, parallelRequests: UInt64)throws -> Update { + return try FfiConverterTypeUpdate.lift(try rustCallWithError(FfiConverterTypeEsploraError.lift) { + uniffi_bdkffi_fn_method_esploraclient_sync(self.uniffiClonePointer(), FfiConverterTypeSyncRequest.lower(syncRequest), FfiConverterUInt64.lower(parallelRequests),$0 ) +}) } - ) - } + } @@ -1579,6 +1838,8 @@ public struct FfiConverterTypeEsploraClient: FfiConverter { } + + public func FfiConverterTypeEsploraClient_lift(_ pointer: UnsafeMutableRawPointer) throws -> EsploraClient { return try FfiConverterTypeEsploraClient.lift(pointer) } @@ -1590,102 +1851,68 @@ public func FfiConverterTypeEsploraClient_lower(_ value: EsploraClient) -> Unsaf -public protocol FeeRateProtocol : AnyObject { - - func toSatPerKwu() -> UInt64 - - func toSatPerVbCeil() -> UInt64 - - func toSatPerVbFloor() -> UInt64 +public protocol FullScanRequestProtocol : AnyObject { } -public class FeeRate: - FeeRateProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class FullScanRequest: + FullScanRequestProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_bdkffi_fn_clone_feerate(self.pointer, $0) } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil } - deinit { - try! rustCall { uniffi_bdkffi_fn_free_feerate(pointer, $0) } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_bdkffi_fn_clone_fullscanrequest(self.pointer, $0) } } + // No primary constructor declared for this class. - - public static func fromSatPerKwu(satPerKwu: UInt64) -> FeeRate { - return FeeRate(unsafeFromRawPointer: try! rustCall() { - uniffi_bdkffi_fn_constructor_feerate_from_sat_per_kwu( - FfiConverterUInt64.lower(satPerKwu),$0) -}) - } + deinit { + guard let pointer = pointer else { + return + } - - public static func fromSatPerVb(satPerVb: UInt64) throws -> FeeRate { - return FeeRate(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeFeeRateError.lift) { - uniffi_bdkffi_fn_constructor_feerate_from_sat_per_vb( - FfiConverterUInt64.lower(satPerVb),$0) -}) + try! rustCall { uniffi_bdkffi_fn_free_fullscanrequest(pointer, $0) } } - - public func toSatPerKwu() -> UInt64 { - return try! FfiConverterUInt64.lift( - try! - rustCall() { - - uniffi_bdkffi_fn_method_feerate_to_sat_per_kwu(self.uniffiClonePointer(), $0 - ) -} - ) - } - public func toSatPerVbCeil() -> UInt64 { - return try! FfiConverterUInt64.lift( - try! - rustCall() { - - uniffi_bdkffi_fn_method_feerate_to_sat_per_vb_ceil(self.uniffiClonePointer(), $0 - ) -} - ) - } - public func toSatPerVbFloor() -> UInt64 { - return try! FfiConverterUInt64.lift( - try! - rustCall() { - - uniffi_bdkffi_fn_method_feerate_to_sat_per_vb_floor(self.uniffiClonePointer(), $0 - ) -} - ) - } } -public struct FfiConverterTypeFeeRate: FfiConverter { +public struct FfiConverterTypeFullScanRequest: FfiConverter { typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = FeeRate + typealias SwiftType = FullScanRequest - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FeeRate { - return FeeRate(unsafeFromRawPointer: pointer) + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FullScanRequest { + return FullScanRequest(unsafeFromRawPointer: pointer) } - public static func lower(_ value: FeeRate) -> UnsafeMutableRawPointer { + public static func lower(_ value: FullScanRequest) -> UnsafeMutableRawPointer { return value.uniffiClonePointer() } - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FeeRate { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FullScanRequest { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -1696,7 +1923,7 @@ public struct FfiConverterTypeFeeRate: FfiConverter { return try lift(ptr!) } - public static func write(_ value: FeeRate, into buf: inout [UInt8]) { + public static func write(_ value: FullScanRequest, into buf: inout [UInt8]) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) @@ -1704,61 +1931,100 @@ public struct FfiConverterTypeFeeRate: FfiConverter { } -public func FfiConverterTypeFeeRate_lift(_ pointer: UnsafeMutableRawPointer) throws -> FeeRate { - return try FfiConverterTypeFeeRate.lift(pointer) + + +public func FfiConverterTypeFullScanRequest_lift(_ pointer: UnsafeMutableRawPointer) throws -> FullScanRequest { + return try FfiConverterTypeFullScanRequest.lift(pointer) } -public func FfiConverterTypeFeeRate_lower(_ value: FeeRate) -> UnsafeMutableRawPointer { - return FfiConverterTypeFeeRate.lower(value) +public func FfiConverterTypeFullScanRequest_lower(_ value: FullScanRequest) -> UnsafeMutableRawPointer { + return FfiConverterTypeFullScanRequest.lower(value) } -public protocol FullScanRequestProtocol : AnyObject { +public protocol FullScanRequestBuilderProtocol : AnyObject { + + func build() throws -> FullScanRequest + + func inspectSpksForAllKeychains(inspector: FullScanScriptInspector) throws -> FullScanRequestBuilder } -public class FullScanRequest: - FullScanRequestProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class FullScanRequestBuilder: + FullScanRequestBuilderProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_bdkffi_fn_clone_fullscanrequest(self.pointer, $0) } + return try! rustCall { uniffi_bdkffi_fn_clone_fullscanrequestbuilder(self.pointer, $0) } } + // No primary constructor declared for this class. deinit { - try! rustCall { uniffi_bdkffi_fn_free_fullscanrequest(pointer, $0) } + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_bdkffi_fn_free_fullscanrequestbuilder(pointer, $0) } } +open func build()throws -> FullScanRequest { + return try FfiConverterTypeFullScanRequest.lift(try rustCallWithError(FfiConverterTypeRequestBuilderError.lift) { + uniffi_bdkffi_fn_method_fullscanrequestbuilder_build(self.uniffiClonePointer(),$0 + ) +}) +} + +open func inspectSpksForAllKeychains(inspector: FullScanScriptInspector)throws -> FullScanRequestBuilder { + return try FfiConverterTypeFullScanRequestBuilder.lift(try rustCallWithError(FfiConverterTypeRequestBuilderError.lift) { + uniffi_bdkffi_fn_method_fullscanrequestbuilder_inspect_spks_for_all_keychains(self.uniffiClonePointer(), + FfiConverterTypeFullScanScriptInspector.lower(inspector),$0 + ) +}) +} } -public struct FfiConverterTypeFullScanRequest: FfiConverter { +public struct FfiConverterTypeFullScanRequestBuilder: FfiConverter { typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = FullScanRequest + typealias SwiftType = FullScanRequestBuilder - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FullScanRequest { - return FullScanRequest(unsafeFromRawPointer: pointer) + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FullScanRequestBuilder { + return FullScanRequestBuilder(unsafeFromRawPointer: pointer) } - public static func lower(_ value: FullScanRequest) -> UnsafeMutableRawPointer { + public static func lower(_ value: FullScanRequestBuilder) -> UnsafeMutableRawPointer { return value.uniffiClonePointer() } - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FullScanRequest { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FullScanRequestBuilder { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -1769,7 +2035,7 @@ public struct FfiConverterTypeFullScanRequest: FfiConverter { return try lift(ptr!) } - public static func write(_ value: FullScanRequest, into buf: inout [UInt8]) { + public static func write(_ value: FullScanRequestBuilder, into buf: inout [UInt8]) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) @@ -1777,74 +2043,255 @@ public struct FfiConverterTypeFullScanRequest: FfiConverter { } -public func FfiConverterTypeFullScanRequest_lift(_ pointer: UnsafeMutableRawPointer) throws -> FullScanRequest { - return try FfiConverterTypeFullScanRequest.lift(pointer) + + +public func FfiConverterTypeFullScanRequestBuilder_lift(_ pointer: UnsafeMutableRawPointer) throws -> FullScanRequestBuilder { + return try FfiConverterTypeFullScanRequestBuilder.lift(pointer) } -public func FfiConverterTypeFullScanRequest_lower(_ value: FullScanRequest) -> UnsafeMutableRawPointer { - return FfiConverterTypeFullScanRequest.lower(value) +public func FfiConverterTypeFullScanRequestBuilder_lower(_ value: FullScanRequestBuilder) -> UnsafeMutableRawPointer { + return FfiConverterTypeFullScanRequestBuilder.lower(value) } -public protocol MnemonicProtocol : AnyObject { +public protocol FullScanScriptInspector : AnyObject { - func asString() -> String + func inspect(keychain: KeychainKind, index: UInt32, script: Script) } -public class Mnemonic: - MnemonicProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class FullScanScriptInspectorImpl: + FullScanScriptInspector { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_bdkffi_fn_clone_fullscanscriptinspector(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_bdkffi_fn_free_fullscanscriptinspector(pointer, $0) } + } + + + + +open func inspect(keychain: KeychainKind, index: UInt32, script: Script) {try! rustCall() { + uniffi_bdkffi_fn_method_fullscanscriptinspector_inspect(self.uniffiClonePointer(), + FfiConverterTypeKeychainKind.lower(keychain), + FfiConverterUInt32.lower(index), + FfiConverterTypeScript_lower(script),$0 + ) +} +} + + +} +// Magic number for the Rust proxy to call using the same mechanism as every other method, +// to free the callback once it's dropped by Rust. +private let IDX_CALLBACK_FREE: Int32 = 0 +// Callback return codes +private let UNIFFI_CALLBACK_SUCCESS: Int32 = 0 +private let UNIFFI_CALLBACK_ERROR: Int32 = 1 +private let UNIFFI_CALLBACK_UNEXPECTED_ERROR: Int32 = 2 + +// Put the implementation in a struct so we don't pollute the top-level namespace +fileprivate struct UniffiCallbackInterfaceFullScanScriptInspector { + + // Create the VTable using a series of closures. + // Swift automatically converts these into C callback functions. + static var vtable: UniffiVTableCallbackInterfaceFullScanScriptInspector = UniffiVTableCallbackInterfaceFullScanScriptInspector( + inspect: { ( + uniffiHandle: UInt64, + keychain: RustBuffer, + index: UInt32, + script: UnsafeMutableRawPointer, + uniffiOutReturn: UnsafeMutableRawPointer, + uniffiCallStatus: UnsafeMutablePointer + ) in + let makeCall = { + () throws -> () in + guard let uniffiObj = try? FfiConverterTypeFullScanScriptInspector.handleMap.get(handle: uniffiHandle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return uniffiObj.inspect( + keychain: try FfiConverterTypeKeychainKind.lift(keychain), + index: try FfiConverterUInt32.lift(index), + script: try FfiConverterTypeScript_lift(script) + ) + } + + + let writeReturn = { () } + uniffiTraitInterfaceCall( + callStatus: uniffiCallStatus, + makeCall: makeCall, + writeReturn: writeReturn + ) + }, + uniffiFree: { (uniffiHandle: UInt64) -> () in + let result = try? FfiConverterTypeFullScanScriptInspector.handleMap.remove(handle: uniffiHandle) + if result == nil { + print("Uniffi callback interface FullScanScriptInspector: handle missing in uniffiFree") + } + } + ) +} + +private func uniffiCallbackInitFullScanScriptInspector() { + uniffi_bdkffi_fn_init_callback_vtable_fullscanscriptinspector(&UniffiCallbackInterfaceFullScanScriptInspector.vtable) +} + +public struct FfiConverterTypeFullScanScriptInspector: FfiConverter { + fileprivate static var handleMap = UniffiHandleMap() + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = FullScanScriptInspector + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FullScanScriptInspector { + return FullScanScriptInspectorImpl(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FullScanScriptInspector) -> UnsafeMutableRawPointer { + guard let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: handleMap.insert(obj: value))) else { + fatalError("Cast to UnsafeMutableRawPointer failed") + } + return ptr + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FullScanScriptInspector { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: FullScanScriptInspector, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + + + +public func FfiConverterTypeFullScanScriptInspector_lift(_ pointer: UnsafeMutableRawPointer) throws -> FullScanScriptInspector { + return try FfiConverterTypeFullScanScriptInspector.lift(pointer) +} + +public func FfiConverterTypeFullScanScriptInspector_lower(_ value: FullScanScriptInspector) -> UnsafeMutableRawPointer { + return FfiConverterTypeFullScanScriptInspector.lower(value) +} + + + + +public protocol MnemonicProtocol : AnyObject { + +} + +open class Mnemonic: + CustomStringConvertible, + MnemonicProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_mnemonic(self.pointer, $0) } } - public convenience init(wordCount: WordCount) { - self.init(unsafeFromRawPointer: try! rustCall() { +public convenience init(wordCount: WordCount) { + let pointer = + try! rustCall() { uniffi_bdkffi_fn_constructor_mnemonic_new( - FfiConverterTypeWordCount.lower(wordCount),$0) -}) - } + FfiConverterTypeWordCount.lower(wordCount),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_bdkffi_fn_free_mnemonic(pointer, $0) } } - public static func fromEntropy(entropy: [UInt8]) throws -> Mnemonic { - return Mnemonic(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeBip39Error.lift) { +public static func fromEntropy(entropy: [UInt8])throws -> Mnemonic { + return try FfiConverterTypeMnemonic.lift(try rustCallWithError(FfiConverterTypeBip39Error.lift) { uniffi_bdkffi_fn_constructor_mnemonic_from_entropy( - FfiConverterSequenceUInt8.lower(entropy),$0) + FfiConverterSequenceUInt8.lower(entropy),$0 + ) }) - } - +} - public static func fromString(mnemonic: String) throws -> Mnemonic { - return Mnemonic(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeBip39Error.lift) { +public static func fromString(mnemonic: String)throws -> Mnemonic { + return try FfiConverterTypeMnemonic.lift(try rustCallWithError(FfiConverterTypeBip39Error.lift) { uniffi_bdkffi_fn_constructor_mnemonic_from_string( - FfiConverterString.lower(mnemonic),$0) + FfiConverterString.lower(mnemonic),$0 + ) }) - } - +} - - public func asString() -> String { + open var description: String { return try! FfiConverterString.lift( - try! - rustCall() { - - uniffi_bdkffi_fn_method_mnemonic_as_string(self.uniffiClonePointer(), $0 + try! rustCall() { + uniffi_bdkffi_fn_method_mnemonic_uniffi_trait_display(self.uniffiClonePointer(),$0 ) } ) @@ -1884,6 +2331,8 @@ public struct FfiConverterTypeMnemonic: FfiConverter { } + + public func FfiConverterTypeMnemonic_lift(_ pointer: UnsafeMutableRawPointer) throws -> Mnemonic { return try FfiConverterTypeMnemonic.lift(pointer) } @@ -1897,60 +2346,103 @@ public func FfiConverterTypeMnemonic_lower(_ value: Mnemonic) -> UnsafeMutableRa public protocol PsbtProtocol : AnyObject { + func combine(other: Psbt) throws -> Psbt + func extractTx() throws -> Transaction + func fee() throws -> UInt64 + + func jsonSerialize() -> String + func serialize() -> String } -public class Psbt: +open class Psbt: PsbtProtocol { - fileprivate let pointer: UnsafeMutableRawPointer + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_psbt(self.pointer, $0) } } - public convenience init(psbtBase64: String) throws { - self.init(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypePsbtParseError.lift) { +public convenience init(psbtBase64: String)throws { + let pointer = + try rustCallWithError(FfiConverterTypePsbtParseError.lift) { uniffi_bdkffi_fn_constructor_psbt_new( - FfiConverterString.lower(psbtBase64),$0) -}) - } + FfiConverterString.lower(psbtBase64),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_bdkffi_fn_free_psbt(pointer, $0) } } +open func combine(other: Psbt)throws -> Psbt { + return try FfiConverterTypePsbt.lift(try rustCallWithError(FfiConverterTypePsbtError.lift) { + uniffi_bdkffi_fn_method_psbt_combine(self.uniffiClonePointer(), + FfiConverterTypePsbt.lower(other),$0 + ) +}) +} - public func extractTx() throws -> Transaction { - return try FfiConverterTypeTransaction.lift( - try - rustCallWithError(FfiConverterTypeExtractTxError.lift) { - uniffi_bdkffi_fn_method_psbt_extract_tx(self.uniffiClonePointer(), $0 +open func extractTx()throws -> Transaction { + return try FfiConverterTypeTransaction.lift(try rustCallWithError(FfiConverterTypeExtractTxError.lift) { + uniffi_bdkffi_fn_method_psbt_extract_tx(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func serialize() -> String { - return try! FfiConverterString.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_psbt_serialize(self.uniffiClonePointer(), $0 +open func fee()throws -> UInt64 { + return try FfiConverterUInt64.lift(try rustCallWithError(FfiConverterTypePsbtError.lift) { + uniffi_bdkffi_fn_method_psbt_fee(self.uniffiClonePointer(),$0 ) +}) } - ) - } + +open func jsonSerialize() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_bdkffi_fn_method_psbt_json_serialize(self.uniffiClonePointer(),$0 + ) +}) +} + +open func serialize() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_bdkffi_fn_method_psbt_serialize(self.uniffiClonePointer(),$0 + ) +}) +} + } @@ -1986,6 +2478,8 @@ public struct FfiConverterTypePsbt: FfiConverter { } + + public func FfiConverterTypePsbt_lift(_ pointer: UnsafeMutableRawPointer) throws -> Psbt { return try FfiConverterTypePsbt.lift(pointer) } @@ -1997,68 +2491,180 @@ public func FfiConverterTypePsbt_lower(_ value: Psbt) -> UnsafeMutableRawPointer -public protocol ScriptProtocol : AnyObject { - - func toBytes() -> [UInt8] +public protocol SyncRequestProtocol : AnyObject { } -public class Script: - ScriptProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class SyncRequest: + SyncRequestProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_bdkffi_fn_clone_script(self.pointer, $0) } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil } - public convenience init(rawOutputScript: [UInt8]) { - self.init(unsafeFromRawPointer: try! rustCall() { - uniffi_bdkffi_fn_constructor_script_new( - FfiConverterSequenceUInt8.lower(rawOutputScript),$0) -}) + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_bdkffi_fn_clone_syncrequest(self.pointer, $0) } } + // No primary constructor declared for this class. deinit { - try! rustCall { uniffi_bdkffi_fn_free_script(pointer, $0) } + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_bdkffi_fn_free_syncrequest(pointer, $0) } + } + + + + + +} + +public struct FfiConverterTypeSyncRequest: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = SyncRequest + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncRequest { + return SyncRequest(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: SyncRequest) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SyncRequest { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: SyncRequest, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } +} + + + +public func FfiConverterTypeSyncRequest_lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncRequest { + return try FfiConverterTypeSyncRequest.lift(pointer) +} + +public func FfiConverterTypeSyncRequest_lower(_ value: SyncRequest) -> UnsafeMutableRawPointer { + return FfiConverterTypeSyncRequest.lower(value) +} + + + + +public protocol SyncRequestBuilderProtocol : AnyObject { + + func build() throws -> SyncRequest + + func inspectSpks(inspector: SyncScriptInspector) throws -> SyncRequestBuilder +} + +open class SyncRequestBuilder: + SyncRequestBuilderProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_bdkffi_fn_clone_syncrequestbuilder(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_bdkffi_fn_free_syncrequestbuilder(pointer, $0) } + } + - public func toBytes() -> [UInt8] { - return try! FfiConverterSequenceUInt8.lift( - try! - rustCall() { +open func build()throws -> SyncRequest { + return try FfiConverterTypeSyncRequest.lift(try rustCallWithError(FfiConverterTypeRequestBuilderError.lift) { + uniffi_bdkffi_fn_method_syncrequestbuilder_build(self.uniffiClonePointer(),$0 + ) +}) +} - uniffi_bdkffi_fn_method_script_to_bytes(self.uniffiClonePointer(), $0 +open func inspectSpks(inspector: SyncScriptInspector)throws -> SyncRequestBuilder { + return try FfiConverterTypeSyncRequestBuilder.lift(try rustCallWithError(FfiConverterTypeRequestBuilderError.lift) { + uniffi_bdkffi_fn_method_syncrequestbuilder_inspect_spks(self.uniffiClonePointer(), + FfiConverterTypeSyncScriptInspector.lower(inspector),$0 ) +}) } - ) - } + } -public struct FfiConverterTypeScript: FfiConverter { +public struct FfiConverterTypeSyncRequestBuilder: FfiConverter { typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Script + typealias SwiftType = SyncRequestBuilder - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Script { - return Script(unsafeFromRawPointer: pointer) + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncRequestBuilder { + return SyncRequestBuilder(unsafeFromRawPointer: pointer) } - public static func lower(_ value: Script) -> UnsafeMutableRawPointer { + public static func lower(_ value: SyncRequestBuilder) -> UnsafeMutableRawPointer { return value.uniffiClonePointer() } - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Script { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SyncRequestBuilder { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -2069,7 +2675,7 @@ public struct FfiConverterTypeScript: FfiConverter { return try lift(ptr!) } - public static func write(_ value: Script, into buf: inout [UInt8]) { + public static func write(_ value: SyncRequestBuilder, into buf: inout [UInt8]) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) @@ -2077,61 +2683,141 @@ public struct FfiConverterTypeScript: FfiConverter { } -public func FfiConverterTypeScript_lift(_ pointer: UnsafeMutableRawPointer) throws -> Script { - return try FfiConverterTypeScript.lift(pointer) + + +public func FfiConverterTypeSyncRequestBuilder_lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncRequestBuilder { + return try FfiConverterTypeSyncRequestBuilder.lift(pointer) } -public func FfiConverterTypeScript_lower(_ value: Script) -> UnsafeMutableRawPointer { - return FfiConverterTypeScript.lower(value) +public func FfiConverterTypeSyncRequestBuilder_lower(_ value: SyncRequestBuilder) -> UnsafeMutableRawPointer { + return FfiConverterTypeSyncRequestBuilder.lower(value) } -public protocol SyncRequestProtocol : AnyObject { +public protocol SyncScriptInspector : AnyObject { + + func inspect(script: Script, total: UInt64) } -public class SyncRequest: - SyncRequestProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class SyncScriptInspectorImpl: + SyncScriptInspector { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_bdkffi_fn_clone_syncrequest(self.pointer, $0) } + return try! rustCall { uniffi_bdkffi_fn_clone_syncscriptinspector(self.pointer, $0) } } + // No primary constructor declared for this class. deinit { - try! rustCall { uniffi_bdkffi_fn_free_syncrequest(pointer, $0) } + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_bdkffi_fn_free_syncscriptinspector(pointer, $0) } } +open func inspect(script: Script, total: UInt64) {try! rustCall() { + uniffi_bdkffi_fn_method_syncscriptinspector_inspect(self.uniffiClonePointer(), + FfiConverterTypeScript_lower(script), + FfiConverterUInt64.lower(total),$0 + ) +} +} } -public struct FfiConverterTypeSyncRequest: FfiConverter { + +// Put the implementation in a struct so we don't pollute the top-level namespace +fileprivate struct UniffiCallbackInterfaceSyncScriptInspector { + + // Create the VTable using a series of closures. + // Swift automatically converts these into C callback functions. + static var vtable: UniffiVTableCallbackInterfaceSyncScriptInspector = UniffiVTableCallbackInterfaceSyncScriptInspector( + inspect: { ( + uniffiHandle: UInt64, + script: UnsafeMutableRawPointer, + total: UInt64, + uniffiOutReturn: UnsafeMutableRawPointer, + uniffiCallStatus: UnsafeMutablePointer + ) in + let makeCall = { + () throws -> () in + guard let uniffiObj = try? FfiConverterTypeSyncScriptInspector.handleMap.get(handle: uniffiHandle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return uniffiObj.inspect( + script: try FfiConverterTypeScript_lift(script), + total: try FfiConverterUInt64.lift(total) + ) + } + + + let writeReturn = { () } + uniffiTraitInterfaceCall( + callStatus: uniffiCallStatus, + makeCall: makeCall, + writeReturn: writeReturn + ) + }, + uniffiFree: { (uniffiHandle: UInt64) -> () in + let result = try? FfiConverterTypeSyncScriptInspector.handleMap.remove(handle: uniffiHandle) + if result == nil { + print("Uniffi callback interface SyncScriptInspector: handle missing in uniffiFree") + } + } + ) +} + +private func uniffiCallbackInitSyncScriptInspector() { + uniffi_bdkffi_fn_init_callback_vtable_syncscriptinspector(&UniffiCallbackInterfaceSyncScriptInspector.vtable) +} + +public struct FfiConverterTypeSyncScriptInspector: FfiConverter { + fileprivate static var handleMap = UniffiHandleMap() typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = SyncRequest + typealias SwiftType = SyncScriptInspector - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncRequest { - return SyncRequest(unsafeFromRawPointer: pointer) + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncScriptInspector { + return SyncScriptInspectorImpl(unsafeFromRawPointer: pointer) } - public static func lower(_ value: SyncRequest) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() + public static func lower(_ value: SyncScriptInspector) -> UnsafeMutableRawPointer { + guard let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: handleMap.insert(obj: value))) else { + fatalError("Cast to UnsafeMutableRawPointer failed") + } + return ptr } - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SyncRequest { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SyncScriptInspector { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -2142,7 +2828,7 @@ public struct FfiConverterTypeSyncRequest: FfiConverter { return try lift(ptr!) } - public static func write(_ value: SyncRequest, into buf: inout [UInt8]) { + public static func write(_ value: SyncScriptInspector, into buf: inout [UInt8]) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) @@ -2150,12 +2836,14 @@ public struct FfiConverterTypeSyncRequest: FfiConverter { } -public func FfiConverterTypeSyncRequest_lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncRequest { - return try FfiConverterTypeSyncRequest.lift(pointer) + + +public func FfiConverterTypeSyncScriptInspector_lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncScriptInspector { + return try FfiConverterTypeSyncScriptInspector.lift(pointer) } -public func FfiConverterTypeSyncRequest_lower(_ value: SyncRequest) -> UnsafeMutableRawPointer { - return FfiConverterTypeSyncRequest.lower(value) +public func FfiConverterTypeSyncScriptInspector_lower(_ value: SyncScriptInspector) -> UnsafeMutableRawPointer { + return FfiConverterTypeSyncScriptInspector.lower(value) } @@ -2163,6 +2851,8 @@ public func FfiConverterTypeSyncRequest_lower(_ value: SyncRequest) -> UnsafeMut public protocol TransactionProtocol : AnyObject { + func computeTxid() -> String + func input() -> [TxIn] func isCoinbase() -> Bool @@ -2179,8 +2869,6 @@ public protocol TransactionProtocol : AnyObject { func totalSize() -> UInt64 - func txid() -> String - func version() -> Int32 func vsize() -> UInt64 @@ -2189,155 +2877,139 @@ public protocol TransactionProtocol : AnyObject { } -public class Transaction: +open class Transaction: TransactionProtocol { - fileprivate let pointer: UnsafeMutableRawPointer + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_transaction(self.pointer, $0) } } - public convenience init(transactionBytes: [UInt8]) throws { - self.init(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeTransactionError.lift) { +public convenience init(transactionBytes: [UInt8])throws { + let pointer = + try rustCallWithError(FfiConverterTypeTransactionError.lift) { uniffi_bdkffi_fn_constructor_transaction_new( - FfiConverterSequenceUInt8.lower(transactionBytes),$0) -}) - } + FfiConverterSequenceUInt8.lower(transactionBytes),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_bdkffi_fn_free_transaction(pointer, $0) } } - - public func input() -> [TxIn] { - return try! FfiConverterSequenceTypeTxIn.lift( - try! - rustCall() { - - uniffi_bdkffi_fn_method_transaction_input(self.uniffiClonePointer(), $0 +open func computeTxid() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_bdkffi_fn_method_transaction_compute_txid(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func isCoinbase() -> Bool { - return try! FfiConverterBool.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_transaction_is_coinbase(self.uniffiClonePointer(), $0 +open func input() -> [TxIn] { + return try! FfiConverterSequenceTypeTxIn.lift(try! rustCall() { + uniffi_bdkffi_fn_method_transaction_input(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func isExplicitlyRbf() -> Bool { - return try! FfiConverterBool.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_transaction_is_explicitly_rbf(self.uniffiClonePointer(), $0 +open func isCoinbase() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_bdkffi_fn_method_transaction_is_coinbase(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func isLockTimeEnabled() -> Bool { - return try! FfiConverterBool.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_transaction_is_lock_time_enabled(self.uniffiClonePointer(), $0 +open func isExplicitlyRbf() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_bdkffi_fn_method_transaction_is_explicitly_rbf(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func lockTime() -> UInt32 { - return try! FfiConverterUInt32.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_transaction_lock_time(self.uniffiClonePointer(), $0 +open func isLockTimeEnabled() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_bdkffi_fn_method_transaction_is_lock_time_enabled(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func output() -> [TxOut] { - return try! FfiConverterSequenceTypeTxOut.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_transaction_output(self.uniffiClonePointer(), $0 +open func lockTime() -> UInt32 { + return try! FfiConverterUInt32.lift(try! rustCall() { + uniffi_bdkffi_fn_method_transaction_lock_time(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func serialize() -> [UInt8] { - return try! FfiConverterSequenceUInt8.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_transaction_serialize(self.uniffiClonePointer(), $0 +open func output() -> [TxOut] { + return try! FfiConverterSequenceTypeTxOut.lift(try! rustCall() { + uniffi_bdkffi_fn_method_transaction_output(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func totalSize() -> UInt64 { - return try! FfiConverterUInt64.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_transaction_total_size(self.uniffiClonePointer(), $0 +open func serialize() -> [UInt8] { + return try! FfiConverterSequenceUInt8.lift(try! rustCall() { + uniffi_bdkffi_fn_method_transaction_serialize(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func txid() -> String { - return try! FfiConverterString.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_transaction_txid(self.uniffiClonePointer(), $0 +open func totalSize() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_bdkffi_fn_method_transaction_total_size(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func version() -> Int32 { - return try! FfiConverterInt32.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_transaction_version(self.uniffiClonePointer(), $0 +open func version() -> Int32 { + return try! FfiConverterInt32.lift(try! rustCall() { + uniffi_bdkffi_fn_method_transaction_version(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func vsize() -> UInt64 { - return try! FfiConverterUInt64.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_transaction_vsize(self.uniffiClonePointer(), $0 +open func vsize() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_bdkffi_fn_method_transaction_vsize(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func weight() -> UInt64 { - return try! FfiConverterUInt64.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_transaction_weight(self.uniffiClonePointer(), $0 +open func weight() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_bdkffi_fn_method_transaction_weight(self.uniffiClonePointer(),$0 ) +}) } - ) - } + } @@ -2373,6 +3045,8 @@ public struct FfiConverterTypeTransaction: FfiConverter { } + + public func FfiConverterTypeTransaction_lift(_ pointer: UnsafeMutableRawPointer) throws -> Transaction { return try FfiConverterTypeTransaction.lift(pointer) } @@ -2386,6 +3060,8 @@ public func FfiConverterTypeTransaction_lower(_ value: Transaction) -> UnsafeMut public protocol TxBuilderProtocol : AnyObject { + func addGlobalXpubs() -> TxBuilder + func addRecipient(script: Script, amount: Amount) -> TxBuilder func addUnspendable(unspendable: OutPoint) -> TxBuilder @@ -2404,7 +3080,7 @@ public protocol TxBuilderProtocol : AnyObject { func enableRbfWithSequence(nsequence: UInt32) -> TxBuilder - func feeAbsolute(fee: UInt64) -> TxBuilder + func feeAbsolute(fee: Amount) -> TxBuilder func feeRate(feeRate: FeeRate) -> TxBuilder @@ -2420,205 +3096,185 @@ public protocol TxBuilderProtocol : AnyObject { } -public class TxBuilder: +open class TxBuilder: TxBuilderProtocol { - fileprivate let pointer: UnsafeMutableRawPointer + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_txbuilder(self.pointer, $0) } } - public convenience init() { - self.init(unsafeFromRawPointer: try! rustCall() { - uniffi_bdkffi_fn_constructor_txbuilder_new($0) -}) - } +public convenience init() { + let pointer = + try! rustCall() { + uniffi_bdkffi_fn_constructor_txbuilder_new($0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } - deinit { try! rustCall { uniffi_bdkffi_fn_free_txbuilder(pointer, $0) } } +open func addGlobalXpubs() -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_add_global_xpubs(self.uniffiClonePointer(),$0 + ) +}) +} - public func addRecipient(script: Script, amount: Amount) -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - - uniffi_bdkffi_fn_method_txbuilder_add_recipient(self.uniffiClonePointer(), - FfiConverterTypeScript.lower(script), - FfiConverterTypeAmount.lower(amount),$0 +open func addRecipient(script: Script, amount: Amount) -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_add_recipient(self.uniffiClonePointer(), + FfiConverterTypeScript_lower(script), + FfiConverterTypeAmount_lower(amount),$0 ) +}) } - ) - } - public func addUnspendable(unspendable: OutPoint) -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_add_unspendable(self.uniffiClonePointer(), - FfiConverterTypeOutPoint.lower(unspendable),$0 +open func addUnspendable(unspendable: OutPoint) -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_add_unspendable(self.uniffiClonePointer(), + FfiConverterTypeOutPoint_lower(unspendable),$0 ) +}) } - ) - } - public func addUtxo(outpoint: OutPoint) -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_add_utxo(self.uniffiClonePointer(), - FfiConverterTypeOutPoint.lower(outpoint),$0 +open func addUtxo(outpoint: OutPoint) -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_add_utxo(self.uniffiClonePointer(), + FfiConverterTypeOutPoint_lower(outpoint),$0 ) +}) } - ) - } - public func changePolicy(changePolicy: ChangeSpendPolicy) -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_change_policy(self.uniffiClonePointer(), +open func changePolicy(changePolicy: ChangeSpendPolicy) -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_change_policy(self.uniffiClonePointer(), FfiConverterTypeChangeSpendPolicy.lower(changePolicy),$0 ) +}) } - ) - } - public func doNotSpendChange() -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_do_not_spend_change(self.uniffiClonePointer(), $0 +open func doNotSpendChange() -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_do_not_spend_change(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func drainTo(script: Script) -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_drain_to(self.uniffiClonePointer(), - FfiConverterTypeScript.lower(script),$0 +open func drainTo(script: Script) -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_drain_to(self.uniffiClonePointer(), + FfiConverterTypeScript_lower(script),$0 ) +}) } - ) - } - public func drainWallet() -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_drain_wallet(self.uniffiClonePointer(), $0 +open func drainWallet() -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_drain_wallet(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func enableRbf() -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_enable_rbf(self.uniffiClonePointer(), $0 +open func enableRbf() -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_enable_rbf(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func enableRbfWithSequence(nsequence: UInt32) -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_enable_rbf_with_sequence(self.uniffiClonePointer(), +open func enableRbfWithSequence(nsequence: UInt32) -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_enable_rbf_with_sequence(self.uniffiClonePointer(), FfiConverterUInt32.lower(nsequence),$0 ) +}) } - ) - } - public func feeAbsolute(fee: UInt64) -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_fee_absolute(self.uniffiClonePointer(), - FfiConverterUInt64.lower(fee),$0 +open func feeAbsolute(fee: Amount) -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_fee_absolute(self.uniffiClonePointer(), + FfiConverterTypeAmount_lower(fee),$0 ) +}) } - ) - } - public func feeRate(feeRate: FeeRate) -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_fee_rate(self.uniffiClonePointer(), - FfiConverterTypeFeeRate.lower(feeRate),$0 +open func feeRate(feeRate: FeeRate) -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_fee_rate(self.uniffiClonePointer(), + FfiConverterTypeFeeRate_lower(feeRate),$0 ) +}) } - ) - } - public func finish(wallet: Wallet) throws -> Psbt { - return try FfiConverterTypePsbt.lift( - try - rustCallWithError(FfiConverterTypeCreateTxError.lift) { - uniffi_bdkffi_fn_method_txbuilder_finish(self.uniffiClonePointer(), + +open func finish(wallet: Wallet)throws -> Psbt { + return try FfiConverterTypePsbt.lift(try rustCallWithError(FfiConverterTypeCreateTxError.lift) { + uniffi_bdkffi_fn_method_txbuilder_finish(self.uniffiClonePointer(), FfiConverterTypeWallet.lower(wallet),$0 ) +}) } - ) - } - public func manuallySelectedOnly() -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_manually_selected_only(self.uniffiClonePointer(), $0 +open func manuallySelectedOnly() -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_manually_selected_only(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func onlySpendChange() -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_only_spend_change(self.uniffiClonePointer(), $0 +open func onlySpendChange() -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_only_spend_change(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func setRecipients(recipients: [ScriptAmount]) -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_set_recipients(self.uniffiClonePointer(), +open func setRecipients(recipients: [ScriptAmount]) -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_set_recipients(self.uniffiClonePointer(), FfiConverterSequenceTypeScriptAmount.lower(recipients),$0 ) +}) } - ) - } - public func unspendable(unspendable: [OutPoint]) -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_txbuilder_unspendable(self.uniffiClonePointer(), +open func unspendable(unspendable: [OutPoint]) -> TxBuilder { + return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_txbuilder_unspendable(self.uniffiClonePointer(), FfiConverterSequenceTypeOutPoint.lower(unspendable),$0 ) +}) } - ) - } + } @@ -2654,6 +3310,8 @@ public struct FfiConverterTypeTxBuilder: FfiConverter { } + + public func FfiConverterTypeTxBuilder_lift(_ pointer: UnsafeMutableRawPointer) throws -> TxBuilder { return try FfiConverterTypeTxBuilder.lift(pointer) } @@ -2669,29 +3327,47 @@ public protocol UpdateProtocol : AnyObject { } -public class Update: +open class Update: UpdateProtocol { - fileprivate let pointer: UnsafeMutableRawPointer + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_update(self.pointer, $0) } } + // No primary constructor declared for this class. deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_bdkffi_fn_free_update(pointer, $0) } } - } @@ -2727,6 +3403,8 @@ public struct FfiConverterTypeUpdate: FfiConverter { } + + public func FfiConverterTypeUpdate_lift(_ pointer: UnsafeMutableRawPointer) throws -> Update { return try FfiConverterTypeUpdate.lift(pointer) } @@ -2742,13 +3420,13 @@ public protocol WalletProtocol : AnyObject { func applyUpdate(update: Update) throws - func calculateFee(tx: Transaction) throws -> UInt64 + func balance() -> Balance - func calculateFeeRate(tx: Transaction) throws -> FeeRate + func calculateFee(tx: Transaction) throws -> Amount - func commit() throws -> Bool + func calculateFeeRate(tx: Transaction) throws -> FeeRate - func getBalance() -> Balance + func derivationIndex(keychain: KeychainKind) -> UInt32? func getTx(txid: String) throws -> CanonicalTx? @@ -2760,221 +3438,212 @@ public protocol WalletProtocol : AnyObject { func network() -> Network - func revealNextAddress(keychain: KeychainKind) throws -> AddressInfo + func persist(connection: Connection) throws -> Bool + + func revealNextAddress(keychain: KeychainKind) -> AddressInfo func sentAndReceived(tx: Transaction) -> SentAndReceivedValues func sign(psbt: Psbt) throws -> Bool - func startFullScan() -> FullScanRequest + func startFullScan() -> FullScanRequestBuilder - func startSyncWithRevealedSpks() -> SyncRequest + func startSyncWithRevealedSpks() -> SyncRequestBuilder func transactions() -> [CanonicalTx] } -public class Wallet: +open class Wallet: WalletProtocol { - fileprivate let pointer: UnsafeMutableRawPointer + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer: NoPointer) { + self.pointer = nil + } + public func uniffiClonePointer() -> UnsafeMutableRawPointer { return try! rustCall { uniffi_bdkffi_fn_clone_wallet(self.pointer, $0) } } - public convenience init(descriptor: Descriptor, changeDescriptor: Descriptor?, persistenceBackendPath: String, network: Network) throws { - self.init(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeWalletCreationError.lift) { +public convenience init(descriptor: Descriptor, changeDescriptor: Descriptor, network: Network, connection: Connection)throws { + let pointer = + try rustCallWithError(FfiConverterTypeCreateWithPersistError.lift) { uniffi_bdkffi_fn_constructor_wallet_new( FfiConverterTypeDescriptor.lower(descriptor), - FfiConverterOptionTypeDescriptor.lower(changeDescriptor), - FfiConverterString.lower(persistenceBackendPath), - FfiConverterTypeNetwork.lower(network),$0) -}) - } + FfiConverterTypeDescriptor.lower(changeDescriptor), + FfiConverterTypeNetwork_lower(network), + FfiConverterTypeConnection.lower(connection),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_bdkffi_fn_free_wallet(pointer, $0) } } - public static func newNoPersist(descriptor: Descriptor, changeDescriptor: Descriptor?, network: Network) throws -> Wallet { - return Wallet(unsafeFromRawPointer: try rustCallWithError(FfiConverterTypeDescriptorError.lift) { - uniffi_bdkffi_fn_constructor_wallet_new_no_persist( +public static func load(descriptor: Descriptor, changeDescriptor: Descriptor, connection: Connection)throws -> Wallet { + return try FfiConverterTypeWallet.lift(try rustCallWithError(FfiConverterTypeLoadWithPersistError.lift) { + uniffi_bdkffi_fn_constructor_wallet_load( FfiConverterTypeDescriptor.lower(descriptor), - FfiConverterOptionTypeDescriptor.lower(changeDescriptor), - FfiConverterTypeNetwork.lower(network),$0) + FfiConverterTypeDescriptor.lower(changeDescriptor), + FfiConverterTypeConnection.lower(connection),$0 + ) }) - } - +} - - public func applyUpdate(update: Update) throws { - try - rustCallWithError(FfiConverterTypeCannotConnectError.lift) { - uniffi_bdkffi_fn_method_wallet_apply_update(self.uniffiClonePointer(), +open func applyUpdate(update: Update)throws {try rustCallWithError(FfiConverterTypeCannotConnectError.lift) { + uniffi_bdkffi_fn_method_wallet_apply_update(self.uniffiClonePointer(), FfiConverterTypeUpdate.lower(update),$0 ) } - } - public func calculateFee(tx: Transaction) throws -> UInt64 { - return try FfiConverterUInt64.lift( - try - rustCallWithError(FfiConverterTypeCalculateFeeError.lift) { - uniffi_bdkffi_fn_method_wallet_calculate_fee(self.uniffiClonePointer(), - FfiConverterTypeTransaction.lower(tx),$0 +} + +open func balance() -> Balance { + return try! FfiConverterTypeBalance.lift(try! rustCall() { + uniffi_bdkffi_fn_method_wallet_balance(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func calculateFeeRate(tx: Transaction) throws -> FeeRate { - return try FfiConverterTypeFeeRate.lift( - try - rustCallWithError(FfiConverterTypeCalculateFeeError.lift) { - uniffi_bdkffi_fn_method_wallet_calculate_fee_rate(self.uniffiClonePointer(), + +open func calculateFee(tx: Transaction)throws -> Amount { + return try FfiConverterTypeAmount_lift(try rustCallWithError(FfiConverterTypeCalculateFeeError.lift) { + uniffi_bdkffi_fn_method_wallet_calculate_fee(self.uniffiClonePointer(), FfiConverterTypeTransaction.lower(tx),$0 ) +}) } - ) - } - public func commit() throws -> Bool { - return try FfiConverterBool.lift( - try - rustCallWithError(FfiConverterTypePersistenceError.lift) { - uniffi_bdkffi_fn_method_wallet_commit(self.uniffiClonePointer(), $0 + +open func calculateFeeRate(tx: Transaction)throws -> FeeRate { + return try FfiConverterTypeFeeRate_lift(try rustCallWithError(FfiConverterTypeCalculateFeeError.lift) { + uniffi_bdkffi_fn_method_wallet_calculate_fee_rate(self.uniffiClonePointer(), + FfiConverterTypeTransaction.lower(tx),$0 ) +}) } - ) - } - public func getBalance() -> Balance { - return try! FfiConverterTypeBalance.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_wallet_get_balance(self.uniffiClonePointer(), $0 +open func derivationIndex(keychain: KeychainKind) -> UInt32? { + return try! FfiConverterOptionUInt32.lift(try! rustCall() { + uniffi_bdkffi_fn_method_wallet_derivation_index(self.uniffiClonePointer(), + FfiConverterTypeKeychainKind.lower(keychain),$0 ) +}) } - ) - } - public func getTx(txid: String) throws -> CanonicalTx? { - return try FfiConverterOptionTypeCanonicalTx.lift( - try - rustCallWithError(FfiConverterTypeTxidParseError.lift) { - uniffi_bdkffi_fn_method_wallet_get_tx(self.uniffiClonePointer(), + +open func getTx(txid: String)throws -> CanonicalTx? { + return try FfiConverterOptionTypeCanonicalTx.lift(try rustCallWithError(FfiConverterTypeTxidParseError.lift) { + uniffi_bdkffi_fn_method_wallet_get_tx(self.uniffiClonePointer(), FfiConverterString.lower(txid),$0 ) +}) } - ) - } - public func isMine(script: Script) -> Bool { - return try! FfiConverterBool.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_wallet_is_mine(self.uniffiClonePointer(), - FfiConverterTypeScript.lower(script),$0 +open func isMine(script: Script) -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_bdkffi_fn_method_wallet_is_mine(self.uniffiClonePointer(), + FfiConverterTypeScript_lower(script),$0 ) +}) } - ) - } - public func listOutput() -> [LocalOutput] { - return try! FfiConverterSequenceTypeLocalOutput.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_wallet_list_output(self.uniffiClonePointer(), $0 +open func listOutput() -> [LocalOutput] { + return try! FfiConverterSequenceTypeLocalOutput.lift(try! rustCall() { + uniffi_bdkffi_fn_method_wallet_list_output(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func listUnspent() -> [LocalOutput] { - return try! FfiConverterSequenceTypeLocalOutput.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_wallet_list_unspent(self.uniffiClonePointer(), $0 +open func listUnspent() -> [LocalOutput] { + return try! FfiConverterSequenceTypeLocalOutput.lift(try! rustCall() { + uniffi_bdkffi_fn_method_wallet_list_unspent(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func network() -> Network { - return try! FfiConverterTypeNetwork.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_wallet_network(self.uniffiClonePointer(), $0 +open func network() -> Network { + return try! FfiConverterTypeNetwork_lift(try! rustCall() { + uniffi_bdkffi_fn_method_wallet_network(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func revealNextAddress(keychain: KeychainKind) throws -> AddressInfo { - return try FfiConverterTypeAddressInfo.lift( - try - rustCallWithError(FfiConverterTypePersistenceError.lift) { - uniffi_bdkffi_fn_method_wallet_reveal_next_address(self.uniffiClonePointer(), + +open func persist(connection: Connection)throws -> Bool { + return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeSqliteError.lift) { + uniffi_bdkffi_fn_method_wallet_persist(self.uniffiClonePointer(), + FfiConverterTypeConnection.lower(connection),$0 + ) +}) +} + +open func revealNextAddress(keychain: KeychainKind) -> AddressInfo { + return try! FfiConverterTypeAddressInfo.lift(try! rustCall() { + uniffi_bdkffi_fn_method_wallet_reveal_next_address(self.uniffiClonePointer(), FfiConverterTypeKeychainKind.lower(keychain),$0 ) +}) } - ) - } - public func sentAndReceived(tx: Transaction) -> SentAndReceivedValues { - return try! FfiConverterTypeSentAndReceivedValues.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_wallet_sent_and_received(self.uniffiClonePointer(), +open func sentAndReceived(tx: Transaction) -> SentAndReceivedValues { + return try! FfiConverterTypeSentAndReceivedValues.lift(try! rustCall() { + uniffi_bdkffi_fn_method_wallet_sent_and_received(self.uniffiClonePointer(), FfiConverterTypeTransaction.lower(tx),$0 ) +}) } - ) - } - public func sign(psbt: Psbt) throws -> Bool { - return try FfiConverterBool.lift( - try - rustCallWithError(FfiConverterTypeSignerError.lift) { - uniffi_bdkffi_fn_method_wallet_sign(self.uniffiClonePointer(), + +open func sign(psbt: Psbt)throws -> Bool { + return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeSignerError.lift) { + uniffi_bdkffi_fn_method_wallet_sign(self.uniffiClonePointer(), FfiConverterTypePsbt.lower(psbt),$0 ) +}) } - ) - } - public func startFullScan() -> FullScanRequest { - return try! FfiConverterTypeFullScanRequest.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_wallet_start_full_scan(self.uniffiClonePointer(), $0 +open func startFullScan() -> FullScanRequestBuilder { + return try! FfiConverterTypeFullScanRequestBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_wallet_start_full_scan(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func startSyncWithRevealedSpks() -> SyncRequest { - return try! FfiConverterTypeSyncRequest.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_wallet_start_sync_with_revealed_spks(self.uniffiClonePointer(), $0 +open func startSyncWithRevealedSpks() -> SyncRequestBuilder { + return try! FfiConverterTypeSyncRequestBuilder.lift(try! rustCall() { + uniffi_bdkffi_fn_method_wallet_start_sync_with_revealed_spks(self.uniffiClonePointer(),$0 ) +}) } - ) - } - public func transactions() -> [CanonicalTx] { - return try! FfiConverterSequenceTypeCanonicalTx.lift( - try! - rustCall() { - uniffi_bdkffi_fn_method_wallet_transactions(self.uniffiClonePointer(), $0 +open func transactions() -> [CanonicalTx] { + return try! FfiConverterSequenceTypeCanonicalTx.lift(try! rustCall() { + uniffi_bdkffi_fn_method_wallet_transactions(self.uniffiClonePointer(),$0 ) +}) } - ) - } + } @@ -3010,6 +3679,8 @@ public struct FfiConverterTypeWallet: FfiConverter { } + + public func FfiConverterTypeWallet_lift(_ pointer: UnsafeMutableRawPointer) throws -> Wallet { return try FfiConverterTypeWallet.lift(pointer) } @@ -3026,10 +3697,7 @@ public struct AddressInfo { // Default memberwise initializers are never public by default, so we // declare one manually. - public init( - index: UInt32, - address: Address, - keychain: KeychainKind) { + public init(index: UInt32, address: Address, keychain: KeychainKind) { self.index = index self.address = address self.keychain = keychain @@ -3075,13 +3743,7 @@ public struct Balance { // Default memberwise initializers are never public by default, so we // declare one manually. - public init( - immature: Amount, - trustedPending: Amount, - untrustedPending: Amount, - confirmed: Amount, - trustedSpendable: Amount, - total: Amount) { + public init(immature: Amount, trustedPending: Amount, untrustedPending: Amount, confirmed: Amount, trustedSpendable: Amount, total: Amount) { self.immature = immature self.trustedPending = trustedPending self.untrustedPending = untrustedPending @@ -3126,15 +3788,70 @@ public func FfiConverterTypeBalance_lower(_ value: Balance) -> RustBuffer { } +public struct BlockId { + public var height: UInt32 + public var hash: String + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(height: UInt32, hash: String) { + self.height = height + self.hash = hash + } +} + + + +extension BlockId: Equatable, Hashable { + public static func ==(lhs: BlockId, rhs: BlockId) -> Bool { + if lhs.height != rhs.height { + return false + } + if lhs.hash != rhs.hash { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(height) + hasher.combine(hash) + } +} + + +public struct FfiConverterTypeBlockId: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> BlockId { + return + try BlockId( + height: FfiConverterUInt32.read(from: &buf), + hash: FfiConverterString.read(from: &buf) + ) + } + + public static func write(_ value: BlockId, into buf: inout [UInt8]) { + FfiConverterUInt32.write(value.height, into: &buf) + FfiConverterString.write(value.hash, into: &buf) + } +} + + +public func FfiConverterTypeBlockId_lift(_ buf: RustBuffer) throws -> BlockId { + return try FfiConverterTypeBlockId.lift(buf) +} + +public func FfiConverterTypeBlockId_lower(_ value: BlockId) -> RustBuffer { + return FfiConverterTypeBlockId.lower(value) +} + + public struct CanonicalTx { public var transaction: Transaction public var chainPosition: ChainPosition // Default memberwise initializers are never public by default, so we // declare one manually. - public init( - transaction: Transaction, - chainPosition: ChainPosition) { + public init(transaction: Transaction, chainPosition: ChainPosition) { self.transaction = transaction self.chainPosition = chainPosition } @@ -3167,6 +3884,63 @@ public func FfiConverterTypeCanonicalTx_lower(_ value: CanonicalTx) -> RustBuffe } +public struct ConfirmationBlockTime { + public var blockId: BlockId + public var confirmationTime: UInt64 + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(blockId: BlockId, confirmationTime: UInt64) { + self.blockId = blockId + self.confirmationTime = confirmationTime + } +} + + + +extension ConfirmationBlockTime: Equatable, Hashable { + public static func ==(lhs: ConfirmationBlockTime, rhs: ConfirmationBlockTime) -> Bool { + if lhs.blockId != rhs.blockId { + return false + } + if lhs.confirmationTime != rhs.confirmationTime { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(blockId) + hasher.combine(confirmationTime) + } +} + + +public struct FfiConverterTypeConfirmationBlockTime: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ConfirmationBlockTime { + return + try ConfirmationBlockTime( + blockId: FfiConverterTypeBlockId.read(from: &buf), + confirmationTime: FfiConverterUInt64.read(from: &buf) + ) + } + + public static func write(_ value: ConfirmationBlockTime, into buf: inout [UInt8]) { + FfiConverterTypeBlockId.write(value.blockId, into: &buf) + FfiConverterUInt64.write(value.confirmationTime, into: &buf) + } +} + + +public func FfiConverterTypeConfirmationBlockTime_lift(_ buf: RustBuffer) throws -> ConfirmationBlockTime { + return try FfiConverterTypeConfirmationBlockTime.lift(buf) +} + +public func FfiConverterTypeConfirmationBlockTime_lower(_ value: ConfirmationBlockTime) -> RustBuffer { + return FfiConverterTypeConfirmationBlockTime.lower(value) +} + + public struct LocalOutput { public var outpoint: OutPoint public var txout: TxOut @@ -3175,11 +3949,7 @@ public struct LocalOutput { // Default memberwise initializers are never public by default, so we // declare one manually. - public init( - outpoint: OutPoint, - txout: TxOut, - keychain: KeychainKind, - isSpent: Bool) { + public init(outpoint: OutPoint, txout: TxOut, keychain: KeychainKind, isSpent: Bool) { self.outpoint = outpoint self.txout = txout self.keychain = keychain @@ -3218,73 +3988,13 @@ public func FfiConverterTypeLocalOutput_lower(_ value: LocalOutput) -> RustBuffe } -public struct OutPoint { - public var txid: String - public var vout: UInt32 - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init( - txid: String, - vout: UInt32) { - self.txid = txid - self.vout = vout - } -} - - -extension OutPoint: Equatable, Hashable { - public static func ==(lhs: OutPoint, rhs: OutPoint) -> Bool { - if lhs.txid != rhs.txid { - return false - } - if lhs.vout != rhs.vout { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(txid) - hasher.combine(vout) - } -} - - -public struct FfiConverterTypeOutPoint: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> OutPoint { - return - try OutPoint( - txid: FfiConverterString.read(from: &buf), - vout: FfiConverterUInt32.read(from: &buf) - ) - } - - public static func write(_ value: OutPoint, into buf: inout [UInt8]) { - FfiConverterString.write(value.txid, into: &buf) - FfiConverterUInt32.write(value.vout, into: &buf) - } -} - - -public func FfiConverterTypeOutPoint_lift(_ buf: RustBuffer) throws -> OutPoint { - return try FfiConverterTypeOutPoint.lift(buf) -} - -public func FfiConverterTypeOutPoint_lower(_ value: OutPoint) -> RustBuffer { - return FfiConverterTypeOutPoint.lower(value) -} - - public struct ScriptAmount { public var script: Script public var amount: Amount // Default memberwise initializers are never public by default, so we // declare one manually. - public init( - script: Script, - amount: Amount) { + public init(script: Script, amount: Amount) { self.script = script self.amount = amount } @@ -3323,9 +4033,7 @@ public struct SentAndReceivedValues { // Default memberwise initializers are never public by default, so we // declare one manually. - public init( - sent: Amount, - received: Amount) { + public init(sent: Amount, received: Amount) { self.sent = sent self.received = received } @@ -3366,11 +4074,7 @@ public struct TxIn { // Default memberwise initializers are never public by default, so we // declare one manually. - public init( - previousOutput: OutPoint, - scriptSig: Script, - sequence: UInt32, - witness: [[UInt8]]) { + public init(previousOutput: OutPoint, scriptSig: Script, sequence: UInt32, witness: [[UInt8]]) { self.previousOutput = previousOutput self.scriptSig = scriptSig self.sequence = sequence @@ -3415,9 +4119,7 @@ public struct TxOut { // Default memberwise initializers are never public by default, so we // declare one manually. - public init( - value: UInt64, - scriptPubkey: Script) { + public init(value: UInt64, scriptPubkey: Script) { self.value = value self.scriptPubkey = scriptPubkey } @@ -3450,38 +4152,29 @@ public func FfiConverterTypeTxOut_lower(_ value: TxOut) -> RustBuffer { } -public enum AddressError { +public enum AddressParseError { case Base58 case Bech32 - case WitnessVersion( - errorMessage: String - ) - case WitnessProgram( - errorMessage: String + case WitnessVersion(errorMessage: String ) - case UncompressedPubkey - case ExcessiveScriptSize - case UnrecognizedScript - case NetworkValidation( - required: Network, - found: Network, - address: String + case WitnessProgram(errorMessage: String ) - case OtherAddressErr - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeAddressError.lift(error) - } + case UnknownHrp + case LegacyAddressTooLong + case InvalidBase58PayloadLength + case InvalidLegacyPrefix + case NetworkValidation + case OtherAddressParseErr } -public struct FfiConverterTypeAddressError: FfiConverterRustBuffer { - typealias SwiftType = AddressError +public struct FfiConverterTypeAddressParseError: FfiConverterRustBuffer { + typealias SwiftType = AddressParseError - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AddressError { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AddressParseError { let variant: Int32 = try readInt(&buf) switch variant { @@ -3496,21 +4189,18 @@ public struct FfiConverterTypeAddressError: FfiConverterRustBuffer { case 4: return .WitnessProgram( errorMessage: try FfiConverterString.read(from: &buf) ) - case 5: return .UncompressedPubkey - case 6: return .ExcessiveScriptSize - case 7: return .UnrecognizedScript - case 8: return .NetworkValidation( - required: try FfiConverterTypeNetwork.read(from: &buf), - found: try FfiConverterTypeNetwork.read(from: &buf), - address: try FfiConverterString.read(from: &buf) - ) - case 9: return .OtherAddressErr + case 5: return .UnknownHrp + case 6: return .LegacyAddressTooLong + case 7: return .InvalidBase58PayloadLength + case 8: return .InvalidLegacyPrefix + case 9: return .NetworkValidation + case 10: return .OtherAddressParseErr default: throw UniffiInternalError.unexpectedEnumCase } } - public static func write(_ value: AddressError, into buf: inout [UInt8]) { + public static func write(_ value: AddressParseError, into buf: inout [UInt8]) { switch value { @@ -3535,36 +4225,41 @@ public struct FfiConverterTypeAddressError: FfiConverterRustBuffer { FfiConverterString.write(errorMessage, into: &buf) - case .UncompressedPubkey: + case .UnknownHrp: writeInt(&buf, Int32(5)) - case .ExcessiveScriptSize: + case .LegacyAddressTooLong: writeInt(&buf, Int32(6)) - case .UnrecognizedScript: + case .InvalidBase58PayloadLength: writeInt(&buf, Int32(7)) - case let .NetworkValidation(required,found,address): + case .InvalidLegacyPrefix: writeInt(&buf, Int32(8)) - FfiConverterTypeNetwork.write(required, into: &buf) - FfiConverterTypeNetwork.write(found, into: &buf) - FfiConverterString.write(address, into: &buf) - - case .OtherAddressErr: + + case .NetworkValidation: writeInt(&buf, Int32(9)) + + case .OtherAddressParseErr: + writeInt(&buf, Int32(10)) + } } } -extension AddressError: Equatable, Hashable {} +extension AddressParseError: Equatable, Hashable {} -extension AddressError: Error { } +extension AddressParseError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} public enum Bip32Error { @@ -3572,36 +4267,24 @@ public enum Bip32Error { case CannotDeriveFromHardenedKey - case Secp256k1( - errorMessage: String + case Secp256k1(errorMessage: String ) - case InvalidChildNumber( - childNumber: UInt32 + case InvalidChildNumber(childNumber: UInt32 ) case InvalidChildNumberFormat case InvalidDerivationPathFormat - case UnknownVersion( - version: String + case UnknownVersion(version: String ) - case WrongExtendedKeyLength( - length: UInt32 + case WrongExtendedKeyLength(length: UInt32 ) - case Base58( - errorMessage: String + case Base58(errorMessage: String ) - case Hex( - errorMessage: String + case Hex(errorMessage: String ) - case InvalidPublicKeyHexLength( - length: UInt32 + case InvalidPublicKeyHexLength(length: UInt32 ) - case UnknownError( - errorMessage: String + case UnknownError(errorMessage: String ) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeBip32Error.lift(error) - } } @@ -3712,30 +4395,26 @@ public struct FfiConverterTypeBip32Error: FfiConverterRustBuffer { extension Bip32Error: Equatable, Hashable {} -extension Bip32Error: Error { } +extension Bip32Error: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} public enum Bip39Error { - case BadWordCount( - wordCount: UInt64 + case BadWordCount(wordCount: UInt64 ) - case UnknownWord( - index: UInt64 + case UnknownWord(index: UInt64 ) - case BadEntropyBitCount( - bitCount: UInt64 + case BadEntropyBitCount(bitCount: UInt64 ) case InvalidChecksum - case AmbiguousLanguages( - languages: String + case AmbiguousLanguages(languages: String ) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeBip39Error.lift(error) - } } @@ -3804,23 +4483,21 @@ public struct FfiConverterTypeBip39Error: FfiConverterRustBuffer { extension Bip39Error: Equatable, Hashable {} -extension Bip39Error: Error { } +extension Bip39Error: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} public enum CalculateFeeError { - case MissingTxOut( - outPoints: [OutPoint] + case MissingTxOut(outPoints: [OutPoint] ) - case NegativeFee( - fee: Int64 + case NegativeFee(amount: String ) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeCalculateFeeError.lift(error) - } } @@ -3838,7 +4515,7 @@ public struct FfiConverterTypeCalculateFeeError: FfiConverterRustBuffer { outPoints: try FfiConverterSequenceTypeOutPoint.read(from: &buf) ) case 2: return .NegativeFee( - fee: try FfiConverterInt64.read(from: &buf) + amount: try FfiConverterString.read(from: &buf) ) default: throw UniffiInternalError.unexpectedEnumCase @@ -3857,9 +4534,9 @@ public struct FfiConverterTypeCalculateFeeError: FfiConverterRustBuffer { FfiConverterSequenceTypeOutPoint.write(outPoints, into: &buf) - case let .NegativeFee(fee): + case let .NegativeFee(amount): writeInt(&buf, Int32(2)) - FfiConverterInt64.write(fee, into: &buf) + FfiConverterString.write(amount, into: &buf) } } @@ -3868,20 +4545,19 @@ public struct FfiConverterTypeCalculateFeeError: FfiConverterRustBuffer { extension CalculateFeeError: Equatable, Hashable {} -extension CalculateFeeError: Error { } +extension CalculateFeeError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} public enum CannotConnectError { - case Include( - height: UInt32 + case Include(height: UInt32 ) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeCannotConnectError.lift(error) - } } @@ -3921,21 +4597,24 @@ public struct FfiConverterTypeCannotConnectError: FfiConverterRustBuffer { extension CannotConnectError: Equatable, Hashable {} -extension CannotConnectError: Error { } +extension CannotConnectError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + public enum ChainPosition { - case confirmed( - height: UInt32, - timestamp: UInt64 + case confirmed(confirmationBlockTime: ConfirmationBlockTime ) - case unconfirmed( - timestamp: UInt64 + case unconfirmed(timestamp: UInt64 ) } + public struct FfiConverterTypeChainPosition: FfiConverterRustBuffer { typealias SwiftType = ChainPosition @@ -3943,13 +4622,10 @@ public struct FfiConverterTypeChainPosition: FfiConverterRustBuffer { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return .confirmed( - height: try FfiConverterUInt32.read(from: &buf), - timestamp: try FfiConverterUInt64.read(from: &buf) + case 1: return .confirmed(confirmationBlockTime: try FfiConverterTypeConfirmationBlockTime.read(from: &buf) ) - case 2: return .unconfirmed( - timestamp: try FfiConverterUInt64.read(from: &buf) + case 2: return .unconfirmed(timestamp: try FfiConverterUInt64.read(from: &buf) ) default: throw UniffiInternalError.unexpectedEnumCase @@ -3960,10 +4636,9 @@ public struct FfiConverterTypeChainPosition: FfiConverterRustBuffer { switch value { - case let .confirmed(height,timestamp): + case let .confirmed(confirmationBlockTime): writeInt(&buf, Int32(1)) - FfiConverterUInt32.write(height, into: &buf) - FfiConverterUInt64.write(timestamp, into: &buf) + FfiConverterTypeConfirmationBlockTime.write(confirmationBlockTime, into: &buf) case let .unconfirmed(timestamp): @@ -3984,12 +4659,14 @@ public func FfiConverterTypeChainPosition_lower(_ value: ChainPosition) -> RustB } + extension ChainPosition: Equatable, Hashable {} // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + public enum ChangeSpendPolicy { case changeAllowed @@ -3997,6 +4674,7 @@ public enum ChangeSpendPolicy { case changeForbidden } + public struct FfiConverterTypeChangeSpendPolicy: FfiConverterRustBuffer { typealias SwiftType = ChangeSpendPolicy @@ -4043,6 +4721,7 @@ public func FfiConverterTypeChangeSpendPolicy_lower(_ value: ChangeSpendPolicy) } + extension ChangeSpendPolicy: Equatable, Hashable {} @@ -4052,67 +4731,42 @@ public enum CreateTxError { - case Descriptor( - errorMessage: String - ) - case Persist( - errorMessage: String + case Descriptor(errorMessage: String ) - case Policy( - errorMessage: String + case Policy(errorMessage: String ) - case SpendingPolicyRequired( - kind: String + case SpendingPolicyRequired(kind: String ) case Version0 case Version1Csv - case LockTime( - requested: String, - required: String + case LockTime(requested: String, required: String ) case RbfSequence - case RbfSequenceCsv( - rbf: String, - csv: String + case RbfSequenceCsv(rbf: String, csv: String ) - case FeeTooLow( - required: UInt64 + case FeeTooLow(required: String ) - case FeeRateTooLow( - required: String + case FeeRateTooLow(required: String ) case NoUtxosSelected - case OutputBelowDustLimit( - index: UInt64 + case OutputBelowDustLimit(index: UInt64 ) case ChangePolicyDescriptor - case CoinSelection( - errorMessage: String + case CoinSelection(errorMessage: String ) - case InsufficientFunds( - needed: UInt64, - available: UInt64 + case InsufficientFunds(needed: UInt64, available: UInt64 ) case NoRecipients - case Psbt( - errorMessage: String + case Psbt(errorMessage: String ) - case MissingKeyOrigin( - key: String + case MissingKeyOrigin(key: String ) - case UnknownUtxo( - outpoint: String + case UnknownUtxo(outpoint: String ) - case MissingNonWitnessUtxo( - outpoint: String + case MissingNonWitnessUtxo(outpoint: String ) - case MiniscriptPsbt( - errorMessage: String + case MiniscriptPsbt(errorMessage: String ) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeCreateTxError.lift(error) - } } @@ -4129,58 +4783,55 @@ public struct FfiConverterTypeCreateTxError: FfiConverterRustBuffer { case 1: return .Descriptor( errorMessage: try FfiConverterString.read(from: &buf) ) - case 2: return .Persist( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 3: return .Policy( + case 2: return .Policy( errorMessage: try FfiConverterString.read(from: &buf) ) - case 4: return .SpendingPolicyRequired( + case 3: return .SpendingPolicyRequired( kind: try FfiConverterString.read(from: &buf) ) - case 5: return .Version0 - case 6: return .Version1Csv - case 7: return .LockTime( + case 4: return .Version0 + case 5: return .Version1Csv + case 6: return .LockTime( requested: try FfiConverterString.read(from: &buf), required: try FfiConverterString.read(from: &buf) ) - case 8: return .RbfSequence - case 9: return .RbfSequenceCsv( + case 7: return .RbfSequence + case 8: return .RbfSequenceCsv( rbf: try FfiConverterString.read(from: &buf), csv: try FfiConverterString.read(from: &buf) ) - case 10: return .FeeTooLow( - required: try FfiConverterUInt64.read(from: &buf) + case 9: return .FeeTooLow( + required: try FfiConverterString.read(from: &buf) ) - case 11: return .FeeRateTooLow( + case 10: return .FeeRateTooLow( required: try FfiConverterString.read(from: &buf) ) - case 12: return .NoUtxosSelected - case 13: return .OutputBelowDustLimit( + case 11: return .NoUtxosSelected + case 12: return .OutputBelowDustLimit( index: try FfiConverterUInt64.read(from: &buf) ) - case 14: return .ChangePolicyDescriptor - case 15: return .CoinSelection( + case 13: return .ChangePolicyDescriptor + case 14: return .CoinSelection( errorMessage: try FfiConverterString.read(from: &buf) ) - case 16: return .InsufficientFunds( + case 15: return .InsufficientFunds( needed: try FfiConverterUInt64.read(from: &buf), available: try FfiConverterUInt64.read(from: &buf) ) - case 17: return .NoRecipients - case 18: return .Psbt( + case 16: return .NoRecipients + case 17: return .Psbt( errorMessage: try FfiConverterString.read(from: &buf) ) - case 19: return .MissingKeyOrigin( + case 18: return .MissingKeyOrigin( key: try FfiConverterString.read(from: &buf) ) - case 20: return .UnknownUtxo( + case 19: return .UnknownUtxo( outpoint: try FfiConverterString.read(from: &buf) ) - case 21: return .MissingNonWitnessUtxo( + case 20: return .MissingNonWitnessUtxo( outpoint: try FfiConverterString.read(from: &buf) ) - case 22: return .MiniscriptPsbt( + case 21: return .MiniscriptPsbt( errorMessage: try FfiConverterString.read(from: &buf) ) @@ -4200,105 +4851,100 @@ public struct FfiConverterTypeCreateTxError: FfiConverterRustBuffer { FfiConverterString.write(errorMessage, into: &buf) - case let .Persist(errorMessage): - writeInt(&buf, Int32(2)) - FfiConverterString.write(errorMessage, into: &buf) - - case let .Policy(errorMessage): - writeInt(&buf, Int32(3)) + writeInt(&buf, Int32(2)) FfiConverterString.write(errorMessage, into: &buf) case let .SpendingPolicyRequired(kind): - writeInt(&buf, Int32(4)) + writeInt(&buf, Int32(3)) FfiConverterString.write(kind, into: &buf) case .Version0: - writeInt(&buf, Int32(5)) + writeInt(&buf, Int32(4)) case .Version1Csv: - writeInt(&buf, Int32(6)) + writeInt(&buf, Int32(5)) case let .LockTime(requested,required): - writeInt(&buf, Int32(7)) + writeInt(&buf, Int32(6)) FfiConverterString.write(requested, into: &buf) FfiConverterString.write(required, into: &buf) case .RbfSequence: - writeInt(&buf, Int32(8)) + writeInt(&buf, Int32(7)) case let .RbfSequenceCsv(rbf,csv): - writeInt(&buf, Int32(9)) + writeInt(&buf, Int32(8)) FfiConverterString.write(rbf, into: &buf) FfiConverterString.write(csv, into: &buf) case let .FeeTooLow(required): - writeInt(&buf, Int32(10)) - FfiConverterUInt64.write(required, into: &buf) + writeInt(&buf, Int32(9)) + FfiConverterString.write(required, into: &buf) case let .FeeRateTooLow(required): - writeInt(&buf, Int32(11)) + writeInt(&buf, Int32(10)) FfiConverterString.write(required, into: &buf) case .NoUtxosSelected: - writeInt(&buf, Int32(12)) + writeInt(&buf, Int32(11)) case let .OutputBelowDustLimit(index): - writeInt(&buf, Int32(13)) + writeInt(&buf, Int32(12)) FfiConverterUInt64.write(index, into: &buf) case .ChangePolicyDescriptor: - writeInt(&buf, Int32(14)) + writeInt(&buf, Int32(13)) case let .CoinSelection(errorMessage): - writeInt(&buf, Int32(15)) + writeInt(&buf, Int32(14)) FfiConverterString.write(errorMessage, into: &buf) case let .InsufficientFunds(needed,available): - writeInt(&buf, Int32(16)) + writeInt(&buf, Int32(15)) FfiConverterUInt64.write(needed, into: &buf) FfiConverterUInt64.write(available, into: &buf) case .NoRecipients: - writeInt(&buf, Int32(17)) + writeInt(&buf, Int32(16)) case let .Psbt(errorMessage): - writeInt(&buf, Int32(18)) + writeInt(&buf, Int32(17)) FfiConverterString.write(errorMessage, into: &buf) case let .MissingKeyOrigin(key): - writeInt(&buf, Int32(19)) + writeInt(&buf, Int32(18)) FfiConverterString.write(key, into: &buf) case let .UnknownUtxo(outpoint): - writeInt(&buf, Int32(20)) + writeInt(&buf, Int32(19)) FfiConverterString.write(outpoint, into: &buf) case let .MissingNonWitnessUtxo(outpoint): - writeInt(&buf, Int32(21)) + writeInt(&buf, Int32(20)) FfiConverterString.write(outpoint, into: &buf) case let .MiniscriptPsbt(errorMessage): - writeInt(&buf, Int32(22)) + writeInt(&buf, Int32(21)) FfiConverterString.write(errorMessage, into: &buf) } @@ -4308,7 +4954,79 @@ public struct FfiConverterTypeCreateTxError: FfiConverterRustBuffer { extension CreateTxError: Equatable, Hashable {} -extension CreateTxError: Error { } +extension CreateTxError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} + + +public enum CreateWithPersistError { + + + + case Persist(errorMessage: String + ) + case DataAlreadyExists + case Descriptor(errorMessage: String + ) +} + + +public struct FfiConverterTypeCreateWithPersistError: FfiConverterRustBuffer { + typealias SwiftType = CreateWithPersistError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CreateWithPersistError { + let variant: Int32 = try readInt(&buf) + switch variant { + + + + + case 1: return .Persist( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 2: return .DataAlreadyExists + case 3: return .Descriptor( + errorMessage: try FfiConverterString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: CreateWithPersistError, into buf: inout [UInt8]) { + switch value { + + + + + + case let .Persist(errorMessage): + writeInt(&buf, Int32(1)) + FfiConverterString.write(errorMessage, into: &buf) + + + case .DataAlreadyExists: + writeInt(&buf, Int32(2)) + + + case let .Descriptor(errorMessage): + writeInt(&buf, Int32(3)) + FfiConverterString.write(errorMessage, into: &buf) + + } + } +} + + +extension CreateWithPersistError: Equatable, Hashable {} + +extension CreateWithPersistError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} public enum DescriptorError { @@ -4319,34 +5037,23 @@ public enum DescriptorError { case InvalidDescriptorChecksum case HardenedDerivationXpub case MultiPath - case Key( - errorMessage: String + case Key(errorMessage: String ) - case Policy( - errorMessage: String + case Policy(errorMessage: String ) - case InvalidDescriptorCharacter( - char: String + case InvalidDescriptorCharacter(char: String ) - case Bip32( - errorMessage: String + case Bip32(errorMessage: String ) - case Base58( - errorMessage: String + case Base58(errorMessage: String ) - case Pk( - errorMessage: String + case Pk(errorMessage: String ) - case Miniscript( - errorMessage: String + case Miniscript(errorMessage: String ) - case Hex( - errorMessage: String + case Hex(errorMessage: String ) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeDescriptorError.lift(error) - } + case ExternalAndInternalAreTheSame } @@ -4388,6 +5095,7 @@ public struct FfiConverterTypeDescriptorError: FfiConverterRustBuffer { case 12: return .Hex( errorMessage: try FfiConverterString.read(from: &buf) ) + case 13: return .ExternalAndInternalAreTheSame default: throw UniffiInternalError.unexpectedEnumCase } @@ -4455,6 +5163,10 @@ public struct FfiConverterTypeDescriptorError: FfiConverterRustBuffer { writeInt(&buf, Int32(12)) FfiConverterString.write(errorMessage, into: &buf) + + case .ExternalAndInternalAreTheSame: + writeInt(&buf, Int32(13)) + } } } @@ -4462,24 +5174,22 @@ public struct FfiConverterTypeDescriptorError: FfiConverterRustBuffer { extension DescriptorError: Equatable, Hashable {} -extension DescriptorError: Error { } +extension DescriptorError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} public enum DescriptorKeyError { - case Parse( - errorMessage: String + case Parse(errorMessage: String ) case InvalidKeyType - case Bip32( - errorMessage: String + case Bip32(errorMessage: String ) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeDescriptorKeyError.lift(error) - } } @@ -4532,54 +5242,44 @@ public struct FfiConverterTypeDescriptorKeyError: FfiConverterRustBuffer { extension DescriptorKeyError: Equatable, Hashable {} -extension DescriptorKeyError: Error { } +extension DescriptorKeyError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} public enum ElectrumError { - case IoError( - errorMessage: String + case IoError(errorMessage: String ) - case Json( - errorMessage: String + case Json(errorMessage: String ) - case Hex( - errorMessage: String + case Hex(errorMessage: String ) - case Protocol( - errorMessage: String + case Protocol(errorMessage: String ) - case Bitcoin( - errorMessage: String + case Bitcoin(errorMessage: String ) case AlreadySubscribed case NotSubscribed - case InvalidResponse( - errorMessage: String + case InvalidResponse(errorMessage: String ) - case Message( - errorMessage: String + case Message(errorMessage: String ) - case InvalidDnsNameError( - domain: String + case InvalidDnsNameError(domain: String ) case MissingDomain case AllAttemptsErrored - case SharedIoError( - errorMessage: String + case SharedIoError(errorMessage: String ) case CouldntLockReader case Mpsc - case CouldNotCreateConnection( - errorMessage: String + case CouldNotCreateConnection(errorMessage: String ) case RequestAlreadyConsumed - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeElectrumError.lift(error) - } } @@ -4726,51 +5426,40 @@ public struct FfiConverterTypeElectrumError: FfiConverterRustBuffer { extension ElectrumError: Equatable, Hashable {} -extension ElectrumError: Error { } +extension ElectrumError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} public enum EsploraError { - case Minreq( - errorMessage: String + case Minreq(errorMessage: String ) - case HttpResponse( - status: UInt16, - errorMessage: String + case HttpResponse(status: UInt16, errorMessage: String ) - case Parsing( - errorMessage: String + case Parsing(errorMessage: String ) - case StatusCode( - errorMessage: String + case StatusCode(errorMessage: String ) - case BitcoinEncoding( - errorMessage: String + case BitcoinEncoding(errorMessage: String ) - case HexToArray( - errorMessage: String + case HexToArray(errorMessage: String ) - case HexToBytes( - errorMessage: String + case HexToBytes(errorMessage: String ) case TransactionNotFound - case HeaderHeightNotFound( - height: UInt32 + case HeaderHeightNotFound(height: UInt32 ) case HeaderHashNotFound - case InvalidHttpHeaderName( - name: String + case InvalidHttpHeaderName(name: String ) - case InvalidHttpHeaderValue( - value: String + case InvalidHttpHeaderValue(value: String ) case RequestAlreadyConsumed - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeEsploraError.lift(error) - } } @@ -4899,23 +5588,22 @@ public struct FfiConverterTypeEsploraError: FfiConverterRustBuffer { extension EsploraError: Equatable, Hashable {} -extension EsploraError: Error { } +extension EsploraError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} public enum ExtractTxError { - case AbsurdFeeRate( - feeRate: UInt64 + case AbsurdFeeRate(feeRate: UInt64 ) case MissingInputValue case SendingTooMuch case OtherExtractTxErr - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeExtractTxError.lift(error) - } } @@ -4970,68 +5658,96 @@ public struct FfiConverterTypeExtractTxError: FfiConverterRustBuffer { extension ExtractTxError: Equatable, Hashable {} -extension ExtractTxError: Error { } +extension ExtractTxError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} -public enum FeeRateError { +public enum FromScriptError { - case ArithmeticOverflow(message: String) - - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeFeeRateError.lift(error) - } + case UnrecognizedScript + case WitnessProgram(errorMessage: String + ) + case WitnessVersion(errorMessage: String + ) + case OtherFromScriptErr } -public struct FfiConverterTypeFeeRateError: FfiConverterRustBuffer { - typealias SwiftType = FeeRateError +public struct FfiConverterTypeFromScriptError: FfiConverterRustBuffer { + typealias SwiftType = FromScriptError - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FeeRateError { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FromScriptError { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return .ArithmeticOverflow( - message: try FfiConverterString.read(from: &buf) - ) - + case 1: return .UnrecognizedScript + case 2: return .WitnessProgram( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 3: return .WitnessVersion( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 4: return .OtherFromScriptErr - default: throw UniffiInternalError.unexpectedEnumCase + default: throw UniffiInternalError.unexpectedEnumCase } } - public static func write(_ value: FeeRateError, into buf: inout [UInt8]) { + public static func write(_ value: FromScriptError, into buf: inout [UInt8]) { switch value { - case .ArithmeticOverflow(_ /* message is ignored*/): + + case .UnrecognizedScript: writeInt(&buf, Int32(1)) - + + + case let .WitnessProgram(errorMessage): + writeInt(&buf, Int32(2)) + FfiConverterString.write(errorMessage, into: &buf) + + + case let .WitnessVersion(errorMessage): + writeInt(&buf, Int32(3)) + FfiConverterString.write(errorMessage, into: &buf) + + + case .OtherFromScriptErr: + writeInt(&buf, Int32(4)) } } } -extension FeeRateError: Equatable, Hashable {} +extension FromScriptError: Equatable, Hashable {} -extension FeeRateError: Error { } +extension FromScriptError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + public enum KeychainKind { case external case `internal` } + public struct FfiConverterTypeKeychainKind: FfiConverterRustBuffer { typealias SwiftType = KeychainKind @@ -5041,244 +5757,480 @@ public struct FfiConverterTypeKeychainKind: FfiConverterRustBuffer { case 1: return .external - case 2: return .`internal` + case 2: return .`internal` + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: KeychainKind, into buf: inout [UInt8]) { + switch value { + + + case .external: + writeInt(&buf, Int32(1)) + + + case .`internal`: + writeInt(&buf, Int32(2)) + + } + } +} + + +public func FfiConverterTypeKeychainKind_lift(_ buf: RustBuffer) throws -> KeychainKind { + return try FfiConverterTypeKeychainKind.lift(buf) +} + +public func FfiConverterTypeKeychainKind_lower(_ value: KeychainKind) -> RustBuffer { + return FfiConverterTypeKeychainKind.lower(value) +} + + + +extension KeychainKind: Equatable, Hashable {} + + + + +public enum LoadWithPersistError { + + + + case Persist(errorMessage: String + ) + case InvalidChangeSet(errorMessage: String + ) + case CouldNotLoad +} + + +public struct FfiConverterTypeLoadWithPersistError: FfiConverterRustBuffer { + typealias SwiftType = LoadWithPersistError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> LoadWithPersistError { + let variant: Int32 = try readInt(&buf) + switch variant { + + + - default: throw UniffiInternalError.unexpectedEnumCase + case 1: return .Persist( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 2: return .InvalidChangeSet( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 3: return .CouldNotLoad + + default: throw UniffiInternalError.unexpectedEnumCase } } - public static func write(_ value: KeychainKind, into buf: inout [UInt8]) { + public static func write(_ value: LoadWithPersistError, into buf: inout [UInt8]) { switch value { + + - case .external: - writeInt(&buf, Int32(1)) + case let .Persist(errorMessage): + writeInt(&buf, Int32(1)) + FfiConverterString.write(errorMessage, into: &buf) + - case .`internal`: + case let .InvalidChangeSet(errorMessage): writeInt(&buf, Int32(2)) + FfiConverterString.write(errorMessage, into: &buf) + + + case .CouldNotLoad: + writeInt(&buf, Int32(3)) } } } -public func FfiConverterTypeKeychainKind_lift(_ buf: RustBuffer) throws -> KeychainKind { - return try FfiConverterTypeKeychainKind.lift(buf) -} +extension LoadWithPersistError: Equatable, Hashable {} -public func FfiConverterTypeKeychainKind_lower(_ value: KeychainKind) -> RustBuffer { - return FfiConverterTypeKeychainKind.lower(value) +extension LoadWithPersistError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } } -extension KeychainKind: Equatable, Hashable {} - - +public enum PersistenceError { -// Note that we don't yet support `indirect` for enums. -// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. -public enum Network { - case bitcoin - case testnet - case signet - case regtest + + case Write(errorMessage: String + ) } -public struct FfiConverterTypeNetwork: FfiConverterRustBuffer { - typealias SwiftType = Network - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Network { +public struct FfiConverterTypePersistenceError: FfiConverterRustBuffer { + typealias SwiftType = PersistenceError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PersistenceError { let variant: Int32 = try readInt(&buf) switch variant { + - case 1: return .bitcoin - - case 2: return .testnet - - case 3: return .signet - - case 4: return .regtest + - default: throw UniffiInternalError.unexpectedEnumCase + case 1: return .Write( + errorMessage: try FfiConverterString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase } } - public static func write(_ value: Network, into buf: inout [UInt8]) { + public static func write(_ value: PersistenceError, into buf: inout [UInt8]) { switch value { + + - case .bitcoin: - writeInt(&buf, Int32(1)) - - - case .testnet: - writeInt(&buf, Int32(2)) - - - case .signet: - writeInt(&buf, Int32(3)) - - - case .regtest: - writeInt(&buf, Int32(4)) + case let .Write(errorMessage): + writeInt(&buf, Int32(1)) + FfiConverterString.write(errorMessage, into: &buf) + } } } -public func FfiConverterTypeNetwork_lift(_ buf: RustBuffer) throws -> Network { - return try FfiConverterTypeNetwork.lift(buf) -} +extension PersistenceError: Equatable, Hashable {} -public func FfiConverterTypeNetwork_lower(_ value: Network) -> RustBuffer { - return FfiConverterTypeNetwork.lower(value) +extension PersistenceError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } } -extension Network: Equatable, Hashable {} - - - - -public enum ParseAmountError { +public enum PsbtError { - case Negative - case TooBig - case TooPrecise - case InvalidFormat - case InputTooLarge - case InvalidCharacter( - errorMessage: String + case InvalidMagic + case MissingUtxo + case InvalidSeparator + case PsbtUtxoOutOfBounds + case InvalidKey(key: String ) - case UnknownDenomination( - errorMessage: String + case InvalidProprietaryKey + case DuplicateKey(key: String ) - case PossiblyConfusingDenomination( - errorMessage: String + case UnsignedTxHasScriptSigs + case UnsignedTxHasScriptWitnesses + case MustHaveUnsignedTx + case NoMorePairs + case UnexpectedUnsignedTx + case NonStandardSighashType(sighash: UInt32 ) - case OtherParseAmountErr - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeParseAmountError.lift(error) - } + case InvalidHash(hash: String + ) + case InvalidPreimageHashPair + case CombineInconsistentKeySources(xpub: String + ) + case ConsensusEncoding(encodingError: String + ) + case NegativeFee + case FeeOverflow + case InvalidPublicKey(errorMessage: String + ) + case InvalidSecp256k1PublicKey(secp256k1Error: String + ) + case InvalidXOnlyPublicKey + case InvalidEcdsaSignature(errorMessage: String + ) + case InvalidTaprootSignature(errorMessage: String + ) + case InvalidControlBlock + case InvalidLeafVersion + case Taproot + case TapTree(errorMessage: String + ) + case XPubKey + case Version(errorMessage: String + ) + case PartialDataConsumption + case Io(errorMessage: String + ) + case OtherPsbtErr } -public struct FfiConverterTypeParseAmountError: FfiConverterRustBuffer { - typealias SwiftType = ParseAmountError +public struct FfiConverterTypePsbtError: FfiConverterRustBuffer { + typealias SwiftType = PsbtError - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ParseAmountError { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PsbtError { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return .Negative - case 2: return .TooBig - case 3: return .TooPrecise - case 4: return .InvalidFormat - case 5: return .InputTooLarge - case 6: return .InvalidCharacter( + case 1: return .InvalidMagic + case 2: return .MissingUtxo + case 3: return .InvalidSeparator + case 4: return .PsbtUtxoOutOfBounds + case 5: return .InvalidKey( + key: try FfiConverterString.read(from: &buf) + ) + case 6: return .InvalidProprietaryKey + case 7: return .DuplicateKey( + key: try FfiConverterString.read(from: &buf) + ) + case 8: return .UnsignedTxHasScriptSigs + case 9: return .UnsignedTxHasScriptWitnesses + case 10: return .MustHaveUnsignedTx + case 11: return .NoMorePairs + case 12: return .UnexpectedUnsignedTx + case 13: return .NonStandardSighashType( + sighash: try FfiConverterUInt32.read(from: &buf) + ) + case 14: return .InvalidHash( + hash: try FfiConverterString.read(from: &buf) + ) + case 15: return .InvalidPreimageHashPair + case 16: return .CombineInconsistentKeySources( + xpub: try FfiConverterString.read(from: &buf) + ) + case 17: return .ConsensusEncoding( + encodingError: try FfiConverterString.read(from: &buf) + ) + case 18: return .NegativeFee + case 19: return .FeeOverflow + case 20: return .InvalidPublicKey( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 21: return .InvalidSecp256k1PublicKey( + secp256k1Error: try FfiConverterString.read(from: &buf) + ) + case 22: return .InvalidXOnlyPublicKey + case 23: return .InvalidEcdsaSignature( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 24: return .InvalidTaprootSignature( errorMessage: try FfiConverterString.read(from: &buf) ) - case 7: return .UnknownDenomination( + case 25: return .InvalidControlBlock + case 26: return .InvalidLeafVersion + case 27: return .Taproot + case 28: return .TapTree( errorMessage: try FfiConverterString.read(from: &buf) ) - case 8: return .PossiblyConfusingDenomination( + case 29: return .XPubKey + case 30: return .Version( errorMessage: try FfiConverterString.read(from: &buf) ) - case 9: return .OtherParseAmountErr + case 31: return .PartialDataConsumption + case 32: return .Io( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 33: return .OtherPsbtErr default: throw UniffiInternalError.unexpectedEnumCase } } - public static func write(_ value: ParseAmountError, into buf: inout [UInt8]) { + public static func write(_ value: PsbtError, into buf: inout [UInt8]) { switch value { - case .Negative: + case .InvalidMagic: writeInt(&buf, Int32(1)) - case .TooBig: + case .MissingUtxo: writeInt(&buf, Int32(2)) - case .TooPrecise: + case .InvalidSeparator: writeInt(&buf, Int32(3)) - case .InvalidFormat: + case .PsbtUtxoOutOfBounds: writeInt(&buf, Int32(4)) - case .InputTooLarge: + case let .InvalidKey(key): writeInt(&buf, Int32(5)) + FfiConverterString.write(key, into: &buf) + - - case let .InvalidCharacter(errorMessage): + case .InvalidProprietaryKey: writeInt(&buf, Int32(6)) + + + case let .DuplicateKey(key): + writeInt(&buf, Int32(7)) + FfiConverterString.write(key, into: &buf) + + + case .UnsignedTxHasScriptSigs: + writeInt(&buf, Int32(8)) + + + case .UnsignedTxHasScriptWitnesses: + writeInt(&buf, Int32(9)) + + + case .MustHaveUnsignedTx: + writeInt(&buf, Int32(10)) + + + case .NoMorePairs: + writeInt(&buf, Int32(11)) + + + case .UnexpectedUnsignedTx: + writeInt(&buf, Int32(12)) + + + case let .NonStandardSighashType(sighash): + writeInt(&buf, Int32(13)) + FfiConverterUInt32.write(sighash, into: &buf) + + + case let .InvalidHash(hash): + writeInt(&buf, Int32(14)) + FfiConverterString.write(hash, into: &buf) + + + case .InvalidPreimageHashPair: + writeInt(&buf, Int32(15)) + + + case let .CombineInconsistentKeySources(xpub): + writeInt(&buf, Int32(16)) + FfiConverterString.write(xpub, into: &buf) + + + case let .ConsensusEncoding(encodingError): + writeInt(&buf, Int32(17)) + FfiConverterString.write(encodingError, into: &buf) + + + case .NegativeFee: + writeInt(&buf, Int32(18)) + + + case .FeeOverflow: + writeInt(&buf, Int32(19)) + + + case let .InvalidPublicKey(errorMessage): + writeInt(&buf, Int32(20)) FfiConverterString.write(errorMessage, into: &buf) - case let .UnknownDenomination(errorMessage): - writeInt(&buf, Int32(7)) + case let .InvalidSecp256k1PublicKey(secp256k1Error): + writeInt(&buf, Int32(21)) + FfiConverterString.write(secp256k1Error, into: &buf) + + + case .InvalidXOnlyPublicKey: + writeInt(&buf, Int32(22)) + + + case let .InvalidEcdsaSignature(errorMessage): + writeInt(&buf, Int32(23)) FfiConverterString.write(errorMessage, into: &buf) - case let .PossiblyConfusingDenomination(errorMessage): - writeInt(&buf, Int32(8)) + case let .InvalidTaprootSignature(errorMessage): + writeInt(&buf, Int32(24)) FfiConverterString.write(errorMessage, into: &buf) - case .OtherParseAmountErr: - writeInt(&buf, Int32(9)) + case .InvalidControlBlock: + writeInt(&buf, Int32(25)) + + + case .InvalidLeafVersion: + writeInt(&buf, Int32(26)) + + + case .Taproot: + writeInt(&buf, Int32(27)) + + + case let .TapTree(errorMessage): + writeInt(&buf, Int32(28)) + FfiConverterString.write(errorMessage, into: &buf) + + + case .XPubKey: + writeInt(&buf, Int32(29)) + + + case let .Version(errorMessage): + writeInt(&buf, Int32(30)) + FfiConverterString.write(errorMessage, into: &buf) + + + case .PartialDataConsumption: + writeInt(&buf, Int32(31)) + + + case let .Io(errorMessage): + writeInt(&buf, Int32(32)) + FfiConverterString.write(errorMessage, into: &buf) + + + case .OtherPsbtErr: + writeInt(&buf, Int32(33)) } } } -extension ParseAmountError: Equatable, Hashable {} +extension PsbtError: Equatable, Hashable {} -extension ParseAmountError: Error { } +extension PsbtError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} -public enum PersistenceError { +public enum PsbtParseError { - case Write( - errorMessage: String + case PsbtEncoding(errorMessage: String + ) + case Base64Encoding(errorMessage: String ) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypePersistenceError.lift(error) - } } -public struct FfiConverterTypePersistenceError: FfiConverterRustBuffer { - typealias SwiftType = PersistenceError +public struct FfiConverterTypePsbtParseError: FfiConverterRustBuffer { + typealias SwiftType = PsbtParseError - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PersistenceError { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PsbtParseError { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return .Write( + case 1: return .PsbtEncoding( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 2: return .Base64Encoding( errorMessage: try FfiConverterString.read(from: &buf) ) @@ -5286,89 +6238,82 @@ public struct FfiConverterTypePersistenceError: FfiConverterRustBuffer { } } - public static func write(_ value: PersistenceError, into buf: inout [UInt8]) { + public static func write(_ value: PsbtParseError, into buf: inout [UInt8]) { switch value { - case let .Write(errorMessage): + case let .PsbtEncoding(errorMessage): writeInt(&buf, Int32(1)) FfiConverterString.write(errorMessage, into: &buf) + + case let .Base64Encoding(errorMessage): + writeInt(&buf, Int32(2)) + FfiConverterString.write(errorMessage, into: &buf) + } } } -extension PersistenceError: Equatable, Hashable {} +extension PsbtParseError: Equatable, Hashable {} -extension PersistenceError: Error { } +extension PsbtParseError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} -public enum PsbtParseError { +public enum RequestBuilderError { - case PsbtEncoding( - errorMessage: String - ) - case Base64Encoding( - errorMessage: String - ) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypePsbtParseError.lift(error) - } + case RequestAlreadyConsumed } -public struct FfiConverterTypePsbtParseError: FfiConverterRustBuffer { - typealias SwiftType = PsbtParseError +public struct FfiConverterTypeRequestBuilderError: FfiConverterRustBuffer { + typealias SwiftType = RequestBuilderError - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PsbtParseError { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RequestBuilderError { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return .PsbtEncoding( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 2: return .Base64Encoding( - errorMessage: try FfiConverterString.read(from: &buf) - ) + case 1: return .RequestAlreadyConsumed default: throw UniffiInternalError.unexpectedEnumCase } } - public static func write(_ value: PsbtParseError, into buf: inout [UInt8]) { + public static func write(_ value: RequestBuilderError, into buf: inout [UInt8]) { switch value { - case let .PsbtEncoding(errorMessage): + case .RequestAlreadyConsumed: writeInt(&buf, Int32(1)) - FfiConverterString.write(errorMessage, into: &buf) - - case let .Base64Encoding(errorMessage): - writeInt(&buf, Int32(2)) - FfiConverterString.write(errorMessage, into: &buf) - } } } -extension PsbtParseError: Equatable, Hashable {} +extension RequestBuilderError: Equatable, Hashable {} -extension PsbtParseError: Error { } +extension RequestBuilderError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} public enum SignerError { @@ -5386,19 +6331,18 @@ public enum SignerError { case MissingHdKeypath case NonStandardSighash case InvalidSighash - case SighashError( - errorMessage: String + case SighashP2wpkh(errorMessage: String ) - case MiniscriptPsbt( - errorMessage: String + case SighashTaproot(errorMessage: String ) - case External( - errorMessage: String + case TxInputsIndexError(errorMessage: String + ) + case MiniscriptPsbt(errorMessage: String + ) + case External(errorMessage: String + ) + case Psbt(errorMessage: String ) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeSignerError.lift(error) - } } @@ -5423,13 +6367,22 @@ public struct FfiConverterTypeSignerError: FfiConverterRustBuffer { case 9: return .MissingHdKeypath case 10: return .NonStandardSighash case 11: return .InvalidSighash - case 12: return .SighashError( + case 12: return .SighashP2wpkh( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 13: return .SighashTaproot( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 14: return .TxInputsIndexError( + errorMessage: try FfiConverterString.read(from: &buf) + ) + case 15: return .MiniscriptPsbt( errorMessage: try FfiConverterString.read(from: &buf) ) - case 13: return .MiniscriptPsbt( + case 16: return .External( errorMessage: try FfiConverterString.read(from: &buf) ) - case 14: return .External( + case 17: return .Psbt( errorMessage: try FfiConverterString.read(from: &buf) ) @@ -5488,18 +6441,33 @@ public struct FfiConverterTypeSignerError: FfiConverterRustBuffer { writeInt(&buf, Int32(11)) - case let .SighashError(errorMessage): - writeInt(&buf, Int32(12)) + case let .SighashP2wpkh(errorMessage): + writeInt(&buf, Int32(12)) + FfiConverterString.write(errorMessage, into: &buf) + + + case let .SighashTaproot(errorMessage): + writeInt(&buf, Int32(13)) + FfiConverterString.write(errorMessage, into: &buf) + + + case let .TxInputsIndexError(errorMessage): + writeInt(&buf, Int32(14)) FfiConverterString.write(errorMessage, into: &buf) case let .MiniscriptPsbt(errorMessage): - writeInt(&buf, Int32(13)) + writeInt(&buf, Int32(15)) FfiConverterString.write(errorMessage, into: &buf) case let .External(errorMessage): - writeInt(&buf, Int32(14)) + writeInt(&buf, Int32(16)) + FfiConverterString.write(errorMessage, into: &buf) + + + case let .Psbt(errorMessage): + writeInt(&buf, Int32(17)) FfiConverterString.write(errorMessage, into: &buf) } @@ -5509,7 +6477,63 @@ public struct FfiConverterTypeSignerError: FfiConverterRustBuffer { extension SignerError: Equatable, Hashable {} -extension SignerError: Error { } +extension SignerError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} + + +public enum SqliteError { + + + + case Sqlite(rusqliteError: String + ) +} + + +public struct FfiConverterTypeSqliteError: FfiConverterRustBuffer { + typealias SwiftType = SqliteError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SqliteError { + let variant: Int32 = try readInt(&buf) + switch variant { + + + + + case 1: return .Sqlite( + rusqliteError: try FfiConverterString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: SqliteError, into buf: inout [UInt8]) { + switch value { + + + + + + case let .Sqlite(rusqliteError): + writeInt(&buf, Int32(1)) + FfiConverterString.write(rusqliteError, into: &buf) + + } + } +} + + +extension SqliteError: Equatable, Hashable {} + +extension SqliteError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} public enum TransactionError { @@ -5518,20 +6542,13 @@ public enum TransactionError { case Io case OversizedVectorAllocation - case InvalidChecksum( - expected: String, - actual: String + case InvalidChecksum(expected: String, actual: String ) case NonMinimalVarInt case ParseFailed - case UnsupportedSegwitFlag( - flag: UInt8 + case UnsupportedSegwitFlag(flag: UInt8 ) case OtherTransactionErr - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeTransactionError.lift(error) - } } @@ -5606,20 +6623,19 @@ public struct FfiConverterTypeTransactionError: FfiConverterRustBuffer { extension TransactionError: Equatable, Hashable {} -extension TransactionError: Error { } +extension TransactionError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} public enum TxidParseError { - case InvalidTxid( - txid: String + case InvalidTxid(txid: String ) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeTxidParseError.lift(error) - } } @@ -5659,142 +6675,15 @@ public struct FfiConverterTypeTxidParseError: FfiConverterRustBuffer { extension TxidParseError: Equatable, Hashable {} -extension TxidParseError: Error { } - - -public enum WalletCreationError { - - - - case Io( - errorMessage: String - ) - case InvalidMagicBytes( - got: [UInt8], - expected: [UInt8] - ) - case Descriptor - case Persist( - errorMessage: String - ) - case NotInitialized - case LoadedGenesisDoesNotMatch( - expected: String, - got: String - ) - case LoadedNetworkDoesNotMatch( - expected: Network, - got: Network? - ) - case LoadedDescriptorDoesNotMatch( - got: String, - keychain: KeychainKind - ) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeWalletCreationError.lift(error) - } -} - - -public struct FfiConverterTypeWalletCreationError: FfiConverterRustBuffer { - typealias SwiftType = WalletCreationError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> WalletCreationError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .Io( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 2: return .InvalidMagicBytes( - got: try FfiConverterSequenceUInt8.read(from: &buf), - expected: try FfiConverterSequenceUInt8.read(from: &buf) - ) - case 3: return .Descriptor - case 4: return .Persist( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 5: return .NotInitialized - case 6: return .LoadedGenesisDoesNotMatch( - expected: try FfiConverterString.read(from: &buf), - got: try FfiConverterString.read(from: &buf) - ) - case 7: return .LoadedNetworkDoesNotMatch( - expected: try FfiConverterTypeNetwork.read(from: &buf), - got: try FfiConverterOptionTypeNetwork.read(from: &buf) - ) - case 8: return .LoadedDescriptorDoesNotMatch( - got: try FfiConverterString.read(from: &buf), - keychain: try FfiConverterTypeKeychainKind.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: WalletCreationError, into buf: inout [UInt8]) { - switch value { - - - - - - case let .Io(errorMessage): - writeInt(&buf, Int32(1)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .InvalidMagicBytes(got,expected): - writeInt(&buf, Int32(2)) - FfiConverterSequenceUInt8.write(got, into: &buf) - FfiConverterSequenceUInt8.write(expected, into: &buf) - - - case .Descriptor: - writeInt(&buf, Int32(3)) - - - case let .Persist(errorMessage): - writeInt(&buf, Int32(4)) - FfiConverterString.write(errorMessage, into: &buf) - - - case .NotInitialized: - writeInt(&buf, Int32(5)) - - - case let .LoadedGenesisDoesNotMatch(expected,got): - writeInt(&buf, Int32(6)) - FfiConverterString.write(expected, into: &buf) - FfiConverterString.write(got, into: &buf) - - - case let .LoadedNetworkDoesNotMatch(expected,got): - writeInt(&buf, Int32(7)) - FfiConverterTypeNetwork.write(expected, into: &buf) - FfiConverterOptionTypeNetwork.write(got, into: &buf) - - - case let .LoadedDescriptorDoesNotMatch(got,keychain): - writeInt(&buf, Int32(8)) - FfiConverterString.write(got, into: &buf) - FfiConverterTypeKeychainKind.write(keychain, into: &buf) - - } +extension TxidParseError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) } } - -extension WalletCreationError: Equatable, Hashable {} - -extension WalletCreationError: Error { } - // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + public enum WordCount { case words12 @@ -5804,6 +6693,7 @@ public enum WordCount { case words24 } + public struct FfiConverterTypeWordCount: FfiConverterRustBuffer { typealias SwiftType = WordCount @@ -5862,12 +6752,13 @@ public func FfiConverterTypeWordCount_lower(_ value: WordCount) -> RustBuffer { } + extension WordCount: Equatable, Hashable {} -fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { - typealias SwiftType = String? +fileprivate struct FfiConverterOptionUInt32: FfiConverterRustBuffer { + typealias SwiftType = UInt32? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { guard let value = value else { @@ -5875,20 +6766,20 @@ fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { return } writeInt(&buf, Int8(1)) - FfiConverterString.write(value, into: &buf) + FfiConverterUInt32.write(value, into: &buf) } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { switch try readInt(&buf) as Int8 { case 0: return nil - case 1: return try FfiConverterString.read(from: &buf) + case 1: return try FfiConverterUInt32.read(from: &buf) default: throw UniffiInternalError.unexpectedOptionalTag } } } -fileprivate struct FfiConverterOptionTypeDescriptor: FfiConverterRustBuffer { - typealias SwiftType = Descriptor? +fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { + typealias SwiftType = String? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { guard let value = value else { @@ -5896,13 +6787,13 @@ fileprivate struct FfiConverterOptionTypeDescriptor: FfiConverterRustBuffer { return } writeInt(&buf, Int8(1)) - FfiConverterTypeDescriptor.write(value, into: &buf) + FfiConverterString.write(value, into: &buf) } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { switch try readInt(&buf) as Int8 { case 0: return nil - case 1: return try FfiConverterTypeDescriptor.read(from: &buf) + case 1: return try FfiConverterString.read(from: &buf) default: throw UniffiInternalError.unexpectedOptionalTag } } @@ -5929,27 +6820,6 @@ fileprivate struct FfiConverterOptionTypeCanonicalTx: FfiConverterRustBuffer { } } -fileprivate struct FfiConverterOptionTypeNetwork: FfiConverterRustBuffer { - typealias SwiftType = Network? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterTypeNetwork.write(value, into: &buf) - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - switch try readInt(&buf) as Int8 { - case 0: return nil - case 1: return try FfiConverterTypeNetwork.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - fileprivate struct FfiConverterSequenceUInt8: FfiConverterRustBuffer { typealias SwiftType = [UInt8] @@ -6016,28 +6886,6 @@ fileprivate struct FfiConverterSequenceTypeLocalOutput: FfiConverterRustBuffer { } } -fileprivate struct FfiConverterSequenceTypeOutPoint: FfiConverterRustBuffer { - typealias SwiftType = [OutPoint] - - public static func write(_ value: [OutPoint], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterTypeOutPoint.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [OutPoint] { - let len: Int32 = try readInt(&buf) - var seq = [OutPoint]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterTypeOutPoint.read(from: &buf)) - } - return seq - } -} - fileprivate struct FfiConverterSequenceTypeScriptAmount: FfiConverterRustBuffer { typealias SwiftType = [ScriptAmount] @@ -6126,42 +6974,62 @@ fileprivate struct FfiConverterSequenceSequenceUInt8: FfiConverterRustBuffer { } } +fileprivate struct FfiConverterSequenceTypeOutPoint: FfiConverterRustBuffer { + typealias SwiftType = [OutPoint] + + public static func write(_ value: [OutPoint], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterTypeOutPoint.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [OutPoint] { + let len: Int32 = try readInt(&buf) + var seq = [OutPoint]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeOutPoint.read(from: &buf)) + } + return seq + } +} + + + + + + + + + + + private enum InitializationResult { case ok case contractVersionMismatch case apiChecksumMismatch } -// Use a global variables to perform the versioning checks. Swift ensures that +// Use a global variable to perform the versioning checks. Swift ensures that // the code inside is only computed once. -private var initializationResult: InitializationResult { +private var initializationResult: InitializationResult = { // Get the bindings contract version from our ComponentInterface - let bindings_contract_version = 25 + let bindings_contract_version = 26 // Get the scaffolding contract version by calling the into the dylib let scaffolding_contract_version = ffi_bdkffi_uniffi_contract_version() if bindings_contract_version != scaffolding_contract_version { return InitializationResult.contractVersionMismatch } - if (uniffi_bdkffi_checksum_method_address_as_string() != 26179) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_address_is_valid_for_network() != 10350) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_address_network() != 33317) { + if (uniffi_bdkffi_checksum_method_address_is_valid_for_network() != 2364) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_address_script_pubkey() != 10722) { + if (uniffi_bdkffi_checksum_method_address_script_pubkey() != 5809) { return InitializationResult.apiChecksumMismatch } if (uniffi_bdkffi_checksum_method_address_to_qr_uri() != 48141) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_amount_to_btc() != 52662) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_amount_to_sat() != 54936) { - return InitializationResult.apiChecksumMismatch - } if (uniffi_bdkffi_checksum_method_bumpfeetxbuilder_enable_rbf() != 30060) { return InitializationResult.apiChecksumMismatch } @@ -6171,10 +7039,7 @@ private var initializationResult: InitializationResult { if (uniffi_bdkffi_checksum_method_bumpfeetxbuilder_finish() != 18299) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_descriptor_as_string() != 23756) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_descriptor_as_string_private() != 64930) { + if (uniffi_bdkffi_checksum_method_descriptor_to_string_with_secret() != 18986) { return InitializationResult.apiChecksumMismatch } if (uniffi_bdkffi_checksum_method_descriptorpublickey_as_string() != 37256) { @@ -6219,25 +7084,40 @@ private var initializationResult: InitializationResult { if (uniffi_bdkffi_checksum_method_esploraclient_sync() != 39911) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_feerate_to_sat_per_kwu() != 2433) { + if (uniffi_bdkffi_checksum_method_fullscanrequestbuilder_build() != 56245) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_feerate_to_sat_per_vb_ceil() != 21019) { + if (uniffi_bdkffi_checksum_method_fullscanrequestbuilder_inspect_spks_for_all_keychains() != 6853) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_feerate_to_sat_per_vb_floor() != 54438) { + if (uniffi_bdkffi_checksum_method_fullscanscriptinspector_inspect() != 62348) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_mnemonic_as_string() != 3181) { + if (uniffi_bdkffi_checksum_method_psbt_combine() != 42218) { return InitializationResult.apiChecksumMismatch } if (uniffi_bdkffi_checksum_method_psbt_extract_tx() != 60519) { return InitializationResult.apiChecksumMismatch } + if (uniffi_bdkffi_checksum_method_psbt_fee() != 48877) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bdkffi_checksum_method_psbt_json_serialize() != 9611) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_bdkffi_checksum_method_psbt_serialize() != 33309) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_script_to_bytes() != 31368) { + if (uniffi_bdkffi_checksum_method_syncrequestbuilder_build() != 38954) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bdkffi_checksum_method_syncrequestbuilder_inspect_spks() != 33029) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bdkffi_checksum_method_syncscriptinspector_inspect() != 32429) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bdkffi_checksum_method_transaction_compute_txid() != 46504) { return InitializationResult.apiChecksumMismatch } if (uniffi_bdkffi_checksum_method_transaction_input() != 5374) { @@ -6264,9 +7144,6 @@ private var initializationResult: InitializationResult { if (uniffi_bdkffi_checksum_method_transaction_total_size() != 12759) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_transaction_txid() != 29904) { - return InitializationResult.apiChecksumMismatch - } if (uniffi_bdkffi_checksum_method_transaction_version() != 15271) { return InitializationResult.apiChecksumMismatch } @@ -6276,13 +7153,16 @@ private var initializationResult: InitializationResult { if (uniffi_bdkffi_checksum_method_transaction_weight() != 21879) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_txbuilder_add_recipient() != 2935) { + if (uniffi_bdkffi_checksum_method_txbuilder_add_global_xpubs() != 61114) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bdkffi_checksum_method_txbuilder_add_recipient() != 20490) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_txbuilder_add_unspendable() != 33319) { + if (uniffi_bdkffi_checksum_method_txbuilder_add_unspendable() != 14416) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_txbuilder_add_utxo() != 43637) { + if (uniffi_bdkffi_checksum_method_txbuilder_add_utxo() != 14001) { return InitializationResult.apiChecksumMismatch } if (uniffi_bdkffi_checksum_method_txbuilder_change_policy() != 22333) { @@ -6291,7 +7171,7 @@ private var initializationResult: InitializationResult { if (uniffi_bdkffi_checksum_method_txbuilder_do_not_spend_change() != 51770) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_txbuilder_drain_to() != 21128) { + if (uniffi_bdkffi_checksum_method_txbuilder_drain_to() != 29829) { return InitializationResult.apiChecksumMismatch } if (uniffi_bdkffi_checksum_method_txbuilder_drain_wallet() != 5081) { @@ -6303,10 +7183,10 @@ private var initializationResult: InitializationResult { if (uniffi_bdkffi_checksum_method_txbuilder_enable_rbf_with_sequence() != 26979) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_txbuilder_fee_absolute() != 59649) { + if (uniffi_bdkffi_checksum_method_txbuilder_fee_absolute() != 28626) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_txbuilder_fee_rate() != 60371) { + if (uniffi_bdkffi_checksum_method_txbuilder_fee_rate() != 49200) { return InitializationResult.apiChecksumMismatch } if (uniffi_bdkffi_checksum_method_txbuilder_finish() != 61082) { @@ -6321,28 +7201,28 @@ private var initializationResult: InitializationResult { if (uniffi_bdkffi_checksum_method_txbuilder_set_recipients() != 20461) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_txbuilder_unspendable() != 49004) { + if (uniffi_bdkffi_checksum_method_txbuilder_unspendable() != 49896) { return InitializationResult.apiChecksumMismatch } if (uniffi_bdkffi_checksum_method_wallet_apply_update() != 65428) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_wallet_calculate_fee() != 34670) { + if (uniffi_bdkffi_checksum_method_wallet_balance() != 32173) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_wallet_calculate_fee_rate() != 61555) { + if (uniffi_bdkffi_checksum_method_wallet_calculate_fee() != 39344) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_wallet_commit() != 59082) { + if (uniffi_bdkffi_checksum_method_wallet_calculate_fee_rate() != 23373) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_wallet_get_balance() != 41846) { + if (uniffi_bdkffi_checksum_method_wallet_derivation_index() != 63084) { return InitializationResult.apiChecksumMismatch } if (uniffi_bdkffi_checksum_method_wallet_get_tx() != 59450) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_wallet_is_mine() != 10423) { + if (uniffi_bdkffi_checksum_method_wallet_is_mine() != 36368) { return InitializationResult.apiChecksumMismatch } if (uniffi_bdkffi_checksum_method_wallet_list_output() != 27359) { @@ -6351,10 +7231,13 @@ private var initializationResult: InitializationResult { if (uniffi_bdkffi_checksum_method_wallet_list_unspent() != 25643) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_wallet_network() != 32197) { + if (uniffi_bdkffi_checksum_method_wallet_network() != 21775) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_bdkffi_checksum_method_wallet_persist() != 14909) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_wallet_reveal_next_address() != 53719) { + if (uniffi_bdkffi_checksum_method_wallet_reveal_next_address() != 54031) { return InitializationResult.apiChecksumMismatch } if (uniffi_bdkffi_checksum_method_wallet_sent_and_received() != 15077) { @@ -6363,108 +7246,104 @@ private var initializationResult: InitializationResult { if (uniffi_bdkffi_checksum_method_wallet_sign() != 15606) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_wallet_start_full_scan() != 18134) { + if (uniffi_bdkffi_checksum_method_wallet_start_full_scan() != 3023) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_method_wallet_start_sync_with_revealed_spks() != 64824) { + if (uniffi_bdkffi_checksum_method_wallet_start_sync_with_revealed_spks() != 41977) { return InitializationResult.apiChecksumMismatch } if (uniffi_bdkffi_checksum_method_wallet_transactions() != 37950) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_address_new() != 45929) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_amount_from_btc() != 13049) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_amount_from_sat() != 52691) { + if (uniffi_bdkffi_checksum_constructor_address_from_script() != 28697) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_bumpfeetxbuilder_new() != 4758) { + if (uniffi_bdkffi_checksum_constructor_address_new() != 42937) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_derivationpath_new() != 24471) { + if (uniffi_bdkffi_checksum_constructor_bumpfeetxbuilder_new() != 33618) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_descriptor_new() != 56307) { + if (uniffi_bdkffi_checksum_constructor_connection_new() != 59352) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip44() != 46337) { + if (uniffi_bdkffi_checksum_constructor_connection_new_in_memory() != 31408) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip44_public() != 54845) { + if (uniffi_bdkffi_checksum_constructor_derivationpath_new() != 6139) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip49() != 56932) { + if (uniffi_bdkffi_checksum_constructor_descriptor_new() != 64471) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip49_public() != 16380) { + if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip44() != 56381) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip84() != 41357) { + if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip44_public() != 7263) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip84_public() != 3965) { + if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip49() != 38651) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip86() != 19316) { + if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip49_public() != 34965) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip86_public() != 48565) { + if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip84() != 48402) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_descriptorpublickey_from_string() != 20475) { + if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip84_public() != 13927) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_descriptorsecretkey_from_string() != 51341) { + if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip86() != 30427) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_descriptorsecretkey_new() != 47131) { + if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip86_public() != 14236) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_electrumclient_new() != 28947) { + if (uniffi_bdkffi_checksum_constructor_descriptorpublickey_from_string() != 34928) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_esploraclient_new() != 45557) { + if (uniffi_bdkffi_checksum_constructor_descriptorsecretkey_from_string() != 56519) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_feerate_from_sat_per_kwu() != 60699) { + if (uniffi_bdkffi_checksum_constructor_descriptorsecretkey_new() != 29746) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_feerate_from_sat_per_vb() != 50427) { + if (uniffi_bdkffi_checksum_constructor_electrumclient_new() != 10238) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_mnemonic_from_entropy() != 57762) { + if (uniffi_bdkffi_checksum_constructor_esploraclient_new() != 19298) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_mnemonic_from_string() != 41785) { + if (uniffi_bdkffi_checksum_constructor_mnemonic_from_entropy() != 16992) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_mnemonic_new() != 26468) { + if (uniffi_bdkffi_checksum_constructor_mnemonic_from_string() != 56187) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_psbt_new() != 58680) { + if (uniffi_bdkffi_checksum_constructor_mnemonic_new() != 51578) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_script_new() != 36370) { + if (uniffi_bdkffi_checksum_constructor_psbt_new() != 33069) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_transaction_new() != 45575) { + if (uniffi_bdkffi_checksum_constructor_transaction_new() != 58769) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_txbuilder_new() != 978) { + if (uniffi_bdkffi_checksum_constructor_txbuilder_new() != 6280) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_wallet_new() != 64341) { + if (uniffi_bdkffi_checksum_constructor_wallet_load() != 21717) { return InitializationResult.apiChecksumMismatch } - if (uniffi_bdkffi_checksum_constructor_wallet_new_no_persist() != 44289) { + if (uniffi_bdkffi_checksum_constructor_wallet_new() != 51039) { return InitializationResult.apiChecksumMismatch } + uniffiCallbackInitFullScanScriptInspector() + uniffiCallbackInitSyncScriptInspector() return InitializationResult.ok -} +}() private func uniffiEnsureInitialized() { switch initializationResult { @@ -6475,4 +7354,6 @@ private func uniffiEnsureInitialized() { case .apiChecksumMismatch: fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } -} \ No newline at end of file +} + +// swiftlint:enable all \ No newline at end of file