Skip to content

Commit 6fc0691

Browse files
authored
Recourser can be Anon (#663)
1 parent f064d3c commit 6fc0691

File tree

16 files changed

+133
-100
lines changed

16 files changed

+133
-100
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* Add `default_court_url` to config and add API to share a bill with a court
77
* Add API to share company and identity details with an external party
88
* Removed the concept of an `Authorized Signer`
9+
* Fix it so that Anon holders of a bill can do recourse (breaking DB and API change)
10+
* `recourser` went from `BillIdentParticipant` to `BillParticipant`
911

1012
# 0.4.8
1113

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

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -129,43 +129,44 @@ impl BillService {
129129
timestamp,
130130
)?
131131
}
132-
// has to be ident to req recourse
132+
// can be anon to req recourse
133133
BillAction::RequestRecourse(recoursee, recourse_reason) => {
134134
validate_node_id_network(&recoursee.node_id)?;
135-
if let BillParticipant::Ident(signer) = signer_public_data {
136-
let (sum, currency, reason) = match *recourse_reason {
137-
RecourseReason::Accept => (
138-
bill.sum,
139-
bill.currency.clone(),
140-
BillRecourseReasonBlockData::Accept,
141-
),
142-
RecourseReason::Pay(sum, ref currency) => {
143-
(sum, currency.to_owned(), BillRecourseReasonBlockData::Pay)
144-
}
145-
};
146-
let block_data = BillRequestRecourseBlockData {
147-
recourser: signer.clone().into(),
148-
recoursee: recoursee.clone().into(),
149-
sum,
150-
currency: currency.to_owned(),
151-
recourse_reason: reason,
152-
signatory: signing_keys.signatory_identity,
153-
signing_timestamp: timestamp,
154-
signing_address: signer.postal_address.clone(),
155-
};
156-
block_data.validate()?;
157-
BillBlock::create_block_for_request_recourse(
158-
bill_id.to_owned(),
159-
previous_block,
160-
&block_data,
161-
&signing_keys.signatory_keys,
162-
signing_keys.company_keys.as_ref(),
163-
&BcrKeys::from_private_key(&bill_keys.private_key)?,
164-
timestamp,
165-
)?
166-
} else {
167-
return Err(Error::Validation(ValidationError::SignerCantBeAnon));
168-
}
135+
let (sum, currency, reason) = match *recourse_reason {
136+
RecourseReason::Accept => (
137+
bill.sum,
138+
bill.currency.clone(),
139+
BillRecourseReasonBlockData::Accept,
140+
),
141+
RecourseReason::Pay(sum, ref currency) => {
142+
(sum, currency.to_owned(), BillRecourseReasonBlockData::Pay)
143+
}
144+
};
145+
let block_data = BillRequestRecourseBlockData {
146+
recourser: if holder_is_anon {
147+
// if holder is anon, we need to continue as anon
148+
signer_public_data.as_anon().into()
149+
} else {
150+
signer_public_data.clone().into()
151+
},
152+
recoursee: recoursee.clone().into(),
153+
sum,
154+
currency: currency.to_owned(),
155+
recourse_reason: reason,
156+
signatory: signing_keys.signatory_identity,
157+
signing_timestamp: timestamp,
158+
signing_address: signer_public_data.postal_address(),
159+
};
160+
block_data.validate()?;
161+
BillBlock::create_block_for_request_recourse(
162+
bill_id.to_owned(),
163+
previous_block,
164+
&block_data,
165+
&signing_keys.signatory_keys,
166+
signing_keys.company_keys.as_ref(),
167+
&BcrKeys::from_private_key(&bill_keys.private_key)?,
168+
timestamp,
169+
)?
169170
}
170171
// has to be ident to recourse
171172
BillAction::Recourse(recoursee, sum, currency, recourse_reason) => {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl BillService {
474474
}
475475

476476
let recourser = self
477-
.extend_bill_chain_identity_data_from_contacts_or_identity(
477+
.extend_bill_chain_participant_data_from_contacts_or_identity(
478478
payment_info.recourser.clone(),
479479
local_identity,
480480
&contacts,
@@ -490,7 +490,7 @@ impl BillService {
490490

491491
let address_to_pay = self.bitcoin_client.get_address_to_pay(
492492
&bill_keys.public_key,
493-
&payment_info.recourser.node_id.pub_key(),
493+
&payment_info.recourser.node_id().pub_key(),
494494
)?;
495495

496496
let link_to_pay = self.bitcoin_client.generate_link_to_pay(
@@ -768,7 +768,7 @@ impl BillService {
768768
}
769769
Some(BillCurrentWaitingState::Recourse(state)) => {
770770
state.recourser = self
771-
.extend_bill_chain_identity_data_from_contacts_or_identity(
771+
.extend_bill_chain_participant_data_from_contacts_or_identity(
772772
state.recourser.clone().into(),
773773
identity,
774774
contacts,

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

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5363,7 +5363,10 @@ pub mod tests {
53635363
bill_id_test(),
53645364
chain.get_latest_block(),
53655365
&BillRequestRecourseBlockData {
5366-
recourser: bill_identified_participant_only_node_id(payee.node_id()).into(),
5366+
recourser: BillParticipant::Ident(
5367+
bill_identified_participant_only_node_id(payee.node_id()),
5368+
)
5369+
.into(),
53675370
recoursee: BillIdentParticipant::new(get_baseline_identity().identity)
53685371
.unwrap()
53695372
.into(),
@@ -5372,7 +5375,7 @@ pub mod tests {
53725375
recourse_reason: BillRecourseReasonBlockData::Pay,
53735376
signatory: None,
53745377
signing_timestamp: now,
5375-
signing_address: empty_address(),
5378+
signing_address: Some(empty_address()),
53765379
},
53775380
&BcrKeys::from_private_key(&private_key_test()).unwrap(),
53785381
None,
@@ -5431,7 +5434,10 @@ pub mod tests {
54315434
bill_id_test(),
54325435
chain.get_latest_block(),
54335436
&BillRequestRecourseBlockData {
5434-
recourser: bill_identified_participant_only_node_id(payee.node_id()).into(),
5437+
recourser: BillParticipant::Ident(
5438+
bill_identified_participant_only_node_id(payee.node_id()),
5439+
)
5440+
.into(),
54355441
recoursee: BillIdentParticipant::new(get_baseline_identity().identity)
54365442
.unwrap()
54375443
.into(),
@@ -5440,7 +5446,7 @@ pub mod tests {
54405446
recourse_reason: BillRecourseReasonBlockData::Pay,
54415447
signatory: None,
54425448
signing_timestamp: now,
5443-
signing_address: empty_address(),
5449+
signing_address: Some(empty_address()),
54445450
},
54455451
&BcrKeys::from_private_key(&private_key_test()).unwrap(),
54465452
None,
@@ -5502,17 +5508,18 @@ pub mod tests {
55025508
bill_id_test(),
55035509
chain.get_latest_block(),
55045510
&BillRequestRecourseBlockData {
5505-
recourser: BillIdentParticipant::new(get_baseline_identity().identity)
5506-
.unwrap()
5507-
.into(),
5511+
recourser: BillParticipant::Ident(
5512+
BillIdentParticipant::new(get_baseline_identity().identity).unwrap(),
5513+
)
5514+
.into(),
55085515
recoursee: bill_identified_participant_only_node_id(recoursee.clone())
55095516
.into(),
55105517
currency: "sat".to_string(),
55115518
sum: 15000,
55125519
recourse_reason: BillRecourseReasonBlockData::Pay,
55135520
signatory: None,
55145521
signing_timestamp: now,
5515-
signing_address: empty_address(),
5522+
signing_address: Some(empty_address()),
55165523
},
55175524
&BcrKeys::from_private_key(&private_key_test()).unwrap(),
55185525
None,
@@ -5577,7 +5584,10 @@ pub mod tests {
55775584
bill_id_test(),
55785585
chain.get_latest_block(),
55795586
&BillRequestRecourseBlockData {
5580-
recourser: BillIdentParticipant::from(company_clone.clone()).into(),
5587+
recourser: BillParticipant::Ident(BillIdentParticipant::from(
5588+
company_clone.clone(),
5589+
))
5590+
.into(),
55815591
recoursee: bill_identified_participant_only_node_id(recoursee.clone())
55825592
.into(),
55835593
currency: "sat".to_string(),
@@ -5588,7 +5598,7 @@ pub mod tests {
55885598
name: get_baseline_identity().identity.name.clone(),
55895599
}),
55905600
signing_timestamp: now,
5591-
signing_address: empty_address(),
5601+
signing_address: Some(empty_address()),
55925602
},
55935603
&BcrKeys::from_private_key(&private_key_test()).unwrap(),
55945604
Some(&BcrKeys::from_private_key(&private_key_test()).unwrap()),
@@ -5714,7 +5724,7 @@ pub mod tests {
57145724
}
57155725

57165726
#[tokio::test]
5717-
async fn request_recourse_fails_for_anon() {
5727+
async fn request_recourse_works_for_anon() {
57185728
let mut ctx = get_ctx();
57195729
let identity = get_baseline_identity();
57205730
let mut bill = get_baseline_bill(&bill_id_test());
@@ -5794,6 +5804,8 @@ pub mod tests {
57945804
ctx.notification_service
57955805
.expect_send_recourse_action_event()
57965806
.returning(|_, _, _| Ok(()));
5807+
// Populates identity block
5808+
expect_populates_identity_block(&mut ctx);
57975809
let service = get_service(ctx);
57985810

57995811
let res = service
@@ -5808,11 +5820,9 @@ pub mod tests {
58085820
1731593928,
58095821
)
58105822
.await;
5811-
assert!(res.is_err());
5812-
assert!(matches!(
5813-
res.as_ref().unwrap_err(),
5814-
Error::Validation(ValidationError::SignerCantBeAnon)
5815-
));
5823+
assert!(res.is_ok());
5824+
assert!(res.as_ref().unwrap().blocks().len() == 5);
5825+
assert!(res.unwrap().blocks()[4].op_code == BillOpCode::RequestRecourse);
58165826
}
58175827

58185828
#[tokio::test]
@@ -5951,16 +5961,17 @@ pub mod tests {
59515961
bill_id_test(),
59525962
chain.get_latest_block(),
59535963
&BillRequestRecourseBlockData {
5954-
recourser: BillIdentParticipant::new(identity_clone.clone())
5955-
.unwrap()
5956-
.into(),
5964+
recourser: BillParticipant::Ident(
5965+
BillIdentParticipant::new(identity_clone.clone()).unwrap(),
5966+
)
5967+
.into(),
59575968
recoursee: recoursee_clone.clone().into(),
59585969
sum: 15000,
59595970
currency: "sat".to_string(),
59605971
recourse_reason: BillRecourseReasonBlockData::Pay,
59615972
signatory: None,
59625973
signing_timestamp: 1731593927,
5963-
signing_address: empty_address(),
5974+
signing_address: Some(empty_address()),
59645975
},
59655976
&BcrKeys::new(),
59665977
None,
@@ -6032,16 +6043,17 @@ pub mod tests {
60326043
bill_id_test(),
60336044
chain.get_latest_block(),
60346045
&BillRequestRecourseBlockData {
6035-
recourser: BillIdentParticipant::new(identity_clone.clone())
6036-
.unwrap()
6037-
.into(),
6046+
recourser: BillParticipant::Ident(
6047+
BillIdentParticipant::new(identity_clone.clone()).unwrap(),
6048+
)
6049+
.into(),
60386050
recoursee: recoursee_clone.clone().into(),
60396051
sum: 15000,
60406052
currency: "sat".to_string(),
60416053
recourse_reason: BillRecourseReasonBlockData::Pay,
60426054
signatory: None,
60436055
signing_timestamp: 1731593927,
6044-
signing_address: empty_address(),
6056+
signing_address: Some(empty_address()),
60456057
},
60466058
&BcrKeys::new(),
60476059
None,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl BillService {
128128
// calculate payment address
129129
let payment_address = self.bitcoin_client.get_address_to_pay(
130130
&bill_keys.public_key,
131-
&payment_info.recourser.node_id.pub_key(),
131+
&payment_info.recourser.node_id().pub_key(),
132132
)?;
133133
// check if paid
134134
if let Ok(payment_state) = self
@@ -164,7 +164,7 @@ impl BillService {
164164
"bill {bill_id} is recourse-paid - creating recourse block if we're recourser"
165165
);
166166
// If we are the recourser and a bill issuer and it's paid, we add a Recourse block
167-
if payment_info.recourser.node_id == identity.identity.node_id {
167+
if payment_info.recourser.node_id() == identity.identity.node_id {
168168
if let Ok(signer_identity) =
169169
BillIdentParticipant::new(identity.identity.clone())
170170
{
@@ -207,7 +207,7 @@ impl BillService {
207207
self.company_store.get_all().await?;
208208
// If a local company is the recourser, create the recourse block as that company
209209
if let Some(recourser_company) =
210-
local_companies.get(&payment_info.recourser.node_id)
210+
local_companies.get(&payment_info.recourser.node_id())
211211
&& recourser_company
212212
.0
213213
.signatories

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ impl BillServiceApi for BillService {
13941394
for past_sell_payment in past_recourse_payments {
13951395
let address_to_pay = self.bitcoin_client.get_address_to_pay(
13961396
&bill_keys.public_key,
1397-
&past_sell_payment.0.recourser.node_id.pub_key(),
1397+
&past_sell_payment.0.recourser.node_id().pub_key(),
13981398
)?;
13991399
let link_to_pay = self.bitcoin_client.generate_link_to_pay(
14001400
&address_to_pay,

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,17 @@ pub fn request_to_recourse_block(
331331
id.to_owned(),
332332
first_block,
333333
&BillRequestRecourseBlockData {
334-
recourser: bill_identified_participant_only_node_id(node_id_test()).into(),
334+
recourser: BillParticipant::Ident(bill_identified_participant_only_node_id(
335+
node_id_test(),
336+
))
337+
.into(),
335338
recoursee: recoursee.to_owned().into(),
336339
sum: 15000,
337340
currency: "sat".to_string(),
338341
recourse_reason: BillRecourseReasonBlockData::Pay,
339342
signatory: None,
340343
signing_timestamp: timestamp,
341-
signing_address: empty_address(),
344+
signing_address: Some(empty_address()),
342345
},
343346
&BcrKeys::from_private_key(&private_key_test()).unwrap(),
344347
None,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ pub struct BillWaitingForPaymentState {
260260

261261
#[derive(Debug, Clone, PartialEq, Eq)]
262262
pub struct BillWaitingForRecourseState {
263-
pub recourser: BillIdentParticipant,
263+
pub recourser: BillParticipant,
264264
pub recoursee: BillIdentParticipant,
265265
pub payment_data: BillWaitingStatePaymentData,
266266
}
@@ -598,7 +598,7 @@ pub struct PastPaymentDataPayment {
598598
#[derive(Debug, Clone)]
599599
pub struct PastPaymentDataRecourse {
600600
pub time_of_request: u64,
601-
pub recourser: BillIdentParticipant,
601+
pub recourser: BillParticipant,
602602
pub recoursee: BillIdentParticipant,
603603
pub currency: String,
604604
pub sum: String,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl Validate for BillValidateActionData {
250250
if payment_info.sum != *sum
251251
|| payment_info.currency != *currency
252252
|| payment_info.recoursee.node_id != recoursee.node_id
253-
|| payment_info.recourser.node_id != self.signer_node_id
253+
|| payment_info.recourser.node_id() != self.signer_node_id
254254
|| payment_info.reason != recourse_reason
255255
{
256256
return Err(ValidationError::BillRecourseDataInvalid);
@@ -767,14 +767,14 @@ mod tests {
767767
bill_id_test(),
768768
chain.get_latest_block(),
769769
&BillRequestRecourseBlockData {
770-
recourser: valid_bill_identified_participant().into(),
770+
recourser: BillParticipant::Ident(valid_bill_identified_participant()).into(),
771771
recoursee: valid_other_bill_identified_participant().into(),
772772
sum: 500,
773773
currency: "sat".into(),
774774
recourse_reason: BillRecourseReasonBlockData::Accept,
775775
signatory: None,
776776
signing_timestamp: chain.get_latest_block().timestamp + 1,
777-
signing_address: valid_address(),
777+
signing_address: Some(valid_address()),
778778
},
779779
&keys(),
780780
None,

0 commit comments

Comments
 (0)