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