Skip to content

Commit

Permalink
delete bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Jun 7, 2024
1 parent 668a640 commit 61d0edf
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 5 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 = "70ba0bd885818b2313dad13aedda8de941c2aba7", features = [
sphinx = { git = "https://github.com/stakwork/sphinx", rev = "0d40771c9a5efcdbd7fe9357bfdc77a44e8ade0a", features = [
"msg",
"bindings",
] }
Expand Down
16 changes: 16 additions & 0 deletions sphinx-ffi/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct RunReturn {
pub payments: Option<String>,
pub payments_total: Option<u64>,
pub tags: Option<String>,
pub deleted_msgs: Option<String>,
}

pub fn set_network(net: String) -> Result<RunReturn> {
Expand Down Expand Up @@ -677,6 +678,20 @@ pub fn get_tags(
)
}

pub fn delete_msgs(
seed: String,
unique_time: String,
full_state: Vec<u8>,
pubkey: Option<String>,
msg_idxs: Option<Vec<u64>>,
) -> Result<RunReturn> {
Ok(
bindings::delete_msgs(&seed, &unique_time, &full_state, pubkey, msg_idxs)
.map_err(|e| SphinxError::SendFailed { r: e.to_string() })?
.into(),
)
}

impl From<bindings::Msg> for Msg {
fn from(rr: bindings::Msg) -> Self {
Msg {
Expand Down Expand Up @@ -740,6 +755,7 @@ impl From<bindings::RunReturn> for RunReturn {
payments: rr.payments,
payments_total: rr.payments_total,
tags: rr.tags,
deleted_msgs: rr.deleted_msgs,
}
}
}
71 changes: 69 additions & 2 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,11 @@ public struct RunReturn {
public var `payments`: String?
public var `paymentsTotal`: UInt64?
public var `tags`: String?
public var `deletedMsgs`: String?

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(`msgs`: [Msg], `msgsTotal`: UInt64?, `msgsCounts`: String?, `subscriptionTopics`: [String], `settleTopic`: String?, `settlePayload`: Data?, `topics`: [String], `payloads`: [Data], `stateMp`: Data?, `stateToDelete`: [String], `newBalance`: UInt64?, `myContactInfo`: String?, `sentStatus`: String?, `settledStatus`: String?, `error`: String?, `newTribe`: String?, `tribeMembers`: String?, `newInvite`: String?, `inviterContactInfo`: String?, `inviterAlias`: String?, `initialTribe`: String?, `lspHost`: String?, `invoice`: String?, `route`: String?, `node`: String?, `lastRead`: String?, `muteLevels`: String?, `payments`: String?, `paymentsTotal`: UInt64?, `tags`: String?) {
public init(`msgs`: [Msg], `msgsTotal`: UInt64?, `msgsCounts`: String?, `subscriptionTopics`: [String], `settleTopic`: String?, `settlePayload`: Data?, `topics`: [String], `payloads`: [Data], `stateMp`: Data?, `stateToDelete`: [String], `newBalance`: UInt64?, `myContactInfo`: String?, `sentStatus`: String?, `settledStatus`: String?, `error`: String?, `newTribe`: String?, `tribeMembers`: String?, `newInvite`: String?, `inviterContactInfo`: String?, `inviterAlias`: String?, `initialTribe`: String?, `lspHost`: String?, `invoice`: String?, `route`: String?, `node`: String?, `lastRead`: String?, `muteLevels`: String?, `payments`: String?, `paymentsTotal`: UInt64?, `tags`: String?, `deletedMsgs`: String?) {
self.`msgs` = `msgs`
self.`msgsTotal` = `msgsTotal`
self.`msgsCounts` = `msgsCounts`
Expand Down Expand Up @@ -746,6 +747,7 @@ public struct RunReturn {
self.`payments` = `payments`
self.`paymentsTotal` = `paymentsTotal`
self.`tags` = `tags`
self.`deletedMsgs` = `deletedMsgs`
}
}

Expand Down Expand Up @@ -842,6 +844,9 @@ extension RunReturn: Equatable, Hashable {
if lhs.`tags` != rhs.`tags` {
return false
}
if lhs.`deletedMsgs` != rhs.`deletedMsgs` {
return false
}
return true
}

Expand Down Expand Up @@ -876,6 +881,7 @@ extension RunReturn: Equatable, Hashable {
hasher.combine(`payments`)
hasher.combine(`paymentsTotal`)
hasher.combine(`tags`)
hasher.combine(`deletedMsgs`)
}
}

Expand Down Expand Up @@ -912,7 +918,8 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer {
`muteLevels`: FfiConverterOptionString.read(from: &buf),
`payments`: FfiConverterOptionString.read(from: &buf),
`paymentsTotal`: FfiConverterOptionUInt64.read(from: &buf),
`tags`: FfiConverterOptionString.read(from: &buf)
`tags`: FfiConverterOptionString.read(from: &buf),
`deletedMsgs`: FfiConverterOptionString.read(from: &buf)
)
}

Expand Down Expand Up @@ -947,6 +954,7 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer {
FfiConverterOptionString.write(value.`payments`, into: &buf)
FfiConverterOptionUInt64.write(value.`paymentsTotal`, into: &buf)
FfiConverterOptionString.write(value.`tags`, into: &buf)
FfiConverterOptionString.write(value.`deletedMsgs`, into: &buf)
}
}

Expand Down Expand Up @@ -1478,6 +1486,49 @@ fileprivate struct FfiConverterOptionData: FfiConverterRustBuffer {
}
}

