@runflame/wallet-rn 0.0.0-stage → 0.0.1-rc.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.
Files changed (21) hide show
  1. package/FlameWalletNative.podspec +15 -0
  2. package/LICENSE.txt +201 -0
  3. package/android/build.gradle +30 -0
  4. package/android/src/main/java/com/flame/wallet/flamewallet_ffi.kt +3041 -0
  5. package/android/src/main/jniLibs/arm64-v8a/libflamewallet_ffi.so +0 -0
  6. package/android/src/main/jniLibs/armeabi-v7a/libflamewallet_ffi.so +0 -0
  7. package/android/src/main/jniLibs/x86_64/libflamewallet_ffi.so +0 -0
  8. package/expo-module.config.json +3 -0
  9. package/ios/FlameWallet.swift +2453 -0
  10. package/ios/FlameWalletFFI.xcframework/Info.plist +44 -0
  11. package/ios/FlameWalletFFI.xcframework/ios-arm64/FlameWalletFFI.framework/FlameWalletFFI +0 -0
  12. package/ios/FlameWalletFFI.xcframework/ios-arm64/FlameWalletFFI.framework/Headers/FlameWalletFFI.h +698 -0
  13. package/ios/FlameWalletFFI.xcframework/ios-arm64/FlameWalletFFI.framework/Info.plist +16 -0
  14. package/ios/FlameWalletFFI.xcframework/ios-arm64/FlameWalletFFI.framework/Modules/module.modulemap +4 -0
  15. package/ios/FlameWalletFFI.xcframework/ios-arm64_x86_64-simulator/FlameWalletFFI.framework/FlameWalletFFI +0 -0
  16. package/ios/FlameWalletFFI.xcframework/ios-arm64_x86_64-simulator/FlameWalletFFI.framework/Headers/FlameWalletFFI.h +698 -0
  17. package/ios/FlameWalletFFI.xcframework/ios-arm64_x86_64-simulator/FlameWalletFFI.framework/Info.plist +16 -0
  18. package/ios/FlameWalletFFI.xcframework/ios-arm64_x86_64-simulator/FlameWalletFFI.framework/Modules/module.modulemap +4 -0
  19. package/package.json +17 -4
  20. package/sbom.cdx.json +5880 -0
  21. package/README.md +0 -3
