File tree Expand file tree Collapse file tree 9 files changed +29
-20
lines changed
bcr-ebill-transport/src/handler Expand file tree Collapse file tree 9 files changed +29
-20
lines changed Original file line number Diff line number Diff line change @@ -6,5 +6,5 @@ pub const MAX_FILE_NAME_CHARACTERS: usize = 200;
6
6
pub const VALID_FILE_MIME_TYPES : [ & str ; 3 ] = [ "image/jpeg" , "image/png" , "application/pdf" ] ;
7
7
8
8
// When subscribing events we subtract this from the last received event time
9
- pub const NOSTR_EVENT_TIME_SLACK : u64 = 3600 * 24 ; // 1 day
9
+ pub const NOSTR_EVENT_TIME_SLACK : u64 = 3600 * 24 * 7 ; // 1 week
10
10
pub use bcr_ebill_core:: constants:: CURRENCY_SAT ;
Original file line number Diff line number Diff line change @@ -300,7 +300,8 @@ impl CompanyServiceApi for CompanyService {
300
300
. iter ( )
301
301
. any ( |c| c. node_id == identity. node_id )
302
302
{
303
- signatory_contacts. push ( identity. as_contact ( ) ) ;
303
+ // we force person for this as it will be thrown out in later validation
304
+ signatory_contacts. push ( identity. as_contact ( Some ( ContactType :: Person ) ) ) ;
304
305
}
305
306
306
307
// if we are still missing some signatory details try to fill them from nostr contacts
@@ -317,7 +318,7 @@ impl CompanyServiceApi for CompanyService {
317
318
. by_node_ids ( missing)
318
319
. await ?
319
320
. into_iter ( )
320
- . filter_map ( |c| c. into_contact ( ) )
321
+ . filter_map ( |c| c. into_contact ( Some ( ContactType :: Person ) ) )
321
322
. collect ( ) ;
322
323
323
324
signatory_contacts. extend ( nostr_contacts) ;
Original file line number Diff line number Diff line change @@ -254,7 +254,7 @@ impl ContactServiceApi for ContactService {
254
254
. filter_map ( |c| {
255
255
// only return nostr contacts that are not in contacts and have a name
256
256
if !lookup. contains ( & c. node_id ) {
257
- c. into_contact ( )
257
+ c. into_contact ( None )
258
258
} else {
259
259
None
260
260
}
Original file line number Diff line number Diff line change @@ -202,11 +202,10 @@ impl IdentityService {
202
202
}
203
203
204
204
async fn on_identity_contact_change ( & self , identity : & Identity , keys : & BcrKeys ) -> Result < ( ) > {
205
- debug ! ( "Company change, publishing our company contact to nostr profile" ) ;
205
+ debug ! ( "Identity change, publishing our identity contact to nostr profile" ) ;
206
206
let bcr_data = get_bcr_data ( identity, keys) ?;
207
207
let contact_data =
208
208
NostrContactData :: new ( & identity. name , identity. nostr_relays . clone ( ) , bcr_data) ;
209
- debug ! ( "Publishing company contact data: {contact_data:?}" ) ;
210
209
self . notification_service
211
210
. publish_contact ( & identity. node_id , & contact_data)
212
211
. await ?;
@@ -217,7 +216,8 @@ impl IdentityService {
217
216
/// Derives a child key, encrypts the contact data with it and returns the bcr metadata
218
217
fn get_bcr_data ( identity : & Identity , keys : & BcrKeys ) -> Result < BcrMetadata > {
219
218
let derived_keys = keys. derive_keypair ( ) ?;
220
- let contact = identity. as_contact ( ) ;
219
+ let contact = identity. as_contact ( None ) ;
220
+ debug ! ( "Publishing identity contact data: {contact:?}" ) ;
221
221
let payload = serde_json:: to_string ( & contact) ?;
222
222
let encrypted = base58_encode ( & util:: crypto:: encrypt_ecies (
223
223
payload. as_bytes ( ) ,
Original file line number Diff line number Diff line change @@ -136,11 +136,11 @@ impl Identity {
136
136
}
137
137
}
138
138
139
- pub fn as_contact ( & self ) -> Contact {
140
- let contact_type = match self . t {
139
+ pub fn as_contact ( & self , t : Option < ContactType > ) -> Contact {
140
+ let contact_type = t . unwrap_or ( match self . t {
141
141
IdentityType :: Ident => ContactType :: Person ,
142
142
IdentityType :: Anon => ContactType :: Anon ,
143
- } ;
143
+ } ) ;
144
144
Contact {
145
145
t : contact_type,
146
146
node_id : self . node_id . clone ( ) ,
Original file line number Diff line number Diff line change @@ -67,11 +67,11 @@ impl NostrContact {
67
67
}
68
68
69
69
/// Returns a lightweight version of the contact if all required data is present.
70
- pub fn into_contact ( self ) -> Option < Contact > {
70
+ pub fn into_contact ( self , t : Option < ContactType > ) -> Option < Contact > {
71
71
if self . name . is_some ( ) {
72
72
Some ( Contact {
73
73
node_id : self . node_id ,
74
- t : ContactType :: Anon ,
74
+ t : t . unwrap_or ( ContactType :: Anon ) ,
75
75
name : self . name . unwrap ( ) ,
76
76
email : None ,
77
77
postal_address : None ,
Original file line number Diff line number Diff line change @@ -165,6 +165,13 @@ impl CompanyChainEventProcessor {
165
165
self . nostr_contact_processor
166
166
. ensure_nostr_contact ( & company_id)
167
167
. await ;
168
+
169
+ // as well as all the company signatories
170
+ for signatory in company. signatories . iter ( ) {
171
+ self . nostr_contact_processor
172
+ . ensure_nostr_contact ( signatory)
173
+ . await ;
174
+ }
168
175
} else {
169
176
info ! ( "We are not a signatory for company {company_id} so skipping chain" ) ;
170
177
}
@@ -588,7 +595,7 @@ pub mod tests {
588
595
. expect_ensure_nostr_contact ( )
589
596
. with ( eq ( node_id. clone ( ) ) )
590
597
. returning ( |_| ( ) )
591
- . once ( ) ;
598
+ . times ( 2 ) ;
592
599
593
600
let handler = CompanyChainEventProcessor :: new (
594
601
Arc :: new ( chain_store) ,
Original file line number Diff line number Diff line change @@ -339,8 +339,10 @@ async function listCompanies() {
339
339
}
340
340
341
341
async function listSignatories ( ) {
342
- let signatories = await companyApi . list_signatories ( document . getElementById ( "company_update_id" ) . value ) ;
343
- console . log ( "signatories:" , signatories ) ;
342
+ let measured = measure ( async ( ) => {
343
+ return await companyApi . list_signatories ( document . getElementById ( "company_update_id" ) . value ) ;
344
+ } ) ;
345
+ await measured ( ) ;
344
346
}
345
347
346
348
async function triggerContact ( ) {
Original file line number Diff line number Diff line change @@ -115,8 +115,9 @@ pub struct SignatoryResponse {
115
115
#[ tsify( type = "string" ) ]
116
116
pub node_id : NodeId ,
117
117
pub name : String ,
118
- pub postal_address : PostalAddressWeb ,
118
+ pub postal_address : Option < PostalAddressWeb > ,
119
119
pub avatar_file : Option < FileWeb > ,
120
+ pub is_logical : bool ,
120
121
}
121
122
122
123
impl TryFrom < Contact > for SignatoryResponse {
@@ -130,11 +131,9 @@ impl TryFrom<Contact> for SignatoryResponse {
130
131
t : value. t . into ( ) ,
131
132
node_id : value. node_id . clone ( ) ,
132
133
name : value. name ,
133
- postal_address : value
134
- . postal_address
135
- . ok_or ( ValidationError :: InvalidContact ( value. node_id . to_string ( ) ) )
136
- . map ( |pa| pa. into ( ) ) ?,
134
+ postal_address : value. postal_address . map ( |pa| pa. into ( ) ) ,
137
135
avatar_file : value. avatar_file . map ( |f| f. into ( ) ) ,
136
+ is_logical : value. is_logical ,
138
137
} )
139
138
}
140
139
}
You can’t perform that action at this time.
0 commit comments