Skip to content

Commit 0d88139

Browse files
authored
remove unnecessary borsh derives (#555)
1 parent 5d0175f commit 0d88139

File tree

9 files changed

+18
-141
lines changed

9 files changed

+18
-141
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use super::{
1616
},
1717
notification::Notification,
1818
};
19-
use borsh_derive::{BorshDeserialize, BorshSerialize};
2019
use serde::{Deserialize, Serialize};
2120

2221
pub mod validation;
@@ -200,7 +199,7 @@ pub struct BillValidateActionData {
200199
pub is_paid: bool,
201200
}
202201

203-
#[derive(BorshSerialize, BorshDeserialize, Debug, Serialize, Deserialize, Clone)]
202+
#[derive(Debug, Serialize, Deserialize, Clone)]
204203
pub struct BitcreditBill {
205204
pub id: String,
206205
pub country_of_issuing: String,
@@ -222,7 +221,7 @@ pub struct BitcreditBill {
222221
pub files: Vec<File>,
223222
}
224223

225-
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, Clone)]
224+
#[derive(Serialize, Deserialize, Debug, Clone)]
226225
pub struct BillKeys {
227226
pub private_key: String,
228227
pub public_key: String,
@@ -536,7 +535,7 @@ pub enum BillsFilterRole {
536535
Contingent,
537536
}
538537

539-
#[derive(BorshSerialize, BorshDeserialize, Debug)]
538+
#[derive(Debug)]
540539
pub struct PastEndorsee {
541540
pub pay_to_the_order_of: LightBillIdentParticipant,
542541
pub signed: LightSignedBy,
@@ -552,7 +551,7 @@ pub struct Endorsement {
552551
pub signing_address: Option<PostalAddress>,
553552
}
554553

555-
#[derive(BorshSerialize, BorshDeserialize, Debug)]
554+
#[derive(Debug)]
556555
pub struct LightSignedBy {
557556
pub data: LightBillParticipant,
558557
pub signatory: Option<LightBillIdentParticipant>,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use serde::{Deserialize, Serialize};
2727
use std::collections::HashSet;
2828
use std::str::FromStr;
2929

30-
#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Debug, Clone, PartialEq)]
30+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
3131
pub struct BillBlock {
3232
pub bill_id: String,
3333
pub id: u64,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::contact::{
1414
BillParticipant, ContactType, LightBillIdentParticipant, LightBillParticipant,
1515
};
1616
use crate::util::{self, BcrKeys};
17-
use borsh_derive::{BorshDeserialize, BorshSerialize};
1817
use log::error;
1918
use serde::{Deserialize, Serialize};
2019
use std::collections::HashMap;
@@ -27,7 +26,7 @@ pub struct BillParties {
2726
pub endorsee: Option<BillParticipantBlockData>,
2827
}
2928

30-
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, Clone)]
29+
#[derive(Serialize, Deserialize, Debug, Clone)]
3130
pub struct BillBlockchain {
3231
blocks: Vec<BillBlock>,
3332
}

crates/bcr-ebill-core/src/company.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use super::{File, PostalAddress};
2-
use borsh_derive::{BorshDeserialize, BorshSerialize};
32
use serde::{Deserialize, Serialize};
43

5-
#[derive(BorshSerialize, BorshDeserialize, Debug, Serialize, Deserialize, Clone)]
4+
#[derive(Debug, Serialize, Deserialize, Clone)]
65
pub struct Company {
76
pub id: String,
87
pub name: String,
@@ -17,7 +16,7 @@ pub struct Company {
1716
pub signatories: Vec<String>,
1817
}
1918

20-
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, Clone)]
19+
#[derive(Serialize, Deserialize, Debug, Clone)]
2120
pub struct CompanyKeys {
2221
pub private_key: String,
2322
pub public_key: String,

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct Contact {
5757
pub nostr_relays: Vec<String>,
5858
}
5959

60-
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
60+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
6161
pub enum BillParticipant {
6262
Anon(BillAnonParticipant),
6363
Ident(BillIdentParticipant),
@@ -117,9 +117,7 @@ impl BillParticipant {
117117
}
118118
}
119119

120-
#[derive(
121-
BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default,
122-
)]
120+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
123121
pub struct BillAnonParticipant {
124122
/// The node id of the participant
125123
pub node_id: String,
@@ -148,9 +146,7 @@ impl From<BillParticipant> for BillAnonParticipant {
148146
}
149147
}
150148

