From af1d605ffdddf322b431ae5e4ccdbfd345ebd75f Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Sat, 9 Nov 2024 00:50:00 -0600 Subject: [PATCH] ci: update scripts to build xcframework --- .github/workflows/publish-spm.yaml | 6 +- Package.swift | 36 - Sources/BitcoinDevKit/Bitcoin.swift | 1223 ---- Sources/BitcoinDevKit/BitcoinDevKit.swift | 7629 --------------------- 4 files changed, 2 insertions(+), 8892 deletions(-) delete mode 100644 Package.swift delete mode 100644 Sources/BitcoinDevKit/Bitcoin.swift delete mode 100644 Sources/BitcoinDevKit/BitcoinDevKit.swift diff --git a/.github/workflows/publish-spm.yaml b/.github/workflows/publish-spm.yaml index fafb143..5348419 100644 --- a/.github/workflows/publish-spm.yaml +++ b/.github/workflows/publish-spm.yaml @@ -35,7 +35,7 @@ jobs: ./build-xcframework.sh # remove old xcframework zip rm bdkFFI.xcframework.zip || true - zip -9 -r bdkFFI.xcframework.zip bdkFFI.xcframework + zip -9 -r bdkFFI.xcframework.zip bdkffi.xcframework echo "BDKFFICHECKSUM=`swift package compute-checksum bdkFFI.xcframework.zip`" >> $GITHUB_ENV echo "BDKFFIURL=https\:\/\/github\.com\/${{ github.repository_owner }}\/bdk\-swift\/releases\/download\/${{ inputs.version }}\/bdkFFI\.xcframework\.zip" >> $GITHUB_ENV @@ -45,11 +45,9 @@ jobs: echo checksum = ${{ env.BDKFFICHECKSUM }} echo url = ${{ env.BDKFFIURL }} sed "s/BDKFFICHECKSUM/${BDKFFICHECKSUM}/;s/BDKFFIURL/${BDKFFIURL}/" Package.swift.txt > ../../dist/Package.swift - cp Sources/BitcoinDevKit/BitcoinDevKit.swift ../../dist/Sources/BitcoinDevKit/BitcoinDevKit.swift - cp Sources/BitcoinDevKit/Bitcoin.swift ../../dist/Sources/BitcoinDevKit/Bitcoin.swift + cp Sources/BitcoinDevKit/bdk.swift ../../dist/Sources/BitcoinDevKit/BitcoinDevKit.swift cd ../../dist git add Sources/BitcoinDevKit/BitcoinDevKit.swift - git add Sources/BitcoinDevKit/Bitcoin.swift git add Package.swift git commit -m "Update BitcoinDevKit.swift and Package.swift for release ${{ inputs.version }}" git push diff --git a/Package.swift b/Package.swift deleted file mode 100644 index ffd9978..0000000 --- a/Package.swift +++ /dev/null @@ -1,36 +0,0 @@ -// swift-tools-version:5.5 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -let package = Package( - name: "bdk-swift", - platforms: [ - .macOS(.v12), - .iOS(.v15) - ], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "BitcoinDevKit", - targets: ["bdkFFI", "BitcoinDevKit"]), - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - // .package(url: /* package url */, from: "1.0.0"), - ], - targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // 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-beta.5/bdkFFI.xcframework.zip", - checksum: "0cced9d10e2bc110724e796875e883dc3458d402480856002eedab14b0ca7b00"), - .target( - name: "BitcoinDevKit", - dependencies: ["bdkFFI"]), - .testTarget( - name: "BitcoinDevKitTests", - dependencies: ["BitcoinDevKit"]), - ] -) diff --git a/Sources/BitcoinDevKit/Bitcoin.swift b/Sources/BitcoinDevKit/Bitcoin.swift deleted file mode 100644 index 4a6b79a..0000000 --- a/Sources/BitcoinDevKit/Bitcoin.swift +++ /dev/null @@ -1,1223 +0,0 @@ -// 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 deleted file mode 100644 index 814e717..0000000 --- a/Sources/BitcoinDevKit/BitcoinDevKit.swift +++ /dev/null @@ -1,7629 +0,0 @@ -// 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(BitcoinDevKitFFI) -import BitcoinDevKitFFI -#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_bdkffi_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_bdkffi_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 FfiConverterUInt16: FfiConverterPrimitive { - typealias FfiType = UInt16 - typealias SwiftType = UInt16 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt16 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: SwiftType, 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 FfiConverterInt32: FfiConverterPrimitive { - typealias FfiType = Int32 - typealias SwiftType = Int32 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Int32 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: Int32, 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 FfiConverterBool : FfiConverter { - typealias FfiType = Int8 - typealias SwiftType = Bool - - public static func lift(_ value: Int8) throws -> Bool { - return value != 0 - } - - public static func lower(_ value: Bool) -> Int8 { - return value ? 1 : 0 - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool { - return try lift(readInt(&buf)) - } - - public static func write(_ value: Bool, into buf: inout [UInt8]) { - writeInt(&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 AddressProtocol : AnyObject { - - func isValidForNetwork(network: Network) -> Bool - - func scriptPubkey() -> Script - - func toQrUri() -> String - -} - -open class Address: - CustomStringConvertible, - AddressProtocol { - 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_address(self.pointer, $0) } - } -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 - ) -} - self.init(unsafeFromRawPointer: pointer) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_bdkffi_fn_free_address(pointer, $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 - ) -}) -} - - - -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 - ) -}) -} - -open 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 - ) -}) -} - - open var description: String { - return try! FfiConverterString.lift( - try! rustCall() { - uniffi_bdkffi_fn_method_address_uniffi_trait_display(self.uniffiClonePointer(),$0 - ) -} - ) - } - -} - -public struct FfiConverterTypeAddress: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Address - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Address { - return Address(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: Address) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Address { - 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: Address, 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 FfiConverterTypeAddress_lift(_ pointer: UnsafeMutableRawPointer) throws -> Address { - return try FfiConverterTypeAddress.lift(pointer) -} - -public func FfiConverterTypeAddress_lower(_ value: Address) -> UnsafeMutableRawPointer { - return FfiConverterTypeAddress.lower(value) -} - - - - -public protocol BumpFeeTxBuilderProtocol : AnyObject { - - func finish(wallet: Wallet) throws -> Psbt - - func setExactSequence(nsequence: UInt32) -> BumpFeeTxBuilder - -} - -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 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_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) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_bdkffi_fn_free_bumpfeetxbuilder(pointer, $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 - ) -}) -} - -open func setExactSequence(nsequence: UInt32) -> BumpFeeTxBuilder { - return try! FfiConverterTypeBumpFeeTxBuilder.lift(try! rustCall() { - uniffi_bdkffi_fn_method_bumpfeetxbuilder_set_exact_sequence(self.uniffiClonePointer(), - FfiConverterUInt32.lower(nsequence),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeBumpFeeTxBuilder: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = BumpFeeTxBuilder - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> BumpFeeTxBuilder { - return BumpFeeTxBuilder(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: BumpFeeTxBuilder) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - 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. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - 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))))) - } -} - - - - -public func FfiConverterTypeBumpFeeTxBuilder_lift(_ pointer: UnsafeMutableRawPointer) throws -> BumpFeeTxBuilder { - return try FfiConverterTypeBumpFeeTxBuilder.lift(pointer) -} - -public func FfiConverterTypeBumpFeeTxBuilder_lower(_ value: BumpFeeTxBuilder) -> UnsafeMutableRawPointer { - return FfiConverterTypeBumpFeeTxBuilder.lower(value) -} - - - - -public protocol ChangeSetProtocol : AnyObject { - -} - -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 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_changeset(self.pointer, $0) } - } - // No primary constructor declared for this class. - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_bdkffi_fn_free_changeset(pointer, $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 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 { - -} - -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() {} - } - - // 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 FfiConverterTypeConnection: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Connection - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Connection { - return Connection(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: Connection) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - 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. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - 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))))) - } -} - - - - -public func FfiConverterTypeConnection_lift(_ pointer: UnsafeMutableRawPointer) throws -> Connection { - return try FfiConverterTypeConnection.lift(pointer) -} - -public func FfiConverterTypeConnection_lower(_ value: Connection) -> UnsafeMutableRawPointer { - return FfiConverterTypeConnection.lower(value) -} - - - - -public protocol DerivationPathProtocol : AnyObject { - -} - -open class DerivationPath: - DerivationPathProtocol { - 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_derivationpath(self.pointer, $0) } - } -public convenience init(path: String)throws { - let pointer = - try rustCallWithError(FfiConverterTypeBip32Error.lift) { - uniffi_bdkffi_fn_constructor_derivationpath_new( - FfiConverterString.lower(path),$0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_bdkffi_fn_free_derivationpath(pointer, $0) } - } - - - - - -} - -public struct FfiConverterTypeDerivationPath: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = DerivationPath - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> DerivationPath { - return DerivationPath(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: DerivationPath) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DerivationPath { - 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: DerivationPath, 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 FfiConverterTypeDerivationPath_lift(_ pointer: UnsafeMutableRawPointer) throws -> DerivationPath { - return try FfiConverterTypeDerivationPath.lift(pointer) -} - -public func FfiConverterTypeDerivationPath_lower(_ value: DerivationPath) -> UnsafeMutableRawPointer { - return FfiConverterTypeDerivationPath.lower(value) -} - - - - -public protocol DescriptorProtocol : AnyObject { - - func toStringWithSecret() -> String - -} - -open class Descriptor: - CustomStringConvertible, - DescriptorProtocol { - 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_descriptor(self.pointer, $0) } - } -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 - ) -} - 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 try! FfiConverterTypeDescriptor.lift(try! rustCall() { - uniffi_bdkffi_fn_constructor_descriptor_new_bip44( - FfiConverterTypeDescriptorSecretKey.lower(secretKey), - FfiConverterTypeKeychainKind.lower(keychain), - FfiConverterTypeNetwork_lower(network),$0 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - - - -open func toStringWithSecret() -> String { - return try! FfiConverterString.lift(try! rustCall() { - uniffi_bdkffi_fn_method_descriptor_to_string_with_secret(self.uniffiClonePointer(),$0 - ) -}) -} - - open var description: String { - return try! FfiConverterString.lift( - try! rustCall() { - uniffi_bdkffi_fn_method_descriptor_uniffi_trait_display(self.uniffiClonePointer(),$0 - ) -} - ) - } - -} - -public struct FfiConverterTypeDescriptor: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Descriptor - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Descriptor { - return Descriptor(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: Descriptor) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Descriptor { - 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: Descriptor, 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 FfiConverterTypeDescriptor_lift(_ pointer: UnsafeMutableRawPointer) throws -> Descriptor { - return try FfiConverterTypeDescriptor.lift(pointer) -} - -public func FfiConverterTypeDescriptor_lower(_ value: Descriptor) -> UnsafeMutableRawPointer { - return FfiConverterTypeDescriptor.lower(value) -} - - - - -public protocol DescriptorPublicKeyProtocol : AnyObject { - - func asString() -> String - - func derive(path: DerivationPath) throws -> DescriptorPublicKey - - func extend(path: DerivationPath) throws -> DescriptorPublicKey - -} - -open class DescriptorPublicKey: - DescriptorPublicKeyProtocol { - 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_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 try FfiConverterTypeDescriptorPublicKey.lift(try rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { - uniffi_bdkffi_fn_constructor_descriptorpublickey_from_string( - FfiConverterString.lower(publicKey),$0 - ) -}) -} - - - -open func asString() -> String { - return try! FfiConverterString.lift(try! rustCall() { - uniffi_bdkffi_fn_method_descriptorpublickey_as_string(self.uniffiClonePointer(),$0 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - - -} - -public struct FfiConverterTypeDescriptorPublicKey: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = DescriptorPublicKey - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> DescriptorPublicKey { - return DescriptorPublicKey(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: DescriptorPublicKey) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DescriptorPublicKey { - 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: DescriptorPublicKey, 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 FfiConverterTypeDescriptorPublicKey_lift(_ pointer: UnsafeMutableRawPointer) throws -> DescriptorPublicKey { - return try FfiConverterTypeDescriptorPublicKey.lift(pointer) -} - -public func FfiConverterTypeDescriptorPublicKey_lower(_ value: DescriptorPublicKey) -> UnsafeMutableRawPointer { - return FfiConverterTypeDescriptorPublicKey.lower(value) -} - - - - -public protocol DescriptorSecretKeyProtocol : AnyObject { - - func asPublic() -> DescriptorPublicKey - - func asString() -> String - - func derive(path: DerivationPath) throws -> DescriptorSecretKey - - func extend(path: DerivationPath) throws -> DescriptorSecretKey - - func secretBytes() -> [UInt8] - -} - -open class DescriptorSecretKey: - DescriptorSecretKeyProtocol { - 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_descriptorsecretkey(self.pointer, $0) } - } -public convenience init(network: Network, mnemonic: Mnemonic, password: String?) { - let pointer = - try! rustCall() { - uniffi_bdkffi_fn_constructor_descriptorsecretkey_new( - FfiConverterTypeNetwork_lower(network), - FfiConverterTypeMnemonic.lower(mnemonic), - 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 try FfiConverterTypeDescriptorSecretKey.lift(try rustCallWithError(FfiConverterTypeDescriptorKeyError.lift) { - uniffi_bdkffi_fn_constructor_descriptorsecretkey_from_string( - FfiConverterString.lower(secretKey),$0 - ) -}) -} - - - -open func asPublic() -> DescriptorPublicKey { - return try! FfiConverterTypeDescriptorPublicKey.lift(try! rustCall() { - uniffi_bdkffi_fn_method_descriptorsecretkey_as_public(self.uniffiClonePointer(),$0 - ) -}) -} - -open func asString() -> String { - return try! FfiConverterString.lift(try! rustCall() { - uniffi_bdkffi_fn_method_descriptorsecretkey_as_string(self.uniffiClonePointer(),$0 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - -open func secretBytes() -> [UInt8] { - return try! FfiConverterSequenceUInt8.lift(try! rustCall() { - uniffi_bdkffi_fn_method_descriptorsecretkey_secret_bytes(self.uniffiClonePointer(),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeDescriptorSecretKey: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = DescriptorSecretKey - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> DescriptorSecretKey { - return DescriptorSecretKey(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: DescriptorSecretKey) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DescriptorSecretKey { - 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: DescriptorSecretKey, 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 FfiConverterTypeDescriptorSecretKey_lift(_ pointer: UnsafeMutableRawPointer) throws -> DescriptorSecretKey { - return try FfiConverterTypeDescriptorSecretKey.lift(pointer) -} - -public func FfiConverterTypeDescriptorSecretKey_lower(_ value: DescriptorSecretKey) -> UnsafeMutableRawPointer { - return FfiConverterTypeDescriptorSecretKey.lower(value) -} - - - - -public protocol ElectrumClientProtocol : AnyObject { - - func broadcast(transaction: Transaction) throws -> String - - func fullScan(fullScanRequest: FullScanRequest, stopGap: UInt64, batchSize: UInt64, fetchPrevTxouts: Bool) throws -> Update - - func sync(syncRequest: SyncRequest, batchSize: UInt64, fetchPrevTxouts: Bool) throws -> Update - -} - -open class ElectrumClient: - ElectrumClientProtocol { - 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_electrumclient(self.pointer, $0) } - } -public convenience init(url: String)throws { - let pointer = - try rustCallWithError(FfiConverterTypeElectrumError.lift) { - uniffi_bdkffi_fn_constructor_electrumclient_new( - FfiConverterString.lower(url),$0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_bdkffi_fn_free_electrumclient(pointer, $0) } - } - - - - -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 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - - -} - -public struct FfiConverterTypeElectrumClient: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = ElectrumClient - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> ElectrumClient { - return ElectrumClient(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: ElectrumClient) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ElectrumClient { - 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: ElectrumClient, 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 FfiConverterTypeElectrumClient_lift(_ pointer: UnsafeMutableRawPointer) throws -> ElectrumClient { - return try FfiConverterTypeElectrumClient.lift(pointer) -} - -public func FfiConverterTypeElectrumClient_lower(_ value: ElectrumClient) -> UnsafeMutableRawPointer { - return FfiConverterTypeElectrumClient.lower(value) -} - - - - -public protocol EsploraClientProtocol : AnyObject { - - func broadcast(transaction: Transaction) throws - - func fullScan(fullScanRequest: FullScanRequest, stopGap: UInt64, parallelRequests: UInt64) throws -> Update - - func getTx(txid: String) throws -> Transaction? - - func sync(syncRequest: SyncRequest, parallelRequests: UInt64) throws -> Update - -} - -open class EsploraClient: - EsploraClientProtocol { - 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_esploraclient(self.pointer, $0) } - } -public convenience init(url: String) { - let pointer = - try! rustCall() { - uniffi_bdkffi_fn_constructor_esploraclient_new( - FfiConverterString.lower(url),$0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_bdkffi_fn_free_esploraclient(pointer, $0) } - } - - - - -open func broadcast(transaction: Transaction)throws {try rustCallWithError(FfiConverterTypeEsploraError.lift) { - uniffi_bdkffi_fn_method_esploraclient_broadcast(self.uniffiClonePointer(), - FfiConverterTypeTransaction.lower(transaction),$0 - ) -} -} - -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 - ) -}) -} - -open func getTx(txid: String)throws -> Transaction? { - return try FfiConverterOptionTypeTransaction.lift(try rustCallWithError(FfiConverterTypeEsploraError.lift) { - uniffi_bdkffi_fn_method_esploraclient_get_tx(self.uniffiClonePointer(), - FfiConverterString.lower(txid),$0 - ) -}) -} - -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 - ) -}) -} - - -} - -public struct FfiConverterTypeEsploraClient: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = EsploraClient - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> EsploraClient { - return EsploraClient(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: EsploraClient) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> EsploraClient { - 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: EsploraClient, 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 FfiConverterTypeEsploraClient_lift(_ pointer: UnsafeMutableRawPointer) throws -> EsploraClient { - return try FfiConverterTypeEsploraClient.lift(pointer) -} - -public func FfiConverterTypeEsploraClient_lower(_ value: EsploraClient) -> UnsafeMutableRawPointer { - return FfiConverterTypeEsploraClient.lower(value) -} - - - - -public protocol FullScanRequestProtocol : AnyObject { - -} - -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 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) } - } - // No primary constructor declared for this class. - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_bdkffi_fn_free_fullscanrequest(pointer, $0) } - } - - - - - -} - -public struct FfiConverterTypeFullScanRequest: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = FullScanRequest - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FullScanRequest { - return FullScanRequest(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: FullScanRequest) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - 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. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - 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))))) - } -} - - - - -public func FfiConverterTypeFullScanRequest_lift(_ pointer: UnsafeMutableRawPointer) throws -> FullScanRequest { - return try FfiConverterTypeFullScanRequest.lift(pointer) -} - -public func FfiConverterTypeFullScanRequest_lower(_ value: FullScanRequest) -> UnsafeMutableRawPointer { - return FfiConverterTypeFullScanRequest.lower(value) -} - - - - -public protocol FullScanRequestBuilderProtocol : AnyObject { - - func build() throws -> FullScanRequest - - func inspectSpksForAllKeychains(inspector: FullScanScriptInspector) throws -> FullScanRequestBuilder - -} - -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 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_fullscanrequestbuilder(self.pointer, $0) } - } - // No primary constructor declared for this class. - - deinit { - 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 FfiConverterTypeFullScanRequestBuilder: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = FullScanRequestBuilder - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FullScanRequestBuilder { - return FullScanRequestBuilder(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: FullScanRequestBuilder) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - 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. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - 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))))) - } -} - - - - -public func FfiConverterTypeFullScanRequestBuilder_lift(_ pointer: UnsafeMutableRawPointer) throws -> FullScanRequestBuilder { - return try FfiConverterTypeFullScanRequestBuilder.lift(pointer) -} - -public func FfiConverterTypeFullScanRequestBuilder_lower(_ value: FullScanRequestBuilder) -> UnsafeMutableRawPointer { - return FfiConverterTypeFullScanRequestBuilder.lower(value) -} - - - - -public protocol FullScanScriptInspector : AnyObject { - - func inspect(keychain: KeychainKind, index: UInt32, script: Script) - -} - -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 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) { - let pointer = - try! rustCall() { - uniffi_bdkffi_fn_constructor_mnemonic_new( - 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 try FfiConverterTypeMnemonic.lift(try rustCallWithError(FfiConverterTypeBip39Error.lift) { - uniffi_bdkffi_fn_constructor_mnemonic_from_entropy( - FfiConverterSequenceUInt8.lower(entropy),$0 - ) -}) -} - -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 - ) -}) -} - - - - open var description: String { - return try! FfiConverterString.lift( - try! rustCall() { - uniffi_bdkffi_fn_method_mnemonic_uniffi_trait_display(self.uniffiClonePointer(),$0 - ) -} - ) - } - -} - -public struct FfiConverterTypeMnemonic: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Mnemonic - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Mnemonic { - return Mnemonic(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: Mnemonic) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Mnemonic { - 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: Mnemonic, 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 FfiConverterTypeMnemonic_lift(_ pointer: UnsafeMutableRawPointer) throws -> Mnemonic { - return try FfiConverterTypeMnemonic.lift(pointer) -} - -public func FfiConverterTypeMnemonic_lower(_ value: Mnemonic) -> UnsafeMutableRawPointer { - return FfiConverterTypeMnemonic.lower(value) -} - - - - -public protocol PsbtProtocol : AnyObject { - - func combine(other: Psbt) throws -> Psbt - - func extractTx() throws -> Transaction - - func fee() throws -> UInt64 - - func jsonSerialize() -> String - - func serialize() -> String - -} - -open class Psbt: - PsbtProtocol { - 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_psbt(self.pointer, $0) } - } -public convenience init(psbtBase64: String)throws { - let pointer = - try rustCallWithError(FfiConverterTypePsbtParseError.lift) { - uniffi_bdkffi_fn_constructor_psbt_new( - 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 - ) -}) -} - -open func extractTx()throws -> Transaction { - return try FfiConverterTypeTransaction.lift(try rustCallWithError(FfiConverterTypeExtractTxError.lift) { - uniffi_bdkffi_fn_method_psbt_extract_tx(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 - ) -}) -} - - -} - -public struct FfiConverterTypePsbt: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Psbt - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Psbt { - return Psbt(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: Psbt) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Psbt { - 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: Psbt, 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 FfiConverterTypePsbt_lift(_ pointer: UnsafeMutableRawPointer) throws -> Psbt { - return try FfiConverterTypePsbt.lift(pointer) -} - -public func FfiConverterTypePsbt_lower(_ value: Psbt) -> UnsafeMutableRawPointer { - return FfiConverterTypePsbt.lower(value) -} - - - - -public protocol SyncRequestProtocol : AnyObject { - -} - -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 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) } - } - // No primary constructor declared for this class. - - deinit { - 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) } - } - - - - -open func build()throws -> SyncRequest { - return try FfiConverterTypeSyncRequest.lift(try rustCallWithError(FfiConverterTypeRequestBuilderError.lift) { - uniffi_bdkffi_fn_method_syncrequestbuilder_build(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 FfiConverterTypeSyncRequestBuilder: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = SyncRequestBuilder - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncRequestBuilder { - return SyncRequestBuilder(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: SyncRequestBuilder) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - 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. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - 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))))) - } -} - - - - -public func FfiConverterTypeSyncRequestBuilder_lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncRequestBuilder { - return try FfiConverterTypeSyncRequestBuilder.lift(pointer) -} - -public func FfiConverterTypeSyncRequestBuilder_lower(_ value: SyncRequestBuilder) -> UnsafeMutableRawPointer { - return FfiConverterTypeSyncRequestBuilder.lower(value) -} - - - - -public protocol SyncScriptInspector : AnyObject { - - func inspect(script: Script, total: UInt64) - -} - -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 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_syncscriptinspector(self.pointer, $0) } - } - // No primary constructor declared for this class. - - deinit { - 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 - ) -} -} - - -} - - -// 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 = SyncScriptInspector - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncScriptInspector { - return SyncScriptInspectorImpl(unsafeFromRawPointer: pointer) - } - - 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 -> 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. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - 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))))) - } -} - - - - -public func FfiConverterTypeSyncScriptInspector_lift(_ pointer: UnsafeMutableRawPointer) throws -> SyncScriptInspector { - return try FfiConverterTypeSyncScriptInspector.lift(pointer) -} - -public func FfiConverterTypeSyncScriptInspector_lower(_ value: SyncScriptInspector) -> UnsafeMutableRawPointer { - return FfiConverterTypeSyncScriptInspector.lower(value) -} - - - - -public protocol TransactionProtocol : AnyObject { - - func computeTxid() -> String - - func input() -> [TxIn] - - func isCoinbase() -> Bool - - func isExplicitlyRbf() -> Bool - - func isLockTimeEnabled() -> Bool - - func lockTime() -> UInt32 - - func output() -> [TxOut] - - func serialize() -> [UInt8] - - func totalSize() -> UInt64 - - func version() -> Int32 - - func vsize() -> UInt64 - - func weight() -> UInt64 - -} - -open class Transaction: - TransactionProtocol { - 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_transaction(self.pointer, $0) } - } -public convenience init(transactionBytes: [UInt8])throws { - let pointer = - try rustCallWithError(FfiConverterTypeTransactionError.lift) { - uniffi_bdkffi_fn_constructor_transaction_new( - FfiConverterSequenceUInt8.lower(transactionBytes),$0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_bdkffi_fn_free_transaction(pointer, $0) } - } - - - - -open func computeTxid() -> String { - return try! FfiConverterString.lift(try! rustCall() { - uniffi_bdkffi_fn_method_transaction_compute_txid(self.uniffiClonePointer(),$0 - ) -}) -} - -open func input() -> [TxIn] { - return try! FfiConverterSequenceTypeTxIn.lift(try! rustCall() { - uniffi_bdkffi_fn_method_transaction_input(self.uniffiClonePointer(),$0 - ) -}) -} - -open func isCoinbase() -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_bdkffi_fn_method_transaction_is_coinbase(self.uniffiClonePointer(),$0 - ) -}) -} - -open func isExplicitlyRbf() -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_bdkffi_fn_method_transaction_is_explicitly_rbf(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 - ) -}) -} - -open func lockTime() -> UInt32 { - return try! FfiConverterUInt32.lift(try! rustCall() { - uniffi_bdkffi_fn_method_transaction_lock_time(self.uniffiClonePointer(),$0 - ) -}) -} - -open func output() -> [TxOut] { - return try! FfiConverterSequenceTypeTxOut.lift(try! rustCall() { - uniffi_bdkffi_fn_method_transaction_output(self.uniffiClonePointer(),$0 - ) -}) -} - -open func serialize() -> [UInt8] { - return try! FfiConverterSequenceUInt8.lift(try! rustCall() { - uniffi_bdkffi_fn_method_transaction_serialize(self.uniffiClonePointer(),$0 - ) -}) -} - -open func totalSize() -> UInt64 { - return try! FfiConverterUInt64.lift(try! rustCall() { - uniffi_bdkffi_fn_method_transaction_total_size(self.uniffiClonePointer(),$0 - ) -}) -} - -open func version() -> Int32 { - return try! FfiConverterInt32.lift(try! rustCall() { - uniffi_bdkffi_fn_method_transaction_version(self.uniffiClonePointer(),$0 - ) -}) -} - -open func vsize() -> UInt64 { - return try! FfiConverterUInt64.lift(try! rustCall() { - uniffi_bdkffi_fn_method_transaction_vsize(self.uniffiClonePointer(),$0 - ) -}) -} - -open func weight() -> UInt64 { - return try! FfiConverterUInt64.lift(try! rustCall() { - uniffi_bdkffi_fn_method_transaction_weight(self.uniffiClonePointer(),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeTransaction: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Transaction - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Transaction { - return Transaction(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: Transaction) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Transaction { - 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: Transaction, 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 FfiConverterTypeTransaction_lift(_ pointer: UnsafeMutableRawPointer) throws -> Transaction { - return try FfiConverterTypeTransaction.lift(pointer) -} - -public func FfiConverterTypeTransaction_lower(_ value: Transaction) -> UnsafeMutableRawPointer { - return FfiConverterTypeTransaction.lower(value) -} - - - - -public protocol TxBuilderProtocol : AnyObject { - - func addGlobalXpubs() -> TxBuilder - - func addRecipient(script: Script, amount: Amount) -> TxBuilder - - func addUnspendable(unspendable: OutPoint) -> TxBuilder - - func addUtxo(outpoint: OutPoint) -> TxBuilder - - func changePolicy(changePolicy: ChangeSpendPolicy) -> TxBuilder - - func doNotSpendChange() -> TxBuilder - - func drainTo(script: Script) -> TxBuilder - - func drainWallet() -> TxBuilder - - func feeAbsolute(fee: Amount) -> TxBuilder - - func feeRate(feeRate: FeeRate) -> TxBuilder - - func finish(wallet: Wallet) throws -> Psbt - - func manuallySelectedOnly() -> TxBuilder - - func onlySpendChange() -> TxBuilder - - func setExactSequence(nsequence: UInt32) -> TxBuilder - - func setRecipients(recipients: [ScriptAmount]) -> TxBuilder - - func unspendable(unspendable: [OutPoint]) -> TxBuilder - -} - -open class TxBuilder: - TxBuilderProtocol { - 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_txbuilder(self.pointer, $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 - } - - 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 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - -open func doNotSpendChange() -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { - uniffi_bdkffi_fn_method_txbuilder_do_not_spend_change(self.uniffiClonePointer(),$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 - ) -}) -} - -open func drainWallet() -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { - uniffi_bdkffi_fn_method_txbuilder_drain_wallet(self.uniffiClonePointer(),$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 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - -open func manuallySelectedOnly() -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { - uniffi_bdkffi_fn_method_txbuilder_manually_selected_only(self.uniffiClonePointer(),$0 - ) -}) -} - -open func onlySpendChange() -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { - uniffi_bdkffi_fn_method_txbuilder_only_spend_change(self.uniffiClonePointer(),$0 - ) -}) -} - -open func setExactSequence(nsequence: UInt32) -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { - uniffi_bdkffi_fn_method_txbuilder_set_exact_sequence(self.uniffiClonePointer(), - FfiConverterUInt32.lower(nsequence),$0 - ) -}) -} - -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 - ) -}) -} - -open func unspendable(unspendable: [OutPoint]) -> TxBuilder { - return try! FfiConverterTypeTxBuilder.lift(try! rustCall() { - uniffi_bdkffi_fn_method_txbuilder_unspendable(self.uniffiClonePointer(), - FfiConverterSequenceTypeOutPoint.lower(unspendable),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeTxBuilder: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = TxBuilder - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> TxBuilder { - return TxBuilder(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: TxBuilder) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TxBuilder { - 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: TxBuilder, 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 FfiConverterTypeTxBuilder_lift(_ pointer: UnsafeMutableRawPointer) throws -> TxBuilder { - return try FfiConverterTypeTxBuilder.lift(pointer) -} - -public func FfiConverterTypeTxBuilder_lower(_ value: TxBuilder) -> UnsafeMutableRawPointer { - return FfiConverterTypeTxBuilder.lower(value) -} - - - - -public protocol UpdateProtocol : AnyObject { - -} - -open class Update: - UpdateProtocol { - 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_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) } - } - - - - - -} - -public struct FfiConverterTypeUpdate: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Update - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Update { - return Update(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: Update) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Update { - 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: Update, 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 FfiConverterTypeUpdate_lift(_ pointer: UnsafeMutableRawPointer) throws -> Update { - return try FfiConverterTypeUpdate.lift(pointer) -} - -public func FfiConverterTypeUpdate_lower(_ value: Update) -> UnsafeMutableRawPointer { - return FfiConverterTypeUpdate.lower(value) -} - - - - -public protocol WalletProtocol : AnyObject { - - func applyUpdate(update: Update) throws - - func balance() -> Balance - - func calculateFee(tx: Transaction) throws -> Amount - - func calculateFeeRate(tx: Transaction) throws -> FeeRate - - func cancelTx(tx: Transaction) - - func derivationIndex(keychain: KeychainKind) -> UInt32? - - func derivationOfSpk(spk: Script) -> KeychainAndIndex? - - func descriptorChecksum(keychain: KeychainKind) -> String - - func finalizePsbt(psbt: Psbt) throws -> Bool - - func getTx(txid: String) throws -> CanonicalTx? - - func getUtxo(op: OutPoint) -> LocalOutput? - - func isMine(script: Script) -> Bool - - func listOutput() -> [LocalOutput] - - func listUnspent() -> [LocalOutput] - - func listUnusedAddresses(keychain: KeychainKind) -> [AddressInfo] - - func markUsed(keychain: KeychainKind, index: UInt32) -> Bool - - func network() -> Network - - func nextDerivationIndex(keychain: KeychainKind) -> UInt32 - - func nextUnusedAddress(keychain: KeychainKind) -> AddressInfo - - func peekAddress(keychain: KeychainKind, index: UInt32) -> AddressInfo - - func persist(connection: Connection) throws -> Bool - - func revealAddressesTo(keychain: KeychainKind, index: UInt32) -> [AddressInfo] - - func revealNextAddress(keychain: KeychainKind) -> AddressInfo - - func sentAndReceived(tx: Transaction) -> SentAndReceivedValues - - func sign(psbt: Psbt) throws -> Bool - - func startFullScan() -> FullScanRequestBuilder - - func startSyncWithRevealedSpks() -> SyncRequestBuilder - - func transactions() -> [CanonicalTx] - -} - -open class Wallet: - WalletProtocol { - 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_wallet(self.pointer, $0) } - } -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), - 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 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), - FfiConverterTypeDescriptor.lower(changeDescriptor), - FfiConverterTypeConnection.lower(connection),$0 - ) -}) -} - - - -open func applyUpdate(update: Update)throws {try rustCallWithError(FfiConverterTypeCannotConnectError.lift) { - uniffi_bdkffi_fn_method_wallet_apply_update(self.uniffiClonePointer(), - FfiConverterTypeUpdate.lower(update),$0 - ) -} -} - -open func balance() -> Balance { - return try! FfiConverterTypeBalance.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_balance(self.uniffiClonePointer(),$0 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - -open func cancelTx(tx: Transaction) {try! rustCall() { - uniffi_bdkffi_fn_method_wallet_cancel_tx(self.uniffiClonePointer(), - FfiConverterTypeTransaction.lower(tx),$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 - ) -}) -} - -open func derivationOfSpk(spk: Script) -> KeychainAndIndex? { - return try! FfiConverterOptionTypeKeychainAndIndex.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_derivation_of_spk(self.uniffiClonePointer(), - FfiConverterTypeScript_lower(spk),$0 - ) -}) -} - -open func descriptorChecksum(keychain: KeychainKind) -> String { - return try! FfiConverterString.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_descriptor_checksum(self.uniffiClonePointer(), - FfiConverterTypeKeychainKind.lower(keychain),$0 - ) -}) -} - -open func finalizePsbt(psbt: Psbt)throws -> Bool { - return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeSignerError.lift) { - uniffi_bdkffi_fn_method_wallet_finalize_psbt(self.uniffiClonePointer(), - FfiConverterTypePsbt.lower(psbt),$0 - ) -}) -} - -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 - ) -}) -} - -open func getUtxo(op: OutPoint) -> LocalOutput? { - return try! FfiConverterOptionTypeLocalOutput.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_get_utxo(self.uniffiClonePointer(), - FfiConverterTypeOutPoint_lower(op),$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 - ) -}) -} - -open func listOutput() -> [LocalOutput] { - return try! FfiConverterSequenceTypeLocalOutput.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_list_output(self.uniffiClonePointer(),$0 - ) -}) -} - -open func listUnspent() -> [LocalOutput] { - return try! FfiConverterSequenceTypeLocalOutput.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_list_unspent(self.uniffiClonePointer(),$0 - ) -}) -} - -open func listUnusedAddresses(keychain: KeychainKind) -> [AddressInfo] { - return try! FfiConverterSequenceTypeAddressInfo.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_list_unused_addresses(self.uniffiClonePointer(), - FfiConverterTypeKeychainKind.lower(keychain),$0 - ) -}) -} - -open func markUsed(keychain: KeychainKind, index: UInt32) -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_mark_used(self.uniffiClonePointer(), - FfiConverterTypeKeychainKind.lower(keychain), - FfiConverterUInt32.lower(index),$0 - ) -}) -} - -open func network() -> Network { - return try! FfiConverterTypeNetwork_lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_network(self.uniffiClonePointer(),$0 - ) -}) -} - -open func nextDerivationIndex(keychain: KeychainKind) -> UInt32 { - return try! FfiConverterUInt32.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_next_derivation_index(self.uniffiClonePointer(), - FfiConverterTypeKeychainKind.lower(keychain),$0 - ) -}) -} - -open func nextUnusedAddress(keychain: KeychainKind) -> AddressInfo { - return try! FfiConverterTypeAddressInfo.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_next_unused_address(self.uniffiClonePointer(), - FfiConverterTypeKeychainKind.lower(keychain),$0 - ) -}) -} - -open func peekAddress(keychain: KeychainKind, index: UInt32) -> AddressInfo { - return try! FfiConverterTypeAddressInfo.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_peek_address(self.uniffiClonePointer(), - FfiConverterTypeKeychainKind.lower(keychain), - FfiConverterUInt32.lower(index),$0 - ) -}) -} - -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 revealAddressesTo(keychain: KeychainKind, index: UInt32) -> [AddressInfo] { - return try! FfiConverterSequenceTypeAddressInfo.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_reveal_addresses_to(self.uniffiClonePointer(), - FfiConverterTypeKeychainKind.lower(keychain), - FfiConverterUInt32.lower(index),$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 - ) -}) -} - -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 - ) -}) -} - -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 - ) -}) -} - -open func startFullScan() -> FullScanRequestBuilder { - return try! FfiConverterTypeFullScanRequestBuilder.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_start_full_scan(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 - ) -}) -} - -open func transactions() -> [CanonicalTx] { - return try! FfiConverterSequenceTypeCanonicalTx.lift(try! rustCall() { - uniffi_bdkffi_fn_method_wallet_transactions(self.uniffiClonePointer(),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeWallet: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Wallet - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Wallet { - return Wallet(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: Wallet) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Wallet { - 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: Wallet, 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 FfiConverterTypeWallet_lift(_ pointer: UnsafeMutableRawPointer) throws -> Wallet { - return try FfiConverterTypeWallet.lift(pointer) -} - -public func FfiConverterTypeWallet_lower(_ value: Wallet) -> UnsafeMutableRawPointer { - return FfiConverterTypeWallet.lower(value) -} - - -public struct AddressInfo { - public var index: UInt32 - public var address: Address - public var keychain: KeychainKind - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(index: UInt32, address: Address, keychain: KeychainKind) { - self.index = index - self.address = address - self.keychain = keychain - } -} - - - -public struct FfiConverterTypeAddressInfo: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AddressInfo { - return - try AddressInfo( - index: FfiConverterUInt32.read(from: &buf), - address: FfiConverterTypeAddress.read(from: &buf), - keychain: FfiConverterTypeKeychainKind.read(from: &buf) - ) - } - - public static func write(_ value: AddressInfo, into buf: inout [UInt8]) { - FfiConverterUInt32.write(value.index, into: &buf) - FfiConverterTypeAddress.write(value.address, into: &buf) - FfiConverterTypeKeychainKind.write(value.keychain, into: &buf) - } -} - - -public func FfiConverterTypeAddressInfo_lift(_ buf: RustBuffer) throws -> AddressInfo { - return try FfiConverterTypeAddressInfo.lift(buf) -} - -public func FfiConverterTypeAddressInfo_lower(_ value: AddressInfo) -> RustBuffer { - return FfiConverterTypeAddressInfo.lower(value) -} - - -public struct Balance { - public var immature: Amount - public var trustedPending: Amount - public var untrustedPending: Amount - public var confirmed: Amount - public var trustedSpendable: Amount - public var total: Amount - - // 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) { - self.immature = immature - self.trustedPending = trustedPending - self.untrustedPending = untrustedPending - self.confirmed = confirmed - self.trustedSpendable = trustedSpendable - self.total = total - } -} - - - -public struct FfiConverterTypeBalance: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Balance { - return - try Balance( - immature: FfiConverterTypeAmount.read(from: &buf), - trustedPending: FfiConverterTypeAmount.read(from: &buf), - untrustedPending: FfiConverterTypeAmount.read(from: &buf), - confirmed: FfiConverterTypeAmount.read(from: &buf), - trustedSpendable: FfiConverterTypeAmount.read(from: &buf), - total: FfiConverterTypeAmount.read(from: &buf) - ) - } - - public static func write(_ value: Balance, into buf: inout [UInt8]) { - FfiConverterTypeAmount.write(value.immature, into: &buf) - FfiConverterTypeAmount.write(value.trustedPending, into: &buf) - FfiConverterTypeAmount.write(value.untrustedPending, into: &buf) - FfiConverterTypeAmount.write(value.confirmed, into: &buf) - FfiConverterTypeAmount.write(value.trustedSpendable, into: &buf) - FfiConverterTypeAmount.write(value.total, into: &buf) - } -} - - -public func FfiConverterTypeBalance_lift(_ buf: RustBuffer) throws -> Balance { - return try FfiConverterTypeBalance.lift(buf) -} - -public func FfiConverterTypeBalance_lower(_ value: Balance) -> RustBuffer { - return FfiConverterTypeBalance.lower(value) -} - - -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) { - self.transaction = transaction - self.chainPosition = chainPosition - } -} - - - -public struct FfiConverterTypeCanonicalTx: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CanonicalTx { - return - try CanonicalTx( - transaction: FfiConverterTypeTransaction.read(from: &buf), - chainPosition: FfiConverterTypeChainPosition.read(from: &buf) - ) - } - - public static func write(_ value: CanonicalTx, into buf: inout [UInt8]) { - FfiConverterTypeTransaction.write(value.transaction, into: &buf) - FfiConverterTypeChainPosition.write(value.chainPosition, into: &buf) - } -} - - -public func FfiConverterTypeCanonicalTx_lift(_ buf: RustBuffer) throws -> CanonicalTx { - return try FfiConverterTypeCanonicalTx.lift(buf) -} - -public func FfiConverterTypeCanonicalTx_lower(_ value: CanonicalTx) -> RustBuffer { - return FfiConverterTypeCanonicalTx.lower(value) -} - - -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 KeychainAndIndex { - public var keychain: KeychainKind - public var index: UInt32 - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(keychain: KeychainKind, index: UInt32) { - self.keychain = keychain - self.index = index - } -} - - - -extension KeychainAndIndex: Equatable, Hashable { - public static func ==(lhs: KeychainAndIndex, rhs: KeychainAndIndex) -> Bool { - if lhs.keychain != rhs.keychain { - return false - } - if lhs.index != rhs.index { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(keychain) - hasher.combine(index) - } -} - - -public struct FfiConverterTypeKeychainAndIndex: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeychainAndIndex { - return - try KeychainAndIndex( - keychain: FfiConverterTypeKeychainKind.read(from: &buf), - index: FfiConverterUInt32.read(from: &buf) - ) - } - - public static func write(_ value: KeychainAndIndex, into buf: inout [UInt8]) { - FfiConverterTypeKeychainKind.write(value.keychain, into: &buf) - FfiConverterUInt32.write(value.index, into: &buf) - } -} - - -public func FfiConverterTypeKeychainAndIndex_lift(_ buf: RustBuffer) throws -> KeychainAndIndex { - return try FfiConverterTypeKeychainAndIndex.lift(buf) -} - -public func FfiConverterTypeKeychainAndIndex_lower(_ value: KeychainAndIndex) -> RustBuffer { - return FfiConverterTypeKeychainAndIndex.lower(value) -} - - -public struct LocalOutput { - public var outpoint: OutPoint - public var txout: TxOut - public var keychain: KeychainKind - public var isSpent: Bool - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(outpoint: OutPoint, txout: TxOut, keychain: KeychainKind, isSpent: Bool) { - self.outpoint = outpoint - self.txout = txout - self.keychain = keychain - self.isSpent = isSpent - } -} - - - -public struct FfiConverterTypeLocalOutput: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> LocalOutput { - return - try LocalOutput( - outpoint: FfiConverterTypeOutPoint.read(from: &buf), - txout: FfiConverterTypeTxOut.read(from: &buf), - keychain: FfiConverterTypeKeychainKind.read(from: &buf), - isSpent: FfiConverterBool.read(from: &buf) - ) - } - - public static func write(_ value: LocalOutput, into buf: inout [UInt8]) { - FfiConverterTypeOutPoint.write(value.outpoint, into: &buf) - FfiConverterTypeTxOut.write(value.txout, into: &buf) - FfiConverterTypeKeychainKind.write(value.keychain, into: &buf) - FfiConverterBool.write(value.isSpent, into: &buf) - } -} - - -public func FfiConverterTypeLocalOutput_lift(_ buf: RustBuffer) throws -> LocalOutput { - return try FfiConverterTypeLocalOutput.lift(buf) -} - -public func FfiConverterTypeLocalOutput_lower(_ value: LocalOutput) -> RustBuffer { - return FfiConverterTypeLocalOutput.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) { - self.script = script - self.amount = amount - } -} - - - -public struct FfiConverterTypeScriptAmount: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ScriptAmount { - return - try ScriptAmount( - script: FfiConverterTypeScript.read(from: &buf), - amount: FfiConverterTypeAmount.read(from: &buf) - ) - } - - public static func write(_ value: ScriptAmount, into buf: inout [UInt8]) { - FfiConverterTypeScript.write(value.script, into: &buf) - FfiConverterTypeAmount.write(value.amount, into: &buf) - } -} - - -public func FfiConverterTypeScriptAmount_lift(_ buf: RustBuffer) throws -> ScriptAmount { - return try FfiConverterTypeScriptAmount.lift(buf) -} - -public func FfiConverterTypeScriptAmount_lower(_ value: ScriptAmount) -> RustBuffer { - return FfiConverterTypeScriptAmount.lower(value) -} - - -public struct SentAndReceivedValues { - public var sent: Amount - public var received: Amount - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(sent: Amount, received: Amount) { - self.sent = sent - self.received = received - } -} - - - -public struct FfiConverterTypeSentAndReceivedValues: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SentAndReceivedValues { - return - try SentAndReceivedValues( - sent: FfiConverterTypeAmount.read(from: &buf), - received: FfiConverterTypeAmount.read(from: &buf) - ) - } - - public static func write(_ value: SentAndReceivedValues, into buf: inout [UInt8]) { - FfiConverterTypeAmount.write(value.sent, into: &buf) - FfiConverterTypeAmount.write(value.received, into: &buf) - } -} - - -public func FfiConverterTypeSentAndReceivedValues_lift(_ buf: RustBuffer) throws -> SentAndReceivedValues { - return try FfiConverterTypeSentAndReceivedValues.lift(buf) -} - -public func FfiConverterTypeSentAndReceivedValues_lower(_ value: SentAndReceivedValues) -> RustBuffer { - return FfiConverterTypeSentAndReceivedValues.lower(value) -} - - -public struct TxIn { - public var previousOutput: OutPoint - public var scriptSig: Script - public var sequence: UInt32 - public var witness: [[UInt8]] - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(previousOutput: OutPoint, scriptSig: Script, sequence: UInt32, witness: [[UInt8]]) { - self.previousOutput = previousOutput - self.scriptSig = scriptSig - self.sequence = sequence - self.witness = witness - } -} - - - -public struct FfiConverterTypeTxIn: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TxIn { - return - try TxIn( - previousOutput: FfiConverterTypeOutPoint.read(from: &buf), - scriptSig: FfiConverterTypeScript.read(from: &buf), - sequence: FfiConverterUInt32.read(from: &buf), - witness: FfiConverterSequenceSequenceUInt8.read(from: &buf) - ) - } - - public static func write(_ value: TxIn, into buf: inout [UInt8]) { - FfiConverterTypeOutPoint.write(value.previousOutput, into: &buf) - FfiConverterTypeScript.write(value.scriptSig, into: &buf) - FfiConverterUInt32.write(value.sequence, into: &buf) - FfiConverterSequenceSequenceUInt8.write(value.witness, into: &buf) - } -} - - -public func FfiConverterTypeTxIn_lift(_ buf: RustBuffer) throws -> TxIn { - return try FfiConverterTypeTxIn.lift(buf) -} - -public func FfiConverterTypeTxIn_lower(_ value: TxIn) -> RustBuffer { - return FfiConverterTypeTxIn.lower(value) -} - - -public struct TxOut { - public var value: UInt64 - public var scriptPubkey: Script - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(value: UInt64, scriptPubkey: Script) { - self.value = value - self.scriptPubkey = scriptPubkey - } -} - - - -public struct FfiConverterTypeTxOut: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TxOut { - return - try TxOut( - value: FfiConverterUInt64.read(from: &buf), - scriptPubkey: FfiConverterTypeScript.read(from: &buf) - ) - } - - public static func write(_ value: TxOut, into buf: inout [UInt8]) { - FfiConverterUInt64.write(value.value, into: &buf) - FfiConverterTypeScript.write(value.scriptPubkey, into: &buf) - } -} - - -public func FfiConverterTypeTxOut_lift(_ buf: RustBuffer) throws -> TxOut { - return try FfiConverterTypeTxOut.lift(buf) -} - -public func FfiConverterTypeTxOut_lower(_ value: TxOut) -> RustBuffer { - return FfiConverterTypeTxOut.lower(value) -} - - -public enum AddressParseError { - - - - case Base58 - case Bech32 - case WitnessVersion(errorMessage: String - ) - case WitnessProgram(errorMessage: String - ) - case UnknownHrp - case LegacyAddressTooLong - case InvalidBase58PayloadLength - case InvalidLegacyPrefix - case NetworkValidation - case OtherAddressParseErr -} - - -public struct FfiConverterTypeAddressParseError: FfiConverterRustBuffer { - typealias SwiftType = AddressParseError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AddressParseError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .Base58 - case 2: return .Bech32 - case 3: return .WitnessVersion( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 4: return .WitnessProgram( - errorMessage: try FfiConverterString.read(from: &buf) - ) - 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: AddressParseError, into buf: inout [UInt8]) { - switch value { - - - - - - case .Base58: - writeInt(&buf, Int32(1)) - - - case .Bech32: - writeInt(&buf, Int32(2)) - - - case let .WitnessVersion(errorMessage): - writeInt(&buf, Int32(3)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .WitnessProgram(errorMessage): - writeInt(&buf, Int32(4)) - FfiConverterString.write(errorMessage, into: &buf) - - - case .UnknownHrp: - writeInt(&buf, Int32(5)) - - - case .LegacyAddressTooLong: - writeInt(&buf, Int32(6)) - - - case .InvalidBase58PayloadLength: - writeInt(&buf, Int32(7)) - - - case .InvalidLegacyPrefix: - writeInt(&buf, Int32(8)) - - - case .NetworkValidation: - writeInt(&buf, Int32(9)) - - - case .OtherAddressParseErr: - writeInt(&buf, Int32(10)) - - } - } -} - - -extension AddressParseError: Equatable, Hashable {} - -extension AddressParseError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum Bip32Error { - - - - case CannotDeriveFromHardenedKey - case Secp256k1(errorMessage: String - ) - case InvalidChildNumber(childNumber: UInt32 - ) - case InvalidChildNumberFormat - case InvalidDerivationPathFormat - case UnknownVersion(version: String - ) - case WrongExtendedKeyLength(length: UInt32 - ) - case Base58(errorMessage: String - ) - case Hex(errorMessage: String - ) - case InvalidPublicKeyHexLength(length: UInt32 - ) - case UnknownError(errorMessage: String - ) -} - - -public struct FfiConverterTypeBip32Error: FfiConverterRustBuffer { - typealias SwiftType = Bip32Error - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bip32Error { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .CannotDeriveFromHardenedKey - case 2: return .Secp256k1( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 3: return .InvalidChildNumber( - childNumber: try FfiConverterUInt32.read(from: &buf) - ) - case 4: return .InvalidChildNumberFormat - case 5: return .InvalidDerivationPathFormat - case 6: return .UnknownVersion( - version: try FfiConverterString.read(from: &buf) - ) - case 7: return .WrongExtendedKeyLength( - length: try FfiConverterUInt32.read(from: &buf) - ) - case 8: return .Base58( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 9: return .Hex( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 10: return .InvalidPublicKeyHexLength( - length: try FfiConverterUInt32.read(from: &buf) - ) - case 11: return .UnknownError( - errorMessage: try FfiConverterString.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: Bip32Error, into buf: inout [UInt8]) { - switch value { - - - - - - case .CannotDeriveFromHardenedKey: - writeInt(&buf, Int32(1)) - - - case let .Secp256k1(errorMessage): - writeInt(&buf, Int32(2)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .InvalidChildNumber(childNumber): - writeInt(&buf, Int32(3)) - FfiConverterUInt32.write(childNumber, into: &buf) - - - case .InvalidChildNumberFormat: - writeInt(&buf, Int32(4)) - - - case .InvalidDerivationPathFormat: - writeInt(&buf, Int32(5)) - - - case let .UnknownVersion(version): - writeInt(&buf, Int32(6)) - FfiConverterString.write(version, into: &buf) - - - case let .WrongExtendedKeyLength(length): - writeInt(&buf, Int32(7)) - FfiConverterUInt32.write(length, into: &buf) - - - case let .Base58(errorMessage): - writeInt(&buf, Int32(8)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Hex(errorMessage): - writeInt(&buf, Int32(9)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .InvalidPublicKeyHexLength(length): - writeInt(&buf, Int32(10)) - FfiConverterUInt32.write(length, into: &buf) - - - case let .UnknownError(errorMessage): - writeInt(&buf, Int32(11)) - FfiConverterString.write(errorMessage, into: &buf) - - } - } -} - - -extension Bip32Error: Equatable, Hashable {} - -extension Bip32Error: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum Bip39Error { - - - - case BadWordCount(wordCount: UInt64 - ) - case UnknownWord(index: UInt64 - ) - case BadEntropyBitCount(bitCount: UInt64 - ) - case InvalidChecksum - case AmbiguousLanguages(languages: String - ) -} - - -public struct FfiConverterTypeBip39Error: FfiConverterRustBuffer { - typealias SwiftType = Bip39Error - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bip39Error { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .BadWordCount( - wordCount: try FfiConverterUInt64.read(from: &buf) - ) - case 2: return .UnknownWord( - index: try FfiConverterUInt64.read(from: &buf) - ) - case 3: return .BadEntropyBitCount( - bitCount: try FfiConverterUInt64.read(from: &buf) - ) - case 4: return .InvalidChecksum - case 5: return .AmbiguousLanguages( - languages: try FfiConverterString.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: Bip39Error, into buf: inout [UInt8]) { - switch value { - - - - - - case let .BadWordCount(wordCount): - writeInt(&buf, Int32(1)) - FfiConverterUInt64.write(wordCount, into: &buf) - - - case let .UnknownWord(index): - writeInt(&buf, Int32(2)) - FfiConverterUInt64.write(index, into: &buf) - - - case let .BadEntropyBitCount(bitCount): - writeInt(&buf, Int32(3)) - FfiConverterUInt64.write(bitCount, into: &buf) - - - case .InvalidChecksum: - writeInt(&buf, Int32(4)) - - - case let .AmbiguousLanguages(languages): - writeInt(&buf, Int32(5)) - FfiConverterString.write(languages, into: &buf) - - } - } -} - - -extension Bip39Error: Equatable, Hashable {} - -extension Bip39Error: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum CalculateFeeError { - - - - case MissingTxOut(outPoints: [OutPoint] - ) - case NegativeFee(amount: String - ) -} - - -public struct FfiConverterTypeCalculateFeeError: FfiConverterRustBuffer { - typealias SwiftType = CalculateFeeError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CalculateFeeError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .MissingTxOut( - outPoints: try FfiConverterSequenceTypeOutPoint.read(from: &buf) - ) - case 2: return .NegativeFee( - amount: try FfiConverterString.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: CalculateFeeError, into buf: inout [UInt8]) { - switch value { - - - - - - case let .MissingTxOut(outPoints): - writeInt(&buf, Int32(1)) - FfiConverterSequenceTypeOutPoint.write(outPoints, into: &buf) - - - case let .NegativeFee(amount): - writeInt(&buf, Int32(2)) - FfiConverterString.write(amount, into: &buf) - - } - } -} - - -extension CalculateFeeError: Equatable, Hashable {} - -extension CalculateFeeError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum CannotConnectError { - - - - case Include(height: UInt32 - ) -} - - -public struct FfiConverterTypeCannotConnectError: FfiConverterRustBuffer { - typealias SwiftType = CannotConnectError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CannotConnectError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .Include( - height: try FfiConverterUInt32.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: CannotConnectError, into buf: inout [UInt8]) { - switch value { - - - - - - case let .Include(height): - writeInt(&buf, Int32(1)) - FfiConverterUInt32.write(height, into: &buf) - - } - } -} - - -extension CannotConnectError: Equatable, Hashable {} - -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(confirmationBlockTime: ConfirmationBlockTime - ) - case unconfirmed(timestamp: UInt64 - ) -} - - -public struct FfiConverterTypeChainPosition: FfiConverterRustBuffer { - typealias SwiftType = ChainPosition - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ChainPosition { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .confirmed(confirmationBlockTime: try FfiConverterTypeConfirmationBlockTime.read(from: &buf) - ) - - case 2: return .unconfirmed(timestamp: try FfiConverterUInt64.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: ChainPosition, into buf: inout [UInt8]) { - switch value { - - - case let .confirmed(confirmationBlockTime): - writeInt(&buf, Int32(1)) - FfiConverterTypeConfirmationBlockTime.write(confirmationBlockTime, into: &buf) - - - case let .unconfirmed(timestamp): - writeInt(&buf, Int32(2)) - FfiConverterUInt64.write(timestamp, into: &buf) - - } - } -} - - -public func FfiConverterTypeChainPosition_lift(_ buf: RustBuffer) throws -> ChainPosition { - return try FfiConverterTypeChainPosition.lift(buf) -} - -public func FfiConverterTypeChainPosition_lower(_ value: ChainPosition) -> RustBuffer { - return FfiConverterTypeChainPosition.lower(value) -} - - - -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 - case onlyChange - case changeForbidden -} - - -public struct FfiConverterTypeChangeSpendPolicy: FfiConverterRustBuffer { - typealias SwiftType = ChangeSpendPolicy - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ChangeSpendPolicy { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .changeAllowed - - case 2: return .onlyChange - - case 3: return .changeForbidden - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: ChangeSpendPolicy, into buf: inout [UInt8]) { - switch value { - - - case .changeAllowed: - writeInt(&buf, Int32(1)) - - - case .onlyChange: - writeInt(&buf, Int32(2)) - - - case .changeForbidden: - writeInt(&buf, Int32(3)) - - } - } -} - - -public func FfiConverterTypeChangeSpendPolicy_lift(_ buf: RustBuffer) throws -> ChangeSpendPolicy { - return try FfiConverterTypeChangeSpendPolicy.lift(buf) -} - -public func FfiConverterTypeChangeSpendPolicy_lower(_ value: ChangeSpendPolicy) -> RustBuffer { - return FfiConverterTypeChangeSpendPolicy.lower(value) -} - - - -extension ChangeSpendPolicy: Equatable, Hashable {} - - - - -public enum CreateTxError { - - - - case Descriptor(errorMessage: String - ) - case Policy(errorMessage: String - ) - case SpendingPolicyRequired(kind: String - ) - case Version0 - case Version1Csv - case LockTime(requested: String, required: String - ) - case RbfSequenceCsv(sequence: String, csv: String - ) - case FeeTooLow(required: String - ) - case FeeRateTooLow(required: String - ) - case NoUtxosSelected - case OutputBelowDustLimit(index: UInt64 - ) - case ChangePolicyDescriptor - case CoinSelection(errorMessage: String - ) - case InsufficientFunds(needed: UInt64, available: UInt64 - ) - case NoRecipients - case Psbt(errorMessage: String - ) - case MissingKeyOrigin(key: String - ) - case UnknownUtxo(outpoint: String - ) - case MissingNonWitnessUtxo(outpoint: String - ) - case MiniscriptPsbt(errorMessage: String - ) -} - - -public struct FfiConverterTypeCreateTxError: FfiConverterRustBuffer { - typealias SwiftType = CreateTxError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CreateTxError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .Descriptor( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 2: return .Policy( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 3: return .SpendingPolicyRequired( - kind: try FfiConverterString.read(from: &buf) - ) - 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 7: return .RbfSequenceCsv( - sequence: try FfiConverterString.read(from: &buf), - csv: try FfiConverterString.read(from: &buf) - ) - case 8: return .FeeTooLow( - required: try FfiConverterString.read(from: &buf) - ) - case 9: return .FeeRateTooLow( - required: try FfiConverterString.read(from: &buf) - ) - case 10: return .NoUtxosSelected - case 11: return .OutputBelowDustLimit( - index: try FfiConverterUInt64.read(from: &buf) - ) - case 12: return .ChangePolicyDescriptor - case 13: return .CoinSelection( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 14: return .InsufficientFunds( - needed: try FfiConverterUInt64.read(from: &buf), - available: try FfiConverterUInt64.read(from: &buf) - ) - case 15: return .NoRecipients - case 16: return .Psbt( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 17: return .MissingKeyOrigin( - key: try FfiConverterString.read(from: &buf) - ) - case 18: return .UnknownUtxo( - outpoint: try FfiConverterString.read(from: &buf) - ) - case 19: return .MissingNonWitnessUtxo( - outpoint: try FfiConverterString.read(from: &buf) - ) - case 20: return .MiniscriptPsbt( - errorMessage: try FfiConverterString.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: CreateTxError, into buf: inout [UInt8]) { - switch value { - - - - - - case let .Descriptor(errorMessage): - writeInt(&buf, Int32(1)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Policy(errorMessage): - writeInt(&buf, Int32(2)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .SpendingPolicyRequired(kind): - writeInt(&buf, Int32(3)) - FfiConverterString.write(kind, into: &buf) - - - case .Version0: - writeInt(&buf, Int32(4)) - - - case .Version1Csv: - writeInt(&buf, Int32(5)) - - - case let .LockTime(requested,required): - writeInt(&buf, Int32(6)) - FfiConverterString.write(requested, into: &buf) - FfiConverterString.write(required, into: &buf) - - - case let .RbfSequenceCsv(sequence,csv): - writeInt(&buf, Int32(7)) - FfiConverterString.write(sequence, into: &buf) - FfiConverterString.write(csv, into: &buf) - - - case let .FeeTooLow(required): - writeInt(&buf, Int32(8)) - FfiConverterString.write(required, into: &buf) - - - case let .FeeRateTooLow(required): - writeInt(&buf, Int32(9)) - FfiConverterString.write(required, into: &buf) - - - case .NoUtxosSelected: - writeInt(&buf, Int32(10)) - - - case let .OutputBelowDustLimit(index): - writeInt(&buf, Int32(11)) - FfiConverterUInt64.write(index, into: &buf) - - - case .ChangePolicyDescriptor: - writeInt(&buf, Int32(12)) - - - case let .CoinSelection(errorMessage): - writeInt(&buf, Int32(13)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .InsufficientFunds(needed,available): - writeInt(&buf, Int32(14)) - FfiConverterUInt64.write(needed, into: &buf) - FfiConverterUInt64.write(available, into: &buf) - - - case .NoRecipients: - writeInt(&buf, Int32(15)) - - - case let .Psbt(errorMessage): - writeInt(&buf, Int32(16)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .MissingKeyOrigin(key): - writeInt(&buf, Int32(17)) - FfiConverterString.write(key, into: &buf) - - - case let .UnknownUtxo(outpoint): - writeInt(&buf, Int32(18)) - FfiConverterString.write(outpoint, into: &buf) - - - case let .MissingNonWitnessUtxo(outpoint): - writeInt(&buf, Int32(19)) - FfiConverterString.write(outpoint, into: &buf) - - - case let .MiniscriptPsbt(errorMessage): - writeInt(&buf, Int32(20)) - FfiConverterString.write(errorMessage, into: &buf) - - } - } -} - - -extension CreateTxError: Equatable, Hashable {} - -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 { - - - - case InvalidHdKeyPath - case InvalidDescriptorChecksum - case HardenedDerivationXpub - case MultiPath - case Key(errorMessage: String - ) - case Policy(errorMessage: String - ) - case InvalidDescriptorCharacter(char: String - ) - case Bip32(errorMessage: String - ) - case Base58(errorMessage: String - ) - case Pk(errorMessage: String - ) - case Miniscript(errorMessage: String - ) - case Hex(errorMessage: String - ) - case ExternalAndInternalAreTheSame -} - - -public struct FfiConverterTypeDescriptorError: FfiConverterRustBuffer { - typealias SwiftType = DescriptorError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DescriptorError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .InvalidHdKeyPath - case 2: return .InvalidDescriptorChecksum - case 3: return .HardenedDerivationXpub - case 4: return .MultiPath - case 5: return .Key( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 6: return .Policy( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 7: return .InvalidDescriptorCharacter( - char: try FfiConverterString.read(from: &buf) - ) - case 8: return .Bip32( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 9: return .Base58( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 10: return .Pk( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 11: return .Miniscript( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 12: return .Hex( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 13: return .ExternalAndInternalAreTheSame - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: DescriptorError, into buf: inout [UInt8]) { - switch value { - - - - - - case .InvalidHdKeyPath: - writeInt(&buf, Int32(1)) - - - case .InvalidDescriptorChecksum: - writeInt(&buf, Int32(2)) - - - case .HardenedDerivationXpub: - writeInt(&buf, Int32(3)) - - - case .MultiPath: - writeInt(&buf, Int32(4)) - - - case let .Key(errorMessage): - writeInt(&buf, Int32(5)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Policy(errorMessage): - writeInt(&buf, Int32(6)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .InvalidDescriptorCharacter(char): - writeInt(&buf, Int32(7)) - FfiConverterString.write(char, into: &buf) - - - case let .Bip32(errorMessage): - writeInt(&buf, Int32(8)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Base58(errorMessage): - writeInt(&buf, Int32(9)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Pk(errorMessage): - writeInt(&buf, Int32(10)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Miniscript(errorMessage): - writeInt(&buf, Int32(11)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Hex(errorMessage): - writeInt(&buf, Int32(12)) - FfiConverterString.write(errorMessage, into: &buf) - - - case .ExternalAndInternalAreTheSame: - writeInt(&buf, Int32(13)) - - } - } -} - - -extension DescriptorError: Equatable, Hashable {} - -extension DescriptorError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum DescriptorKeyError { - - - - case Parse(errorMessage: String - ) - case InvalidKeyType - case Bip32(errorMessage: String - ) -} - - -public struct FfiConverterTypeDescriptorKeyError: FfiConverterRustBuffer { - typealias SwiftType = DescriptorKeyError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DescriptorKeyError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .Parse( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 2: return .InvalidKeyType - case 3: return .Bip32( - errorMessage: try FfiConverterString.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: DescriptorKeyError, into buf: inout [UInt8]) { - switch value { - - - - - - case let .Parse(errorMessage): - writeInt(&buf, Int32(1)) - FfiConverterString.write(errorMessage, into: &buf) - - - case .InvalidKeyType: - writeInt(&buf, Int32(2)) - - - case let .Bip32(errorMessage): - writeInt(&buf, Int32(3)) - FfiConverterString.write(errorMessage, into: &buf) - - } - } -} - - -extension DescriptorKeyError: Equatable, Hashable {} - -extension DescriptorKeyError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum ElectrumError { - - - - case IoError(errorMessage: String - ) - case Json(errorMessage: String - ) - case Hex(errorMessage: String - ) - case Protocol(errorMessage: String - ) - case Bitcoin(errorMessage: String - ) - case AlreadySubscribed - case NotSubscribed - case InvalidResponse(errorMessage: String - ) - case Message(errorMessage: String - ) - case InvalidDnsNameError(domain: String - ) - case MissingDomain - case AllAttemptsErrored - case SharedIoError(errorMessage: String - ) - case CouldntLockReader - case Mpsc - case CouldNotCreateConnection(errorMessage: String - ) - case RequestAlreadyConsumed -} - - -public struct FfiConverterTypeElectrumError: FfiConverterRustBuffer { - typealias SwiftType = ElectrumError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ElectrumError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .IoError( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 2: return .Json( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 3: return .Hex( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 4: return .Protocol( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 5: return .Bitcoin( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 6: return .AlreadySubscribed - case 7: return .NotSubscribed - case 8: return .InvalidResponse( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 9: return .Message( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 10: return .InvalidDnsNameError( - domain: try FfiConverterString.read(from: &buf) - ) - case 11: return .MissingDomain - case 12: return .AllAttemptsErrored - case 13: return .SharedIoError( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 14: return .CouldntLockReader - case 15: return .Mpsc - case 16: return .CouldNotCreateConnection( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 17: return .RequestAlreadyConsumed - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: ElectrumError, into buf: inout [UInt8]) { - switch value { - - - - - - case let .IoError(errorMessage): - writeInt(&buf, Int32(1)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Json(errorMessage): - writeInt(&buf, Int32(2)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Hex(errorMessage): - writeInt(&buf, Int32(3)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Protocol(errorMessage): - writeInt(&buf, Int32(4)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Bitcoin(errorMessage): - writeInt(&buf, Int32(5)) - FfiConverterString.write(errorMessage, into: &buf) - - - case .AlreadySubscribed: - writeInt(&buf, Int32(6)) - - - case .NotSubscribed: - writeInt(&buf, Int32(7)) - - - case let .InvalidResponse(errorMessage): - writeInt(&buf, Int32(8)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Message(errorMessage): - writeInt(&buf, Int32(9)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .InvalidDnsNameError(domain): - writeInt(&buf, Int32(10)) - FfiConverterString.write(domain, into: &buf) - - - case .MissingDomain: - writeInt(&buf, Int32(11)) - - - case .AllAttemptsErrored: - writeInt(&buf, Int32(12)) - - - case let .SharedIoError(errorMessage): - writeInt(&buf, Int32(13)) - FfiConverterString.write(errorMessage, into: &buf) - - - case .CouldntLockReader: - writeInt(&buf, Int32(14)) - - - case .Mpsc: - writeInt(&buf, Int32(15)) - - - case let .CouldNotCreateConnection(errorMessage): - writeInt(&buf, Int32(16)) - FfiConverterString.write(errorMessage, into: &buf) - - - case .RequestAlreadyConsumed: - writeInt(&buf, Int32(17)) - - } - } -} - - -extension ElectrumError: Equatable, Hashable {} - -extension ElectrumError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum EsploraError { - - - - case Minreq(errorMessage: String - ) - case HttpResponse(status: UInt16, errorMessage: String - ) - case Parsing(errorMessage: String - ) - case StatusCode(errorMessage: String - ) - case BitcoinEncoding(errorMessage: String - ) - case HexToArray(errorMessage: String - ) - case HexToBytes(errorMessage: String - ) - case TransactionNotFound - case HeaderHeightNotFound(height: UInt32 - ) - case HeaderHashNotFound - case InvalidHttpHeaderName(name: String - ) - case InvalidHttpHeaderValue(value: String - ) - case RequestAlreadyConsumed -} - - -public struct FfiConverterTypeEsploraError: FfiConverterRustBuffer { - typealias SwiftType = EsploraError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> EsploraError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .Minreq( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 2: return .HttpResponse( - status: try FfiConverterUInt16.read(from: &buf), - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 3: return .Parsing( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 4: return .StatusCode( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 5: return .BitcoinEncoding( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 6: return .HexToArray( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 7: return .HexToBytes( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 8: return .TransactionNotFound - case 9: return .HeaderHeightNotFound( - height: try FfiConverterUInt32.read(from: &buf) - ) - case 10: return .HeaderHashNotFound - case 11: return .InvalidHttpHeaderName( - name: try FfiConverterString.read(from: &buf) - ) - case 12: return .InvalidHttpHeaderValue( - value: try FfiConverterString.read(from: &buf) - ) - case 13: return .RequestAlreadyConsumed - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: EsploraError, into buf: inout [UInt8]) { - switch value { - - - - - - case let .Minreq(errorMessage): - writeInt(&buf, Int32(1)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .HttpResponse(status,errorMessage): - writeInt(&buf, Int32(2)) - FfiConverterUInt16.write(status, into: &buf) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Parsing(errorMessage): - writeInt(&buf, Int32(3)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .StatusCode(errorMessage): - writeInt(&buf, Int32(4)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .BitcoinEncoding(errorMessage): - writeInt(&buf, Int32(5)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .HexToArray(errorMessage): - writeInt(&buf, Int32(6)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .HexToBytes(errorMessage): - writeInt(&buf, Int32(7)) - FfiConverterString.write(errorMessage, into: &buf) - - - case .TransactionNotFound: - writeInt(&buf, Int32(8)) - - - case let .HeaderHeightNotFound(height): - writeInt(&buf, Int32(9)) - FfiConverterUInt32.write(height, into: &buf) - - - case .HeaderHashNotFound: - writeInt(&buf, Int32(10)) - - - case let .InvalidHttpHeaderName(name): - writeInt(&buf, Int32(11)) - FfiConverterString.write(name, into: &buf) - - - case let .InvalidHttpHeaderValue(value): - writeInt(&buf, Int32(12)) - FfiConverterString.write(value, into: &buf) - - - case .RequestAlreadyConsumed: - writeInt(&buf, Int32(13)) - - } - } -} - - -extension EsploraError: Equatable, Hashable {} - -extension EsploraError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum ExtractTxError { - - - - case AbsurdFeeRate(feeRate: UInt64 - ) - case MissingInputValue - case SendingTooMuch - case OtherExtractTxErr -} - - -public struct FfiConverterTypeExtractTxError: FfiConverterRustBuffer { - typealias SwiftType = ExtractTxError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ExtractTxError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .AbsurdFeeRate( - feeRate: try FfiConverterUInt64.read(from: &buf) - ) - case 2: return .MissingInputValue - case 3: return .SendingTooMuch - case 4: return .OtherExtractTxErr - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: ExtractTxError, into buf: inout [UInt8]) { - switch value { - - - - - - case let .AbsurdFeeRate(feeRate): - writeInt(&buf, Int32(1)) - FfiConverterUInt64.write(feeRate, into: &buf) - - - case .MissingInputValue: - writeInt(&buf, Int32(2)) - - - case .SendingTooMuch: - writeInt(&buf, Int32(3)) - - - case .OtherExtractTxErr: - writeInt(&buf, Int32(4)) - - } - } -} - - -extension ExtractTxError: Equatable, Hashable {} - -extension ExtractTxError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum FromScriptError { - - - - case UnrecognizedScript - case WitnessProgram(errorMessage: String - ) - case WitnessVersion(errorMessage: String - ) - case OtherFromScriptErr -} - - -public struct FfiConverterTypeFromScriptError: FfiConverterRustBuffer { - typealias SwiftType = FromScriptError - - 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 .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 - } - } - - public static func write(_ value: FromScriptError, into buf: inout [UInt8]) { - switch value { - - - - - - 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 FromScriptError: Equatable, Hashable {} - -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 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeychainKind { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .external - - 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 { - - - - - 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: LoadWithPersistError, into buf: inout [UInt8]) { - switch value { - - - - - - case let .Persist(errorMessage): - writeInt(&buf, Int32(1)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .InvalidChangeSet(errorMessage): - writeInt(&buf, Int32(2)) - FfiConverterString.write(errorMessage, into: &buf) - - - case .CouldNotLoad: - writeInt(&buf, Int32(3)) - - } - } -} - - -extension LoadWithPersistError: Equatable, Hashable {} - -extension LoadWithPersistError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum PersistenceError { - - - - case Write(errorMessage: String - ) -} - - -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 .Write( - errorMessage: try FfiConverterString.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: PersistenceError, into buf: inout [UInt8]) { - switch value { - - - - - - case let .Write(errorMessage): - writeInt(&buf, Int32(1)) - FfiConverterString.write(errorMessage, into: &buf) - - } - } -} - - -extension PersistenceError: Equatable, Hashable {} - -extension PersistenceError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum PsbtError { - - - - case InvalidMagic - case MissingUtxo - case InvalidSeparator - case PsbtUtxoOutOfBounds - case InvalidKey(key: String - ) - case InvalidProprietaryKey - case DuplicateKey(key: String - ) - case UnsignedTxHasScriptSigs - case UnsignedTxHasScriptWitnesses - case MustHaveUnsignedTx - case NoMorePairs - case UnexpectedUnsignedTx - case NonStandardSighashType(sighash: UInt32 - ) - 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 FfiConverterTypePsbtError: FfiConverterRustBuffer { - typealias SwiftType = PsbtError - - 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 .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 25: return .InvalidControlBlock - case 26: return .InvalidLeafVersion - case 27: return .Taproot - case 28: return .TapTree( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 29: return .XPubKey - case 30: return .Version( - errorMessage: try FfiConverterString.read(from: &buf) - ) - 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: PsbtError, into buf: inout [UInt8]) { - switch value { - - - - - - case .InvalidMagic: - writeInt(&buf, Int32(1)) - - - case .MissingUtxo: - writeInt(&buf, Int32(2)) - - - case .InvalidSeparator: - writeInt(&buf, Int32(3)) - - - case .PsbtUtxoOutOfBounds: - writeInt(&buf, Int32(4)) - - - case let .InvalidKey(key): - writeInt(&buf, Int32(5)) - FfiConverterString.write(key, into: &buf) - - - 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 .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 .InvalidTaprootSignature(errorMessage): - writeInt(&buf, Int32(24)) - FfiConverterString.write(errorMessage, into: &buf) - - - 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 PsbtError: Equatable, Hashable {} - -extension PsbtError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum PsbtParseError { - - - - case PsbtEncoding(errorMessage: String - ) - case Base64Encoding(errorMessage: String - ) -} - - -public struct FfiConverterTypePsbtParseError: FfiConverterRustBuffer { - typealias SwiftType = PsbtParseError - - 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 .PsbtEncoding( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 2: return .Base64Encoding( - errorMessage: try FfiConverterString.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: PsbtParseError, into buf: inout [UInt8]) { - switch value { - - - - - - 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 PsbtParseError: Equatable, Hashable {} - -extension PsbtParseError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum RequestBuilderError { - - - - case RequestAlreadyConsumed -} - - -public struct FfiConverterTypeRequestBuilderError: FfiConverterRustBuffer { - typealias SwiftType = RequestBuilderError - - 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 .RequestAlreadyConsumed - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: RequestBuilderError, into buf: inout [UInt8]) { - switch value { - - - - - - case .RequestAlreadyConsumed: - writeInt(&buf, Int32(1)) - - } - } -} - - -extension RequestBuilderError: Equatable, Hashable {} - -extension RequestBuilderError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum SignerError { - - - - case MissingKey - case InvalidKey - case UserCanceled - case InputIndexOutOfRange - case MissingNonWitnessUtxo - case InvalidNonWitnessUtxo - case MissingWitnessUtxo - case MissingWitnessScript - case MissingHdKeypath - case NonStandardSighash - case InvalidSighash - case SighashP2wpkh(errorMessage: String - ) - case SighashTaproot(errorMessage: String - ) - case TxInputsIndexError(errorMessage: String - ) - case MiniscriptPsbt(errorMessage: String - ) - case External(errorMessage: String - ) - case Psbt(errorMessage: String - ) -} - - -public struct FfiConverterTypeSignerError: FfiConverterRustBuffer { - typealias SwiftType = SignerError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SignerError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .MissingKey - case 2: return .InvalidKey - case 3: return .UserCanceled - case 4: return .InputIndexOutOfRange - case 5: return .MissingNonWitnessUtxo - case 6: return .InvalidNonWitnessUtxo - case 7: return .MissingWitnessUtxo - case 8: return .MissingWitnessScript - case 9: return .MissingHdKeypath - case 10: return .NonStandardSighash - case 11: return .InvalidSighash - 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 16: return .External( - errorMessage: try FfiConverterString.read(from: &buf) - ) - case 17: return .Psbt( - errorMessage: try FfiConverterString.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: SignerError, into buf: inout [UInt8]) { - switch value { - - - - - - case .MissingKey: - writeInt(&buf, Int32(1)) - - - case .InvalidKey: - writeInt(&buf, Int32(2)) - - - case .UserCanceled: - writeInt(&buf, Int32(3)) - - - case .InputIndexOutOfRange: - writeInt(&buf, Int32(4)) - - - case .MissingNonWitnessUtxo: - writeInt(&buf, Int32(5)) - - - case .InvalidNonWitnessUtxo: - writeInt(&buf, Int32(6)) - - - case .MissingWitnessUtxo: - writeInt(&buf, Int32(7)) - - - case .MissingWitnessScript: - writeInt(&buf, Int32(8)) - - - case .MissingHdKeypath: - writeInt(&buf, Int32(9)) - - - case .NonStandardSighash: - writeInt(&buf, Int32(10)) - - - case .InvalidSighash: - writeInt(&buf, Int32(11)) - - - 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(15)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .External(errorMessage): - writeInt(&buf, Int32(16)) - FfiConverterString.write(errorMessage, into: &buf) - - - case let .Psbt(errorMessage): - writeInt(&buf, Int32(17)) - FfiConverterString.write(errorMessage, into: &buf) - - } - } -} - - -extension SignerError: Equatable, Hashable {} - -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 { - - - - case Io - case OversizedVectorAllocation - case InvalidChecksum(expected: String, actual: String - ) - case NonMinimalVarInt - case ParseFailed - case UnsupportedSegwitFlag(flag: UInt8 - ) - case OtherTransactionErr -} - - -public struct FfiConverterTypeTransactionError: FfiConverterRustBuffer { - typealias SwiftType = TransactionError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TransactionError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .Io - case 2: return .OversizedVectorAllocation - case 3: return .InvalidChecksum( - expected: try FfiConverterString.read(from: &buf), - actual: try FfiConverterString.read(from: &buf) - ) - case 4: return .NonMinimalVarInt - case 5: return .ParseFailed - case 6: return .UnsupportedSegwitFlag( - flag: try FfiConverterUInt8.read(from: &buf) - ) - case 7: return .OtherTransactionErr - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: TransactionError, into buf: inout [UInt8]) { - switch value { - - - - - - case .Io: - writeInt(&buf, Int32(1)) - - - case .OversizedVectorAllocation: - writeInt(&buf, Int32(2)) - - - case let .InvalidChecksum(expected,actual): - writeInt(&buf, Int32(3)) - FfiConverterString.write(expected, into: &buf) - FfiConverterString.write(actual, into: &buf) - - - case .NonMinimalVarInt: - writeInt(&buf, Int32(4)) - - - case .ParseFailed: - writeInt(&buf, Int32(5)) - - - case let .UnsupportedSegwitFlag(flag): - writeInt(&buf, Int32(6)) - FfiConverterUInt8.write(flag, into: &buf) - - - case .OtherTransactionErr: - writeInt(&buf, Int32(7)) - - } - } -} - - -extension TransactionError: Equatable, Hashable {} - -extension TransactionError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -public enum TxidParseError { - - - - case InvalidTxid(txid: String - ) -} - - -public struct FfiConverterTypeTxidParseError: FfiConverterRustBuffer { - typealias SwiftType = TxidParseError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TxidParseError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .InvalidTxid( - txid: try FfiConverterString.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: TxidParseError, into buf: inout [UInt8]) { - switch value { - - - - - - case let .InvalidTxid(txid): - writeInt(&buf, Int32(1)) - FfiConverterString.write(txid, into: &buf) - - } - } -} - - -extension TxidParseError: Equatable, Hashable {} - -extension TxidParseError: 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 WordCount { - - case words12 - case words15 - case words18 - case words21 - case words24 -} - - -public struct FfiConverterTypeWordCount: FfiConverterRustBuffer { - typealias SwiftType = WordCount - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> WordCount { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .words12 - - case 2: return .words15 - - case 3: return .words18 - - case 4: return .words21 - - case 5: return .words24 - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: WordCount, into buf: inout [UInt8]) { - switch value { - - - case .words12: - writeInt(&buf, Int32(1)) - - - case .words15: - writeInt(&buf, Int32(2)) - - - case .words18: - writeInt(&buf, Int32(3)) - - - case .words21: - writeInt(&buf, Int32(4)) - - - case .words24: - writeInt(&buf, Int32(5)) - - } - } -} - - -public func FfiConverterTypeWordCount_lift(_ buf: RustBuffer) throws -> WordCount { - return try FfiConverterTypeWordCount.lift(buf) -} - -public func FfiConverterTypeWordCount_lower(_ value: WordCount) -> RustBuffer { - return FfiConverterTypeWordCount.lower(value) -} - - - -extension WordCount: Equatable, Hashable {} - - - -fileprivate struct FfiConverterOptionUInt32: FfiConverterRustBuffer { - typealias SwiftType = UInt32? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - 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 FfiConverterUInt32.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { - typealias SwiftType = String? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - 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 FfiConverterString.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -fileprivate struct FfiConverterOptionTypeTransaction: FfiConverterRustBuffer { - typealias SwiftType = Transaction? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterTypeTransaction.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 FfiConverterTypeTransaction.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -fileprivate struct FfiConverterOptionTypeCanonicalTx: FfiConverterRustBuffer { - typealias SwiftType = CanonicalTx? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterTypeCanonicalTx.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 FfiConverterTypeCanonicalTx.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -fileprivate struct FfiConverterOptionTypeKeychainAndIndex: FfiConverterRustBuffer { - typealias SwiftType = KeychainAndIndex? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterTypeKeychainAndIndex.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 FfiConverterTypeKeychainAndIndex.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -fileprivate struct FfiConverterOptionTypeLocalOutput: FfiConverterRustBuffer { - typealias SwiftType = LocalOutput? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterTypeLocalOutput.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 FfiConverterTypeLocalOutput.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -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 - } -} - -fileprivate struct FfiConverterSequenceTypeAddressInfo: FfiConverterRustBuffer { - typealias SwiftType = [AddressInfo] - - public static func write(_ value: [AddressInfo], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterTypeAddressInfo.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [AddressInfo] { - let len: Int32 = try readInt(&buf) - var seq = [AddressInfo]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterTypeAddressInfo.read(from: &buf)) - } - return seq - } -} - -fileprivate struct FfiConverterSequenceTypeCanonicalTx: FfiConverterRustBuffer { - typealias SwiftType = [CanonicalTx] - - public static func write(_ value: [CanonicalTx], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterTypeCanonicalTx.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [CanonicalTx] { - let len: Int32 = try readInt(&buf) - var seq = [CanonicalTx]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterTypeCanonicalTx.read(from: &buf)) - } - return seq - } -} - -fileprivate struct FfiConverterSequenceTypeLocalOutput: FfiConverterRustBuffer { - typealias SwiftType = [LocalOutput] - - public static func write(_ value: [LocalOutput], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterTypeLocalOutput.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [LocalOutput] { - let len: Int32 = try readInt(&buf) - var seq = [LocalOutput]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterTypeLocalOutput.read(from: &buf)) - } - return seq - } -} - -fileprivate struct FfiConverterSequenceTypeScriptAmount: FfiConverterRustBuffer { - typealias SwiftType = [ScriptAmount] - - public static func write(_ value: [ScriptAmount], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterTypeScriptAmount.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [ScriptAmount] { - let len: Int32 = try readInt(&buf) - var seq = [ScriptAmount]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterTypeScriptAmount.read(from: &buf)) - } - return seq - } -} - -fileprivate struct FfiConverterSequenceTypeTxIn: FfiConverterRustBuffer { - typealias SwiftType = [TxIn] - - public static func write(_ value: [TxIn], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterTypeTxIn.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [TxIn] { - let len: Int32 = try readInt(&buf) - var seq = [TxIn]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterTypeTxIn.read(from: &buf)) - } - return seq - } -} - -fileprivate struct FfiConverterSequenceTypeTxOut: FfiConverterRustBuffer { - typealias SwiftType = [TxOut] - - public static func write(_ value: [TxOut], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterTypeTxOut.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [TxOut] { - let len: Int32 = try readInt(&buf) - var seq = [TxOut]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterTypeTxOut.read(from: &buf)) - } - return seq - } -} - -fileprivate struct FfiConverterSequenceSequenceUInt8: 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 { - FfiConverterSequenceUInt8.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 FfiConverterSequenceUInt8.read(from: &buf)) - } - return seq - } -} - -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 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_bdkffi_uniffi_contract_version() - if bindings_contract_version != scaffolding_contract_version { - return InitializationResult.contractVersionMismatch - } - if (uniffi_bdkffi_checksum_method_address_is_valid_for_network() != 2364) { - return InitializationResult.apiChecksumMismatch - } - 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_bumpfeetxbuilder_finish() != 18299) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_bumpfeetxbuilder_set_exact_sequence() != 35609) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_descriptor_to_string_with_secret() != 18986) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_descriptorpublickey_as_string() != 37256) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_descriptorpublickey_derive() != 42652) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_descriptorpublickey_extend() != 46128) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_descriptorsecretkey_as_public() != 56954) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_descriptorsecretkey_as_string() != 28335) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_descriptorsecretkey_derive() != 61335) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_descriptorsecretkey_extend() != 19969) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_descriptorsecretkey_secret_bytes() != 40876) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_electrumclient_broadcast() != 47170) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_electrumclient_full_scan() != 63481) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_electrumclient_sync() != 23534) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_esploraclient_broadcast() != 21200) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_esploraclient_full_scan() != 30443) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_esploraclient_get_tx() != 59770) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_esploraclient_sync() != 39911) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_fullscanrequestbuilder_build() != 56245) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_fullscanrequestbuilder_inspect_spks_for_all_keychains() != 6853) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_fullscanscriptinspector_inspect() != 62348) { - return InitializationResult.apiChecksumMismatch - } - 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_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) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_transaction_is_coinbase() != 14454) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_transaction_is_explicitly_rbf() != 32682) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_transaction_is_lock_time_enabled() != 48885) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_transaction_lock_time() != 49321) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_transaction_output() != 30237) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_transaction_serialize() != 62862) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_transaction_total_size() != 12759) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_transaction_version() != 15271) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_transaction_vsize() != 3804) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_transaction_weight() != 21879) { - return InitializationResult.apiChecksumMismatch - } - 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() != 14416) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_txbuilder_add_utxo() != 14001) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_txbuilder_change_policy() != 22333) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_txbuilder_do_not_spend_change() != 51770) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_txbuilder_drain_to() != 29829) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_txbuilder_drain_wallet() != 5081) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_txbuilder_fee_absolute() != 28626) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_txbuilder_fee_rate() != 49200) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_txbuilder_finish() != 61082) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_txbuilder_manually_selected_only() != 12623) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_txbuilder_only_spend_change() != 18757) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_txbuilder_set_exact_sequence() != 35105) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_txbuilder_set_recipients() != 20461) { - return InitializationResult.apiChecksumMismatch - } - 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_balance() != 32173) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_calculate_fee() != 39344) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_calculate_fee_rate() != 23373) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_cancel_tx() != 27219) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_derivation_index() != 63084) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_derivation_of_spk() != 3430) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_descriptor_checksum() != 60436) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_finalize_psbt() != 44900) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_get_tx() != 59450) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_get_utxo() != 3914) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_is_mine() != 36368) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_list_output() != 27359) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_list_unspent() != 25643) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_list_unused_addresses() != 1695) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_mark_used() != 51163) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_network() != 21775) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_next_derivation_index() != 47127) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_next_unused_address() != 18644) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_peek_address() != 47647) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_persist() != 14909) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_reveal_addresses_to() != 10653) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_reveal_next_address() != 54031) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_sent_and_received() != 15077) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_sign() != 15606) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_method_wallet_start_full_scan() != 3023) { - return InitializationResult.apiChecksumMismatch - } - 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_from_script() != 28697) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_address_new() != 42937) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_bumpfeetxbuilder_new() != 33618) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_connection_new() != 59352) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_connection_new_in_memory() != 31408) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_derivationpath_new() != 6139) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_descriptor_new() != 64471) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip44() != 56381) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip44_public() != 7263) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip49() != 38651) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip49_public() != 34965) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip84() != 48402) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip84_public() != 13927) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip86() != 30427) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_descriptor_new_bip86_public() != 14236) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_descriptorpublickey_from_string() != 34928) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_descriptorsecretkey_from_string() != 56519) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_descriptorsecretkey_new() != 29746) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_electrumclient_new() != 10238) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_esploraclient_new() != 19298) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_mnemonic_from_entropy() != 16992) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_mnemonic_from_string() != 56187) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_mnemonic_new() != 51578) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_psbt_new() != 33069) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_transaction_new() != 58769) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_txbuilder_new() != 6280) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_wallet_load() != 21717) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_bdkffi_checksum_constructor_wallet_new() != 51039) { - return InitializationResult.apiChecksumMismatch - } - - uniffiCallbackInitFullScanScriptInspector() - uniffiCallbackInitSyncScriptInspector() - 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