@@ -2,7 +2,7 @@ use super::HandlerResult;
22use crate :: args:: { CheckRevokedArgs , NilauthCommand , NilauthSubscriptionCommand , RevokeTokenArgs } ;
33use anyhow:: { anyhow, bail, Context , Result } ;
44use chrono:: { DateTime , Utc } ;
5- use nilauth_client:: client:: { About , DefaultNilauthClient , NilauthClient } ;
5+ use nilauth_client:: client:: { About , BlindModule , DefaultNilauthClient , NilauthClient } ;
66use nillion_client:: payments:: { NillionChainClient , NillionChainPrivateKey } ;
77use nillion_nucs:: {
88 envelope:: NucTokenEnvelope ,
@@ -40,16 +40,19 @@ impl NilauthHandler {
4040 pub async fn handle ( self , command : NilauthCommand ) -> HandlerResult {
4141 use NilauthCommand :: * ;
4242 match command {
43- Subscription ( NilauthSubscriptionCommand :: Pay ) => self . pay_subscription ( ) . await ,
44- Subscription ( NilauthSubscriptionCommand :: Status ) => self . subscription_status ( ) . await ,
45- Token => self . request_token ( ) . await ,
43+ Subscription ( NilauthSubscriptionCommand :: Pay { module } ) => self . pay_subscription ( module. into ( ) ) . await ,
44+ Subscription ( NilauthSubscriptionCommand :: Status { module } ) => {
45+ self . subscription_status ( module. into ( ) ) . await
46+ }
47+ Subscription ( NilauthSubscriptionCommand :: Cost { module } ) => self . subscription_cost ( module. into ( ) ) . await ,
48+ Token { module } => self . request_token ( module. into ( ) ) . await ,
4649 Revoke ( args) => self . revoke_token ( args) . await ,
4750 CheckRevoked ( args) => self . check_revoked ( args) . await ,
4851 About => self . about ( ) . await ,
4952 }
5053 }
5154
52- async fn pay_subscription ( self ) -> HandlerResult {
55+ async fn pay_subscription ( self , module : BlindModule ) -> HandlerResult {
5356 #[ derive( Serialize ) ]
5457 struct Output {
5558 tx_hash : String ,
@@ -65,11 +68,11 @@ impl NilauthHandler {
6568 nilchain_client. set_gas_price ( gas_price) ;
6669 }
6770
68- let tx_hash = self . client . pay_subscription ( & mut nilchain_client, & self . key ) . await ?;
71+ let tx_hash = self . client . pay_subscription ( & mut nilchain_client, & self . key , module ) . await ?;
6972 Ok ( Box :: new ( Output { tx_hash : tx_hash. to_string ( ) } ) )
7073 }
7174
72- async fn subscription_status ( self ) -> HandlerResult {
75+ async fn subscription_status ( self , module : BlindModule ) -> HandlerResult {
7376 #[ derive( Serialize ) ]
7477 struct Output {
7578 subscribed : bool ,
@@ -78,25 +81,37 @@ impl NilauthHandler {
7881 expires_at : Option < DateTime < Utc > > ,
7982 }
8083
81- let subscription = self . client . subscription_status ( & self . key ) . await ?;
84+ let subscription = self . client . subscription_status ( & self . key . public_key ( ) , module ) . await ?;
8285 let output =
8386 Output { subscribed : subscription. subscribed , expires_at : subscription. details . map ( |s| s. expires_at ) } ;
8487 Ok ( Box :: new ( output) )
8588 }
8689
87- async fn request_token ( self ) -> HandlerResult {
90+ async fn subscription_cost ( self , module : BlindModule ) -> HandlerResult {
91+ #[ derive( Serialize ) ]
92+ struct Output {
93+ cost_unils : u64 ,
94+ }
95+
96+ let cost = self . client . subscription_cost ( module) . await ?;
97+ let output = Output { cost_unils : cost. to_unil ( ) } ;
98+ Ok ( Box :: new ( output) )
99+ }
100+
101+ async fn request_token ( self , module : BlindModule ) -> HandlerResult {
88102 #[ derive( Serialize ) ]
89103 struct Output {
90104 token : String ,
91105 }
92106
93- let token = self . client . request_token ( & self . key ) . await ?;
107+ let token = self . client . request_token ( & self . key , module ) . await ?;
94108 Ok ( Box :: new ( Output { token } ) )
95109 }
96110
97111 async fn revoke_token ( self , args : RevokeTokenArgs ) -> HandlerResult {
98112 let token = NucTokenEnvelope :: decode ( & args. token ) ?;
99- self . client . revoke_token ( & token, & self . key ) . await ?;
113+ let args = nilauth_client:: client:: RevokeTokenArgs { auth_token : token. clone ( ) , revocable_token : token } ;
114+ self . client . revoke_token ( args, & self . key ) . await ?;
100115 Ok ( Box :: new ( "Token revoked" . to_string ( ) ) )
101116 }
102117
0 commit comments