151-
#[derive(
152-
BorshSerialize, BorshDeserialize, Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Default,
153-
)]
149+
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Default)]
154150
pub struct BillIdentParticipant {
155151
/// The type of identity (0 = person, 1 = company)
156152
#[serde(rename = "type")]
@@ -168,18 +164,18 @@ pub struct BillIdentParticipant {
168164
pub nostr_relays: Vec<String>,
169165
}
170166

171-
#[derive(BorshSerialize, BorshDeserialize, Debug, Serialize, Deserialize, Clone)]
167+
#[derive(Debug, Serialize, Deserialize, Clone)]
172168
pub enum LightBillParticipant {
173169
Anon(LightBillAnonParticipant),
174170
Ident(LightBillIdentParticipant),
175171
}
176172

177-
#[derive(BorshSerialize, BorshDeserialize, Debug, Serialize, Deserialize, Clone, Default)]
173+
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
178174
pub struct LightBillAnonParticipant {
179175
pub node_id: String,
180176
}
181177

182-
#[derive(BorshSerialize, BorshDeserialize, Debug, Serialize, Deserialize, Clone, Default)]
178+
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
183179
pub struct LightBillIdentParticipant {
184180
#[serde(rename = "type")]
185181
pub t: ContactType,
@@ -214,7 +210,7 @@ impl From<BillAnonParticipant> for LightBillAnonParticipant {
214210
}
215211
}
216212

217-
#[derive(BorshSerialize, BorshDeserialize, Debug, Serialize, Deserialize, Clone, Default)]
213+
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
218214
pub struct LightBillIdentParticipantWithAddress {
219215
#[serde(rename = "type")]
220216
pub t: ContactType,

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,18 @@
11
use super::{File, OptionalPostalAddress};
22
use crate::{ValidationError, util::BcrKeys};
3-
use borsh_derive::{BorshDeserialize, BorshSerialize};
43
use serde::{Deserialize, Serialize};
54

65
pub mod validation;
76

87
#[repr(u8)]
9-
#[derive(
10-
Debug,
11-
Clone,
12-
serde_repr::Serialize_repr,
13-
serde_repr::Deserialize_repr,
14-
PartialEq,
15-
Eq,
16-
BorshSerialize,
17-
BorshDeserialize,
18-
)]
19-
#[borsh(use_discriminant = true)]
8+
#[derive(Debug, Clone, serde_repr::Serialize_repr, serde_repr::Deserialize_repr, PartialEq, Eq)]
209
pub enum SwitchIdentityType {
2110
Person = 0,
2211
Company = 1,
2312
}
2413

