Skip to content

Commit

Permalink
bump sphinx
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Jan 25, 2024
1 parent b9c7e61 commit 0fc08f6
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
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 = "f2a1645ecb8af117f78de9790124173aa4996774", features = [
sphinx = { git = "https://github.com/stakwork/sphinx", rev = "ca57734079b57a0b66c980fb5874a3ffb96d68a1", features = [
"msg",
"bindings",
] }
Expand Down
2 changes: 2 additions & 0 deletions sphinx-ffi/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub fn send(
my_alias: String,
my_img: String,
amt_msat: u64,
is_tribe: bool,
) -> Result<RunReturn> {
Ok(bindings::send(
&seed,
Expand All @@ -158,6 +159,7 @@ pub fn send(
&my_alias,
&my_img_opt(&my_img),
amt_msat,
is_tribe,
)
.map_err(|e| SphinxError::SendFailed { r: e.to_string() })?
.into())
Expand Down
28 changes: 25 additions & 3 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,27 @@ fileprivate struct FfiConverterUInt64: FfiConverterPrimitive {
}
}

fileprivate struct FfiConverterBool : FfiConverter {
typealias FfiType = Int8
typealias SwiftType = Bool

public static func lift(_ value: Int8) throws -> Bool {
return value != 0
}

public static func lower(_ value: Bool) -> Int8 {
return value ? 1 : 0
}

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool {
return try lift(readInt(&buf))
}

public static func write(_ value: Bool, into buf: inout [UInt8]) {
writeInt(&buf, lower(value))
}
}

fileprivate struct FfiConverterString: FfiConverter {
typealias SwiftType = String
typealias FfiType = RustBuffer
Expand Down Expand Up @@ -1571,7 +1592,7 @@ public func `handle`(`topic`: String, `payload`: Data, `seed`: String, `uniqueTi
)
}

public func `send`(`seed`: String, `uniqueTime`: String, `to`: String, `msgType`: UInt8, `msgJson`: String, `state`: Data, `myAlias`: String, `myImg`: String, `amtMsat`: UInt64) throws -> RunReturn {
public func `send`(`seed`: String, `uniqueTime`: String, `to`: String, `msgType`: UInt8, `msgJson`: String, `state`: Data, `myAlias`: String, `myImg`: String, `amtMsat`: UInt64, `isTribe`: Bool = false) throws -> RunReturn {
return try FfiConverterTypeRunReturn.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_send(
Expand All @@ -1583,7 +1604,8 @@ public func `send`(`seed`: String, `uniqueTime`: String, `to`: String, `msgType`
FfiConverterData.lower(`state`),
FfiConverterString.lower(`myAlias`),
FfiConverterString.lower(`myImg`),
FfiConverterUInt64.lower(`amtMsat`),$0)
FfiConverterUInt64.lower(`amtMsat`),
FfiConverterBool.lower(`isTribe`),$0)
}
)
}
Expand Down Expand Up @@ -1784,7 +1806,7 @@ private var initializationResult: InitializationResult {
if (uniffi_sphinxrs_checksum_func_handle() != 58131) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_send() != 22190) {
if (uniffi_sphinxrs_checksum_func_send() != 56750) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_make_media_token() != 53931) {
Expand Down
2 changes: 1 addition & 1 deletion sphinx-ffi/src/sphinxrs.udl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace sphinxrs {
[Throws=SphinxError]
RunReturn handle(string topic, bytes payload, string seed, string unique_time, bytes state, string my_alias, string my_img);
[Throws=SphinxError]
RunReturn send(string seed, string unique_time, string to, u8 msg_type, string msg_json, bytes state, string my_alias, string my_img, u64 amt_msat);
RunReturn send(string seed, string unique_time, string to, u8 msg_type, string msg_json, bytes state, string my_alias, string my_img, u64 amt_msat, optional boolean is_tribe = false);
[Throws=SphinxError]
string make_media_token(string seed, string unique_time, bytes state, string host, string muid, string to, u32 expiry);
[Throws=SphinxError]
Expand Down
2 changes: 1 addition & 1 deletion sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ RustBuffer uniffi_sphinxrs_fn_func_fetch_msgs(RustBuffer seed, RustBuffer unique
);
RustBuffer uniffi_sphinxrs_fn_func_handle(RustBuffer topic, RustBuffer payload, RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer my_alias, RustBuffer my_img, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_send(RustBuffer seed, RustBuffer unique_time, RustBuffer to, uint8_t msg_type, RustBuffer msg_json, RustBuffer state, RustBuffer my_alias, RustBuffer my_img, uint64_t amt_msat, RustCallStatus *_Nonnull out_status
RustBuffer uniffi_sphinxrs_fn_func_send(RustBuffer seed, RustBuffer unique_time, RustBuffer to, uint8_t msg_type, RustBuffer msg_json, RustBuffer state, RustBuffer my_alias, RustBuffer my_img, uint64_t amt_msat, int8_t is_tribe, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_make_media_token(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer host, RustBuffer muid, RustBuffer to, uint32_t expiry, RustCallStatus *_Nonnull out_status
);
Expand Down
28 changes: 24 additions & 4 deletions sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ internal interface _UniFFILib : Library {
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_handle(`topic`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`myAlias`: RustBuffer.ByValue,`myImg`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_send(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`to`: RustBuffer.ByValue,`msgType`: Byte,`msgJson`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`myAlias`: RustBuffer.ByValue,`myImg`: RustBuffer.ByValue,`amtMsat`: Long,_uniffi_out_err: RustCallStatus,
fun uniffi_sphinxrs_fn_func_send(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`to`: RustBuffer.ByValue,`msgType`: Byte,`msgJson`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`myAlias`: RustBuffer.ByValue,`myImg`: RustBuffer.ByValue,`amtMsat`: Long,`isTribe`: Byte,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_make_media_token(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`host`: RustBuffer.ByValue,`muid`: RustBuffer.ByValue,`to`: RustBuffer.ByValue,`expiry`: Int,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
Expand Down Expand Up @@ -665,7 +665,7 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_sphinxrs_checksum_func_handle() != 58131.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_send() != 22190.toShort()) {
if (lib.uniffi_sphinxrs_checksum_func_send() != 56750.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_make_media_token() != 53931.toShort()) {
Expand Down Expand Up @@ -768,6 +768,26 @@ public object FfiConverterULong: FfiConverter<ULong, Long> {
}
}

public object FfiConverterBoolean: FfiConverter<Boolean, Byte> {
override fun lift(value: Byte): Boolean {
return value.toInt() != 0
}

override fun read(buf: ByteBuffer): Boolean {
return lift(buf.get())
}

override fun lower(value: Boolean): Byte {
return if (value) 1.toByte() else 0.toByte()
}

override fun allocationSize(value: Boolean) = 1

override fun write(value: Boolean, buf: ByteBuffer) {
buf.put(lower(value))
}
}

public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
// Note: we don't inherit from FfiConverterRustBuffer, because we use a
// special encoding when lowering/lifting. We can use `RustBuffer.len` to
Expand Down Expand Up @@ -2079,10 +2099,10 @@ fun `handle`(`topic`: String, `payload`: ByteArray, `seed`: String, `uniqueTime`

@Throws(SphinxException::class)

fun `send`(`seed`: String, `uniqueTime`: String, `to`: String, `msgType`: UByte, `msgJson`: String, `state`: ByteArray, `myAlias`: String, `myImg`: String, `amtMsat`: ULong): RunReturn {
fun `send`(`seed`: String, `uniqueTime`: String, `to`: String, `msgType`: UByte, `msgJson`: String, `state`: ByteArray, `myAlias`: String, `myImg`: String, `amtMsat`: ULong, `isTribe`: Boolean = false): RunReturn {
return FfiConverterTypeRunReturn.lift(
rustCallWithError(SphinxException) { _status ->
_UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_send(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterString.lower(`to`),FfiConverterUByte.lower(`msgType`),FfiConverterString.lower(`msgJson`),FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`myAlias`),FfiConverterString.lower(`myImg`),FfiConverterULong.lower(`amtMsat`),_status)
_UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_send(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterString.lower(`to`),FfiConverterUByte.lower(`msgType`),FfiConverterString.lower(`msgJson`),FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`myAlias`),FfiConverterString.lower(`myImg`),FfiConverterULong.lower(`amtMsat`),FfiConverterBoolean.lower(`isTribe`),_status)
})
}

Expand Down

0 comments on commit 0fc08f6

Please sign in to comment.