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