2514
#[repr(u8)]
26-
#[derive(
27-
Debug,
28-
Clone,
29-
serde_repr::Serialize_repr,
30-
serde_repr::Deserialize_repr,
31-
PartialEq,
32-
Eq,
33-
BorshSerialize,
34-
BorshDeserialize,
35-
)]
36-
#[borsh(use_discriminant = true)]
15+
#[derive(Debug, Clone, serde_repr::Serialize_repr, serde_repr::Deserialize_repr, PartialEq, Eq)]
3716
pub enum IdentityType {
3817
Ident = 0,
3918
Anon = 1,
@@ -57,7 +36,7 @@ pub struct IdentityWithAll {
5736
pub key_pair: BcrKeys,
5837
}
5938

60-
#[derive(BorshSerialize, BorshDeserialize, Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
39+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
6140
pub struct Identity {
6241
#[serde(rename = "type")]
6342
pub t: IdentityType,

crates/bcr-ebill-core/src/util/crypto.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,9 @@ fn keypair_from_mnemonic(mnemonic: &Mnemonic) -> Result<Keypair> {
331331
mod tests {
332332
use super::*;
333333
use crate::{
334-
PostalAddress,
335-
company::Company,
336334
tests::tests::{TEST_NODE_ID_SECP, TEST_NODE_ID_SECP_AS_NPUB_HEX},
337335
util,
338336
};
339-
use borsh::to_vec;
340337

341338
const PKEY: &str = "926a7ce0fdacad199307bcbbcda4869bca84d54b939011bafe6a83cb194130d3";
342339

@@ -701,44 +698,6 @@ mod tests {
701698
assert_eq!(&msg, decrypted.as_ref().unwrap());
702699
}
703700

704-
#[test]
705-
fn encrypt_decrypt_ecies_big_data() {
706-
let company_data = Company {
707-
id: "company_id".to_owned(),
708-
name: "some_name".to_string(),
709-
country_of_registration: Some("AT".to_string()),
710-
city_of_registration: Some("Vienna".to_string()),
711-
postal_address: PostalAddress {
712-
country: "AT".to_string(),
713-
city: "Vienna".to_string(),
714-
zip: None,
715-
address: "Smithstreet 1".to_string(),
716-
},
717-
email: "[email protected]".to_string(),
718-
registration_number: Some("some_number".to_string()),
719-
registration_date: Some("2012-01-01".to_string()),
720-
proof_of_registration_file: None,
721-
logo_file: None,
722-
signatories: vec!["signatory".to_string()],
723-
};
724-
let mut companies = vec![];
725-
for _ in 0..100 {
726-
companies.push(company_data.clone());
727-
}
728-
let companies_bytes = to_vec(&companies).unwrap();
729-
let keypair = BcrKeys::new();
730-
731-
let encrypted = encrypt_ecies(&companies_bytes, &keypair.get_public_key());
732-
assert!(encrypted.is_ok());
733-
let decrypted = decrypt_ecies(
734-
encrypted.as_ref().unwrap(),
735-
&keypair.get_private_key_string(),
736-
);
737-
assert!(decrypted.is_ok());
738-
739-
assert_eq!(&companies_bytes, decrypted.as_ref().unwrap());
740-
}
741-
742701
#[test]
743702
fn get_nostr_npub_as_hex_from_node_id_base() {
744703
let node_id = "0239a02d7aa976f4ef69173c271926d15fbff71e5b7d9e1adbb37fac2f3a370a70";

crates/bcr-ebill-persistence/src/bill.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use bcr_ebill_core::{
88
blockchain::bill::{BillBlock, BillBlockchain, BillOpCode},
99
};
1010

11-
use borsh::{from_slice, to_vec};
12-
1311
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
1412
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
1513
pub trait BillStoreApi: ServiceTraitBounds {
@@ -73,23 +71,3 @@ pub trait BillChainStoreApi: ServiceTraitBounds {
7371
/// Get the whole blockchain
7472
async fn get_chain(&self, id: &str) -> Result<BillBlockchain>;
7573
}
76-
77-
pub fn bill_chain_from_bytes(bytes: &[u8]) -> Result<BillBlockchain> {
78-
let chain: BillBlockchain = from_slice(bytes)?;
79-
Ok(chain)
80-
}
81-
82-
pub fn bill_keys_from_bytes(bytes: &[u8]) -> Result<BillKeys> {
83-
let keys: BillKeys = from_slice(bytes)?;
84-
Ok(keys)
85-
}
86-
87-
pub fn bill_keys_to_bytes(keys: &BillKeys) -> Result<Vec<u8>> {
88-
let bytes = to_vec(&keys)?;
89-
Ok(bytes)
90-
}
91-
92-
pub fn bill_chain_to_bytes(chain: &BillBlockchain) -> Result<Vec<u8>> {
93-
let bytes = to_vec(&chain)?;
94-
Ok(bytes)
95-
}

crates/bcr-ebill-persistence/src/company.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use std::collections::HashMap;
66
use super::Result;
77
use async_trait::async_trait;
88

9-
use borsh::{from_slice, to_vec};
10-
119
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
1210
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
1311
pub trait CompanyStoreApi: ServiceTraitBounds {
@@ -51,33 +49,3 @@ pub trait CompanyChainStoreApi: ServiceTraitBounds {
5149
/// Get the whole blockchain
5250
async fn get_chain(&self, id: &str) -> Result<CompanyBlockchain>;
5351
}
54-
55-
pub fn company_from_bytes(bytes: &[u8]) -> Result<Company> {
56-
let company: Company = from_slice(bytes)?;
57-
Ok(company)
58-
}
59-
60-
pub fn company_to_bytes(company: &Company) -> Result<Vec<u8>> {
61-
let bytes = to_vec(&company)?;
62-
Ok(bytes)
63-
}
64-
65-
pub fn company_keys_from_bytes(bytes: &[u8]) -> Result<CompanyKeys> {
66-
let company_keys: CompanyKeys = from_slice(bytes)?;
67-
Ok(company_keys)
68-
}
69-
70-
pub fn company_keys_to_bytes(company_keys: &CompanyKeys) -> Result<Vec<u8>> {
71-
let bytes = to_vec(&company_keys)?;
72-
Ok(bytes)
73-
}
74-
75-
pub fn company_chain_from_bytes(bytes: &[u8]) -> Result<CompanyBlockchain> {
76-
let company_chain: CompanyBlockchain = from_slice(bytes)?;
77-
Ok(company_chain)
78-
}
79-
80-
pub fn company_chain_to_bytes(company_chain: &CompanyBlockchain) -> Result<Vec<u8>> {
81-
let bytes = to_vec(&company_chain)?;
82-
Ok(bytes)
83-
}

0 commit comments

Comments
 (0)