@@ -2,68 +2,40 @@ use super::{BillAction, BillServiceApi, Result, error::Error, service::BillServi
22use crate :: util;
33use bcr_ebill_core:: {
44 File , Validate ,
5- bill:: { BillKeys , BillType , BitcreditBill , validation:: validate_bill_issue} ,
5+ bill:: { BillIssueData , BillKeys , BillType , BitcreditBill , validation:: validate_bill_issue} ,
66 blockchain:: {
77 Blockchain ,
88 bill:: { BillBlockchain , block:: BillIssueBlockData } ,
99 } ,
10- contact:: IdentityPublicData ,
1110 util:: BcrKeys ,
1211} ;
1312use bcr_ebill_transport:: BillChainEvent ;
1413use log:: { debug, error} ;
1514
1615impl 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) ?;
4719
4820 let ( public_data_drawee, public_data_payee) = match bill_type {
4921 // Drawer is payee
5022 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 {
5224 Ok ( Some ( drawee) ) => drawee. into ( ) ,
5325 Ok ( None ) | Err ( _) => {
5426 return Err ( Error :: DraweeNotInContacts ) ;
5527 }
5628 } ;
5729
58- let public_data_payee = drawer_public_data. clone ( ) ;
30+ let public_data_payee = data . drawer_public_data . clone ( ) ;
5931
6032 ( public_data_drawee, public_data_payee)
6133 }
6234 // Drawer is drawee
6335 BillType :: PromissoryNote => {
64- let public_data_drawee = drawer_public_data. clone ( ) ;
36+ let public_data_drawee = data . drawer_public_data . clone ( ) ;
6537
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 {
6739 Ok ( Some ( drawee) ) => drawee. into ( ) ,
6840 Ok ( None ) | Err ( _) => {
6941 return Err ( Error :: PayeeNotInContacts ) ;
@@ -74,14 +46,14 @@ impl BillService {
7446 }
7547 // Drawer is neither drawee nor payee
7648 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 {
7850 Ok ( Some ( drawee) ) => drawee. into ( ) ,
7951 Ok ( None ) | Err ( _) => {
8052 return Err ( Error :: DraweeNotInContacts ) ;
8153 }
8254 } ;
8355
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 {
8557 Ok ( Some ( drawee) ) => drawee. into ( ) ,
8658 Ok ( None ) | Err ( _) => {
8759 return Err ( Error :: PayeeNotInContacts ) ;
@@ -104,7 +76,7 @@ impl BillService {
10476 } ;
10577
10678 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 ( ) {
10880 let ( file_name, file_bytes) = & self
10981 . file_upload_store
11082 . read_temp_upload_file ( file_upload_id)
@@ -118,25 +90,29 @@ impl BillService {
11890
11991 let bill = BitcreditBill {
12092 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 ,
12496 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 ,
130102 drawee : public_data_drawee,
131- drawer : drawer_public_data. clone ( ) ,
103+ drawer : data . drawer_public_data . clone ( ) ,
132104 payee : public_data_payee,
133105 endorsee : None ,
134106 files : bill_files,
135107 } ;
136108
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+ ) ;
140116 block_data. validate ( ) ?;
141117
142118 self . store . save_keys ( & bill_id, & bill_keys) . await ?;
@@ -145,19 +121,19 @@ impl BillService {
145121 signing_keys. signatory_keys ,
146122 signing_keys. company_keys ,
147123 keys. clone ( ) ,
148- timestamp,
124+ data . timestamp ,
149125 ) ?;
150126
151127 let block = chain. get_first_block ( ) ;
152128 self . blockchain_store . add_block ( & bill. id , block) . await ?;
153129
154130 self . add_identity_and_company_chain_blocks_for_signed_bill_action (
155- & drawer_public_data,
131+ & data . drawer_public_data ,
156132 & bill_id,
157133 block,
158134 & identity. key_pair ,
159- & drawer_keys,
160- timestamp,
135+ & data . drawer_keys ,
136+ data . timestamp ,
161137 )
162138 . await ?;
163139
@@ -167,13 +143,13 @@ impl BillService {
167143 & chain,
168144 & bill_keys,
169145 & identity. identity ,
170- & drawer_public_data. node_id ,
171- timestamp,
146+ & data . drawer_public_data . node_id ,
147+ data . timestamp ,
172148 )
173149 . await ?;
174150
175151 // 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 ( ) {
177153 if let Err ( e) = self
178154 . file_upload_store
179155 . remove_temp_upload_folder ( file_upload_id)
@@ -209,9 +185,9 @@ impl BillService {
209185 self . execute_bill_action (
210186 & bill_id,
211187 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 ,
215191 )
216192 . await ?;
217193 }
0 commit comments