@@ -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 } ;
@@ -421,9 +423,9 @@ where
421423
422424 // GET /accounts/:username/spsp
423425 let server_secret_clone = server_secret. clone ( ) ;
424- let get_spsp = warp:: get ( )
426+ let get_spsp_without_tracking = 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,47 @@ where
442444 }
443445 } ) ;
444446
447+ // GET /accounts/:username/spsp/tracking_info
448+ let server_secret_clone = server_secret. clone ( ) ;
449+ let get_spsp = 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+ trace ! ( "Tracking info: {:?}" , tracking_info) ;
458+
459+ let server_secret_clone = server_secret_clone. clone ( ) ;
460+ async move {
461+ let accounts = store. get_accounts ( vec ! [ id] ) . await ?;
462+ // TODO return the response without instantiating an SpspResponder (use a simple fn)
463+
464+ match Address :: from_str ( & format ! ( "{}.{}" , accounts[ 0 ] . ilp_address( ) , tracking_info) )
465+ {
466+ Ok ( addr) => {
467+ trace ! (
468+ "merged: {}" ,
469+ format!( "{}.{}" , accounts[ 0 ] . ilp_address( ) , tracking_info)
470+ ) ;
471+ Ok :: < _ , Rejection > (
472+ SpspResponder :: new ( addr, server_secret_clone. clone ( ) )
473+ . generate_http_response ( ) ,
474+ )
475+ }
476+ Err ( err) => {
477+ let msg = format ! ( "Error sending SPSP payment: {}" , err) ;
478+ error ! ( "{}" , msg) ;
479+ // TODO give a different error message depending on what type of error it is
480+ Err ( Rejection :: from (
481+ ApiError :: internal_server_error ( ) . detail ( msg) ,
482+ ) )
483+ }
484+ }
485+ }
486+ } ) ;
487+
445488 // GET /.well-known/pay
446489 // This is the endpoint a [Payment Pointer](https://github.com/interledger/rfcs/blob/master/0026-payment-pointers/0026-payment-pointers.md)
447490 // with no path resolves to
@@ -483,6 +526,7 @@ where
483526 // See `combine!` docs for more details.
484527 combine ! (
485528 get_spsp,
529+ get_spsp_without_tracking,
486530 get_spsp_well_known,
487531 post_accounts,
488532 get_accounts,
0 commit comments