@runflame/wallet-rn 0.0.0-stage → 0.0.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FlameWalletNative.podspec +15 -0
- package/LICENSE.txt +201 -0
- package/android/build.gradle +30 -0
- package/android/src/main/java/com/flame/wallet/flamewallet_ffi.kt +2847 -0
- package/android/src/main/jniLibs/arm64-v8a/libflamewallet_ffi.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libflamewallet_ffi.so +0 -0
- package/android/src/main/jniLibs/x86_64/libflamewallet_ffi.so +0 -0
- package/expo-module.config.json +3 -0
- package/ios/FlameWallet.swift +2195 -0
- package/ios/FlameWalletFFI.xcframework/Info.plist +44 -0
- package/ios/FlameWalletFFI.xcframework/ios-arm64/FlameWalletFFI.framework/FlameWalletFFI +0 -0
- package/ios/FlameWalletFFI.xcframework/ios-arm64/FlameWalletFFI.framework/Headers/FlameWalletFFI.h +687 -0
- package/ios/FlameWalletFFI.xcframework/ios-arm64/FlameWalletFFI.framework/Info.plist +16 -0
- package/ios/FlameWalletFFI.xcframework/ios-arm64/FlameWalletFFI.framework/Modules/module.modulemap +4 -0
- package/ios/FlameWalletFFI.xcframework/ios-arm64_x86_64-simulator/FlameWalletFFI.framework/FlameWalletFFI +0 -0
- package/ios/FlameWalletFFI.xcframework/ios-arm64_x86_64-simulator/FlameWalletFFI.framework/Headers/FlameWalletFFI.h +687 -0
- package/ios/FlameWalletFFI.xcframework/ios-arm64_x86_64-simulator/FlameWalletFFI.framework/Info.plist +16 -0
- package/ios/FlameWalletFFI.xcframework/ios-arm64_x86_64-simulator/FlameWalletFFI.framework/Modules/module.modulemap +4 -0
- package/package.json +17 -4
- package/README.md +0 -3
|
@@ -0,0 +1,2195 @@
|
|
|
1
|
+
// This file was autogenerated by some hot garbage in the `uniffi` crate.
|
|
2
|
+
// Trust me, you don't want to mess with it!
|
|
3
|
+
|
|
4
|
+
// swiftlint:disable all
|
|
5
|
+
import Foundation
|
|
6
|
+
|
|
7
|
+
// Depending on the consumer's build setup, the low-level FFI code
|
|
8
|
+
// might be in a separate module, or it might be compiled inline into
|
|
9
|
+
// this module. This is a bit of light hackery to work with both.
|
|
10
|
+
#if canImport(FlameWalletFFI)
|
|
11
|
+
import FlameWalletFFI
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
fileprivate extension RustBuffer {
|
|
15
|
+
// Allocate a new buffer, copying the contents of a `UInt8` array.
|
|
16
|
+
init(bytes: [UInt8]) {
|
|
17
|
+
let rbuf = bytes.withUnsafeBufferPointer { ptr in
|
|
18
|
+
RustBuffer.from(ptr)
|
|
19
|
+
}
|
|
20
|
+
self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static func empty() -> RustBuffer {
|
|
24
|
+
RustBuffer(capacity: 0, len:0, data: nil)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static func from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
|
|
28
|
+
try! rustCall { ffi_flamewallet_ffi_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Frees the buffer in place.
|
|
32
|
+
// The buffer must not be used after this is called.
|
|
33
|
+
func deallocate() {
|
|
34
|
+
try! rustCall { ffi_flamewallet_ffi_rustbuffer_free(self, $0) }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fileprivate extension ForeignBytes {
|
|
39
|
+
init(bufferPointer: UnsafeBufferPointer<UInt8>) {
|
|
40
|
+
self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
init(rawBufferPointer: UnsafeRawBufferPointer) {
|
|
44
|
+
self.init(
|
|
45
|
+
len: Int32(rawBufferPointer.count),
|
|
46
|
+
data: rawBufferPointer.baseAddress?.assumingMemoryBound(to: UInt8.self)
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Converter for `&[u8]` / `[ByRef] bytes` arguments.
|
|
52
|
+
//
|
|
53
|
+
// Conforms to `FfiConverter` so the compiler enforces the full converter
|
|
54
|
+
// method set. Only the scope-bound `lower(_:_body:)` overload is sound —
|
|
55
|
+
// zero-copy byte buffers only flow foreign -> Rust, and only in argument
|
|
56
|
+
// position. The four protocol-witness methods (`lift`, `lower`, `read`,
|
|
57
|
+
// `write`) `fatalError` at runtime if anyone reaches them.
|
|
58
|
+
//
|
|
59
|
+
// The scope-bound `lower` takes a closure because the `ForeignBytes`
|
|
60
|
+
// pointer is only guaranteed valid for the duration of
|
|
61
|
+
// `Data.withUnsafeBytes`. Callers must run the full FFI call inside
|
|
62
|
+
// the closure body.
|
|
63
|
+
fileprivate enum FfiConverterByRefBytes: FfiConverter {
|
|
64
|
+
typealias SwiftType = Data
|
|
65
|
+
typealias FfiType = ForeignBytes
|
|
66
|
+
|
|
67
|
+
static func lower<R>(_ value: Data, _ body: (ForeignBytes) throws -> R) rethrows -> R {
|
|
68
|
+
return try value.withUnsafeBytes { rawBuf in
|
|
69
|
+
try body(ForeignBytes(rawBufferPointer: rawBuf))
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static func lower(_ value: Data) -> ForeignBytes {
|
|
74
|
+
fatalError("ByRef bytes cannot use the plain lower: returning ForeignBytes escapes the Data.withUnsafeBytes scope. Use the scope-bound lower(_:_body:) overload instead.")
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static func lift(_ value: ForeignBytes) throws -> Data {
|
|
78
|
+
fatalError("ByRef bytes cannot be lifted: zero-copy &[u8] only flows foreign->Rust")
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data {
|
|
82
|
+
fatalError("ByRef bytes cannot be read from a buffer: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.")
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static func write(_ value: Data, into buf: inout [UInt8]) {
|
|
86
|
+
fatalError("ByRef bytes cannot be written to a buffer: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.")
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// For every type used in the interface, we provide helper methods for conveniently
|
|
91
|
+
// lifting and lowering that type from C-compatible data, and for reading and writing
|
|
92
|
+
// values of that type in a buffer.
|
|
93
|
+
|
|
94
|
+
// Helper classes/extensions that don't change.
|
|
95
|
+
// Someday, this will be in a library of its own.
|
|
96
|
+
|
|
97
|
+
fileprivate extension Data {
|
|
98
|
+
init(rustBuffer: RustBuffer) {
|
|
99
|
+
self.init(
|
|
100
|
+
bytesNoCopy: rustBuffer.data!,
|
|
101
|
+
count: Int(rustBuffer.len),
|
|
102
|
+
deallocator: .none
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Define reader functionality. Normally this would be defined in a class or
|
|
108
|
+
// struct, but we use standalone functions instead in order to make external
|
|
109
|
+
// types work.
|
|
110
|
+
//
|
|
111
|
+
// With external types, one swift source file needs to be able to call the read
|
|
112
|
+
// method on another source file's FfiConverter, but then what visibility
|
|
113
|
+
// should Reader have?
|
|
114
|
+
// - If Reader is fileprivate, then this means the read() must also
|
|
115
|
+
// be fileprivate, which doesn't work with external types.
|
|
116
|
+
// - If Reader is internal/public, we'll get compile errors since both source
|
|
117
|
+
// files will try define the same type.
|
|
118
|
+
//
|
|
119
|
+
// Instead, the read() method and these helper functions input a tuple of data
|
|
120
|
+
|
|
121
|
+
fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) {
|
|
122
|
+
(data: data, offset: 0)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Reads an integer at the current offset, in big-endian order, and advances
|
|
126
|
+
// the offset on success. Throws if reading the integer would move the
|
|
127
|
+
// offset past the end of the buffer.
|
|
128
|
+
fileprivate func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
|
|
129
|
+
let range = reader.offset..<reader.offset + MemoryLayout<T>.size
|
|
130
|
+
guard reader.data.count >= range.upperBound else {
|
|
131
|
+
throw UniffiInternalError.bufferOverflow
|
|
132
|
+
}
|
|
133
|
+
if T.self == UInt8.self {
|
|
134
|
+
let value = reader.data[reader.offset]
|
|
135
|
+
reader.offset += 1
|
|
136
|
+
return value as! T
|
|
137
|
+
}
|
|
138
|
+
var value: T = 0
|
|
139
|
+
let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)})
|
|
140
|
+
reader.offset = range.upperBound
|
|
141
|
+
return value.bigEndian
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Reads an arbitrary number of bytes, to be used to read
|
|
145
|
+
// raw bytes, this is useful when lifting strings
|
|
146
|
+
fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array<UInt8> {
|
|
147
|
+
let range = reader.offset..<(reader.offset+count)
|
|
148
|
+
guard reader.data.count >= range.upperBound else {
|
|
149
|
+
throw UniffiInternalError.bufferOverflow
|
|
150
|
+
}
|
|
151
|
+
var value = [UInt8](repeating: 0, count: count)
|
|
152
|
+
value.withUnsafeMutableBufferPointer({ buffer in
|
|
153
|
+
reader.data.copyBytes(to: buffer, from: range)
|
|
154
|
+
})
|
|
155
|
+
reader.offset = range.upperBound
|
|
156
|
+
return value
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Reads a float at the current offset.
|
|
160
|
+
fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
|
|
161
|
+
return Float(bitPattern: try readInt(&reader))
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Reads a float at the current offset.
|
|
165
|
+
fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
|
|
166
|
+
return Double(bitPattern: try readInt(&reader))
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Indicates if the offset has reached the end of the buffer.
|
|
170
|
+
fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
|
|
171
|
+
return reader.offset < reader.data.count
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Define writer functionality. Normally this would be defined in a class or
|
|
175
|
+
// struct, but we use standalone functions instead in order to make external
|
|
176
|
+
// types work. See the above discussion on Readers for details.
|
|
177
|
+
|
|
178
|
+
fileprivate func createWriter() -> [UInt8] {
|
|
179
|
+
return []
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
fileprivate func writeBytes<S>(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 {
|
|
183
|
+
writer.append(contentsOf: byteArr)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Writes an integer in big-endian order.
|
|
187
|
+
//
|
|
188
|
+
// Warning: make sure what you are trying to write
|
|
189
|
+
// is in the correct type!
|
|
190
|
+
fileprivate func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
|
|
191
|
+
var value = value.bigEndian
|
|
192
|
+
withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) {
|
|
196
|
+
writeInt(&writer, value.bitPattern)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
|
|
200
|
+
writeInt(&writer, value.bitPattern)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Protocol for types that transfer other types across the FFI. This is
|
|
204
|
+
// analogous to the Rust trait of the same name.
|
|
205
|
+
fileprivate protocol FfiConverter {
|
|
206
|
+
associatedtype FfiType
|
|
207
|
+
associatedtype SwiftType
|
|
208
|
+
|
|
209
|
+
static func lift(_ value: FfiType) throws -> SwiftType
|
|
210
|
+
static func lower(_ value: SwiftType) -> FfiType
|
|
211
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
|
|
212
|
+
static func write(_ value: SwiftType, into buf: inout [UInt8])
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Types conforming to `Primitive` pass themselves directly over the FFI.
|
|
216
|
+
fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }
|
|
217
|
+
|
|
218
|
+
extension FfiConverterPrimitive {
|
|
219
|
+
#if swift(>=5.8)
|
|
220
|
+
@_documentation(visibility: private)
|
|
221
|
+
#endif
|
|
222
|
+
public static func lift(_ value: FfiType) throws -> SwiftType {
|
|
223
|
+
return value
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
#if swift(>=5.8)
|
|
227
|
+
@_documentation(visibility: private)
|
|
228
|
+
#endif
|
|
229
|
+
public static func lower(_ value: SwiftType) -> FfiType {
|
|
230
|
+
return value
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
|
|
235
|
+
// Used for complex types where it's hard to write a custom lift/lower.
|
|
236
|
+
fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}
|
|
237
|
+
|
|
238
|
+
extension FfiConverterRustBuffer {
|
|
239
|
+
#if swift(>=5.8)
|
|
240
|
+
@_documentation(visibility: private)
|
|
241
|
+
#endif
|
|
242
|
+
public static func lift(_ buf: RustBuffer) throws -> SwiftType {
|
|
243
|
+
var reader = createReader(data: Data(rustBuffer: buf))
|
|
244
|
+
let value = try read(from: &reader)
|
|
245
|
+
if hasRemaining(reader) {
|
|
246
|
+
throw UniffiInternalError.incompleteData
|
|
247
|
+
}
|
|
248
|
+
buf.deallocate()
|
|
249
|
+
return value
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#if swift(>=5.8)
|
|
253
|
+
@_documentation(visibility: private)
|
|
254
|
+
#endif
|
|
255
|
+
public static func lower(_ value: SwiftType) -> RustBuffer {
|
|
256
|
+
var writer = createWriter()
|
|
257
|
+
write(value, into: &writer)
|
|
258
|
+
return RustBuffer(bytes: writer)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// An error type for FFI errors. These errors occur at the UniFFI level, not
|
|
262
|
+
// the library level.
|
|
263
|
+
fileprivate enum UniffiInternalError: LocalizedError {
|
|
264
|
+
case bufferOverflow
|
|
265
|
+
case incompleteData
|
|
266
|
+
case unexpectedOptionalTag
|
|
267
|
+
case unexpectedEnumCase
|
|
268
|
+
case unexpectedNullPointer
|
|
269
|
+
case unexpectedRustCallStatusCode
|
|
270
|
+
case unexpectedRustCallError
|
|
271
|
+
case unexpectedStaleHandle
|
|
272
|
+
case rustPanic(_ message: String)
|
|
273
|
+
|
|
274
|
+
public var errorDescription: String? {
|
|
275
|
+
switch self {
|
|
276
|
+
case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
|
|
277
|
+
case .incompleteData: return "The buffer still has data after lifting its containing value"
|
|
278
|
+
case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
|
|
279
|
+
case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
|
|
280
|
+
case .unexpectedNullPointer: return "Raw pointer value was null"
|
|
281
|
+
case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
|
|
282
|
+
case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
|
|
283
|
+
case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
|
|
284
|
+
case let .rustPanic(message): return message
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
fileprivate extension NSLock {
|
|
290
|
+
func withLock<T>(f: () throws -> T) rethrows -> T {
|
|
291
|
+
self.lock()
|
|
292
|
+
defer { self.unlock() }
|
|
293
|
+
return try f()
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
fileprivate let CALL_SUCCESS: Int8 = 0
|
|
298
|
+
fileprivate let CALL_ERROR: Int8 = 1
|
|
299
|
+
fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2
|
|
300
|
+
fileprivate let CALL_CANCELLED: Int8 = 3
|
|
301
|
+
|
|
302
|
+
fileprivate extension RustCallStatus {
|
|
303
|
+
init() {
|
|
304
|
+
self.init(
|
|
305
|
+
code: CALL_SUCCESS,
|
|
306
|
+
errorBuf: RustBuffer.init(
|
|
307
|
+
capacity: 0,
|
|
308
|
+
len: 0,
|
|
309
|
+
data: nil
|
|
310
|
+
)
|
|
311
|
+
)
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
|
|
316
|
+
let neverThrow: ((RustBuffer) throws -> Never)? = nil
|
|
317
|
+
return try makeRustCall(callback, errorHandler: neverThrow)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private func rustCallWithError<T, E: Swift.Error>(
|
|
321
|
+
_ errorHandler: @escaping (RustBuffer) throws -> E,
|
|
322
|
+
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
|
|
323
|
+
try makeRustCall(callback, errorHandler: errorHandler)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private func makeRustCall<T, E: Swift.Error>(
|
|
327
|
+
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
|
|
328
|
+
errorHandler: ((RustBuffer) throws -> E)?
|
|
329
|
+
) throws -> T {
|
|
330
|
+
uniffiEnsureFlamewalletFfiInitialized()
|
|
331
|
+
var callStatus = RustCallStatus.init()
|
|
332
|
+
let returnedVal = callback(&callStatus)
|
|
333
|
+
try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
|
|
334
|
+
return returnedVal
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
private func uniffiCheckCallStatus<E: Swift.Error>(
|
|
338
|
+
callStatus: RustCallStatus,
|
|
339
|
+
errorHandler: ((RustBuffer) throws -> E)?
|
|
340
|
+
) throws {
|
|
341
|
+
switch callStatus.code {
|
|
342
|
+
case CALL_SUCCESS:
|
|
343
|
+
return
|
|
344
|
+
|
|
345
|
+
case CALL_ERROR:
|
|
346
|
+
if let errorHandler = errorHandler {
|
|
347
|
+
throw try errorHandler(callStatus.errorBuf)
|
|
348
|
+
} else {
|
|
349
|
+
callStatus.errorBuf.deallocate()
|
|
350
|
+
throw UniffiInternalError.unexpectedRustCallError
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
case CALL_UNEXPECTED_ERROR:
|
|
354
|
+
// When the rust code sees a panic, it tries to construct a RustBuffer
|
|
355
|
+
// with the message. But if that code panics, then it just sends back
|
|
356
|
+
// an empty buffer.
|
|
357
|
+
if callStatus.errorBuf.len > 0 {
|
|
358
|
+
throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
|
|
359
|
+
} else {
|
|
360
|
+
callStatus.errorBuf.deallocate()
|
|
361
|
+
throw UniffiInternalError.rustPanic("Rust panic")
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
case CALL_CANCELLED:
|
|
365
|
+
fatalError("Cancellation not supported yet")
|
|
366
|
+
|
|
367
|
+
default:
|
|
368
|
+
throw UniffiInternalError.unexpectedRustCallStatusCode
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
private func uniffiTraitInterfaceCall<T>(
|
|
373
|
+
callStatus: UnsafeMutablePointer<RustCallStatus>,
|
|
374
|
+
makeCall: () throws -> T,
|
|
375
|
+
writeReturn: (T) -> ()
|
|
376
|
+
) {
|
|
377
|
+
do {
|
|
378
|
+
try writeReturn(makeCall())
|
|
379
|
+
} catch let error {
|
|
380
|
+
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
|
|
381
|
+
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
private func uniffiTraitInterfaceCallWithError<T, E>(
|
|
386
|
+
callStatus: UnsafeMutablePointer<RustCallStatus>,
|
|
387
|
+
makeCall: () throws -> T,
|
|
388
|
+
writeReturn: (T) -> (),
|
|
389
|
+
lowerError: (E) -> RustBuffer
|
|
390
|
+
) {
|
|
391
|
+
do {
|
|
392
|
+
try writeReturn(makeCall())
|
|
393
|
+
} catch let error as E {
|
|
394
|
+
callStatus.pointee.code = CALL_ERROR
|
|
395
|
+
callStatus.pointee.errorBuf = lowerError(error)
|
|
396
|
+
} catch {
|
|
397
|
+
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
|
|
398
|
+
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
// Initial value and increment amount for handles.
|
|
402
|
+
// These ensure that SWIFT handles always have the lowest bit set
|
|
403
|
+
fileprivate let UNIFFI_HANDLEMAP_INITIAL: UInt64 = 1
|
|
404
|
+
fileprivate let UNIFFI_HANDLEMAP_DELTA: UInt64 = 2
|
|
405
|
+
|
|
406
|
+
fileprivate final class UniffiHandleMap<T>: @unchecked Sendable {
|
|
407
|
+
// All mutation happens with this lock held, which is why we implement @unchecked Sendable.
|
|
408
|
+
private let lock = NSLock()
|
|
409
|
+
private var map: [UInt64: T] = [:]
|
|
410
|
+
private var currentHandle: UInt64 = UNIFFI_HANDLEMAP_INITIAL
|
|
411
|
+
|
|
412
|
+
func insert(obj: T) -> UInt64 {
|
|
413
|
+
lock.withLock {
|
|
414
|
+
return doInsert(obj)
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// Low-level insert function, this assumes `lock` is held.
|
|
419
|
+
private func doInsert(_ obj: T) -> UInt64 {
|
|
420
|
+
let handle = currentHandle
|
|
421
|
+
currentHandle += UNIFFI_HANDLEMAP_DELTA
|
|
422
|
+
map[handle] = obj
|
|
423
|
+
return handle
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
func get(handle: UInt64) throws -> T {
|
|
427
|
+
try lock.withLock {
|
|
428
|
+
guard let obj = map[handle] else {
|
|
429
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
430
|
+
}
|
|
431
|
+
return obj
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
func clone(handle: UInt64) throws -> UInt64 {
|
|
436
|
+
try lock.withLock {
|
|
437
|
+
guard let obj = map[handle] else {
|
|
438
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
439
|
+
}
|
|
440
|
+
return doInsert(obj)
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
@discardableResult
|
|
445
|
+
func remove(handle: UInt64) throws -> T {
|
|
446
|
+
try lock.withLock {
|
|
447
|
+
guard let obj = map.removeValue(forKey: handle) else {
|
|
448
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
449
|
+
}
|
|
450
|
+
return obj
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
var count: Int {
|
|
455
|
+
get {
|
|
456
|
+
map.count
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
// Public interface members begin here.
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
#if swift(>=5.8)
|
|
466
|
+
@_documentation(visibility: private)
|
|
467
|
+
#endif
|
|
468
|
+
fileprivate struct FfiConverterUInt8: FfiConverterPrimitive {
|
|
469
|
+
typealias FfiType = UInt8
|
|
470
|
+
typealias SwiftType = UInt8
|
|
471
|
+
|
|
472
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt8 {
|
|
473
|
+
return try lift(readInt(&buf))
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
public static func write(_ value: UInt8, into buf: inout [UInt8]) {
|
|
477
|
+
writeInt(&buf, lower(value))
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
#if swift(>=5.8)
|
|
482
|
+
@_documentation(visibility: private)
|
|
483
|
+
#endif
|
|
484
|
+
fileprivate struct FfiConverterUInt32: FfiConverterPrimitive {
|
|
485
|
+
typealias FfiType = UInt32
|
|
486
|
+
typealias SwiftType = UInt32
|
|
487
|
+
|
|
488
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 {
|
|
489
|
+
return try lift(readInt(&buf))
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
493
|
+
writeInt(&buf, lower(value))
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
#if swift(>=5.8)
|
|
498
|
+
@_documentation(visibility: private)
|
|
499
|
+
#endif
|
|
500
|
+
fileprivate struct FfiConverterUInt64: FfiConverterPrimitive {
|
|
501
|
+
typealias FfiType = UInt64
|
|
502
|
+
typealias SwiftType = UInt64
|
|
503
|
+
|
|
504
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 {
|
|
505
|
+
return try lift(readInt(&buf))
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
509
|
+
writeInt(&buf, lower(value))
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
#if swift(>=5.8)
|
|
514
|
+
@_documentation(visibility: private)
|
|
515
|
+
#endif
|
|
516
|
+
fileprivate struct FfiConverterBool : FfiConverter {
|
|
517
|
+
typealias FfiType = Int8
|
|
518
|
+
typealias SwiftType = Bool
|
|
519
|
+
|
|
520
|
+
public static func lift(_ value: Int8) throws -> Bool {
|
|
521
|
+
return value != 0
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
public static func lower(_ value: Bool) -> Int8 {
|
|
525
|
+
return value ? 1 : 0
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool {
|
|
529
|
+
return try lift(readInt(&buf))
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
public static func write(_ value: Bool, into buf: inout [UInt8]) {
|
|
533
|
+
writeInt(&buf, lower(value))
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
#if swift(>=5.8)
|
|
538
|
+
@_documentation(visibility: private)
|
|
539
|
+
#endif
|
|
540
|
+
fileprivate struct FfiConverterString: FfiConverter {
|
|
541
|
+
typealias SwiftType = String
|
|
542
|
+
typealias FfiType = RustBuffer
|
|
543
|
+
|
|
544
|
+
public static func lift(_ value: RustBuffer) throws -> String {
|
|
545
|
+
defer {
|
|
546
|
+
value.deallocate()
|
|
547
|
+
}
|
|
548
|
+
if value.data == nil {
|
|
549
|
+
return String()
|
|
550
|
+
}
|
|
551
|
+
let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
|
|
552
|
+
// Use Swift's native UTF-8 decoder; `String(bytes:encoding:.utf8)` goes
|
|
553
|
+
// through Foundation's NSString and silently strips a leading U+FEFF BOM.
|
|
554
|
+
// Invalid UTF-8 substitutes U+FFFD instead of trapping (unreachable
|
|
555
|
+
// given Rust's `String` invariant).
|
|
556
|
+
return String(decoding: bytes, as: UTF8.self)
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
public static func lower(_ value: String) -> RustBuffer {
|
|
560
|
+
return value.utf8CString.withUnsafeBufferPointer { ptr in
|
|
561
|
+
// The swift string gives us int8_t, we want uint8_t.
|
|
562
|
+
ptr.withMemoryRebound(to: UInt8.self) { ptr in
|
|
563
|
+
// The swift string gives us a trailing null byte, we don't want it.
|
|
564
|
+
let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
|
|
565
|
+
return RustBuffer.from(buf)
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
|
|
571
|
+
let len: Int32 = try readInt(&buf)
|
|
572
|
+
// See `lift` above for why we avoid Foundation's NSString-backed decoder here.
|
|
573
|
+
return String(decoding: try readBytes(&buf, count: Int(len)), as: UTF8.self)
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
public static func write(_ value: String, into buf: inout [UInt8]) {
|
|
577
|
+
let len = Int32(value.utf8.count)
|
|
578
|
+
writeInt(&buf, len)
|
|
579
|
+
writeBytes(&buf, value.utf8)
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
#if swift(>=5.8)
|
|
584
|
+
@_documentation(visibility: private)
|
|
585
|
+
#endif
|
|
586
|
+
fileprivate struct FfiConverterData: FfiConverterRustBuffer {
|
|
587
|
+
typealias SwiftType = Data
|
|
588
|
+
|
|
589
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data {
|
|
590
|
+
let len: Int32 = try readInt(&buf)
|
|
591
|
+
return Data(try readBytes(&buf, count: Int(len)))
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
public static func write(_ value: Data, into buf: inout [UInt8]) {
|
|
595
|
+
let len = Int32(value.count)
|
|
596
|
+
writeInt(&buf, len)
|
|
597
|
+
writeBytes(&buf, value)
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* One account, `m/35263'/network'/0'`, behind an opaque handle.
|
|
606
|
+
*
|
|
607
|
+
* The handle is the only thing that ever holds key material: every
|
|
608
|
+
* spending key is derived inside a call and dropped before it returns. It
|
|
609
|
+
* is safe to share across threads. Calls that read or advance the counter
|
|
610
|
+
* are serialized; [`Wallet::build_transfer`] works on a copy and holds no
|
|
611
|
+
* lock while it proves.
|
|
612
|
+
*/
|
|
613
|
+
public protocol WalletProtocol: AnyObject, Sendable {
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* The address and predicate at `path`, without issuing anything.
|
|
617
|
+
*/
|
|
618
|
+
func address(path: KeyPath) throws -> IssuedAddress
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Builds, proves and signs a transfer. The keys come from the paths
|
|
622
|
+
* the inputs name and never leave this call.
|
|
623
|
+
*
|
|
624
|
+
* Proving takes seconds on a phone, so it runs on a copy of the
|
|
625
|
+
* account with the lock released: other calls on this handle, from a
|
|
626
|
+
* UI thread say, do not wait for it. The build never touches the
|
|
627
|
+
* counter, so nothing the copy does needs writing back.
|
|
628
|
+
*/
|
|
629
|
+
func buildTransfer(request: TransferRequest) throws -> Transfer
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* The network this wallet's addresses are encoded for.
|
|
633
|
+
*/
|
|
634
|
+
func network() -> Network
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Issues the next receiving address and advances the counter.
|
|
638
|
+
*/
|
|
639
|
+
func nextAddress() throws -> IssuedAddress
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* The next receiving index not yet issued.
|
|
643
|
+
*/
|
|
644
|
+
func nextIndex() -> UInt32
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Which path below `next_index + gap`, on either branch, owns
|
|
648
|
+
* `predicate`; `None` if none does. The scan re-derives every address
|
|
649
|
+
* it covers, so `gap` is the caller's cost budget.
|
|
650
|
+
*/
|
|
651
|
+
func owns(predicate: Data, gap: UInt32) throws -> KeyPath?
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* The account's receiving key in bech32f (`recv1…` / `testrecv1…`):
|
|
655
|
+
* what an indexer is given to find this wallet's payments. It derives
|
|
656
|
+
* every address and links their activity, and can neither spend nor
|
|
657
|
+
* read a payment's amount.
|
|
658
|
+
*/
|
|
659
|
+
func receivingKey() -> String
|
|
660
|
+
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* One account, `m/35263'/network'/0'`, behind an opaque handle.
|
|
664
|
+
*
|
|
665
|
+
* The handle is the only thing that ever holds key material: every
|
|
666
|
+
* spending key is derived inside a call and dropped before it returns. It
|
|
667
|
+
* is safe to share across threads. Calls that read or advance the counter
|
|
668
|
+
* are serialized; [`Wallet::build_transfer`] works on a copy and holds no
|
|
669
|
+
* lock while it proves.
|
|
670
|
+
*/
|
|
671
|
+
open class Wallet: WalletProtocol, @unchecked Sendable {
|
|
672
|
+
fileprivate let handle: UInt64
|
|
673
|
+
|
|
674
|
+
/// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly.
|
|
675
|
+
#if swift(>=5.8)
|
|
676
|
+
@_documentation(visibility: private)
|
|
677
|
+
#endif
|
|
678
|
+
public struct NoHandle {
|
|
679
|
+
public init() {}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// TODO: We'd like this to be `private` but for Swifty reasons,
|
|
683
|
+
// we can't implement `FfiConverter` without making this `required` and we can't
|
|
684
|
+
// make it `required` without making it `public`.
|
|
685
|
+
#if swift(>=5.8)
|
|
686
|
+
@_documentation(visibility: private)
|
|
687
|
+
#endif
|
|
688
|
+
required public init(unsafeFromHandle handle: UInt64) {
|
|
689
|
+
self.handle = handle
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// This constructor can be used to instantiate a fake object.
|
|
693
|
+
// - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
|
|
694
|
+
//
|
|
695
|
+
// - Warning:
|
|
696
|
+
// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash.
|
|
697
|
+
#if swift(>=5.8)
|
|
698
|
+
@_documentation(visibility: private)
|
|
699
|
+
#endif
|
|
700
|
+
public init(noHandle: NoHandle) {
|
|
701
|
+
self.handle = 0
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
#if swift(>=5.8)
|
|
705
|
+
@_documentation(visibility: private)
|
|
706
|
+
#endif
|
|
707
|
+
public func uniffiCloneHandle() -> UInt64 {
|
|
708
|
+
return try! rustCall { uniffi_flamewallet_ffi_fn_clone_wallet(self.handle, $0) }
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* The account below a 64-byte seed, as [`mnemonic_to_seed`] gives it,
|
|
712
|
+
* with `next_index` receiving addresses already issued. The seed holds
|
|
713
|
+
* keys, not history: an app stores [`Wallet::next_index`] after each
|
|
714
|
+
* [`Wallet::next_address`] and passes it back here; a new wallet
|
|
715
|
+
* passes 0.
|
|
716
|
+
*/
|
|
717
|
+
public convenience init(seed: Data, network: Network, nextIndex: UInt32)throws {
|
|
718
|
+
let handle =
|
|
719
|
+
try rustCallWithError(FfiConverterTypeFlameError_lift) {
|
|
720
|
+
uniffiCallStatus in
|
|
721
|
+
uniffi_flamewallet_ffi_fn_constructor_wallet_new(
|
|
722
|
+
FfiConverterData.lower(seed),
|
|
723
|
+
FfiConverterTypeNetwork_lower(network),
|
|
724
|
+
FfiConverterUInt32.lower(nextIndex),uniffiCallStatus
|
|
725
|
+
)
|
|
726
|
+
}
|
|
727
|
+
self.init(unsafeFromHandle: handle)
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
deinit {
|
|
731
|
+
if handle == 0 {
|
|
732
|
+
// Mock objects have handle=0 don't try to free them
|
|
733
|
+
return
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
try! rustCall { uniffi_flamewallet_ffi_fn_free_wallet(handle, $0) }
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* The account below `phrase` and `passphrase`, without the caller ever
|
|
742
|
+
* seeing the seed; `next_index` as in [`Wallet::new`].
|
|
743
|
+
*/
|
|
744
|
+
public static func fromMnemonic(phrase: String, passphrase: String, network: Network, nextIndex: UInt32)throws -> Wallet {
|
|
745
|
+
return try FfiConverterTypeWallet_lift(try rustCallWithError(FfiConverterTypeFlameError_lift) {
|
|
746
|
+
uniffiCallStatus in
|
|
747
|
+
uniffi_flamewallet_ffi_fn_constructor_wallet_from_mnemonic(
|
|
748
|
+
FfiConverterString.lower(phrase),
|
|
749
|
+
FfiConverterString.lower(passphrase),
|
|
750
|
+
FfiConverterTypeNetwork_lower(network),
|
|
751
|
+
FfiConverterUInt32.lower(nextIndex),uniffiCallStatus
|
|
752
|
+
)
|
|
753
|
+
})
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* The address and predicate at `path`, without issuing anything.
|
|
760
|
+
*/
|
|
761
|
+
open func address(path: KeyPath)throws -> IssuedAddress {
|
|
762
|
+
return try FfiConverterTypeIssuedAddress_lift(try rustCallWithError(FfiConverterTypeFlameError_lift) {
|
|
763
|
+
uniffiCallStatus in
|
|
764
|
+
uniffi_flamewallet_ffi_fn_method_wallet_address(
|
|
765
|
+
self.uniffiCloneHandle(),
|
|
766
|
+
FfiConverterTypeKeyPath_lower(path),uniffiCallStatus
|
|
767
|
+
)
|
|
768
|
+
})
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Builds, proves and signs a transfer. The keys come from the paths
|
|
773
|
+
* the inputs name and never leave this call.
|
|
774
|
+
*
|
|
775
|
+
* Proving takes seconds on a phone, so it runs on a copy of the
|
|
776
|
+
* account with the lock released: other calls on this handle, from a
|
|
777
|
+
* UI thread say, do not wait for it. The build never touches the
|
|
778
|
+
* counter, so nothing the copy does needs writing back.
|
|
779
|
+
*/
|
|
780
|
+
open func buildTransfer(request: TransferRequest)throws -> Transfer {
|
|
781
|
+
return try FfiConverterTypeTransfer_lift(try rustCallWithError(FfiConverterTypeFlameError_lift) {
|
|
782
|
+
uniffiCallStatus in
|
|
783
|
+
uniffi_flamewallet_ffi_fn_method_wallet_build_transfer(
|
|
784
|
+
self.uniffiCloneHandle(),
|
|
785
|
+
FfiConverterTypeTransferRequest_lower(request),uniffiCallStatus
|
|
786
|
+
)
|
|
787
|
+
})
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* The network this wallet's addresses are encoded for.
|
|
792
|
+
*/
|
|
793
|
+
open func network() -> Network {
|
|
794
|
+
return try! FfiConverterTypeNetwork_lift(try! rustCall() {
|
|
795
|
+
uniffiCallStatus in
|
|
796
|
+
uniffi_flamewallet_ffi_fn_method_wallet_network(
|
|
797
|
+
self.uniffiCloneHandle(),uniffiCallStatus
|
|
798
|
+
)
|
|
799
|
+
})
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Issues the next receiving address and advances the counter.
|
|
804
|
+
*/
|
|
805
|
+
open func nextAddress()throws -> IssuedAddress {
|
|
806
|
+
return try FfiConverterTypeIssuedAddress_lift(try rustCallWithError(FfiConverterTypeFlameError_lift) {
|
|
807
|
+
uniffiCallStatus in
|
|
808
|
+
uniffi_flamewallet_ffi_fn_method_wallet_next_address(
|
|
809
|
+
self.uniffiCloneHandle(),uniffiCallStatus
|
|
810
|
+
)
|
|
811
|
+
})
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* The next receiving index not yet issued.
|
|
816
|
+
*/
|
|
817
|
+
open func nextIndex() -> UInt32 {
|
|
818
|
+
return try! FfiConverterUInt32.lift(try! rustCall() {
|
|
819
|
+
uniffiCallStatus in
|
|
820
|
+
uniffi_flamewallet_ffi_fn_method_wallet_next_index(
|
|
821
|
+
self.uniffiCloneHandle(),uniffiCallStatus
|
|
822
|
+
)
|
|
823
|
+
})
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* Which path below `next_index + gap`, on either branch, owns
|
|
828
|
+
* `predicate`; `None` if none does. The scan re-derives every address
|
|
829
|
+
* it covers, so `gap` is the caller's cost budget.
|
|
830
|
+
*/
|
|
831
|
+
open func owns(predicate: Data, gap: UInt32)throws -> KeyPath? {
|
|
832
|
+
return try FfiConverterOptionTypeKeyPath.lift(try rustCallWithError(FfiConverterTypeFlameError_lift) {
|
|
833
|
+
uniffiCallStatus in
|
|
834
|
+
uniffi_flamewallet_ffi_fn_method_wallet_owns(
|
|
835
|
+
self.uniffiCloneHandle(),
|
|
836
|
+
FfiConverterData.lower(predicate),
|
|
837
|
+
FfiConverterUInt32.lower(gap),uniffiCallStatus
|
|
838
|
+
)
|
|
839
|
+
})
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* The account's receiving key in bech32f (`recv1…` / `testrecv1…`):
|
|
844
|
+
* what an indexer is given to find this wallet's payments. It derives
|
|
845
|
+
* every address and links their activity, and can neither spend nor
|
|
846
|
+
* read a payment's amount.
|
|
847
|
+
*/
|
|
848
|
+
open func receivingKey() -> String {
|
|
849
|
+
return try! FfiConverterString.lift(try! rustCall() {
|
|
850
|
+
uniffiCallStatus in
|
|
851
|
+
uniffi_flamewallet_ffi_fn_method_wallet_receiving_key(
|
|
852
|
+
self.uniffiCloneHandle(),uniffiCallStatus
|
|
853
|
+
)
|
|
854
|
+
})
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
#if swift(>=5.8)
|
|
863
|
+
@_documentation(visibility: private)
|
|
864
|
+
#endif
|
|
865
|
+
public struct FfiConverterTypeWallet: FfiConverter {
|
|
866
|
+
typealias FfiType = UInt64
|
|
867
|
+
typealias SwiftType = Wallet
|
|
868
|
+
|
|
869
|
+
public static func lift(_ handle: UInt64) throws -> Wallet {
|
|
870
|
+
return Wallet(unsafeFromHandle: handle)
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
public static func lower(_ value: Wallet) -> UInt64 {
|
|
874
|
+
return value.uniffiCloneHandle()
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Wallet {
|
|
878
|
+
let handle: UInt64 = try readInt(&buf)
|
|
879
|
+
return try lift(handle)
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
public static func write(_ value: Wallet, into buf: inout [UInt8]) {
|
|
883
|
+
writeInt(&buf, lower(value))
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
#if swift(>=5.8)
|
|
889
|
+
@_documentation(visibility: private)
|
|
890
|
+
#endif
|
|
891
|
+
public func FfiConverterTypeWallet_lift(_ handle: UInt64) throws -> Wallet {
|
|
892
|
+
return try FfiConverterTypeWallet.lift(handle)
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
#if swift(>=5.8)
|
|
896
|
+
@_documentation(visibility: private)
|
|
897
|
+
#endif
|
|
898
|
+
public func FfiConverterTypeWallet_lower(_ value: Wallet) -> UInt64 {
|
|
899
|
+
return FfiConverterTypeWallet.lower(value)
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* A published contract, as much of it as a wallet reads.
|
|
907
|
+
*/
|
|
908
|
+
public struct ContractInfo: Equatable, Hashable {
|
|
909
|
+
/**
|
|
910
|
+
* The 32-byte contract id.
|
|
911
|
+
*/
|
|
912
|
+
public var id: Data
|
|
913
|
+
/**
|
|
914
|
+
* The 32-byte compressed point it is locked with: what
|
|
915
|
+
* [`crate::Wallet::owns`] is asked about.
|
|
916
|
+
*/
|
|
917
|
+
public var predicate: Data
|
|
918
|
+
public var value: ContractValue
|
|
919
|
+
|
|
920
|
+
// Default memberwise initializers are never public by default, so we
|
|
921
|
+
// declare one manually.
|
|
922
|
+
public init(
|
|
923
|
+
/**
|
|
924
|
+
* The 32-byte contract id.
|
|
925
|
+
*/id: Data,
|
|
926
|
+
/**
|
|
927
|
+
* The 32-byte compressed point it is locked with: what
|
|
928
|
+
* [`crate::Wallet::owns`] is asked about.
|
|
929
|
+
*/predicate: Data, value: ContractValue) {
|
|
930
|
+
self.id = id
|
|
931
|
+
self.predicate = predicate
|
|
932
|
+
self.value = value
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
#if compiler(>=6)
|
|
941
|
+
extension ContractInfo: Sendable {}
|
|
942
|
+
#endif
|
|
943
|
+
|
|
944
|
+
#if swift(>=5.8)
|
|
945
|
+
@_documentation(visibility: private)
|
|
946
|
+
#endif
|
|
947
|
+
public struct FfiConverterTypeContractInfo: FfiConverterRustBuffer {
|
|
948
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ContractInfo {
|
|
949
|
+
return
|
|
950
|
+
try ContractInfo(
|
|
951
|
+
id: FfiConverterData.read(from: &buf),
|
|
952
|
+
predicate: FfiConverterData.read(from: &buf),
|
|
953
|
+
value: FfiConverterTypeContractValue.read(from: &buf)
|
|
954
|
+
)
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
public static func write(_ value: ContractInfo, into buf: inout [UInt8]) {
|
|
958
|
+
FfiConverterData.write(value.id, into: &buf)
|
|
959
|
+
FfiConverterData.write(value.predicate, into: &buf)
|
|
960
|
+
FfiConverterTypeContractValue.write(value.value, into: &buf)
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
#if swift(>=5.8)
|
|
966
|
+
@_documentation(visibility: private)
|
|
967
|
+
#endif
|
|
968
|
+
public func FfiConverterTypeContractInfo_lift(_ buf: RustBuffer) throws -> ContractInfo {
|
|
969
|
+
return try FfiConverterTypeContractInfo.lift(buf)
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
#if swift(>=5.8)
|
|
973
|
+
@_documentation(visibility: private)
|
|
974
|
+
#endif
|
|
975
|
+
public func FfiConverterTypeContractInfo_lower(_ value: ContractInfo) -> RustBuffer {
|
|
976
|
+
return FfiConverterTypeContractInfo.lower(value)
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* One contract the transfer creates, in request order.
|
|
982
|
+
*/
|
|
983
|
+
public struct CreatedOutput: Equatable, Hashable {
|
|
984
|
+
public var contractId: Data
|
|
985
|
+
/**
|
|
986
|
+
* Its published bytes, as an indexer will serve them once confirmed.
|
|
987
|
+
*/
|
|
988
|
+
public var contract: Data
|
|
989
|
+
/**
|
|
990
|
+
* Delivered to the recipient out of band, or kept for change: the
|
|
991
|
+
* output can be spent from this record and nothing else.
|
|
992
|
+
*/
|
|
993
|
+
public var opening: Opening
|
|
994
|
+
|
|
995
|
+
// Default memberwise initializers are never public by default, so we
|
|
996
|
+
// declare one manually.
|
|
997
|
+
public init(contractId: Data,
|
|
998
|
+
/**
|
|
999
|
+
* Its published bytes, as an indexer will serve them once confirmed.
|
|
1000
|
+
*/contract: Data,
|
|
1001
|
+
/**
|
|
1002
|
+
* Delivered to the recipient out of band, or kept for change: the
|
|
1003
|
+
* output can be spent from this record and nothing else.
|
|
1004
|
+
*/opening: Opening) {
|
|
1005
|
+
self.contractId = contractId
|
|
1006
|
+
self.contract = contract
|
|
1007
|
+
self.opening = opening
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
#if compiler(>=6)
|
|
1016
|
+
extension CreatedOutput: Sendable {}
|
|
1017
|
+
#endif
|
|
1018
|
+
|
|
1019
|
+
#if swift(>=5.8)
|
|
1020
|
+
@_documentation(visibility: private)
|
|
1021
|
+
#endif
|
|
1022
|
+
public struct FfiConverterTypeCreatedOutput: FfiConverterRustBuffer {
|
|
1023
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CreatedOutput {
|
|
1024
|
+
return
|
|
1025
|
+
try CreatedOutput(
|
|
1026
|
+
contractId: FfiConverterData.read(from: &buf),
|
|
1027
|
+
contract: FfiConverterData.read(from: &buf),
|
|
1028
|
+
opening: FfiConverterTypeOpening.read(from: &buf)
|
|
1029
|
+
)
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
public static func write(_ value: CreatedOutput, into buf: inout [UInt8]) {
|
|
1033
|
+
FfiConverterData.write(value.contractId, into: &buf)
|
|
1034
|
+
FfiConverterData.write(value.contract, into: &buf)
|
|
1035
|
+
FfiConverterTypeOpening.write(value.opening, into: &buf)
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
#if swift(>=5.8)
|
|
1041
|
+
@_documentation(visibility: private)
|
|
1042
|
+
#endif
|
|
1043
|
+
public func FfiConverterTypeCreatedOutput_lift(_ buf: RustBuffer) throws -> CreatedOutput {
|
|
1044
|
+
return try FfiConverterTypeCreatedOutput.lift(buf)
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
#if swift(>=5.8)
|
|
1048
|
+
@_documentation(visibility: private)
|
|
1049
|
+
#endif
|
|
1050
|
+
public func FfiConverterTypeCreatedOutput_lower(_ value: CreatedOutput) -> RustBuffer {
|
|
1051
|
+
return FfiConverterTypeCreatedOutput.lower(value)
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* An address the wallet has handed out, with the predicate an indexer is
|
|
1057
|
+
* asked about.
|
|
1058
|
+
*/
|
|
1059
|
+
public struct IssuedAddress: Equatable, Hashable {
|
|
1060
|
+
public var path: KeyPath
|
|
1061
|
+
/**
|
|
1062
|
+
* bech32f: `f1…` on mainnet, `tf1…` on testnet.
|
|
1063
|
+
*/
|
|
1064
|
+
public var address: String
|
|
1065
|
+
/**
|
|
1066
|
+
* The 32-byte compressed point that locks payments to this address.
|
|
1067
|
+
*/
|
|
1068
|
+
public var predicate: Data
|
|
1069
|
+
|
|
1070
|
+
// Default memberwise initializers are never public by default, so we
|
|
1071
|
+
// declare one manually.
|
|
1072
|
+
public init(path: KeyPath,
|
|
1073
|
+
/**
|
|
1074
|
+
* bech32f: `f1…` on mainnet, `tf1…` on testnet.
|
|
1075
|
+
*/address: String,
|
|
1076
|
+
/**
|
|
1077
|
+
* The 32-byte compressed point that locks payments to this address.
|
|
1078
|
+
*/predicate: Data) {
|
|
1079
|
+
self.path = path
|
|
1080
|
+
self.address = address
|
|
1081
|
+
self.predicate = predicate
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
#if compiler(>=6)
|
|
1090
|
+
extension IssuedAddress: Sendable {}
|
|
1091
|
+
#endif
|
|
1092
|
+
|
|
1093
|
+
#if swift(>=5.8)
|
|
1094
|
+
@_documentation(visibility: private)
|
|
1095
|
+
#endif
|
|
1096
|
+
public struct FfiConverterTypeIssuedAddress: FfiConverterRustBuffer {
|
|
1097
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> IssuedAddress {
|
|
1098
|
+
return
|
|
1099
|
+
try IssuedAddress(
|
|
1100
|
+
path: FfiConverterTypeKeyPath.read(from: &buf),
|
|
1101
|
+
address: FfiConverterString.read(from: &buf),
|
|
1102
|
+
predicate: FfiConverterData.read(from: &buf)
|
|
1103
|
+
)
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
public static func write(_ value: IssuedAddress, into buf: inout [UInt8]) {
|
|
1107
|
+
FfiConverterTypeKeyPath.write(value.path, into: &buf)
|
|
1108
|
+
FfiConverterString.write(value.address, into: &buf)
|
|
1109
|
+
FfiConverterData.write(value.predicate, into: &buf)
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
#if swift(>=5.8)
|
|
1115
|
+
@_documentation(visibility: private)
|
|
1116
|
+
#endif
|
|
1117
|
+
public func FfiConverterTypeIssuedAddress_lift(_ buf: RustBuffer) throws -> IssuedAddress {
|
|
1118
|
+
return try FfiConverterTypeIssuedAddress.lift(buf)
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
#if swift(>=5.8)
|
|
1122
|
+
@_documentation(visibility: private)
|
|
1123
|
+
#endif
|
|
1124
|
+
public func FfiConverterTypeIssuedAddress_lower(_ value: IssuedAddress) -> RustBuffer {
|
|
1125
|
+
return FfiConverterTypeIssuedAddress.lower(value)
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
/**
|
|
1130
|
+
* A position below the account: `m/35263'/network'/0'/branch/index`.
|
|
1131
|
+
* `branch` is `0` for receiving and `1` for change.
|
|
1132
|
+
*/
|
|
1133
|
+
public struct KeyPath: Equatable, Hashable {
|
|
1134
|
+
public var branch: UInt32
|
|
1135
|
+
public var index: UInt32
|
|
1136
|
+
|
|
1137
|
+
// Default memberwise initializers are never public by default, so we
|
|
1138
|
+
// declare one manually.
|
|
1139
|
+
public init(branch: UInt32, index: UInt32) {
|
|
1140
|
+
self.branch = branch
|
|
1141
|
+
self.index = index
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
#if compiler(>=6)
|
|
1150
|
+
extension KeyPath: Sendable {}
|
|
1151
|
+
#endif
|
|
1152
|
+
|
|
1153
|
+
#if swift(>=5.8)
|
|
1154
|
+
@_documentation(visibility: private)
|
|
1155
|
+
#endif
|
|
1156
|
+
public struct FfiConverterTypeKeyPath: FfiConverterRustBuffer {
|
|
1157
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeyPath {
|
|
1158
|
+
return
|
|
1159
|
+
try KeyPath(
|
|
1160
|
+
branch: FfiConverterUInt32.read(from: &buf),
|
|
1161
|
+
index: FfiConverterUInt32.read(from: &buf)
|
|
1162
|
+
)
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
public static func write(_ value: KeyPath, into buf: inout [UInt8]) {
|
|
1166
|
+
FfiConverterUInt32.write(value.branch, into: &buf)
|
|
1167
|
+
FfiConverterUInt32.write(value.index, into: &buf)
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
#if swift(>=5.8)
|
|
1173
|
+
@_documentation(visibility: private)
|
|
1174
|
+
#endif
|
|
1175
|
+
public func FfiConverterTypeKeyPath_lift(_ buf: RustBuffer) throws -> KeyPath {
|
|
1176
|
+
return try FfiConverterTypeKeyPath.lift(buf)
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
#if swift(>=5.8)
|
|
1180
|
+
@_documentation(visibility: private)
|
|
1181
|
+
#endif
|
|
1182
|
+
public func FfiConverterTypeKeyPath_lower(_ value: KeyPath) -> RustBuffer {
|
|
1183
|
+
return FfiConverterTypeKeyPath.lower(value)
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
/**
|
|
1188
|
+
* The secret behind a confidential output: what its recipient needs in
|
|
1189
|
+
* order to spend it. Scalars are 32 canonical little-endian bytes.
|
|
1190
|
+
*/
|
|
1191
|
+
public struct Opening: Equatable, Hashable {
|
|
1192
|
+
public var qty: UInt64
|
|
1193
|
+
public var flavor: Data
|
|
1194
|
+
public var qtyBlinding: Data
|
|
1195
|
+
public var flavorBlinding: Data
|
|
1196
|
+
|
|
1197
|
+
// Default memberwise initializers are never public by default, so we
|
|
1198
|
+
// declare one manually.
|
|
1199
|
+
public init(qty: UInt64, flavor: Data, qtyBlinding: Data, flavorBlinding: Data) {
|
|
1200
|
+
self.qty = qty
|
|
1201
|
+
self.flavor = flavor
|
|
1202
|
+
self.qtyBlinding = qtyBlinding
|
|
1203
|
+
self.flavorBlinding = flavorBlinding
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
#if compiler(>=6)
|
|
1212
|
+
extension Opening: Sendable {}
|
|
1213
|
+
#endif
|
|
1214
|
+
|
|
1215
|
+
#if swift(>=5.8)
|
|
1216
|
+
@_documentation(visibility: private)
|
|
1217
|
+
#endif
|
|
1218
|
+
public struct FfiConverterTypeOpening: FfiConverterRustBuffer {
|
|
1219
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Opening {
|
|
1220
|
+
return
|
|
1221
|
+
try Opening(
|
|
1222
|
+
qty: FfiConverterUInt64.read(from: &buf),
|
|
1223
|
+
flavor: FfiConverterData.read(from: &buf),
|
|
1224
|
+
qtyBlinding: FfiConverterData.read(from: &buf),
|
|
1225
|
+
flavorBlinding: FfiConverterData.read(from: &buf)
|
|
1226
|
+
)
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
public static func write(_ value: Opening, into buf: inout [UInt8]) {
|
|
1230
|
+
FfiConverterUInt64.write(value.qty, into: &buf)
|
|
1231
|
+
FfiConverterData.write(value.flavor, into: &buf)
|
|
1232
|
+
FfiConverterData.write(value.qtyBlinding, into: &buf)
|
|
1233
|
+
FfiConverterData.write(value.flavorBlinding, into: &buf)
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
#if swift(>=5.8)
|
|
1239
|
+
@_documentation(visibility: private)
|
|
1240
|
+
#endif
|
|
1241
|
+
public func FfiConverterTypeOpening_lift(_ buf: RustBuffer) throws -> Opening {
|
|
1242
|
+
return try FfiConverterTypeOpening.lift(buf)
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
#if swift(>=5.8)
|
|
1246
|
+
@_documentation(visibility: private)
|
|
1247
|
+
#endif
|
|
1248
|
+
public func FfiConverterTypeOpening_lower(_ value: Opening) -> RustBuffer {
|
|
1249
|
+
return FfiConverterTypeOpening.lower(value)
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* A signed transfer, ready to publish.
|
|
1255
|
+
*/
|
|
1256
|
+
public struct Transfer: Equatable, Hashable {
|
|
1257
|
+
/**
|
|
1258
|
+
* The 32-byte transaction id.
|
|
1259
|
+
*/
|
|
1260
|
+
public var txid: Data
|
|
1261
|
+
/**
|
|
1262
|
+
* `BlockTx::to_bytes`: what a node's `submit_tx` takes.
|
|
1263
|
+
*/
|
|
1264
|
+
public var blockTx: Data
|
|
1265
|
+
public var outputs: [CreatedOutput]
|
|
1266
|
+
|
|
1267
|
+
// Default memberwise initializers are never public by default, so we
|
|
1268
|
+
// declare one manually.
|
|
1269
|
+
public init(
|
|
1270
|
+
/**
|
|
1271
|
+
* The 32-byte transaction id.
|
|
1272
|
+
*/txid: Data,
|
|
1273
|
+
/**
|
|
1274
|
+
* `BlockTx::to_bytes`: what a node's `submit_tx` takes.
|
|
1275
|
+
*/blockTx: Data, outputs: [CreatedOutput]) {
|
|
1276
|
+
self.txid = txid
|
|
1277
|
+
self.blockTx = blockTx
|
|
1278
|
+
self.outputs = outputs
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
#if compiler(>=6)
|
|
1287
|
+
extension Transfer: Sendable {}
|
|
1288
|
+
#endif
|
|
1289
|
+
|
|
1290
|
+
#if swift(>=5.8)
|
|
1291
|
+
@_documentation(visibility: private)
|
|
1292
|
+
#endif
|
|
1293
|
+
public struct FfiConverterTypeTransfer: FfiConverterRustBuffer {
|
|
1294
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Transfer {
|
|
1295
|
+
return
|
|
1296
|
+
try Transfer(
|
|
1297
|
+
txid: FfiConverterData.read(from: &buf),
|
|
1298
|
+
blockTx: FfiConverterData.read(from: &buf),
|
|
1299
|
+
outputs: FfiConverterSequenceTypeCreatedOutput.read(from: &buf)
|
|
1300
|
+
)
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
public static func write(_ value: Transfer, into buf: inout [UInt8]) {
|
|
1304
|
+
FfiConverterData.write(value.txid, into: &buf)
|
|
1305
|
+
FfiConverterData.write(value.blockTx, into: &buf)
|
|
1306
|
+
FfiConverterSequenceTypeCreatedOutput.write(value.outputs, into: &buf)
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
|
|
1311
|
+
#if swift(>=5.8)
|
|
1312
|
+
@_documentation(visibility: private)
|
|
1313
|
+
#endif
|
|
1314
|
+
public func FfiConverterTypeTransfer_lift(_ buf: RustBuffer) throws -> Transfer {
|
|
1315
|
+
return try FfiConverterTypeTransfer.lift(buf)
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
#if swift(>=5.8)
|
|
1319
|
+
@_documentation(visibility: private)
|
|
1320
|
+
#endif
|
|
1321
|
+
public func FfiConverterTypeTransfer_lower(_ value: Transfer) -> RustBuffer {
|
|
1322
|
+
return FfiConverterTypeTransfer.lower(value)
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
|
|
1326
|
+
/**
|
|
1327
|
+
* One contract being spent, exactly as the indexer served it.
|
|
1328
|
+
*/
|
|
1329
|
+
public struct TransferInput: Equatable, Hashable {
|
|
1330
|
+
/**
|
|
1331
|
+
* The contract's published bytes.
|
|
1332
|
+
*/
|
|
1333
|
+
public var contract: Data
|
|
1334
|
+
/**
|
|
1335
|
+
* Its Utreexo membership proof, valid at the tip the transfer targets.
|
|
1336
|
+
*/
|
|
1337
|
+
public var proof: Data
|
|
1338
|
+
/**
|
|
1339
|
+
* The path of the key it is locked to.
|
|
1340
|
+
*/
|
|
1341
|
+
public var path: KeyPath
|
|
1342
|
+
/**
|
|
1343
|
+
* Required for a confidential contract, refused for a cleartext one.
|
|
1344
|
+
*/
|
|
1345
|
+
public var opening: Opening?
|
|
1346
|
+
|
|
1347
|
+
// Default memberwise initializers are never public by default, so we
|
|
1348
|
+
// declare one manually.
|
|
1349
|
+
public init(
|
|
1350
|
+
/**
|
|
1351
|
+
* The contract's published bytes.
|
|
1352
|
+
*/contract: Data,
|
|
1353
|
+
/**
|
|
1354
|
+
* Its Utreexo membership proof, valid at the tip the transfer targets.
|
|
1355
|
+
*/proof: Data,
|
|
1356
|
+
/**
|
|
1357
|
+
* The path of the key it is locked to.
|
|
1358
|
+
*/path: KeyPath,
|
|
1359
|
+
/**
|
|
1360
|
+
* Required for a confidential contract, refused for a cleartext one.
|
|
1361
|
+
*/opening: Opening?) {
|
|
1362
|
+
self.contract = contract
|
|
1363
|
+
self.proof = proof
|
|
1364
|
+
self.path = path
|
|
1365
|
+
self.opening = opening
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
#if compiler(>=6)
|
|
1374
|
+
extension TransferInput: Sendable {}
|
|
1375
|
+
#endif
|
|
1376
|
+
|
|
1377
|
+
#if swift(>=5.8)
|
|
1378
|
+
@_documentation(visibility: private)
|
|
1379
|
+
#endif
|
|
1380
|
+
public struct FfiConverterTypeTransferInput: FfiConverterRustBuffer {
|
|
1381
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TransferInput {
|
|
1382
|
+
return
|
|
1383
|
+
try TransferInput(
|
|
1384
|
+
contract: FfiConverterData.read(from: &buf),
|
|
1385
|
+
proof: FfiConverterData.read(from: &buf),
|
|
1386
|
+
path: FfiConverterTypeKeyPath.read(from: &buf),
|
|
1387
|
+
opening: FfiConverterOptionTypeOpening.read(from: &buf)
|
|
1388
|
+
)
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
public static func write(_ value: TransferInput, into buf: inout [UInt8]) {
|
|
1392
|
+
FfiConverterData.write(value.contract, into: &buf)
|
|
1393
|
+
FfiConverterData.write(value.proof, into: &buf)
|
|
1394
|
+
FfiConverterTypeKeyPath.write(value.path, into: &buf)
|
|
1395
|
+
FfiConverterOptionTypeOpening.write(value.opening, into: &buf)
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
|
|
1400
|
+
#if swift(>=5.8)
|
|
1401
|
+
@_documentation(visibility: private)
|
|
1402
|
+
#endif
|
|
1403
|
+
public func FfiConverterTypeTransferInput_lift(_ buf: RustBuffer) throws -> TransferInput {
|
|
1404
|
+
return try FfiConverterTypeTransferInput.lift(buf)
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
#if swift(>=5.8)
|
|
1408
|
+
@_documentation(visibility: private)
|
|
1409
|
+
#endif
|
|
1410
|
+
public func FfiConverterTypeTransferInput_lower(_ value: TransferInput) -> RustBuffer {
|
|
1411
|
+
return FfiConverterTypeTransferInput.lower(value)
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
|
|
1415
|
+
/**
|
|
1416
|
+
* One contract being created.
|
|
1417
|
+
*/
|
|
1418
|
+
public struct TransferOutput: Equatable, Hashable {
|
|
1419
|
+
/**
|
|
1420
|
+
* The recipient's predicate: [`crate::address_to_predicate`], or
|
|
1421
|
+
* [`crate::Wallet::address`] on the change branch.
|
|
1422
|
+
*/
|
|
1423
|
+
public var predicate: Data
|
|
1424
|
+
public var qty: UInt64
|
|
1425
|
+
/**
|
|
1426
|
+
* `None` for flames.
|
|
1427
|
+
*/
|
|
1428
|
+
public var flavor: Data?
|
|
1429
|
+
|
|
1430
|
+
// Default memberwise initializers are never public by default, so we
|
|
1431
|
+
// declare one manually.
|
|
1432
|
+
public init(
|
|
1433
|
+
/**
|
|
1434
|
+
* The recipient's predicate: [`crate::address_to_predicate`], or
|
|
1435
|
+
* [`crate::Wallet::address`] on the change branch.
|
|
1436
|
+
*/predicate: Data, qty: UInt64,
|
|
1437
|
+
/**
|
|
1438
|
+
* `None` for flames.
|
|
1439
|
+
*/flavor: Data?) {
|
|
1440
|
+
self.predicate = predicate
|
|
1441
|
+
self.qty = qty
|
|
1442
|
+
self.flavor = flavor
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
#if compiler(>=6)
|
|
1451
|
+
extension TransferOutput: Sendable {}
|
|
1452
|
+
#endif
|
|
1453
|
+
|
|
1454
|
+
#if swift(>=5.8)
|
|
1455
|
+
@_documentation(visibility: private)
|
|
1456
|
+
#endif
|
|
1457
|
+
public struct FfiConverterTypeTransferOutput: FfiConverterRustBuffer {
|
|
1458
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TransferOutput {
|
|
1459
|
+
return
|
|
1460
|
+
try TransferOutput(
|
|
1461
|
+
predicate: FfiConverterData.read(from: &buf),
|
|
1462
|
+
qty: FfiConverterUInt64.read(from: &buf),
|
|
1463
|
+
flavor: FfiConverterOptionData.read(from: &buf)
|
|
1464
|
+
)
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
public static func write(_ value: TransferOutput, into buf: inout [UInt8]) {
|
|
1468
|
+
FfiConverterData.write(value.predicate, into: &buf)
|
|
1469
|
+
FfiConverterUInt64.write(value.qty, into: &buf)
|
|
1470
|
+
FfiConverterOptionData.write(value.flavor, into: &buf)
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
|
|
1475
|
+
#if swift(>=5.8)
|
|
1476
|
+
@_documentation(visibility: private)
|
|
1477
|
+
#endif
|
|
1478
|
+
public func FfiConverterTypeTransferOutput_lift(_ buf: RustBuffer) throws -> TransferOutput {
|
|
1479
|
+
return try FfiConverterTypeTransferOutput.lift(buf)
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
#if swift(>=5.8)
|
|
1483
|
+
@_documentation(visibility: private)
|
|
1484
|
+
#endif
|
|
1485
|
+
public func FfiConverterTypeTransferOutput_lower(_ value: TransferOutput) -> RustBuffer {
|
|
1486
|
+
return FfiConverterTypeTransferOutput.lower(value)
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
public struct TransferRequest: Equatable, Hashable {
|
|
1491
|
+
public var inputs: [TransferInput]
|
|
1492
|
+
public var outputs: [TransferOutput]
|
|
1493
|
+
/**
|
|
1494
|
+
* In sparks. Inputs must equal outputs plus fee, per flavor.
|
|
1495
|
+
*/
|
|
1496
|
+
public var fee: UInt64
|
|
1497
|
+
/**
|
|
1498
|
+
* The gas budget; the node refuses more than its block limit allows.
|
|
1499
|
+
*/
|
|
1500
|
+
public var gas: UInt64
|
|
1501
|
+
/**
|
|
1502
|
+
* `0` for none; otherwise as in Bitcoin.
|
|
1503
|
+
*/
|
|
1504
|
+
public var locktime: UInt32
|
|
1505
|
+
|
|
1506
|
+
// Default memberwise initializers are never public by default, so we
|
|
1507
|
+
// declare one manually.
|
|
1508
|
+
public init(inputs: [TransferInput], outputs: [TransferOutput],
|
|
1509
|
+
/**
|
|
1510
|
+
* In sparks. Inputs must equal outputs plus fee, per flavor.
|
|
1511
|
+
*/fee: UInt64,
|
|
1512
|
+
/**
|
|
1513
|
+
* The gas budget; the node refuses more than its block limit allows.
|
|
1514
|
+
*/gas: UInt64,
|
|
1515
|
+
/**
|
|
1516
|
+
* `0` for none; otherwise as in Bitcoin.
|
|
1517
|
+
*/locktime: UInt32) {
|
|
1518
|
+
self.inputs = inputs
|
|
1519
|
+
self.outputs = outputs
|
|
1520
|
+
self.fee = fee
|
|
1521
|
+
self.gas = gas
|
|
1522
|
+
self.locktime = locktime
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
|
|
1526
|
+
|
|
1527
|
+
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
#if compiler(>=6)
|
|
1531
|
+
extension TransferRequest: Sendable {}
|
|
1532
|
+
#endif
|
|
1533
|
+
|
|
1534
|
+
#if swift(>=5.8)
|
|
1535
|
+
@_documentation(visibility: private)
|
|
1536
|
+
#endif
|
|
1537
|
+
public struct FfiConverterTypeTransferRequest: FfiConverterRustBuffer {
|
|
1538
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TransferRequest {
|
|
1539
|
+
return
|
|
1540
|
+
try TransferRequest(
|
|
1541
|
+
inputs: FfiConverterSequenceTypeTransferInput.read(from: &buf),
|
|
1542
|
+
outputs: FfiConverterSequenceTypeTransferOutput.read(from: &buf),
|
|
1543
|
+
fee: FfiConverterUInt64.read(from: &buf),
|
|
1544
|
+
gas: FfiConverterUInt64.read(from: &buf),
|
|
1545
|
+
locktime: FfiConverterUInt32.read(from: &buf)
|
|
1546
|
+
)
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
public static func write(_ value: TransferRequest, into buf: inout [UInt8]) {
|
|
1550
|
+
FfiConverterSequenceTypeTransferInput.write(value.inputs, into: &buf)
|
|
1551
|
+
FfiConverterSequenceTypeTransferOutput.write(value.outputs, into: &buf)
|
|
1552
|
+
FfiConverterUInt64.write(value.fee, into: &buf)
|
|
1553
|
+
FfiConverterUInt64.write(value.gas, into: &buf)
|
|
1554
|
+
FfiConverterUInt32.write(value.locktime, into: &buf)
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
|
|
1559
|
+
#if swift(>=5.8)
|
|
1560
|
+
@_documentation(visibility: private)
|
|
1561
|
+
#endif
|
|
1562
|
+
public func FfiConverterTypeTransferRequest_lift(_ buf: RustBuffer) throws -> TransferRequest {
|
|
1563
|
+
return try FfiConverterTypeTransferRequest.lift(buf)
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
#if swift(>=5.8)
|
|
1567
|
+
@_documentation(visibility: private)
|
|
1568
|
+
#endif
|
|
1569
|
+
public func FfiConverterTypeTransferRequest_lower(_ value: TransferRequest) -> RustBuffer {
|
|
1570
|
+
return FfiConverterTypeTransferRequest.lower(value)
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
|
|
1574
|
+
/**
|
|
1575
|
+
* What a contract holds.
|
|
1576
|
+
*/
|
|
1577
|
+
|
|
1578
|
+
public enum ContractValue: Equatable, Hashable {
|
|
1579
|
+
|
|
1580
|
+
/**
|
|
1581
|
+
* A cleartext token: the amount is public. A devnet genesis allocation
|
|
1582
|
+
* is one.
|
|
1583
|
+
*/
|
|
1584
|
+
case clear(qty: UInt64, flavor: Data
|
|
1585
|
+
)
|
|
1586
|
+
/**
|
|
1587
|
+
* A confidential token: the amount is readable only with its opening.
|
|
1588
|
+
*/
|
|
1589
|
+
case confidential
|
|
1590
|
+
/**
|
|
1591
|
+
* Anything that is not a bare token; no transfer spends it.
|
|
1592
|
+
*/
|
|
1593
|
+
case other
|
|
1594
|
+
|
|
1595
|
+
|
|
1596
|
+
|
|
1597
|
+
|
|
1598
|
+
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
#if compiler(>=6)
|
|
1602
|
+
extension ContractValue: Sendable {}
|
|
1603
|
+
#endif
|
|
1604
|
+
|
|
1605
|
+
#if swift(>=5.8)
|
|
1606
|
+
@_documentation(visibility: private)
|
|
1607
|
+
#endif
|
|
1608
|
+
public struct FfiConverterTypeContractValue: FfiConverterRustBuffer {
|
|
1609
|
+
typealias SwiftType = ContractValue
|
|
1610
|
+
|
|
1611
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ContractValue {
|
|
1612
|
+
let variant: Int32 = try readInt(&buf)
|
|
1613
|
+
switch variant {
|
|
1614
|
+
|
|
1615
|
+
case 1: return .clear(qty: try FfiConverterUInt64.read(from: &buf), flavor: try FfiConverterData.read(from: &buf)
|
|
1616
|
+
)
|
|
1617
|
+
|
|
1618
|
+
case 2: return .confidential
|
|
1619
|
+
|
|
1620
|
+
case 3: return .other
|
|
1621
|
+
|
|
1622
|
+
default: throw UniffiInternalError.unexpectedEnumCase
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
public static func write(_ value: ContractValue, into buf: inout [UInt8]) {
|
|
1627
|
+
switch value {
|
|
1628
|
+
|
|
1629
|
+
|
|
1630
|
+
case let .clear(qty,flavor):
|
|
1631
|
+
writeInt(&buf, Int32(1))
|
|
1632
|
+
FfiConverterUInt64.write(qty, into: &buf)
|
|
1633
|
+
FfiConverterData.write(flavor, into: &buf)
|
|
1634
|
+
|
|
1635
|
+
|
|
1636
|
+
case .confidential:
|
|
1637
|
+
writeInt(&buf, Int32(2))
|
|
1638
|
+
|
|
1639
|
+
|
|
1640
|
+
case .other:
|
|
1641
|
+
writeInt(&buf, Int32(3))
|
|
1642
|
+
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
|
|
1648
|
+
#if swift(>=5.8)
|
|
1649
|
+
@_documentation(visibility: private)
|
|
1650
|
+
#endif
|
|
1651
|
+
public func FfiConverterTypeContractValue_lift(_ buf: RustBuffer) throws -> ContractValue {
|
|
1652
|
+
return try FfiConverterTypeContractValue.lift(buf)
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
#if swift(>=5.8)
|
|
1656
|
+
@_documentation(visibility: private)
|
|
1657
|
+
#endif
|
|
1658
|
+
public func FfiConverterTypeContractValue_lower(_ value: ContractValue) -> RustBuffer {
|
|
1659
|
+
return FfiConverterTypeContractValue.lower(value)
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
|
|
1663
|
+
|
|
1664
|
+
/**
|
|
1665
|
+
* Why a call was refused.
|
|
1666
|
+
*/
|
|
1667
|
+
public
|
|
1668
|
+
enum FlameError: Swift.Error, Equatable, Hashable, Foundation.LocalizedError {
|
|
1669
|
+
|
|
1670
|
+
|
|
1671
|
+
|
|
1672
|
+
/**
|
|
1673
|
+
* The phrase is not a valid BIP-39 mnemonic in any supported language,
|
|
1674
|
+
* or the word count is not one BIP-39 defines.
|
|
1675
|
+
*/
|
|
1676
|
+
case InvalidMnemonic(reason: String
|
|
1677
|
+
)
|
|
1678
|
+
/**
|
|
1679
|
+
* A seed is not 64 bytes, or flamekd refused to derive from it.
|
|
1680
|
+
*/
|
|
1681
|
+
case InvalidSeed(reason: String
|
|
1682
|
+
)
|
|
1683
|
+
/**
|
|
1684
|
+
* An address does not parse for the wallet's network.
|
|
1685
|
+
*/
|
|
1686
|
+
case InvalidAddress(reason: String
|
|
1687
|
+
)
|
|
1688
|
+
/**
|
|
1689
|
+
* A branch or index is hardened; both must be normal.
|
|
1690
|
+
*/
|
|
1691
|
+
case InvalidKeyPath(reason: String
|
|
1692
|
+
)
|
|
1693
|
+
/**
|
|
1694
|
+
* Bytes do not decode into what they claim to be. `what` names the
|
|
1695
|
+
* field: `contract`, `proof`, `predicate`, `flavor`, `blinding`.
|
|
1696
|
+
*/
|
|
1697
|
+
case InvalidBytes(what: String, reason: String
|
|
1698
|
+
)
|
|
1699
|
+
/**
|
|
1700
|
+
* Input `input` is not locked to the key at the path it names, so its
|
|
1701
|
+
* signature could never verify.
|
|
1702
|
+
*/
|
|
1703
|
+
case KeyMismatch(input: UInt32
|
|
1704
|
+
)
|
|
1705
|
+
/**
|
|
1706
|
+
* The transfer could not be built or signed.
|
|
1707
|
+
*/
|
|
1708
|
+
case Transfer(reason: String
|
|
1709
|
+
)
|
|
1710
|
+
|
|
1711
|
+
|
|
1712
|
+
|
|
1713
|
+
|
|
1714
|
+
|
|
1715
|
+
|
|
1716
|
+
public var errorDescription: String? {
|
|
1717
|
+
String(reflecting: self)
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
#if compiler(>=6)
|
|
1723
|
+
extension FlameError: Sendable {}
|
|
1724
|
+
#endif
|
|
1725
|
+
|
|
1726
|
+
#if swift(>=5.8)
|
|
1727
|
+
@_documentation(visibility: private)
|
|
1728
|
+
#endif
|
|
1729
|
+
public struct FfiConverterTypeFlameError: FfiConverterRustBuffer {
|
|
1730
|
+
typealias SwiftType = FlameError
|
|
1731
|
+
|
|
1732
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FlameError {
|
|
1733
|
+
let variant: Int32 = try readInt(&buf)
|
|
1734
|
+
switch variant {
|
|
1735
|
+
|
|
1736
|
+
|
|
1737
|
+
|
|
1738
|
+
|
|
1739
|
+
case 1: return .InvalidMnemonic(
|
|
1740
|
+
reason: try FfiConverterString.read(from: &buf)
|
|
1741
|
+
)
|
|
1742
|
+
case 2: return .InvalidSeed(
|
|
1743
|
+
reason: try FfiConverterString.read(from: &buf)
|
|
1744
|
+
)
|
|
1745
|
+
case 3: return .InvalidAddress(
|
|
1746
|
+
reason: try FfiConverterString.read(from: &buf)
|
|
1747
|
+
)
|
|
1748
|
+
case 4: return .InvalidKeyPath(
|
|
1749
|
+
reason: try FfiConverterString.read(from: &buf)
|
|
1750
|
+
)
|
|
1751
|
+
case 5: return .InvalidBytes(
|
|
1752
|
+
what: try FfiConverterString.read(from: &buf),
|
|
1753
|
+
reason: try FfiConverterString.read(from: &buf)
|
|
1754
|
+
)
|
|
1755
|
+
case 6: return .KeyMismatch(
|
|
1756
|
+
input: try FfiConverterUInt32.read(from: &buf)
|
|
1757
|
+
)
|
|
1758
|
+
case 7: return .Transfer(
|
|
1759
|
+
reason: try FfiConverterString.read(from: &buf)
|
|
1760
|
+
)
|
|
1761
|
+
|
|
1762
|
+
default: throw UniffiInternalError.unexpectedEnumCase
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
public static func write(_ value: FlameError, into buf: inout [UInt8]) {
|
|
1767
|
+
switch value {
|
|
1768
|
+
|
|
1769
|
+
|
|
1770
|
+
|
|
1771
|
+
|
|
1772
|
+
|
|
1773
|
+
case let .InvalidMnemonic(reason):
|
|
1774
|
+
writeInt(&buf, Int32(1))
|
|
1775
|
+
FfiConverterString.write(reason, into: &buf)
|
|
1776
|
+
|
|
1777
|
+
|
|
1778
|
+
case let .InvalidSeed(reason):
|
|
1779
|
+
writeInt(&buf, Int32(2))
|
|
1780
|
+
FfiConverterString.write(reason, into: &buf)
|
|
1781
|
+
|
|
1782
|
+
|
|
1783
|
+
case let .InvalidAddress(reason):
|
|
1784
|
+
writeInt(&buf, Int32(3))
|
|
1785
|
+
FfiConverterString.write(reason, into: &buf)
|
|
1786
|
+
|
|
1787
|
+
|
|
1788
|
+
case let .InvalidKeyPath(reason):
|
|
1789
|
+
writeInt(&buf, Int32(4))
|
|
1790
|
+
FfiConverterString.write(reason, into: &buf)
|
|
1791
|
+
|
|
1792
|
+
|
|
1793
|
+
case let .InvalidBytes(what,reason):
|
|
1794
|
+
writeInt(&buf, Int32(5))
|
|
1795
|
+
FfiConverterString.write(what, into: &buf)
|
|
1796
|
+
FfiConverterString.write(reason, into: &buf)
|
|
1797
|
+
|
|
1798
|
+
|
|
1799
|
+
case let .KeyMismatch(input):
|
|
1800
|
+
writeInt(&buf, Int32(6))
|
|
1801
|
+
FfiConverterUInt32.write(input, into: &buf)
|
|
1802
|
+
|
|
1803
|
+
|
|
1804
|
+
case let .Transfer(reason):
|
|
1805
|
+
writeInt(&buf, Int32(7))
|
|
1806
|
+
FfiConverterString.write(reason, into: &buf)
|
|
1807
|
+
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
|
|
1813
|
+
#if swift(>=5.8)
|
|
1814
|
+
@_documentation(visibility: private)
|
|
1815
|
+
#endif
|
|
1816
|
+
public func FfiConverterTypeFlameError_lift(_ buf: RustBuffer) throws -> FlameError {
|
|
1817
|
+
return try FfiConverterTypeFlameError.lift(buf)
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
#if swift(>=5.8)
|
|
1821
|
+
@_documentation(visibility: private)
|
|
1822
|
+
#endif
|
|
1823
|
+
public func FfiConverterTypeFlameError_lower(_ value: FlameError) -> RustBuffer {
|
|
1824
|
+
return FfiConverterTypeFlameError.lower(value)
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
|
|
1828
|
+
/**
|
|
1829
|
+
* Which network addresses are encoded for: `f1…` or `tf1…`.
|
|
1830
|
+
*/
|
|
1831
|
+
|
|
1832
|
+
public enum Network: Equatable, Hashable {
|
|
1833
|
+
|
|
1834
|
+
case mainnet
|
|
1835
|
+
case testnet
|
|
1836
|
+
|
|
1837
|
+
|
|
1838
|
+
|
|
1839
|
+
|
|
1840
|
+
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
#if compiler(>=6)
|
|
1844
|
+
extension Network: Sendable {}
|
|
1845
|
+
#endif
|
|
1846
|
+
|
|
1847
|
+
#if swift(>=5.8)
|
|
1848
|
+
@_documentation(visibility: private)
|
|
1849
|
+
#endif
|
|
1850
|
+
public struct FfiConverterTypeNetwork: FfiConverterRustBuffer {
|
|
1851
|
+
typealias SwiftType = Network
|
|
1852
|
+
|
|
1853
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Network {
|
|
1854
|
+
let variant: Int32 = try readInt(&buf)
|
|
1855
|
+
switch variant {
|
|
1856
|
+
|
|
1857
|
+
case 1: return .mainnet
|
|
1858
|
+
|
|
1859
|
+
case 2: return .testnet
|
|
1860
|
+
|
|
1861
|
+
default: throw UniffiInternalError.unexpectedEnumCase
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
public static func write(_ value: Network, into buf: inout [UInt8]) {
|
|
1866
|
+
switch value {
|
|
1867
|
+
|
|
1868
|
+
|
|
1869
|
+
case .mainnet:
|
|
1870
|
+
writeInt(&buf, Int32(1))
|
|
1871
|
+
|
|
1872
|
+
|
|
1873
|
+
case .testnet:
|
|
1874
|
+
writeInt(&buf, Int32(2))
|
|
1875
|
+
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
|
|
1881
|
+
#if swift(>=5.8)
|
|
1882
|
+
@_documentation(visibility: private)
|
|
1883
|
+
#endif
|
|
1884
|
+
public func FfiConverterTypeNetwork_lift(_ buf: RustBuffer) throws -> Network {
|
|
1885
|
+
return try FfiConverterTypeNetwork.lift(buf)
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
#if swift(>=5.8)
|
|
1889
|
+
@_documentation(visibility: private)
|
|
1890
|
+
#endif
|
|
1891
|
+
public func FfiConverterTypeNetwork_lower(_ value: Network) -> RustBuffer {
|
|
1892
|
+
return FfiConverterTypeNetwork.lower(value)
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
|
|
1896
|
+
#if swift(>=5.8)
|
|
1897
|
+
@_documentation(visibility: private)
|
|
1898
|
+
#endif
|
|
1899
|
+
fileprivate struct FfiConverterOptionData: FfiConverterRustBuffer {
|
|
1900
|
+
typealias SwiftType = Data?
|
|
1901
|
+
|
|
1902
|
+
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
1903
|
+
guard let value = value else {
|
|
1904
|
+
writeInt(&buf, Int8(0))
|
|
1905
|
+
return
|
|
1906
|
+
}
|
|
1907
|
+
writeInt(&buf, Int8(1))
|
|
1908
|
+
FfiConverterData.write(value, into: &buf)
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
|
|
1912
|
+
switch try readInt(&buf) as Int8 {
|
|
1913
|
+
case 0: return nil
|
|
1914
|
+
case 1: return try FfiConverterData.read(from: &buf)
|
|
1915
|
+
default: throw UniffiInternalError.unexpectedOptionalTag
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
#if swift(>=5.8)
|
|
1921
|
+
@_documentation(visibility: private)
|
|
1922
|
+
#endif
|
|
1923
|
+
fileprivate struct FfiConverterOptionTypeKeyPath: FfiConverterRustBuffer {
|
|
1924
|
+
typealias SwiftType = KeyPath?
|
|
1925
|
+
|
|
1926
|
+
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
1927
|
+
guard let value = value else {
|
|
1928
|
+
writeInt(&buf, Int8(0))
|
|
1929
|
+
return
|
|
1930
|
+
}
|
|
1931
|
+
writeInt(&buf, Int8(1))
|
|
1932
|
+
FfiConverterTypeKeyPath.write(value, into: &buf)
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
|
|
1936
|
+
switch try readInt(&buf) as Int8 {
|
|
1937
|
+
case 0: return nil
|
|
1938
|
+
case 1: return try FfiConverterTypeKeyPath.read(from: &buf)
|
|
1939
|
+
default: throw UniffiInternalError.unexpectedOptionalTag
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
#if swift(>=5.8)
|
|
1945
|
+
@_documentation(visibility: private)
|
|
1946
|
+
#endif
|
|
1947
|
+
fileprivate struct FfiConverterOptionTypeOpening: FfiConverterRustBuffer {
|
|
1948
|
+
typealias SwiftType = Opening?
|
|
1949
|
+
|
|
1950
|
+
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
1951
|
+
guard let value = value else {
|
|
1952
|
+
writeInt(&buf, Int8(0))
|
|
1953
|
+
return
|
|
1954
|
+
}
|
|
1955
|
+
writeInt(&buf, Int8(1))
|
|
1956
|
+
FfiConverterTypeOpening.write(value, into: &buf)
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
|
|
1960
|
+
switch try readInt(&buf) as Int8 {
|
|
1961
|
+
case 0: return nil
|
|
1962
|
+
case 1: return try FfiConverterTypeOpening.read(from: &buf)
|
|
1963
|
+
default: throw UniffiInternalError.unexpectedOptionalTag
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
#if swift(>=5.8)
|
|
1969
|
+
@_documentation(visibility: private)
|
|
1970
|
+
#endif
|
|
1971
|
+
fileprivate struct FfiConverterSequenceTypeCreatedOutput: FfiConverterRustBuffer {
|
|
1972
|
+
typealias SwiftType = [CreatedOutput]
|
|
1973
|
+
|
|
1974
|
+
public static func write(_ value: [CreatedOutput], into buf: inout [UInt8]) {
|
|
1975
|
+
let len = Int32(value.count)
|
|
1976
|
+
writeInt(&buf, len)
|
|
1977
|
+
for item in value {
|
|
1978
|
+
FfiConverterTypeCreatedOutput.write(item, into: &buf)
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [CreatedOutput] {
|
|
1983
|
+
let len: Int32 = try readInt(&buf)
|
|
1984
|
+
var seq = [CreatedOutput]()
|
|
1985
|
+
seq.reserveCapacity(Int(len))
|
|
1986
|
+
for _ in 0 ..< len {
|
|
1987
|
+
seq.append(try FfiConverterTypeCreatedOutput.read(from: &buf))
|
|
1988
|
+
}
|
|
1989
|
+
return seq
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
#if swift(>=5.8)
|
|
1994
|
+
@_documentation(visibility: private)
|
|
1995
|
+
#endif
|
|
1996
|
+
fileprivate struct FfiConverterSequenceTypeTransferInput: FfiConverterRustBuffer {
|
|
1997
|
+
typealias SwiftType = [TransferInput]
|
|
1998
|
+
|
|
1999
|
+
public static func write(_ value: [TransferInput], into buf: inout [UInt8]) {
|
|
2000
|
+
let len = Int32(value.count)
|
|
2001
|
+
writeInt(&buf, len)
|
|
2002
|
+
for item in value {
|
|
2003
|
+
FfiConverterTypeTransferInput.write(item, into: &buf)
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [TransferInput] {
|
|
2008
|
+
let len: Int32 = try readInt(&buf)
|
|
2009
|
+
var seq = [TransferInput]()
|
|
2010
|
+
seq.reserveCapacity(Int(len))
|
|
2011
|
+
for _ in 0 ..< len {
|
|
2012
|
+
seq.append(try FfiConverterTypeTransferInput.read(from: &buf))
|
|
2013
|
+
}
|
|
2014
|
+
return seq
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
#if swift(>=5.8)
|
|
2019
|
+
@_documentation(visibility: private)
|
|
2020
|
+
#endif
|
|
2021
|
+
fileprivate struct FfiConverterSequenceTypeTransferOutput: FfiConverterRustBuffer {
|
|
2022
|
+
typealias SwiftType = [TransferOutput]
|
|
2023
|
+
|
|
2024
|
+
public static func write(_ value: [TransferOutput], into buf: inout [UInt8]) {
|
|
2025
|
+
let len = Int32(value.count)
|
|
2026
|
+
writeInt(&buf, len)
|
|
2027
|
+
for item in value {
|
|
2028
|
+
FfiConverterTypeTransferOutput.write(item, into: &buf)
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [TransferOutput] {
|
|
2033
|
+
let len: Int32 = try readInt(&buf)
|
|
2034
|
+
var seq = [TransferOutput]()
|
|
2035
|
+
seq.reserveCapacity(Int(len))
|
|
2036
|
+
for _ in 0 ..< len {
|
|
2037
|
+
seq.append(try FfiConverterTypeTransferOutput.read(from: &buf))
|
|
2038
|
+
}
|
|
2039
|
+
return seq
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
/**
|
|
2043
|
+
* Decodes a contract from its published bytes.
|
|
2044
|
+
*/
|
|
2045
|
+
public func decodeContract(bytes: Data)throws -> ContractInfo {
|
|
2046
|
+
return try FfiConverterTypeContractInfo_lift(try rustCallWithError(FfiConverterTypeFlameError_lift) {
|
|
2047
|
+
uniffiCallStatus in
|
|
2048
|
+
uniffi_flamewallet_ffi_fn_func_decode_contract(
|
|
2049
|
+
FfiConverterData.lower(bytes),uniffiCallStatus
|
|
2050
|
+
)
|
|
2051
|
+
})
|
|
2052
|
+
}
|
|
2053
|
+
/**
|
|
2054
|
+
* Whether `opening` opens the confidential contract in `bytes`.
|
|
2055
|
+
*
|
|
2056
|
+
* This is how a recipient checks an opening delivered out of band before
|
|
2057
|
+
* counting the payment: the same id comparison
|
|
2058
|
+
* [`crate::Wallet::build_transfer`] makes, run without spending anything.
|
|
2059
|
+
*/
|
|
2060
|
+
public func openingMatches(contract: Data, opening: Opening)throws -> Bool {
|
|
2061
|
+
return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeFlameError_lift) {
|
|
2062
|
+
uniffiCallStatus in
|
|
2063
|
+
uniffi_flamewallet_ffi_fn_func_opening_matches(
|
|
2064
|
+
FfiConverterData.lower(contract),
|
|
2065
|
+
FfiConverterTypeOpening_lower(opening),uniffiCallStatus
|
|
2066
|
+
)
|
|
2067
|
+
})
|
|
2068
|
+
}
|
|
2069
|
+
/**
|
|
2070
|
+
* The predicate a payment to `address` is locked with: the address's
|
|
2071
|
+
* spending point. Refuses an address encoded for the other network.
|
|
2072
|
+
*/
|
|
2073
|
+
public func addressToPredicate(address: String, network: Network)throws -> Data {
|
|
2074
|
+
return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeFlameError_lift) {
|
|
2075
|
+
uniffiCallStatus in
|
|
2076
|
+
uniffi_flamewallet_ffi_fn_func_address_to_predicate(
|
|
2077
|
+
FfiConverterString.lower(address),
|
|
2078
|
+
FfiConverterTypeNetwork_lower(network),uniffiCallStatus
|
|
2079
|
+
)
|
|
2080
|
+
})
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2083
|
+
* A fresh English mnemonic of `word_count` words: 12, 15, 18, 21 or 24.
|
|
2084
|
+
*/
|
|
2085
|
+
public func generateMnemonic(wordCount: UInt8)throws -> String {
|
|
2086
|
+
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeFlameError_lift) {
|
|
2087
|
+
uniffiCallStatus in
|
|
2088
|
+
uniffi_flamewallet_ffi_fn_func_generate_mnemonic(
|
|
2089
|
+
FfiConverterUInt8.lower(wordCount),uniffiCallStatus
|
|
2090
|
+
)
|
|
2091
|
+
})
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* The 64-byte BIP-39 seed of `phrase` under `passphrase` (`""` for none).
|
|
2095
|
+
* This seed is what [`Wallet::new`] takes and what an app stores.
|
|
2096
|
+
*/
|
|
2097
|
+
public func mnemonicToSeed(phrase: String, passphrase: String)throws -> Data {
|
|
2098
|
+
return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeFlameError_lift) {
|
|
2099
|
+
uniffiCallStatus in
|
|
2100
|
+
uniffi_flamewallet_ffi_fn_func_mnemonic_to_seed(
|
|
2101
|
+
FfiConverterString.lower(phrase),
|
|
2102
|
+
FfiConverterString.lower(passphrase),uniffiCallStatus
|
|
2103
|
+
)
|
|
2104
|
+
})
|
|
2105
|
+
}
|
|
2106
|
+
/**
|
|
2107
|
+
* Whether `phrase` is a valid mnemonic in any BIP-39 language.
|
|
2108
|
+
*/
|
|
2109
|
+
public func validateMnemonic(phrase: String) -> Bool {
|
|
2110
|
+
return try! FfiConverterBool.lift(try! rustCall() {
|
|
2111
|
+
uniffiCallStatus in
|
|
2112
|
+
uniffi_flamewallet_ffi_fn_func_validate_mnemonic(
|
|
2113
|
+
FfiConverterString.lower(phrase),uniffiCallStatus
|
|
2114
|
+
)
|
|
2115
|
+
})
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
private enum InitializationResult {
|
|
2119
|
+
case ok
|
|
2120
|
+
case contractVersionMismatch
|
|
2121
|
+
case apiChecksumMismatch
|
|
2122
|
+
}
|
|
2123
|
+
// Use a global variable to perform the versioning checks. Swift ensures that
|
|
2124
|
+
// the code inside is only computed once.
|
|
2125
|
+
private let initializationResult: InitializationResult = {
|
|
2126
|
+
// Get the bindings contract version from our ComponentInterface
|
|
2127
|
+
let bindings_contract_version = 30
|
|
2128
|
+
// Get the scaffolding contract version by calling the into the dylib
|
|
2129
|
+
let scaffolding_contract_version = ffi_flamewallet_ffi_uniffi_contract_version()
|
|
2130
|
+
if bindings_contract_version != scaffolding_contract_version {
|
|
2131
|
+
return InitializationResult.contractVersionMismatch
|
|
2132
|
+
}
|
|
2133
|
+
if (uniffi_flamewallet_ffi_checksum_func_decode_contract() != 9189) {
|
|
2134
|
+
return InitializationResult.apiChecksumMismatch
|
|
2135
|
+
}
|
|
2136
|
+
if (uniffi_flamewallet_ffi_checksum_func_opening_matches() != 54400) {
|
|
2137
|
+
return InitializationResult.apiChecksumMismatch
|
|
2138
|
+
}
|
|
2139
|
+
if (uniffi_flamewallet_ffi_checksum_func_address_to_predicate() != 27158) {
|
|
2140
|
+
return InitializationResult.apiChecksumMismatch
|
|
2141
|
+
}
|
|
2142
|
+
if (uniffi_flamewallet_ffi_checksum_func_generate_mnemonic() != 49383) {
|
|
2143
|
+
return InitializationResult.apiChecksumMismatch
|
|
2144
|
+
}
|
|
2145
|
+
if (uniffi_flamewallet_ffi_checksum_func_mnemonic_to_seed() != 5184) {
|
|
2146
|
+
return InitializationResult.apiChecksumMismatch
|
|
2147
|
+
}
|
|
2148
|
+
if (uniffi_flamewallet_ffi_checksum_func_validate_mnemonic() != 36978) {
|
|
2149
|
+
return InitializationResult.apiChecksumMismatch
|
|
2150
|
+
}
|
|
2151
|
+
if (uniffi_flamewallet_ffi_checksum_method_wallet_address() != 24772) {
|
|
2152
|
+
return InitializationResult.apiChecksumMismatch
|
|
2153
|
+
}
|
|
2154
|
+
if (uniffi_flamewallet_ffi_checksum_method_wallet_build_transfer() != 41970) {
|
|
2155
|
+
return InitializationResult.apiChecksumMismatch
|
|
2156
|
+
}
|
|
2157
|
+
if (uniffi_flamewallet_ffi_checksum_method_wallet_network() != 6461) {
|
|
2158
|
+
return InitializationResult.apiChecksumMismatch
|
|
2159
|
+
}
|
|
2160
|
+
if (uniffi_flamewallet_ffi_checksum_method_wallet_next_address() != 12667) {
|
|
2161
|
+
return InitializationResult.apiChecksumMismatch
|
|
2162
|
+
}
|
|
2163
|
+
if (uniffi_flamewallet_ffi_checksum_method_wallet_next_index() != 50043) {
|
|
2164
|
+
return InitializationResult.apiChecksumMismatch
|
|
2165
|
+
}
|
|
2166
|
+
if (uniffi_flamewallet_ffi_checksum_method_wallet_owns() != 34274) {
|
|
2167
|
+
return InitializationResult.apiChecksumMismatch
|
|
2168
|
+
}
|
|
2169
|
+
if (uniffi_flamewallet_ffi_checksum_method_wallet_receiving_key() != 41950) {
|
|
2170
|
+
return InitializationResult.apiChecksumMismatch
|
|
2171
|
+
}
|
|
2172
|
+
if (uniffi_flamewallet_ffi_checksum_constructor_wallet_from_mnemonic() != 19125) {
|
|
2173
|
+
return InitializationResult.apiChecksumMismatch
|
|
2174
|
+
}
|
|
2175
|
+
if (uniffi_flamewallet_ffi_checksum_constructor_wallet_new() != 9773) {
|
|
2176
|
+
return InitializationResult.apiChecksumMismatch
|
|
2177
|
+
}
|
|
2178
|
+
|
|
2179
|
+
return InitializationResult.ok
|
|
2180
|
+
}()
|
|
2181
|
+
|
|
2182
|
+
// Make the ensure init function public so that other modules which have external type references to
|
|
2183
|
+
// our types can call it.
|
|
2184
|
+
public func uniffiEnsureFlamewalletFfiInitialized() {
|
|
2185
|
+
switch initializationResult {
|
|
2186
|
+
case .ok:
|
|
2187
|
+
break
|
|
2188
|
+
case .contractVersionMismatch:
|
|
2189
|
+
fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
|
|
2190
|
+
case .apiChecksumMismatch:
|
|
2191
|
+
fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
// swiftlint:enable all
|