Skip to content

Commit

Permalink
restore
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Mar 11, 2024
1 parent 8b66658 commit dc46a3c
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sphinx-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sphinx-signer = { path = "../signer", default-features = false, features = [
"no-native",
] }
sphinx-glyph = { path = "../glyph", default-features = false }
sphinx = { git = "https://github.com/stakwork/sphinx", rev = "d70cfd194044d792409f5e44e86ea7ece3b60c36", features = [
sphinx = { git = "https://github.com/stakwork/sphinx", rev = "6d1c12cf971549494b0595dd08a53b9f94fceb53", features = [
"msg",
"bindings",
] }
Expand Down
44 changes: 44 additions & 0 deletions sphinx-ffi/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,50 @@ pub fn set_push_token(
)
}

pub fn fetch_msgs_batch(
seed: String,
unique_time: String,
full_state: Vec<u8>,
last_msg_idx: u64,
limit: Option<u32>,
reverse: Option<bool>,
is_restore: Option<bool>,
) -> Result<RunReturn> {
Ok(bindings::fetch_msgs_batch(
&seed,
&unique_time,
&full_state,
last_msg_idx,
limit,
reverse,
is_restore,
)
.map_err(|e| SphinxError::FetchMsgsFailed { r: e.to_string() })?
.into())
}

pub fn fetch_msgs_batch_okkey(
seed: String,
unique_time: String,
full_state: Vec<u8>,
last_msg_idx: u64,
limit: Option<u32>,
reverse: Option<bool>,
is_restore: Option<bool>,
) -> Result<RunReturn> {
Ok(bindings::fetch_msgs_batch_okkey(
&seed,
&unique_time,
&full_state,
last_msg_idx,
limit,
reverse,
is_restore,
)
.map_err(|e| SphinxError::FetchMsgsFailed { r: e.to_string() })?
.into())
}

impl From<bindings::Msg> for Msg {
fn from(rr: bindings::Msg) -> Self {
Msg {
Expand Down
57 changes: 57 additions & 0 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,27 @@ fileprivate struct FfiConverterOptionUInt64: FfiConverterRustBuffer {
}
}

fileprivate struct FfiConverterOptionBool: FfiConverterRustBuffer {
typealias SwiftType = Bool?

public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterBool.write(value, into: &buf)
}

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterBool.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}

fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer {
typealias SwiftType = String?

Expand Down Expand Up @@ -2038,6 +2059,36 @@ public func `setPushToken`(`seed`: String, `uniqueTime`: String, `state`: Data,
)
}

public func `fetchMsgsBatch`(`seed`: String, `uniqueTime`: String, `state`: Data, `lastMsgIdx`: UInt64, `limit`: UInt32?, `reverse`: Bool?, `isRestore`: Bool?) throws -> RunReturn {
return try FfiConverterTypeRunReturn.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_fetch_msgs_batch(
FfiConverterString.lower(`seed`),
FfiConverterString.lower(`uniqueTime`),
FfiConverterData.lower(`state`),
FfiConverterUInt64.lower(`lastMsgIdx`),
FfiConverterOptionUInt32.lower(`limit`),
FfiConverterOptionBool.lower(`reverse`),
FfiConverterOptionBool.lower(`isRestore`),$0)
}
)
}

public func `fetchMsgsBatchOkkey`(`seed`: String, `uniqueTime`: String, `state`: Data, `lastMsgIdx`: UInt64, `limit`: UInt32?, `reverse`: Bool?, `isRestore`: Bool?) throws -> RunReturn {
return try FfiConverterTypeRunReturn.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_fetch_msgs_batch_okkey(
FfiConverterString.lower(`seed`),
FfiConverterString.lower(`uniqueTime`),
FfiConverterData.lower(`state`),
FfiConverterUInt64.lower(`lastMsgIdx`),
FfiConverterOptionUInt32.lower(`limit`),
FfiConverterOptionBool.lower(`reverse`),
FfiConverterOptionBool.lower(`isRestore`),$0)
}
)
}

private enum InitializationResult {
case ok
case contractVersionMismatch
Expand Down Expand Up @@ -2221,6 +2272,12 @@ private var initializationResult: InitializationResult {
if (uniffi_sphinxrs_checksum_func_set_push_token() != 7668) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_fetch_msgs_batch() != 65179) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_fetch_msgs_batch_okkey() != 11004) {
return InitializationResult.apiChecksumMismatch
}

