Skip to content

Commit 94d4d41

Browse files
authored
split up data between web and the rest (#404)
1 parent 6065ad4 commit 94d4d41

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1670
-1835
lines changed

src/blockchain/bill/block.rs

Lines changed: 5 additions & 670 deletions
Large diffs are not rendered by default.

src/blockchain/bill/chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::{BillOpCode, RecourseWaitingForPayment};
77
use super::{OfferToSellWaitingForPayment, RecoursePaymentInfo};
88
use crate::blockchain::{Block, Blockchain, Error};
99
use crate::constants::{PAYMENT_DEADLINE_SECONDS, RECOURSE_DEADLINE_SECONDS};
10-
use crate::service::bill_service::BillKeys;
10+
use crate::data::bill::BillKeys;
1111
use crate::util::{self, BcrKeys};
1212
use borsh_derive::{BorshDeserialize, BorshSerialize};
1313
use serde::{Deserialize, Serialize};
@@ -251,7 +251,7 @@ mod tests {
251251
use super::*;
252252
use crate::{
253253
blockchain::bill::{block::BillOfferToSellBlockData, tests::get_baseline_identity},
254-
service::{bill_service::BitcreditBill, contact_service::IdentityPublicData},
254+
data::{bill::BitcreditBill, contact::IdentityPublicData},
255255
tests::tests::{get_bill_keys, TEST_PRIVATE_KEY_SECP},
256256
};
257257

src/blockchain/bill/mod.rs

Lines changed: 5 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use borsh_derive::{BorshDeserialize, BorshSerialize};
22
use serde::{Deserialize, Serialize};
3-
use utoipa::ToSchema;
4-
5-
use super::{Blockchain, Result};
6-
use crate::service::bill_service::BillKeys;
73

84
pub mod block;
95
pub mod chain;
@@ -13,16 +9,7 @@ use block::BillIdentityBlockData;
139
pub use chain::BillBlockchain;
1410

1511
#[derive(
16-
BorshSerialize,
17-
BorshDeserialize,
18-
Serialize,
19-
Deserialize,
20-
Debug,
21-
Clone,
22-
PartialEq,
23-
Eq,
24-
ToSchema,
25-
Hash,
12+
BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash,
2613
)]
2714
pub enum BillOpCode {
2815
Issue,
@@ -70,69 +57,14 @@ pub struct RecoursePaymentInfo {
7057
pub currency: String,
7158
}
7259

73-
#[derive(Serialize, Deserialize, Debug, Clone, ToSchema)]
74-
pub struct BillBlockchainToReturn {
75-
pub blocks: Vec<BillBlockToReturn>,
76-
}
77-
78-
impl BillBlockchainToReturn {
79-
/// Creates a new blockchain to return by transforming a given blockchain into its corresponding representation.
80-
///
81-
/// # Parameters
82-
/// * `chain` - The blockchain to be transformed. It contains the list of blocks and the initial bill version
83-
/// necessary for processing.
84-
/// * `bill_keys` - The keys for the bill
85-
///
86-
/// # Returns
87-
/// A new instance containing the transformed `BillBlockToReturn` objects.
88-
///
89-
pub fn new(chain: BillBlockchain, bill_keys: &BillKeys) -> Result<Self> {
90-
let mut blocks: Vec<BillBlockToReturn> = Vec::new();
91-
for block in chain.blocks() {
92-
blocks.push(BillBlockToReturn::new(block.clone(), bill_keys)?);
93-
}
94-
Ok(Self { blocks })
95-
}
96-
}
97-
98-
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, ToSchema)]
99-
pub struct BillBlockToReturn {
100-
pub id: u64,
101-
pub hash: String,
102-
pub timestamp: u64,
103-
pub data: String,
104-
pub previous_hash: String,
105-
pub signature: String,
106-
pub op_code: BillOpCode,
107-
pub label: String,
108-
}
109-
110-
impl BillBlockToReturn {
111-
/// Creates a new block to return for the given bill, with an attached history label,
112-
/// describing what happened in this block
113-
pub fn new(block: BillBlock, bill_keys: &BillKeys) -> Result<Self> {
114-
let label = block.get_history_label(bill_keys)?;
115-
116-
Ok(Self {
117-
id: block.id,
118-
hash: block.hash,
119-
timestamp: block.timestamp,
120-
data: block.data,
121-
previous_hash: block.previous_hash,
122-
signature: block.signature,
123-
op_code: block.op_code,
124-
label,
125-
})
126-
}
127-
}
128-
12960
#[cfg(test)]
13061
pub mod tests {
13162
use super::*;
13263
use crate::{
133-
service::{
134-
bill_service::BitcreditBill,
135-
identity_service::{Identity, IdentityWithAll},
64+
blockchain::Blockchain,
65+
data::{
66+
bill::BitcreditBill,
67+
identity::{Identity, IdentityWithAll},
13668
},
13769
tests::tests::TEST_PRIVATE_KEY_SECP,
13870
util::BcrKeys,

src/blockchain/company/mod.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use super::bill::BillOpCode;
22
use super::Result;
33
use super::{Block, Blockchain, FIRST_BLOCK_ID};
4-
use crate::service::company_service::{CompanyKeys, CompanyToReturn};
4+
use crate::data::{
5+
company::{Company, CompanyKeys},
6+
File, OptionalPostalAddress, PostalAddress,
7+
};
58
use crate::util::{self, crypto, BcrKeys};
6-
use crate::web::data::{File, OptionalPostalAddress, PostalAddress};
79
use borsh::to_vec;
810
use borsh_derive::{BorshDeserialize, BorshSerialize};
911
use serde::{Deserialize, Serialize};
@@ -74,8 +76,8 @@ pub struct CompanyCreateBlockData {
7476
pub signatories: Vec<String>,
7577
}
7678

77-
impl From<CompanyToReturn> for CompanyCreateBlockData {
78-
fn from(value: CompanyToReturn) -> Self {
79+
impl From<Company> for CompanyCreateBlockData {
80+
fn from(value: Company) -> Self {
7981
Self {
8082
id: value.id,
8183
name: value.name,
@@ -469,17 +471,15 @@ impl CompanyBlockchain {
469471
mod tests {
470472
use super::*;
471473
use crate::{
472-
service::company_service::{tests::get_baseline_company_data, CompanyToReturn},
473-
tests::tests::TEST_PUB_KEY_SECP,
474+
service::company_service::tests::get_baseline_company_data, tests::tests::TEST_PUB_KEY_SECP,
474475
};
475476

476477
#[test]
477478
fn create_and_check_validity() {
478-
let (id, (company, company_keys)) = get_baseline_company_data();
479-
let to_return = CompanyToReturn::from(id, company);
479+
let (_id, (company, company_keys)) = get_baseline_company_data();
480480

481481
let chain = CompanyBlockchain::new(
482-
&CompanyCreateBlockData::from(to_return),
482+
&CompanyCreateBlockData::from(company),
483483
&BcrKeys::new(),
484484
&company_keys,
485485
1731593928,
@@ -491,11 +491,10 @@ mod tests {
491491
#[test]
492492
fn multi_block() {
493493
let (id, (company, company_keys)) = get_baseline_company_data();
494-
let to_return = CompanyToReturn::from(id.clone(), company);
495494
let identity_keys = BcrKeys::new();
496495

497496
let chain = CompanyBlockchain::new(
498-
&CompanyCreateBlockData::from(to_return),
497+
&CompanyCreateBlockData::from(company),
499498
&identity_keys,
500499
&company_keys,
501500
1731593928,

src/blockchain/identity/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use super::bill::BillOpCode;
22
use super::Result;
33
use super::{Block, Blockchain, FIRST_BLOCK_ID};
4-
use crate::service::identity_service::Identity;
4+
use crate::data::{identity::Identity, File, OptionalPostalAddress};
55
use crate::util::{self, crypto, BcrKeys};
6-
use crate::web::data::{File, OptionalPostalAddress};
76
use borsh::to_vec;
87
use borsh_derive::{BorshDeserialize, BorshSerialize};
98
use serde::{Deserialize, Serialize};

0 commit comments

Comments
 (0)