dash-shielded-native 0.0.1
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/CHANGELOG.md +5 -0
- package/LICENSE +27 -0
- package/README.md +36 -0
- package/android/build.gradle +56 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/app/edge/rndashshielded/RNDashShieldedModule.kt +215 -0
- package/android/src/main/java/app/edge/rndashshielded/RNDashShieldedPackage.kt +16 -0
- package/android/src/main/java/uniffi/dash/dash.kt +1665 -0
- package/android/src/main/jniLibs/arm64-v8a/libdashshielded.so +0 -0
- package/dash-shielded-native.podspec +32 -0
- package/ios/.uniffi-generated +1 -0
- package/ios/EdgeDashClient.swift +88 -0
- package/ios/RNDashShielded.m +83 -0
- package/ios/RNDashShielded.swift +214 -0
- package/ios/dash-shielded-native-Bridging-Header.h +2 -0
- package/ios/dash.swift +1124 -0
- package/ios/libdashshielded.xcframework/Info.plist +47 -0
- package/ios/libdashshielded.xcframework/ios-arm64/Headers/dashFFI.h +696 -0
- package/ios/libdashshielded.xcframework/ios-arm64/Headers/module.modulemap +7 -0
- package/ios/libdashshielded.xcframework/ios-arm64/libdashshielded.a +0 -0
- package/ios/libdashshielded.xcframework/ios-arm64-simulator/Headers/dashFFI.h +696 -0
- package/ios/libdashshielded.xcframework/ios-arm64-simulator/Headers/module.modulemap +7 -0
- package/ios/libdashshielded.xcframework/ios-arm64-simulator/libdashshielded.a +0 -0
- package/lib/load-addon.d.ts +34 -0
- package/lib/node.d.ts +50 -0
- package/lib/react-native.d.ts +31 -0
- package/lib/rndash.rn.js +267 -0
- package/lib/rndash.rn.js.map +1 -0
- package/lib/src/node.js +328 -0
- package/lib/src/node.js.map +1 -0
- package/lib/types.d.ts +73 -0
- package/node.d.ts +1 -0
- package/node.js +2 -0
- package/package.json +105 -0
- package/prebuilds/darwin-arm64/dashshielded.node +0 -0
- package/rust/Cargo.lock +6795 -0
- package/rust/Cargo.toml +63 -0
- package/rust/build.rs +7 -0
- package/rust/rust-toolchain.toml +3 -0
- package/rust/src/dash.udl +90 -0
- package/rust/src/lib.rs +16 -0
- package/rust/src/napi_api.rs +164 -0
- package/rust/src/uniffi_api.rs +116 -0
- package/rust/src/wallet.rs +888 -0
- package/rust/uniffi-bindgen.rs +3 -0
- package/src/load-addon.ts +99 -0
- package/src/node.ts +248 -0
- package/src/react-native.ts +212 -0
- package/src/types.ts +88 -0
package/ios/dash.swift
ADDED
|
@@ -0,0 +1,1124 @@
|
|
|
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(dashFFI)
|
|
11
|
+
import dashFFI
|
|
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_dashshielded_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_dashshielded_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
|
+
|
|
44
|
+
// For every type used in the interface, we provide helper methods for conveniently
|
|
45
|
+
// lifting and lowering that type from C-compatible data, and for reading and writing
|
|
46
|
+
// values of that type in a buffer.
|
|
47
|
+
|
|
48
|
+
// Helper classes/extensions that don't change.
|
|
49
|
+
// Someday, this will be in a library of its own.
|
|
50
|
+
|
|
51
|
+
fileprivate extension Data {
|
|
52
|
+
init(rustBuffer: RustBuffer) {
|
|
53
|
+
self.init(
|
|
54
|
+
bytesNoCopy: rustBuffer.data!,
|
|
55
|
+
count: Int(rustBuffer.len),
|
|
56
|
+
deallocator: .none
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Define reader functionality. Normally this would be defined in a class or
|
|
62
|
+
// struct, but we use standalone functions instead in order to make external
|
|
63
|
+
// types work.
|
|
64
|
+
//
|
|
65
|
+
// With external types, one swift source file needs to be able to call the read
|
|
66
|
+
// method on another source file's FfiConverter, but then what visibility
|
|
67
|
+
// should Reader have?
|
|
68
|
+
// - If Reader is fileprivate, then this means the read() must also
|
|
69
|
+
// be fileprivate, which doesn't work with external types.
|
|
70
|
+
// - If Reader is internal/public, we'll get compile errors since both source
|
|
71
|
+
// files will try define the same type.
|
|
72
|
+
//
|
|
73
|
+
// Instead, the read() method and these helper functions input a tuple of data
|
|
74
|
+
|
|
75
|
+
fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) {
|
|
76
|
+
(data: data, offset: 0)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Reads an integer at the current offset, in big-endian order, and advances
|
|
80
|
+
// the offset on success. Throws if reading the integer would move the
|
|
81
|
+
// offset past the end of the buffer.
|
|
82
|
+
fileprivate func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
|
|
83
|
+
let range = reader.offset..<reader.offset + MemoryLayout<T>.size
|
|
84
|
+
guard reader.data.count >= range.upperBound else {
|
|
85
|
+
throw UniffiInternalError.bufferOverflow
|
|
86
|
+
}
|
|
87
|
+
if T.self == UInt8.self {
|
|
88
|
+
let value = reader.data[reader.offset]
|
|
89
|
+
reader.offset += 1
|
|
90
|
+
return value as! T
|
|
91
|
+
}
|
|
92
|
+
var value: T = 0
|
|
93
|
+
let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)})
|
|
94
|
+
reader.offset = range.upperBound
|
|
95
|
+
return value.bigEndian
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Reads an arbitrary number of bytes, to be used to read
|
|
99
|
+
// raw bytes, this is useful when lifting strings
|
|
100
|
+
fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array<UInt8> {
|
|
101
|
+
let range = reader.offset..<(reader.offset+count)
|
|
102
|
+
guard reader.data.count >= range.upperBound else {
|
|
103
|
+
throw UniffiInternalError.bufferOverflow
|
|
104
|
+
}
|
|
105
|
+
var value = [UInt8](repeating: 0, count: count)
|
|
106
|
+
value.withUnsafeMutableBufferPointer({ buffer in
|
|
107
|
+
reader.data.copyBytes(to: buffer, from: range)
|
|
108
|
+
})
|
|
109
|
+
reader.offset = range.upperBound
|
|
110
|
+
return value
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Reads a float at the current offset.
|
|
114
|
+
fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
|
|
115
|
+
return Float(bitPattern: try readInt(&reader))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Reads a float at the current offset.
|
|
119
|
+
fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
|
|
120
|
+
return Double(bitPattern: try readInt(&reader))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Indicates if the offset has reached the end of the buffer.
|
|
124
|
+
fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
|
|
125
|
+
return reader.offset < reader.data.count
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Define writer functionality. Normally this would be defined in a class or
|
|
129
|
+
// struct, but we use standalone functions instead in order to make external
|
|
130
|
+
// types work. See the above discussion on Readers for details.
|
|
131
|
+
|
|
132
|
+
fileprivate func createWriter() -> [UInt8] {
|
|
133
|
+
return []
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
fileprivate func writeBytes<S>(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 {
|
|
137
|
+
writer.append(contentsOf: byteArr)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Writes an integer in big-endian order.
|
|
141
|
+
//
|
|
142
|
+
// Warning: make sure what you are trying to write
|
|
143
|
+
// is in the correct type!
|
|
144
|
+
fileprivate func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
|
|
145
|
+
var value = value.bigEndian
|
|
146
|
+
withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) {
|
|
150
|
+
writeInt(&writer, value.bitPattern)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
|
|
154
|
+
writeInt(&writer, value.bitPattern)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Protocol for types that transfer other types across the FFI. This is
|
|
158
|
+
// analogous to the Rust trait of the same name.
|
|
159
|
+
fileprivate protocol FfiConverter {
|
|
160
|
+
associatedtype FfiType
|
|
161
|
+
associatedtype SwiftType
|
|
162
|
+
|
|
163
|
+
static func lift(_ value: FfiType) throws -> SwiftType
|
|
164
|
+
static func lower(_ value: SwiftType) -> FfiType
|
|
165
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
|
|
166
|
+
static func write(_ value: SwiftType, into buf: inout [UInt8])
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Types conforming to `Primitive` pass themselves directly over the FFI.
|
|
170
|
+
fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }
|
|
171
|
+
|
|
172
|
+
extension FfiConverterPrimitive {
|
|
173
|
+
#if swift(>=5.8)
|
|
174
|
+
@_documentation(visibility: private)
|
|
175
|
+
#endif
|
|
176
|
+
public static func lift(_ value: FfiType) throws -> SwiftType {
|
|
177
|
+
return value
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#if swift(>=5.8)
|
|
181
|
+
@_documentation(visibility: private)
|
|
182
|
+
#endif
|
|
183
|
+
public static func lower(_ value: SwiftType) -> FfiType {
|
|
184
|
+
return value
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
|
|
189
|
+
// Used for complex types where it's hard to write a custom lift/lower.
|
|
190
|
+
fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}
|
|
191
|
+
|
|
192
|
+
extension FfiConverterRustBuffer {
|
|
193
|
+
#if swift(>=5.8)
|
|
194
|
+
@_documentation(visibility: private)
|
|
195
|
+
#endif
|
|
196
|
+
public static func lift(_ buf: RustBuffer) throws -> SwiftType {
|
|
197
|
+
var reader = createReader(data: Data(rustBuffer: buf))
|
|
198
|
+
let value = try read(from: &reader)
|
|
199
|
+
if hasRemaining(reader) {
|
|
200
|
+
throw UniffiInternalError.incompleteData
|
|
201
|
+
}
|
|
202
|
+
buf.deallocate()
|
|
203
|
+
return value
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
#if swift(>=5.8)
|
|
207
|
+
@_documentation(visibility: private)
|
|
208
|
+
#endif
|
|
209
|
+
public static func lower(_ value: SwiftType) -> RustBuffer {
|
|
210
|
+
var writer = createWriter()
|
|
211
|
+
write(value, into: &writer)
|
|
212
|
+
return RustBuffer(bytes: writer)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// An error type for FFI errors. These errors occur at the UniFFI level, not
|
|
216
|
+
// the library level.
|
|
217
|
+
fileprivate enum UniffiInternalError: LocalizedError {
|
|
218
|
+
case bufferOverflow
|
|
219
|
+
case incompleteData
|
|
220
|
+
case unexpectedOptionalTag
|
|
221
|
+
case unexpectedEnumCase
|
|
222
|
+
case unexpectedNullPointer
|
|
223
|
+
case unexpectedRustCallStatusCode
|
|
224
|
+
case unexpectedRustCallError
|
|
225
|
+
case unexpectedStaleHandle
|
|
226
|
+
case rustPanic(_ message: String)
|
|
227
|
+
|
|
228
|
+
public var errorDescription: String? {
|
|
229
|
+
switch self {
|
|
230
|
+
case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
|
|
231
|
+
case .incompleteData: return "The buffer still has data after lifting its containing value"
|
|
232
|
+
case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
|
|
233
|
+
case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
|
|
234
|
+
case .unexpectedNullPointer: return "Raw pointer value was null"
|
|
235
|
+
case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
|
|
236
|
+
case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
|
|
237
|
+
case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
|
|
238
|
+
case let .rustPanic(message): return message
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
fileprivate extension NSLock {
|
|
244
|
+
func withLock<T>(f: () throws -> T) rethrows -> T {
|
|
245
|
+
self.lock()
|
|
246
|
+
defer { self.unlock() }
|
|
247
|
+
return try f()
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
fileprivate let CALL_SUCCESS: Int8 = 0
|
|
252
|
+
fileprivate let CALL_ERROR: Int8 = 1
|
|
253
|
+
fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2
|
|
254
|
+
fileprivate let CALL_CANCELLED: Int8 = 3
|
|
255
|
+
|
|
256
|
+
fileprivate extension RustCallStatus {
|
|
257
|
+
init() {
|
|
258
|
+
self.init(
|
|
259
|
+
code: CALL_SUCCESS,
|
|
260
|
+
errorBuf: RustBuffer.init(
|
|
261
|
+
capacity: 0,
|
|
262
|
+
len: 0,
|
|
263
|
+
data: nil
|
|
264
|
+
)
|
|
265
|
+
)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
|
|
270
|
+
let neverThrow: ((RustBuffer) throws -> Never)? = nil
|
|
271
|
+
return try makeRustCall(callback, errorHandler: neverThrow)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private func rustCallWithError<T, E: Swift.Error>(
|
|
275
|
+
_ errorHandler: @escaping (RustBuffer) throws -> E,
|
|
276
|
+
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
|
|
277
|
+
try makeRustCall(callback, errorHandler: errorHandler)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private func makeRustCall<T, E: Swift.Error>(
|
|
281
|
+
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
|
|
282
|
+
errorHandler: ((RustBuffer) throws -> E)?
|
|
283
|
+
) throws -> T {
|
|
284
|
+
uniffiEnsureDashshieldedInitialized()
|
|
285
|
+
var callStatus = RustCallStatus.init()
|
|
286
|
+
let returnedVal = callback(&callStatus)
|
|
287
|
+
try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
|
|
288
|
+
return returnedVal
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private func uniffiCheckCallStatus<E: Swift.Error>(
|
|
292
|
+
callStatus: RustCallStatus,
|
|
293
|
+
errorHandler: ((RustBuffer) throws -> E)?
|
|
294
|
+
) throws {
|
|
295
|
+
switch callStatus.code {
|
|
296
|
+
case CALL_SUCCESS:
|
|
297
|
+
return
|
|
298
|
+
|
|
299
|
+
case CALL_ERROR:
|
|
300
|
+
if let errorHandler = errorHandler {
|
|
301
|
+
throw try errorHandler(callStatus.errorBuf)
|
|
302
|
+
} else {
|
|
303
|
+
callStatus.errorBuf.deallocate()
|
|
304
|
+
throw UniffiInternalError.unexpectedRustCallError
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
case CALL_UNEXPECTED_ERROR:
|
|
308
|
+
// When the rust code sees a panic, it tries to construct a RustBuffer
|
|
309
|
+
// with the message. But if that code panics, then it just sends back
|
|
310
|
+
// an empty buffer.
|
|
311
|
+
if callStatus.errorBuf.len > 0 {
|
|
312
|
+
throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
|
|
313
|
+
} else {
|
|
314
|
+
callStatus.errorBuf.deallocate()
|
|
315
|
+
throw UniffiInternalError.rustPanic("Rust panic")
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
case CALL_CANCELLED:
|
|
319
|
+
fatalError("Cancellation not supported yet")
|
|
320
|
+
|
|
321
|
+
default:
|
|
322
|
+
throw UniffiInternalError.unexpectedRustCallStatusCode
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private func uniffiTraitInterfaceCall<T>(
|
|
327
|
+
callStatus: UnsafeMutablePointer<RustCallStatus>,
|
|
328
|
+
makeCall: () throws -> T,
|
|
329
|
+
writeReturn: (T) -> ()
|
|
330
|
+
) {
|
|
331
|
+
do {
|
|
332
|
+
try writeReturn(makeCall())
|
|
333
|
+
} catch let error {
|
|
334
|
+
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
|
|
335
|
+
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private func uniffiTraitInterfaceCallWithError<T, E>(
|
|
340
|
+
callStatus: UnsafeMutablePointer<RustCallStatus>,
|
|
341
|
+
makeCall: () throws -> T,
|
|
342
|
+
writeReturn: (T) -> (),
|
|
343
|
+
lowerError: (E) -> RustBuffer
|
|
344
|
+
) {
|
|
345
|
+
do {
|
|
346
|
+
try writeReturn(makeCall())
|
|
347
|
+
} catch let error as E {
|
|
348
|
+
callStatus.pointee.code = CALL_ERROR
|
|
349
|
+
callStatus.pointee.errorBuf = lowerError(error)
|
|
350
|
+
} catch {
|
|
351
|
+
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
|
|
352
|
+
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
fileprivate final class UniffiHandleMap<T>: @unchecked Sendable {
|
|
356
|
+
// All mutation happens with this lock held, which is why we implement @unchecked Sendable.
|
|
357
|
+
private let lock = NSLock()
|
|
358
|
+
private var map: [UInt64: T] = [:]
|
|
359
|
+
private var currentHandle: UInt64 = 1
|
|
360
|
+
|
|
361
|
+
func insert(obj: T) -> UInt64 {
|
|
362
|
+
lock.withLock {
|
|
363
|
+
let handle = currentHandle
|
|
364
|
+
currentHandle += 1
|
|
365
|
+
map[handle] = obj
|
|
366
|
+
return handle
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
func get(handle: UInt64) throws -> T {
|
|
371
|
+
try lock.withLock {
|
|
372
|
+
guard let obj = map[handle] else {
|
|
373
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
374
|
+
}
|
|
375
|
+
return obj
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
@discardableResult
|
|
380
|
+
func remove(handle: UInt64) throws -> T {
|
|
381
|
+
try lock.withLock {
|
|
382
|
+
guard let obj = map.removeValue(forKey: handle) else {
|
|
383
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
384
|
+
}
|
|
385
|
+
return obj
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
var count: Int {
|
|
390
|
+
get {
|
|
391
|
+
map.count
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
// Public interface members begin here.
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
#if swift(>=5.8)
|
|
401
|
+
@_documentation(visibility: private)
|
|
402
|
+
#endif
|
|
403
|
+
fileprivate struct FfiConverterUInt32: FfiConverterPrimitive {
|
|
404
|
+
typealias FfiType = UInt32
|
|
405
|
+
typealias SwiftType = UInt32
|
|
406
|
+
|
|
407
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 {
|
|
408
|
+
return try lift(readInt(&buf))
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
412
|
+
writeInt(&buf, lower(value))
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
#if swift(>=5.8)
|
|
417
|
+
@_documentation(visibility: private)
|
|
418
|
+
#endif
|
|
419
|
+
fileprivate struct FfiConverterInt64: FfiConverterPrimitive {
|
|
420
|
+
typealias FfiType = Int64
|
|
421
|
+
typealias SwiftType = Int64
|
|
422
|
+
|
|
423
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Int64 {
|
|
424
|
+
return try lift(readInt(&buf))
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
public static func write(_ value: Int64, into buf: inout [UInt8]) {
|
|
428
|
+
writeInt(&buf, lower(value))
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
#if swift(>=5.8)
|
|
433
|
+
@_documentation(visibility: private)
|
|
434
|
+
#endif
|
|
435
|
+
fileprivate struct FfiConverterDouble: FfiConverterPrimitive {
|
|
436
|
+
typealias FfiType = Double
|
|
437
|
+
typealias SwiftType = Double
|
|
438
|
+
|
|
439
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Double {
|
|
440
|
+
return try lift(readDouble(&buf))
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
public static func write(_ value: Double, into buf: inout [UInt8]) {
|
|
444
|
+
writeDouble(&buf, lower(value))
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
#if swift(>=5.8)
|
|
449
|
+
@_documentation(visibility: private)
|
|
450
|
+
#endif
|
|
451
|
+
fileprivate struct FfiConverterBool : FfiConverter {
|
|
452
|
+
typealias FfiType = Int8
|
|
453
|
+
typealias SwiftType = Bool
|
|
454
|
+
|
|
455
|
+
public static func lift(_ value: Int8) throws -> Bool {
|
|
456
|
+
return value != 0
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
public static func lower(_ value: Bool) -> Int8 {
|
|
460
|
+
return value ? 1 : 0
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool {
|
|
464
|
+
return try lift(readInt(&buf))
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
public static func write(_ value: Bool, into buf: inout [UInt8]) {
|
|
468
|
+
writeInt(&buf, lower(value))
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
#if swift(>=5.8)
|
|
473
|
+
@_documentation(visibility: private)
|
|
474
|
+
#endif
|
|
475
|
+
fileprivate struct FfiConverterString: FfiConverter {
|
|
476
|
+
typealias SwiftType = String
|
|
477
|
+
typealias FfiType = RustBuffer
|
|
478
|
+
|
|
479
|
+
public static func lift(_ value: RustBuffer) throws -> String {
|
|
480
|
+
defer {
|
|
481
|
+
value.deallocate()
|
|
482
|
+
}
|
|
483
|
+
if value.data == nil {
|
|
484
|
+
return String()
|
|
485
|
+
}
|
|
486
|
+
let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
|
|
487
|
+
return String(bytes: bytes, encoding: String.Encoding.utf8)!
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
public static func lower(_ value: String) -> RustBuffer {
|
|
491
|
+
return value.utf8CString.withUnsafeBufferPointer { ptr in
|
|
492
|
+
// The swift string gives us int8_t, we want uint8_t.
|
|
493
|
+
ptr.withMemoryRebound(to: UInt8.self) { ptr in
|
|
494
|
+
// The swift string gives us a trailing null byte, we don't want it.
|
|
495
|
+
let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
|
|
496
|
+
return RustBuffer.from(buf)
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
|
|
502
|
+
let len: Int32 = try readInt(&buf)
|
|
503
|
+
return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)!
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
public static func write(_ value: String, into buf: inout [UInt8]) {
|
|
507
|
+
let len = Int32(value.utf8.count)
|
|
508
|
+
writeInt(&buf, len)
|
|
509
|
+
writeBytes(&buf, value.utf8)
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
public struct Addresses {
|
|
515
|
+
public var shieldedAddress: String
|
|
516
|
+
|
|
517
|
+
// Default memberwise initializers are never public by default, so we
|
|
518
|
+
// declare one manually.
|
|
519
|
+
public init(shieldedAddress: String) {
|
|
520
|
+
self.shieldedAddress = shieldedAddress
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
#if compiler(>=6)
|
|
525
|
+
extension Addresses: Sendable {}
|
|
526
|
+
#endif
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
extension Addresses: Equatable, Hashable {
|
|
530
|
+
public static func ==(lhs: Addresses, rhs: Addresses) -> Bool {
|
|
531
|
+
if lhs.shieldedAddress != rhs.shieldedAddress {
|
|
532
|
+
return false
|
|
533
|
+
}
|
|
534
|
+
return true
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
public func hash(into hasher: inout Hasher) {
|
|
538
|
+
hasher.combine(shieldedAddress)
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
#if swift(>=5.8)
|
|
545
|
+
@_documentation(visibility: private)
|
|
546
|
+
#endif
|
|
547
|
+
public struct FfiConverterTypeAddresses: FfiConverterRustBuffer {
|
|
548
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Addresses {
|
|
549
|
+
return
|
|
550
|
+
try Addresses(
|
|
551
|
+
shieldedAddress: FfiConverterString.read(from: &buf)
|
|
552
|
+
)
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
public static func write(_ value: Addresses, into buf: inout [UInt8]) {
|
|
556
|
+
FfiConverterString.write(value.shieldedAddress, into: &buf)
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
#if swift(>=5.8)
|
|
562
|
+
@_documentation(visibility: private)
|
|
563
|
+
#endif
|
|
564
|
+
public func FfiConverterTypeAddresses_lift(_ buf: RustBuffer) throws -> Addresses {
|
|
565
|
+
return try FfiConverterTypeAddresses.lift(buf)
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
#if swift(>=5.8)
|
|
569
|
+
@_documentation(visibility: private)
|
|
570
|
+
#endif
|
|
571
|
+
public func FfiConverterTypeAddresses_lower(_ value: Addresses) -> RustBuffer {
|
|
572
|
+
return FfiConverterTypeAddresses.lower(value)
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
public struct Poll {
|
|
577
|
+
public var alias: String
|
|
578
|
+
public var status: String
|
|
579
|
+
public var scanProgress: Double
|
|
580
|
+
public var networkBlockHeight: UInt32
|
|
581
|
+
public var availableCredits: String
|
|
582
|
+
public var totalCredits: String
|
|
583
|
+
public var transactions: [Transaction]
|
|
584
|
+
|
|
585
|
+
// Default memberwise initializers are never public by default, so we
|
|
586
|
+
// declare one manually.
|
|
587
|
+
public init(alias: String, status: String, scanProgress: Double, networkBlockHeight: UInt32, availableCredits: String, totalCredits: String, transactions: [Transaction]) {
|
|
588
|
+
self.alias = alias
|
|
589
|
+
self.status = status
|
|
590
|
+
self.scanProgress = scanProgress
|
|
591
|
+
self.networkBlockHeight = networkBlockHeight
|
|
592
|
+
self.availableCredits = availableCredits
|
|
593
|
+
self.totalCredits = totalCredits
|
|
594
|
+
self.transactions = transactions
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
#if compiler(>=6)
|
|
599
|
+
extension Poll: Sendable {}
|
|
600
|
+
#endif
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
extension Poll: Equatable, Hashable {
|
|
604
|
+
public static func ==(lhs: Poll, rhs: Poll) -> Bool {
|
|
605
|
+
if lhs.alias != rhs.alias {
|
|
606
|
+
return false
|
|
607
|
+
}
|
|
608
|
+
if lhs.status != rhs.status {
|
|
609
|
+
return false
|
|
610
|
+
}
|
|
611
|
+
if lhs.scanProgress != rhs.scanProgress {
|
|
612
|
+
return false
|
|
613
|
+
}
|
|
614
|
+
if lhs.networkBlockHeight != rhs.networkBlockHeight {
|
|
615
|
+
return false
|
|
616
|
+
}
|
|
617
|
+
if lhs.availableCredits != rhs.availableCredits {
|
|
618
|
+
return false
|
|
619
|
+
}
|
|
620
|
+
if lhs.totalCredits != rhs.totalCredits {
|
|
621
|
+
return false
|
|
622
|
+
}
|
|
623
|
+
if lhs.transactions != rhs.transactions {
|
|
624
|
+
return false
|
|
625
|
+
}
|
|
626
|
+
return true
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
public func hash(into hasher: inout Hasher) {
|
|
630
|
+
hasher.combine(alias)
|
|
631
|
+
hasher.combine(status)
|
|
632
|
+
hasher.combine(scanProgress)
|
|
633
|
+
hasher.combine(networkBlockHeight)
|
|
634
|
+
hasher.combine(availableCredits)
|
|
635
|
+
hasher.combine(totalCredits)
|
|
636
|
+
hasher.combine(transactions)
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
#if swift(>=5.8)
|
|
643
|
+
@_documentation(visibility: private)
|
|
644
|
+
#endif
|
|
645
|
+
public struct FfiConverterTypePoll: FfiConverterRustBuffer {
|
|
646
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Poll {
|
|
647
|
+
return
|
|
648
|
+
try Poll(
|
|
649
|
+
alias: FfiConverterString.read(from: &buf),
|
|
650
|
+
status: FfiConverterString.read(from: &buf),
|
|
651
|
+
scanProgress: FfiConverterDouble.read(from: &buf),
|
|
652
|
+
networkBlockHeight: FfiConverterUInt32.read(from: &buf),
|
|
653
|
+
availableCredits: FfiConverterString.read(from: &buf),
|
|
654
|
+
totalCredits: FfiConverterString.read(from: &buf),
|
|
655
|
+
transactions: FfiConverterSequenceTypeTransaction.read(from: &buf)
|
|
656
|
+
)
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
public static func write(_ value: Poll, into buf: inout [UInt8]) {
|
|
660
|
+
FfiConverterString.write(value.alias, into: &buf)
|
|
661
|
+
FfiConverterString.write(value.status, into: &buf)
|
|
662
|
+
FfiConverterDouble.write(value.scanProgress, into: &buf)
|
|
663
|
+
FfiConverterUInt32.write(value.networkBlockHeight, into: &buf)
|
|
664
|
+
FfiConverterString.write(value.availableCredits, into: &buf)
|
|
665
|
+
FfiConverterString.write(value.totalCredits, into: &buf)
|
|
666
|
+
FfiConverterSequenceTypeTransaction.write(value.transactions, into: &buf)
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
#if swift(>=5.8)
|
|
672
|
+
@_documentation(visibility: private)
|
|
673
|
+
#endif
|
|
674
|
+
public func FfiConverterTypePoll_lift(_ buf: RustBuffer) throws -> Poll {
|
|
675
|
+
return try FfiConverterTypePoll.lift(buf)
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
#if swift(>=5.8)
|
|
679
|
+
@_documentation(visibility: private)
|
|
680
|
+
#endif
|
|
681
|
+
public func FfiConverterTypePoll_lower(_ value: Poll) -> RustBuffer {
|
|
682
|
+
return FfiConverterTypePoll.lower(value)
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
public struct Transaction {
|
|
687
|
+
public var txid: String
|
|
688
|
+
public var blockTimeInSeconds: Int64
|
|
689
|
+
public var minedHeight: Int64
|
|
690
|
+
public var value: String
|
|
691
|
+
public var fee: String?
|
|
692
|
+
public var toAddress: String?
|
|
693
|
+
public var memos: [String]
|
|
694
|
+
|
|
695
|
+
// Default memberwise initializers are never public by default, so we
|
|
696
|
+
// declare one manually.
|
|
697
|
+
public init(txid: String, blockTimeInSeconds: Int64, minedHeight: Int64, value: String, fee: String?, toAddress: String?, memos: [String]) {
|
|
698
|
+
self.txid = txid
|
|
699
|
+
self.blockTimeInSeconds = blockTimeInSeconds
|
|
700
|
+
self.minedHeight = minedHeight
|
|
701
|
+
self.value = value
|
|
702
|
+
self.fee = fee
|
|
703
|
+
self.toAddress = toAddress
|
|
704
|
+
self.memos = memos
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
#if compiler(>=6)
|
|
709
|
+
extension Transaction: Sendable {}
|
|
710
|
+
#endif
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
extension Transaction: Equatable, Hashable {
|
|
714
|
+
public static func ==(lhs: Transaction, rhs: Transaction) -> Bool {
|
|
715
|
+
if lhs.txid != rhs.txid {
|
|
716
|
+
return false
|
|
717
|
+
}
|
|
718
|
+
if lhs.blockTimeInSeconds != rhs.blockTimeInSeconds {
|
|
719
|
+
return false
|
|
720
|
+
}
|
|
721
|
+
if lhs.minedHeight != rhs.minedHeight {
|
|
722
|
+
return false
|
|
723
|
+
}
|
|
724
|
+
if lhs.value != rhs.value {
|
|
725
|
+
return false
|
|
726
|
+
}
|
|
727
|
+
if lhs.fee != rhs.fee {
|
|
728
|
+
return false
|
|
729
|
+
}
|
|
730
|
+
if lhs.toAddress != rhs.toAddress {
|
|
731
|
+
return false
|
|
732
|
+
}
|
|
733
|
+
if lhs.memos != rhs.memos {
|
|
734
|
+
return false
|
|
735
|
+
}
|
|
736
|
+
return true
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
public func hash(into hasher: inout Hasher) {
|
|
740
|
+
hasher.combine(txid)
|
|
741
|
+
hasher.combine(blockTimeInSeconds)
|
|
742
|
+
hasher.combine(minedHeight)
|
|
743
|
+
hasher.combine(value)
|
|
744
|
+
hasher.combine(fee)
|
|
745
|
+
hasher.combine(toAddress)
|
|
746
|
+
hasher.combine(memos)
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
#if swift(>=5.8)
|
|
753
|
+
@_documentation(visibility: private)
|
|
754
|
+
#endif
|
|
755
|
+
public struct FfiConverterTypeTransaction: FfiConverterRustBuffer {
|
|
756
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Transaction {
|
|
757
|
+
return
|
|
758
|
+
try Transaction(
|
|
759
|
+
txid: FfiConverterString.read(from: &buf),
|
|
760
|
+
blockTimeInSeconds: FfiConverterInt64.read(from: &buf),
|
|
761
|
+
minedHeight: FfiConverterInt64.read(from: &buf),
|
|
762
|
+
value: FfiConverterString.read(from: &buf),
|
|
763
|
+
fee: FfiConverterOptionString.read(from: &buf),
|
|
764
|
+
toAddress: FfiConverterOptionString.read(from: &buf),
|
|
765
|
+
memos: FfiConverterSequenceString.read(from: &buf)
|
|
766
|
+
)
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
public static func write(_ value: Transaction, into buf: inout [UInt8]) {
|
|
770
|
+
FfiConverterString.write(value.txid, into: &buf)
|
|
771
|
+
FfiConverterInt64.write(value.blockTimeInSeconds, into: &buf)
|
|
772
|
+
FfiConverterInt64.write(value.minedHeight, into: &buf)
|
|
773
|
+
FfiConverterString.write(value.value, into: &buf)
|
|
774
|
+
FfiConverterOptionString.write(value.fee, into: &buf)
|
|
775
|
+
FfiConverterOptionString.write(value.toAddress, into: &buf)
|
|
776
|
+
FfiConverterSequenceString.write(value.memos, into: &buf)
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
#if swift(>=5.8)
|
|
782
|
+
@_documentation(visibility: private)
|
|
783
|
+
#endif
|
|
784
|
+
public func FfiConverterTypeTransaction_lift(_ buf: RustBuffer) throws -> Transaction {
|
|
785
|
+
return try FfiConverterTypeTransaction.lift(buf)
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
#if swift(>=5.8)
|
|
789
|
+
@_documentation(visibility: private)
|
|
790
|
+
#endif
|
|
791
|
+
public func FfiConverterTypeTransaction_lower(_ value: Transaction) -> RustBuffer {
|
|
792
|
+
return FfiConverterTypeTransaction.lower(value)
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
public enum DashError: Swift.Error {
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
case Internal(message: String
|
|
801
|
+
)
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
#if swift(>=5.8)
|
|
806
|
+
@_documentation(visibility: private)
|
|
807
|
+
#endif
|
|
808
|
+
public struct FfiConverterTypeDashError: FfiConverterRustBuffer {
|
|
809
|
+
typealias SwiftType = DashError
|
|
810
|
+
|
|
811
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DashError {
|
|
812
|
+
let variant: Int32 = try readInt(&buf)
|
|
813
|
+
switch variant {
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
case 1: return .Internal(
|
|
819
|
+
message: try FfiConverterString.read(from: &buf)
|
|
820
|
+
)
|
|
821
|
+
|
|
822
|
+
default: throw UniffiInternalError.unexpectedEnumCase
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
public static func write(_ value: DashError, into buf: inout [UInt8]) {
|
|
827
|
+
switch value {
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
case let .Internal(message):
|
|
834
|
+
writeInt(&buf, Int32(1))
|
|
835
|
+
FfiConverterString.write(message, into: &buf)
|
|
836
|
+
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
#if swift(>=5.8)
|
|
843
|
+
@_documentation(visibility: private)
|
|
844
|
+
#endif
|
|
845
|
+
public func FfiConverterTypeDashError_lift(_ buf: RustBuffer) throws -> DashError {
|
|
846
|
+
return try FfiConverterTypeDashError.lift(buf)
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
#if swift(>=5.8)
|
|
850
|
+
@_documentation(visibility: private)
|
|
851
|
+
#endif
|
|
852
|
+
public func FfiConverterTypeDashError_lower(_ value: DashError) -> RustBuffer {
|
|
853
|
+
return FfiConverterTypeDashError.lower(value)
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
extension DashError: Equatable, Hashable {}
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
extension DashError: Foundation.LocalizedError {
|
|
863
|
+
public var errorDescription: String? {
|
|
864
|
+
String(reflecting: self)
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
#if swift(>=5.8)
|
|
872
|
+
@_documentation(visibility: private)
|
|
873
|
+
#endif
|
|
874
|
+
fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer {
|
|
875
|
+
typealias SwiftType = String?
|
|
876
|
+
|
|
877
|
+
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
878
|
+
guard let value = value else {
|
|
879
|
+
writeInt(&buf, Int8(0))
|
|
880
|
+
return
|
|
881
|
+
}
|
|
882
|
+
writeInt(&buf, Int8(1))
|
|
883
|
+
FfiConverterString.write(value, into: &buf)
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
|
|
887
|
+
switch try readInt(&buf) as Int8 {
|
|
888
|
+
case 0: return nil
|
|
889
|
+
case 1: return try FfiConverterString.read(from: &buf)
|
|
890
|
+
default: throw UniffiInternalError.unexpectedOptionalTag
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
#if swift(>=5.8)
|
|
896
|
+
@_documentation(visibility: private)
|
|
897
|
+
#endif
|
|
898
|
+
fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer {
|
|
899
|
+
typealias SwiftType = [String]
|
|
900
|
+
|
|
901
|
+
public static func write(_ value: [String], into buf: inout [UInt8]) {
|
|
902
|
+
let len = Int32(value.count)
|
|
903
|
+
writeInt(&buf, len)
|
|
904
|
+
for item in value {
|
|
905
|
+
FfiConverterString.write(item, into: &buf)
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] {
|
|
910
|
+
let len: Int32 = try readInt(&buf)
|
|
911
|
+
var seq = [String]()
|
|
912
|
+
seq.reserveCapacity(Int(len))
|
|
913
|
+
for _ in 0 ..< len {
|
|
914
|
+
seq.append(try FfiConverterString.read(from: &buf))
|
|
915
|
+
}
|
|
916
|
+
return seq
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
#if swift(>=5.8)
|
|
921
|
+
@_documentation(visibility: private)
|
|
922
|
+
#endif
|
|
923
|
+
fileprivate struct FfiConverterSequenceTypeTransaction: FfiConverterRustBuffer {
|
|
924
|
+
typealias SwiftType = [Transaction]
|
|
925
|
+
|
|
926
|
+
public static func write(_ value: [Transaction], into buf: inout [UInt8]) {
|
|
927
|
+
let len = Int32(value.count)
|
|
928
|
+
writeInt(&buf, len)
|
|
929
|
+
for item in value {
|
|
930
|
+
FfiConverterTypeTransaction.write(item, into: &buf)
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [Transaction] {
|
|
935
|
+
let len: Int32 = try readInt(&buf)
|
|
936
|
+
var seq = [Transaction]()
|
|
937
|
+
seq.reserveCapacity(Int(len))
|
|
938
|
+
for _ in 0 ..< len {
|
|
939
|
+
seq.append(try FfiConverterTypeTransaction.read(from: &buf))
|
|
940
|
+
}
|
|
941
|
+
return seq
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
public func createTransfer(alias: String, proposalId: String, mnemonicSeed: String)throws -> String {
|
|
945
|
+
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeDashError_lift) {
|
|
946
|
+
uniffi_dashshielded_fn_func_create_transfer(
|
|
947
|
+
FfiConverterString.lower(alias),
|
|
948
|
+
FfiConverterString.lower(proposalId),
|
|
949
|
+
FfiConverterString.lower(mnemonicSeed),$0
|
|
950
|
+
)
|
|
951
|
+
})
|
|
952
|
+
}
|
|
953
|
+
public func deriveShieldedAddress(alias: String)throws -> Addresses {
|
|
954
|
+
return try FfiConverterTypeAddresses_lift(try rustCallWithError(FfiConverterTypeDashError_lift) {
|
|
955
|
+
uniffi_dashshielded_fn_func_derive_shielded_address(
|
|
956
|
+
FfiConverterString.lower(alias),$0
|
|
957
|
+
)
|
|
958
|
+
})
|
|
959
|
+
}
|
|
960
|
+
public func deriveShieldedAddressFromSeed(mnemonicSeed: String, network: String, account: UInt32)throws -> String {
|
|
961
|
+
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeDashError_lift) {
|
|
962
|
+
uniffi_dashshielded_fn_func_derive_shielded_address_from_seed(
|
|
963
|
+
FfiConverterString.lower(mnemonicSeed),
|
|
964
|
+
FfiConverterString.lower(network),
|
|
965
|
+
FfiConverterUInt32.lower(account),$0
|
|
966
|
+
)
|
|
967
|
+
})
|
|
968
|
+
}
|
|
969
|
+
public func deriveViewingKey(mnemonicSeed: String, network: String)throws -> String {
|
|
970
|
+
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeDashError_lift) {
|
|
971
|
+
uniffi_dashshielded_fn_func_derive_viewing_key(
|
|
972
|
+
FfiConverterString.lower(mnemonicSeed),
|
|
973
|
+
FfiConverterString.lower(network),$0
|
|
974
|
+
)
|
|
975
|
+
})
|
|
976
|
+
}
|
|
977
|
+
public func initialize(mnemonicSeed: String, account: UInt32, alias: String, networkName: String, defaultHost: String, defaultPort: UInt32)throws {try rustCallWithError(FfiConverterTypeDashError_lift) {
|
|
978
|
+
uniffi_dashshielded_fn_func_initialize(
|
|
979
|
+
FfiConverterString.lower(mnemonicSeed),
|
|
980
|
+
FfiConverterUInt32.lower(account),
|
|
981
|
+
FfiConverterString.lower(alias),
|
|
982
|
+
FfiConverterString.lower(networkName),
|
|
983
|
+
FfiConverterString.lower(defaultHost),
|
|
984
|
+
FfiConverterUInt32.lower(defaultPort),$0
|
|
985
|
+
)
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
public func isProverReady() -> Bool {
|
|
989
|
+
return try! FfiConverterBool.lift(try! rustCall() {
|
|
990
|
+
uniffi_dashshielded_fn_func_is_prover_ready($0
|
|
991
|
+
)
|
|
992
|
+
})
|
|
993
|
+
}
|
|
994
|
+
public func isValidAddress(address: String, network: String) -> Bool {
|
|
995
|
+
return try! FfiConverterBool.lift(try! rustCall() {
|
|
996
|
+
uniffi_dashshielded_fn_func_is_valid_address(
|
|
997
|
+
FfiConverterString.lower(address),
|
|
998
|
+
FfiConverterString.lower(network),$0
|
|
999
|
+
)
|
|
1000
|
+
})
|
|
1001
|
+
}
|
|
1002
|
+
public func poll(alias: String)throws -> Poll {
|
|
1003
|
+
return try FfiConverterTypePoll_lift(try rustCallWithError(FfiConverterTypeDashError_lift) {
|
|
1004
|
+
uniffi_dashshielded_fn_func_poll(
|
|
1005
|
+
FfiConverterString.lower(alias),$0
|
|
1006
|
+
)
|
|
1007
|
+
})
|
|
1008
|
+
}
|
|
1009
|
+
public func proposeTransfer(alias: String, amountCredits: String, toAddress: String, memo: String?)throws -> String {
|
|
1010
|
+
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeDashError_lift) {
|
|
1011
|
+
uniffi_dashshielded_fn_func_propose_transfer(
|
|
1012
|
+
FfiConverterString.lower(alias),
|
|
1013
|
+
FfiConverterString.lower(amountCredits),
|
|
1014
|
+
FfiConverterString.lower(toAddress),
|
|
1015
|
+
FfiConverterOptionString.lower(memo),$0
|
|
1016
|
+
)
|
|
1017
|
+
})
|
|
1018
|
+
}
|
|
1019
|
+
public func setDocumentDirectory(path: String)throws {try rustCallWithError(FfiConverterTypeDashError_lift) {
|
|
1020
|
+
uniffi_dashshielded_fn_func_set_document_directory(
|
|
1021
|
+
FfiConverterString.lower(path),$0
|
|
1022
|
+
)
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
public func startSync(alias: String)throws {try rustCallWithError(FfiConverterTypeDashError_lift) {
|
|
1026
|
+
uniffi_dashshielded_fn_func_start_sync(
|
|
1027
|
+
FfiConverterString.lower(alias),$0
|
|
1028
|
+
)
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
public func stop(alias: String)throws -> String {
|
|
1032
|
+
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeDashError_lift) {
|
|
1033
|
+
uniffi_dashshielded_fn_func_stop(
|
|
1034
|
+
FfiConverterString.lower(alias),$0
|
|
1035
|
+
)
|
|
1036
|
+
})
|
|
1037
|
+
}
|
|
1038
|
+
public func stopSync(alias: String)throws {try rustCallWithError(FfiConverterTypeDashError_lift) {
|
|
1039
|
+
uniffi_dashshielded_fn_func_stop_sync(
|
|
1040
|
+
FfiConverterString.lower(alias),$0
|
|
1041
|
+
)
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
public func warmUpProver()throws {try rustCallWithError(FfiConverterTypeDashError_lift) {
|
|
1045
|
+
uniffi_dashshielded_fn_func_warm_up_prover($0
|
|
1046
|
+
)
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
private enum InitializationResult {
|
|
1051
|
+
case ok
|
|
1052
|
+
case contractVersionMismatch
|
|
1053
|
+
case apiChecksumMismatch
|
|
1054
|
+
}
|
|
1055
|
+
// Use a global variable to perform the versioning checks. Swift ensures that
|
|
1056
|
+
// the code inside is only computed once.
|
|
1057
|
+
private let initializationResult: InitializationResult = {
|
|
1058
|
+
// Get the bindings contract version from our ComponentInterface
|
|
1059
|
+
let bindings_contract_version = 29
|
|
1060
|
+
// Get the scaffolding contract version by calling the into the dylib
|
|
1061
|
+
let scaffolding_contract_version = ffi_dashshielded_uniffi_contract_version()
|
|
1062
|
+
if bindings_contract_version != scaffolding_contract_version {
|
|
1063
|
+
return InitializationResult.contractVersionMismatch
|
|
1064
|
+
}
|
|
1065
|
+
if (uniffi_dashshielded_checksum_func_create_transfer() != 10651) {
|
|
1066
|
+
return InitializationResult.apiChecksumMismatch
|
|
1067
|
+
}
|
|
1068
|
+
if (uniffi_dashshielded_checksum_func_derive_shielded_address() != 17735) {
|
|
1069
|
+
return InitializationResult.apiChecksumMismatch
|
|
1070
|
+
}
|
|
1071
|
+
if (uniffi_dashshielded_checksum_func_derive_shielded_address_from_seed() != 20809) {
|
|
1072
|
+
return InitializationResult.apiChecksumMismatch
|
|
1073
|
+
}
|
|
1074
|
+
if (uniffi_dashshielded_checksum_func_derive_viewing_key() != 35588) {
|
|
1075
|
+
return InitializationResult.apiChecksumMismatch
|
|
1076
|
+
}
|
|
1077
|
+
if (uniffi_dashshielded_checksum_func_initialize() != 3174) {
|
|
1078
|
+
return InitializationResult.apiChecksumMismatch
|
|
1079
|
+
}
|
|
1080
|
+
if (uniffi_dashshielded_checksum_func_is_prover_ready() != 38748) {
|
|
1081
|
+
return InitializationResult.apiChecksumMismatch
|
|
1082
|
+
}
|
|
1083
|
+
if (uniffi_dashshielded_checksum_func_is_valid_address() != 228) {
|
|
1084
|
+
return InitializationResult.apiChecksumMismatch
|
|
1085
|
+
}
|
|
1086
|
+
if (uniffi_dashshielded_checksum_func_poll() != 4874) {
|
|
1087
|
+
return InitializationResult.apiChecksumMismatch
|
|
1088
|
+
}
|
|
1089
|
+
if (uniffi_dashshielded_checksum_func_propose_transfer() != 1851) {
|
|
1090
|
+
return InitializationResult.apiChecksumMismatch
|
|
1091
|
+
}
|
|
1092
|
+
if (uniffi_dashshielded_checksum_func_set_document_directory() != 41116) {
|
|
1093
|
+
return InitializationResult.apiChecksumMismatch
|
|
1094
|
+
}
|
|
1095
|
+
if (uniffi_dashshielded_checksum_func_start_sync() != 56361) {
|
|
1096
|
+
return InitializationResult.apiChecksumMismatch
|
|
1097
|
+
}
|
|
1098
|
+
if (uniffi_dashshielded_checksum_func_stop() != 11070) {
|
|
1099
|
+
return InitializationResult.apiChecksumMismatch
|
|
1100
|
+
}
|
|
1101
|
+
if (uniffi_dashshielded_checksum_func_stop_sync() != 6076) {
|
|
1102
|
+
return InitializationResult.apiChecksumMismatch
|
|
1103
|
+
}
|
|
1104
|
+
if (uniffi_dashshielded_checksum_func_warm_up_prover() != 10994) {
|
|
1105
|
+
return InitializationResult.apiChecksumMismatch
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
return InitializationResult.ok
|
|
1109
|
+
}()
|
|
1110
|
+
|
|
1111
|
+
// Make the ensure init function public so that other modules which have external type references to
|
|
1112
|
+
// our types can call it.
|
|
1113
|
+
public func uniffiEnsureDashshieldedInitialized() {
|
|
1114
|
+
switch initializationResult {
|
|
1115
|
+
case .ok:
|
|
1116
|
+
break
|
|
1117
|
+
case .contractVersionMismatch:
|
|
1118
|
+
fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
|
|
1119
|
+
case .apiChecksumMismatch:
|
|
1120
|
+
fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// swiftlint:enable all
|