Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/client/tempo/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ impl PaymentProvider for TempoProvider {
// Auto-generate an attribution memo when the server doesn't provide one,
// so MPP transactions are identifiable on-chain via `TransferWithMemo` events.
if charge.memo().is_none() {
let memo =
crate::tempo::attribution::encode(&challenge.realm, self.client_id.as_deref());
let memo = crate::tempo::attribution::encode(
&challenge.id,
&challenge.realm,
self.client_id.as_deref(),
);
charge = charge.with_memo(memo);
}

Expand Down Expand Up @@ -236,7 +239,8 @@ mod tests {

#[test]
fn test_auto_generated_memo_is_mpp_memo() {
let memo = crate::tempo::attribution::encode("api.example.com", Some("my-app"));
let memo =
crate::tempo::attribution::encode("challenge-123", "api.example.com", Some("my-app"));
assert!(crate::tempo::attribution::is_mpp_memo(&memo));
}

Expand Down
18 changes: 18 additions & 0 deletions src/protocol/methods/tempo/charge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl TempoChargeExt for ChargeRequest {
.as_ref()
.and_then(|v| v.get("memo"))
.and_then(|v| v.as_str())
.filter(|s| !s.is_empty())
.map(|s| s.to_string())
}

Expand All @@ -119,6 +120,9 @@ fn parse_memo_bytes_in_context(memo: Option<&str>, context: &str) -> Result<Opti
let Some(memo) = memo else {
return Ok(None);
};
if memo.is_empty() {
return Ok(None);
}

let hex_str = memo.strip_prefix("0x").unwrap_or(memo);
let bytes = hex::decode(hex_str)
Expand Down Expand Up @@ -218,6 +222,20 @@ mod tests {
req_with_memo.memo(),
Some("0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef".to_string())
);

let req_with_empty_memo = ChargeRequest {
method_details: Some(serde_json::json!({
"chainId": 42431,
"memo": ""
})),
..test_charge_request()
};
assert!(req_with_empty_memo.memo().is_none());
}

#[test]
fn test_parse_memo_bytes_checked_treats_empty_as_none() {
assert!(parse_memo_bytes_checked(Some("")).unwrap().is_none());
}

#[test]
Expand Down
Loading
Loading