Skip to content

Commit a6624b9

Browse files
authored
Show all endorsements in the endorsement list (#638)
1 parent 82e47cb commit a6624b9

File tree

7 files changed

+45
-36
lines changed

7 files changed

+45
-36
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
* Add basic logic for implementing (social) identity proofs
44
* Add persistence, basic service layer and WASM API for identity proofs
5+
* Fix block propagation inconsistencies with company identities
56
* Changed default relay to `wss://bcr-relay-dev.minibill.tech`
7+
* Change `endorsements` endpoint, making sure all endorsees (also anon) are displayed (breaking for API because of the return type)
68

79
# 0.4.5
810

crates/bcr-ebill-api/src/service/bill_service/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,7 +3475,7 @@ pub mod tests {
34753475
assert_eq!(
34763476
endorsements.as_ref().unwrap()[0]
34773477
.pay_to_the_order_of
3478-
.node_id,
3478+
.node_id(),
34793479
identity.identity.node_id
34803480
);
34813481
}
@@ -4130,15 +4130,15 @@ pub mod tests {
41304130
.get_endorsements(&bill_id_test(), &identity.identity.node_id)
41314131
.await;
41324132
assert!(res.is_ok());
4133-
// with duplicates
4134-
assert_eq!(res.as_ref().unwrap().len(), 2);
4133+
// with duplicates, anon are also counted
4134+
assert_eq!(res.as_ref().unwrap().len(), 3);
41354135
// mint was last, so it's first
41364136
assert_eq!(
4137-
res.as_ref().unwrap()[0].pay_to_the_order_of.node_id,
4137+
res.as_ref().unwrap()[0].pay_to_the_order_of.node_id(),
41384138
mint_endorsee_clone.node_id
41394139
);
41404140
assert_eq!(
4141-
res.as_ref().unwrap()[1].pay_to_the_order_of.node_id,
4141+
res.as_ref().unwrap()[1].pay_to_the_order_of.node_id(),
41424142
sell_endorsee_clone.node_id
41434143
);
41444144
// endorsee is not in the list, since they're anon
@@ -4266,15 +4266,15 @@ pub mod tests {
42664266
assert_eq!(res.as_ref().unwrap().len(), 3);
42674267
// mint was last, so it's first
42684268
assert_eq!(
4269-
res.as_ref().unwrap()[0].pay_to_the_order_of.node_id,
4269+
res.as_ref().unwrap()[0].pay_to_the_order_of.node_id(),
42704270
mint_endorsee_clone.node_id
42714271
);
42724272
assert_eq!(
4273-
res.as_ref().unwrap()[1].pay_to_the_order_of.node_id,
4273+
res.as_ref().unwrap()[1].pay_to_the_order_of.node_id(),
42744274
sell_endorsee_clone.node_id
42754275
);
42764276
assert_eq!(
4277-
res.as_ref().unwrap()[2].pay_to_the_order_of.node_id,
4277+
res.as_ref().unwrap()[2].pay_to_the_order_of.node_id(),
42784278
endorse_endorsee_clone.node_id
42794279
);
42804280
}

crates/bcr-ebill-core/src/bill/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use std::str::FromStr;
22

33
use super::{
44
File, PostalAddress,
5-
contact::{
6-
BillIdentParticipant, LightBillIdentParticipant, LightBillIdentParticipantWithAddress,
7-
},
5+
contact::{BillIdentParticipant, LightBillIdentParticipant},
86
notification::Notification,
97
};
108
use crate::{
@@ -539,7 +537,7 @@ pub struct PastEndorsee {
539537

540538
#[derive(Debug)]
541539
pub struct Endorsement {
542-
pub pay_to_the_order_of: LightBillIdentParticipantWithAddress,
540+
pub pay_to_the_order_of: LightBillParticipant,
543541
pub signed: LightSignedBy,
544542
pub signing_timestamp: u64,
545543
pub signing_address: Option<PostalAddress>,

crates/bcr-ebill-core/src/blockchain/bill/chain.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ impl BillBlockchain {
674674
Ok(nodes)
675675
}
676676

677+
/// Returns all endorsements for the bill (including anonymous holders)
677678
pub fn get_endorsements_for_bill(&self, bill_keys: &BillKeys) -> Vec<Endorsement> {
678679
let mut result: Vec<Endorsement> = vec![];
679680
// iterate from the back to the front, collecting all endorsement blocks
@@ -683,28 +684,26 @@ impl BillBlockchain {
683684
continue;
684685
}
685686
if let Ok(Some(holder_from_block)) = block.get_holder_from_block(bill_keys) {
686-
// we ignore blocks with an anonymous holder
687-
if let BillParticipantBlockData::Ident(holder_data) = holder_from_block.holder {
688-
result.push(Endorsement {
689-
pay_to_the_order_of: holder_data.clone().into(),
690-
signed: LightSignedBy {
691-
data: holder_from_block.signer.clone().into(),
692-
signatory: holder_from_block.signatory.map(|s| {
693-
LightBillIdentParticipant {
694-
// signatories are always identified people
695-
t: ContactType::Person,
696-
name: s.name,
697-
node_id: s.node_id,
698-
}
699-
}),
700-
},
701-
signing_timestamp: block.timestamp,
702-
signing_address: match holder_from_block.signer {
703-
BillParticipantBlockData::Anon(_) => None,
704-
BillParticipantBlockData::Ident(data) => Some(data.postal_address),
705-
},
706-
});
707-
}
687+
let holder_data = holder_from_block.holder;
688+
result.push(Endorsement {
689+
pay_to_the_order_of: holder_data.clone().into(),
690+
signed: LightSignedBy {
691+
data: holder_from_block.signer.clone().into(),
692+
signatory: holder_from_block.signatory.map(|s| {
693+
LightBillIdentParticipant {
694+
// signatories are always identified people
695+
t: ContactType::Person,
696+
name: s.name,
697+
node_id: s.node_id,
698+
}
699+
}),
700+
},
701+
signing_timestamp: block.timestamp,
702+
signing_address: match holder_from_block.signer {
703+
BillParticipantBlockData::Anon(_) => None,
704+
BillParticipantBlockData::Ident(data) => Some(data.postal_address),
705+
},
706+
});
708707
}
709708
}
710709

@@ -729,6 +728,7 @@ impl BillBlockchain {
729728
result
730729
}
731730

731+
/// Returns past endorsees, which can be recoursed against (no recourse blocks, no anon)
732732
pub fn get_past_endorsees_for_bill(
733733
&self,
734734
bill_keys: &BillKeys,

crates/bcr-ebill-core/src/contact/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ pub enum LightBillParticipant {
164164
Ident(LightBillIdentParticipantWithAddress),
165165
}
166166

167+
impl LightBillParticipant {
168+
pub fn node_id(&self) -> NodeId {
169+
match self {
170+
LightBillParticipant::Ident(data) => data.node_id.clone(),
171+
LightBillParticipant::Anon(data) => data.node_id.clone(),
172+
}
173+
}
174+
}
175+
167176
#[derive(Debug, Serialize, Deserialize, Clone)]
168177
pub struct LightBillAnonParticipant {
169178
pub node_id: NodeId,

crates/bcr-ebill-wasm/src/api/notification.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Notification {
2929
#[wasm_bindgen(unchecked_return_type = "NotificationStatusWeb[]")]
3030
pub async fn active_notifications_for_node_ids(
3131
&self,
32-
#[wasm_bindgen(unchecked_param_type = "Vec<String>")] node_ids: JsValue,
32+
#[wasm_bindgen(unchecked_param_type = "string[]")] node_ids: JsValue,
3333
) -> Result<JsValue> {
3434
let node_ids_parsed: Vec<NodeId> = serde_wasm_bindgen::from_value(node_ids)?;
3535
let notification_status = get_ctx()

crates/bcr-ebill-wasm/src/data/bill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl From<LightSignedBy> for LightSignedByWeb {
207207
#[derive(Tsify, Debug, Clone, Serialize)]
208208
#[tsify(into_wasm_abi)]
209209
pub struct EndorsementWeb {
210-
pub pay_to_the_order_of: LightBillIdentParticipantWithAddressWeb,
210+
pub pay_to_the_order_of: LightBillParticipantWeb,
211211
pub signed: LightSignedByWeb,
212212
pub signing_timestamp: u64,
213213
pub signing_address: Option<PostalAddressWeb>,

0 commit comments

Comments
 (0)