2021-11-24 00:10:26 -08:00
|
|
|
// This file was autogenerated by some hot garbage in the `uniffi` crate.
|
|
|
|
// Trust me, you don't want to mess with it!
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
// Depending on the consumer's build setup, the low-level FFI code
|
|
|
|
// might be in a separate module, or it might be compiled inline into
|
|
|
|
// this module. This is a bit of light hackery to work with both.
|
|
|
|
#if canImport(bdkFFI)
|
|
|
|
import bdkFFI
|
|
|
|
#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 from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
|
2022-10-21 17:18:30 -05:00
|
|
|
try! rustCall { ffi_bdk_1724_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Frees the buffer in place.
|
|
|
|
// The buffer must not be used after this is called.
|
|
|
|
func deallocate() {
|
2022-10-21 17:18:30 -05:00
|
|
|
try! rustCall { ffi_bdk_1724_rustbuffer_free(self, $0) }
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate extension ForeignBytes {
|
|
|
|
init(bufferPointer: UnsafeBufferPointer<UInt8>) {
|
|
|
|
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 libray 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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A helper class to read values out of a byte buffer.
|
|
|
|
fileprivate class Reader {
|
|
|
|
let data: Data
|
|
|
|
var offset: Data.Index
|
|
|
|
|
|
|
|
init(data: Data) {
|
|
|
|
self.data = data
|
|
|
|
self.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.
|
|
|
|
func readInt<T: FixedWidthInteger>() throws -> T {
|
|
|
|
let range = offset..<offset + MemoryLayout<T>.size
|
|
|
|
guard data.count >= range.upperBound else {
|
|
|
|
throw UniffiInternalError.bufferOverflow
|
|
|
|
}
|
|
|
|
if T.self == UInt8.self {
|
|
|
|
let value = data[offset]
|
|
|
|
offset += 1
|
|
|
|
return value as! T
|
|
|
|
}
|
|
|
|
var value: T = 0
|
|
|
|
let _ = withUnsafeMutableBytes(of: &value, { data.copyBytes(to: $0, from: range)})
|
|
|
|
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
|
|
|
|
func readBytes(count: Int) throws -> Array<UInt8> {
|
|
|
|
let range = offset..<(offset+count)
|
|
|
|
guard data.count >= range.upperBound else {
|
|
|
|
throw UniffiInternalError.bufferOverflow
|
|
|
|
}
|
|
|
|
var value = [UInt8](repeating: 0, count: count)
|
|
|
|
value.withUnsafeMutableBufferPointer({ buffer in
|
|
|
|
data.copyBytes(to: buffer, from: range)
|
|
|
|
})
|
|
|
|
offset = range.upperBound
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reads a float at the current offset.
|
|
|
|
@inlinable
|
|
|
|
func readFloat() throws -> Float {
|
|
|
|
return Float(bitPattern: try readInt())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reads a float at the current offset.
|
|
|
|
@inlinable
|
|
|
|
func readDouble() throws -> Double {
|
|
|
|
return Double(bitPattern: try readInt())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Indicates if the offset has reached the end of the buffer.
|
|
|
|
@inlinable
|
|
|
|
func hasRemaining() -> Bool {
|
|
|
|
return offset < data.count
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A helper class to write values into a byte buffer.
|
|
|
|
fileprivate class Writer {
|
|
|
|
var bytes: [UInt8]
|
|
|
|
var offset: Array<UInt8>.Index
|
|
|
|
|
|
|
|
init() {
|
|
|
|
self.bytes = []
|
|
|
|
self.offset = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func writeBytes<S>(_ byteArr: S) where S: Sequence, S.Element == UInt8 {
|
|
|
|
bytes.append(contentsOf: byteArr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Writes an integer in big-endian order.
|
|
|
|
//
|
|
|
|
// Warning: make sure what you are trying to write
|
|
|
|
// is in the correct type!
|
|
|
|
func writeInt<T: FixedWidthInteger>(_ value: T) {
|
|
|
|
var value = value.bigEndian
|
|
|
|
withUnsafeBytes(of: &value) { bytes.append(contentsOf: $0) }
|
|
|
|
}
|
|
|
|
|
|
|
|
@inlinable
|
|
|
|
func writeFloat(_ value: Float) {
|
|
|
|
writeInt(value.bitPattern)
|
|
|
|
}
|
|
|
|
|
|
|
|
@inlinable
|
|
|
|
func writeDouble(_ value: Double) {
|
|
|
|
writeInt(value.bitPattern)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
// Protocol for types that transfer other types across the FFI. This is
|
|
|
|
// analogous go the Rust trait of the same name.
|
|
|
|
fileprivate protocol FfiConverter {
|
2021-11-24 00:10:26 -08:00
|
|
|
associatedtype FfiType
|
2022-10-21 17:18:30 -05:00
|
|
|
associatedtype SwiftType
|
|
|
|
|
|
|
|
static func lift(_ value: FfiType) throws -> SwiftType
|
|
|
|
static func lower(_ value: SwiftType) -> FfiType
|
|
|
|
static func read(from buf: Reader) throws -> SwiftType
|
|
|
|
static func write(_ value: SwiftType, into buf: Writer)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Types conforming to `Primitive` pass themselves directly over the FFI.
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
extension FfiConverterPrimitive {
|
|
|
|
static func lift(_ value: FfiType) throws -> SwiftType {
|
|
|
|
return value
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lower(_ value: SwiftType) -> FfiType {
|
|
|
|
return value
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
// 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 {}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
extension FfiConverterRustBuffer {
|
|
|
|
static func lift(_ buf: RustBuffer) throws -> SwiftType {
|
|
|
|
let reader = Reader(data: Data(rustBuffer: buf))
|
|
|
|
let value = try read(from: reader)
|
|
|
|
if reader.hasRemaining() {
|
|
|
|
throw UniffiInternalError.incompleteData
|
|
|
|
}
|
|
|
|
buf.deallocate()
|
|
|
|
return value
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lower(_ value: SwiftType) -> RustBuffer {
|
|
|
|
let writer = Writer()
|
|
|
|
write(value, into: writer)
|
|
|
|
return RustBuffer(bytes: writer.bytes)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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 let CALL_SUCCESS: Int8 = 0
|
|
|
|
fileprivate let CALL_ERROR: Int8 = 1
|
|
|
|
fileprivate let CALL_PANIC: Int8 = 2
|
|
|
|
|
|
|
|
fileprivate extension RustCallStatus {
|
|
|
|
init() {
|
|
|
|
self.init(
|
|
|
|
code: CALL_SUCCESS,
|
|
|
|
errorBuf: RustBuffer.init(
|
|
|
|
capacity: 0,
|
|
|
|
len: 0,
|
|
|
|
data: nil
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
|
|
|
|
try makeRustCall(callback, errorHandler: {
|
|
|
|
$0.deallocate()
|
|
|
|
return UniffiInternalError.unexpectedRustCallError
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
private func rustCallWithError<T, F: FfiConverter>
|
|
|
|
(_ errorFfiConverter: F.Type, _ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T
|
|
|
|
where F.SwiftType: Error, F.FfiType == RustBuffer
|
|
|
|
{
|
|
|
|
try makeRustCall(callback, errorHandler: { return try errorFfiConverter.lift($0) })
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private func makeRustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T, errorHandler: (RustBuffer) throws -> Error) throws -> T {
|
|
|
|
var callStatus = RustCallStatus.init()
|
|
|
|
let returnedVal = callback(&callStatus)
|
|
|
|
switch callStatus.code {
|
|
|
|
case CALL_SUCCESS:
|
|
|
|
return returnedVal
|
|
|
|
|
|
|
|
case CALL_ERROR:
|
|
|
|
throw try errorHandler(callStatus.errorBuf)
|
|
|
|
|
|
|
|
case CALL_PANIC:
|
|
|
|
// 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 {
|
2022-10-21 17:18:30 -05:00
|
|
|
throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
|
2021-11-24 00:10:26 -08:00
|
|
|
} else {
|
|
|
|
callStatus.errorBuf.deallocate()
|
|
|
|
throw UniffiInternalError.rustPanic("Rust panic")
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw UniffiInternalError.unexpectedRustCallStatusCode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
// Public interface members begin here.
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterUInt8: FfiConverterPrimitive {
|
|
|
|
typealias FfiType = UInt8
|
|
|
|
typealias SwiftType = UInt8
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> UInt8 {
|
|
|
|
return try lift(buf.readInt())
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: UInt8, into buf: Writer) {
|
|
|
|
buf.writeInt(lower(value))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterUInt32: FfiConverterPrimitive {
|
|
|
|
typealias FfiType = UInt32
|
|
|
|
typealias SwiftType = UInt32
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> UInt32 {
|
|
|
|
return try lift(buf.readInt())
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: SwiftType, into buf: Writer) {
|
|
|
|
buf.writeInt(lower(value))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterUInt64: FfiConverterPrimitive {
|
|
|
|
typealias FfiType = UInt64
|
|
|
|
typealias SwiftType = UInt64
|
|
|
|
|
|
|
|
static func read(from buf: Reader) throws -> UInt64 {
|
|
|
|
return try lift(buf.readInt())
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: SwiftType, into buf: Writer) {
|
|
|
|
buf.writeInt(lower(value))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterFloat: FfiConverterPrimitive {
|
|
|
|
typealias FfiType = Float
|
|
|
|
typealias SwiftType = Float
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> Float {
|
|
|
|
return try lift(buf.readFloat())
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: Float, into buf: Writer) {
|
|
|
|
buf.writeFloat(lower(value))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterBool : FfiConverter {
|
|
|
|
typealias FfiType = Int8
|
|
|
|
typealias SwiftType = Bool
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lift(_ value: Int8) throws -> Bool {
|
|
|
|
return value != 0
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lower(_ value: Bool) -> Int8 {
|
|
|
|
return value ? 1 : 0
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> Bool {
|
|
|
|
return try lift(buf.readInt())
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: Bool, into buf: Writer) {
|
|
|
|
buf.writeInt(lower(value))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterString: FfiConverter {
|
|
|
|
typealias SwiftType = String
|
|
|
|
typealias FfiType = RustBuffer
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lift(_ value: RustBuffer) throws -> String {
|
|
|
|
defer {
|
|
|
|
value.deallocate()
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
if value.data == nil {
|
|
|
|
return String()
|
|
|
|
}
|
|
|
|
let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
|
|
|
|
return String(bytes: bytes, encoding: String.Encoding.utf8)!
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> String {
|
|
|
|
let len: Int32 = try buf.readInt()
|
|
|
|
return String(bytes: try buf.readBytes(count: Int(len)), encoding: String.Encoding.utf8)!
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: String, into buf: Writer) {
|
|
|
|
let len = Int32(value.utf8.count)
|
|
|
|
buf.writeInt(len)
|
|
|
|
buf.writeBytes(value.utf8)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 11:03:45 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public protocol AddressProtocol {
|
|
|
|
func `scriptPubkey`() -> Script
|
2022-06-23 11:03:45 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public class Address: AddressProtocol {
|
|
|
|
fileprivate let pointer: UnsafeMutableRawPointer
|
2022-06-23 11:03:45 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
// TODO: We'd like this to be `private` but for Swifty reasons,
|
|
|
|
// we can't implement `FfiConverter` without making this `required` and we can't
|
|
|
|
// make it `required` without making it `public`.
|
|
|
|
required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
|
|
self.pointer = pointer
|
|
|
|
}
|
|
|
|
public convenience init(`address`: String) throws {
|
|
|
|
self.init(unsafeFromRawPointer: try
|
|
|
|
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
|
|
|
|
bdk_1724_Address_new(
|
|
|
|
FfiConverterString.lower(`address`), $0)
|
|
|
|
})
|
2022-06-23 11:03:45 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
deinit {
|
|
|
|
try! rustCall { ffi_bdk_1724_Address_object_free(pointer, $0) }
|
|
|
|
}
|
2022-06-23 11:03:45 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `scriptPubkey`() -> Script {
|
|
|
|
return try! FfiConverterTypeScript.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_Address_script_pubkey(self.pointer, $0
|
|
|
|
)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeAddress: FfiConverter {
|
|
|
|
typealias FfiType = UnsafeMutableRawPointer
|
|
|
|
typealias SwiftType = Address
|
|
|
|
|
|
|
|
static func read(from buf: Reader) throws -> Address {
|
|
|
|
let v: UInt64 = try buf.readInt()
|
|
|
|
// 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
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return try lift(ptr!)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: Address, into buf: Writer) {
|
|
|
|
// 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`.
|
|
|
|
buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Address {
|
|
|
|
return Address(unsafeFromRawPointer: pointer)
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lower(_ value: Address) -> UnsafeMutableRawPointer {
|
|
|
|
return value.pointer
|
|
|
|
}
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public protocol BlockchainProtocol {
|
|
|
|
func `broadcast`(`psbt`: PartiallySignedBitcoinTransaction) throws
|
|
|
|
func `getHeight`() throws -> UInt32
|
|
|
|
func `getBlockHash`(`height`: UInt32) throws -> String
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public class Blockchain: BlockchainProtocol {
|
|
|
|
fileprivate let pointer: UnsafeMutableRawPointer
|
|
|
|
|
|
|
|
// TODO: We'd like this to be `private` but for Swifty reasons,
|
|
|
|
// we can't implement `FfiConverter` without making this `required` and we can't
|
|
|
|
// make it `required` without making it `public`.
|
|
|
|
required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
|
|
self.pointer = pointer
|
|
|
|
}
|
|
|
|
public convenience init(`config`: BlockchainConfig) throws {
|
|
|
|
self.init(unsafeFromRawPointer: try
|
|
|
|
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
|
|
|
|
bdk_1724_Blockchain_new(
|
|
|
|
FfiConverterTypeBlockchainConfig.lower(`config`), $0)
|
|
|
|
})
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
deinit {
|
|
|
|
try! rustCall { ffi_bdk_1724_Blockchain_object_free(pointer, $0) }
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `broadcast`(`psbt`: PartiallySignedBitcoinTransaction) throws {
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_Blockchain_broadcast(self.pointer,
|
|
|
|
FfiConverterTypePartiallySignedBitcoinTransaction.lower(`psbt`), $0
|
|
|
|
)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `getHeight`() throws -> UInt32 {
|
|
|
|
return try FfiConverterUInt32.lift(
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_Blockchain_get_height(self.pointer, $0
|
|
|
|
)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `getBlockHash`(`height`: UInt32) throws -> String {
|
|
|
|
return try FfiConverterString.lift(
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_Blockchain_get_block_hash(self.pointer,
|
|
|
|
FfiConverterUInt32.lower(`height`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeBlockchain: FfiConverter {
|
|
|
|
typealias FfiType = UnsafeMutableRawPointer
|
|
|
|
typealias SwiftType = Blockchain
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> Blockchain {
|
|
|
|
let v: UInt64 = try buf.readInt()
|
|
|
|
// 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
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return try lift(ptr!)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: Blockchain, into buf: Writer) {
|
|
|
|
// 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`.
|
|
|
|
buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Blockchain {
|
|
|
|
return Blockchain(unsafeFromRawPointer: pointer)
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lower(_ value: Blockchain) -> UnsafeMutableRawPointer {
|
|
|
|
return value.pointer
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public protocol BumpFeeTxBuilderProtocol {
|
|
|
|
func `allowShrinking`(`address`: String) -> BumpFeeTxBuilder
|
|
|
|
func `enableRbf`() -> BumpFeeTxBuilder
|
|
|
|
func `enableRbfWithSequence`(`nsequence`: UInt32) -> BumpFeeTxBuilder
|
|
|
|
func `finish`(`wallet`: Wallet) throws -> PartiallySignedBitcoinTransaction
|
2022-05-13 13:45:48 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public class BumpFeeTxBuilder: BumpFeeTxBuilderProtocol {
|
2022-05-13 13:45:48 -07:00
|
|
|
fileprivate let pointer: UnsafeMutableRawPointer
|
|
|
|
|
|
|
|
// TODO: We'd like this to be `private` but for Swifty reasons,
|
2022-10-21 17:18:30 -05:00
|
|
|
// we can't implement `FfiConverter` without making this `required` and we can't
|
2022-05-13 13:45:48 -07:00
|
|
|
// make it `required` without making it `public`.
|
|
|
|
required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
|
|
self.pointer = pointer
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public convenience init(`txid`: String, `newFeeRate`: Float) {
|
|
|
|
self.init(unsafeFromRawPointer: try!
|
2022-05-13 13:45:48 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
rustCall() {
|
2022-05-13 13:45:48 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_BumpFeeTxBuilder_new(
|
|
|
|
FfiConverterString.lower(`txid`),
|
|
|
|
FfiConverterFloat.lower(`newFeeRate`), $0)
|
2022-05-13 13:45:48 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
2022-10-21 17:18:30 -05:00
|
|
|
try! rustCall { ffi_bdk_1724_BumpFeeTxBuilder_object_free(pointer, $0) }
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `allowShrinking`(`address`: String) -> BumpFeeTxBuilder {
|
|
|
|
return try! FfiConverterTypeBumpFeeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_BumpFeeTxBuilder_allow_shrinking(self.pointer,
|
|
|
|
FfiConverterString.lower(`address`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `enableRbf`() -> BumpFeeTxBuilder {
|
|
|
|
return try! FfiConverterTypeBumpFeeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_BumpFeeTxBuilder_enable_rbf(self.pointer, $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `enableRbfWithSequence`(`nsequence`: UInt32) -> BumpFeeTxBuilder {
|
|
|
|
return try! FfiConverterTypeBumpFeeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
2022-05-13 13:45:48 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_BumpFeeTxBuilder_enable_rbf_with_sequence(self.pointer,
|
|
|
|
FfiConverterUInt32.lower(`nsequence`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `finish`(`wallet`: Wallet) throws -> PartiallySignedBitcoinTransaction {
|
|
|
|
return try FfiConverterTypePartiallySignedBitcoinTransaction.lift(
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_BumpFeeTxBuilder_finish(self.pointer,
|
|
|
|
FfiConverterTypeWallet.lower(`wallet`), $0
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeBumpFeeTxBuilder: FfiConverter {
|
2022-05-13 13:45:48 -07:00
|
|
|
typealias FfiType = UnsafeMutableRawPointer
|
2022-10-21 17:18:30 -05:00
|
|
|
typealias SwiftType = BumpFeeTxBuilder
|
2022-05-13 13:45:48 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> BumpFeeTxBuilder {
|
2022-05-13 13:45:48 -07:00
|
|
|
let v: UInt64 = try buf.readInt()
|
|
|
|
// 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
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return try lift(ptr!)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: BumpFeeTxBuilder, into buf: Writer) {
|
2022-05-13 13:45:48 -07:00
|
|
|
// 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`.
|
2022-10-21 17:18:30 -05:00
|
|
|
buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lift(_ pointer: UnsafeMutableRawPointer) throws -> BumpFeeTxBuilder {
|
|
|
|
return BumpFeeTxBuilder(unsafeFromRawPointer: pointer)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lower(_ value: BumpFeeTxBuilder) -> UnsafeMutableRawPointer {
|
|
|
|
return value.pointer
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public protocol DerivationPathProtocol {
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public class DerivationPath: DerivationPathProtocol {
|
2021-11-24 00:10:26 -08:00
|
|
|
fileprivate let pointer: UnsafeMutableRawPointer
|
|
|
|
|
|
|
|
// TODO: We'd like this to be `private` but for Swifty reasons,
|
2022-10-21 17:18:30 -05:00
|
|
|
// we can't implement `FfiConverter` without making this `required` and we can't
|
2021-11-24 00:10:26 -08:00
|
|
|
// make it `required` without making it `public`.
|
|
|
|
required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
|
|
self.pointer = pointer
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public convenience init(`path`: String) throws {
|
2021-11-24 00:10:26 -08:00
|
|
|
self.init(unsafeFromRawPointer: try
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_DerivationPath_new(
|
|
|
|
FfiConverterString.lower(`path`), $0)
|
2021-11-24 00:10:26 -08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
2022-10-21 17:18:30 -05:00
|
|
|
try! rustCall { ffi_bdk_1724_DerivationPath_object_free(pointer, $0) }
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeDerivationPath: FfiConverter {
|
2022-03-02 15:17:53 -08:00
|
|
|
typealias FfiType = UnsafeMutableRawPointer
|
2022-10-21 17:18:30 -05:00
|
|
|
typealias SwiftType = DerivationPath
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> DerivationPath {
|
2021-11-24 00:10:26 -08:00
|
|
|
let v: UInt64 = try buf.readInt()
|
|
|
|
// 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
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return try lift(ptr!)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: DerivationPath, into buf: Writer) {
|
2021-11-24 00:10:26 -08:00
|
|
|
// 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`.
|
2022-10-21 17:18:30 -05:00
|
|
|
buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lift(_ pointer: UnsafeMutableRawPointer) throws -> DerivationPath {
|
|
|
|
return DerivationPath(unsafeFromRawPointer: pointer)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lower(_ value: DerivationPath) -> UnsafeMutableRawPointer {
|
|
|
|
return value.pointer
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public protocol DescriptorPublicKeyProtocol {
|
|
|
|
func `derive`(`path`: DerivationPath) throws -> DescriptorPublicKey
|
|
|
|
func `extend`(`path`: DerivationPath) -> DescriptorPublicKey
|
|
|
|
func `asString`() -> String
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public class DescriptorPublicKey: DescriptorPublicKeyProtocol {
|
2021-11-24 00:10:26 -08:00
|
|
|
fileprivate let pointer: UnsafeMutableRawPointer
|
|
|
|
|
|
|
|
// TODO: We'd like this to be `private` but for Swifty reasons,
|
2022-10-21 17:18:30 -05:00
|
|
|
// we can't implement `FfiConverter` without making this `required` and we can't
|
2021-11-24 00:10:26 -08:00
|
|
|
// make it `required` without making it `public`.
|
|
|
|
required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
|
|
self.pointer = pointer
|
|
|
|
}
|
2022-05-13 13:45:48 -07:00
|
|
|
|
|
|
|
deinit {
|
2022-10-21 17:18:30 -05:00
|
|
|
try! rustCall { ffi_bdk_1724_DescriptorPublicKey_object_free(pointer, $0) }
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `derive`(`path`: DerivationPath) throws -> DescriptorPublicKey {
|
|
|
|
return try FfiConverterTypeDescriptorPublicKey.lift(
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_DescriptorPublicKey_derive(self.pointer,
|
|
|
|
FfiConverterTypeDerivationPath.lower(`path`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `extend`(`path`: DerivationPath) -> DescriptorPublicKey {
|
|
|
|
return try! FfiConverterTypeDescriptorPublicKey.lift(
|
|
|
|
try!
|
2022-05-13 13:45:48 -07:00
|
|
|
rustCall() {
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_DescriptorPublicKey_extend(self.pointer,
|
|
|
|
FfiConverterTypeDerivationPath.lower(`path`), $0
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `asString`() -> String {
|
|
|
|
return try! FfiConverterString.lift(
|
|
|
|
try!
|
2022-05-13 13:45:48 -07:00
|
|
|
rustCall() {
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_DescriptorPublicKey_as_string(self.pointer, $0
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeDescriptorPublicKey: FfiConverter {
|
2022-05-13 13:45:48 -07:00
|
|
|
typealias FfiType = UnsafeMutableRawPointer
|
2022-10-21 17:18:30 -05:00
|
|
|
typealias SwiftType = DescriptorPublicKey
|
2022-05-13 13:45:48 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> DescriptorPublicKey {
|
2022-05-13 13:45:48 -07:00
|
|
|
let v: UInt64 = try buf.readInt()
|
|
|
|
// 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
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return try lift(ptr!)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: DescriptorPublicKey, into buf: Writer) {
|
2022-05-13 13:45:48 -07:00
|
|
|
// 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`.
|
2022-10-21 17:18:30 -05:00
|
|
|
buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lift(_ pointer: UnsafeMutableRawPointer) throws -> DescriptorPublicKey {
|
|
|
|
return DescriptorPublicKey(unsafeFromRawPointer: pointer)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lower(_ value: DescriptorPublicKey) -> UnsafeMutableRawPointer {
|
|
|
|
return value.pointer
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public protocol DescriptorSecretKeyProtocol {
|
|
|
|
func `derive`(`path`: DerivationPath) throws -> DescriptorSecretKey
|
|
|
|
func `extend`(`path`: DerivationPath) -> DescriptorSecretKey
|
|
|
|
func `asPublic`() -> DescriptorPublicKey
|
|
|
|
func `secretBytes`() -> [UInt8]
|
|
|
|
func `asString`() -> String
|
2022-05-13 13:45:48 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public class DescriptorSecretKey: DescriptorSecretKeyProtocol {
|
2022-05-13 13:45:48 -07:00
|
|
|
fileprivate let pointer: UnsafeMutableRawPointer
|
|
|
|
|
|
|
|
// TODO: We'd like this to be `private` but for Swifty reasons,
|
2022-10-21 17:18:30 -05:00
|
|
|
// we can't implement `FfiConverter` without making this `required` and we can't
|
2022-05-13 13:45:48 -07:00
|
|
|
// make it `required` without making it `public`.
|
|
|
|
required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
|
|
self.pointer = pointer
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public convenience init(`network`: Network, `mnemonic`: String, `password`: String?) throws {
|
|
|
|
self.init(unsafeFromRawPointer: try
|
2022-05-13 13:45:48 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
2022-05-13 13:45:48 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_DescriptorSecretKey_new(
|
|
|
|
FfiConverterTypeNetwork.lower(`network`),
|
|
|
|
FfiConverterString.lower(`mnemonic`),
|
|
|
|
FfiConverterOptionString.lower(`password`), $0)
|
2021-11-24 00:10:26 -08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
2022-10-21 17:18:30 -05:00
|
|
|
try! rustCall { ffi_bdk_1724_DescriptorSecretKey_object_free(pointer, $0) }
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-13 13:45:48 -07:00
|
|
|
|
2022-03-02 15:17:53 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `derive`(`path`: DerivationPath) throws -> DescriptorSecretKey {
|
|
|
|
return try FfiConverterTypeDescriptorSecretKey.lift(
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_DescriptorSecretKey_derive(self.pointer,
|
|
|
|
FfiConverterTypeDerivationPath.lower(`path`), $0
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `extend`(`path`: DerivationPath) -> DescriptorSecretKey {
|
|
|
|
return try! FfiConverterTypeDescriptorSecretKey.lift(
|
|
|
|
try!
|
2022-05-13 13:45:48 -07:00
|
|
|
rustCall() {
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_DescriptorSecretKey_extend(self.pointer,
|
|
|
|
FfiConverterTypeDerivationPath.lower(`path`), $0
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `asPublic`() -> DescriptorPublicKey {
|
|
|
|
return try! FfiConverterTypeDescriptorPublicKey.lift(
|
|
|
|
try!
|
2022-05-13 13:45:48 -07:00
|
|
|
rustCall() {
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_DescriptorSecretKey_as_public(self.pointer, $0
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `secretBytes`() -> [UInt8] {
|
|
|
|
return try! FfiConverterSequenceUInt8.lift(
|
|
|
|
try!
|
2022-05-13 13:45:48 -07:00
|
|
|
rustCall() {
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_DescriptorSecretKey_secret_bytes(self.pointer, $0
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `asString`() -> String {
|
|
|
|
return try! FfiConverterString.lift(
|
|
|
|
try!
|
2022-05-13 13:45:48 -07:00
|
|
|
rustCall() {
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_DescriptorSecretKey_as_string(self.pointer, $0
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeDescriptorSecretKey: FfiConverter {
|
2022-05-13 13:45:48 -07:00
|
|
|
typealias FfiType = UnsafeMutableRawPointer
|
2022-10-21 17:18:30 -05:00
|
|
|
typealias SwiftType = DescriptorSecretKey
|
2022-05-13 13:45:48 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> DescriptorSecretKey {
|
2022-05-13 13:45:48 -07:00
|
|
|
let v: UInt64 = try buf.readInt()
|
|
|
|
// 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
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return try lift(ptr!)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: DescriptorSecretKey, into buf: Writer) {
|
2022-05-13 13:45:48 -07:00
|
|
|
// 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`.
|
2022-10-21 17:18:30 -05:00
|
|
|
buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lift(_ pointer: UnsafeMutableRawPointer) throws -> DescriptorSecretKey {
|
|
|
|
return DescriptorSecretKey(unsafeFromRawPointer: pointer)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lower(_ value: DescriptorSecretKey) -> UnsafeMutableRawPointer {
|
|
|
|
return value.pointer
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public protocol PartiallySignedBitcoinTransactionProtocol {
|
|
|
|
func `serialize`() -> String
|
|
|
|
func `txid`() -> String
|
|
|
|
func `extractTx`() -> [UInt8]
|
|
|
|
func `combine`(`other`: PartiallySignedBitcoinTransaction) throws -> PartiallySignedBitcoinTransaction
|
2022-05-13 13:45:48 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public class PartiallySignedBitcoinTransaction: PartiallySignedBitcoinTransactionProtocol {
|
2022-05-13 13:45:48 -07:00
|
|
|
fileprivate let pointer: UnsafeMutableRawPointer
|
|
|
|
|
|
|
|
// TODO: We'd like this to be `private` but for Swifty reasons,
|
2022-10-21 17:18:30 -05:00
|
|
|
// we can't implement `FfiConverter` without making this `required` and we can't
|
2022-05-13 13:45:48 -07:00
|
|
|
// make it `required` without making it `public`.
|
|
|
|
required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
|
|
self.pointer = pointer
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public convenience init(`psbtBase64`: String) throws {
|
|
|
|
self.init(unsafeFromRawPointer: try
|
2022-05-13 13:45:48 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
2022-05-13 13:45:48 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_PartiallySignedBitcoinTransaction_new(
|
|
|
|
FfiConverterString.lower(`psbtBase64`), $0)
|
2022-03-02 15:17:53 -08:00
|
|
|
})
|
|
|
|
}
|
2022-05-13 13:45:48 -07:00
|
|
|
|
|
|
|
deinit {
|
2022-10-21 17:18:30 -05:00
|
|
|
try! rustCall { ffi_bdk_1724_PartiallySignedBitcoinTransaction_object_free(pointer, $0) }
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:17:53 -08:00
|
|
|
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `serialize`() -> String {
|
|
|
|
return try! FfiConverterString.lift(
|
|
|
|
try!
|
2022-03-02 15:17:53 -08:00
|
|
|
rustCall() {
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_PartiallySignedBitcoinTransaction_serialize(self.pointer, $0
|
2022-03-02 15:17:53 -08:00
|
|
|
)
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `txid`() -> String {
|
|
|
|
return try! FfiConverterString.lift(
|
|
|
|
try!
|
2022-05-13 13:45:48 -07:00
|
|
|
rustCall() {
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_PartiallySignedBitcoinTransaction_txid(self.pointer, $0
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `extractTx`() -> [UInt8] {
|
|
|
|
return try! FfiConverterSequenceUInt8.lift(
|
|
|
|
try!
|
2022-05-13 13:45:48 -07:00
|
|
|
rustCall() {
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
bdk_1724_PartiallySignedBitcoinTransaction_extract_tx(self.pointer, $0
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `combine`(`other`: PartiallySignedBitcoinTransaction) throws -> PartiallySignedBitcoinTransaction {
|
|
|
|
return try FfiConverterTypePartiallySignedBitcoinTransaction.lift(
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_PartiallySignedBitcoinTransaction_combine(self.pointer,
|
|
|
|
FfiConverterTypePartiallySignedBitcoinTransaction.lower(`other`), $0
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
)
|
2022-03-02 15:17:53 -08:00
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypePartiallySignedBitcoinTransaction: FfiConverter {
|
2022-03-02 15:17:53 -08:00
|
|
|
typealias FfiType = UnsafeMutableRawPointer
|
2022-10-21 17:18:30 -05:00
|
|
|
typealias SwiftType = PartiallySignedBitcoinTransaction
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> PartiallySignedBitcoinTransaction {
|
2021-11-24 00:10:26 -08:00
|
|
|
let v: UInt64 = try buf.readInt()
|
|
|
|
// 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
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return try lift(ptr!)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: PartiallySignedBitcoinTransaction, into buf: Writer) {
|
2021-11-24 00:10:26 -08:00
|
|
|
// 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`.
|
2022-10-21 17:18:30 -05:00
|
|
|
buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lift(_ pointer: UnsafeMutableRawPointer) throws -> PartiallySignedBitcoinTransaction {
|
|
|
|
return PartiallySignedBitcoinTransaction(unsafeFromRawPointer: pointer)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func lower(_ value: PartiallySignedBitcoinTransaction) -> UnsafeMutableRawPointer {
|
|
|
|
return value.pointer
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 11:03:45 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public protocol ScriptProtocol {
|
|
|
|
|
2022-06-23 11:03:45 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public class Script: ScriptProtocol {
|
|
|
|
fileprivate let pointer: UnsafeMutableRawPointer
|
2022-06-23 11:03:45 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
// TODO: We'd like this to be `private` but for Swifty reasons,
|
|
|
|
// we can't implement `FfiConverter` without making this `required` and we can't
|
|
|
|
// make it `required` without making it `public`.
|
|
|
|
required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
|
|
self.pointer = pointer
|
|
|
|
}
|
|
|
|
public convenience init(`rawOutputScript`: [UInt8]) {
|
|
|
|
self.init(unsafeFromRawPointer: try!
|
|
|
|
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_Script_new(
|
|
|
|
FfiConverterSequenceUInt8.lower(`rawOutputScript`), $0)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
|
|
|
try! rustCall { ffi_bdk_1724_Script_object_free(pointer, $0) }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeScript: FfiConverter {
|
|
|
|
typealias FfiType = UnsafeMutableRawPointer
|
|
|
|
typealias SwiftType = Script
|
|
|
|
|
|
|
|
static func read(from buf: Reader) throws -> Script {
|
|
|
|
let v: UInt64 = try buf.readInt()
|
|
|
|
// 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!)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func write(_ value: Script, into buf: Writer) {
|
|
|
|
// 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`.
|
|
|
|
buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
|
|
|
}
|
|
|
|
|
|
|
|
static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Script {
|
|
|
|
return Script(unsafeFromRawPointer: pointer)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func lower(_ value: Script) -> UnsafeMutableRawPointer {
|
|
|
|
return value.pointer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public protocol TxBuilderProtocol {
|
|
|
|
func `addRecipient`(`script`: Script, `amount`: UInt64) -> TxBuilder
|
|
|
|
func `addUnspendable`(`unspendable`: OutPoint) -> TxBuilder
|
|
|
|
func `addUtxo`(`outpoint`: OutPoint) -> TxBuilder
|
|
|
|
func `addUtxos`(`outpoints`: [OutPoint]) -> TxBuilder
|
|
|
|
func `doNotSpendChange`() -> TxBuilder
|
|
|
|
func `manuallySelectedOnly`() -> TxBuilder
|
|
|
|
func `onlySpendChange`() -> TxBuilder
|
|
|
|
func `unspendable`(`unspendable`: [OutPoint]) -> TxBuilder
|
|
|
|
func `feeRate`(`satPerVbyte`: Float) -> TxBuilder
|
|
|
|
func `feeAbsolute`(`feeAmount`: UInt64) -> TxBuilder
|
|
|
|
func `drainWallet`() -> TxBuilder
|
|
|
|
func `drainTo`(`address`: String) -> TxBuilder
|
|
|
|
func `enableRbf`() -> TxBuilder
|
|
|
|
func `enableRbfWithSequence`(`nsequence`: UInt32) -> TxBuilder
|
|
|
|
func `addData`(`data`: [UInt8]) -> TxBuilder
|
|
|
|
func `setRecipients`(`recipients`: [ScriptAmount]) -> TxBuilder
|
|
|
|
func `finish`(`wallet`: Wallet) throws -> TxBuilderResult
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TxBuilder: TxBuilderProtocol {
|
|
|
|
fileprivate let pointer: UnsafeMutableRawPointer
|
|
|
|
|
|
|
|
// TODO: We'd like this to be `private` but for Swifty reasons,
|
|
|
|
// we can't implement `FfiConverter` without making this `required` and we can't
|
|
|
|
// make it `required` without making it `public`.
|
|
|
|
required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
|
|
self.pointer = pointer
|
|
|
|
}
|
|
|
|
public convenience init() {
|
|
|
|
self.init(unsafeFromRawPointer: try!
|
|
|
|
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_new($0)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
|
|
|
try! rustCall { ffi_bdk_1724_TxBuilder_object_free(pointer, $0) }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public func `addRecipient`(`script`: Script, `amount`: UInt64) -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_add_recipient(self.pointer,
|
|
|
|
FfiConverterTypeScript.lower(`script`),
|
|
|
|
FfiConverterUInt64.lower(`amount`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `addUnspendable`(`unspendable`: OutPoint) -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_add_unspendable(self.pointer,
|
|
|
|
FfiConverterTypeOutPoint.lower(`unspendable`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `addUtxo`(`outpoint`: OutPoint) -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_add_utxo(self.pointer,
|
|
|
|
FfiConverterTypeOutPoint.lower(`outpoint`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `addUtxos`(`outpoints`: [OutPoint]) -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_add_utxos(self.pointer,
|
|
|
|
FfiConverterSequenceTypeOutPoint.lower(`outpoints`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `doNotSpendChange`() -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_do_not_spend_change(self.pointer, $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `manuallySelectedOnly`() -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_manually_selected_only(self.pointer, $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `onlySpendChange`() -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_only_spend_change(self.pointer, $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `unspendable`(`unspendable`: [OutPoint]) -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_unspendable(self.pointer,
|
|
|
|
FfiConverterSequenceTypeOutPoint.lower(`unspendable`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `feeRate`(`satPerVbyte`: Float) -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_fee_rate(self.pointer,
|
|
|
|
FfiConverterFloat.lower(`satPerVbyte`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `feeAbsolute`(`feeAmount`: UInt64) -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_fee_absolute(self.pointer,
|
|
|
|
FfiConverterUInt64.lower(`feeAmount`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `drainWallet`() -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_drain_wallet(self.pointer, $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `drainTo`(`address`: String) -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_drain_to(self.pointer,
|
|
|
|
FfiConverterString.lower(`address`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `enableRbf`() -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_enable_rbf(self.pointer, $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `enableRbfWithSequence`(`nsequence`: UInt32) -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_enable_rbf_with_sequence(self.pointer,
|
|
|
|
FfiConverterUInt32.lower(`nsequence`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `addData`(`data`: [UInt8]) -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_add_data(self.pointer,
|
|
|
|
FfiConverterSequenceUInt8.lower(`data`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `setRecipients`(`recipients`: [ScriptAmount]) -> TxBuilder {
|
|
|
|
return try! FfiConverterTypeTxBuilder.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_TxBuilder_set_recipients(self.pointer,
|
|
|
|
FfiConverterSequenceTypeScriptAmount.lower(`recipients`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `finish`(`wallet`: Wallet) throws -> TxBuilderResult {
|
|
|
|
return try FfiConverterTypeTxBuilderResult.lift(
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_TxBuilder_finish(self.pointer,
|
|
|
|
FfiConverterTypeWallet.lower(`wallet`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeTxBuilder: FfiConverter {
|
|
|
|
typealias FfiType = UnsafeMutableRawPointer
|
|
|
|
typealias SwiftType = TxBuilder
|
|
|
|
|
|
|
|
static func read(from buf: Reader) throws -> TxBuilder {
|
|
|
|
let v: UInt64 = try buf.readInt()
|
|
|
|
// 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!)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func write(_ value: TxBuilder, into buf: Writer) {
|
|
|
|
// 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`.
|
|
|
|
buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
|
|
|
}
|
|
|
|
|
|
|
|
static func lift(_ pointer: UnsafeMutableRawPointer) throws -> TxBuilder {
|
|
|
|
return TxBuilder(unsafeFromRawPointer: pointer)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func lower(_ value: TxBuilder) -> UnsafeMutableRawPointer {
|
|
|
|
return value.pointer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public protocol WalletProtocol {
|
|
|
|
func `getAddress`(`addressIndex`: AddressIndex) throws -> AddressInfo
|
|
|
|
func `getBalance`() throws -> Balance
|
|
|
|
func `sign`(`psbt`: PartiallySignedBitcoinTransaction) throws -> Bool
|
|
|
|
func `listTransactions`() throws -> [TransactionDetails]
|
|
|
|
func `network`() -> Network
|
|
|
|
func `sync`(`blockchain`: Blockchain, `progress`: Progress?) throws
|
|
|
|
func `listUnspent`() throws -> [LocalUtxo]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public class Wallet: WalletProtocol {
|
|
|
|
fileprivate let pointer: UnsafeMutableRawPointer
|
|
|
|
|
|
|
|
// TODO: We'd like this to be `private` but for Swifty reasons,
|
|
|
|
// we can't implement `FfiConverter` without making this `required` and we can't
|
|
|
|
// make it `required` without making it `public`.
|
|
|
|
required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
|
|
self.pointer = pointer
|
|
|
|
}
|
|
|
|
public convenience init(`descriptor`: String, `changeDescriptor`: String?, `network`: Network, `databaseConfig`: DatabaseConfig) throws {
|
|
|
|
self.init(unsafeFromRawPointer: try
|
|
|
|
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
|
|
|
|
bdk_1724_Wallet_new(
|
|
|
|
FfiConverterString.lower(`descriptor`),
|
|
|
|
FfiConverterOptionString.lower(`changeDescriptor`),
|
|
|
|
FfiConverterTypeNetwork.lower(`network`),
|
|
|
|
FfiConverterTypeDatabaseConfig.lower(`databaseConfig`), $0)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
|
|
|
try! rustCall { ffi_bdk_1724_Wallet_object_free(pointer, $0) }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public func `getAddress`(`addressIndex`: AddressIndex) throws -> AddressInfo {
|
|
|
|
return try FfiConverterTypeAddressInfo.lift(
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_Wallet_get_address(self.pointer,
|
|
|
|
FfiConverterTypeAddressIndex.lower(`addressIndex`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `getBalance`() throws -> Balance {
|
|
|
|
return try FfiConverterTypeBalance.lift(
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_Wallet_get_balance(self.pointer, $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `sign`(`psbt`: PartiallySignedBitcoinTransaction) throws -> Bool {
|
|
|
|
return try FfiConverterBool.lift(
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_Wallet_sign(self.pointer,
|
|
|
|
FfiConverterTypePartiallySignedBitcoinTransaction.lower(`psbt`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `listTransactions`() throws -> [TransactionDetails] {
|
|
|
|
return try FfiConverterSequenceTypeTransactionDetails.lift(
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_Wallet_list_transactions(self.pointer, $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `network`() -> Network {
|
|
|
|
return try! FfiConverterTypeNetwork.lift(
|
|
|
|
try!
|
|
|
|
rustCall() {
|
|
|
|
|
|
|
|
bdk_1724_Wallet_network(self.pointer, $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
public func `sync`(`blockchain`: Blockchain, `progress`: Progress?) throws {
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_Wallet_sync(self.pointer,
|
|
|
|
FfiConverterTypeBlockchain.lower(`blockchain`),
|
|
|
|
FfiConverterOptionCallbackInterfaceProgress.lower(`progress`), $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public func `listUnspent`() throws -> [LocalUtxo] {
|
|
|
|
return try FfiConverterSequenceTypeLocalUtxo.lift(
|
|
|
|
try
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
bdk_1724_Wallet_list_unspent(self.pointer, $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeWallet: FfiConverter {
|
|
|
|
typealias FfiType = UnsafeMutableRawPointer
|
|
|
|
typealias SwiftType = Wallet
|
|
|
|
|
|
|
|
static func read(from buf: Reader) throws -> Wallet {
|
|
|
|
let v: UInt64 = try buf.readInt()
|
|
|
|
// 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!)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func write(_ value: Wallet, into buf: Writer) {
|
|
|
|
// 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`.
|
|
|
|
buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
|
|
|
}
|
|
|
|
|
|
|
|
static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Wallet {
|
|
|
|
return Wallet(unsafeFromRawPointer: pointer)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func lower(_ value: Wallet) -> UnsafeMutableRawPointer {
|
|
|
|
return value.pointer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public struct AddressInfo {
|
|
|
|
public var `index`: UInt32
|
|
|
|
public var `address`: String
|
|
|
|
|
|
|
|
// Default memberwise initializers are never public by default, so we
|
|
|
|
// declare one manually.
|
|
|
|
public init(`index`: UInt32, `address`: String) {
|
|
|
|
self.`index` = `index`
|
|
|
|
self.`address` = `address`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension AddressInfo: Equatable, Hashable {
|
|
|
|
public static func ==(lhs: AddressInfo, rhs: AddressInfo) -> Bool {
|
|
|
|
if lhs.`index` != rhs.`index` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`address` != rhs.`address` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(`index`)
|
|
|
|
hasher.combine(`address`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeAddressInfo: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> AddressInfo {
|
|
|
|
return try AddressInfo(
|
|
|
|
`index`: FfiConverterUInt32.read(from: buf),
|
|
|
|
`address`: FfiConverterString.read(from: buf)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate static func write(_ value: AddressInfo, into buf: Writer) {
|
|
|
|
FfiConverterUInt32.write(value.`index`, into: buf)
|
|
|
|
FfiConverterString.write(value.`address`, into: buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public struct Balance {
|
|
|
|
public var `immature`: UInt64
|
|
|
|
public var `trustedPending`: UInt64
|
|
|
|
public var `untrustedPending`: UInt64
|
|
|
|
public var `confirmed`: UInt64
|
|
|
|
public var `spendable`: UInt64
|
|
|
|
public var `total`: UInt64
|
|
|
|
|
|
|
|
// Default memberwise initializers are never public by default, so we
|
|
|
|
// declare one manually.
|
|
|
|
public init(`immature`: UInt64, `trustedPending`: UInt64, `untrustedPending`: UInt64, `confirmed`: UInt64, `spendable`: UInt64, `total`: UInt64) {
|
|
|
|
self.`immature` = `immature`
|
|
|
|
self.`trustedPending` = `trustedPending`
|
|
|
|
self.`untrustedPending` = `untrustedPending`
|
|
|
|
self.`confirmed` = `confirmed`
|
|
|
|
self.`spendable` = `spendable`
|
|
|
|
self.`total` = `total`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension Balance: Equatable, Hashable {
|
|
|
|
public static func ==(lhs: Balance, rhs: Balance) -> Bool {
|
|
|
|
if lhs.`immature` != rhs.`immature` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`trustedPending` != rhs.`trustedPending` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`untrustedPending` != rhs.`untrustedPending` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`confirmed` != rhs.`confirmed` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`spendable` != rhs.`spendable` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`total` != rhs.`total` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(`immature`)
|
|
|
|
hasher.combine(`trustedPending`)
|
|
|
|
hasher.combine(`untrustedPending`)
|
|
|
|
hasher.combine(`confirmed`)
|
|
|
|
hasher.combine(`spendable`)
|
|
|
|
hasher.combine(`total`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeBalance: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> Balance {
|
|
|
|
return try Balance(
|
|
|
|
`immature`: FfiConverterUInt64.read(from: buf),
|
|
|
|
`trustedPending`: FfiConverterUInt64.read(from: buf),
|
|
|
|
`untrustedPending`: FfiConverterUInt64.read(from: buf),
|
|
|
|
`confirmed`: FfiConverterUInt64.read(from: buf),
|
|
|
|
`spendable`: FfiConverterUInt64.read(from: buf),
|
|
|
|
`total`: FfiConverterUInt64.read(from: buf)
|
|
|
|
)
|
2022-06-23 11:03:45 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate static func write(_ value: Balance, into buf: Writer) {
|
|
|
|
FfiConverterUInt64.write(value.`immature`, into: buf)
|
|
|
|
FfiConverterUInt64.write(value.`trustedPending`, into: buf)
|
|
|
|
FfiConverterUInt64.write(value.`untrustedPending`, into: buf)
|
|
|
|
FfiConverterUInt64.write(value.`confirmed`, into: buf)
|
|
|
|
FfiConverterUInt64.write(value.`spendable`, into: buf)
|
|
|
|
FfiConverterUInt64.write(value.`total`, into: buf)
|
|
|
|
}
|
|
|
|
}
|
2022-06-23 11:03:45 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
|
|
|
|
public struct BlockTime {
|
|
|
|
public var `height`: UInt32
|
|
|
|
public var `timestamp`: UInt64
|
|
|
|
|
|
|
|
// Default memberwise initializers are never public by default, so we
|
|
|
|
// declare one manually.
|
|
|
|
public init(`height`: UInt32, `timestamp`: UInt64) {
|
|
|
|
self.`height` = `height`
|
|
|
|
self.`timestamp` = `timestamp`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension BlockTime: Equatable, Hashable {
|
|
|
|
public static func ==(lhs: BlockTime, rhs: BlockTime) -> Bool {
|
|
|
|
if lhs.`height` != rhs.`height` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`timestamp` != rhs.`timestamp` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(`height`)
|
|
|
|
hasher.combine(`timestamp`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeBlockTime: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> BlockTime {
|
|
|
|
return try BlockTime(
|
|
|
|
`height`: FfiConverterUInt32.read(from: buf),
|
|
|
|
`timestamp`: FfiConverterUInt64.read(from: buf)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate static func write(_ value: BlockTime, into buf: Writer) {
|
|
|
|
FfiConverterUInt32.write(value.`height`, into: buf)
|
|
|
|
FfiConverterUInt64.write(value.`timestamp`, into: buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public struct ElectrumConfig {
|
|
|
|
public var `url`: String
|
|
|
|
public var `socks5`: String?
|
|
|
|
public var `retry`: UInt8
|
|
|
|
public var `timeout`: UInt8?
|
|
|
|
public var `stopGap`: UInt64
|
|
|
|
|
|
|
|
// Default memberwise initializers are never public by default, so we
|
|
|
|
// declare one manually.
|
|
|
|
public init(`url`: String, `socks5`: String?, `retry`: UInt8, `timeout`: UInt8?, `stopGap`: UInt64) {
|
|
|
|
self.`url` = `url`
|
|
|
|
self.`socks5` = `socks5`
|
|
|
|
self.`retry` = `retry`
|
|
|
|
self.`timeout` = `timeout`
|
|
|
|
self.`stopGap` = `stopGap`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension ElectrumConfig: Equatable, Hashable {
|
|
|
|
public static func ==(lhs: ElectrumConfig, rhs: ElectrumConfig) -> Bool {
|
|
|
|
if lhs.`url` != rhs.`url` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`socks5` != rhs.`socks5` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`retry` != rhs.`retry` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`timeout` != rhs.`timeout` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`stopGap` != rhs.`stopGap` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(`url`)
|
|
|
|
hasher.combine(`socks5`)
|
|
|
|
hasher.combine(`retry`)
|
|
|
|
hasher.combine(`timeout`)
|
|
|
|
hasher.combine(`stopGap`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeElectrumConfig: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> ElectrumConfig {
|
|
|
|
return try ElectrumConfig(
|
|
|
|
`url`: FfiConverterString.read(from: buf),
|
|
|
|
`socks5`: FfiConverterOptionString.read(from: buf),
|
|
|
|
`retry`: FfiConverterUInt8.read(from: buf),
|
|
|
|
`timeout`: FfiConverterOptionUInt8.read(from: buf),
|
|
|
|
`stopGap`: FfiConverterUInt64.read(from: buf)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate static func write(_ value: ElectrumConfig, into buf: Writer) {
|
|
|
|
FfiConverterString.write(value.`url`, into: buf)
|
|
|
|
FfiConverterOptionString.write(value.`socks5`, into: buf)
|
|
|
|
FfiConverterUInt8.write(value.`retry`, into: buf)
|
|
|
|
FfiConverterOptionUInt8.write(value.`timeout`, into: buf)
|
|
|
|
FfiConverterUInt64.write(value.`stopGap`, into: buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public struct EsploraConfig {
|
|
|
|
public var `baseUrl`: String
|
|
|
|
public var `proxy`: String?
|
|
|
|
public var `concurrency`: UInt8?
|
|
|
|
public var `stopGap`: UInt64
|
|
|
|
public var `timeout`: UInt64?
|
|
|
|
|
|
|
|
// Default memberwise initializers are never public by default, so we
|
|
|
|
// declare one manually.
|
|
|
|
public init(`baseUrl`: String, `proxy`: String?, `concurrency`: UInt8?, `stopGap`: UInt64, `timeout`: UInt64?) {
|
|
|
|
self.`baseUrl` = `baseUrl`
|
|
|
|
self.`proxy` = `proxy`
|
|
|
|
self.`concurrency` = `concurrency`
|
|
|
|
self.`stopGap` = `stopGap`
|
|
|
|
self.`timeout` = `timeout`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension EsploraConfig: Equatable, Hashable {
|
|
|
|
public static func ==(lhs: EsploraConfig, rhs: EsploraConfig) -> Bool {
|
|
|
|
if lhs.`baseUrl` != rhs.`baseUrl` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`proxy` != rhs.`proxy` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`concurrency` != rhs.`concurrency` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`stopGap` != rhs.`stopGap` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`timeout` != rhs.`timeout` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(`baseUrl`)
|
|
|
|
hasher.combine(`proxy`)
|
|
|
|
hasher.combine(`concurrency`)
|
|
|
|
hasher.combine(`stopGap`)
|
|
|
|
hasher.combine(`timeout`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeEsploraConfig: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> EsploraConfig {
|
|
|
|
return try EsploraConfig(
|
|
|
|
`baseUrl`: FfiConverterString.read(from: buf),
|
|
|
|
`proxy`: FfiConverterOptionString.read(from: buf),
|
|
|
|
`concurrency`: FfiConverterOptionUInt8.read(from: buf),
|
|
|
|
`stopGap`: FfiConverterUInt64.read(from: buf),
|
|
|
|
`timeout`: FfiConverterOptionUInt64.read(from: buf)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate static func write(_ value: EsploraConfig, into buf: Writer) {
|
|
|
|
FfiConverterString.write(value.`baseUrl`, into: buf)
|
|
|
|
FfiConverterOptionString.write(value.`proxy`, into: buf)
|
|
|
|
FfiConverterOptionUInt8.write(value.`concurrency`, into: buf)
|
|
|
|
FfiConverterUInt64.write(value.`stopGap`, into: buf)
|
|
|
|
FfiConverterOptionUInt64.write(value.`timeout`, into: buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public struct LocalUtxo {
|
|
|
|
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`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension LocalUtxo: Equatable, Hashable {
|
|
|
|
public static func ==(lhs: LocalUtxo, rhs: LocalUtxo) -> Bool {
|
|
|
|
if lhs.`outpoint` != rhs.`outpoint` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`txout` != rhs.`txout` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`keychain` != rhs.`keychain` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`isSpent` != rhs.`isSpent` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(`outpoint`)
|
|
|
|
hasher.combine(`txout`)
|
|
|
|
hasher.combine(`keychain`)
|
|
|
|
hasher.combine(`isSpent`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeLocalUtxo: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> LocalUtxo {
|
|
|
|
return try LocalUtxo(
|
|
|
|
`outpoint`: FfiConverterTypeOutPoint.read(from: buf),
|
|
|
|
`txout`: FfiConverterTypeTxOut.read(from: buf),
|
|
|
|
`keychain`: FfiConverterTypeKeychainKind.read(from: buf),
|
|
|
|
`isSpent`: FfiConverterBool.read(from: buf)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate static func write(_ value: LocalUtxo, into buf: Writer) {
|
|
|
|
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 struct OutPoint {
|
|
|
|
public var `txid`: String
|
|
|
|
public var `vout`: UInt32
|
|
|
|
|
|
|
|
// Default memberwise initializers are never public by default, so we
|
|
|
|
// declare one manually.
|
|
|
|
public init(`txid`: String, `vout`: UInt32) {
|
|
|
|
self.`txid` = `txid`
|
|
|
|
self.`vout` = `vout`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension OutPoint: Equatable, Hashable {
|
|
|
|
public static func ==(lhs: OutPoint, rhs: OutPoint) -> Bool {
|
|
|
|
if lhs.`txid` != rhs.`txid` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`vout` != rhs.`vout` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(`txid`)
|
|
|
|
hasher.combine(`vout`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeOutPoint: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> OutPoint {
|
|
|
|
return try OutPoint(
|
|
|
|
`txid`: FfiConverterString.read(from: buf),
|
|
|
|
`vout`: FfiConverterUInt32.read(from: buf)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate static func write(_ value: OutPoint, into buf: Writer) {
|
|
|
|
FfiConverterString.write(value.`txid`, into: buf)
|
|
|
|
FfiConverterUInt32.write(value.`vout`, into: buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public struct ScriptAmount {
|
|
|
|
public var `script`: Script
|
|
|
|
public var `amount`: UInt64
|
|
|
|
|
|
|
|
// Default memberwise initializers are never public by default, so we
|
|
|
|
// declare one manually.
|
|
|
|
public init(`script`: Script, `amount`: UInt64) {
|
|
|
|
self.`script` = `script`
|
|
|
|
self.`amount` = `amount`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeScriptAmount: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> ScriptAmount {
|
|
|
|
return try ScriptAmount(
|
|
|
|
`script`: FfiConverterTypeScript.read(from: buf),
|
|
|
|
`amount`: FfiConverterUInt64.read(from: buf)
|
2022-06-23 11:03:45 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate static func write(_ value: ScriptAmount, into buf: Writer) {
|
|
|
|
FfiConverterTypeScript.write(value.`script`, into: buf)
|
|
|
|
FfiConverterUInt64.write(value.`amount`, into: buf)
|
2022-06-23 11:03:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-24 00:10:26 -08:00
|
|
|
public struct SledDbConfiguration {
|
2022-10-21 17:18:30 -05:00
|
|
|
public var `path`: String
|
|
|
|
public var `treeName`: String
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
// Default memberwise initializers are never public by default, so we
|
|
|
|
// declare one manually.
|
2022-10-21 17:18:30 -05:00
|
|
|
public init(`path`: String, `treeName`: String) {
|
|
|
|
self.`path` = `path`
|
|
|
|
self.`treeName` = `treeName`
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension SledDbConfiguration: Equatable, Hashable {
|
|
|
|
public static func ==(lhs: SledDbConfiguration, rhs: SledDbConfiguration) -> Bool {
|
2022-10-21 17:18:30 -05:00
|
|
|
if lhs.`path` != rhs.`path` {
|
2021-11-24 00:10:26 -08:00
|
|
|
return false
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
if lhs.`treeName` != rhs.`treeName` {
|
2021-11-24 00:10:26 -08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
2022-10-21 17:18:30 -05:00
|
|
|
hasher.combine(`path`)
|
|
|
|
hasher.combine(`treeName`)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeSledDbConfiguration: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> SledDbConfiguration {
|
2021-11-24 00:10:26 -08:00
|
|
|
return try SledDbConfiguration(
|
2022-10-21 17:18:30 -05:00
|
|
|
`path`: FfiConverterString.read(from: buf),
|
|
|
|
`treeName`: FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate static func write(_ value: SledDbConfiguration, into buf: Writer) {
|
|
|
|
FfiConverterString.write(value.`path`, into: buf)
|
|
|
|
FfiConverterString.write(value.`treeName`, into: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-13 13:45:48 -07:00
|
|
|
public struct SqliteDbConfiguration {
|
2022-10-21 17:18:30 -05:00
|
|
|
public var `path`: String
|
2022-05-13 13:45:48 -07:00
|
|
|
|
|
|
|
// Default memberwise initializers are never public by default, so we
|
|
|
|
// declare one manually.
|
2022-10-21 17:18:30 -05:00
|
|
|
public init(`path`: String) {
|
|
|
|
self.`path` = `path`
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension SqliteDbConfiguration: Equatable, Hashable {
|
|
|
|
public static func ==(lhs: SqliteDbConfiguration, rhs: SqliteDbConfiguration) -> Bool {
|
2022-10-21 17:18:30 -05:00
|
|
|
if lhs.`path` != rhs.`path` {
|
2022-05-13 13:45:48 -07:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
2022-10-21 17:18:30 -05:00
|
|
|
hasher.combine(`path`)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeSqliteDbConfiguration: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> SqliteDbConfiguration {
|
2022-05-13 13:45:48 -07:00
|
|
|
return try SqliteDbConfiguration(
|
2022-10-21 17:18:30 -05:00
|
|
|
`path`: FfiConverterString.read(from: buf)
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate static func write(_ value: SqliteDbConfiguration, into buf: Writer) {
|
|
|
|
FfiConverterString.write(value.`path`, into: buf)
|
2022-05-13 13:45:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-24 00:10:26 -08:00
|
|
|
public struct TransactionDetails {
|
2022-10-21 17:18:30 -05:00
|
|
|
public var `fee`: UInt64?
|
|
|
|
public var `received`: UInt64
|
|
|
|
public var `sent`: UInt64
|
|
|
|
public var `txid`: String
|
|
|
|
public var `confirmationTime`: BlockTime?
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
// Default memberwise initializers are never public by default, so we
|
|
|
|
// declare one manually.
|
2022-10-21 17:18:30 -05:00
|
|
|
public init(`fee`: UInt64?, `received`: UInt64, `sent`: UInt64, `txid`: String, `confirmationTime`: BlockTime?) {
|
|
|
|
self.`fee` = `fee`
|
|
|
|
self.`received` = `received`
|
|
|
|
self.`sent` = `sent`
|
|
|
|
self.`txid` = `txid`
|
|
|
|
self.`confirmationTime` = `confirmationTime`
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension TransactionDetails: Equatable, Hashable {
|
|
|
|
public static func ==(lhs: TransactionDetails, rhs: TransactionDetails) -> Bool {
|
2022-10-21 17:18:30 -05:00
|
|
|
if lhs.`fee` != rhs.`fee` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`received` != rhs.`received` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`sent` != rhs.`sent` {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if lhs.`txid` != rhs.`txid` {
|
2021-11-24 00:10:26 -08:00
|
|
|
return false
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
if lhs.`confirmationTime` != rhs.`confirmationTime` {
|
2021-11-24 00:10:26 -08:00
|
|
|
return false
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(`fee`)
|
|
|
|
hasher.combine(`received`)
|
|
|
|
hasher.combine(`sent`)
|
|
|
|
hasher.combine(`txid`)
|
|
|
|
hasher.combine(`confirmationTime`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeTransactionDetails: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> TransactionDetails {
|
|
|
|
return try TransactionDetails(
|
|
|
|
`fee`: FfiConverterOptionUInt64.read(from: buf),
|
|
|
|
`received`: FfiConverterUInt64.read(from: buf),
|
|
|
|
`sent`: FfiConverterUInt64.read(from: buf),
|
|
|
|
`txid`: FfiConverterString.read(from: buf),
|
|
|
|
`confirmationTime`: FfiConverterOptionTypeBlockTime.read(from: buf)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate static func write(_ value: TransactionDetails, into buf: Writer) {
|
|
|
|
FfiConverterOptionUInt64.write(value.`fee`, into: buf)
|
|
|
|
FfiConverterUInt64.write(value.`received`, into: buf)
|
|
|
|
FfiConverterUInt64.write(value.`sent`, into: buf)
|
|
|
|
FfiConverterString.write(value.`txid`, into: buf)
|
|
|
|
FfiConverterOptionTypeBlockTime.write(value.`confirmationTime`, into: buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public struct TxBuilderResult {
|
|
|
|
public var `psbt`: PartiallySignedBitcoinTransaction
|
|
|
|
public var `transactionDetails`: TransactionDetails
|
|
|
|
|
|
|
|
// Default memberwise initializers are never public by default, so we
|
|
|
|
// declare one manually.
|
|
|
|
public init(`psbt`: PartiallySignedBitcoinTransaction, `transactionDetails`: TransactionDetails) {
|
|
|
|
self.`psbt` = `psbt`
|
|
|
|
self.`transactionDetails` = `transactionDetails`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeTxBuilderResult: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> TxBuilderResult {
|
|
|
|
return try TxBuilderResult(
|
|
|
|
`psbt`: FfiConverterTypePartiallySignedBitcoinTransaction.read(from: buf),
|
|
|
|
`transactionDetails`: FfiConverterTypeTransactionDetails.read(from: buf)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate static func write(_ value: TxBuilderResult, into buf: Writer) {
|
|
|
|
FfiConverterTypePartiallySignedBitcoinTransaction.write(value.`psbt`, into: buf)
|
|
|
|
FfiConverterTypeTransactionDetails.write(value.`transactionDetails`, into: buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public struct TxOut {
|
|
|
|
public var `value`: UInt64
|
|
|
|
public var `address`: String
|
|
|
|
|
|
|
|
// Default memberwise initializers are never public by default, so we
|
|
|
|
// declare one manually.
|
|
|
|
public init(`value`: UInt64, `address`: String) {
|
|
|
|
self.`value` = `value`
|
|
|
|
self.`address` = `address`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension TxOut: Equatable, Hashable {
|
|
|
|
public static func ==(lhs: TxOut, rhs: TxOut) -> Bool {
|
|
|
|
if lhs.`value` != rhs.`value` {
|
2021-11-24 00:10:26 -08:00
|
|
|
return false
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
if lhs.`address` != rhs.`address` {
|
2021-11-24 00:10:26 -08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(`value`)
|
|
|
|
hasher.combine(`address`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeTxOut: FfiConverterRustBuffer {
|
|
|
|
fileprivate static func read(from buf: Reader) throws -> TxOut {
|
|
|
|
return try TxOut(
|
|
|
|
`value`: FfiConverterUInt64.read(from: buf),
|
|
|
|
`address`: FfiConverterString.read(from: buf)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate static func write(_ value: TxOut, into buf: Writer) {
|
|
|
|
FfiConverterUInt64.write(value.`value`, into: buf)
|
|
|
|
FfiConverterString.write(value.`address`, into: buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that we don't yet support `indirect` for enums.
|
|
|
|
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
|
|
|
|
public enum AddressIndex {
|
|
|
|
|
|
|
|
case `new`
|
|
|
|
case `lastUnused`
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterTypeAddressIndex: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = AddressIndex
|
|
|
|
|
|
|
|
static func read(from buf: Reader) throws -> AddressIndex {
|
|
|
|
let variant: Int32 = try buf.readInt()
|
|
|
|
switch variant {
|
|
|
|
|
|
|
|
case 1: return .`new`
|
|
|
|
|
|
|
|
case 2: return .`lastUnused`
|
|
|
|
|
|
|
|
default: throw UniffiInternalError.unexpectedEnumCase
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static func write(_ value: AddressIndex, into buf: Writer) {
|
|
|
|
switch value {
|
|
|
|
|
|
|
|
|
|
|
|
case .`new`:
|
|
|
|
buf.writeInt(Int32(1))
|
|
|
|
|
|
|
|
|
|
|
|
case .`lastUnused`:
|
|
|
|
buf.writeInt(Int32(2))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension AddressIndex: 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 BlockchainConfig {
|
|
|
|
|
|
|
|
case `electrum`(`config`: ElectrumConfig)
|
|
|
|
case `esplora`(`config`: EsploraConfig)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeBlockchainConfig: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = BlockchainConfig
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> BlockchainConfig {
|
|
|
|
let variant: Int32 = try buf.readInt()
|
|
|
|
switch variant {
|
|
|
|
|
|
|
|
case 1: return .`electrum`(
|
|
|
|
`config`: try FfiConverterTypeElectrumConfig.read(from: buf)
|
|
|
|
)
|
|
|
|
|
|
|
|
case 2: return .`esplora`(
|
|
|
|
`config`: try FfiConverterTypeEsploraConfig.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
2022-10-21 17:18:30 -05:00
|
|
|
|
|
|
|
default: throw UniffiInternalError.unexpectedEnumCase
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: BlockchainConfig, into buf: Writer) {
|
|
|
|
switch value {
|
|
|
|
|
|
|
|
|
|
|
|
case let .`electrum`(`config`):
|
|
|
|
buf.writeInt(Int32(1))
|
|
|
|
FfiConverterTypeElectrumConfig.write(`config`, into: buf)
|
|
|
|
|
|
|
|
|
|
|
|
case let .`esplora`(`config`):
|
|
|
|
buf.writeInt(Int32(2))
|
|
|
|
FfiConverterTypeEsploraConfig.write(`config`, into: buf)
|
|
|
|
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
extension BlockchainConfig: Equatable, Hashable {}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
// Note that we don't yet support `indirect` for enums.
|
|
|
|
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
|
|
|
|
public enum DatabaseConfig {
|
|
|
|
|
|
|
|
case `memory`
|
|
|
|
case `sled`(`config`: SledDbConfiguration)
|
|
|
|
case `sqlite`(`config`: SqliteDbConfiguration)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeDatabaseConfig: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = DatabaseConfig
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> DatabaseConfig {
|
|
|
|
let variant: Int32 = try buf.readInt()
|
|
|
|
switch variant {
|
|
|
|
|
|
|
|
case 1: return .`memory`
|
|
|
|
|
|
|
|
case 2: return .`sled`(
|
|
|
|
`config`: try FfiConverterTypeSledDbConfiguration.read(from: buf)
|
|
|
|
)
|
|
|
|
|
|
|
|
case 3: return .`sqlite`(
|
|
|
|
`config`: try FfiConverterTypeSqliteDbConfiguration.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
2022-10-21 17:18:30 -05:00
|
|
|
|
|
|
|
default: throw UniffiInternalError.unexpectedEnumCase
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: DatabaseConfig, into buf: Writer) {
|
|
|
|
switch value {
|
|
|
|
|
|
|
|
|
|
|
|
case .`memory`:
|
|
|
|
buf.writeInt(Int32(1))
|
|
|
|
|
|
|
|
|
|
|
|
case let .`sled`(`config`):
|
|
|
|
buf.writeInt(Int32(2))
|
|
|
|
FfiConverterTypeSledDbConfiguration.write(`config`, into: buf)
|
|
|
|
|
|
|
|
|
|
|
|
case let .`sqlite`(`config`):
|
|
|
|
buf.writeInt(Int32(3))
|
|
|
|
FfiConverterTypeSqliteDbConfiguration.write(`config`, into: buf)
|
|
|
|
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
extension DatabaseConfig: Equatable, Hashable {}
|
|
|
|
|
2022-06-23 11:03:45 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
// 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`
|
2022-06-23 11:03:45 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeKeychainKind: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = KeychainKind
|
2022-06-23 11:03:45 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> KeychainKind {
|
|
|
|
let variant: Int32 = try buf.readInt()
|
|
|
|
switch variant {
|
|
|
|
|
|
|
|
case 1: return .`external`
|
|
|
|
|
|
|
|
case 2: return .`internal`
|
|
|
|
|
|
|
|
default: throw UniffiInternalError.unexpectedEnumCase
|
2022-06-23 11:03:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: KeychainKind, into buf: Writer) {
|
|
|
|
switch value {
|
|
|
|
|
|
|
|
|
|
|
|
case .`external`:
|
|
|
|
buf.writeInt(Int32(1))
|
|
|
|
|
|
|
|
|
|
|
|
case .`internal`:
|
|
|
|
buf.writeInt(Int32(2))
|
|
|
|
|
|
|
|
}
|
2022-06-23 11:03:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
extension KeychainKind: Equatable, Hashable {}
|
2022-06-23 11:03:45 -07:00
|
|
|
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
// 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`
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeNetwork: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = Network
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> Network {
|
|
|
|
let variant: Int32 = try buf.readInt()
|
|
|
|
switch variant {
|
|
|
|
|
|
|
|
case 1: return .`bitcoin`
|
|
|
|
|
|
|
|
case 2: return .`testnet`
|
|
|
|
|
|
|
|
case 3: return .`signet`
|
|
|
|
|
|
|
|
case 4: return .`regtest`
|
|
|
|
|
|
|
|
default: throw UniffiInternalError.unexpectedEnumCase
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: Network, into buf: Writer) {
|
|
|
|
switch value {
|
|
|
|
|
|
|
|
|
|
|
|
case .`bitcoin`:
|
|
|
|
buf.writeInt(Int32(1))
|
|
|
|
|
|
|
|
|
|
|
|
case .`testnet`:
|
|
|
|
buf.writeInt(Int32(2))
|
|
|
|
|
|
|
|
|
|
|
|
case .`signet`:
|
|
|
|
buf.writeInt(Int32(3))
|
|
|
|
|
|
|
|
|
|
|
|
case .`regtest`:
|
|
|
|
buf.writeInt(Int32(4))
|
|
|
|
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
extension Network: Equatable, Hashable {}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
// 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`
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeWordCount: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = WordCount
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> WordCount {
|
|
|
|
let variant: Int32 = try buf.readInt()
|
|
|
|
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
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: WordCount, into buf: Writer) {
|
|
|
|
switch value {
|
|
|
|
|
|
|
|
|
|
|
|
case .`words12`:
|
|
|
|
buf.writeInt(Int32(1))
|
|
|
|
|
|
|
|
|
|
|
|
case .`words15`:
|
|
|
|
buf.writeInt(Int32(2))
|
|
|
|
|
|
|
|
|
|
|
|
case .`words18`:
|
|
|
|
buf.writeInt(Int32(3))
|
|
|
|
|
|
|
|
|
|
|
|
case .`words21`:
|
|
|
|
buf.writeInt(Int32(4))
|
|
|
|
|
|
|
|
|
|
|
|
case .`words24`:
|
|
|
|
buf.writeInt(Int32(5))
|
|
|
|
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
extension WordCount: Equatable, Hashable {}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public enum BdkError {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case InvalidU32Bytes(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Generic(message: String)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
// Simple error enums only carry a message
|
|
|
|
case MissingCachedScripts(message: String)
|
|
|
|
|
2021-11-24 00:10:26 -08:00
|
|
|
// Simple error enums only carry a message
|
|
|
|
case ScriptDoesntHaveAddressForm(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case NoRecipients(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case NoUtxosSelected(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case OutputBelowDustLimit(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case InsufficientFunds(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case BnBTotalTriesExceeded(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case BnBNoExactMatch(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case UnknownUtxo(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case TransactionNotFound(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case TransactionConfirmed(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case IrreplaceableTransaction(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case FeeRateTooLow(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case FeeTooLow(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case FeeRateUnavailable(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case MissingKeyOrigin(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Key(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case ChecksumMismatch(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case SpendingPolicyRequired(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case InvalidPolicyPathError(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Signer(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case InvalidNetwork(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case InvalidProgressValue(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case ProgressUpdateError(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case InvalidOutpoint(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Descriptor(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case AddressValidator(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Encode(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Miniscript(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Bip32(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Secp256k1(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Json(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Hex(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Psbt(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case PsbtParse(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Electrum(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Esplora(message: String)
|
|
|
|
|
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Sled(message: String)
|
|
|
|
|
2022-05-13 13:45:48 -07:00
|
|
|
// Simple error enums only carry a message
|
|
|
|
case Rusqlite(message: String)
|
|
|
|
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterTypeBdkError: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = BdkError
|
|
|
|
|
|
|
|
static func read(from buf: Reader) throws -> BdkError {
|
2021-11-24 00:10:26 -08:00
|
|
|
let variant: Int32 = try buf.readInt()
|
|
|
|
switch variant {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 1: return .InvalidU32Bytes(
|
2022-10-21 17:18:30 -05:00
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
case 2: return .Generic(
|
2022-10-21 17:18:30 -05:00
|
|
|
message: try FfiConverterString.read(from: buf)
|
|
|
|
)
|
|
|
|
|
|
|
|
case 3: return .MissingCachedScripts(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 4: return .ScriptDoesntHaveAddressForm(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 5: return .NoRecipients(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 6: return .NoUtxosSelected(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 7: return .OutputBelowDustLimit(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 8: return .InsufficientFunds(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 9: return .BnBTotalTriesExceeded(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 10: return .BnBNoExactMatch(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 11: return .UnknownUtxo(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 12: return .TransactionNotFound(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 13: return .TransactionConfirmed(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 14: return .IrreplaceableTransaction(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 15: return .FeeRateTooLow(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 16: return .FeeTooLow(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 17: return .FeeRateUnavailable(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 18: return .MissingKeyOrigin(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 19: return .Key(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 20: return .ChecksumMismatch(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 21: return .SpendingPolicyRequired(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 22: return .InvalidPolicyPathError(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 23: return .Signer(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 24: return .InvalidNetwork(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 25: return .InvalidProgressValue(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 26: return .ProgressUpdateError(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 27: return .InvalidOutpoint(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 28: return .Descriptor(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 29: return .AddressValidator(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 30: return .Encode(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 31: return .Miniscript(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 32: return .Bip32(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 33: return .Secp256k1(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 34: return .Json(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 35: return .Hex(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 36: return .Psbt(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 37: return .PsbtParse(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 38: return .Electrum(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 39: return .Esplora(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 40: return .Sled(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
case 41: return .Rusqlite(
|
|
|
|
message: try FfiConverterString.read(from: buf)
|
2022-05-13 13:45:48 -07:00
|
|
|
)
|
|
|
|
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
default: throw UniffiInternalError.unexpectedEnumCase
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: BdkError, into buf: Writer) {
|
|
|
|
switch value {
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case let .InvalidU32Bytes(message):
|
|
|
|
buf.writeInt(Int32(1))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
case let .Generic(message):
|
|
|
|
buf.writeInt(Int32(2))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .MissingCachedScripts(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(3))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .ScriptDoesntHaveAddressForm(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(4))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .NoRecipients(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(5))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .NoUtxosSelected(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(6))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .OutputBelowDustLimit(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(7))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .InsufficientFunds(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(8))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .BnBTotalTriesExceeded(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(9))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .BnBNoExactMatch(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(10))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .UnknownUtxo(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(11))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .TransactionNotFound(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(12))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .TransactionConfirmed(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(13))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .IrreplaceableTransaction(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(14))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .FeeRateTooLow(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(15))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .FeeTooLow(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(16))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .FeeRateUnavailable(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(17))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .MissingKeyOrigin(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(18))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Key(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(19))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .ChecksumMismatch(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(20))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .SpendingPolicyRequired(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(21))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .InvalidPolicyPathError(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(22))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Signer(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(23))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .InvalidNetwork(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(24))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .InvalidProgressValue(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(25))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .ProgressUpdateError(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(26))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .InvalidOutpoint(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(27))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Descriptor(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(28))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .AddressValidator(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(29))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Encode(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(30))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Miniscript(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(31))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Bip32(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(32))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Secp256k1(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(33))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Json(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(34))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Hex(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(35))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Psbt(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(36))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .PsbtParse(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(37))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Electrum(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(38))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Esplora(message):
|
2021-11-24 00:10:26 -08:00
|
|
|
buf.writeInt(Int32(39))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Sled(message):
|
2022-05-13 13:45:48 -07:00
|
|
|
buf.writeInt(Int32(40))
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
case let .Rusqlite(message):
|
|
|
|
buf.writeInt(Int32(41))
|
|
|
|
FfiConverterString.write(message, into: buf)
|
|
|
|
|
|
|
|
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension BdkError: Equatable, Hashable {}
|
|
|
|
|
|
|
|
extension BdkError: Error { }
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate extension NSLock {
|
|
|
|
func withLock<T>(f: () throws -> T) rethrows -> T {
|
|
|
|
self.lock()
|
|
|
|
defer { self.unlock() }
|
|
|
|
return try f()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate typealias Handle = UInt64
|
|
|
|
fileprivate class ConcurrentHandleMap<T> {
|
|
|
|
private var leftMap: [Handle: T] = [:]
|
|
|
|
private var counter: [Handle: UInt64] = [:]
|
|
|
|
private var rightMap: [ObjectIdentifier: Handle] = [:]
|
|
|
|
|
|
|
|
private let lock = NSLock()
|
|
|
|
private var currentHandle: Handle = 0
|
|
|
|
private let stride: Handle = 1
|
|
|
|
|
|
|
|
func insert(obj: T) -> Handle {
|
|
|
|
lock.withLock {
|
|
|
|
let id = ObjectIdentifier(obj as AnyObject)
|
|
|
|
let handle = rightMap[id] ?? {
|
|
|
|
currentHandle += stride
|
|
|
|
let handle = currentHandle
|
|
|
|
leftMap[handle] = obj
|
|
|
|
rightMap[id] = handle
|
|
|
|
return handle
|
|
|
|
}()
|
|
|
|
counter[handle] = (counter[handle] ?? 0) + 1
|
|
|
|
return handle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func get(handle: Handle) -> T? {
|
|
|
|
lock.withLock {
|
|
|
|
leftMap[handle]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func delete(handle: Handle) {
|
|
|
|
remove(handle: handle)
|
|
|
|
}
|
|
|
|
|
|
|
|
@discardableResult
|
|
|
|
func remove(handle: Handle) -> T? {
|
|
|
|
lock.withLock {
|
|
|
|
defer { counter[handle] = (counter[handle] ?? 1) - 1 }
|
|
|
|
guard counter[handle] == 1 else { return leftMap[handle] }
|
|
|
|
let obj = leftMap.removeValue(forKey: handle)
|
|
|
|
if let obj = obj {
|
|
|
|
rightMap.removeValue(forKey: ObjectIdentifier(obj as AnyObject))
|
|
|
|
}
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-05-13 13:45:48 -07:00
|
|
|
// Declaration and FfiConverters for Progress Callback Interface
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-05-13 13:45:48 -07:00
|
|
|
public protocol Progress : AnyObject {
|
2022-10-21 17:18:30 -05:00
|
|
|
func `update`(`progress`: Float, `message`: String?)
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// The ForeignCallback that is passed to Rust.
|
2022-05-13 13:45:48 -07:00
|
|
|
fileprivate let foreignCallbackCallbackInterfaceProgress : ForeignCallback =
|
2022-03-02 15:17:53 -08:00
|
|
|
{ (handle: Handle, method: Int32, args: RustBuffer, out_buf: UnsafeMutablePointer<RustBuffer>) -> Int32 in
|
2022-10-21 17:18:30 -05:00
|
|
|
func `invokeUpdate`(_ swiftCallbackInterface: Progress, _ args: RustBuffer) throws -> RustBuffer {
|
2021-11-24 00:10:26 -08:00
|
|
|
defer { args.deallocate() }
|
|
|
|
|
|
|
|
let reader = Reader(data: Data(rustBuffer: args))
|
2022-10-21 17:18:30 -05:00
|
|
|
swiftCallbackInterface.`update`(
|
|
|
|
`progress`: try FfiConverterFloat.read(from: reader),
|
|
|
|
`message`: try FfiConverterOptionString.read(from: reader)
|
2021-11-24 00:10:26 -08:00
|
|
|
)
|
|
|
|
return RustBuffer()
|
|
|
|
// TODO catch errors and report them back to Rust.
|
|
|
|
// https://github.com/mozilla/uniffi-rs/issues/351
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let cb: Progress
|
|
|
|
do {
|
|
|
|
cb = try FfiConverterCallbackInterfaceProgress.lift(handle)
|
|
|
|
} catch {
|
|
|
|
out_buf.pointee = FfiConverterString.lower("Progress: Invalid handle")
|
|
|
|
return -1
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
switch method {
|
|
|
|
case IDX_CALLBACK_FREE:
|
2022-10-21 17:18:30 -05:00
|
|
|
FfiConverterCallbackInterfaceProgress.drop(handle: handle)
|
2022-03-02 15:17:53 -08:00
|
|
|
// No return value.
|
|
|
|
// See docs of ForeignCallback in `uniffi/src/ffi/foreigncallbacks.rs`
|
|
|
|
return 0
|
|
|
|
case 1:
|
2022-10-21 17:18:30 -05:00
|
|
|
do {
|
|
|
|
out_buf.pointee = try `invokeUpdate`(cb, args)
|
|
|
|
// Value written to out buffer.
|
|
|
|
// See docs of ForeignCallback in `uniffi/src/ffi/foreigncallbacks.rs`
|
|
|
|
return 1
|
|
|
|
} catch let error {
|
|
|
|
out_buf.pointee = FfiConverterString.lower(String(describing: error))
|
|
|
|
return -1
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
// This should never happen, because an out of bounds method index won't
|
|
|
|
// ever be used. Once we can catch errors, we should return an InternalError.
|
|
|
|
// https://github.com/mozilla/uniffi-rs/issues/351
|
2022-03-02 15:17:53 -08:00
|
|
|
default:
|
|
|
|
// An unexpected error happened.
|
|
|
|
// See docs of ForeignCallback in `uniffi/src/ffi/foreigncallbacks.rs`
|
|
|
|
return -1
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
// FFIConverter protocol for callback interfaces
|
|
|
|
fileprivate struct FfiConverterCallbackInterfaceProgress {
|
|
|
|
// Initialize our callback method with the scaffolding code
|
|
|
|
private static var callbackInitialized = false
|
|
|
|
private static func initCallback() {
|
|
|
|
try! rustCall { (err: UnsafeMutablePointer<RustCallStatus>) in
|
|
|
|
ffi_bdk_1724_Progress_init_callback(foreignCallbackCallbackInterfaceProgress, err)
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
private static func ensureCallbackinitialized() {
|
|
|
|
if !callbackInitialized {
|
|
|
|
initCallback()
|
|
|
|
callbackInitialized = true
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func drop(handle: Handle) {
|
|
|
|
handleMap.remove(handle: handle)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
|
|
|
|
private static var handleMap = ConcurrentHandleMap<Progress>()
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
|
|
|
|
extension FfiConverterCallbackInterfaceProgress : FfiConverter {
|
|
|
|
typealias SwiftType = Progress
|
|
|
|
// We can use Handle as the FFIType because it's a typealias to UInt64
|
|
|
|
typealias FfiType = Handle
|
|
|
|
|
|
|
|
static func lift(_ handle: Handle) throws -> SwiftType {
|
|
|
|
ensureCallbackinitialized();
|
|
|
|
guard let callback = handleMap.get(handle: handle) else {
|
|
|
|
throw UniffiInternalError.unexpectedStaleHandle
|
|
|
|
}
|
|
|
|
return callback
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> SwiftType {
|
|
|
|
ensureCallbackinitialized();
|
|
|
|
let handle: Handle = try buf.readInt()
|
|
|
|
return try lift(handle)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
|
|
|
|
static func lower(_ v: SwiftType) -> Handle {
|
|
|
|
ensureCallbackinitialized();
|
|
|
|
return handleMap.insert(obj: v)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ v: SwiftType, into buf: Writer) {
|
|
|
|
ensureCallbackinitialized();
|
|
|
|
buf.writeInt(lower(v))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
|
|
|
|
fileprivate struct FfiConverterOptionUInt8: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = UInt8?
|
|
|
|
|
|
|
|
static func write(_ value: SwiftType, into buf: Writer) {
|
|
|
|
guard let value = value else {
|
|
|
|
buf.writeInt(Int8(0))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
buf.writeInt(Int8(1))
|
|
|
|
FfiConverterUInt8.write(value, into: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> SwiftType {
|
|
|
|
switch try buf.readInt() as Int8 {
|
|
|
|
case 0: return nil
|
|
|
|
case 1: return try FfiConverterUInt8.read(from: buf)
|
|
|
|
default: throw UniffiInternalError.unexpectedOptionalTag
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
2022-06-23 11:03:45 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterOptionUInt64: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = UInt64?
|
|
|
|
|
|
|
|
static func write(_ value: SwiftType, into buf: Writer) {
|
|
|
|
guard let value = value else {
|
|
|
|
buf.writeInt(Int8(0))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
buf.writeInt(Int8(1))
|
|
|
|
FfiConverterUInt64.write(value, into: buf)
|
2022-06-23 11:03:45 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> SwiftType {
|
|
|
|
switch try buf.readInt() as Int8 {
|
|
|
|
case 0: return nil
|
|
|
|
case 1: return try FfiConverterUInt64.read(from: buf)
|
|
|
|
default: throw UniffiInternalError.unexpectedOptionalTag
|
|
|
|
}
|
2022-06-23 11:03:45 -07:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = String?
|
2022-06-23 11:03:45 -07:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: SwiftType, into buf: Writer) {
|
|
|
|
guard let value = value else {
|
|
|
|
buf.writeInt(Int8(0))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
buf.writeInt(Int8(1))
|
|
|
|
FfiConverterString.write(value, into: buf)
|
2022-06-23 11:03:45 -07:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> SwiftType {
|
|
|
|
switch try buf.readInt() as Int8 {
|
|
|
|
case 0: return nil
|
|
|
|
case 1: return try FfiConverterString.read(from: buf)
|
|
|
|
default: throw UniffiInternalError.unexpectedOptionalTag
|
|
|
|
}
|
2022-06-23 11:03:45 -07:00
|
|
|
}
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterOptionTypeBlockTime: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = BlockTime?
|
|
|
|
|
|
|
|
static func write(_ value: SwiftType, into buf: Writer) {
|
|
|
|
guard let value = value else {
|
|
|
|
buf.writeInt(Int8(0))
|
|
|
|
return
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
buf.writeInt(Int8(1))
|
|
|
|
FfiConverterTypeBlockTime.write(value, into: buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func read(from buf: Reader) throws -> SwiftType {
|
|
|
|
switch try buf.readInt() as Int8 {
|
|
|
|
case 0: return nil
|
|
|
|
case 1: return try FfiConverterTypeBlockTime.read(from: buf)
|
|
|
|
default: throw UniffiInternalError.unexpectedOptionalTag
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterOptionCallbackInterfaceProgress: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = Progress?
|
|
|
|
|
|
|
|
static func write(_ value: SwiftType, into buf: Writer) {
|
|
|
|
guard let value = value else {
|
|
|
|
buf.writeInt(Int8(0))
|
|
|
|
return
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
buf.writeInt(Int8(1))
|
|
|
|
FfiConverterCallbackInterfaceProgress.write(value, into: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> SwiftType {
|
|
|
|
switch try buf.readInt() as Int8 {
|
|
|
|
case 0: return nil
|
|
|
|
case 1: return try FfiConverterCallbackInterfaceProgress.read(from: buf)
|
|
|
|
default: throw UniffiInternalError.unexpectedOptionalTag
|
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
}
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterSequenceUInt8: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = [UInt8]
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: [UInt8], into buf: Writer) {
|
|
|
|
let len = Int32(value.count)
|
|
|
|
buf.writeInt(len)
|
|
|
|
for item in value {
|
|
|
|
FfiConverterUInt8.write(item, into: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> [UInt8] {
|
|
|
|
let len: Int32 = try buf.readInt()
|
|
|
|
var seq = [UInt8]()
|
|
|
|
seq.reserveCapacity(Int(len))
|
|
|
|
for _ in 0 ..< len {
|
|
|
|
seq.append(try FfiConverterUInt8.read(from: buf))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return seq
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterSequenceTypeLocalUtxo: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = [LocalUtxo]
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: [LocalUtxo], into buf: Writer) {
|
|
|
|
let len = Int32(value.count)
|
|
|
|
buf.writeInt(len)
|
|
|
|
for item in value {
|
|
|
|
FfiConverterTypeLocalUtxo.write(item, into: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> [LocalUtxo] {
|
|
|
|
let len: Int32 = try buf.readInt()
|
|
|
|
var seq = [LocalUtxo]()
|
|
|
|
seq.reserveCapacity(Int(len))
|
|
|
|
for _ in 0 ..< len {
|
|
|
|
seq.append(try FfiConverterTypeLocalUtxo.read(from: buf))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return seq
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterSequenceTypeOutPoint: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = [OutPoint]
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: [OutPoint], into buf: Writer) {
|
|
|
|
let len = Int32(value.count)
|
|
|
|
buf.writeInt(len)
|
|
|
|
for item in value {
|
|
|
|
FfiConverterTypeOutPoint.write(item, into: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> [OutPoint] {
|
|
|
|
let len: Int32 = try buf.readInt()
|
|
|
|
var seq = [OutPoint]()
|
|
|
|
seq.reserveCapacity(Int(len))
|
|
|
|
for _ in 0 ..< len {
|
|
|
|
seq.append(try FfiConverterTypeOutPoint.read(from: buf))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return seq
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterSequenceTypeScriptAmount: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = [ScriptAmount]
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: [ScriptAmount], into buf: Writer) {
|
|
|
|
let len = Int32(value.count)
|
|
|
|
buf.writeInt(len)
|
|
|
|
for item in value {
|
|
|
|
FfiConverterTypeScriptAmount.write(item, into: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> [ScriptAmount] {
|
|
|
|
let len: Int32 = try buf.readInt()
|
|
|
|
var seq = [ScriptAmount]()
|
|
|
|
seq.reserveCapacity(Int(len))
|
|
|
|
for _ in 0 ..< len {
|
|
|
|
seq.append(try FfiConverterTypeScriptAmount.read(from: buf))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return seq
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
fileprivate struct FfiConverterSequenceTypeTransactionDetails: FfiConverterRustBuffer {
|
|
|
|
typealias SwiftType = [TransactionDetails]
|
2021-11-24 00:10:26 -08:00
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func write(_ value: [TransactionDetails], into buf: Writer) {
|
|
|
|
let len = Int32(value.count)
|
|
|
|
buf.writeInt(len)
|
|
|
|
for item in value {
|
|
|
|
FfiConverterTypeTransactionDetails.write(item, into: buf)
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
static func read(from buf: Reader) throws -> [TransactionDetails] {
|
|
|
|
let len: Int32 = try buf.readInt()
|
|
|
|
var seq = [TransactionDetails]()
|
|
|
|
seq.reserveCapacity(Int(len))
|
|
|
|
for _ in 0 ..< len {
|
|
|
|
seq.append(try FfiConverterTypeTransactionDetails.read(from: buf))
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
2022-10-21 17:18:30 -05:00
|
|
|
return seq
|
2021-11-24 00:10:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:18:30 -05:00
|
|
|
public func `generateMnemonic`(`wordCount`: WordCount) throws -> String {
|
|
|
|
return try FfiConverterString.lift(
|
|
|
|
try
|
|
|
|
|
|
|
|
rustCallWithError(FfiConverterTypeBdkError.self) {
|
|
|
|
|
|
|
|
bdk_1724_generate_mnemonic(
|
|
|
|
FfiConverterTypeWordCount.lower(`wordCount`), $0)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-24 00:10:26 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Top level initializers and tear down methods.
|
|
|
|
*
|
|
|
|
* This is generated by uniffi.
|
|
|
|
*/
|
|
|
|
public enum BdkLifecycle {
|
|
|
|
/**
|
|
|
|
* Initialize the FFI and Rust library. This should be only called once per application.
|
|
|
|
*/
|
|
|
|
func initialize() {
|
|
|
|
}
|
|
|
|
}
|