@@ -0,0 +1,3041 @@
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
+ @file:Suppress("NAME_SHADOWING")
5
+
6
+ package com.flame.wallet
7
+
8
+ // Common helper code.
9
+ //
10
+ // Ideally this would live in a separate .kt file where it can be unittested etc
11
+ // in isolation, and perhaps even published as a re-useable package.
12
+ //
13
+ // However, it's important that the details of how this helper code works (e.g. the
14
+ // way that different builtin types are passed across the FFI) exactly match what's
15
+ // expected by the Rust code on the other side of the interface. In practice right
16
+ // now that means coming from the exact some version of `uniffi` that was used to
17
+ // compile the Rust component. The easiest way to ensure this is to bundle the Kotlin
18
+ // helpers directly inline like we're doing here.
19
+
20
+ import com.sun.jna.Library
21
+ import com.sun.jna.IntegerType
22
+ import com.sun.jna.Native
23
+ import com.sun.jna.Pointer
24
+ import com.sun.jna.Structure
25
+ import com.sun.jna.Callback
26
+ import com.sun.jna.ptr.*
27
+ import java.nio.ByteBuffer
28
+ import java.nio.ByteOrder
29
+ import java.nio.CharBuffer
30
+ import java.nio.charset.CodingErrorAction
31
+ import java.util.concurrent.atomic.AtomicLong
32
+ import java.util.concurrent.ConcurrentHashMap
33
+ import java.util.concurrent.atomic.AtomicBoolean
34
+
35
+ // This is a helper for safely working with byte buffers returned from the Rust code.
36
+ // A rust-owned buffer is represented by its capacity, its current length, and a
37
+ // pointer to the underlying data.
38
+
39
+ /**
40
+ * @suppress
41
+ */
42
+ @Structure.FieldOrder("capacity", "len", "data")
43
+ open class RustBuffer : Structure() {
44
+ // Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values.
45
+ // When dealing with these fields, make sure to call `toULong()`.
46
+ @JvmField var capacity: Long = 0
47
+ @JvmField var len: Long = 0
48
+ @JvmField var data: Pointer? = null
49
+
50
+ class ByValue: RustBuffer(), Structure.ByValue
51
+ class ByReference: RustBuffer(), Structure.ByReference
52
+
53
+ internal fun setValue(other: RustBuffer) {
54
+ capacity = other.capacity
55
+ len = other.len
56
+ data = other.data
57
+ }
58
+
59
+ companion object {
60
+ internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status ->
61
+ // Note: need to convert the size to a `Long` value to make this work with JVM.
62
+ UniffiLib.ffi_flamewallet_ffi_rustbuffer_alloc(size.toLong(), status)
63
+ }.also {
64
+ if(it.data == null) {
65
+ throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})")
66
+ }
67
+ }
68
+
69
+ internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue {
70
+ var buf = RustBuffer.ByValue()
71
+ buf.capacity = capacity.toLong()
72
+ buf.len = len.toLong()
73
+ buf.data = data
74
+ return buf
75
+ }
76
+
77
+ internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status ->
78
+ UniffiLib.ffi_flamewallet_ffi_rustbuffer_free(buf, status)
79
+ }
80
+ }
81
+
82
+ @Suppress("TooGenericExceptionThrown")
83
+ fun asByteBuffer() =
84
+ this.data?.getByteBuffer(0, this.len)?.also {
85
+ it.order(ByteOrder.BIG_ENDIAN)
86
+ }
87
+ }
88
+
89
+ // This is a helper for safely passing byte references into the rust code.
90
+ // It's not actually used at the moment, because there aren't many things that you
91
+ // can take a direct pointer to in the JVM, and if we're going to copy something
92
+ // then we might as well copy it into a `RustBuffer`. But it's here for API
93
+ // completeness.
94
+
95
+ @Structure.FieldOrder("len", "data")
96
+ internal open class ForeignBytes : Structure() {
97
+ @JvmField var len: Int = 0
98
+ @JvmField var data: Pointer? = null
99
+
100
+ class ByValue : ForeignBytes(), Structure.ByValue
101
+ }
102
+
103
+ // Converter for `&[u8]` / `[ByRef] bytes` arguments.
104
+ //
105
+ // Only `lower` is valid — zero-copy byte buffers only flow foreign -> Rust,
106
+ // and only in argument position. `lift`, `read`, `write`, and
107
+ // `allocationSize` have no sound implementation here and all panic at
108
+ // runtime. The `FfiConverter` interface is implemented so that the
109
+ // compiler enforces the full method set (rather than relying on eyeball).
110
+ //
111
+ // The provided `ByteBuffer` MUST be direct — only direct buffers have a
112
+ // stable native address that JNA can expose via `getDirectBufferPointer`.
113
+ // The returned `ForeignBytes.ByValue` is only valid for the duration of
114
+ // the FFI call; the Rust side treats it as a borrow.
115
+ internal object FfiConverterByRefBytes : FfiConverter<java.nio.ByteBuffer, ForeignBytes.ByValue> {
116
+ override fun lower(value: java.nio.ByteBuffer): ForeignBytes.ByValue {
117
+ require(value.isDirect) { "UniFFI zero-copy &[u8] requires a direct ByteBuffer. Use ByteBuffer.allocateDirect()." }
118
+ val remaining = value.remaining()
119
+ val fb = ForeignBytes.ByValue()
120
+ fb.len = remaining
121
+ // Zero-length direct buffers: skip getDirectBufferPointer (platform-variable behavior)
122
+ // and pass null. The Rust side treats (null, 0) as &[].
123
+ fb.data = if (remaining == 0) null else com.sun.jna.Native.getDirectBufferPointer(value)
124
+ return fb
125
+ }
126
+
127
+ override fun lift(value: ForeignBytes.ByValue): java.nio.ByteBuffer =
128
+ error("ByRef bytes cannot be lifted: zero-copy &[u8] only flows foreign->Rust")
129
+
130
+ override fun read(buf: java.nio.ByteBuffer): java.nio.ByteBuffer =
131
+ error("ByRef bytes cannot be read from a buffer: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.")
132
+
133
+ override fun write(value: java.nio.ByteBuffer, buf: java.nio.ByteBuffer): Unit =
134
+ error("ByRef bytes cannot be written to a buffer: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.")
135
+
136
+ override fun allocationSize(value: java.nio.ByteBuffer): ULong =
137
+ error("ByRef bytes have no RustBuffer allocation size: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.")
138
+ }
139
+ /**
140
+ * The FfiConverter interface handles converter types to and from the FFI
141
+ *
142
+ * All implementing objects should be public to support external types. When a
143
+ * type is external we need to import it's FfiConverter.
144
+ *
145
+ * @suppress
146
+ */
147
+ public interface FfiConverter<KotlinType, FfiType> {
148
+ // Convert an FFI type to a Kotlin type
149
+ fun lift(value: FfiType): KotlinType
150
+
151
+ // Convert an Kotlin type to an FFI type
152
+ fun lower(value: KotlinType): FfiType
153
+
154
+ // Read a Kotlin type from a `ByteBuffer`
155
+ fun read(buf: ByteBuffer): KotlinType
156
+
157
+ // Calculate bytes to allocate when creating a `RustBuffer`
158
+ //
159
+ // This must return at least as many bytes as the write() function will
160
+ // write. It can return more bytes than needed, for example when writing
161
+ // Strings we can't know the exact bytes needed until we the UTF-8
162
+ // encoding, so we pessimistically allocate the largest size possible (3
163
+ // bytes per codepoint). Allocating extra bytes is not really a big deal
164
+ // because the `RustBuffer` is short-lived.
165
+ fun allocationSize(value: KotlinType): ULong
166
+
167
+ // Write a Kotlin type to a `ByteBuffer`
168
+ fun write(value: KotlinType, buf: ByteBuffer)
169
+
170
+ // Lower a value into a `RustBuffer`
171
+ //
172
+ // This method lowers a value into a `RustBuffer` rather than the normal
173
+ // FfiType. It's used by the callback interface code. Callback interface
174
+ // returns are always serialized into a `RustBuffer` regardless of their
175
+ // normal FFI type.
176
+ fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue {
177
+ val rbuf = RustBuffer.alloc(allocationSize(value))
178
+ try {
179
+ val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also {
180
+ it.order(ByteOrder.BIG_ENDIAN)
181
+ }
182
+ write(value, bbuf)
183
+ rbuf.writeField("len", bbuf.position().toLong())
184
+ return rbuf
185
+ } catch (e: Throwable) {
186
+ RustBuffer.free(rbuf)
187
+ throw e
188
+ }
189
+ }
190
+
191
+ // Lift a value from a `RustBuffer`.
192
+ //
193
+ // This here mostly because of the symmetry with `lowerIntoRustBuffer()`.
194
+ // It's currently only used by the `FfiConverterRustBuffer` class below.
195
+ fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType {
196
+ val byteBuf = rbuf.asByteBuffer()!!
197
+ try {
198
+ val item = read(byteBuf)
199
+ if (byteBuf.hasRemaining()) {
200
+ throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!")
201
+ }
202
+ return item
203
+ } finally {
204
+ RustBuffer.free(rbuf)
205
+ }
206
+ }
207
+ }
208
+
209
+ /**
210
+ * FfiConverter that uses `RustBuffer` as the FfiType
211
+ *
212
+ * @suppress
213
+ */
214
+ public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> {
215
+ override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value)
216
+ override fun lower(value: KotlinType) = lowerIntoRustBuffer(value)
217
+ }
218
+ // A handful of classes and functions to support the generated data structures.
219
+ // This would be a good candidate for isolating in its own ffi-support lib.
220
+
221
+ internal const val UNIFFI_CALL_SUCCESS = 0.toByte()
222
+ internal const val UNIFFI_CALL_ERROR = 1.toByte()
223
+ internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte()
224
+
225
+ @Structure.FieldOrder("code", "error_buf")
226
+ internal open class UniffiRustCallStatus : Structure() {
227
+ @JvmField var code: Byte = 0
228
+ @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue()
229
+
230
+ class ByValue: UniffiRustCallStatus(), Structure.ByValue
231
+
232
+ fun isSuccess(): Boolean {
233
+ return code == UNIFFI_CALL_SUCCESS
234
+ }
235
+
236
+ fun isError(): Boolean {
237
+ return code == UNIFFI_CALL_ERROR
238
+ }
239
+
240
+ fun isPanic(): Boolean {
241
+ return code == UNIFFI_CALL_UNEXPECTED_ERROR
242
+ }
243
+
244
+ companion object {
245
+ fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue {
246
+ val callStatus = UniffiRustCallStatus.ByValue()
247
+ callStatus.code = code
248
+ callStatus.error_buf = errorBuf
249
+ return callStatus
250
+ }
251
+ }
252
+ }
253
+
254
+ class InternalException(message: String) : kotlin.Exception(message)
255
+
256
+ /**
257
+ * Each top-level error class has a companion object that can lift the error from the call status's rust buffer
258
+ *
259
+ * @suppress
260
+ */
261
+ interface UniffiRustCallStatusErrorHandler<E> {
262
+ fun lift(error_buf: RustBuffer.ByValue): E;
263
+ }
264
+
265
+ // Helpers for calling Rust
266
+ // In practice we usually need to be synchronized to call this safely, so it doesn't
267
+ // synchronize itself
268
+
269
+ // Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err
270
+ private inline fun <U, E: kotlin.Exception> uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler<E>, callback: (UniffiRustCallStatus) -> U): U {
271
+ var status = UniffiRustCallStatus()
272
+ val return_value = callback(status)
273
+ uniffiCheckCallStatus(errorHandler, status)
274
+ return return_value
275
+ }
276
+
277
+ // Check UniffiRustCallStatus and throw an error if the call wasn't successful
278
+ private fun<E: kotlin.Exception> uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler<E>, status: UniffiRustCallStatus) {
279
+ if (status.isSuccess()) {
280
+ return
281
+ } else if (status.isError()) {
282
+ throw errorHandler.lift(status.error_buf)
283
+ } else if (status.isPanic()) {
284
+ // when the rust code sees a panic, it tries to construct a rustbuffer
285
+ // with the message. but if that code panics, then it just sends back
286
+ // an empty buffer.
287
+ if (status.error_buf.len > 0) {
288
+ throw InternalException(FfiConverterString.lift(status.error_buf))
289
+ } else {
290
+ throw InternalException("Rust panic")
291
+ }
292
+ } else {
293
+ throw InternalException("Unknown rust call status: $status.code")
294
+ }
295
+ }
296
+
297
+ /**
298
+ * UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
299
+ *
300
+ * @suppress
301
+ */
302
+ object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<InternalException> {
303
+ override fun lift(error_buf: RustBuffer.ByValue): InternalException {
304
+ RustBuffer.free(error_buf)
305
+ return InternalException("Unexpected CALL_ERROR")
306
+ }
307
+ }
308
+
309
+ // Call a rust function that returns a plain value
310
+ private inline fun <U> uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U {
311
+ return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback)
312
+ }
313
+
314
+ internal inline fun<T> uniffiTraitInterfaceCall(
315
+ callStatus: UniffiRustCallStatus,
316
+ makeCall: () -> T,
317
+ writeReturn: (T) -> Unit,
318
+ ) {
319
+ try {
320
+ writeReturn(makeCall())
321
+ } catch(e: kotlin.Exception) {
322
+ val err = try { e.stackTraceToString() } catch(_: Throwable) { "" }
323
+ callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
324
+ callStatus.error_buf = FfiConverterString.lower(err)
325
+ }
326
+ }
327
+
328
+ internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError(
329
+ callStatus: UniffiRustCallStatus,
330
+ makeCall: () -> T,
331
+ writeReturn: (T) -> Unit,
332
+ lowerError: (E) -> RustBuffer.ByValue
333
+ ) {
334
+ try {
335
+ writeReturn(makeCall())
336
+ } catch(e: kotlin.Exception) {
337
+ if (e is E) {
338
+ callStatus.code = UNIFFI_CALL_ERROR
339
+ callStatus.error_buf = lowerError(e)
340
+ } else {
341
+ val err = try { e.stackTraceToString() } catch(_: Throwable) { "" }
342
+ callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
343
+ callStatus.error_buf = FfiConverterString.lower(err)
344
+ }
345
+ }
346
+ }
347
+ // Initial value and increment amount for handles.
348
+ // These ensure that Kotlin-generated handles always have the lowest bit set
349
+ private const val UNIFFI_HANDLEMAP_INITIAL = 1.toLong()
350
+ private const val UNIFFI_HANDLEMAP_DELTA = 2.toLong()
351
+
352
+ // Map handles to objects
353
+ //
354
+ // This is used pass an opaque 64-bit handle representing a foreign object to the Rust code.
355
+ internal class UniffiHandleMap<T: Any> {
356
+ private val map = ConcurrentHashMap<Long, T>()
357
+ // Start
358
+ private val counter = java.util.concurrent.atomic.AtomicLong(UNIFFI_HANDLEMAP_INITIAL)
359
+
360
+ val size: Int
361
+ get() = map.size
362
+
363
+ // Insert a new object into the handle map and get a handle for it
364
+ fun insert(obj: T): Long {
365
+ val handle = counter.getAndAdd(UNIFFI_HANDLEMAP_DELTA)
366
+ map.put(handle, obj)
367
+ return handle
368
+ }
369
+
370
+ // Clone a handle, creating a new one
371
+ fun clone(handle: Long): Long {
372
+ val obj = map.get(handle) ?: throw InternalException("UniffiHandleMap.clone: Invalid handle")
373
+ return insert(obj)
374
+ }
375
+
376
+ // Get an object from the handle map
377
+ fun get(handle: Long): T {
378
+ return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle")
379
+ }
380
+
381
+ // Remove an entry from the handlemap and get the Kotlin object back
382
+ fun remove(handle: Long): T {
383
+ return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle")
384
+ }
385
+ }
386
+
387
+ // Contains loading, initialization code,
388
+ // and the FFI Function declarations in a com.sun.jna.Library.
389
+ @Synchronized
390
+ private fun findLibraryName(componentName: String): String {
391
+ val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride")
392
+ if (libOverride != null) {
393
+ return libOverride
394
+ }
395
+ return "flamewallet_ffi"
396
+ }
397
+
398
+ // Define FFI callback types
399
+ internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback {
400
+ fun callback(`data`: Long,`pollResult`: Byte,)
401
+ }
402
+ internal interface UniffiForeignFutureDroppedCallback : com.sun.jna.Callback {
403
+ fun callback(`handle`: Long,)
404
+ }
405
+ internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback {
406
+ fun callback(`handle`: Long,)
407
+ }
408
+ internal interface UniffiCallbackInterfaceClone : com.sun.jna.Callback {
409
+ fun callback(`handle`: Long,)
410
+ : Long
411
+ }
412
+ @Structure.FieldOrder("handle", "free")
413
+ internal open class UniffiForeignFutureDroppedCallbackStruct(
414
+ @JvmField internal var `handle`: Long = 0.toLong(),
415
+ @JvmField internal var `free`: UniffiForeignFutureDroppedCallback? = null,
416
+ ) : Structure() {
417
+ class UniffiByValue(
418
+ `handle`: Long = 0.toLong(),
419
+ `free`: UniffiForeignFutureDroppedCallback? = null,
420
+ ): UniffiForeignFutureDroppedCallbackStruct(`handle`,`free`,), Structure.ByValue
421
+
422
+ internal fun uniffiSetValue(other: UniffiForeignFutureDroppedCallbackStruct) {
423
+ `handle` = other.`handle`
424
+ `free` = other.`free`
425
+ }
426
+
427
+ }
428
+ @Structure.FieldOrder("returnValue", "callStatus")
429
+ internal open class UniffiForeignFutureResultU8(
430
+ @JvmField internal var `returnValue`: Byte = 0.toByte(),
431
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
432
+ ) : Structure() {
433
+ class UniffiByValue(
434
+ `returnValue`: Byte = 0.toByte(),
435
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
436
+ ): UniffiForeignFutureResultU8(`returnValue`,`callStatus`,), Structure.ByValue
437
+
438
+ internal fun uniffiSetValue(other: UniffiForeignFutureResultU8) {
439
+ `returnValue` = other.`returnValue`
440
+ `callStatus` = other.`callStatus`
441
+ }
442
+
443
+ }
444
+ internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback {
445
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU8.UniffiByValue,)
446
+ }
447
+ @Structure.FieldOrder("returnValue", "callStatus")
448
+ internal open class UniffiForeignFutureResultI8(
449
+ @JvmField internal var `returnValue`: Byte = 0.toByte(),
450
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
451
+ ) : Structure() {
452
+ class UniffiByValue(
453
+ `returnValue`: Byte = 0.toByte(),
454
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
455
+ ): UniffiForeignFutureResultI8(`returnValue`,`callStatus`,), Structure.ByValue
456
+
457
+ internal fun uniffiSetValue(other: UniffiForeignFutureResultI8) {
458
+ `returnValue` = other.`returnValue`
459
+ `callStatus` = other.`callStatus`
460
+ }
461
+
462
+ }
463
+ internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback {
464
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI8.UniffiByValue,)
465
+ }
466
+ @Structure.FieldOrder("returnValue", "callStatus")
467
+ internal open class UniffiForeignFutureResultU16(
468
+ @JvmField internal var `returnValue`: Short = 0.toShort(),
469
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
470
+ ) : Structure() {
471
+ class UniffiByValue(
472
+ `returnValue`: Short = 0.toShort(),
473
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
474
+ ): UniffiForeignFutureResultU16(`returnValue`,`callStatus`,), Structure.ByValue
475
+
476
+ internal fun uniffiSetValue(other: UniffiForeignFutureResultU16) {
477
+ `returnValue` = other.`returnValue`
478
+ `callStatus` = other.`callStatus`
479
+ }
480
+
481
+ }
482
+ internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback {
483
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU16.UniffiByValue,)
484
+ }
485
+ @Structure.FieldOrder("returnValue", "callStatus")
486
+ internal open class UniffiForeignFutureResultI16(
487
+ @JvmField internal var `returnValue`: Short = 0.toShort(),
488
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
489
+ ) : Structure() {
490
+ class UniffiByValue(
491
+ `returnValue`: Short = 0.toShort(),
492
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
493
+ ): UniffiForeignFutureResultI16(`returnValue`,`callStatus`,), Structure.ByValue
494
+
495
+ internal fun uniffiSetValue(other: UniffiForeignFutureResultI16) {
496
+ `returnValue` = other.`returnValue`
497
+ `callStatus` = other.`callStatus`
498
+ }
499
+
500
+ }
501
+ internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback {
502
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI16.UniffiByValue,)
503
+ }
504
+ @Structure.FieldOrder("returnValue", "callStatus")
505
+ internal open class UniffiForeignFutureResultU32(
506
+ @JvmField internal var `returnValue`: Int = 0,
507
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
508
+ ) : Structure() {
509
+ class UniffiByValue(
510
+ `returnValue`: Int = 0,
511
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
512
+ ): UniffiForeignFutureResultU32(`returnValue`,`callStatus`,), Structure.ByValue
513
+
514
+ internal fun uniffiSetValue(other: UniffiForeignFutureResultU32) {
515
+ `returnValue` = other.`returnValue`
516
+ `callStatus` = other.`callStatus`
517
+ }
518
+
519
+ }
520
+ internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback {
521
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU32.UniffiByValue,)
522
+ }
523
+ @Structure.FieldOrder("returnValue", "callStatus")
524
+ internal open class UniffiForeignFutureResultI32(
525
+ @JvmField internal var `returnValue`: Int = 0,
526
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
527
+ ) : Structure() {
528
+ class UniffiByValue(
529
+ `returnValue`: Int = 0,
530
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
531
+ ): UniffiForeignFutureResultI32(`returnValue`,`callStatus`,), Structure.ByValue
532
+
533
+ internal fun uniffiSetValue(other: UniffiForeignFutureResultI32) {
534
+ `returnValue` = other.`returnValue`
535
+ `callStatus` = other.`callStatus`
536
+ }
537
+
538
+ }
539
+ internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback {
540
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI32.UniffiByValue,)
541
+ }
542
+ @Structure.FieldOrder("returnValue", "callStatus")
543
+ internal open class UniffiForeignFutureResultU64(
544
+ @JvmField internal var `returnValue`: Long = 0.toLong(),
545
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
546
+ ) : Structure() {
547
+ class UniffiByValue(
548
+ `returnValue`: Long = 0.toLong(),
549
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
550
+ ): UniffiForeignFutureResultU64(`returnValue`,`callStatus`,), Structure.ByValue
551
+
552
+ internal fun uniffiSetValue(other: UniffiForeignFutureResultU64) {
553
+ `returnValue` = other.`returnValue`
554
+ `callStatus` = other.`callStatus`
555
+ }
556
+
557
+ }
558
+ internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback {
559
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU64.UniffiByValue,)
560
+ }
561
+ @Structure.FieldOrder("returnValue", "callStatus")
562
+ internal open class UniffiForeignFutureResultI64(
563
+ @JvmField internal var `returnValue`: Long = 0.toLong(),
564
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
565
+ ) : Structure() {
566
+ class UniffiByValue(
567
+ `returnValue`: Long = 0.toLong(),
568
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
569
+ ): UniffiForeignFutureResultI64(`returnValue`,`callStatus`,), Structure.ByValue
570
+
571
+ internal fun uniffiSetValue(other: UniffiForeignFutureResultI64) {
572
+ `returnValue` = other.`returnValue`
573
+ `callStatus` = other.`callStatus`
574
+ }
575
+
576
+ }
577
+ internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback {
578
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI64.UniffiByValue,)
579
+ }
580
+ @Structure.FieldOrder("returnValue", "callStatus")
581
+ internal open class UniffiForeignFutureResultF32(
582
+ @JvmField internal var `returnValue`: Float = 0.0f,
583
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
584
+ ) : Structure() {
585
+ class UniffiByValue(
586
+ `returnValue`: Float = 0.0f,
587
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
588
+ ): UniffiForeignFutureResultF32(`returnValue`,`callStatus`,), Structure.ByValue
589
+
590
+ internal fun uniffiSetValue(other: UniffiForeignFutureResultF32) {
591
+ `returnValue` = other.`returnValue`
592
+ `callStatus` = other.`callStatus`
593
+ }
594
+
595
+ }
596
+ internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback {
597
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF32.UniffiByValue,)
598
+ }
599
+ @Structure.FieldOrder("returnValue", "callStatus")
600
+ internal open class UniffiForeignFutureResultF64(
601
+ @JvmField internal var `returnValue`: Double = 0.0,
602
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
603
+ ) : Structure() {
604
+ class UniffiByValue(
605
+ `returnValue`: Double = 0.0,
606
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
607
+ ): UniffiForeignFutureResultF64(`returnValue`,`callStatus`,), Structure.ByValue
608
+
609
+ internal fun uniffiSetValue(other: UniffiForeignFutureResultF64) {
610
+ `returnValue` = other.`returnValue`
611
+ `callStatus` = other.`callStatus`
612
+ }
613
+
614
+ }
615
+ internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback {
616
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF64.UniffiByValue,)
617
+ }
618
+ @Structure.FieldOrder("returnValue", "callStatus")
619
+ internal open class UniffiForeignFutureResultRustBuffer(
620
+ @JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
621
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
622
+ ) : Structure() {
623
+ class UniffiByValue(
624
+ `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
625
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
626
+ ): UniffiForeignFutureResultRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue
627
+
628
+ internal fun uniffiSetValue(other: UniffiForeignFutureResultRustBuffer) {
629
+ `returnValue` = other.`returnValue`
630
+ `callStatus` = other.`callStatus`
631
+ }
632
+
633
+ }
634
+ internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback {
635
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultRustBuffer.UniffiByValue,)
636
+ }
637
+ @Structure.FieldOrder("callStatus")
638
+ internal open class UniffiForeignFutureResultVoid(
639
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
640
+ ) : Structure() {
641
+ class UniffiByValue(
642
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
643
+ ): UniffiForeignFutureResultVoid(`callStatus`,), Structure.ByValue
644
+
645
+ internal fun uniffiSetValue(other: UniffiForeignFutureResultVoid) {
646
+ `callStatus` = other.`callStatus`
647
+ }
648
+
649
+ }
650
+ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {
651
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultVoid.UniffiByValue,)
652
+ }
653
+
654
+ // A JNA Library to expose the extern-C FFI definitions.
655
+ // This is an implementation detail which will be called internally by the public API.
656
+
657
+ // For large crates we prevent `MethodTooLargeException` (see #2340)
658
+ // N.B. the name of the extension is very misleading, since it is
659
+ // rather `InterfaceTooLargeException`, caused by too many methods
660
+ // in the interface for large crates.
661
+ //
662
+ // By splitting the otherwise huge interface into two parts
663
+ // * UniffiLib (this)
664
+ // * IntegrityCheckingUniffiLib
665
+ // And all checksum methods are put into `IntegrityCheckingUniffiLib`
666
+ // we allow for ~2x as many methods in the UniffiLib interface.
667
+ //
668
+ // Note: above all written when we used JNA's `loadIndirect` etc.
669
+ // We now use JNA's "direct mapping" - unclear if same considerations apply exactly.
670
+ internal object IntegrityCheckingUniffiLib {
671
+ init {
672
+ Native.register(IntegrityCheckingUniffiLib::class.java, findLibraryName(componentName = "flamewallet_ffi"))
673
+ uniffiCheckContractApiVersion(this)
674
+ uniffiCheckApiChecksums(this)
675
+ }
676
+
677
+ internal fun ensureInitialized() = Unit
678
+ external fun uniffi_flamewallet_ffi_checksum_func_decode_contract(
679
+ ): Int
680
+ external fun uniffi_flamewallet_ffi_checksum_func_opening_matches(
681
+ ): Int
682
+ external fun uniffi_flamewallet_ffi_checksum_func_address_to_predicate(
683
+ ): Int
684
+ external fun uniffi_flamewallet_ffi_checksum_func_generate_mnemonic(
685
+ ): Int
686
+ external fun uniffi_flamewallet_ffi_checksum_func_mnemonic_to_seed(
687
+ ): Int
688
+ external fun uniffi_flamewallet_ffi_checksum_func_validate_mnemonic(
689
+ ): Int
690
+ external fun uniffi_flamewallet_ffi_checksum_method_wallet_address(
691
+ ): Int
692
+ external fun uniffi_flamewallet_ffi_checksum_method_wallet_build_transfer(
693
+ ): Int
694
+ external fun uniffi_flamewallet_ffi_checksum_method_wallet_network(
695
+ ): Int
696
+ external fun uniffi_flamewallet_ffi_checksum_method_wallet_next_address(
697
+ ): Int
698
+ external fun uniffi_flamewallet_ffi_checksum_method_wallet_next_index(
699
+ ): Int
700
+ external fun uniffi_flamewallet_ffi_checksum_method_wallet_open_note(
701
+ ): Int
702
+ external fun uniffi_flamewallet_ffi_checksum_method_wallet_owns(
703
+ ): Int
704
+ external fun uniffi_flamewallet_ffi_checksum_method_wallet_receiving_key(
705
+ ): Int
706
+ external fun uniffi_flamewallet_ffi_checksum_constructor_wallet_from_mnemonic(
707
+ ): Int
708
+ external fun uniffi_flamewallet_ffi_checksum_constructor_wallet_new(
709
+ ): Int
710
+ external fun ffi_flamewallet_ffi_uniffi_contract_version(
711
+ ): Int
712
+
713
+
714
+ }
715
+
716
+ internal object UniffiLib {
717
+
718
+ // The Cleaner for the whole library
719
+ internal val CLEANER: UniffiCleaner by lazy {
720
+ UniffiCleaner.create()
721
+ }
722
+
723
+
724
+ init {
725
+ Native.register(UniffiLib::class.java, findLibraryName(componentName = "flamewallet_ffi"))
726
+
727
+ }
728
+
729
+ internal fun ensureInitialized() = Unit
730
+ external fun uniffi_flamewallet_ffi_fn_clone_wallet(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
731
+ ): Long
732
+ external fun uniffi_flamewallet_ffi_fn_free_wallet(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
733
+ ): Unit
734
+ external fun uniffi_flamewallet_ffi_fn_constructor_wallet_from_mnemonic(`phrase`: RustBuffer.ByValue,`passphrase`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`nextIndex`: Int,uniffi_out_err: UniffiRustCallStatus,
735
+ ): Long
736
+ external fun uniffi_flamewallet_ffi_fn_constructor_wallet_new(`seed`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`nextIndex`: Int,uniffi_out_err: UniffiRustCallStatus,
737
+ ): Long
738
+ external fun uniffi_flamewallet_ffi_fn_method_wallet_address(`ptr`: Long,`path`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
739
+ ): RustBuffer.ByValue
740
+ external fun uniffi_flamewallet_ffi_fn_method_wallet_build_transfer(`ptr`: Long,`request`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
741
+ ): RustBuffer.ByValue
742
+ external fun uniffi_flamewallet_ffi_fn_method_wallet_network(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
743
+ ): RustBuffer.ByValue
744
+ external fun uniffi_flamewallet_ffi_fn_method_wallet_next_address(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
745
+ ): RustBuffer.ByValue
746
+ external fun uniffi_flamewallet_ffi_fn_method_wallet_next_index(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
747
+ ): Int
748
+ external fun uniffi_flamewallet_ffi_fn_method_wallet_open_note(`ptr`: Long,`contract`: RustBuffer.ByValue,`note`: RustBuffer.ByValue,`path`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
749
+ ): RustBuffer.ByValue
750
+ external fun uniffi_flamewallet_ffi_fn_method_wallet_owns(`ptr`: Long,`predicate`: RustBuffer.ByValue,`gap`: Int,uniffi_out_err: UniffiRustCallStatus,
751
+ ): RustBuffer.ByValue
752
+ external fun uniffi_flamewallet_ffi_fn_method_wallet_receiving_key(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
753
+ ): RustBuffer.ByValue
754
+ external fun uniffi_flamewallet_ffi_fn_func_decode_contract(`bytes`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
755
+ ): RustBuffer.ByValue
756
+ external fun uniffi_flamewallet_ffi_fn_func_opening_matches(`contract`: RustBuffer.ByValue,`opening`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
757
+ ): Byte
758
+ external fun uniffi_flamewallet_ffi_fn_func_address_to_predicate(`address`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
759
+ ): RustBuffer.ByValue
760
+ external fun uniffi_flamewallet_ffi_fn_func_generate_mnemonic(`wordCount`: Byte,uniffi_out_err: UniffiRustCallStatus,
761
+ ): RustBuffer.ByValue
762
+ external fun uniffi_flamewallet_ffi_fn_func_mnemonic_to_seed(`phrase`: RustBuffer.ByValue,`passphrase`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
763
+ ): RustBuffer.ByValue
764
+ external fun uniffi_flamewallet_ffi_fn_func_validate_mnemonic(`phrase`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
765
+ ): Byte
766
+ external fun ffi_flamewallet_ffi_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus,
767
+ ): RustBuffer.ByValue
768
+ external fun ffi_flamewallet_ffi_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus,
769
+ ): RustBuffer.ByValue
770
+ external fun ffi_flamewallet_ffi_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
771
+ ): Unit
772
+ external fun ffi_flamewallet_ffi_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus,
773
+ ): RustBuffer.ByValue
774
+ external fun ffi_flamewallet_ffi_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
775
+ ): Unit
776
+ external fun ffi_flamewallet_ffi_rust_future_cancel_u8(`handle`: Long,
777
+ ): Unit
778
+ external fun ffi_flamewallet_ffi_rust_future_free_u8(`handle`: Long,
779
+ ): Unit
780
+ external fun ffi_flamewallet_ffi_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
781
+ ): Int
782
+ external fun ffi_flamewallet_ffi_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
783
+ ): Unit
784
+ external fun ffi_flamewallet_ffi_rust_future_cancel_i8(`handle`: Long,
785
+ ): Unit
786
+ external fun ffi_flamewallet_ffi_rust_future_free_i8(`handle`: Long,
787
+ ): Unit
788
+ external fun ffi_flamewallet_ffi_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
789
+ ): Byte
790
+ external fun ffi_flamewallet_ffi_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
791
+ ): Unit
792
+ external fun ffi_flamewallet_ffi_rust_future_cancel_u16(`handle`: Long,
793
+ ): Unit
794
+ external fun ffi_flamewallet_ffi_rust_future_free_u16(`handle`: Long,
795
+ ): Unit
796
+ external fun ffi_flamewallet_ffi_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
797
+ ): Int
798
+ external fun ffi_flamewallet_ffi_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
799
+ ): Unit
800
+ external fun ffi_flamewallet_ffi_rust_future_cancel_i16(`handle`: Long,
801
+ ): Unit
802
+ external fun ffi_flamewallet_ffi_rust_future_free_i16(`handle`: Long,
803
+ ): Unit
804
+ external fun ffi_flamewallet_ffi_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
805
+ ): Short
806
+ external fun ffi_flamewallet_ffi_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
807
+ ): Unit
808
+ external fun ffi_flamewallet_ffi_rust_future_cancel_u32(`handle`: Long,
809
+ ): Unit
810
+ external fun ffi_flamewallet_ffi_rust_future_free_u32(`handle`: Long,
811
+ ): Unit
812
+ external fun ffi_flamewallet_ffi_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
813
+ ): Int
814
+ external fun ffi_flamewallet_ffi_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
815
+ ): Unit
816
+ external fun ffi_flamewallet_ffi_rust_future_cancel_i32(`handle`: Long,
817
+ ): Unit
818
+ external fun ffi_flamewallet_ffi_rust_future_free_i32(`handle`: Long,
819
+ ): Unit
820
+ external fun ffi_flamewallet_ffi_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
821
+ ): Int
822
+ external fun ffi_flamewallet_ffi_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
823
+ ): Unit
824
+ external fun ffi_flamewallet_ffi_rust_future_cancel_u64(`handle`: Long,
825
+ ): Unit
826
+ external fun ffi_flamewallet_ffi_rust_future_free_u64(`handle`: Long,
827
+ ): Unit
828
+ external fun ffi_flamewallet_ffi_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
829
+ ): Long
830
+ external fun ffi_flamewallet_ffi_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
831
+ ): Unit
832
+ external fun ffi_flamewallet_ffi_rust_future_cancel_i64(`handle`: Long,
833
+ ): Unit
834
+ external fun ffi_flamewallet_ffi_rust_future_free_i64(`handle`: Long,
835
+ ): Unit
836
+ external fun ffi_flamewallet_ffi_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
837
+ ): Long
838
+ external fun ffi_flamewallet_ffi_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
839
+ ): Unit
840
+ external fun ffi_flamewallet_ffi_rust_future_cancel_f32(`handle`: Long,
841
+ ): Unit
842
+ external fun ffi_flamewallet_ffi_rust_future_free_f32(`handle`: Long,
843
+ ): Unit
844
+ external fun ffi_flamewallet_ffi_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
845
+ ): Float
846
+ external fun ffi_flamewallet_ffi_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
847
+ ): Unit
848
+ external fun ffi_flamewallet_ffi_rust_future_cancel_f64(`handle`: Long,
849
+ ): Unit
850
+ external fun ffi_flamewallet_ffi_rust_future_free_f64(`handle`: Long,
851
+ ): Unit
852
+ external fun ffi_flamewallet_ffi_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
853
+ ): Double
854
+ external fun ffi_flamewallet_ffi_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
855
+ ): Unit
856
+ external fun ffi_flamewallet_ffi_rust_future_cancel_rust_buffer(`handle`: Long,
857
+ ): Unit
858
+ external fun ffi_flamewallet_ffi_rust_future_free_rust_buffer(`handle`: Long,
859
+ ): Unit
860
+ external fun ffi_flamewallet_ffi_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
861
+ ): RustBuffer.ByValue
862
+ external fun ffi_flamewallet_ffi_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
863
+ ): Unit
864
+ external fun ffi_flamewallet_ffi_rust_future_cancel_void(`handle`: Long,
865
+ ): Unit
866
+ external fun ffi_flamewallet_ffi_rust_future_free_void(`handle`: Long,
867
+ ): Unit
868
+ external fun ffi_flamewallet_ffi_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
869
+ ): Unit
870
+
871
+
872
+ }
873
+
874
+ private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) {
875
+ // Get the bindings contract version from our ComponentInterface
876
+ val bindings_contract_version = 30
877
+ // Get the scaffolding contract version by calling the into the dylib
878
+ val scaffolding_contract_version = lib.ffi_flamewallet_ffi_uniffi_contract_version()
879
+ if (bindings_contract_version != scaffolding_contract_version) {
880
+ throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project")
881
+ }
882
+ }
883
+ @Suppress("UNUSED_PARAMETER")
884
+ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) {
885
+ if ((lib.uniffi_flamewallet_ffi_checksum_func_decode_contract() and 0xFFFF) != 9189) {
886
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
887
+ }
888
+ if ((lib.uniffi_flamewallet_ffi_checksum_func_opening_matches() and 0xFFFF) != 54400) {
889
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
890
+ }
891
+ if ((lib.uniffi_flamewallet_ffi_checksum_func_address_to_predicate() and 0xFFFF) != 27158) {
892
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
893
+ }
894
+ if ((lib.uniffi_flamewallet_ffi_checksum_func_generate_mnemonic() and 0xFFFF) != 49383) {
895
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
896
+ }
897
+ if ((lib.uniffi_flamewallet_ffi_checksum_func_mnemonic_to_seed() and 0xFFFF) != 5184) {
898
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
899
+ }
900
+ if ((lib.uniffi_flamewallet_ffi_checksum_func_validate_mnemonic() and 0xFFFF) != 36978) {
901
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
902
+ }
903
+ if ((lib.uniffi_flamewallet_ffi_checksum_method_wallet_address() and 0xFFFF) != 24772) {
904
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
905
+ }
906
+ if ((lib.uniffi_flamewallet_ffi_checksum_method_wallet_build_transfer() and 0xFFFF) != 41970) {
907
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
908
+ }
909
+ if ((lib.uniffi_flamewallet_ffi_checksum_method_wallet_network() and 0xFFFF) != 6461) {
910
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
911
+ }
912
+ if ((lib.uniffi_flamewallet_ffi_checksum_method_wallet_next_address() and 0xFFFF) != 12667) {
913
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
914
+ }
915
+ if ((lib.uniffi_flamewallet_ffi_checksum_method_wallet_next_index() and 0xFFFF) != 50043) {
916
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
917
+ }
918
+ if ((lib.uniffi_flamewallet_ffi_checksum_method_wallet_open_note() and 0xFFFF) != 45629) {
919
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
920
+ }
921
+ if ((lib.uniffi_flamewallet_ffi_checksum_method_wallet_owns() and 0xFFFF) != 34274) {
922
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
923
+ }
924
+ if ((lib.uniffi_flamewallet_ffi_checksum_method_wallet_receiving_key() and 0xFFFF) != 41950) {
925
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
926
+ }
927
+ if ((lib.uniffi_flamewallet_ffi_checksum_constructor_wallet_from_mnemonic() and 0xFFFF) != 19125) {
928
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
929
+ }
930
+ if ((lib.uniffi_flamewallet_ffi_checksum_constructor_wallet_new() and 0xFFFF) != 9773) {
931
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
932
+ }
933
+ }
934
+
935
+ /**
936
+ * @suppress
937
+ */
938
+ public fun uniffiEnsureInitialized() {
939
+ // Call arbitrary methods on IntegrityCheckingUniffiLib and UniffiLib to ensure that
940
+ // their init blocks run. This ensures initialization across crates works as expected.
941
+ IntegrityCheckingUniffiLib.ensureInitialized()
942
+ UniffiLib.ensureInitialized()
943
+ }
944
+
945
+ // Async support
946
+
947
+ // Public interface members begin here.
948
+
949
+
950
+ // Interface implemented by anything that can contain an object reference.
951
+ //
952
+ // Such types expose a `destroy()` method that must be called to cleanly
953
+ // dispose of the contained objects. Failure to call this method may result
954
+ // in memory leaks.
955
+ //
956
+ // The easiest way to ensure this method is called is to use the `.use`
957
+ // helper method to execute a block and destroy the object at the end.
958
+ interface Disposable {
959
+ fun destroy()
960
+ companion object {
961
+ fun destroy(vararg args: Any?) {
962
+ for (arg in args) {
963
+ when (arg) {
964
+ is Disposable -> arg.destroy()
965
+ is ArrayList<*> -> {
966
+ for (idx in arg.indices) {
967
+ val element = arg[idx]
968
+ if (element is Disposable) {
969
+ element.destroy()
970
+ }
971
+ }
972
+ }
973
+ is Map<*, *> -> {
974
+ for (element in arg.values) {
975
+ if (element is Disposable) {
976
+ element.destroy()
977
+ }
978
+ }
979
+ }
980
+ is Iterable<*> -> {
981
+ for (element in arg) {
982
+ if (element is Disposable) {
983
+ element.destroy()
984
+ }
985
+ }
986
+ }
987
+ }
988
+ }
989
+ }
990
+ }
991
+ }
992
+
993
+ /**
994
+ * @suppress
995
+ */
996
+ inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
997
+ try {
998
+ block(this)
999
+ } finally {
1000
+ try {
1001
+ // N.B. our implementation is on the nullable type `Disposable?`.
1002
+ this?.destroy()
1003
+ } catch (e: Throwable) {
1004
+ // swallow
1005
+ }
1006
+ }
1007
+
1008
+ /**
1009
+ * Placeholder object used to signal that we're constructing an interface with a FFI handle.
1010
+ *
1011
+ * This is the first argument for interface constructors that input a raw handle. It exists is that
1012
+ * so we can avoid signature conflicts when an interface has a regular constructor than inputs a
1013
+ * Long.
1014
+ *
1015
+ * @suppress
1016
+ * */
1017
+ object UniffiWithHandle
1018
+
1019
+ /**
1020
+ * Used to instantiate an interface without an actual pointer, for fakes in tests, mostly.
1021
+ *
1022
+ * @suppress
1023
+ * */
1024
+ object NoHandle
1025
+ /**
1026
+ * The cleaner interface for Object finalization code to run.
1027
+ * This is the entry point to any implementation that we're using.
1028
+ *
1029
+ * The cleaner registers objects and returns cleanables, so now we are
1030
+ * defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the
1031
+ * different implmentations available at compile time.
1032
+ *
1033
+ * @suppress
1034
+ */
1035
+ interface UniffiCleaner {
1036
+ interface Cleanable {
1037
+ fun clean()
1038
+ }
1039
+
1040
+ fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable
1041
+
1042
+ companion object
1043
+ }
1044
+
1045
+ // The fallback Jna cleaner, which is available for both Android, and the JVM.
1046
+ private class UniffiJnaCleaner : UniffiCleaner {
1047
+ private val cleaner = com.sun.jna.internal.Cleaner.getCleaner()
1048
+
1049
+ override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
1050
+ UniffiJnaCleanable(cleaner.register(value, cleanUpTask))
1051
+ }
1052
+
1053
+ private class UniffiJnaCleanable(
1054
+ private val cleanable: com.sun.jna.internal.Cleaner.Cleanable,
1055
+ ) : UniffiCleaner.Cleanable {
1056
+ override fun clean() = cleanable.clean()
1057
+ }
1058
+
1059
+
1060
+ // We decide at uniffi binding generation time whether we were
1061
+ // using Android or not.
1062
+ // There are further runtime checks to chose the correct implementation
1063
+ // of the cleaner.
1064
+ private fun UniffiCleaner.Companion.create(): UniffiCleaner =
1065
+ try {
1066
+ // For safety's sake: if the library hasn't been run in android_cleaner = true
1067
+ // mode, but is being run on Android, then we still need to think about
1068
+ // Android API versions.
1069
+ // So we check if java.lang.ref.Cleaner is there, and use that…
1070
+ java.lang.Class.forName("java.lang.ref.Cleaner")
1071
+ JavaLangRefCleaner()
1072
+ } catch (e: ClassNotFoundException) {
1073
+ // … otherwise, fallback to the JNA cleaner.
1074
+ UniffiJnaCleaner()
1075
+ }
1076
+
1077
+ private class JavaLangRefCleaner : UniffiCleaner {
1078
+ val cleaner = java.lang.ref.Cleaner.create()
1079
+
1080
+ override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
1081
+ JavaLangRefCleanable(cleaner.register(value, cleanUpTask))
1082
+ }
1083
+
1084
+ private class JavaLangRefCleanable(
1085
+ val cleanable: java.lang.ref.Cleaner.Cleanable
1086
+ ) : UniffiCleaner.Cleanable {
1087
+ override fun clean() = cleanable.clean()
1088
+ }
1089
+
1090
+ /**
1091
+ * @suppress
1092
+ */
1093
+ public object FfiConverterUByte: FfiConverter<UByte, Byte> {
1094
+ override fun lift(value: Byte): UByte {
1095
+ return value.toUByte()
1096
+ }
1097
+
1098
+ fun lift(value: Int): UByte {
1099
+ return value.toUByte()
1100
+ }
1101
+
1102
+ override fun read(buf: ByteBuffer): UByte {
1103
+ return lift(buf.get())
1104
+ }
1105
+
1106
+ override fun lower(value: UByte): Byte {
1107
+ return value.toByte()
1108
+ }
1109
+
1110
+ override fun allocationSize(value: UByte) = 1UL
1111
+
1112
+ override fun write(value: UByte, buf: ByteBuffer) {
1113
+ buf.put(value.toByte())
1114
+ }
1115
+ }
1116
+
1117
+ /**
1118
+ * @suppress
1119
+ */
1120
+ public object FfiConverterUInt: FfiConverter<UInt, Int> {
1121
+ override fun lift(value: Int): UInt {
1122
+ return value.toUInt()
1123
+ }
1124
+
1125
+ override fun read(buf: ByteBuffer): UInt {
1126
+ return lift(buf.getInt())
1127
+ }
1128
+
1129
+ override fun lower(value: UInt): Int {
1130
+ return value.toInt()
1131
+ }
1132
+
1133
+ override fun allocationSize(value: UInt) = 4UL
1134
+
1135
+ override fun write(value: UInt, buf: ByteBuffer) {
1136
+ buf.putInt(value.toInt())
1137
+ }
1138
+ }
1139
+
1140
+ /**
1141
+ * @suppress
1142
+ */
1143
+ public object FfiConverterULong: FfiConverter<ULong, Long> {
1144
+ override fun lift(value: Long): ULong {
1145
+ return value.toULong()
1146
+ }
1147
+
1148
+ override fun read(buf: ByteBuffer): ULong {
1149
+ return lift(buf.getLong())
1150
+ }
1151
+
1152
+ override fun lower(value: ULong): Long {
1153
+ return value.toLong()
1154
+ }
1155
+
1156
+ override fun allocationSize(value: ULong) = 8UL
1157
+
1158
+ override fun write(value: ULong, buf: ByteBuffer) {
1159
+ buf.putLong(value.toLong())
1160
+ }
1161
+ }
1162
+
1163
+ /**
1164
+ * @suppress
1165
+ */
1166
+ public object FfiConverterBoolean: FfiConverter<Boolean, Byte> {
1167
+ override fun lift(value: Byte): Boolean {
1168
+ return value.toInt() != 0
1169
+ }
1170
+
1171
+ override fun read(buf: ByteBuffer): Boolean {
1172
+ return lift(buf.get())
1173
+ }
1174
+
1175
+ override fun lower(value: Boolean): Byte {
1176
+ return if (value) 1.toByte() else 0.toByte()
1177
+ }
1178
+
1179
+ override fun allocationSize(value: Boolean) = 1UL
1180
+
1181
+ override fun write(value: Boolean, buf: ByteBuffer) {
1182
+ buf.put(lower(value))
1183
+ }
1184
+ }
1185
+
1186
+ /**
1187
+ * @suppress
1188
+ */
1189
+ public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
1190
+ // Note: we don't inherit from FfiConverterRustBuffer, because we use a
1191
+ // special encoding when lowering/lifting. We can use `RustBuffer.len` to
1192
+ // store our length and avoid writing it out to the buffer.
1193
+ override fun lift(value: RustBuffer.ByValue): String {
1194
+ try {
1195
+ val byteArr = ByteArray(value.len.toInt())
1196
+ value.asByteBuffer()!!.get(byteArr)
1197
+ return byteArr.toString(Charsets.UTF_8)
1198
+ } finally {
1199
+ RustBuffer.free(value)
1200
+ }
1201
+ }
1202
+
1203
+ override fun read(buf: ByteBuffer): String {
1204
+ val len = buf.getInt()
1205
+ val byteArr = ByteArray(len)
1206
+ buf.get(byteArr)
1207
+ return byteArr.toString(Charsets.UTF_8)
1208
+ }
1209
+
1210
+ fun toUtf8(value: String): ByteBuffer {
1211
+ // Make sure we don't have invalid UTF-16, check for lone surrogates.
1212
+ return Charsets.UTF_8.newEncoder().run {
1213
+ onMalformedInput(CodingErrorAction.REPORT)
1214
+ encode(CharBuffer.wrap(value))
1215
+ }
1216
+ }
1217
+
1218
+ override fun lower(value: String): RustBuffer.ByValue {
1219
+ val byteBuf = toUtf8(value)
1220
+ // Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us
1221
+ // to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`.
1222
+ val rbuf = RustBuffer.alloc(byteBuf.limit().toULong())
1223
+ rbuf.asByteBuffer()!!.put(byteBuf)
1224
+ return rbuf
1225
+ }
1226
+
1227
+ // We aren't sure exactly how many bytes our string will be once it's UTF-8
1228
+ // encoded. Allocate 3 bytes per UTF-16 code unit which will always be
1229
+ // enough.
1230
+ override fun allocationSize(value: String): ULong {
1231
+ val sizeForLength = 4UL
1232
+ val sizeForString = value.length.toULong() * 3UL
1233
+ return sizeForLength + sizeForString
1234
+ }
1235
+
1236
+ override fun write(value: String, buf: ByteBuffer) {
1237
+ val byteBuf = toUtf8(value)
1238
+ buf.putInt(byteBuf.limit())
1239
+ buf.put(byteBuf)
1240
+ }
1241
+ }
1242
+
1243
+ /**
1244
+ * @suppress
1245
+ */
1246
+ public object FfiConverterByteArray: FfiConverterRustBuffer<ByteArray> {
1247
+ override fun read(buf: ByteBuffer): ByteArray {
1248
+ val len = buf.getInt()
1249
+ val byteArr = ByteArray(len)
1250
+ buf.get(byteArr)
1251
+ return byteArr
1252
+ }
1253
+ override fun allocationSize(value: ByteArray): ULong {
1254
+ return 4UL + value.size.toULong()
1255
+ }
1256
+ override fun write(value: ByteArray, buf: ByteBuffer) {
1257
+ buf.putInt(value.size)
1258
+ buf.put(value)
1259
+ }
1260
+ }
1261
+
1262
+
1263
+ // This template implements a class for working with a Rust struct via a handle
1264
+ // to the live Rust struct on the other side of the FFI.
1265
+ //
1266
+ // There's some subtlety here, because we have to be careful not to operate on a Rust
1267
+ // struct after it has been dropped, and because we must expose a public API for freeing
1268
+ // theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
1269
+ //
1270
+ // * Each instance holds an opaque handle to the underlying Rust struct.
1271
+ // Method calls need to read this handle from the object's state and pass it in to
1272
+ // the Rust FFI.
1273
+ //
1274
+ // * When an instance is no longer needed, its handle should be passed to a
1275
+ // special destructor function provided by the Rust FFI, which will drop the
1276
+ // underlying Rust struct.
1277
+ //
1278
+ // * Given an instance, calling code is expected to call the special
1279
+ // `destroy` method in order to free it after use, either by calling it explicitly
1280
+ // or by using a higher-level helper like the `use` method. Failing to do so risks
1281
+ // leaking the underlying Rust struct.
1282
+ //
1283
+ // * We can't assume that calling code will do the right thing, and must be prepared
1284
+ // to handle Kotlin method calls executing concurrently with or even after a call to
1285
+ // `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
1286
+ //
1287
+ // * We must never allow Rust code to operate on the underlying Rust struct after
1288
+ // the destructor has been called, and must never call the destructor more than once.
1289
+ // Doing so may trigger memory unsafety.
1290
+ //
1291
+ // * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
1292
+ // is implemented to call the destructor when the Kotlin object becomes unreachable.
1293
+ // This is done in a background thread. This is not a panacea, and client code should be aware that
1294
+ // 1. the thread may starve if some there are objects that have poorly performing
1295
+ // `drop` methods or do significant work in their `drop` methods.
1296
+ // 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
1297
+ // or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
1298
+ //
1299
+ // If we try to implement this with mutual exclusion on access to the handle, there is the
1300
+ // possibility of a race between a method call and a concurrent call to `destroy`:
1301
+ //
1302
+ // * Thread A starts a method call, reads the value of the handle, but is interrupted
1303
+ // before it can pass the handle over the FFI to Rust.
1304
+ // * Thread B calls `destroy` and frees the underlying Rust struct.
1305
+ // * Thread A resumes, passing the already-read handle value to Rust and triggering
1306
+ // a use-after-free.
1307
+ //
1308
+ // One possible solution would be to use a `ReadWriteLock`, with each method call taking
1309
+ // a read lock (and thus allowed to run concurrently) and the special `destroy` method
1310
+ // taking a write lock (and thus blocking on live method calls). However, we aim not to
1311
+ // generate methods with any hidden blocking semantics, and a `destroy` method that might
1312
+ // block if called incorrectly seems to meet that bar.
1313
+ //
1314
+ // So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
1315
+ // the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
1316
+ // has been called. These are updated according to the following rules:
1317
+ //
1318
+ // * The initial value of the counter is 1, indicating a live object with no in-flight calls.
1319
+ // The initial value for the flag is false.
1320
+ //
1321
+ // * At the start of each method call, we atomically check the counter.
1322
+ // If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
1323
+ // If it is nonzero them we atomically increment it by 1 and proceed with the method call.
1324
+ //
1325
+ // * At the end of each method call, we atomically decrement and check the counter.
1326
+ // If it has reached zero then we destroy the underlying Rust struct.
1327
+ //
1328
+ // * When `destroy` is called, we atomically flip the flag from false to true.
1329
+ // If the flag was already true we silently fail.
1330
+ // Otherwise we atomically decrement and check the counter.
1331
+ // If it has reached zero then we destroy the underlying Rust struct.
1332
+ //
1333
+ // Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
1334
+ // and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
1335
+ //
1336
+ // The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
1337
+ // called *and* all in-flight method calls have completed, avoiding violating any of the expectations
1338
+ // of the underlying Rust code.
1339
+ //
1340
+ // This makes a cleaner a better alternative to _not_ calling `destroy()` as
1341
+ // and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
1342
+ // method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
1343
+ // thread may be starved, and the app will leak memory.
1344
+ //
1345
+ // In this case, `destroy`ing manually may be a better solution.
1346
+ //
1347
+ // The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
1348
+ // with Rust peers are reclaimed:
1349
+ //
1350
+ // 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
1351
+ // 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
1352
+ // 3. The memory is reclaimed when the process terminates.
1353
+ //
1354
+ // [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
1355
+ //
1356
+
1357
+
1358
+ /**
1359
+ * One account, `m/35263'/network'/0'`, behind an opaque handle.
1360
+ *
1361
+ * The handle is the only thing that ever holds key material: every
1362
+ * spending key is derived inside a call and dropped before it returns. It
1363
+ * is safe to share across threads. Calls that read or advance the counter
1364
+ * are serialized; [`Wallet::build_transfer`] works on a copy and holds no
1365
+ * lock while it proves.
1366
+ */
1367
+ public interface WalletInterface {
1368
+
1369
+ /**
1370
+ * The address and predicate at `path`, without issuing anything.
1371
+ */
1372
+ fun `address`(`path`: KeyPath): IssuedAddress
1373
+
1374
+ /**
1375
+ * Builds, proves and signs a transfer. The keys come from the paths
1376
+ * the inputs name and never leave this call.
1377
+ *
1378
+ * Proving takes seconds on a phone, so it runs on a copy of the
1379
+ * account with the lock released: other calls on this handle, from a
1380
+ * UI thread say, do not wait for it. The build never touches the
1381
+ * counter, so nothing the copy does needs writing back.
1382
+ */
1383
+ fun `buildTransfer`(`request`: TransferRequest): Transfer
1384
+
1385
+ /**
1386
+ * The network this wallet's addresses are encoded for.
1387
+ */
1388
+ fun `network`(): Network
1389
+
1390
+ /**
1391
+ * Issues the next receiving address and advances the counter.
1392
+ */
1393
+ fun `nextAddress`(): IssuedAddress
1394
+
1395
+ /**
1396
+ * The next receiving index not yet issued.
1397
+ */
1398
+ fun `nextIndex`(): kotlin.UInt
1399
+
1400
+ /**
1401
+ * Opens the note that followed `contract` in its log, as a scan serves
1402
+ * the pair; `note` is `None` when the scan served none. `path` is what
1403
+ * [`Wallet::owns`] found for the contract's predicate. The opening it
1404
+ * gives is what a later [`crate::TransferInput`] spends the output with.
1405
+ */
1406
+ fun `openNote`(`contract`: kotlin.ByteArray, `note`: kotlin.ByteArray?, `path`: KeyPath): ReceivedNote
1407
+
1408
+ /**
1409
+ * Which path below `next_index + gap`, on either branch, owns
1410
+ * `predicate`; `None` if none does. The scan re-derives every address
1411
+ * it covers, so `gap` is the caller's cost budget.
1412
+ */
1413
+ fun `owns`(`predicate`: kotlin.ByteArray, `gap`: kotlin.UInt): KeyPath?
1414
+
1415
+ /**
1416
+ * The account's receiving key in bech32f (`recv1…` / `testrecv1…`):
1417
+ * what an indexer is given to find this wallet's payments. It derives
1418
+ * every address and links their activity, and can neither spend nor
1419
+ * read a payment's amount.
1420
+ */
1421
+ fun `receivingKey`(): kotlin.String
1422
+
1423
+ companion object
1424
+ }
1425
+
1426
+ /**
1427
+ * One account, `m/35263'/network'/0'`, behind an opaque handle.
1428
+ *
1429
+ * The handle is the only thing that ever holds key material: every
1430
+ * spending key is derived inside a call and dropped before it returns. It
1431
+ * is safe to share across threads. Calls that read or advance the counter
1432
+ * are serialized; [`Wallet::build_transfer`] works on a copy and holds no
1433
+ * lock while it proves.
1434
+ */
1435
+ open class Wallet: Disposable, AutoCloseable, WalletInterface
1436
+ {
1437
+
1438
+ @Suppress("UNUSED_PARAMETER")
1439
+ /**
1440
+ * @suppress
1441
+ */
1442
+ constructor(withHandle: UniffiWithHandle, handle: Long) {
1443
+ this.handle = handle
1444
+ this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
1445
+ }
1446
+
1447
+ /**
1448
+ * @suppress
1449
+ *
1450
+ * This constructor can be used to instantiate a fake object. Only used for tests. Any
1451
+ * attempt to actually use an object constructed this way will fail as there is no
1452
+ * connected Rust object.
1453
+ */
1454
+ @Suppress("UNUSED_PARAMETER")
1455
+ constructor(noHandle: NoHandle) {
1456
+ this.handle = 0
1457
+ this.cleanable = null
1458
+ }
1459
+ /**
1460
+ * The account below a 64-byte seed, as [`mnemonic_to_seed`] gives it,
1461
+ * with `next_index` receiving addresses already issued. The seed holds
1462
+ * keys, not history: an app stores [`Wallet::next_index`] after each
1463
+ * [`Wallet::next_address`] and passes it back here; a new wallet
1464
+ * passes 0.
1465
+ */
1466
+ constructor(`seed`: kotlin.ByteArray, `network`: Network, `nextIndex`: kotlin.UInt) :
1467
+ this(UniffiWithHandle,
1468
+ uniffiRustCallWithError(FlameException) { _status ->
1469
+ UniffiLib.uniffi_flamewallet_ffi_fn_constructor_wallet_new(
1470
+
1471
+
1472
+ FfiConverterByteArray.lower(`seed`),
1473
+ FfiConverterTypeNetwork.lower(`network`),
1474
+ FfiConverterUInt.lower(`nextIndex`),_status)
1475
+ }
1476
+ )
1477
+
1478
+ protected val handle: Long
1479
+ protected val cleanable: UniffiCleaner.Cleanable?
1480
+
1481
+ private val wasDestroyed = AtomicBoolean(false)
1482
+ private val callCounter = AtomicLong(1)
1483
+
1484
+ /**
1485
+ * Whether the current object has been destroyed and its reference is gone in the Rust side.
1486
+ */
1487
+ val uniffiIsDestroyed: Boolean get() = wasDestroyed.get()
1488
+
1489
+ override fun destroy() {
1490
+ // Only allow a single call to this method.
1491
+ // TODO: maybe we should log a warning if called more than once?
1492
+ if (this.wasDestroyed.compareAndSet(false, true)) {
1493
+ // This decrement always matches the initial count of 1 given at creation time.
1494
+ if (this.callCounter.decrementAndGet() == 0L) {
1495
+ cleanable?.clean()
1496
+ }
1497
+ }
1498
+ }
1499
+
1500
+ @Synchronized
1501
+ override fun close() {
1502
+ this.destroy()
1503
+ }
1504
+
1505
+ internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
1506
+ // Check and increment the call counter, to keep the object alive.
1507
+ // This needs a compare-and-set retry loop in case of concurrent updates.
1508
+ do {
1509
+ val c = this.callCounter.get()
1510
+ if (c == 0L) {
1511
+ throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
1512
+ }
1513
+ if (c == Long.MAX_VALUE) {
1514
+ throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
1515
+ }
1516
+ } while (! this.callCounter.compareAndSet(c, c + 1L))
1517
+ // Now we can safely do the method call without the handle being freed concurrently.
1518
+ try {
1519
+ return block(this.uniffiCloneHandle())
1520
+ } finally {
1521
+ // This decrement always matches the increment we performed above.
1522
+ if (this.callCounter.decrementAndGet() == 0L) {
1523
+ cleanable?.clean()
1524
+ }
1525
+ }
1526
+ }
1527
+
1528
+ // Use a static inner class instead of a closure so as not to accidentally
1529
+ // capture `this` as part of the cleanable's action.
1530
+ private class UniffiCleanAction(private val handle: Long) : Runnable {
1531
+ override fun run() {
1532
+ if (handle == 0.toLong()) {
1533
+ // Fake object created with `NoHandle`, don't try to free.
1534
+ return;
1535
+ }
1536
+ uniffiRustCall { status ->
1537
+ UniffiLib.uniffi_flamewallet_ffi_fn_free_wallet(handle, status)
1538
+ }
1539
+ }
1540
+ }
1541
+
1542
+ /**
1543
+ * @suppress
1544
+ */
1545
+ fun uniffiCloneHandle(): Long {
1546
+ if (handle == 0.toLong()) {
1547
+ throw InternalException("uniffiCloneHandle() called on NoHandle object");
1548
+ }
1549
+ return uniffiRustCall() { status ->
1550
+ UniffiLib.uniffi_flamewallet_ffi_fn_clone_wallet(handle, status)
1551
+ }
1552
+ }
1553
+
1554
+
1555
+ /**
1556
+ * The address and predicate at `path`, without issuing anything.
1557
+ */
1558
+ @Throws(FlameException::class)override fun `address`(`path`: KeyPath): IssuedAddress {
1559
+ return FfiConverterTypeIssuedAddress.lift(
1560
+ callWithHandle {
1561
+ uniffiRustCallWithError(FlameException) { _status ->
1562
+ UniffiLib.uniffi_flamewallet_ffi_fn_method_wallet_address(
1563
+ it,
1564
+
1565
+ FfiConverterTypeKeyPath.lower(`path`),_status)
1566
+ }
1567
+ }
1568
+ )
1569
+ }
1570
+
1571
+
1572
+
1573
+ /**
1574
+ * Builds, proves and signs a transfer. The keys come from the paths
1575
+ * the inputs name and never leave this call.
1576
+ *
1577
+ * Proving takes seconds on a phone, so it runs on a copy of the
1578
+ * account with the lock released: other calls on this handle, from a
1579
+ * UI thread say, do not wait for it. The build never touches the
1580
+ * counter, so nothing the copy does needs writing back.
1581
+ */
1582
+ @Throws(FlameException::class)override fun `buildTransfer`(`request`: TransferRequest): Transfer {
1583
+ return FfiConverterTypeTransfer.lift(
1584
+ callWithHandle {
1585
+ uniffiRustCallWithError(FlameException) { _status ->
1586
+ UniffiLib.uniffi_flamewallet_ffi_fn_method_wallet_build_transfer(
1587
+ it,
1588
+
1589
+ FfiConverterTypeTransferRequest.lower(`request`),_status)
1590
+ }
1591
+ }
1592
+ )
1593
+ }
1594
+
1595
+
1596
+
1597
+ /**
1598
+ * The network this wallet's addresses are encoded for.
1599
+ */override fun `network`(): Network {
1600
+ return FfiConverterTypeNetwork.lift(
1601
+ callWithHandle {
1602
+ uniffiRustCall() { _status ->
1603
+ UniffiLib.uniffi_flamewallet_ffi_fn_method_wallet_network(
1604
+ it,
1605
+ _status)
1606
+ }
1607
+ }
1608
+ )
1609
+ }
1610
+
1611
+
1612
+
1613
+ /**
1614
+ * Issues the next receiving address and advances the counter.
1615
+ */
1616
+ @Throws(FlameException::class)override fun `nextAddress`(): IssuedAddress {
1617
+ return FfiConverterTypeIssuedAddress.lift(
1618
+ callWithHandle {
1619
+ uniffiRustCallWithError(FlameException) { _status ->
1620
+ UniffiLib.uniffi_flamewallet_ffi_fn_method_wallet_next_address(
1621
+ it,
1622
+ _status)
1623
+ }
1624
+ }
1625
+ )
1626
+ }
1627
+
1628
+
1629
+
1630
+ /**
1631
+ * The next receiving index not yet issued.
1632
+ */override fun `nextIndex`(): kotlin.UInt {
1633
+ return FfiConverterUInt.lift(
1634
+ callWithHandle {
1635
+ uniffiRustCall() { _status ->
1636
+ UniffiLib.uniffi_flamewallet_ffi_fn_method_wallet_next_index(
1637
+ it,
1638
+ _status)
1639
+ }
1640
+ }
1641
+ )
1642
+ }
1643
+
1644
+
1645
+
1646
+ /**
1647
+ * Opens the note that followed `contract` in its log, as a scan serves
1648
+ * the pair; `note` is `None` when the scan served none. `path` is what
1649
+ * [`Wallet::owns`] found for the contract's predicate. The opening it
1650
+ * gives is what a later [`crate::TransferInput`] spends the output with.
1651
+ */
1652
+ @Throws(FlameException::class)override fun `openNote`(`contract`: kotlin.ByteArray, `note`: kotlin.ByteArray?, `path`: KeyPath): ReceivedNote {
1653
+ return FfiConverterTypeReceivedNote.lift(
1654
+ callWithHandle {
1655
+ uniffiRustCallWithError(FlameException) { _status ->
1656
+ UniffiLib.uniffi_flamewallet_ffi_fn_method_wallet_open_note(
1657
+ it,
1658
+
1659
+ FfiConverterByteArray.lower(`contract`),
1660
+ FfiConverterOptionalByteArray.lower(`note`),
1661
+ FfiConverterTypeKeyPath.lower(`path`),_status)
1662
+ }
1663
+ }
1664
+ )
1665
+ }
1666
+
1667
+
1668
+
1669
+ /**
1670
+ * Which path below `next_index + gap`, on either branch, owns
1671
+ * `predicate`; `None` if none does. The scan re-derives every address
1672
+ * it covers, so `gap` is the caller's cost budget.
1673
+ */
1674
+ @Throws(FlameException::class)override fun `owns`(`predicate`: kotlin.ByteArray, `gap`: kotlin.UInt): KeyPath? {
1675
+ return FfiConverterOptionalTypeKeyPath.lift(
1676
+ callWithHandle {
1677
+ uniffiRustCallWithError(FlameException) { _status ->
1678
+ UniffiLib.uniffi_flamewallet_ffi_fn_method_wallet_owns(
1679
+ it,
1680
+
1681
+ FfiConverterByteArray.lower(`predicate`),
1682
+ FfiConverterUInt.lower(`gap`),_status)
1683
+ }
1684
+ }
1685
+ )
1686
+ }
1687
+
1688
+
1689
+
1690
+ /**
1691
+ * The account's receiving key in bech32f (`recv1…` / `testrecv1…`):
1692
+ * what an indexer is given to find this wallet's payments. It derives
1693
+ * every address and links their activity, and can neither spend nor
1694
+ * read a payment's amount.
1695
+ */override fun `receivingKey`(): kotlin.String {
1696
+ return FfiConverterString.lift(
1697
+ callWithHandle {
1698
+ uniffiRustCall() { _status ->
1699
+ UniffiLib.uniffi_flamewallet_ffi_fn_method_wallet_receiving_key(
1700
+ it,
1701
+ _status)
1702
+ }
1703
+ }
1704
+ )
1705
+ }
1706
+
1707
+
1708
+
1709
+
1710
+
1711
+
1712
+
1713
+
1714
+ companion object {
1715
+
1716
+ /**
1717
+ * The account below `phrase` and `passphrase`, without the caller ever
1718
+ * seeing the seed; `next_index` as in [`Wallet::new`].
1719
+ */
1720
+ @Throws(FlameException::class) fun `fromMnemonic`(`phrase`: kotlin.String, `passphrase`: kotlin.String, `network`: Network, `nextIndex`: kotlin.UInt): Wallet {
1721
+ return FfiConverterTypeWallet.lift(
1722
+ uniffiRustCallWithError(FlameException) { _status ->
1723
+ UniffiLib.uniffi_flamewallet_ffi_fn_constructor_wallet_from_mnemonic(
1724
+
1725
+
1726
+ FfiConverterString.lower(`phrase`),
1727
+ FfiConverterString.lower(`passphrase`),
1728
+ FfiConverterTypeNetwork.lower(`network`),
1729
+ FfiConverterUInt.lower(`nextIndex`),_status)
1730
+ }
1731
+ )
1732
+ }
1733
+
1734
+
1735
+
1736
+ }
1737
+
1738
+ }
1739
+
1740
+
1741
+ /**
1742
+ * @suppress
1743
+ */
1744
+ public object FfiConverterTypeWallet: FfiConverter<Wallet, Long> {
1745
+ override fun lower(value: Wallet): Long {
1746
+ return value.uniffiCloneHandle()
1747
+ }
1748
+
1749
+ override fun lift(value: Long): Wallet {
1750
+ return Wallet(UniffiWithHandle, value)
1751
+ }
1752
+
1753
+ override fun read(buf: ByteBuffer): Wallet {
1754
+ return lift(buf.getLong())
1755
+ }
1756
+
1757
+ override fun allocationSize(value: Wallet) = 8UL
1758
+
1759
+ override fun write(value: Wallet, buf: ByteBuffer) {
1760
+ buf.putLong(lower(value))
1761
+ }
1762
+ }
1763
+
1764
+
1765
+
1766
+ /**
1767
+ * A published contract, as much of it as a wallet reads.
1768
+ */
1769
+ data class ContractInfo (
1770
+ /**
1771
+ * The 32-byte contract id.
1772
+ */
1773
+ var `id`: kotlin.ByteArray
1774
+ ,
1775
+ /**
1776
+ * The 32-byte compressed point it is locked with: what
1777
+ * [`crate::Wallet::owns`] is asked about.
1778
+ */
1779
+ var `predicate`: kotlin.ByteArray
1780
+ ,
1781
+ var `value`: ContractValue
1782
+
1783
+ ){
1784
+
1785
+
1786
+
1787
+
1788
+
1789
+ companion object
1790
+ }
1791
+
1792
+ /**
1793
+ * @suppress
1794
+ */
1795
+ public object FfiConverterTypeContractInfo: FfiConverterRustBuffer<ContractInfo> {
1796
+ override fun read(buf: ByteBuffer): ContractInfo {
1797
+ return ContractInfo(
1798
+ FfiConverterByteArray.read(buf),
1799
+ FfiConverterByteArray.read(buf),
1800
+ FfiConverterTypeContractValue.read(buf),
1801
+ )
1802
+ }
1803
+
1804
+ override fun allocationSize(value: ContractInfo) = (
1805
+ FfiConverterByteArray.allocationSize(value.`id`) +
1806
+ FfiConverterByteArray.allocationSize(value.`predicate`) +
1807
+ FfiConverterTypeContractValue.allocationSize(value.`value`)
1808
+ )
1809
+
1810
+ override fun write(value: ContractInfo, buf: ByteBuffer) {
1811
+ FfiConverterByteArray.write(value.`id`, buf)
1812
+ FfiConverterByteArray.write(value.`predicate`, buf)
1813
+ FfiConverterTypeContractValue.write(value.`value`, buf)
1814
+ }
1815
+ }
1816
+
1817
+
1818
+
1819
+ /**
1820
+ * One contract the transfer creates.
1821
+ */
1822
+ data class CreatedOutput (
1823
+ var `contractId`: kotlin.ByteArray
1824
+ ,
1825
+ /**
1826
+ * Its published bytes, as an indexer will serve them once confirmed.
1827
+ */
1828
+ var `contract`: kotlin.ByteArray
1829
+ ,
1830
+ /**
1831
+ * The encrypted note that follows it on chain, as an indexer's scan
1832
+ * serves it. Its recipient opens it with [`crate::Wallet::open_note`];
1833
+ * so does this wallet, for its change.
1834
+ */
1835
+ var `note`: kotlin.ByteArray
1836
+
1837
+ ){
1838
+
1839
+
1840
+
1841
+
1842
+
1843
+ companion object
1844
+ }
1845
+
1846
+ /**
1847
+ * @suppress
1848
+ */
1849
+ public object FfiConverterTypeCreatedOutput: FfiConverterRustBuffer<CreatedOutput> {
1850
+ override fun read(buf: ByteBuffer): CreatedOutput {
1851
+ return CreatedOutput(
1852
+ FfiConverterByteArray.read(buf),
1853
+ FfiConverterByteArray.read(buf),
1854
+ FfiConverterByteArray.read(buf),
1855
+ )
1856
+ }
1857
+
1858
+ override fun allocationSize(value: CreatedOutput) = (
1859
+ FfiConverterByteArray.allocationSize(value.`contractId`) +
1860
+ FfiConverterByteArray.allocationSize(value.`contract`) +
1861
+ FfiConverterByteArray.allocationSize(value.`note`)
1862
+ )
1863
+
1864
+ override fun write(value: CreatedOutput, buf: ByteBuffer) {
1865
+ FfiConverterByteArray.write(value.`contractId`, buf)
1866
+ FfiConverterByteArray.write(value.`contract`, buf)
1867
+ FfiConverterByteArray.write(value.`note`, buf)
1868
+ }
1869
+ }
1870
+
1871
+
1872
+
1873
+ /**
1874
+ * An address the wallet has handed out, with the predicate an indexer is
1875
+ * asked about.
1876
+ */
1877
+ data class IssuedAddress (
1878
+ var `path`: KeyPath
1879
+ ,
1880
+ /**
1881
+ * bech32f: `f1…` on mainnet, `tf1…` on testnet.
1882
+ */
1883
+ var `address`: kotlin.String
1884
+ ,
1885
+ /**
1886
+ * The 32-byte compressed point that locks payments to this address.
1887
+ */
1888
+ var `predicate`: kotlin.ByteArray
1889
+
1890
+ ){
1891
+
1892
+
1893
+
1894
+
1895
+
1896
+ companion object
1897
+ }
1898
+
1899
+ /**
1900
+ * @suppress
1901
+ */
1902
+ public object FfiConverterTypeIssuedAddress: FfiConverterRustBuffer<IssuedAddress> {
1903
+ override fun read(buf: ByteBuffer): IssuedAddress {
1904
+ return IssuedAddress(
1905
+ FfiConverterTypeKeyPath.read(buf),
1906
+ FfiConverterString.read(buf),
1907
+ FfiConverterByteArray.read(buf),
1908
+ )
1909
+ }
1910
+
1911
+ override fun allocationSize(value: IssuedAddress) = (
1912
+ FfiConverterTypeKeyPath.allocationSize(value.`path`) +
1913
+ FfiConverterString.allocationSize(value.`address`) +
1914
+ FfiConverterByteArray.allocationSize(value.`predicate`)
1915
+ )
1916
+
1917
+ override fun write(value: IssuedAddress, buf: ByteBuffer) {
1918
+ FfiConverterTypeKeyPath.write(value.`path`, buf)
1919
+ FfiConverterString.write(value.`address`, buf)
1920
+ FfiConverterByteArray.write(value.`predicate`, buf)
1921
+ }
1922
+ }
1923
+
1924
+
1925
+
1926
+ /**
1927
+ * A position below the account: `m/35263'/network'/0'/branch/index`.
1928
+ * `branch` is `0` for receiving and `1` for change.
1929
+ */
1930
+ data class KeyPath (
1931
+ var `branch`: kotlin.UInt
1932
+ ,
1933
+ var `index`: kotlin.UInt
1934
+
1935
+ ){
1936
+
1937
+
1938
+
1939
+
1940
+
1941
+ companion object
1942
+ }
1943
+
1944
+ /**
1945
+ * @suppress
1946
+ */
1947
+ public object FfiConverterTypeKeyPath: FfiConverterRustBuffer<KeyPath> {
1948
+ override fun read(buf: ByteBuffer): KeyPath {
1949
+ return KeyPath(
1950
+ FfiConverterUInt.read(buf),
1951
+ FfiConverterUInt.read(buf),
1952
+ )
1953
+ }
1954
+
1955
+ override fun allocationSize(value: KeyPath) = (
1956
+ FfiConverterUInt.allocationSize(value.`branch`) +
1957
+ FfiConverterUInt.allocationSize(value.`index`)
1958
+ )
1959
+
1960
+ override fun write(value: KeyPath, buf: ByteBuffer) {
1961
+ FfiConverterUInt.write(value.`branch`, buf)
1962
+ FfiConverterUInt.write(value.`index`, buf)
1963
+ }
1964
+ }
1965
+
1966
+
1967
+
1968
+ /**
1969
+ * The secret behind a confidential output: what its recipient needs in
1970
+ * order to spend it. Scalars are 32 canonical little-endian bytes.
1971
+ */
1972
+ data class Opening (
1973
+ var `qty`: kotlin.ULong
1974
+ ,
1975
+ var `flavor`: kotlin.ByteArray
1976
+ ,
1977
+ var `qtyBlinding`: kotlin.ByteArray
1978
+ ,
1979
+ var `flavorBlinding`: kotlin.ByteArray
1980
+
1981
+ ){
1982
+
1983
+
1984
+
1985
+
1986
+
1987
+ companion object
1988
+ }
1989
+
1990
+ /**
1991
+ * @suppress
1992
+ */
1993
+ public object FfiConverterTypeOpening: FfiConverterRustBuffer<Opening> {
1994
+ override fun read(buf: ByteBuffer): Opening {
1995
+ return Opening(
1996
+ FfiConverterULong.read(buf),
1997
+ FfiConverterByteArray.read(buf),
1998
+ FfiConverterByteArray.read(buf),
1999
+ FfiConverterByteArray.read(buf),
2000
+ )
2001
+ }
2002
+
2003
+ override fun allocationSize(value: Opening) = (
2004
+ FfiConverterULong.allocationSize(value.`qty`) +
2005
+ FfiConverterByteArray.allocationSize(value.`flavor`) +
2006
+ FfiConverterByteArray.allocationSize(value.`qtyBlinding`) +
2007
+ FfiConverterByteArray.allocationSize(value.`flavorBlinding`)
2008
+ )
2009
+
2010
+ override fun write(value: Opening, buf: ByteBuffer) {
2011
+ FfiConverterULong.write(value.`qty`, buf)
2012
+ FfiConverterByteArray.write(value.`flavor`, buf)
2013
+ FfiConverterByteArray.write(value.`qtyBlinding`, buf)
2014
+ FfiConverterByteArray.write(value.`flavorBlinding`, buf)
2015
+ }
2016
+ }
2017
+
2018
+
2019
+
2020
+ /**
2021
+ * What an opened note gives its recipient.
2022
+ */
2023
+ data class ReceivedNote (
2024
+ /**
2025
+ * What a [`crate::TransferInput`] spends the output with.
2026
+ */
2027
+ var `opening`: Opening
2028
+ ,
2029
+ /**
2030
+ * The memo, as the sender wrote it.
2031
+ */
2032
+ var `memo`: kotlin.ByteArray
2033
+
2034
+ ){
2035
+
2036
+
2037
+
2038
+
2039
+
2040
+ companion object
2041
+ }
2042
+
2043
+ /**
2044
+ * @suppress
2045
+ */
2046
+ public object FfiConverterTypeReceivedNote: FfiConverterRustBuffer<ReceivedNote> {
2047
+ override fun read(buf: ByteBuffer): ReceivedNote {
2048
+ return ReceivedNote(
2049
+ FfiConverterTypeOpening.read(buf),
2050
+ FfiConverterByteArray.read(buf),
2051
+ )
2052
+ }
2053
+
2054
+ override fun allocationSize(value: ReceivedNote) = (
2055
+ FfiConverterTypeOpening.allocationSize(value.`opening`) +
2056
+ FfiConverterByteArray.allocationSize(value.`memo`)
2057
+ )
2058
+
2059
+ override fun write(value: ReceivedNote, buf: ByteBuffer) {
2060
+ FfiConverterTypeOpening.write(value.`opening`, buf)
2061
+ FfiConverterByteArray.write(value.`memo`, buf)
2062
+ }
2063
+ }
2064
+
2065
+
2066
+
2067
+ /**
2068
+ * A signed transfer, ready to publish.
2069
+ */
2070
+ data class Transfer (
2071
+ /**
2072
+ * The 32-byte transaction id.
2073
+ */
2074
+ var `txid`: kotlin.ByteArray
2075
+ ,
2076
+ /**
2077
+ * `BlockTx::to_bytes`: what a node's `submit_tx` takes.
2078
+ */
2079
+ var `blockTx`: kotlin.ByteArray
2080
+ ,
2081
+ /**
2082
+ * In the order they are published, which is not request order: the
2083
+ * builder sorts them so that position says nothing about which one is
2084
+ * the change. Match one to its request by its predicate.
2085
+ */
2086
+ var `outputs`: List<CreatedOutput>
2087
+
2088
+ ){
2089
+
2090
+
2091
+
2092
+
2093
+
2094
+ companion object
2095
+ }
2096
+
2097
+ /**
2098
+ * @suppress
2099
+ */
2100
+ public object FfiConverterTypeTransfer: FfiConverterRustBuffer<Transfer> {
2101
+ override fun read(buf: ByteBuffer): Transfer {
2102
+ return Transfer(
2103
+ FfiConverterByteArray.read(buf),
2104
+ FfiConverterByteArray.read(buf),
2105
+ FfiConverterSequenceTypeCreatedOutput.read(buf),
2106
+ )
2107
+ }
2108
+
2109
+ override fun allocationSize(value: Transfer) = (
2110
+ FfiConverterByteArray.allocationSize(value.`txid`) +
2111
+ FfiConverterByteArray.allocationSize(value.`blockTx`) +
2112
+ FfiConverterSequenceTypeCreatedOutput.allocationSize(value.`outputs`)
2113
+ )
2114
+
2115
+ override fun write(value: Transfer, buf: ByteBuffer) {
2116
+ FfiConverterByteArray.write(value.`txid`, buf)
2117
+ FfiConverterByteArray.write(value.`blockTx`, buf)
2118
+ FfiConverterSequenceTypeCreatedOutput.write(value.`outputs`, buf)
2119
+ }
2120
+ }
2121
+
2122
+
2123
+
2124
+ /**
2125
+ * One contract being spent, exactly as the indexer served it.
2126
+ */
2127
+ data class TransferInput (
2128
+ /**
2129
+ * The contract's published bytes.
2130
+ */
2131
+ var `contract`: kotlin.ByteArray
2132
+ ,
2133
+ /**
2134
+ * Its Utreexo membership proof, valid at the tip the transfer targets.
2135
+ */
2136
+ var `proof`: kotlin.ByteArray
2137
+ ,
2138
+ /**
2139
+ * The path of the key it is locked to.
2140
+ */
2141
+ var `path`: KeyPath
2142
+ ,
2143
+ /**
2144
+ * Required for a confidential contract, refused for a cleartext one.
2145
+ */
2146
+ var `opening`: Opening?
2147
+
2148
+ ){
2149
+
2150
+
2151
+
2152
+
2153
+
2154
+ companion object
2155
+ }
2156
+
2157
+ /**
2158
+ * @suppress
2159
+ */
2160
+ public object FfiConverterTypeTransferInput: FfiConverterRustBuffer<TransferInput> {
2161
+ override fun read(buf: ByteBuffer): TransferInput {
2162
+ return TransferInput(
2163
+ FfiConverterByteArray.read(buf),
2164
+ FfiConverterByteArray.read(buf),
2165
+ FfiConverterTypeKeyPath.read(buf),
2166
+ FfiConverterOptionalTypeOpening.read(buf),
2167
+ )
2168
+ }
2169
+
2170
+ override fun allocationSize(value: TransferInput) = (
2171
+ FfiConverterByteArray.allocationSize(value.`contract`) +
2172
+ FfiConverterByteArray.allocationSize(value.`proof`) +
2173
+ FfiConverterTypeKeyPath.allocationSize(value.`path`) +
2174
+ FfiConverterOptionalTypeOpening.allocationSize(value.`opening`)
2175
+ )
2176
+
2177
+ override fun write(value: TransferInput, buf: ByteBuffer) {
2178
+ FfiConverterByteArray.write(value.`contract`, buf)
2179
+ FfiConverterByteArray.write(value.`proof`, buf)
2180
+ FfiConverterTypeKeyPath.write(value.`path`, buf)
2181
+ FfiConverterOptionalTypeOpening.write(value.`opening`, buf)
2182
+ }
2183
+ }
2184
+
2185
+
2186
+
2187
+ /**
2188
+ * One contract being created.
2189
+ */
2190
+ data class TransferOutput (
2191
+ /**
2192
+ * The recipient's bech32f address, for the wallet's network; for
2193
+ * change, [`crate::Wallet::address`] on the change branch.
2194
+ */
2195
+ var `address`: kotlin.String
2196
+ ,
2197
+ var `qty`: kotlin.ULong
2198
+ ,
2199
+ /**
2200
+ * `None` for flames.
2201
+ */
2202
+ var `flavor`: kotlin.ByteArray?
2203
+ ,
2204
+ /**
2205
+ * Sealed into the output's note with the amount; only the recipient
2206
+ * reads it. At most 8102 bytes; empty for none.
2207
+ */
2208
+ var `memo`: kotlin.ByteArray
2209
+
2210
+ ){
2211
+
2212
+
2213
+
2214
+
2215
+
2216
+ companion object
2217
+ }
2218
+
2219
+ /**
2220
+ * @suppress
2221
+ */
2222
+ public object FfiConverterTypeTransferOutput: FfiConverterRustBuffer<TransferOutput> {
2223
+ override fun read(buf: ByteBuffer): TransferOutput {
2224
+ return TransferOutput(
2225
+ FfiConverterString.read(buf),
2226
+ FfiConverterULong.read(buf),
2227
+ FfiConverterOptionalByteArray.read(buf),
2228
+ FfiConverterByteArray.read(buf),
2229
+ )
2230
+ }
2231
+
2232
+ override fun allocationSize(value: TransferOutput) = (
2233
+ FfiConverterString.allocationSize(value.`address`) +
2234
+ FfiConverterULong.allocationSize(value.`qty`) +
2235
+ FfiConverterOptionalByteArray.allocationSize(value.`flavor`) +
2236
+ FfiConverterByteArray.allocationSize(value.`memo`)
2237
+ )
2238
+
2239
+ override fun write(value: TransferOutput, buf: ByteBuffer) {
2240
+ FfiConverterString.write(value.`address`, buf)
2241
+ FfiConverterULong.write(value.`qty`, buf)
2242
+ FfiConverterOptionalByteArray.write(value.`flavor`, buf)
2243
+ FfiConverterByteArray.write(value.`memo`, buf)
2244
+ }
2245
+ }
2246
+
2247
+
2248
+
2249
+ data class TransferRequest (
2250
+ var `inputs`: List<TransferInput>
2251
+ ,
2252
+ var `outputs`: List<TransferOutput>
2253
+ ,
2254
+ /**
2255
+ * In sparks. Inputs must equal outputs plus fee, per flavor.
2256
+ */
2257
+ var `fee`: kotlin.ULong
2258
+ ,
2259
+ /**
2260
+ * The gas budget; the node refuses more than its block limit allows.
2261
+ */
2262
+ var `gas`: kotlin.ULong
2263
+ ,
2264
+ /**
2265
+ * `0` for none; otherwise as in Bitcoin.
2266
+ */
2267
+ var `locktime`: kotlin.UInt
2268
+
2269
+ ){
2270
+
2271
+
2272
+
2273
+
2274
+
2275
+ companion object
2276
+ }
2277
+
2278
+ /**
2279
+ * @suppress
2280
+ */
2281
+ public object FfiConverterTypeTransferRequest: FfiConverterRustBuffer<TransferRequest> {
2282
+ override fun read(buf: ByteBuffer): TransferRequest {
2283
+ return TransferRequest(
2284
+ FfiConverterSequenceTypeTransferInput.read(buf),
2285
+ FfiConverterSequenceTypeTransferOutput.read(buf),
2286
+ FfiConverterULong.read(buf),
2287
+ FfiConverterULong.read(buf),
2288
+ FfiConverterUInt.read(buf),
2289
+ )
2290
+ }
2291
+
2292
+ override fun allocationSize(value: TransferRequest) = (
2293
+ FfiConverterSequenceTypeTransferInput.allocationSize(value.`inputs`) +
2294
+ FfiConverterSequenceTypeTransferOutput.allocationSize(value.`outputs`) +
2295
+ FfiConverterULong.allocationSize(value.`fee`) +
2296
+ FfiConverterULong.allocationSize(value.`gas`) +
2297
+ FfiConverterUInt.allocationSize(value.`locktime`)
2298
+ )
2299
+
2300
+ override fun write(value: TransferRequest, buf: ByteBuffer) {
2301
+ FfiConverterSequenceTypeTransferInput.write(value.`inputs`, buf)
2302
+ FfiConverterSequenceTypeTransferOutput.write(value.`outputs`, buf)
2303
+ FfiConverterULong.write(value.`fee`, buf)
2304
+ FfiConverterULong.write(value.`gas`, buf)
2305
+ FfiConverterUInt.write(value.`locktime`, buf)
2306
+ }
2307
+ }
2308
+
2309
+
2310
+
2311
+ /**
2312
+ * What a contract holds.
2313
+ */
2314
+ sealed class ContractValue {
2315
+
2316
+ /**
2317
+ * A cleartext token: the amount is public. A devnet genesis allocation
2318
+ * is one.
2319
+ */
2320
+ data class Clear(
2321
+ val `qty`: kotlin.ULong,
2322
+ val `flavor`: kotlin.ByteArray) : ContractValue()
2323
+
2324
+ {
2325
+
2326
+
2327
+ companion object
2328
+ }
2329
+
2330
+ /**
2331
+ * A confidential token: the amount is readable only with its opening.
2332
+ */
2333
+ object Confidential : ContractValue()
2334
+
2335
+
2336
+ /**
2337
+ * Anything that is not a bare token; no transfer spends it.
2338
+ */
2339
+ object Other : ContractValue()
2340
+
2341
+
2342
+
2343
+
2344
+
2345
+
2346
+
2347
+
2348
+
2349
+ companion object
2350
+ }
2351
+
2352
+ /**
2353
+ * @suppress
2354
+ */
2355
+ public object FfiConverterTypeContractValue : FfiConverterRustBuffer<ContractValue>{
2356
+ override fun read(buf: ByteBuffer): ContractValue {
2357
+ return when(buf.getInt()) {
2358
+ 1 -> ContractValue.Clear(
2359
+ FfiConverterULong.read(buf),
2360
+ FfiConverterByteArray.read(buf),
2361
+ )
2362
+ 2 -> ContractValue.Confidential
2363
+ 3 -> ContractValue.Other
2364
+ else -> throw RuntimeException("invalid enum value, something is very wrong!!")
2365
+ }
2366
+ }
2367
+
2368
+ override fun allocationSize(value: ContractValue): ULong = when(value) {
2369
+ is ContractValue.Clear -> {
2370
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
2371
+ (
2372
+ 4UL
2373
+ + FfiConverterULong.allocationSize(value.`qty`)
2374
+ + FfiConverterByteArray.allocationSize(value.`flavor`)
2375
+ )
2376
+ }
2377
+ is ContractValue.Confidential -> {
2378
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
2379
+ (
2380
+ 4UL
2381
+ )
2382
+ }
2383
+ is ContractValue.Other -> {
2384
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
2385
+ (
2386
+ 4UL
2387
+ )
2388
+ }
2389
+ }
2390
+
2391
+ override fun write(value: ContractValue, buf: ByteBuffer) {
2392
+ when(value) {
2393
+ is ContractValue.Clear -> {
2394
+ buf.putInt(1)
2395
+ FfiConverterULong.write(value.`qty`, buf)
2396
+ FfiConverterByteArray.write(value.`flavor`, buf)
2397
+ Unit
2398
+ }
2399
+ is ContractValue.Confidential -> {
2400
+ buf.putInt(2)
2401
+ Unit
2402
+ }
2403
+ is ContractValue.Other -> {
2404
+ buf.putInt(3)
2405
+ Unit
2406
+ }
2407
+ }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
2408
+ }
2409
+ }
2410
+
2411
+
2412
+
2413
+
2414
+
2415
+
2416
+
2417
+ /**
2418
+ * Why a call was refused.
2419
+ */
2420
+ sealed class FlameException: kotlin.Exception() {
2421
+
2422
+ /**
2423
+ * The phrase is not a valid BIP-39 mnemonic in any supported language,
2424
+ * or the word count is not one BIP-39 defines.
2425
+ */
2426
+ class InvalidMnemonic(
2427
+
2428
+ val `reason`: kotlin.String
2429
+ ) : FlameException() {
2430
+ override val message
2431
+ get() = "reason=${ `reason` }"
2432
+ }
2433
+
2434
+ /**
2435
+ * A seed is not 64 bytes, or flamekd refused to derive from it.
2436
+ */
2437
+ class InvalidSeed(
2438
+
2439
+ val `reason`: kotlin.String
2440
+ ) : FlameException() {
2441
+ override val message
2442
+ get() = "reason=${ `reason` }"
2443
+ }
2444
+
2445
+ /**
2446
+ * An address does not parse for the wallet's network.
2447
+ */
2448
+ class InvalidAddress(
2449
+
2450
+ val `reason`: kotlin.String
2451
+ ) : FlameException() {
2452
+ override val message
2453
+ get() = "reason=${ `reason` }"
2454
+ }
2455
+
2456
+ /**
2457
+ * A branch or index is hardened; both must be normal.
2458
+ */
2459
+ class InvalidKeyPath(
2460
+
2461
+ val `reason`: kotlin.String
2462
+ ) : FlameException() {
2463
+ override val message
2464
+ get() = "reason=${ `reason` }"
2465
+ }
2466
+
2467
+ /**
2468
+ * Bytes do not decode into what they claim to be. `what` names the
2469
+ * field: `contract`, `proof`, `predicate`, `flavor`, `blinding`.
2470
+ */
2471
+ class InvalidBytes(
2472
+
2473
+ val `what`: kotlin.String,
2474
+
2475
+ val `reason`: kotlin.String
2476
+ ) : FlameException() {
2477
+ override val message
2478
+ get() = "what=${ `what` }, reason=${ `reason` }"
2479
+ }
2480
+
2481
+ /**
2482
+ * Input `input` is not locked to the key at the path it names, so its
2483
+ * signature could never verify.
2484
+ */
2485
+ class KeyMismatch(
2486
+
2487
+ val `input`: kotlin.UInt
2488
+ ) : FlameException() {
2489
+ override val message
2490
+ get() = "input=${ `input` }"
2491
+ }
2492
+
2493
+ /**
2494
+ * A note did not open; `failure` says how, and so what the wallet does
2495
+ * with the output.
2496
+ */
2497
+ class Note(
2498
+
2499
+ val `failure`: NoteFailure,
2500
+
2501
+ val `reason`: kotlin.String
2502
+ ) : FlameException() {
2503
+ override val message
2504
+ get() = "failure=${ `failure` }, reason=${ `reason` }"
2505
+ }
2506
+
2507
+ /**
2508
+ * The transfer could not be built or signed.
2509
+ */
2510
+ class Transfer(
2511
+
2512
+ val `reason`: kotlin.String
2513
+ ) : FlameException() {
2514
+ override val message
2515
+ get() = "reason=${ `reason` }"
2516
+ }
2517
+
2518
+
2519
+
2520
+
2521
+
2522
+ companion object ErrorHandler : UniffiRustCallStatusErrorHandler<FlameException> {
2523
+ override fun lift(error_buf: RustBuffer.ByValue): FlameException = FfiConverterTypeFlameError.lift(error_buf)
2524
+ }
2525
+
2526
+
2527
+ }
2528
+
2529
+ /**
2530
+ * @suppress
2531
+ */
2532
+ public object FfiConverterTypeFlameError : FfiConverterRustBuffer<FlameException> {
2533
+ override fun read(buf: ByteBuffer): FlameException {
2534
+
2535
+
2536
+ return when(buf.getInt()) {
2537
+ 1 -> FlameException.InvalidMnemonic(
2538
+ FfiConverterString.read(buf),
2539
+ )
2540
+ 2 -> FlameException.InvalidSeed(
2541
+ FfiConverterString.read(buf),
2542
+ )
2543
+ 3 -> FlameException.InvalidAddress(
2544
+ FfiConverterString.read(buf),
2545
+ )
2546
+ 4 -> FlameException.InvalidKeyPath(
2547
+ FfiConverterString.read(buf),
2548
+ )
2549
+ 5 -> FlameException.InvalidBytes(
2550
+ FfiConverterString.read(buf),
2551
+ FfiConverterString.read(buf),
2552
+ )
2553
+ 6 -> FlameException.KeyMismatch(
2554
+ FfiConverterUInt.read(buf),
2555
+ )
2556
+ 7 -> FlameException.Note(
2557
+ FfiConverterTypeNoteFailure.read(buf),
2558
+ FfiConverterString.read(buf),
2559
+ )
2560
+ 8 -> FlameException.Transfer(
2561
+ FfiConverterString.read(buf),
2562
+ )
2563
+ else -> throw RuntimeException("invalid error enum value, something is very wrong!!")
2564
+ }
2565
+ }
2566
+
2567
+ override fun allocationSize(value: FlameException): ULong {
2568
+ return when(value) {
2569
+ is FlameException.InvalidMnemonic -> (
2570
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
2571
+ 4UL
2572
+ + FfiConverterString.allocationSize(value.`reason`)
2573
+ )
2574
+ is FlameException.InvalidSeed -> (
2575
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
2576
+ 4UL
2577
+ + FfiConverterString.allocationSize(value.`reason`)
2578
+ )
2579
+ is FlameException.InvalidAddress -> (
2580
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
2581
+ 4UL
2582
+ + FfiConverterString.allocationSize(value.`reason`)
2583
+ )
2584
+ is FlameException.InvalidKeyPath -> (
2585
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
2586
+ 4UL
2587
+ + FfiConverterString.allocationSize(value.`reason`)
2588
+ )
2589
+ is FlameException.InvalidBytes -> (
2590
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
2591
+ 4UL
2592
+ + FfiConverterString.allocationSize(value.`what`)
2593
+ + FfiConverterString.allocationSize(value.`reason`)
2594
+ )
2595
+ is FlameException.KeyMismatch -> (
2596
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
2597
+ 4UL
2598
+ + FfiConverterUInt.allocationSize(value.`input`)
2599
+ )
2600
+ is FlameException.Note -> (
2601
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
2602
+ 4UL
2603
+ + FfiConverterTypeNoteFailure.allocationSize(value.`failure`)
2604
+ + FfiConverterString.allocationSize(value.`reason`)
2605
+ )
2606
+ is FlameException.Transfer -> (
2607
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
2608
+ 4UL
2609
+ + FfiConverterString.allocationSize(value.`reason`)
2610
+ )
2611
+ }
2612
+ }
2613
+
2614
+ override fun write(value: FlameException, buf: ByteBuffer) {
2615
+ when(value) {
2616
+ is FlameException.InvalidMnemonic -> {
2617
+ buf.putInt(1)
2618
+ FfiConverterString.write(value.`reason`, buf)
2619
+ Unit
2620
+ }
2621
+ is FlameException.InvalidSeed -> {
2622
+ buf.putInt(2)
2623
+ FfiConverterString.write(value.`reason`, buf)
2624
+ Unit
2625
+ }
2626
+ is FlameException.InvalidAddress -> {
2627
+ buf.putInt(3)
2628
+ FfiConverterString.write(value.`reason`, buf)
2629
+ Unit
2630
+ }
2631
+ is FlameException.InvalidKeyPath -> {
2632
+ buf.putInt(4)
2633
+ FfiConverterString.write(value.`reason`, buf)
2634
+ Unit
2635
+ }
2636
+ is FlameException.InvalidBytes -> {
2637
+ buf.putInt(5)
2638
+ FfiConverterString.write(value.`what`, buf)
2639
+ FfiConverterString.write(value.`reason`, buf)
2640
+ Unit
2641
+ }
2642
+ is FlameException.KeyMismatch -> {
2643
+ buf.putInt(6)
2644
+ FfiConverterUInt.write(value.`input`, buf)
2645
+ Unit
2646
+ }
2647
+ is FlameException.Note -> {
2648
+ buf.putInt(7)
2649
+ FfiConverterTypeNoteFailure.write(value.`failure`, buf)
2650
+ FfiConverterString.write(value.`reason`, buf)
2651
+ Unit
2652
+ }
2653
+ is FlameException.Transfer -> {
2654
+ buf.putInt(8)
2655
+ FfiConverterString.write(value.`reason`, buf)
2656
+ Unit
2657
+ }
2658
+ }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
2659
+ }
2660
+
2661
+ }
2662
+
2663
+
2664
+
2665
+ /**
2666
+ * Which network addresses are encoded for: `f1…` or `tf1…`.
2667
+ */
2668
+
2669
+ enum class Network {
2670
+
2671
+ MAINNET,
2672
+ TESTNET;
2673
+
2674
+
2675
+
2676
+
2677
+ companion object
2678
+ }
2679
+
2680
+
2681
+ /**
2682
+ * @suppress
2683
+ */
2684
+ public object FfiConverterTypeNetwork: FfiConverterRustBuffer<Network> {
2685
+ override fun read(buf: ByteBuffer) = try {
2686
+ Network.values()[buf.getInt() - 1]
2687
+ } catch (e: IndexOutOfBoundsException) {
2688
+ throw RuntimeException("invalid enum value, something is very wrong!!", e)
2689
+ }
2690
+
2691
+ override fun allocationSize(value: Network) = 4UL
2692
+
2693
+ override fun write(value: Network, buf: ByteBuffer) {
2694
+ buf.putInt(value.ordinal + 1)
2695
+ }
2696
+ }
2697
+
2698
+
2699
+
2700
+
2701
+
2702
+ /**
2703
+ * Why a note did not open: the outcomes of `docs/payments.md`
2704
+ * "Receiving", which a wallet treats differently.
2705
+ */
2706
+
2707
+ enum class NoteFailure {
2708
+
2709
+ /**
2710
+ * No note followed the output. The output is ours but unreadable: keep
2711
+ * and list it, and leave it out of the balance.
2712
+ */
2713
+ MISSING,
2714
+ /**
2715
+ * The note is malformed. Treated as [`NoteFailure::Missing`].
2716
+ */
2717
+ MALFORMED,
2718
+ /**
2719
+ * A note version this library does not know; a later one may open it.
2720
+ */
2721
+ UNKNOWN_VERSION,
2722
+ /**
2723
+ * The note does not decrypt under this address. Treated as
2724
+ * [`NoteFailure::Missing`].
2725
+ */
2726
+ UNDECRYPTABLE,
2727
+ /**
2728
+ * The note decrypts but misstates its output: the sender erred or lied.
2729
+ * Keep and flag it; never count it.
2730
+ */
2731
+ OPENING_MISMATCH,
2732
+ /**
2733
+ * The contract is a cleartext token, or not a token: there is no note
2734
+ * to open, and [`crate::decode_contract`] reads its amount.
2735
+ */
2736
+ NOT_CONFIDENTIAL;
2737
+
2738
+
2739
+
2740
+
2741
+ companion object
2742
+ }
2743
+
2744
+
2745
+ /**
2746
+ * @suppress
2747
+ */
2748
+ public object FfiConverterTypeNoteFailure: FfiConverterRustBuffer<NoteFailure> {
2749
+ override fun read(buf: ByteBuffer) = try {
2750
+ NoteFailure.values()[buf.getInt() - 1]
2751
+ } catch (e: IndexOutOfBoundsException) {
2752
+ throw RuntimeException("invalid enum value, something is very wrong!!", e)
2753
+ }
2754
+
2755
+ override fun allocationSize(value: NoteFailure) = 4UL
2756
+
2757
+ override fun write(value: NoteFailure, buf: ByteBuffer) {
2758
+ buf.putInt(value.ordinal + 1)
2759
+ }
2760
+ }
2761
+
2762
+
2763
+
2764
+
2765
+
2766
+
2767
+ /**
2768
+ * @suppress
2769
+ */
2770
+ public object FfiConverterOptionalByteArray: FfiConverterRustBuffer<kotlin.ByteArray?> {
2771
+ override fun read(buf: ByteBuffer): kotlin.ByteArray? {
2772
+ if (buf.get().toInt() == 0) {
2773
+ return null
2774
+ }
2775
+ return FfiConverterByteArray.read(buf)
2776
+ }
2777
+
2778
+ override fun allocationSize(value: kotlin.ByteArray?): ULong {
2779
+ if (value == null) {
2780
+ return 1UL
2781
+ } else {
2782
+ return 1UL + FfiConverterByteArray.allocationSize(value)
2783
+ }
2784
+ }
2785
+
2786
+ override fun write(value: kotlin.ByteArray?, buf: ByteBuffer) {
2787
+ if (value == null) {
2788
+ buf.put(0)
2789
+ } else {
2790
+ buf.put(1)
2791
+ FfiConverterByteArray.write(value, buf)
2792
+ }
2793
+ }
2794
+ }
2795
+
2796
+
2797
+
2798
+
2799
+ /**
2800
+ * @suppress
2801
+ */
2802
+ public object FfiConverterOptionalTypeKeyPath: FfiConverterRustBuffer<KeyPath?> {
2803
+ override fun read(buf: ByteBuffer): KeyPath? {
2804
+ if (buf.get().toInt() == 0) {
2805
+ return null
2806
+ }
2807
+ return FfiConverterTypeKeyPath.read(buf)
2808
+ }
2809
+
2810
+ override fun allocationSize(value: KeyPath?): ULong {
2811
+ if (value == null) {
2812
+ return 1UL
2813
+ } else {
2814
+ return 1UL + FfiConverterTypeKeyPath.allocationSize(value)
2815
+ }
2816
+ }
2817
+
2818
+ override fun write(value: KeyPath?, buf: ByteBuffer) {
2819
+ if (value == null) {
2820
+ buf.put(0)
2821
+ } else {
2822
+ buf.put(1)
2823
+ FfiConverterTypeKeyPath.write(value, buf)
2824
+ }
2825
+ }
2826
+ }
2827
+
2828
+
2829
+
2830
+
2831
+ /**
2832
+ * @suppress
2833
+ */
2834
+ public object FfiConverterOptionalTypeOpening: FfiConverterRustBuffer<Opening?> {
2835
+ override fun read(buf: ByteBuffer): Opening? {
2836
+ if (buf.get().toInt() == 0) {
2837
+ return null
2838
+ }
2839
+ return FfiConverterTypeOpening.read(buf)
2840
+ }
2841
+
2842
+ override fun allocationSize(value: Opening?): ULong {
2843
+ if (value == null) {
2844
+ return 1UL
2845
+ } else {
2846
+ return 1UL + FfiConverterTypeOpening.allocationSize(value)
2847
+ }
2848
+ }
2849
+
2850
+ override fun write(value: Opening?, buf: ByteBuffer) {
2851
+ if (value == null) {
2852
+ buf.put(0)
2853
+ } else {
2854
+ buf.put(1)
2855
+ FfiConverterTypeOpening.write(value, buf)
2856
+ }
2857
+ }
2858
+ }
2859
+
2860
+
2861
+
2862
+
2863
+ /**
2864
+ * @suppress
2865
+ */
2866
+ public object FfiConverterSequenceTypeCreatedOutput: FfiConverterRustBuffer<List<CreatedOutput>> {
2867
+ override fun read(buf: ByteBuffer): List<CreatedOutput> {
2868
+ val len = buf.getInt()
2869
+ return List<CreatedOutput>(len) {
2870
+ FfiConverterTypeCreatedOutput.read(buf)
2871
+ }
2872
+ }
2873
+
2874
+ override fun allocationSize(value: List<CreatedOutput>): ULong {
2875
+ val sizeForLength = 4UL
2876
+ val sizeForItems = value.map { FfiConverterTypeCreatedOutput.allocationSize(it) }.sum()
2877
+ return sizeForLength + sizeForItems
2878
+ }
2879
+
2880
+ override fun write(value: List<CreatedOutput>, buf: ByteBuffer) {
2881
+ buf.putInt(value.size)
2882
+ value.iterator().forEach {
2883
+ FfiConverterTypeCreatedOutput.write(it, buf)
2884
+ }
2885
+ }
2886
+ }
2887
+
2888
+
2889
+
2890
+
2891
+ /**
2892
+ * @suppress
2893
+ */
2894
+ public object FfiConverterSequenceTypeTransferInput: FfiConverterRustBuffer<List<TransferInput>> {
2895
+ override fun read(buf: ByteBuffer): List<TransferInput> {
2896
+ val len = buf.getInt()
2897
+ return List<TransferInput>(len) {
2898
+ FfiConverterTypeTransferInput.read(buf)
2899
+ }
2900
+ }
2901
+
2902
+ override fun allocationSize(value: List<TransferInput>): ULong {
2903
+ val sizeForLength = 4UL
2904
+ val sizeForItems = value.map { FfiConverterTypeTransferInput.allocationSize(it) }.sum()
2905
+ return sizeForLength + sizeForItems
2906
+ }
2907
+
2908
+ override fun write(value: List<TransferInput>, buf: ByteBuffer) {
2909
+ buf.putInt(value.size)
2910
+ value.iterator().forEach {
2911
+ FfiConverterTypeTransferInput.write(it, buf)
2912
+ }
2913
+ }
2914
+ }
2915
+
2916
+
2917
+
2918
+
2919
+ /**
2920
+ * @suppress
2921
+ */
2922
+ public object FfiConverterSequenceTypeTransferOutput: FfiConverterRustBuffer<List<TransferOutput>> {
2923
+ override fun read(buf: ByteBuffer): List<TransferOutput> {
2924
+ val len = buf.getInt()
2925
+ return List<TransferOutput>(len) {
2926
+ FfiConverterTypeTransferOutput.read(buf)
2927
+ }
2928
+ }
2929
+
2930
+ override fun allocationSize(value: List<TransferOutput>): ULong {
2931
+ val sizeForLength = 4UL
2932
+ val sizeForItems = value.map { FfiConverterTypeTransferOutput.allocationSize(it) }.sum()
2933
+ return sizeForLength + sizeForItems
2934
+ }
2935
+
2936
+ override fun write(value: List<TransferOutput>, buf: ByteBuffer) {
2937
+ buf.putInt(value.size)
2938
+ value.iterator().forEach {
2939
+ FfiConverterTypeTransferOutput.write(it, buf)
2940
+ }
2941
+ }
2942
+ }
2943
+ /**
2944
+ * Decodes a contract from its published bytes.
2945
+ */
2946
+ @Throws(FlameException::class) fun `decodeContract`(`bytes`: kotlin.ByteArray): ContractInfo {
2947
+ return FfiConverterTypeContractInfo.lift(
2948
+ uniffiRustCallWithError(FlameException) { _status ->
2949
+ UniffiLib.uniffi_flamewallet_ffi_fn_func_decode_contract(
2950
+
2951
+
2952
+ FfiConverterByteArray.lower(`bytes`),_status)
2953
+ }
2954
+ )
2955
+ }
2956
+
2957
+
2958
+ /**
2959
+ * Whether `opening` opens the confidential contract in `bytes`.
2960
+ *
2961
+ * This is how a recipient checks an opening delivered out of band before
2962
+ * counting the payment: the same id comparison
2963
+ * [`crate::Wallet::build_transfer`] makes, run without spending anything.
2964
+ */
2965
+ @Throws(FlameException::class) fun `openingMatches`(`contract`: kotlin.ByteArray, `opening`: Opening): kotlin.Boolean {
2966
+ return FfiConverterBoolean.lift(
2967
+ uniffiRustCallWithError(FlameException) { _status ->
2968
+ UniffiLib.uniffi_flamewallet_ffi_fn_func_opening_matches(
2969
+
2970
+
2971
+ FfiConverterByteArray.lower(`contract`),
2972
+ FfiConverterTypeOpening.lower(`opening`),_status)
2973
+ }
2974
+ )
2975
+ }
2976
+
2977
+
2978
+ /**
2979
+ * The predicate a payment to `address` is locked with: the address's
2980
+ * spending point. Refuses an address encoded for the other network.
2981
+ */
2982
+ @Throws(FlameException::class) fun `addressToPredicate`(`address`: kotlin.String, `network`: Network): kotlin.ByteArray {
2983
+ return FfiConverterByteArray.lift(
2984
+ uniffiRustCallWithError(FlameException) { _status ->
2985
+ UniffiLib.uniffi_flamewallet_ffi_fn_func_address_to_predicate(
2986
+
2987
+
2988
+ FfiConverterString.lower(`address`),
2989
+ FfiConverterTypeNetwork.lower(`network`),_status)
2990
+ }
2991
+ )
2992
+ }
2993
+
2994
+
2995
+ /**
2996
+ * A fresh English mnemonic of `word_count` words: 12, 15, 18, 21 or 24.
2997
+ */
2998
+ @Throws(FlameException::class) fun `generateMnemonic`(`wordCount`: kotlin.UByte): kotlin.String {
2999
+ return FfiConverterString.lift(
3000
+ uniffiRustCallWithError(FlameException) { _status ->
3001
+ UniffiLib.uniffi_flamewallet_ffi_fn_func_generate_mnemonic(
3002
+
3003
+
3004
+ FfiConverterUByte.lower(`wordCount`),_status)
3005
+ }
3006
+ )
3007
+ }
3008
+
3009
+
3010
+ /**
3011
+ * The 64-byte BIP-39 seed of `phrase` under `passphrase` (`""` for none).
3012
+ * This seed is what [`Wallet::new`] takes and what an app stores.
3013
+ */
3014
+ @Throws(FlameException::class) fun `mnemonicToSeed`(`phrase`: kotlin.String, `passphrase`: kotlin.String): kotlin.ByteArray {
3015
+ return FfiConverterByteArray.lift(
3016
+ uniffiRustCallWithError(FlameException) { _status ->
3017
+ UniffiLib.uniffi_flamewallet_ffi_fn_func_mnemonic_to_seed(
3018
+
3019
+
3020
+ FfiConverterString.lower(`phrase`),
3021
+ FfiConverterString.lower(`passphrase`),_status)
3022
+ }
3023
+ )
3024
+ }
3025
+
3026
+
3027
+ /**
3028
+ * Whether `phrase` is a valid mnemonic in any BIP-39 language.
3029
+ */ fun `validateMnemonic`(`phrase`: kotlin.String): kotlin.Boolean {
3030
+ return FfiConverterBoolean.lift(
3031
+ uniffiRustCall() { _status ->
3032
+ UniffiLib.uniffi_flamewallet_ffi_fn_func_validate_mnemonic(
3033
+
3034
+
3035
+ FfiConverterString.lower(`phrase`),_status)
3036
+ }
3037
+ )
3038
+ }
3039
+
3040
+
3041
+