fileprivate struct FfiConverterOptionSequenceUInt64: FfiConverterRustBuffer {
typealias SwiftType = [UInt64]?

public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterSequenceUInt64.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 FfiConverterSequenceUInt64.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}

fileprivate struct FfiConverterSequenceUInt64: FfiConverterRustBuffer {
typealias SwiftType = [UInt64]

public static func write(_ value: [UInt64], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterUInt64.write(item, into: &buf)
}
}

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [UInt64] {
let len: Int32 = try readInt(&buf)
var seq = [UInt64]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterUInt64.read(from: &buf))
}
return seq
}
}

fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer {
typealias SwiftType = [String]

Expand Down Expand Up @@ -2389,6 +2440,19 @@ public func `getTags`(`seed`: String, `uniqueTime`: String, `state`: Data, `tags
)
}

public func `deleteMsgs`(`seed`: String, `uniqueTime`: String, `state`: Data, `pubkey`: String?, `msgIdxs`: [UInt64]?) throws -> RunReturn {
return try FfiConverterTypeRunReturn.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_delete_msgs(
FfiConverterString.lower(`seed`),
FfiConverterString.lower(`uniqueTime`),
FfiConverterData.lower(`state`),
FfiConverterOptionString.lower(`pubkey`),
FfiConverterOptionSequenceUInt64.lower(`msgIdxs`),$0)
}
)
}

private enum InitializationResult {
case ok
case contractVersionMismatch
Expand Down Expand Up @@ -2611,6 +2675,9 @@ private var initializationResult: InitializationResult {
if (uniffi_sphinxrs_checksum_func_get_tags() != 42493) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_delete_msgs() != 39403) {
return InitializationResult.apiChecksumMismatch
}

return InitializationResult.ok
}
Expand Down
3 changes: 3 additions & 0 deletions sphinx-ffi/src/sphinxrs.udl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ dictionary RunReturn {
string? payments;
u64? payments_total;
string? tags;
string? deleted_msgs;
};

namespace sphinxrs {
Expand Down Expand Up @@ -236,4 +237,6 @@ namespace sphinxrs {
RunReturn fetch_payments(string seed, string unique_time, bytes state, u64? since, u32? limit, u64? scid, boolean? remote_only, u64? min_msat, boolean? reverse);
[Throws=SphinxError]
RunReturn get_tags(string seed, string unique_time, bytes state, sequence<string> tags, string? pubkey);
[Throws=SphinxError]
RunReturn delete_msgs(string seed, string unique_time, bytes state, string? pubkey, sequence<u64>? msg_idxs);
};
5 changes: 5 additions & 0 deletions sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ RustBuffer uniffi_sphinxrs_fn_func_fetch_payments(RustBuffer seed, RustBuffer un
);
RustBuffer uniffi_sphinxrs_fn_func_get_tags(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer tags, RustBuffer pubkey, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_delete_msgs(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer pubkey, RustBuffer msg_idxs, 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 @@ -415,6 +417,9 @@ uint16_t uniffi_sphinxrs_checksum_func_fetch_payments(void
);
uint16_t uniffi_sphinxrs_checksum_func_get_tags(void

);
uint16_t uniffi_sphinxrs_checksum_func_delete_msgs(void

);
uint32_t ffi_sphinxrs_uniffi_contract_version(void

Expand Down
78 changes: 76 additions & 2 deletions sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ internal interface _UniFFILib : Library {
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_get_tags(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`tags`: RustBuffer.ByValue,`pubkey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_delete_msgs(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`pubkey`: RustBuffer.ByValue,`msgIdxs`: 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 @@ -648,6 +650,8 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_sphinxrs_checksum_func_get_tags(
): Short
fun uniffi_sphinxrs_checksum_func_delete_msgs(
): Short
fun ffi_sphinxrs_uniffi_contract_version(
): Int

Expand Down Expand Up @@ -872,6 +876,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_sphinxrs_checksum_func_get_tags() != 42493.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_delete_msgs() != 39403.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
}

// Public interface members begin here.
Expand Down Expand Up @@ -1207,7 +1214,8 @@ data class RunReturn (
var `muteLevels`: String?,
var `payments`: String?,
var `paymentsTotal`: ULong?,
var `tags`: String?
var `tags`: String?,
var `deletedMsgs`: String?
) {

}
Expand Down Expand Up @@ -1245,6 +1253,7 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer<RunReturn> {
FfiConverterOptionalString.read(buf),
FfiConverterOptionalULong.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterOptionalString.read(buf),
)
}

Expand Down Expand Up @@ -1278,7 +1287,8 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer<RunReturn> {
FfiConverterOptionalString.allocationSize(value.`muteLevels`) +
FfiConverterOptionalString.allocationSize(value.`payments`) +
FfiConverterOptionalULong.allocationSize(value.`paymentsTotal`) +
FfiConverterOptionalString.allocationSize(value.`tags`)
FfiConverterOptionalString.allocationSize(value.`tags`) +
FfiConverterOptionalString.allocationSize(value.`deletedMsgs`)
)

override fun write(value: RunReturn, buf: ByteBuffer) {
Expand Down Expand Up @@ -1312,6 +1322,7 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer<RunReturn> {
FfiConverterOptionalString.write(value.`payments`, buf)
FfiConverterOptionalULong.write(value.`paymentsTotal`, buf)
FfiConverterOptionalString.write(value.`tags`, buf)
FfiConverterOptionalString.write(value.`deletedMsgs`, buf)
}
}

Expand Down Expand Up @@ -2158,6 +2169,60 @@ public object FfiConverterOptionalByteArray: FfiConverterRustBuffer<ByteArray?>



public object FfiConverterOptionalSequenceULong: FfiConverterRustBuffer<List<ULong>?> {
override fun read(buf: ByteBuffer): List<ULong>? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterSequenceULong.read(buf)
}

override fun allocationSize(value: List<ULong>?): Int {
if (value == null) {
return 1
} else {
return 1 + FfiConverterSequenceULong.allocationSize(value)
}
}

override fun write(value: List<ULong>?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterSequenceULong.write(value, buf)
}
}
}




