@@ -2,68 +2,40 @@ use super::{BillAction, BillServiceApi, Result, error::Error, service::BillServi
2
2
use crate :: util;
3
3
use bcr_ebill_core:: {
4
4
File , Validate ,
5
- bill:: { BillKeys , BillType , BitcreditBill , validation:: validate_bill_issue} ,
5
+ bill:: { BillIssueData , BillKeys , BillType , BitcreditBill , validation:: validate_bill_issue} ,
6
6
blockchain:: {
7
7
Blockchain ,
8
8
bill:: { BillBlockchain , block:: BillIssueBlockData } ,
9
9
} ,
10
- contact:: IdentityPublicData ,
11
10
util:: BcrKeys ,
12
11
} ;
13
12
use bcr_ebill_transport:: BillChainEvent ;
14
13
use log:: { debug, error} ;
15
14
16
15
impl BillService {
17
- #[ allow( clippy:: too_many_arguments) ]
18
- pub ( super ) async fn issue_bill (
19
- & self ,
20
- t : u64 ,
21
- country_of_issuing : String ,
22
- city_of_issuing : String ,
23
- issue_date : String ,
24
- maturity_date : String ,
25
- drawee : String ,
26
- payee : String ,
27
- sum : String ,
28
- currency : String ,
29
- country_of_payment : String ,
30
- city_of_payment : String ,
31
- language : String ,
32
- file_upload_ids : Vec < String > ,
33
- drawer_public_data : IdentityPublicData ,
34
- drawer_keys : BcrKeys ,
35
- timestamp : u64 ,
36
- ) -> Result < BitcreditBill > {
37
- debug ! ( "issuing bill with type {t}" ) ;
38
- let ( sum, bill_type) = validate_bill_issue (
39
- & sum,
40
- & file_upload_ids,
41
- & issue_date,
42
- & maturity_date,
43
- & drawee,
44
- & payee,
45
- t,
46
- ) ?;
16
+ pub ( super ) async fn issue_bill ( & self , data : BillIssueData ) -> Result < BitcreditBill > {
17
+ debug ! ( "issuing bill with type {}" , & data. t) ;
18
+ let ( sum, bill_type) = validate_bill_issue ( & data) ?;
47
19
48
20
let ( public_data_drawee, public_data_payee) = match bill_type {
49
21
// Drawer is payee
50
22
BillType :: SelfDrafted => {
51
- let public_data_drawee = match self . contact_store . get ( & drawee) . await {
23
+ let public_data_drawee = match self . contact_store . get ( & data . drawee ) . await {
52
24
Ok ( Some ( drawee) ) => drawee. into ( ) ,
53
25
Ok ( None ) | Err ( _) => {
54
26
return Err ( Error :: DraweeNotInContacts ) ;
55
27
}
56
28
} ;
57
29
58
- let public_data_payee = drawer_public_data. clone ( ) ;
30
+ let public_data_payee = data . drawer_public_data . clone ( ) ;
59
31
60
32
( public_data_drawee, public_data_payee)
61
33
}
62
34
// Drawer is drawee
63
35
BillType :: PromissoryNote => {
64
- let public_data_drawee = drawer_public_data. clone ( ) ;
36
+ let public_data_drawee = data . drawer_public_data . clone ( ) ;
65
37
66
- let public_data_payee = match self . contact_store . get ( & payee) . await {
38
+ let public_data_payee = match self . contact_store . get ( & data . payee ) . await {
67
39
Ok ( Some ( drawee) ) => drawee. into ( ) ,
68
40
Ok ( None ) | Err ( _) => {
69
41
return Err ( Error :: PayeeNotInContacts ) ;
@@ -74,14 +46,14 @@ impl BillService {
74
46
}
75
47
// Drawer is neither drawee nor payee
76
48
BillType :: ThreeParties => {
77
- let public_data_drawee = match self . contact_store . get ( & drawee) . await {
49
+ let public_data_drawee = match self . contact_store . get ( & data . drawee ) . await {
78
50
Ok ( Some ( drawee) ) => drawee. into ( ) ,
79
51
Ok ( None ) | Err ( _) => {
80
52
return Err ( Error :: DraweeNotInContacts ) ;
81
53
}
82
54
} ;
83
55
84
- let public_data_payee = match self . contact_store . get ( & payee) . await {
56
+ let public_data_payee = match self . contact_store . get ( & data . payee ) . await {
85
57
Ok ( Some ( drawee) ) => drawee. into ( ) ,
86
58
Ok ( None ) | Err ( _) => {
87
59
return Err ( Error :: PayeeNotInContacts ) ;
@@ -104,7 +76,7 @@ impl BillService {
104
76
} ;
105
77
106
78
let mut bill_files: Vec < File > = vec ! [ ] ;
107
- for file_upload_id in file_upload_ids. iter ( ) {
79
+ for file_upload_id in data . file_upload_ids . iter ( ) {
108
80
let ( file_name, file_bytes) = & self
109
81
. file_upload_store
110
82
. read_temp_upload_file ( file_upload_id)
@@ -118,25 +90,29 @@ impl BillService {
118
90
119
91
let bill = BitcreditBill {
120
92
id : bill_id. clone ( ) ,
121
- country_of_issuing,
122
- city_of_issuing,
123
- currency,
93
+ country_of_issuing : data . country_of_issuing ,
94
+ city_of_issuing : data . city_of_issuing ,
95
+ currency : data . currency ,
124
96
sum,
125
- maturity_date,
126
- issue_date,
127
- country_of_payment,
128
- city_of_payment,
129
- language,
97
+ maturity_date : data . maturity_date ,
98
+ issue_date : data . issue_date ,
99
+ country_of_payment : data . country_of_payment ,
100
+ city_of_payment : data . city_of_payment ,
101
+ language : data . language ,
130
102
drawee : public_data_drawee,
131
- drawer : drawer_public_data. clone ( ) ,
103
+ drawer : data . drawer_public_data . clone ( ) ,
132
104
payee : public_data_payee,
133
105
endorsee : None ,
134
106
files : bill_files,
135
107
} ;
136
108
137
- let signing_keys = self . get_bill_signing_keys ( & drawer_public_data, & drawer_keys, & identity) ;
138
- let block_data =
139
- BillIssueBlockData :: from ( bill. clone ( ) , signing_keys. signatory_identity , timestamp) ;
109
+ let signing_keys =
110
+ self . get_bill_signing_keys ( & data. drawer_public_data , & data. drawer_keys , & identity) ;
111
+ let block_data = BillIssueBlockData :: from (
112
+ bill. clone ( ) ,
113
+ signing_keys. signatory_identity ,
114
+ data. timestamp ,
115
+ ) ;
140
116
block_data. validate ( ) ?;
141
117
142
118
self . store . save_keys ( & bill_id, & bill_keys) . await ?;
@@ -145,19 +121,19 @@ impl BillService {
145
121
signing_keys. signatory_keys ,
146
122
signing_keys. company_keys ,
147
123
keys. clone ( ) ,
148
- timestamp,
124
+ data . timestamp ,
149
125
) ?;
150
126
151
127
let block = chain. get_first_block ( ) ;
152
128
self . blockchain_store . add_block ( & bill. id , block) . await ?;
153
129
154
130
self . add_identity_and_company_chain_blocks_for_signed_bill_action (
155
- & drawer_public_data,
131
+ & data . drawer_public_data ,
156
132
& bill_id,
157
133
block,
158
134
& identity. key_pair ,
159
- & drawer_keys,
160
- timestamp,
135
+ & data . drawer_keys ,
136
+ data . timestamp ,
161
137
)
162
138
. await ?;
163
139
@@ -167,13 +143,13 @@ impl BillService {
167
143
& chain,
168
144
& bill_keys,
169
145
& identity. identity ,
170
- & drawer_public_data. node_id ,
171
- timestamp,
146
+ & data . drawer_public_data . node_id ,
147
+ data . timestamp ,
172
148
)
173
149
. await ?;
174
150
175
151
// clean up temporary file uploads, if there are any, logging any errors
176
- for file_upload_id in file_upload_ids. iter ( ) {
152
+ for file_upload_id in data . file_upload_ids . iter ( ) {
177
153
if let Err ( e) = self
178
154
. file_upload_store
179
155
. remove_temp_upload_folder ( file_upload_id)
@@ -209,9 +185,9 @@ impl BillService {
209
185
self . execute_bill_action (
210
186
& bill_id,
211
187
BillAction :: Accept ,
212
- & drawer_public_data,
213
- & drawer_keys,
214
- timestamp + 1 ,
188
+ & data . drawer_public_data ,
189
+ & data . drawer_keys ,
190
+ data . timestamp + 1 ,
215
191
)
216
192
. await ?;
217
193
}
0 commit comments