@@ -7,6 +7,7 @@ use interledger_errors::*;
77use interledger_http:: { deserialize_json, HttpAccount , HttpStore } ;
88use interledger_ildcp:: IldcpRequest ;
99use interledger_ildcp:: IldcpResponse ;
10+ use interledger_packet:: Address ;
1011use interledger_rates:: ExchangeRateStore ;
1112use interledger_router:: RouterStore ;
1213use interledger_service:: {
@@ -22,6 +23,7 @@ use serde::{Deserialize, Serialize};
2223use serde_json:: json;
2324use std:: convert:: TryFrom ;
2425use std:: fmt:: Debug ;
26+ use std:: str:: FromStr ;
2527use tracing:: { debug, error, trace} ;
2628use uuid:: Uuid ;
2729use warp:: { self , reply:: Json , Filter , Rejection } ;
@@ -423,7 +425,7 @@ where
423425 let server_secret_clone = server_secret. clone ( ) ;
424426 let get_spsp = warp:: get ( )
425427 . and ( warp:: path ( "accounts" ) )
426- . and ( account_username_to_id)
428+ . and ( account_username_to_id. clone ( ) )
427429 . and ( warp:: path ( "spsp" ) )
428430 . and ( warp:: path:: end ( ) )
429431 . and ( with_store. clone ( ) )
@@ -442,6 +444,46 @@ where
442444 }
443445 } ) ;
444446
447+ // GET /accounts/:username/spsp/tracking_info
448+ let server_secret_clone = server_secret. clone ( ) ;
449+ let get_spsp_with_tracking = warp:: get ( )
450+ . and ( warp:: path ( "accounts" ) )
451+ . and ( account_username_to_id)
452+ . and ( warp:: path ( "spsp" ) )
453+ . and ( warp:: path:: param :: < String > ( ) )
454+ . and ( warp:: path:: end ( ) )
455+ . and ( with_store. clone ( ) )
456+ . and_then ( move |id : Uuid , tracking_info : String , store : S | {
457+ let server_secret_clone = server_secret_clone. clone ( ) ;
458+ async move {
459+ let accounts = store. get_accounts ( vec ! [ id] ) . await ?;
460+ // TODO return the response without instantiating an SpspResponder (use a simple fn)
461+
462+ let with_tracking = format ! ( "{}.{}" , accounts[ 0 ] . ilp_address( ) , tracking_info) ;
463+ match Address :: from_str ( & with_tracking) {
464+ Ok ( addr) => {
465+ trace ! (
466+ account_id = %id,
467+ "Appended tracking info: {}" ,
468+ addr,
469+ ) ;
470+ Ok :: < _ , Rejection > (
471+ SpspResponder :: new ( addr, server_secret_clone. clone ( ) )
472+ . generate_http_response ( ) ,
473+ )
474+ }
475+ Err ( err) => {
476+ let msg = format ! ( "Error appending tracking info: {}" , err) ;
477+ error ! ( address_with_tracking = ?with_tracking, "{}" , msg) ;
478+ // TODO give a different error message depending on what type of error it is
479+ Err ( Rejection :: from (
480+ ApiError :: internal_server_error ( ) . detail ( msg) ,
481+ ) )
482+ }
483+ }
484+ }
485+ } ) ;
486+
445487 // GET /.well-known/pay
446488 // This is the endpoint a [Payment Pointer](https://github.com/interledger/rfcs/blob/master/0026-payment-pointers/0026-payment-pointers.md)
447489 // with no path resolves to
@@ -483,6 +525,7 @@ where
483525 // See `combine!` docs for more details.
484526 combine ! (
485527 get_spsp,
528+ get_spsp_with_tracking,
486529 get_spsp_well_known,
487530 post_accounts,
488531 get_accounts,
0 commit comments