@walletconnect/react-native-compat 2.17.2-canary-rcnt-3 → 2.17.2-canary-ca-1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2069 @@
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 uniffi.yttrium
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
+ import java.lang.ref.Cleaner
35
+
36
+ // This is a helper for safely working with byte buffers returned from the Rust code.
37
+ // A rust-owned buffer is represented by its capacity, its current length, and a
38
+ // pointer to the underlying data.
39
+
40
+ /**
41
+ * @suppress
42
+ */
43
+ @Structure.FieldOrder("capacity", "len", "data")
44
+ open class RustBuffer : Structure() {
45
+ // Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values.
46
+ // When dealing with these fields, make sure to call `toULong()`.
47
+ @JvmField var capacity: Long = 0
48
+ @JvmField var len: Long = 0
49
+ @JvmField var data: Pointer? = null
50
+
51
+ class ByValue: RustBuffer(), Structure.ByValue
52
+ class ByReference: RustBuffer(), Structure.ByReference
53
+
54
+ internal fun setValue(other: RustBuffer) {
55
+ capacity = other.capacity
56
+ len = other.len
57
+ data = other.data
58
+ }
59
+
60
+ companion object {
61
+ internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status ->
62
+ // Note: need to convert the size to a `Long` value to make this work with JVM.
63
+ UniffiLib.INSTANCE.ffi_yttrium_rustbuffer_alloc(size.toLong(), status)
64
+ }.also {
65
+ if(it.data == null) {
66
+ throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})")
67
+ }
68
+ }
69
+
70
+ internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue {
71
+ var buf = RustBuffer.ByValue()
72
+ buf.capacity = capacity.toLong()
73
+ buf.len = len.toLong()
74
+ buf.data = data
75
+ return buf
76
+ }
77
+
78
+ internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status ->
79
+ UniffiLib.INSTANCE.ffi_yttrium_rustbuffer_free(buf, status)
80
+ }
81
+ }
82
+
83
+ @Suppress("TooGenericExceptionThrown")
84
+ fun asByteBuffer() =
85
+ this.data?.getByteBuffer(0, this.len.toLong())?.also {
86
+ it.order(ByteOrder.BIG_ENDIAN)
87
+ }
88
+ }
89
+
90
+ /**
91
+ * The equivalent of the `*mut RustBuffer` type.
92
+ * Required for callbacks taking in an out pointer.
93
+ *
94
+ * Size is the sum of all values in the struct.
95
+ *
96
+ * @suppress
97
+ */
98
+ class RustBufferByReference : ByReference(16) {
99
+ /**
100
+ * Set the pointed-to `RustBuffer` to the given value.
101
+ */
102
+ fun setValue(value: RustBuffer.ByValue) {
103
+ // NOTE: The offsets are as they are in the C-like struct.
104
+ val pointer = getPointer()
105
+ pointer.setLong(0, value.capacity)
106
+ pointer.setLong(8, value.len)
107
+ pointer.setPointer(16, value.data)
108
+ }
109
+
110
+ /**
111
+ * Get a `RustBuffer.ByValue` from this reference.
112
+ */
113
+ fun getValue(): RustBuffer.ByValue {
114
+ val pointer = getPointer()
115
+ val value = RustBuffer.ByValue()
116
+ value.writeField("capacity", pointer.getLong(0))
117
+ value.writeField("len", pointer.getLong(8))
118
+ value.writeField("data", pointer.getLong(16))
119
+
120
+ return value
121
+ }
122
+ }
123
+
124
+ // This is a helper for safely passing byte references into the rust code.
125
+ // It's not actually used at the moment, because there aren't many things that you
126
+ // can take a direct pointer to in the JVM, and if we're going to copy something
127
+ // then we might as well copy it into a `RustBuffer`. But it's here for API
128
+ // completeness.
129
+
130
+ @Structure.FieldOrder("len", "data")
131
+ internal open class ForeignBytes : Structure() {
132
+ @JvmField var len: Int = 0
133
+ @JvmField var data: Pointer? = null
134
+
135
+ class ByValue : ForeignBytes(), Structure.ByValue
136
+ }
137
+ /**
138
+ * The FfiConverter interface handles converter types to and from the FFI
139
+ *
140
+ * All implementing objects should be public to support external types. When a
141
+ * type is external we need to import it's FfiConverter.
142
+ *
143
+ * @suppress
144
+ */
145
+ public interface FfiConverter<KotlinType, FfiType> {
146
+ // Convert an FFI type to a Kotlin type
147
+ fun lift(value: FfiType): KotlinType
148
+
149
+ // Convert an Kotlin type to an FFI type
150
+ fun lower(value: KotlinType): FfiType
151
+
152
+ // Read a Kotlin type from a `ByteBuffer`
153
+ fun read(buf: ByteBuffer): KotlinType
154
+
155
+ // Calculate bytes to allocate when creating a `RustBuffer`
156
+ //
157
+ // This must return at least as many bytes as the write() function will
158
+ // write. It can return more bytes than needed, for example when writing
159
+ // Strings we can't know the exact bytes needed until we the UTF-8
160
+ // encoding, so we pessimistically allocate the largest size possible (3
161
+ // bytes per codepoint). Allocating extra bytes is not really a big deal
162
+ // because the `RustBuffer` is short-lived.
163
+ fun allocationSize(value: KotlinType): ULong
164
+
165
+ // Write a Kotlin type to a `ByteBuffer`
166
+ fun write(value: KotlinType, buf: ByteBuffer)
167
+
168
+ // Lower a value into a `RustBuffer`
169
+ //
170
+ // This method lowers a value into a `RustBuffer` rather than the normal
171
+ // FfiType. It's used by the callback interface code. Callback interface
172
+ // returns are always serialized into a `RustBuffer` regardless of their
173
+ // normal FFI type.
174
+ fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue {
175
+ val rbuf = RustBuffer.alloc(allocationSize(value))
176
+ try {
177
+ val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also {
178
+ it.order(ByteOrder.BIG_ENDIAN)
179
+ }
180
+ write(value, bbuf)
181
+ rbuf.writeField("len", bbuf.position().toLong())
182
+ return rbuf
183
+ } catch (e: Throwable) {
184
+ RustBuffer.free(rbuf)
185
+ throw e
186
+ }
187
+ }
188
+
189
+ // Lift a value from a `RustBuffer`.
190
+ //
191
+ // This here mostly because of the symmetry with `lowerIntoRustBuffer()`.
192
+ // It's currently only used by the `FfiConverterRustBuffer` class below.
193
+ fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType {
194
+ val byteBuf = rbuf.asByteBuffer()!!
195
+ try {
196
+ val item = read(byteBuf)
197
+ if (byteBuf.hasRemaining()) {
198
+ throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!")
199
+ }
200
+ return item
201
+ } finally {
202
+ RustBuffer.free(rbuf)
203
+ }
204
+ }
205
+ }
206
+
207
+ /**
208
+ * FfiConverter that uses `RustBuffer` as the FfiType
209
+ *
210
+ * @suppress
211
+ */
212
+ public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> {
213
+ override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value)
214
+ override fun lower(value: KotlinType) = lowerIntoRustBuffer(value)
215
+ }
216
+ // A handful of classes and functions to support the generated data structures.
217
+ // This would be a good candidate for isolating in its own ffi-support lib.
218
+
219
+ internal const val UNIFFI_CALL_SUCCESS = 0.toByte()
220
+ internal const val UNIFFI_CALL_ERROR = 1.toByte()
221
+ internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte()
222
+
223
+ @Structure.FieldOrder("code", "error_buf")
224
+ internal open class UniffiRustCallStatus : Structure() {
225
+ @JvmField var code: Byte = 0
226
+ @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue()
227
+
228
+ class ByValue: UniffiRustCallStatus(), Structure.ByValue
229
+
230
+ fun isSuccess(): Boolean {
231
+ return code == UNIFFI_CALL_SUCCESS
232
+ }
233
+
234
+ fun isError(): Boolean {
235
+ return code == UNIFFI_CALL_ERROR
236
+ }
237
+
238
+ fun isPanic(): Boolean {
239
+ return code == UNIFFI_CALL_UNEXPECTED_ERROR
240
+ }
241
+
242
+ companion object {
243
+ fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue {
244
+ val callStatus = UniffiRustCallStatus.ByValue()
245
+ callStatus.code = code
246
+ callStatus.error_buf = errorBuf
247
+ return callStatus
248
+ }
249
+ }
250
+ }
251
+
252
+ class InternalException(message: String) : kotlin.Exception(message)
253
+
254
+ /**
255
+ * Each top-level error class has a companion object that can lift the error from the call status's rust buffer
256
+ *
257
+ * @suppress
258
+ */
259
+ interface UniffiRustCallStatusErrorHandler<E> {
260
+ fun lift(error_buf: RustBuffer.ByValue): E;
261
+ }
262
+
263
+ // Helpers for calling Rust
264
+ // In practice we usually need to be synchronized to call this safely, so it doesn't
265
+ // synchronize itself
266
+
267
+ // Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err
268
+ private inline fun <U, E: kotlin.Exception> uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler<E>, callback: (UniffiRustCallStatus) -> U): U {
269
+ var status = UniffiRustCallStatus()
270
+ val return_value = callback(status)
271
+ uniffiCheckCallStatus(errorHandler, status)
272
+ return return_value
273
+ }
274
+
275
+ // Check UniffiRustCallStatus and throw an error if the call wasn't successful
276
+ private fun<E: kotlin.Exception> uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler<E>, status: UniffiRustCallStatus) {
277
+ if (status.isSuccess()) {
278
+ return
279
+ } else if (status.isError()) {
280
+ throw errorHandler.lift(status.error_buf)
281
+ } else if (status.isPanic()) {
282
+ // when the rust code sees a panic, it tries to construct a rustbuffer
283
+ // with the message. but if that code panics, then it just sends back
284
+ // an empty buffer.
285
+ if (status.error_buf.len > 0) {
286
+ throw InternalException(FfiConverterString.lift(status.error_buf))
287
+ } else {
288
+ throw InternalException("Rust panic")
289
+ }
290
+ } else {
291
+ throw InternalException("Unknown rust call status: $status.code")
292
+ }
293
+ }
294
+
295
+ /**
296
+ * UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
297
+ *
298
+ * @suppress
299
+ */
300
+ object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<InternalException> {
301
+ override fun lift(error_buf: RustBuffer.ByValue): InternalException {
302
+ RustBuffer.free(error_buf)
303
+ return InternalException("Unexpected CALL_ERROR")
304
+ }
305
+ }
306
+
307
+ // Call a rust function that returns a plain value
308
+ private inline fun <U> uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U {
309
+ return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback)
310
+ }
311
+
312
+ internal inline fun<T> uniffiTraitInterfaceCall(
313
+ callStatus: UniffiRustCallStatus,
314
+ makeCall: () -> T,
315
+ writeReturn: (T) -> Unit,
316
+ ) {
317
+ try {
318
+ writeReturn(makeCall())
319
+ } catch(e: kotlin.Exception) {
320
+ callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
321
+ callStatus.error_buf = FfiConverterString.lower(e.toString())
322
+ }
323
+ }
324
+
325
+ internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError(
326
+ callStatus: UniffiRustCallStatus,
327
+ makeCall: () -> T,
328
+ writeReturn: (T) -> Unit,
329
+ lowerError: (E) -> RustBuffer.ByValue
330
+ ) {
331
+ try {
332
+ writeReturn(makeCall())
333
+ } catch(e: kotlin.Exception) {
334
+ if (e is E) {
335
+ callStatus.code = UNIFFI_CALL_ERROR
336
+ callStatus.error_buf = lowerError(e)
337
+ } else {
338
+ callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
339
+ callStatus.error_buf = FfiConverterString.lower(e.toString())
340
+ }
341
+ }
342
+ }
343
+ // Map handles to objects
344
+ //
345
+ // This is used pass an opaque 64-bit handle representing a foreign object to the Rust code.
346
+ internal class UniffiHandleMap<T: Any> {
347
+ private val map = ConcurrentHashMap<Long, T>()
348
+ private val counter = java.util.concurrent.atomic.AtomicLong(0)
349
+
350
+ val size: Int
351
+ get() = map.size
352
+
353
+ // Insert a new object into the handle map and get a handle for it
354
+ fun insert(obj: T): Long {
355
+ val handle = counter.getAndAdd(1)
356
+ map.put(handle, obj)
357
+ return handle
358
+ }
359
+
360
+ // Get an object from the handle map
361
+ fun get(handle: Long): T {
362
+ return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle")
363
+ }
364
+
365
+ // Remove an entry from the handlemap and get the Kotlin object back
366
+ fun remove(handle: Long): T {
367
+ return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle")
368
+ }
369
+ }
370
+
371
+ // Contains loading, initialization code,
372
+ // and the FFI Function declarations in a com.sun.jna.Library.
373
+ @Synchronized
374
+ private fun findLibraryName(componentName: String): String {
375
+ val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride")
376
+ if (libOverride != null) {
377
+ return libOverride
378
+ }
379
+ return "uniffi_yttrium"
380
+ }
381
+
382
+ private inline fun <reified Lib : Library> loadIndirect(
383
+ componentName: String
384
+ ): Lib {
385
+ return Native.load<Lib>(findLibraryName(componentName), Lib::class.java)
386
+ }
387
+
388
+ // Define FFI callback types
389
+ internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback {
390
+ fun callback(`data`: Long,`pollResult`: Byte,)
391
+ }
392
+ internal interface UniffiForeignFutureFree : com.sun.jna.Callback {
393
+ fun callback(`handle`: Long,)
394
+ }
395
+ internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback {
396
+ fun callback(`handle`: Long,)
397
+ }
398
+ @Structure.FieldOrder("handle", "free")
399
+ internal open class UniffiForeignFuture(
400
+ @JvmField internal var `handle`: Long = 0.toLong(),
401
+ @JvmField internal var `free`: UniffiForeignFutureFree? = null,
402
+ ) : Structure() {
403
+ class UniffiByValue(
404
+ `handle`: Long = 0.toLong(),
405
+ `free`: UniffiForeignFutureFree? = null,
406
+ ): UniffiForeignFuture(`handle`,`free`,), Structure.ByValue
407
+
408
+ internal fun uniffiSetValue(other: UniffiForeignFuture) {
409
+ `handle` = other.`handle`
410
+ `free` = other.`free`
411
+ }
412
+
413
+ }
414
+ @Structure.FieldOrder("returnValue", "callStatus")
415
+ internal open class UniffiForeignFutureStructU8(
416
+ @JvmField internal var `returnValue`: Byte = 0.toByte(),
417
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
418
+ ) : Structure() {
419
+ class UniffiByValue(
420
+ `returnValue`: Byte = 0.toByte(),
421
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
422
+ ): UniffiForeignFutureStructU8(`returnValue`,`callStatus`,), Structure.ByValue
423
+
424
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU8) {
425
+ `returnValue` = other.`returnValue`
426
+ `callStatus` = other.`callStatus`
427
+ }
428
+
429
+ }
430
+ internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback {
431
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU8.UniffiByValue,)
432
+ }
433
+ @Structure.FieldOrder("returnValue", "callStatus")
434
+ internal open class UniffiForeignFutureStructI8(
435
+ @JvmField internal var `returnValue`: Byte = 0.toByte(),
436
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
437
+ ) : Structure() {
438
+ class UniffiByValue(
439
+ `returnValue`: Byte = 0.toByte(),
440
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
441
+ ): UniffiForeignFutureStructI8(`returnValue`,`callStatus`,), Structure.ByValue
442
+
443
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI8) {
444
+ `returnValue` = other.`returnValue`
445
+ `callStatus` = other.`callStatus`
446
+ }
447
+
448
+ }
449
+ internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback {
450
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI8.UniffiByValue,)
451
+ }
452
+ @Structure.FieldOrder("returnValue", "callStatus")
453
+ internal open class UniffiForeignFutureStructU16(
454
+ @JvmField internal var `returnValue`: Short = 0.toShort(),
455
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
456
+ ) : Structure() {
457
+ class UniffiByValue(
458
+ `returnValue`: Short = 0.toShort(),
459
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
460
+ ): UniffiForeignFutureStructU16(`returnValue`,`callStatus`,), Structure.ByValue
461
+
462
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU16) {
463
+ `returnValue` = other.`returnValue`
464
+ `callStatus` = other.`callStatus`
465
+ }
466
+
467
+ }
468
+ internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback {
469
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU16.UniffiByValue,)
470
+ }
471
+ @Structure.FieldOrder("returnValue", "callStatus")
472
+ internal open class UniffiForeignFutureStructI16(
473
+ @JvmField internal var `returnValue`: Short = 0.toShort(),
474
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
475
+ ) : Structure() {
476
+ class UniffiByValue(
477
+ `returnValue`: Short = 0.toShort(),
478
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
479
+ ): UniffiForeignFutureStructI16(`returnValue`,`callStatus`,), Structure.ByValue
480
+
481
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI16) {
482
+ `returnValue` = other.`returnValue`
483
+ `callStatus` = other.`callStatus`
484
+ }
485
+
486
+ }
487
+ internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback {
488
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI16.UniffiByValue,)
489
+ }
490
+ @Structure.FieldOrder("returnValue", "callStatus")
491
+ internal open class UniffiForeignFutureStructU32(
492
+ @JvmField internal var `returnValue`: Int = 0,
493
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
494
+ ) : Structure() {
495
+ class UniffiByValue(
496
+ `returnValue`: Int = 0,
497
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
498
+ ): UniffiForeignFutureStructU32(`returnValue`,`callStatus`,), Structure.ByValue
499
+
500
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU32) {
501
+ `returnValue` = other.`returnValue`
502
+ `callStatus` = other.`callStatus`
503
+ }
504
+
505
+ }
506
+ internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback {
507
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU32.UniffiByValue,)
508
+ }
509
+ @Structure.FieldOrder("returnValue", "callStatus")
510
+ internal open class UniffiForeignFutureStructI32(
511
+ @JvmField internal var `returnValue`: Int = 0,
512
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
513
+ ) : Structure() {
514
+ class UniffiByValue(
515
+ `returnValue`: Int = 0,
516
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
517
+ ): UniffiForeignFutureStructI32(`returnValue`,`callStatus`,), Structure.ByValue
518
+
519
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI32) {
520
+ `returnValue` = other.`returnValue`
521
+ `callStatus` = other.`callStatus`
522
+ }
523
+
524
+ }
525
+ internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback {
526
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI32.UniffiByValue,)
527
+ }
528
+ @Structure.FieldOrder("returnValue", "callStatus")
529
+ internal open class UniffiForeignFutureStructU64(
530
+ @JvmField internal var `returnValue`: Long = 0.toLong(),
531
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
532
+ ) : Structure() {
533
+ class UniffiByValue(
534
+ `returnValue`: Long = 0.toLong(),
535
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
536
+ ): UniffiForeignFutureStructU64(`returnValue`,`callStatus`,), Structure.ByValue
537
+
538
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU64) {
539
+ `returnValue` = other.`returnValue`
540
+ `callStatus` = other.`callStatus`
541
+ }
542
+
543
+ }
544
+ internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback {
545
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU64.UniffiByValue,)
546
+ }
547
+ @Structure.FieldOrder("returnValue", "callStatus")
548
+ internal open class UniffiForeignFutureStructI64(
549
+ @JvmField internal var `returnValue`: Long = 0.toLong(),
550
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
551
+ ) : Structure() {
552
+ class UniffiByValue(
553
+ `returnValue`: Long = 0.toLong(),
554
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
555
+ ): UniffiForeignFutureStructI64(`returnValue`,`callStatus`,), Structure.ByValue
556
+
557
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI64) {
558
+ `returnValue` = other.`returnValue`
559
+ `callStatus` = other.`callStatus`
560
+ }
561
+
562
+ }
563
+ internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback {
564
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI64.UniffiByValue,)
565
+ }
566
+ @Structure.FieldOrder("returnValue", "callStatus")
567
+ internal open class UniffiForeignFutureStructF32(
568
+ @JvmField internal var `returnValue`: Float = 0.0f,
569
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
570
+ ) : Structure() {
571
+ class UniffiByValue(
572
+ `returnValue`: Float = 0.0f,
573
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
574
+ ): UniffiForeignFutureStructF32(`returnValue`,`callStatus`,), Structure.ByValue
575
+
576
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructF32) {
577
+ `returnValue` = other.`returnValue`
578
+ `callStatus` = other.`callStatus`
579
+ }
580
+
581
+ }
582
+ internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback {
583
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF32.UniffiByValue,)
584
+ }
585
+ @Structure.FieldOrder("returnValue", "callStatus")
586
+ internal open class UniffiForeignFutureStructF64(
587
+ @JvmField internal var `returnValue`: Double = 0.0,
588
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
589
+ ) : Structure() {
590
+ class UniffiByValue(
591
+ `returnValue`: Double = 0.0,
592
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
593
+ ): UniffiForeignFutureStructF64(`returnValue`,`callStatus`,), Structure.ByValue
594
+
595
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructF64) {
596
+ `returnValue` = other.`returnValue`
597
+ `callStatus` = other.`callStatus`
598
+ }
599
+
600
+ }
601
+ internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback {
602
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF64.UniffiByValue,)
603
+ }
604
+ @Structure.FieldOrder("returnValue", "callStatus")
605
+ internal open class UniffiForeignFutureStructPointer(
606
+ @JvmField internal var `returnValue`: Pointer = Pointer.NULL,
607
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
608
+ ) : Structure() {
609
+ class UniffiByValue(
610
+ `returnValue`: Pointer = Pointer.NULL,
611
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
612
+ ): UniffiForeignFutureStructPointer(`returnValue`,`callStatus`,), Structure.ByValue
613
+
614
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructPointer) {
615
+ `returnValue` = other.`returnValue`
616
+ `callStatus` = other.`callStatus`
617
+ }
618
+
619
+ }
620
+ internal interface UniffiForeignFutureCompletePointer : com.sun.jna.Callback {
621
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructPointer.UniffiByValue,)
622
+ }
623
+ @Structure.FieldOrder("returnValue", "callStatus")
624
+ internal open class UniffiForeignFutureStructRustBuffer(
625
+ @JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
626
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
627
+ ) : Structure() {
628
+ class UniffiByValue(
629
+ `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
630
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
631
+ ): UniffiForeignFutureStructRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue
632
+
633
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructRustBuffer) {
634
+ `returnValue` = other.`returnValue`
635
+ `callStatus` = other.`callStatus`
636
+ }
637
+
638
+ }
639
+ internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback {
640
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructRustBuffer.UniffiByValue,)
641
+ }
642
+ @Structure.FieldOrder("callStatus")
643
+ internal open class UniffiForeignFutureStructVoid(
644
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
645
+ ) : Structure() {
646
+ class UniffiByValue(
647
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
648
+ ): UniffiForeignFutureStructVoid(`callStatus`,), Structure.ByValue
649
+
650
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructVoid) {
651
+ `callStatus` = other.`callStatus`
652
+ }
653
+
654
+ }
655
+ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {
656
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructVoid.UniffiByValue,)
657
+ }
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+
679
+
680
+
681
+
682
+
683
+
684
+
685
+
686
+
687
+
688
+
689
+
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+ // A JNA Library to expose the extern-C FFI definitions.
719
+ // This is an implementation detail which will be called internally by the public API.
720
+
721
+ internal interface UniffiLib : Library {
722
+ companion object {
723
+ internal val INSTANCE: UniffiLib by lazy {
724
+ loadIndirect<UniffiLib>(componentName = "yttrium")
725
+ .also { lib: UniffiLib ->
726
+ uniffiCheckContractApiVersion(lib)
727
+ uniffiCheckApiChecksums(lib)
728
+ }
729
+ }
730
+
731
+ // The Cleaner for the whole library
732
+ internal val CLEANER: UniffiCleaner by lazy {
733
+ UniffiCleaner.create()
734
+ }
735
+ }
736
+
737
+ fun uniffi_yttrium_fn_clone_accountclient(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
738
+ ): Pointer
739
+ fun uniffi_yttrium_fn_free_accountclient(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
740
+ ): Unit
741
+ fun ffi_yttrium_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus,
742
+ ): RustBuffer.ByValue
743
+ fun ffi_yttrium_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus,
744
+ ): RustBuffer.ByValue
745
+ fun ffi_yttrium_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
746
+ ): Unit
747
+ fun ffi_yttrium_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus,
748
+ ): RustBuffer.ByValue
749
+ fun ffi_yttrium_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
750
+ ): Unit
751
+ fun ffi_yttrium_rust_future_cancel_u8(`handle`: Long,
752
+ ): Unit
753
+ fun ffi_yttrium_rust_future_free_u8(`handle`: Long,
754
+ ): Unit
755
+ fun ffi_yttrium_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
756
+ ): Byte
757
+ fun ffi_yttrium_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
758
+ ): Unit
759
+ fun ffi_yttrium_rust_future_cancel_i8(`handle`: Long,
760
+ ): Unit
761
+ fun ffi_yttrium_rust_future_free_i8(`handle`: Long,
762
+ ): Unit
763
+ fun ffi_yttrium_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
764
+ ): Byte
765
+ fun ffi_yttrium_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
766
+ ): Unit
767
+ fun ffi_yttrium_rust_future_cancel_u16(`handle`: Long,
768
+ ): Unit
769
+ fun ffi_yttrium_rust_future_free_u16(`handle`: Long,
770
+ ): Unit
771
+ fun ffi_yttrium_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
772
+ ): Short
773
+ fun ffi_yttrium_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
774
+ ): Unit
775
+ fun ffi_yttrium_rust_future_cancel_i16(`handle`: Long,
776
+ ): Unit
777
+ fun ffi_yttrium_rust_future_free_i16(`handle`: Long,
778
+ ): Unit
779
+ fun ffi_yttrium_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
780
+ ): Short
781
+ fun ffi_yttrium_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
782
+ ): Unit
783
+ fun ffi_yttrium_rust_future_cancel_u32(`handle`: Long,
784
+ ): Unit
785
+ fun ffi_yttrium_rust_future_free_u32(`handle`: Long,
786
+ ): Unit
787
+ fun ffi_yttrium_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
788
+ ): Int
789
+ fun ffi_yttrium_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
790
+ ): Unit
791
+ fun ffi_yttrium_rust_future_cancel_i32(`handle`: Long,
792
+ ): Unit
793
+ fun ffi_yttrium_rust_future_free_i32(`handle`: Long,
794
+ ): Unit
795
+ fun ffi_yttrium_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
796
+ ): Int
797
+ fun ffi_yttrium_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
798
+ ): Unit
799
+ fun ffi_yttrium_rust_future_cancel_u64(`handle`: Long,
800
+ ): Unit
801
+ fun ffi_yttrium_rust_future_free_u64(`handle`: Long,
802
+ ): Unit
803
+ fun ffi_yttrium_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
804
+ ): Long
805
+ fun ffi_yttrium_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
806
+ ): Unit
807
+ fun ffi_yttrium_rust_future_cancel_i64(`handle`: Long,
808
+ ): Unit
809
+ fun ffi_yttrium_rust_future_free_i64(`handle`: Long,
810
+ ): Unit
811
+ fun ffi_yttrium_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
812
+ ): Long
813
+ fun ffi_yttrium_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
814
+ ): Unit
815
+ fun ffi_yttrium_rust_future_cancel_f32(`handle`: Long,
816
+ ): Unit
817
+ fun ffi_yttrium_rust_future_free_f32(`handle`: Long,
818
+ ): Unit
819
+ fun ffi_yttrium_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
820
+ ): Float
821
+ fun ffi_yttrium_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
822
+ ): Unit
823
+ fun ffi_yttrium_rust_future_cancel_f64(`handle`: Long,
824
+ ): Unit
825
+ fun ffi_yttrium_rust_future_free_f64(`handle`: Long,
826
+ ): Unit
827
+ fun ffi_yttrium_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
828
+ ): Double
829
+ fun ffi_yttrium_rust_future_poll_pointer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
830
+ ): Unit
831
+ fun ffi_yttrium_rust_future_cancel_pointer(`handle`: Long,
832
+ ): Unit
833
+ fun ffi_yttrium_rust_future_free_pointer(`handle`: Long,
834
+ ): Unit
835
+ fun ffi_yttrium_rust_future_complete_pointer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
836
+ ): Pointer
837
+ fun ffi_yttrium_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
838
+ ): Unit
839
+ fun ffi_yttrium_rust_future_cancel_rust_buffer(`handle`: Long,
840
+ ): Unit
841
+ fun ffi_yttrium_rust_future_free_rust_buffer(`handle`: Long,
842
+ ): Unit
843
+ fun ffi_yttrium_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
844
+ ): RustBuffer.ByValue
845
+ fun ffi_yttrium_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
846
+ ): Unit
847
+ fun ffi_yttrium_rust_future_cancel_void(`handle`: Long,
848
+ ): Unit
849
+ fun ffi_yttrium_rust_future_free_void(`handle`: Long,
850
+ ): Unit
851
+ fun ffi_yttrium_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
852
+ ): Unit
853
+ fun ffi_yttrium_uniffi_contract_version(
854
+ ): Int
855
+
856
+ }
857
+
858
+ private fun uniffiCheckContractApiVersion(lib: UniffiLib) {
859
+ // Get the bindings contract version from our ComponentInterface
860
+ val bindings_contract_version = 29
861
+ // Get the scaffolding contract version by calling the into the dylib
862
+ val scaffolding_contract_version = lib.ffi_yttrium_uniffi_contract_version()
863
+ if (bindings_contract_version != scaffolding_contract_version) {
864
+ throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project")
865
+ }
866
+ }
867
+
868
+ @Suppress("UNUSED_PARAMETER")
869
+ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
870
+ }
871
+
872
+ // Async support
873
+
874
+ // Public interface members begin here.
875
+
876
+
877
+ // Interface implemented by anything that can contain an object reference.
878
+ //
879
+ // Such types expose a `destroy()` method that must be called to cleanly
880
+ // dispose of the contained objects. Failure to call this method may result
881
+ // in memory leaks.
882
+ //
883
+ // The easiest way to ensure this method is called is to use the `.use`
884
+ // helper method to execute a block and destroy the object at the end.
885
+ interface Disposable {
886
+ fun destroy()
887
+ companion object {
888
+ fun destroy(vararg args: Any?) {
889
+ args.filterIsInstance<Disposable>()
890
+ .forEach(Disposable::destroy)
891
+ }
892
+ }
893
+ }
894
+
895
+ /**
896
+ * @suppress
897
+ */
898
+ inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
899
+ try {
900
+ block(this)
901
+ } finally {
902
+ try {
903
+ // N.B. our implementation is on the nullable type `Disposable?`.
904
+ this?.destroy()
905
+ } catch (e: Throwable) {
906
+ // swallow
907
+ }
908
+ }
909
+
910
+ /**
911
+ * Used to instantiate an interface without an actual pointer, for fakes in tests, mostly.
912
+ *
913
+ * @suppress
914
+ * */
915
+ object NoPointer
916
+
917
+ /**
918
+ * @suppress
919
+ */
920
+ public object FfiConverterULong: FfiConverter<ULong, Long> {
921
+ override fun lift(value: Long): ULong {
922
+ return value.toULong()
923
+ }
924
+
925
+ override fun read(buf: ByteBuffer): ULong {
926
+ return lift(buf.getLong())
927
+ }
928
+
929
+ override fun lower(value: ULong): Long {
930
+ return value.toLong()
931
+ }
932
+
933
+ override fun allocationSize(value: ULong) = 8UL
934
+
935
+ override fun write(value: ULong, buf: ByteBuffer) {
936
+ buf.putLong(value.toLong())
937
+ }
938
+ }
939
+
940
+ /**
941
+ * @suppress
942
+ */
943
+ public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
944
+ // Note: we don't inherit from FfiConverterRustBuffer, because we use a
945
+ // special encoding when lowering/lifting. We can use `RustBuffer.len` to
946
+ // store our length and avoid writing it out to the buffer.
947
+ override fun lift(value: RustBuffer.ByValue): String {
948
+ try {
949
+ val byteArr = ByteArray(value.len.toInt())
950
+ value.asByteBuffer()!!.get(byteArr)
951
+ return byteArr.toString(Charsets.UTF_8)
952
+ } finally {
953
+ RustBuffer.free(value)
954
+ }
955
+ }
956
+
957
+ override fun read(buf: ByteBuffer): String {
958
+ val len = buf.getInt()
959
+ val byteArr = ByteArray(len)
960
+ buf.get(byteArr)
961
+ return byteArr.toString(Charsets.UTF_8)
962
+ }
963
+
964
+ fun toUtf8(value: String): ByteBuffer {
965
+ // Make sure we don't have invalid UTF-16, check for lone surrogates.
966
+ return Charsets.UTF_8.newEncoder().run {
967
+ onMalformedInput(CodingErrorAction.REPORT)
968
+ encode(CharBuffer.wrap(value))
969
+ }
970
+ }
971
+
972
+ override fun lower(value: String): RustBuffer.ByValue {
973
+ val byteBuf = toUtf8(value)
974
+ // Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us
975
+ // to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`.
976
+ val rbuf = RustBuffer.alloc(byteBuf.limit().toULong())
977
+ rbuf.asByteBuffer()!!.put(byteBuf)
978
+ return rbuf
979
+ }
980
+
981
+ // We aren't sure exactly how many bytes our string will be once it's UTF-8
982
+ // encoded. Allocate 3 bytes per UTF-16 code unit which will always be
983
+ // enough.
984
+ override fun allocationSize(value: String): ULong {
985
+ val sizeForLength = 4UL
986
+ val sizeForString = value.length.toULong() * 3UL
987
+ return sizeForLength + sizeForString
988
+ }
989
+
990
+ override fun write(value: String, buf: ByteBuffer) {
991
+ val byteBuf = toUtf8(value)
992
+ buf.putInt(byteBuf.limit())
993
+ buf.put(byteBuf)
994
+ }
995
+ }
996
+
997
+
998
+ // This template implements a class for working with a Rust struct via a Pointer/Arc<T>
999
+ // to the live Rust struct on the other side of the FFI.
1000
+ //
1001
+ // Each instance implements core operations for working with the Rust `Arc<T>` and the
1002
+ // Kotlin Pointer to work with the live Rust struct on the other side of the FFI.
1003
+ //
1004
+ // There's some subtlety here, because we have to be careful not to operate on a Rust
1005
+ // struct after it has been dropped, and because we must expose a public API for freeing
1006
+ // theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
1007
+ //
1008
+ // * Each instance holds an opaque pointer to the underlying Rust struct.
1009
+ // Method calls need to read this pointer from the object's state and pass it in to
1010
+ // the Rust FFI.
1011
+ //
1012
+ // * When an instance is no longer needed, its pointer should be passed to a
1013
+ // special destructor function provided by the Rust FFI, which will drop the
1014
+ // underlying Rust struct.
1015
+ //
1016
+ // * Given an instance, calling code is expected to call the special
1017
+ // `destroy` method in order to free it after use, either by calling it explicitly
1018
+ // or by using a higher-level helper like the `use` method. Failing to do so risks
1019
+ // leaking the underlying Rust struct.
1020
+ //
1021
+ // * We can't assume that calling code will do the right thing, and must be prepared
1022
+ // to handle Kotlin method calls executing concurrently with or even after a call to
1023
+ // `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
1024
+ //
1025
+ // * We must never allow Rust code to operate on the underlying Rust struct after
1026
+ // the destructor has been called, and must never call the destructor more than once.
1027
+ // Doing so may trigger memory unsafety.
1028
+ //
1029
+ // * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
1030
+ // is implemented to call the destructor when the Kotlin object becomes unreachable.
1031
+ // This is done in a background thread. This is not a panacea, and client code should be aware that
1032
+ // 1. the thread may starve if some there are objects that have poorly performing
1033
+ // `drop` methods or do significant work in their `drop` methods.
1034
+ // 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
1035
+ // or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
1036
+ //
1037
+ // If we try to implement this with mutual exclusion on access to the pointer, there is the
1038
+ // possibility of a race between a method call and a concurrent call to `destroy`:
1039
+ //
1040
+ // * Thread A starts a method call, reads the value of the pointer, but is interrupted
1041
+ // before it can pass the pointer over the FFI to Rust.
1042
+ // * Thread B calls `destroy` and frees the underlying Rust struct.
1043
+ // * Thread A resumes, passing the already-read pointer value to Rust and triggering
1044
+ // a use-after-free.
1045
+ //
1046
+ // One possible solution would be to use a `ReadWriteLock`, with each method call taking
1047
+ // a read lock (and thus allowed to run concurrently) and the special `destroy` method
1048
+ // taking a write lock (and thus blocking on live method calls). However, we aim not to
1049
+ // generate methods with any hidden blocking semantics, and a `destroy` method that might
1050
+ // block if called incorrectly seems to meet that bar.
1051
+ //
1052
+ // So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
1053
+ // the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
1054
+ // has been called. These are updated according to the following rules:
1055
+ //
1056
+ // * The initial value of the counter is 1, indicating a live object with no in-flight calls.
1057
+ // The initial value for the flag is false.
1058
+ //
1059
+ // * At the start of each method call, we atomically check the counter.
1060
+ // If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
1061
+ // If it is nonzero them we atomically increment it by 1 and proceed with the method call.
1062
+ //
1063
+ // * At the end of each method call, we atomically decrement and check the counter.
1064
+ // If it has reached zero then we destroy the underlying Rust struct.
1065
+ //
1066
+ // * When `destroy` is called, we atomically flip the flag from false to true.
1067
+ // If the flag was already true we silently fail.
1068
+ // Otherwise we atomically decrement and check the counter.
1069
+ // If it has reached zero then we destroy the underlying Rust struct.
1070
+ //
1071
+ // Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
1072
+ // and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
1073
+ //
1074
+ // The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
1075
+ // called *and* all in-flight method calls have completed, avoiding violating any of the expectations
1076
+ // of the underlying Rust code.
1077
+ //
1078
+ // This makes a cleaner a better alternative to _not_ calling `destroy()` as
1079
+ // and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
1080
+ // method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
1081
+ // thread may be starved, and the app will leak memory.
1082
+ //
1083
+ // In this case, `destroy`ing manually may be a better solution.
1084
+ //
1085
+ // The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
1086
+ // with Rust peers are reclaimed:
1087
+ //
1088
+ // 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
1089
+ // 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
1090
+ // 3. The memory is reclaimed when the process terminates.
1091
+ //
1092
+ // [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
1093
+ //
1094
+
1095
+
1096
+ /**
1097
+ * The cleaner interface for Object finalization code to run.
1098
+ * This is the entry point to any implementation that we're using.
1099
+ *
1100
+ * The cleaner registers objects and returns cleanables, so now we are
1101
+ * defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the
1102
+ * different implmentations available at compile time.
1103
+ *
1104
+ * @suppress
1105
+ */
1106
+ interface UniffiCleaner {
1107
+ interface Cleanable {
1108
+ fun clean()
1109
+ }
1110
+
1111
+ fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable
1112
+
1113
+ companion object
1114
+ }
1115
+
1116
+ // The fallback Jna cleaner, which is available for both Android, and the JVM.
1117
+ private class UniffiJnaCleaner : UniffiCleaner {
1118
+ private val cleaner = java.lang.ref.Cleaner.create()
1119
+
1120
+ override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
1121
+ UniffiJnaCleanable(cleaner.register(value, cleanUpTask))
1122
+ }
1123
+
1124
+ private class UniffiJnaCleanable(
1125
+ private val cleanable: java.lang.ref.Cleaner.Cleanable
1126
+ ) : UniffiCleaner.Cleanable {
1127
+ override fun clean() = cleanable.clean()
1128
+ }
1129
+
1130
+ // We decide at uniffi binding generation time whether we were
1131
+ // using Android or not.
1132
+ // There are further runtime checks to chose the correct implementation
1133
+ // of the cleaner.
1134
+ private fun UniffiCleaner.Companion.create(): UniffiCleaner =
1135
+ try {
1136
+ // For safety's sake: if the library hasn't been run in android_cleaner = true
1137
+ // mode, but is being run on Android, then we still need to think about
1138
+ // Android API versions.
1139
+ // So we check if java.lang.ref.Cleaner is there, and use that…
1140
+ java.lang.Class.forName("java.lang.ref.Cleaner")
1141
+ JavaLangRefCleaner()
1142
+ } catch (e: ClassNotFoundException) {
1143
+ // … otherwise, fallback to the JNA cleaner.
1144
+ UniffiJnaCleaner()
1145
+ }
1146
+
1147
+ private class JavaLangRefCleaner : UniffiCleaner {
1148
+ val cleaner = java.lang.ref.Cleaner.create()
1149
+
1150
+ override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
1151
+ JavaLangRefCleanable(cleaner.register(value, cleanUpTask))
1152
+ }
1153
+
1154
+ private class JavaLangRefCleanable(
1155
+ val cleanable: java.lang.ref.Cleaner.Cleanable
1156
+ ) : UniffiCleaner.Cleanable {
1157
+ override fun clean() = cleanable.clean()
1158
+ }
1159
+ public interface AccountClientInterface {
1160
+
1161
+ companion object
1162
+ }
1163
+
1164
+ open class AccountClient: Disposable, AutoCloseable, AccountClientInterface
1165
+ {
1166
+
1167
+ constructor(pointer: Pointer) {
1168
+ this.pointer = pointer
1169
+ this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer))
1170
+ }
1171
+
1172
+ /**
1173
+ * This constructor can be used to instantiate a fake object. Only used for tests. Any
1174
+ * attempt to actually use an object constructed this way will fail as there is no
1175
+ * connected Rust object.
1176
+ */
1177
+ @Suppress("UNUSED_PARAMETER")
1178
+ constructor(noPointer: NoPointer) {
1179
+ this.pointer = null
1180
+ this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer))
1181
+ }
1182
+
1183
+ protected val pointer: Pointer?
1184
+ protected val cleanable: UniffiCleaner.Cleanable
1185
+
1186
+ private val wasDestroyed = AtomicBoolean(false)
1187
+ private val callCounter = AtomicLong(1)
1188
+
1189
+ override fun destroy() {
1190
+ // Only allow a single call to this method.
1191
+ // TODO: maybe we should log a warning if called more than once?
1192
+ if (this.wasDestroyed.compareAndSet(false, true)) {
1193
+ // This decrement always matches the initial count of 1 given at creation time.
1194
+ if (this.callCounter.decrementAndGet() == 0L) {
1195
+ cleanable.clean()
1196
+ }
1197
+ }
1198
+ }
1199
+
1200
+ @Synchronized
1201
+ override fun close() {
1202
+ this.destroy()
1203
+ }
1204
+
1205
+ internal inline fun <R> callWithPointer(block: (ptr: Pointer) -> R): R {
1206
+ // Check and increment the call counter, to keep the object alive.
1207
+ // This needs a compare-and-set retry loop in case of concurrent updates.
1208
+ do {
1209
+ val c = this.callCounter.get()
1210
+ if (c == 0L) {
1211
+ throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
1212
+ }
1213
+ if (c == Long.MAX_VALUE) {
1214
+ throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
1215
+ }
1216
+ } while (! this.callCounter.compareAndSet(c, c + 1L))
1217
+ // Now we can safely do the method call without the pointer being freed concurrently.
1218
+ try {
1219
+ return block(this.uniffiClonePointer())
1220
+ } finally {
1221
+ // This decrement always matches the increment we performed above.
1222
+ if (this.callCounter.decrementAndGet() == 0L) {
1223
+ cleanable.clean()
1224
+ }
1225
+ }
1226
+ }
1227
+
1228
+ // Use a static inner class instead of a closure so as not to accidentally
1229
+ // capture `this` as part of the cleanable's action.
1230
+ private class UniffiCleanAction(private val pointer: Pointer?) : Runnable {
1231
+ override fun run() {
1232
+ pointer?.let { ptr ->
1233
+ uniffiRustCall { status ->
1234
+ UniffiLib.INSTANCE.uniffi_yttrium_fn_free_accountclient(ptr, status)
1235
+ }
1236
+ }
1237
+ }
1238
+ }
1239
+
1240
+ fun uniffiClonePointer(): Pointer {
1241
+ return uniffiRustCall() { status ->
1242
+ UniffiLib.INSTANCE.uniffi_yttrium_fn_clone_accountclient(pointer!!, status)
1243
+ }
1244
+ }
1245
+
1246
+
1247
+
1248
+
1249
+
1250
+ companion object
1251
+
1252
+ }
1253
+
1254
+ /**
1255
+ * @suppress
1256
+ */
1257
+ public object FfiConverterTypeAccountClient: FfiConverter<AccountClient, Pointer> {
1258
+
1259
+ override fun lower(value: AccountClient): Pointer {
1260
+ return value.uniffiClonePointer()
1261
+ }
1262
+
1263
+ override fun lift(value: Pointer): AccountClient {
1264
+ return AccountClient(value)
1265
+ }
1266
+
1267
+ override fun read(buf: ByteBuffer): AccountClient {
1268
+ // The Rust code always writes pointers as 8 bytes, and will
1269
+ // fail to compile if they don't fit.
1270
+ return lift(Pointer(buf.getLong()))
1271
+ }
1272
+
1273
+ override fun allocationSize(value: AccountClient) = 8UL
1274
+
1275
+ override fun write(value: AccountClient, buf: ByteBuffer) {
1276
+ // The Rust code always expects pointers written as 8 bytes,
1277
+ // and will fail to compile if they don't fit.
1278
+ buf.putLong(Pointer.nativeValue(lower(value)))
1279
+ }
1280
+ }
1281
+
1282
+
1283
+
1284
+ data class Config (
1285
+ var `endpoints`: Endpoints
1286
+ ) {
1287
+
1288
+ companion object
1289
+ }
1290
+
1291
+ /**
1292
+ * @suppress
1293
+ */
1294
+ public object FfiConverterTypeConfig: FfiConverterRustBuffer<Config> {
1295
+ override fun read(buf: ByteBuffer): Config {
1296
+ return Config(
1297
+ FfiConverterTypeEndpoints.read(buf),
1298
+ )
1299
+ }
1300
+
1301
+ override fun allocationSize(value: Config) = (
1302
+ FfiConverterTypeEndpoints.allocationSize(value.`endpoints`)
1303
+ )
1304
+
1305
+ override fun write(value: Config, buf: ByteBuffer) {
1306
+ FfiConverterTypeEndpoints.write(value.`endpoints`, buf)
1307
+ }
1308
+ }
1309
+
1310
+
1311
+
1312
+ data class Endpoint (
1313
+ var `baseUrl`: kotlin.String,
1314
+ var `apiKey`: kotlin.String
1315
+ ) {
1316
+
1317
+ companion object
1318
+ }
1319
+
1320
+ /**
1321
+ * @suppress
1322
+ */
1323
+ public object FfiConverterTypeEndpoint: FfiConverterRustBuffer<Endpoint> {
1324
+ override fun read(buf: ByteBuffer): Endpoint {
1325
+ return Endpoint(
1326
+ FfiConverterString.read(buf),
1327
+ FfiConverterString.read(buf),
1328
+ )
1329
+ }
1330
+
1331
+ override fun allocationSize(value: Endpoint) = (
1332
+ FfiConverterString.allocationSize(value.`baseUrl`) +
1333
+ FfiConverterString.allocationSize(value.`apiKey`)
1334
+ )
1335
+
1336
+ override fun write(value: Endpoint, buf: ByteBuffer) {
1337
+ FfiConverterString.write(value.`baseUrl`, buf)
1338
+ FfiConverterString.write(value.`apiKey`, buf)
1339
+ }
1340
+ }
1341
+
1342
+
1343
+
1344
+ data class Endpoints (
1345
+ var `rpc`: Endpoint,
1346
+ var `bundler`: Endpoint,
1347
+ var `paymaster`: Endpoint
1348
+ ) {
1349
+
1350
+ companion object
1351
+ }
1352
+
1353
+ /**
1354
+ * @suppress
1355
+ */
1356
+ public object FfiConverterTypeEndpoints: FfiConverterRustBuffer<Endpoints> {
1357
+ override fun read(buf: ByteBuffer): Endpoints {
1358
+ return Endpoints(
1359
+ FfiConverterTypeEndpoint.read(buf),
1360
+ FfiConverterTypeEndpoint.read(buf),
1361
+ FfiConverterTypeEndpoint.read(buf),
1362
+ )
1363
+ }
1364
+
1365
+ override fun allocationSize(value: Endpoints) = (
1366
+ FfiConverterTypeEndpoint.allocationSize(value.`rpc`) +
1367
+ FfiConverterTypeEndpoint.allocationSize(value.`bundler`) +
1368
+ FfiConverterTypeEndpoint.allocationSize(value.`paymaster`)
1369
+ )
1370
+
1371
+ override fun write(value: Endpoints, buf: ByteBuffer) {
1372
+ FfiConverterTypeEndpoint.write(value.`rpc`, buf)
1373
+ FfiConverterTypeEndpoint.write(value.`bundler`, buf)
1374
+ FfiConverterTypeEndpoint.write(value.`paymaster`, buf)
1375
+ }
1376
+ }
1377
+
1378
+
1379
+
1380
+ data class FundingMetadata (
1381
+ var `chainId`: kotlin.String,
1382
+ var `tokenContract`: Address,
1383
+ var `symbol`: kotlin.String,
1384
+ var `amount`: kotlin.String
1385
+ ) {
1386
+
1387
+ companion object
1388
+ }
1389
+
1390
+ /**
1391
+ * @suppress
1392
+ */
1393
+ public object FfiConverterTypeFundingMetadata: FfiConverterRustBuffer<FundingMetadata> {
1394
+ override fun read(buf: ByteBuffer): FundingMetadata {
1395
+ return FundingMetadata(
1396
+ FfiConverterString.read(buf),
1397
+ FfiConverterTypeAddress.read(buf),
1398
+ FfiConverterString.read(buf),
1399
+ FfiConverterString.read(buf),
1400
+ )
1401
+ }
1402
+
1403
+ override fun allocationSize(value: FundingMetadata) = (
1404
+ FfiConverterString.allocationSize(value.`chainId`) +
1405
+ FfiConverterTypeAddress.allocationSize(value.`tokenContract`) +
1406
+ FfiConverterString.allocationSize(value.`symbol`) +
1407
+ FfiConverterString.allocationSize(value.`amount`)
1408
+ )
1409
+
1410
+ override fun write(value: FundingMetadata, buf: ByteBuffer) {
1411
+ FfiConverterString.write(value.`chainId`, buf)
1412
+ FfiConverterTypeAddress.write(value.`tokenContract`, buf)
1413
+ FfiConverterString.write(value.`symbol`, buf)
1414
+ FfiConverterString.write(value.`amount`, buf)
1415
+ }
1416
+ }
1417
+
1418
+
1419
+
1420
+ data class Metadata (
1421
+ var `fundingFrom`: List<FundingMetadata>,
1422
+ var `checkIn`: kotlin.ULong
1423
+ ) {
1424
+
1425
+ companion object
1426
+ }
1427
+
1428
+ /**
1429
+ * @suppress
1430
+ */
1431
+ public object FfiConverterTypeMetadata: FfiConverterRustBuffer<Metadata> {
1432
+ override fun read(buf: ByteBuffer): Metadata {
1433
+ return Metadata(
1434
+ FfiConverterSequenceTypeFundingMetadata.read(buf),
1435
+ FfiConverterULong.read(buf),
1436
+ )
1437
+ }
1438
+
1439
+ override fun allocationSize(value: Metadata) = (
1440
+ FfiConverterSequenceTypeFundingMetadata.allocationSize(value.`fundingFrom`) +
1441
+ FfiConverterULong.allocationSize(value.`checkIn`)
1442
+ )
1443
+
1444
+ override fun write(value: Metadata, buf: ByteBuffer) {
1445
+ FfiConverterSequenceTypeFundingMetadata.write(value.`fundingFrom`, buf)
1446
+ FfiConverterULong.write(value.`checkIn`, buf)
1447
+ }
1448
+ }
1449
+
1450
+
1451
+
1452
+ data class RouteResponseAvailable (
1453
+ var `orchestrationId`: kotlin.String,
1454
+ var `initialTransaction`: Transaction,
1455
+ var `transactions`: List<Transaction>,
1456
+ var `metadata`: Metadata
1457
+ ) {
1458
+
1459
+ companion object
1460
+ }
1461
+
1462
+ /**
1463
+ * @suppress
1464
+ */
1465
+ public object FfiConverterTypeRouteResponseAvailable: FfiConverterRustBuffer<RouteResponseAvailable> {
1466
+ override fun read(buf: ByteBuffer): RouteResponseAvailable {
1467
+ return RouteResponseAvailable(
1468
+ FfiConverterString.read(buf),
1469
+ FfiConverterTypeTransaction.read(buf),
1470
+ FfiConverterSequenceTypeTransaction.read(buf),
1471
+ FfiConverterTypeMetadata.read(buf),
1472
+ )
1473
+ }
1474
+
1475
+ override fun allocationSize(value: RouteResponseAvailable) = (
1476
+ FfiConverterString.allocationSize(value.`orchestrationId`) +
1477
+ FfiConverterTypeTransaction.allocationSize(value.`initialTransaction`) +
1478
+ FfiConverterSequenceTypeTransaction.allocationSize(value.`transactions`) +
1479
+ FfiConverterTypeMetadata.allocationSize(value.`metadata`)
1480
+ )
1481
+
1482
+ override fun write(value: RouteResponseAvailable, buf: ByteBuffer) {
1483
+ FfiConverterString.write(value.`orchestrationId`, buf)
1484
+ FfiConverterTypeTransaction.write(value.`initialTransaction`, buf)
1485
+ FfiConverterSequenceTypeTransaction.write(value.`transactions`, buf)
1486
+ FfiConverterTypeMetadata.write(value.`metadata`, buf)
1487
+ }
1488
+ }
1489
+
1490
+
1491
+
1492
+ /**
1493
+ * Bridging check error response that should be returned as a normal HTTP 200
1494
+ * response
1495
+ */
1496
+ data class RouteResponseError (
1497
+ var `error`: BridgingError
1498
+ ) {
1499
+
1500
+ companion object
1501
+ }
1502
+
1503
+ /**
1504
+ * @suppress
1505
+ */
1506
+ public object FfiConverterTypeRouteResponseError: FfiConverterRustBuffer<RouteResponseError> {
1507
+ override fun read(buf: ByteBuffer): RouteResponseError {
1508
+ return RouteResponseError(
1509
+ FfiConverterTypeBridgingError.read(buf),
1510
+ )
1511
+ }
1512
+
1513
+ override fun allocationSize(value: RouteResponseError) = (
1514
+ FfiConverterTypeBridgingError.allocationSize(value.`error`)
1515
+ )
1516
+
1517
+ override fun write(value: RouteResponseError, buf: ByteBuffer) {
1518
+ FfiConverterTypeBridgingError.write(value.`error`, buf)
1519
+ }
1520
+ }
1521
+
1522
+
1523
+
1524
+ data class RouteResponseNotRequired (
1525
+ var `initialTransaction`: Transaction,
1526
+ var `transactions`: List<Transaction>
1527
+ ) {
1528
+
1529
+ companion object
1530
+ }
1531
+
1532
+ /**
1533
+ * @suppress
1534
+ */
1535
+ public object FfiConverterTypeRouteResponseNotRequired: FfiConverterRustBuffer<RouteResponseNotRequired> {
1536
+ override fun read(buf: ByteBuffer): RouteResponseNotRequired {
1537
+ return RouteResponseNotRequired(
1538
+ FfiConverterTypeTransaction.read(buf),
1539
+ FfiConverterSequenceTypeTransaction.read(buf),
1540
+ )
1541
+ }
1542
+
1543
+ override fun allocationSize(value: RouteResponseNotRequired) = (
1544
+ FfiConverterTypeTransaction.allocationSize(value.`initialTransaction`) +
1545
+ FfiConverterSequenceTypeTransaction.allocationSize(value.`transactions`)
1546
+ )
1547
+
1548
+ override fun write(value: RouteResponseNotRequired, buf: ByteBuffer) {
1549
+ FfiConverterTypeTransaction.write(value.`initialTransaction`, buf)
1550
+ FfiConverterSequenceTypeTransaction.write(value.`transactions`, buf)
1551
+ }
1552
+ }
1553
+
1554
+
1555
+
1556
+ data class StatusResponseCompleted (
1557
+ var `createdAt`: kotlin.ULong
1558
+ ) {
1559
+
1560
+ companion object
1561
+ }
1562
+
1563
+ /**
1564
+ * @suppress
1565
+ */
1566
+ public object FfiConverterTypeStatusResponseCompleted: FfiConverterRustBuffer<StatusResponseCompleted> {
1567
+ override fun read(buf: ByteBuffer): StatusResponseCompleted {
1568
+ return StatusResponseCompleted(
1569
+ FfiConverterULong.read(buf),
1570
+ )
1571
+ }
1572
+
1573
+ override fun allocationSize(value: StatusResponseCompleted) = (
1574
+ FfiConverterULong.allocationSize(value.`createdAt`)
1575
+ )
1576
+
1577
+ override fun write(value: StatusResponseCompleted, buf: ByteBuffer) {
1578
+ FfiConverterULong.write(value.`createdAt`, buf)
1579
+ }
1580
+ }
1581
+
1582
+
1583
+
1584
+ data class StatusResponseError (
1585
+ var `createdAt`: kotlin.ULong,
1586
+ var `error`: kotlin.String
1587
+ ) {
1588
+
1589
+ companion object
1590
+ }
1591
+
1592
+ /**
1593
+ * @suppress
1594
+ */
1595
+ public object FfiConverterTypeStatusResponseError: FfiConverterRustBuffer<StatusResponseError> {
1596
+ override fun read(buf: ByteBuffer): StatusResponseError {
1597
+ return StatusResponseError(
1598
+ FfiConverterULong.read(buf),
1599
+ FfiConverterString.read(buf),
1600
+ )
1601
+ }
1602
+
1603
+ override fun allocationSize(value: StatusResponseError) = (
1604
+ FfiConverterULong.allocationSize(value.`createdAt`) +
1605
+ FfiConverterString.allocationSize(value.`error`)
1606
+ )
1607
+
1608
+ override fun write(value: StatusResponseError, buf: ByteBuffer) {
1609
+ FfiConverterULong.write(value.`createdAt`, buf)
1610
+ FfiConverterString.write(value.`error`, buf)
1611
+ }
1612
+ }
1613
+
1614
+
1615
+
1616
+ data class StatusResponsePending (
1617
+ var `createdAt`: kotlin.ULong,
1618
+ /**
1619
+ * Polling interval in ms for the client
1620
+ */
1621
+ var `checkIn`: kotlin.ULong
1622
+ ) {
1623
+
1624
+ companion object
1625
+ }
1626
+
1627
+ /**
1628
+ * @suppress
1629
+ */
1630
+ public object FfiConverterTypeStatusResponsePending: FfiConverterRustBuffer<StatusResponsePending> {
1631
+ override fun read(buf: ByteBuffer): StatusResponsePending {
1632
+ return StatusResponsePending(
1633
+ FfiConverterULong.read(buf),
1634
+ FfiConverterULong.read(buf),
1635
+ )
1636
+ }
1637
+
1638
+ override fun allocationSize(value: StatusResponsePending) = (
1639
+ FfiConverterULong.allocationSize(value.`createdAt`) +
1640
+ FfiConverterULong.allocationSize(value.`checkIn`)
1641
+ )
1642
+
1643
+ override fun write(value: StatusResponsePending, buf: ByteBuffer) {
1644
+ FfiConverterULong.write(value.`createdAt`, buf)
1645
+ FfiConverterULong.write(value.`checkIn`, buf)
1646
+ }
1647
+ }
1648
+
1649
+
1650
+
1651
+ data class Transaction (
1652
+ var `from`: Address,
1653
+ var `to`: Address,
1654
+ var `value`: U256,
1655
+ var `gas`: U64,
1656
+ var `data`: Bytes,
1657
+ var `nonce`: U64,
1658
+ var `chainId`: kotlin.String,
1659
+ var `gasPrice`: U256,
1660
+ var `maxFeePerGas`: U256,
1661
+ var `maxPriorityFeePerGas`: U256
1662
+ ) {
1663
+
1664
+ companion object
1665
+ }
1666
+
1667
+ /**
1668
+ * @suppress
1669
+ */
1670
+ public object FfiConverterTypeTransaction: FfiConverterRustBuffer<Transaction> {
1671
+ override fun read(buf: ByteBuffer): Transaction {
1672
+ return Transaction(
1673
+ FfiConverterTypeAddress.read(buf),
1674
+ FfiConverterTypeAddress.read(buf),
1675
+ FfiConverterTypeU256.read(buf),
1676
+ FfiConverterTypeU64.read(buf),
1677
+ FfiConverterTypeBytes.read(buf),
1678
+ FfiConverterTypeU64.read(buf),
1679
+ FfiConverterString.read(buf),
1680
+ FfiConverterTypeU256.read(buf),
1681
+ FfiConverterTypeU256.read(buf),
1682
+ FfiConverterTypeU256.read(buf),
1683
+ )
1684
+ }
1685
+
1686
+ override fun allocationSize(value: Transaction) = (
1687
+ FfiConverterTypeAddress.allocationSize(value.`from`) +
1688
+ FfiConverterTypeAddress.allocationSize(value.`to`) +
1689
+ FfiConverterTypeU256.allocationSize(value.`value`) +
1690
+ FfiConverterTypeU64.allocationSize(value.`gas`) +
1691
+ FfiConverterTypeBytes.allocationSize(value.`data`) +
1692
+ FfiConverterTypeU64.allocationSize(value.`nonce`) +
1693
+ FfiConverterString.allocationSize(value.`chainId`) +
1694
+ FfiConverterTypeU256.allocationSize(value.`gasPrice`) +
1695
+ FfiConverterTypeU256.allocationSize(value.`maxFeePerGas`) +
1696
+ FfiConverterTypeU256.allocationSize(value.`maxPriorityFeePerGas`)
1697
+ )
1698
+
1699
+ override fun write(value: Transaction, buf: ByteBuffer) {
1700
+ FfiConverterTypeAddress.write(value.`from`, buf)
1701
+ FfiConverterTypeAddress.write(value.`to`, buf)
1702
+ FfiConverterTypeU256.write(value.`value`, buf)
1703
+ FfiConverterTypeU64.write(value.`gas`, buf)
1704
+ FfiConverterTypeBytes.write(value.`data`, buf)
1705
+ FfiConverterTypeU64.write(value.`nonce`, buf)
1706
+ FfiConverterString.write(value.`chainId`, buf)
1707
+ FfiConverterTypeU256.write(value.`gasPrice`, buf)
1708
+ FfiConverterTypeU256.write(value.`maxFeePerGas`, buf)
1709
+ FfiConverterTypeU256.write(value.`maxPriorityFeePerGas`, buf)
1710
+ }
1711
+ }
1712
+
1713
+
1714
+
1715
+
1716
+ enum class BridgingError {
1717
+
1718
+ NO_ROUTES_AVAILABLE,
1719
+ INSUFFICIENT_FUNDS,
1720
+ INSUFFICIENT_GAS_FUNDS;
1721
+ companion object
1722
+ }
1723
+
1724
+
1725
+ /**
1726
+ * @suppress
1727
+ */
1728
+ public object FfiConverterTypeBridgingError: FfiConverterRustBuffer<BridgingError> {
1729
+ override fun read(buf: ByteBuffer) = try {
1730
+ BridgingError.values()[buf.getInt() - 1]
1731
+ } catch (e: IndexOutOfBoundsException) {
1732
+ throw RuntimeException("invalid enum value, something is very wrong!!", e)
1733
+ }
1734
+
1735
+ override fun allocationSize(value: BridgingError) = 4UL
1736
+
1737
+ override fun write(value: BridgingError, buf: ByteBuffer) {
1738
+ buf.putInt(value.ordinal + 1)
1739
+ }
1740
+ }
1741
+
1742
+
1743
+
1744
+
1745
+
1746
+ sealed class RouteResponse {
1747
+
1748
+ data class Success(
1749
+ val v1: RouteResponseSuccess) : RouteResponse() {
1750
+ companion object
1751
+ }
1752
+
1753
+ data class Error(
1754
+ val v1: RouteResponseError) : RouteResponse() {
1755
+ companion object
1756
+ }
1757
+
1758
+
1759
+
1760
+ companion object
1761
+ }
1762
+
1763
+ /**
1764
+ * @suppress
1765
+ */
1766
+ public object FfiConverterTypeRouteResponse : FfiConverterRustBuffer<RouteResponse>{
1767
+ override fun read(buf: ByteBuffer): RouteResponse {
1768
+ return when(buf.getInt()) {
1769
+ 1 -> RouteResponse.Success(
1770
+ FfiConverterTypeRouteResponseSuccess.read(buf),
1771
+ )
1772
+ 2 -> RouteResponse.Error(
1773
+ FfiConverterTypeRouteResponseError.read(buf),
1774
+ )
1775
+ else -> throw RuntimeException("invalid enum value, something is very wrong!!")
1776
+ }
1777
+ }
1778
+
1779
+ override fun allocationSize(value: RouteResponse) = when(value) {
1780
+ is RouteResponse.Success -> {
1781
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
1782
+ (
1783
+ 4UL
1784
+ + FfiConverterTypeRouteResponseSuccess.allocationSize(value.v1)
1785
+ )
1786
+ }
1787
+ is RouteResponse.Error -> {
1788
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
1789
+ (
1790
+ 4UL
1791
+ + FfiConverterTypeRouteResponseError.allocationSize(value.v1)
1792
+ )
1793
+ }
1794
+ }
1795
+
1796
+ override fun write(value: RouteResponse, buf: ByteBuffer) {
1797
+ when(value) {
1798
+ is RouteResponse.Success -> {
1799
+ buf.putInt(1)
1800
+ FfiConverterTypeRouteResponseSuccess.write(value.v1, buf)
1801
+ Unit
1802
+ }
1803
+ is RouteResponse.Error -> {
1804
+ buf.putInt(2)
1805
+ FfiConverterTypeRouteResponseError.write(value.v1, buf)
1806
+ Unit
1807
+ }
1808
+ }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
1809
+ }
1810
+ }
1811
+
1812
+
1813
+
1814
+
1815
+
1816
+ sealed class RouteResponseSuccess {
1817
+
1818
+ data class Available(
1819
+ val v1: RouteResponseAvailable) : RouteResponseSuccess() {
1820
+ companion object
1821
+ }
1822
+
1823
+ data class NotRequired(
1824
+ val v1: RouteResponseNotRequired) : RouteResponseSuccess() {
1825
+ companion object
1826
+ }
1827
+
1828
+
1829
+
1830
+ companion object
1831
+ }
1832
+
1833
+ /**
1834
+ * @suppress
1835
+ */
1836
+ public object FfiConverterTypeRouteResponseSuccess : FfiConverterRustBuffer<RouteResponseSuccess>{
1837
+ override fun read(buf: ByteBuffer): RouteResponseSuccess {
1838
+ return when(buf.getInt()) {
1839
+ 1 -> RouteResponseSuccess.Available(
1840
+ FfiConverterTypeRouteResponseAvailable.read(buf),
1841
+ )
1842
+ 2 -> RouteResponseSuccess.NotRequired(
1843
+ FfiConverterTypeRouteResponseNotRequired.read(buf),
1844
+ )
1845
+ else -> throw RuntimeException("invalid enum value, something is very wrong!!")
1846
+ }
1847
+ }
1848
+
1849
+ override fun allocationSize(value: RouteResponseSuccess) = when(value) {
1850
+ is RouteResponseSuccess.Available -> {
1851
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
1852
+ (
1853
+ 4UL
1854
+ + FfiConverterTypeRouteResponseAvailable.allocationSize(value.v1)
1855
+ )
1856
+ }
1857
+ is RouteResponseSuccess.NotRequired -> {
1858
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
1859
+ (
1860
+ 4UL
1861
+ + FfiConverterTypeRouteResponseNotRequired.allocationSize(value.v1)
1862
+ )
1863
+ }
1864
+ }
1865
+
1866
+ override fun write(value: RouteResponseSuccess, buf: ByteBuffer) {
1867
+ when(value) {
1868
+ is RouteResponseSuccess.Available -> {
1869
+ buf.putInt(1)
1870
+ FfiConverterTypeRouteResponseAvailable.write(value.v1, buf)
1871
+ Unit
1872
+ }
1873
+ is RouteResponseSuccess.NotRequired -> {
1874
+ buf.putInt(2)
1875
+ FfiConverterTypeRouteResponseNotRequired.write(value.v1, buf)
1876
+ Unit
1877
+ }
1878
+ }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
1879
+ }
1880
+ }
1881
+
1882
+
1883
+
1884
+
1885
+
1886
+ sealed class StatusResponse {
1887
+
1888
+ data class Pending(
1889
+ val v1: StatusResponsePending) : StatusResponse() {
1890
+ companion object
1891
+ }
1892
+
1893
+ data class Completed(
1894
+ val v1: StatusResponseCompleted) : StatusResponse() {
1895
+ companion object
1896
+ }
1897
+
1898
+ data class Error(
1899
+ val v1: StatusResponseError) : StatusResponse() {
1900
+ companion object
1901
+ }
1902
+
1903
+
1904
+
1905
+ companion object
1906
+ }
1907
+
1908
+ /**
1909
+ * @suppress
1910
+ */
1911
+ public object FfiConverterTypeStatusResponse : FfiConverterRustBuffer<StatusResponse>{
1912
+ override fun read(buf: ByteBuffer): StatusResponse {
1913
+ return when(buf.getInt()) {
1914
+ 1 -> StatusResponse.Pending(
1915
+ FfiConverterTypeStatusResponsePending.read(buf),
1916
+ )
1917
+ 2 -> StatusResponse.Completed(
1918
+ FfiConverterTypeStatusResponseCompleted.read(buf),
1919
+ )
1920
+ 3 -> StatusResponse.Error(
1921
+ FfiConverterTypeStatusResponseError.read(buf),
1922
+ )
1923
+ else -> throw RuntimeException("invalid enum value, something is very wrong!!")
1924
+ }
1925
+ }
1926
+
1927
+ override fun allocationSize(value: StatusResponse) = when(value) {
1928
+ is StatusResponse.Pending -> {
1929
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
1930
+ (
1931
+ 4UL
1932
+ + FfiConverterTypeStatusResponsePending.allocationSize(value.v1)
1933
+ )
1934
+ }
1935
+ is StatusResponse.Completed -> {
1936
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
1937
+ (
1938
+ 4UL
1939
+ + FfiConverterTypeStatusResponseCompleted.allocationSize(value.v1)
1940
+ )
1941
+ }
1942
+ is StatusResponse.Error -> {
1943
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
1944
+ (
1945
+ 4UL
1946
+ + FfiConverterTypeStatusResponseError.allocationSize(value.v1)
1947
+ )
1948
+ }
1949
+ }
1950
+
1951
+ override fun write(value: StatusResponse, buf: ByteBuffer) {
1952
+ when(value) {
1953
+ is StatusResponse.Pending -> {
1954
+ buf.putInt(1)
1955
+ FfiConverterTypeStatusResponsePending.write(value.v1, buf)
1956
+ Unit
1957
+ }
1958
+ is StatusResponse.Completed -> {
1959
+ buf.putInt(2)
1960
+ FfiConverterTypeStatusResponseCompleted.write(value.v1, buf)
1961
+ Unit
1962
+ }
1963
+ is StatusResponse.Error -> {
1964
+ buf.putInt(3)
1965
+ FfiConverterTypeStatusResponseError.write(value.v1, buf)
1966
+ Unit
1967
+ }
1968
+ }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
1969
+ }
1970
+ }
1971
+
1972
+
1973
+
1974
+
1975
+
1976
+
1977
+ /**
1978
+ * @suppress
1979
+ */
1980
+ public object FfiConverterSequenceTypeFundingMetadata: FfiConverterRustBuffer<List<FundingMetadata>> {
1981
+ override fun read(buf: ByteBuffer): List<FundingMetadata> {
1982
+ val len = buf.getInt()
1983
+ return List<FundingMetadata>(len) {
1984
+ FfiConverterTypeFundingMetadata.read(buf)
1985
+ }
1986
+ }
1987
+
1988
+ override fun allocationSize(value: List<FundingMetadata>): ULong {
1989
+ val sizeForLength = 4UL
1990
+ val sizeForItems = value.map { FfiConverterTypeFundingMetadata.allocationSize(it) }.sum()
1991
+ return sizeForLength + sizeForItems
1992
+ }
1993
+
1994
+ override fun write(value: List<FundingMetadata>, buf: ByteBuffer) {
1995
+ buf.putInt(value.size)
1996
+ value.iterator().forEach {
1997
+ FfiConverterTypeFundingMetadata.write(it, buf)
1998
+ }
1999
+ }
2000
+ }
2001
+
2002
+
2003
+
2004
+
2005
+ /**
2006
+ * @suppress
2007
+ */
2008
+ public object FfiConverterSequenceTypeTransaction: FfiConverterRustBuffer<List<Transaction>> {
2009
+ override fun read(buf: ByteBuffer): List<Transaction> {
2010
+ val len = buf.getInt()
2011
+ return List<Transaction>(len) {
2012
+ FfiConverterTypeTransaction.read(buf)
2013
+ }
2014
+ }
2015
+
2016
+ override fun allocationSize(value: List<Transaction>): ULong {
2017
+ val sizeForLength = 4UL
2018
+ val sizeForItems = value.map { FfiConverterTypeTransaction.allocationSize(it) }.sum()
2019
+ return sizeForLength + sizeForItems
2020
+ }
2021
+
2022
+ override fun write(value: List<Transaction>, buf: ByteBuffer) {
2023
+ buf.putInt(value.size)
2024
+ value.iterator().forEach {
2025
+ FfiConverterTypeTransaction.write(it, buf)
2026
+ }
2027
+ }
2028
+ }
2029
+
2030
+
2031
+
2032
+ /**
2033
+ * Typealias from the type name used in the UDL file to the builtin type. This
2034
+ * is needed because the UDL type name is used in function/method signatures.
2035
+ * It's also what we have an external type that references a custom type.
2036
+ */
2037
+ public typealias Address = kotlin.String
2038
+ public typealias FfiConverterTypeAddress = FfiConverterString
2039
+
2040
+
2041
+
2042
+ /**
2043
+ * Typealias from the type name used in the UDL file to the builtin type. This
2044
+ * is needed because the UDL type name is used in function/method signatures.
2045
+ * It's also what we have an external type that references a custom type.
2046
+ */
2047
+ public typealias Bytes = kotlin.String
2048
+ public typealias FfiConverterTypeBytes = FfiConverterString
2049
+
2050
+
2051
+
2052
+ /**
2053
+ * Typealias from the type name used in the UDL file to the builtin type. This
2054
+ * is needed because the UDL type name is used in function/method signatures.
2055
+ * It's also what we have an external type that references a custom type.
2056
+ */
2057
+ public typealias U256 = kotlin.String
2058
+ public typealias FfiConverterTypeU256 = FfiConverterString
2059
+
2060
+
2061
+
2062
+ /**
2063
+ * Typealias from the type name used in the UDL file to the builtin type. This
2064
+ * is needed because the UDL type name is used in function/method signatures.
2065
+ * It's also what we have an external type that references a custom type.
2066
+ */
2067
+ public typealias U64 = kotlin.String
2068
+ public typealias FfiConverterTypeU64 = FfiConverterString
2069
+