Skip to content

Commit

Permalink
route_hint in sender json, TAGS fetching, sends tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Jun 5, 2024
1 parent 06b7ac1 commit 668a640
Show file tree
Hide file tree
Showing 6 changed files with 73 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 = "52d742b830c7d74be1302f68e8c37f71558cf5fc", features = [
sphinx = { git = "https://github.com/stakwork/sphinx", rev = "70ba0bd885818b2313dad13aedda8de941c2aba7", 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 @@ -54,6 +54,7 @@ pub struct RunReturn {
pub mute_levels: Option<String>,
pub payments: Option<String>,
pub payments_total: Option<u64>,
pub tags: Option<String>,
}

pub fn set_network(net: String) -> Result<RunReturn> {
Expand Down Expand Up @@ -662,6 +663,20 @@ pub fn fetch_payments(
.into())
}

pub fn get_tags(
seed: String,
unique_time: String,
full_state: Vec<u8>,
tags: Vec<String>,
pubkey: Option<String>,
) -> Result<RunReturn> {
Ok(
bindings::get_tags(&seed, &unique_time, &full_state, tags, pubkey)
.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 @@ -724,6 +739,7 @@ impl From<bindings::RunReturn> for RunReturn {
mute_levels: rr.mute_levels,
payments: rr.payments,
payments_total: rr.payments_total,
tags: rr.tags,
}
}
}
28 changes: 26 additions & 2 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,11 @@ public struct RunReturn {
public var `muteLevels`: String?
public var `payments`: String?
public var `paymentsTotal`: UInt64?
public var `tags`: 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?) {
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?) {
self.`msgs` = `msgs`
self.`msgsTotal` = `msgsTotal`
self.`msgsCounts` = `msgsCounts`
Expand Down Expand Up @@ -744,6 +745,7 @@ public struct RunReturn {
self.`muteLevels` = `muteLevels`
self.`payments` = `payments`
self.`paymentsTotal` = `paymentsTotal`
self.`tags` = `tags`
}
}

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

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

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

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

Expand Down Expand Up @@ -2368,6 +2376,19 @@ public func `fetchPayments`(`seed`: String, `uniqueTime`: String, `state`: Data,
)
}

public func `getTags`(`seed`: String, `uniqueTime`: String, `state`: Data, `tags`: [String], `pubkey`: String?) throws -> RunReturn {
return try FfiConverterTypeRunReturn.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_get_tags(
FfiConverterString.lower(`seed`),
FfiConverterString.lower(`uniqueTime`),
FfiConverterData.lower(`state`),
FfiConverterSequenceString.lower(`tags`),
FfiConverterOptionString.lower(`pubkey`),$0)
}
)
}

private enum InitializationResult {
case ok
case contractVersionMismatch
Expand Down Expand Up @@ -2587,6 +2608,9 @@ private var initializationResult: InitializationResult {
if (uniffi_sphinxrs_checksum_func_fetch_payments() != 58291) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_get_tags() != 42493) {
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 @@ -95,6 +95,7 @@ dictionary RunReturn {
string? mute_levels;
string? payments;
u64? payments_total;
string? tags;
};

namespace sphinxrs {
Expand Down Expand Up @@ -233,4 +234,6 @@ namespace sphinxrs {
RunReturn fetch_first_msgs_per_key(string seed, string unique_time, bytes state, u64 last_msg_idx, u32? limit, boolean? reverse);
[Throws=SphinxError]
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);
};
5 changes: 5 additions & 0 deletions sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ RustBuffer uniffi_sphinxrs_fn_func_fetch_first_msgs_per_key(RustBuffer seed, Rus
);
RustBuffer uniffi_sphinxrs_fn_func_fetch_payments(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer since, RustBuffer limit, RustBuffer scid, RustBuffer remote_only, RustBuffer min_msat, RustBuffer reverse, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_get_tags(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer tags, RustBuffer pubkey, 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 @@ -410,6 +412,9 @@ uint16_t uniffi_sphinxrs_checksum_func_fetch_first_msgs_per_key(void
);
uint16_t uniffi_sphinxrs_checksum_func_fetch_payments(void

);
uint16_t uniffi_sphinxrs_checksum_func_get_tags(void

);
uint32_t ffi_sphinxrs_uniffi_contract_version(void

Expand Down
24 changes: 22 additions & 2 deletions sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ internal interface _UniFFILib : Library {
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_fetch_payments(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`since`: RustBuffer.ByValue,`limit`: RustBuffer.ByValue,`scid`: RustBuffer.ByValue,`remoteOnly`: RustBuffer.ByValue,`minMsat`: RustBuffer.ByValue,`reverse`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): 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 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 @@ -644,6 +646,8 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_sphinxrs_checksum_func_fetch_payments(
): Short
fun uniffi_sphinxrs_checksum_func_get_tags(
): Short
fun ffi_sphinxrs_uniffi_contract_version(
): Int

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

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

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

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

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

Expand Down Expand Up @@ -2829,4 +2840,13 @@ fun `fetchPayments`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `s
})
}

@Throws(SphinxException::class)

fun `getTags`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `tags`: List<String>, `pubkey`: String?): RunReturn {
return FfiConverterTypeRunReturn.lift(
rustCallWithError(SphinxException) { _status ->
_UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_get_tags(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterSequenceString.lower(`tags`),FfiConverterOptionalString.lower(`pubkey`),_status)
})
}


0 comments on commit 668a640

Please sign in to comment.