return InitializationResult.ok
}
Expand Down
4 changes: 4 additions & 0 deletions sphinx-ffi/src/sphinxrs.udl
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,8 @@ namespace sphinxrs {
RunReturn get_mutes(string seed, string unique_time, bytes state);
[Throws=SphinxError]
RunReturn set_push_token(string seed, string unique_time, bytes state, string push_token);
[Throws=SphinxError]
RunReturn fetch_msgs_batch(string seed, string unique_time, bytes state, u64 last_msg_idx, u32? limit, boolean? reverse, boolean? is_restore);
[Throws=SphinxError]
RunReturn fetch_msgs_batch_okkey(string seed, string unique_time, bytes state, u64 last_msg_idx, u32? limit, boolean? reverse, boolean? is_restore);
};
10 changes: 10 additions & 0 deletions sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ RustBuffer uniffi_sphinxrs_fn_func_get_mutes(RustBuffer seed, RustBuffer unique_
);
RustBuffer uniffi_sphinxrs_fn_func_set_push_token(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer push_token, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_fetch_msgs_batch(RustBuffer seed, RustBuffer unique_time, RustBuffer state, uint64_t last_msg_idx, RustBuffer limit, RustBuffer reverse, RustBuffer is_restore, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_fetch_msgs_batch_okkey(RustBuffer seed, RustBuffer unique_time, RustBuffer state, uint64_t last_msg_idx, RustBuffer limit, RustBuffer reverse, RustBuffer is_restore, RustCallStatus *_Nonnull out_status
);
RustBuffer ffi_sphinxrs_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
);
RustBuffer ffi_sphinxrs_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status
Expand Down Expand Up @@ -350,6 +354,12 @@ uint16_t uniffi_sphinxrs_checksum_func_get_mutes(void
);
uint16_t uniffi_sphinxrs_checksum_func_set_push_token(void

);
uint16_t uniffi_sphinxrs_checksum_func_fetch_msgs_batch(void

);
uint16_t uniffi_sphinxrs_checksum_func_fetch_msgs_batch_okkey(void

);
uint32_t ffi_sphinxrs_uniffi_contract_version(void

Expand Down
61 changes: 61 additions & 0 deletions sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ internal interface _UniFFILib : Library {
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_set_push_token(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`pushToken`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_fetch_msgs_batch(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`lastMsgIdx`: Long,`limit`: RustBuffer.ByValue,`reverse`: RustBuffer.ByValue,`isRestore`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_fetch_msgs_batch_okkey(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`lastMsgIdx`: Long,`limit`: RustBuffer.ByValue,`reverse`: RustBuffer.ByValue,`isRestore`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun ffi_sphinxrs_rustbuffer_alloc(`size`: Int,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun ffi_sphinxrs_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,_uniffi_out_err: RustCallStatus,
Expand Down Expand Up @@ -596,6 +600,10 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_sphinxrs_checksum_func_set_push_token(
): Short
fun uniffi_sphinxrs_checksum_func_fetch_msgs_batch(
): Short
fun uniffi_sphinxrs_checksum_func_fetch_msgs_batch_okkey(
): Short
fun ffi_sphinxrs_uniffi_contract_version(
): Int

Expand Down Expand Up @@ -781,6 +789,12 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_sphinxrs_checksum_func_set_push_token() != 7668.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_fetch_msgs_batch() != 65179.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_fetch_msgs_batch_okkey() != 11004.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
}

// Public interface members begin here.
Expand Down Expand Up @@ -1895,6 +1909,35 @@ public object FfiConverterOptionalULong: FfiConverterRustBuffer<ULong?> {



public object FfiConverterOptionalBoolean: FfiConverterRustBuffer<Boolean?> {
override fun read(buf: ByteBuffer): Boolean? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterBoolean.read(buf)
}

override fun allocationSize(value: Boolean?): Int {
if (value == null) {
return 1
} else {
return 1 + FfiConverterBoolean.allocationSize(value)
}
}

override fun write(value: Boolean?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterBoolean.write(value, buf)
}
}
}




public object FfiConverterOptionalString: FfiConverterRustBuffer<String?> {
override fun read(buf: ByteBuffer): String? {
if (buf.get().toInt() == 0) {
Expand Down Expand Up @@ -2527,4 +2570,22 @@ fun `setPushToken`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `pu
})
}

@Throws(SphinxException::class)

fun `fetchMsgsBatch`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `lastMsgIdx`: ULong, `limit`: UInt?, `reverse`: Boolean?, `isRestore`: Boolean?): RunReturn {
return FfiConverterTypeRunReturn.lift(
rustCallWithError(SphinxException) { _status ->
_UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_fetch_msgs_batch(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterULong.lower(`lastMsgIdx`),FfiConverterOptionalUInt.lower(`limit`),FfiConverterOptionalBoolean.lower(`reverse`),FfiConverterOptionalBoolean.lower(`isRestore`),_status)
})
}

@Throws(SphinxException::class)

fun `fetchMsgsBatchOkkey`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `lastMsgIdx`: ULong, `limit`: UInt?, `reverse`: Boolean?, `isRestore`: Boolean?): RunReturn {
return FfiConverterTypeRunReturn.lift(
rustCallWithError(SphinxException) { _status ->
_UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_fetch_msgs_batch_okkey(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterULong.lower(`lastMsgIdx`),FfiConverterOptionalUInt.lower(`limit`),FfiConverterOptionalBoolean.lower(`reverse`),FfiConverterOptionalBoolean.lower(`isRestore`),_status)
})
}


0 comments on commit dc46a3c

Please sign in to comment.