public object FfiConverterSequenceULong: FfiConverterRustBuffer<List<ULong>> {
override fun read(buf: ByteBuffer): List<ULong> {
val len = buf.getInt()
return List<ULong>(len) {
FfiConverterULong.read(buf)
}
}

override fun allocationSize(value: List<ULong>): Int {
val sizeForLength = 4
val sizeForItems = value.map { FfiConverterULong.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}

override fun write(value: List<ULong>, buf: ByteBuffer) {
buf.putInt(value.size)
value.forEach {
FfiConverterULong.write(it, buf)
}
}
}




public object FfiConverterSequenceString: FfiConverterRustBuffer<List<String>> {
override fun read(buf: ByteBuffer): List<String> {
val len = buf.getInt()
Expand Down Expand Up @@ -2849,4 +2914,13 @@ fun `getTags`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `tags`:
})
}

@Throws(SphinxException::class)

fun `deleteMsgs`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `pubkey`: String?, `msgIdxs`: List<ULong>?): RunReturn {
return FfiConverterTypeRunReturn.lift(
rustCallWithError(SphinxException) { _status ->
_UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_delete_msgs(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterOptionalString.lower(`pubkey`),FfiConverterOptionalSequenceULong.lower(`msgIdxs`),_status)
})
}


0 comments on commit 61d0edf

Please sign in to comment.