11pub mod add_invoice;
2+ pub mod adm_send_dm;
23pub mod conversation_key;
4+ pub mod dm_to_user;
35pub mod get_dm;
6+ pub mod get_dm_user;
47pub mod list_disputes;
58pub mod list_orders;
69pub mod new_order;
@@ -13,8 +16,11 @@ pub mod take_dispute;
1316pub mod take_sell;
1417
1518use crate :: cli:: add_invoice:: execute_add_invoice;
19+ use crate :: cli:: adm_send_dm:: execute_adm_send_dm;
1620use crate :: cli:: conversation_key:: execute_conversation_key;
21+ use crate :: cli:: dm_to_user:: execute_dm_to_user;
1722use crate :: cli:: get_dm:: execute_get_dm;
23+ use crate :: cli:: get_dm_user:: execute_get_dm_user;
1824use crate :: cli:: list_disputes:: execute_list_disputes;
1925use crate :: cli:: list_orders:: execute_list_orders;
2026use crate :: cli:: new_order:: execute_new_order;
@@ -158,6 +164,13 @@ pub enum Commands {
158164 #[ arg( short) ]
159165 from_user : bool ,
160166 } ,
167+ /// Get direct messages sent to any trade keys
168+ GetDmUser {
169+ /// Since time of the messages in minutes
170+ #[ arg( short, long) ]
171+ #[ clap( default_value_t = 30 ) ]
172+ since : i64 ,
173+ } ,
161174 /// Get the latest direct messages for admin
162175 GetAdminDm {
163176 /// Since time of the messages in minutes
@@ -180,6 +193,18 @@ pub enum Commands {
180193 #[ arg( short, long) ]
181194 message : String ,
182195 } ,
196+ /// Send gift wrapped direct message to a user
197+ DmToUser {
198+ /// Pubkey of the recipient
199+ #[ arg( short, long) ]
200+ pubkey : String ,
201+ /// Order id to get ephemeral keys
202+ #[ arg( short, long) ]
203+ order_id : Uuid ,
204+ /// Message to send
205+ #[ arg( short, long) ]
206+ message : String ,
207+ } ,
183208 /// Send fiat sent message to confirm payment to other user
184209 FiatSent {
185210 /// Order id
@@ -241,6 +266,15 @@ pub enum Commands {
241266 #[ arg( short, long) ]
242267 dispute_id : Uuid ,
243268 } ,
269+ /// Send gift wrapped direct message to a user (only admin)
270+ AdmSendDm {
271+ /// Pubkey of the recipient
272+ #[ arg( short, long) ]
273+ pubkey : String ,
274+ /// Message to send
275+ #[ arg( short, long) ]
276+ message : String ,
277+ } ,
244278 /// Get the conversation key for direct messaging with a user
245279 ConversationKey {
246280 /// Pubkey of the counterpart
@@ -373,10 +407,13 @@ pub async fn run() -> Result<()> {
373407 execute_add_invoice ( order_id, invoice, & identity_keys, mostro_key, & client) . await ?
374408 }
375409 Commands :: GetDm { since, from_user } => {
376- execute_get_dm ( since, trade_index, & client, * from_user, false ) . await ?
410+ execute_get_dm ( since, trade_index, & client, * from_user, false , & mostro_key) . await ?
411+ }
412+ Commands :: GetDmUser { since } => {
413+ execute_get_dm_user ( since, & client, & mostro_key) . await ?
377414 }
378415 Commands :: GetAdminDm { since, from_user } => {
379- execute_get_dm ( since, trade_index, & client, * from_user, true ) . await ?
416+ execute_get_dm ( since, trade_index, & client, * from_user, true , & mostro_key ) . await ?
380417 }
381418 Commands :: FiatSent { order_id }
382419 | Commands :: Release { order_id }
@@ -396,8 +433,7 @@ pub async fn run() -> Result<()> {
396433 let id_key = match std:: env:: var ( "NSEC_PRIVKEY" ) {
397434 Ok ( id_key) => Keys :: parse ( & id_key) ?,
398435 Err ( e) => {
399- println ! ( "Failed to get mostro admin private key: {}" , e) ;
400- std:: process:: exit ( 1 ) ;
436+ anyhow:: bail!( "NSEC_PRIVKEY not set: {e}" ) ;
401437 }
402438 } ;
403439 execute_admin_add_solver ( npubkey, & id_key, & trade_keys, mostro_key, & client) . await ?
@@ -439,8 +475,7 @@ pub async fn run() -> Result<()> {
439475 let id_key = match std:: env:: var ( "NSEC_PRIVKEY" ) {
440476 Ok ( id_key) => Keys :: parse ( & id_key) ?,
441477 Err ( e) => {
442- println ! ( "Failed to get mostro admin private key: {}" , e) ;
443- std:: process:: exit ( 1 ) ;
478+ anyhow:: bail!( "NSEC_PRIVKEY not set: {e}" ) ;
444479 }
445480 } ;
446481 execute_admin_settle_dispute ( order_id, & id_key, & trade_keys, mostro_key, & client)
@@ -450,8 +485,7 @@ pub async fn run() -> Result<()> {
450485 let id_key = match std:: env:: var ( "NSEC_PRIVKEY" ) {
451486 Ok ( id_key) => Keys :: parse ( & id_key) ?,
452487 Err ( e) => {
453- println ! ( "Failed to get mostro admin private key: {}" , e) ;
454- std:: process:: exit ( 1 ) ;
488+ anyhow:: bail!( "NSEC_PRIVKEY not set: {e}" ) ;
455489 }
456490 } ;
457491 execute_admin_cancel_dispute ( order_id, & id_key, & trade_keys, mostro_key, & client)
@@ -461,8 +495,7 @@ pub async fn run() -> Result<()> {
461495 let id_key = match std:: env:: var ( "NSEC_PRIVKEY" ) {
462496 Ok ( id_key) => Keys :: parse ( & id_key) ?,
463497 Err ( e) => {
464- println ! ( "Failed to get mostro admin private key: {}" , e) ;
465- std:: process:: exit ( 1 ) ;
498+ anyhow:: bail!( "NSEC_PRIVKEY not set: {e}" ) ;
466499 }
467500 } ;
468501
@@ -477,6 +510,18 @@ pub async fn run() -> Result<()> {
477510 let pubkey = PublicKey :: from_str ( pubkey) ?;
478511 execute_send_dm ( pubkey, & client, order_id, message) . await ?
479512 }
513+ Commands :: DmToUser {
514+ pubkey,
515+ order_id,
516+ message,
517+ } => {
518+ let pubkey = PublicKey :: from_str ( pubkey) ?;
519+ execute_dm_to_user ( pubkey, & client, order_id, message) . await ?
520+ }
521+ Commands :: AdmSendDm { pubkey, message } => {
522+ let pubkey = PublicKey :: from_str ( pubkey) ?;
523+ execute_adm_send_dm ( pubkey, & client, message) . await ?
524+ }
480525 } ;
481526 }
482527
0 commit comments