Skip to content

Commit 7343fb0

Browse files
committed
Renaming AutoConceal trait and removing CommitEncode for Assignments
1 parent 0a12889 commit 7343fb0

File tree

5 files changed

+85
-52
lines changed

5 files changed

+85
-52
lines changed

src/contract/assignments.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use lnpbp::seals::OutpointReveal;
2727
use strict_encoding::{StrictDecode, StrictEncode};
2828

2929
use super::{
30-
data, seal, value, AtomicValue, AutoConceal, NoDataError, NodeId,
30+
data, seal, value, AtomicValue, ConcealState, NoDataError, NodeId,
3131
SealDefinition, SealEndpoint, SECP256K1_ZKP,
3232
};
3333
use crate::schema;
@@ -615,16 +615,19 @@ impl Assignments {
615615
}
616616
}
617617

618-
impl AutoConceal for Assignments {
619-
fn conceal_except(&mut self, seals: &Vec<seal::Confidential>) -> usize {
618+
impl ConcealState for Assignments {
619+
fn conceal_state_except(
620+
&mut self,
621+
seals: &Vec<seal::Confidential>,
622+
) -> usize {
620623
match self {
621-
Assignments::Declarative(data) => data as &mut dyn AutoConceal,
624+
Assignments::Declarative(data) => data as &mut dyn ConcealState,
622625
Assignments::DiscreteFiniteField(data) => {
623-
data as &mut dyn AutoConceal
626+
data as &mut dyn ConcealState
624627
}
625-
Assignments::CustomData(data) => data as &mut dyn AutoConceal,
628+
Assignments::CustomData(data) => data as &mut dyn ConcealState,
626629
}
627-
.conceal_except(seals)
630+
.conceal_state_except(seals)
628631
}
629632
}
630633

@@ -981,15 +984,18 @@ where
981984
}
982985
}
983986

984-
impl<STATE> AutoConceal for OwnedState<STATE>
987+
impl<STATE> ConcealState for OwnedState<STATE>
985988
where
986989
STATE: StateTypes,
987990
STATE::Revealed: CommitConceal,
988991
STATE::Confidential: PartialEq + Eq,
989992
<STATE as StateTypes>::Confidential:
990993
From<<STATE::Revealed as CommitConceal>::ConcealedCommitment>,
991994
{
992-
fn conceal_except(&mut self, seals: &Vec<seal::Confidential>) -> usize {
995+
fn conceal_state_except(
996+
&mut self,
997+
seals: &Vec<seal::Confidential>,
998+
) -> usize {
993999
match self {
9941000
OwnedState::Confidential { .. }
9951001
| OwnedState::ConfidentialAmount { .. } => 0,
@@ -2116,7 +2122,7 @@ mod test {
21162122
// CommitConceal all without any exception
21172123
// This will create 2 Confidential and 2 ConfidentialState type
21182124
// Assignments
2119-
assert_eq!(2, hash_type.conceal_all());
2125+
assert_eq!(2, hash_type.conceal_state());
21202126

21212127
// Precomputed values of revealed seals in 2 ConfidentialState type
21222128
// Assignments

src/contract/conceal.rs

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,73 +16,91 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
1616

1717
use super::seal;
1818

19-
pub trait AutoConceal {
20-
fn conceal_all(&mut self) -> usize {
21-
self.conceal_except(&vec![])
19+
pub trait ConcealState {
20+
fn conceal_state(&mut self) -> usize {
21+
self.conceal_state_except(&vec![])
2222
}
23-
fn conceal_except(&mut self, seals: &Vec<seal::Confidential>) -> usize;
23+
fn conceal_state_except(
24+
&mut self,
25+
seals: &Vec<seal::Confidential>,
26+
) -> usize;
2427
}
2528

26-
impl<T> AutoConceal for Vec<T>
29+
impl<T> ConcealState for Vec<T>
2730
where
28-
T: AutoConceal,
31+
T: ConcealState,
2932
{
30-
fn conceal_except(&mut self, seals: &Vec<seal::Confidential>) -> usize {
33+
fn conceal_state_except(
34+
&mut self,
35+
seals: &Vec<seal::Confidential>,
36+
) -> usize {
3137
self.iter_mut()
32-
.fold(0usize, |sum, item| sum + item.conceal_except(seals))
38+
.fold(0usize, |sum, item| sum + item.conceal_state_except(seals))
3339
}
3440
}
3541

36-
impl<T> AutoConceal for BTreeSet<T>
42+
impl<T> ConcealState for BTreeSet<T>
3743
where
38-
T: AutoConceal + Ord + Clone,
44+
T: ConcealState + Ord + Clone,
3945
{
40-
fn conceal_except(&mut self, seals: &Vec<seal::Confidential>) -> usize {
46+
fn conceal_state_except(
47+
&mut self,
48+
seals: &Vec<seal::Confidential>,
49+
) -> usize {
4150
let mut count = 0;
4251
let mut new_self = BTreeSet::<T>::new();
4352
for item in self.iter() {
4453
let mut new_item = item.clone();
45-
count += new_item.conceal_except(seals);
54+
count += new_item.conceal_state_except(seals);
4655
new_self.insert(new_item);
4756
}
4857
*self = new_self;
4958
count
5059
}
5160
}
5261

53-
impl<K, V> AutoConceal for BTreeMap<K, V>
62+
impl<K, V> ConcealState for BTreeMap<K, V>
5463
where
55-
V: AutoConceal,
64+
V: ConcealState,
5665
{
57-
fn conceal_except(&mut self, seals: &Vec<seal::Confidential>) -> usize {
66+
fn conceal_state_except(
67+
&mut self,
68+
seals: &Vec<seal::Confidential>,
69+
) -> usize {
5870
self.iter_mut()
59-
.fold(0usize, |sum, item| sum + item.1.conceal_except(seals))
71+
.fold(0usize, |sum, item| sum + item.1.conceal_state_except(seals))
6072
}
6173
}
6274

63-
impl<T> AutoConceal for HashSet<T>
75+
impl<T> ConcealState for HashSet<T>
6476
where
65-
T: AutoConceal + Ord + Clone + std::hash::Hash,
77+
T: ConcealState + Ord + Clone + std::hash::Hash,
6678
{
67-
fn conceal_except(&mut self, seals: &Vec<seal::Confidential>) -> usize {
79+
fn conceal_state_except(
80+
&mut self,
81+
seals: &Vec<seal::Confidential>,
82+
) -> usize {
6883
let mut count = 0;
6984
let mut new_self = HashSet::<T>::new();
7085
for item in self.iter() {
7186
let mut new_item = item.clone();
72-
count += new_item.conceal_except(seals);
87+
count += new_item.conceal_state_except(seals);
7388
new_self.insert(new_item);
7489
}
7590
*self = new_self;
7691
count
7792
}
7893
}
7994

80-
impl<K, V> AutoConceal for HashMap<K, V>
95+
impl<K, V> ConcealState for HashMap<K, V>
8196
where
82-
V: AutoConceal,
97+
V: ConcealState,
8398
{
84-
fn conceal_except(&mut self, seals: &Vec<seal::Confidential>) -> usize {
99+
fn conceal_state_except(
100+
&mut self,
101+
seals: &Vec<seal::Confidential>,
102+
) -> usize {
85103
self.iter_mut()
86-
.fold(0usize, |sum, item| sum + item.1.conceal_except(seals))
104+
.fold(0usize, |sum, item| sum + item.1.conceal_state_except(seals))
87105
}
88106
}

src/contract/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(self) use assignments::{
2929
OwnedRightsInner, ParentOwnedRightsInner, ParentPublicRightsInner,
3030
PublicRightsInner,
3131
};
32-
pub use conceal::AutoConceal;
32+
pub use conceal::ConcealState;
3333
pub use metadata::Metadata;
3434
pub use nodes::{ContractId, Extension, Genesis, Node, NodeId, Transition};
3535
pub use seal::{SealDefinition, SealEndpoint};

src/contract/nodes.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use lnpbp::commit_verify::CommitVerify;
2525
use lnpbp::{Chain, TaggedHash};
2626

2727
use super::{
28-
Assignments, AutoConceal, OwnedRights, ParentOwnedRights,
28+
Assignments, ConcealState, OwnedRights, ParentOwnedRights,
2929
ParentPublicRights, PublicRights,
3030
};
3131
use super::{
@@ -328,31 +328,40 @@ impl CommitEncode for Transition {
328328
}
329329
}
330330

331-
impl AutoConceal for Genesis {
332-
fn conceal_except(&mut self, seals: &Vec<seal::Confidential>) -> usize {
331+
impl ConcealState for Genesis {
332+
fn conceal_state_except(
333+
&mut self,
334+
seals: &Vec<seal::Confidential>,
335+
) -> usize {
333336
let mut count = 0;
334337
for (_, assignment) in self.owned_rights_mut() {
335-
count += assignment.conceal_except(seals);
338+
count += assignment.conceal_state_except(seals);
336339
}
337340
count
338341
}
339342
}
340343

341-
impl AutoConceal for Extension {
342-
fn conceal_except(&mut self, seals: &Vec<seal::Confidential>) -> usize {
344+
impl ConcealState for Extension {
345+
fn conceal_state_except(
346+
&mut self,
347+
seals: &Vec<seal::Confidential>,
348+
) -> usize {
343349
let mut count = 0;
344350
for (_, assignment) in self.owned_rights_mut() {
345-
count += assignment.conceal_except(seals);
351+
count += assignment.conceal_state_except(seals);
346352
}
347353
count
348354
}
349355
}
350356

351-
impl AutoConceal for Transition {
352-
fn conceal_except(&mut self, seals: &Vec<seal::Confidential>) -> usize {
357+
impl ConcealState for Transition {
358+
fn conceal_state_except(
359+
&mut self,
360+
seals: &Vec<seal::Confidential>,
361+
) -> usize {
353362
let mut count = 0;
354363
for (_, assignment) in self.owned_rights_mut() {
355-
count += assignment.conceal_except(seals);
364+
count += assignment.conceal_state_except(seals);
356365
}
357366
count
358367
}
@@ -765,12 +774,12 @@ mod test {
765774

766775
use super::*;
767776
use lnpbp::chain::{Chain, GENESIS_HASH_MAINNET};
777+
use lnpbp::client_side_validation::CommitConceal;
768778
use lnpbp::commit_verify::CommitVerify;
769779
use lnpbp::strict_encoding::{
770780
strict_serialize, StrictDecode, StrictEncode,
771781
};
772782
use lnpbp::tagged_hash;
773-
use lnpbp::client_side_validation::CommitConceal;
774783

775784
static TRANSITION: [u8; 2356] = include!("../../test/transition.in");
776785
static GENESIS: [u8; 2454] = include!("../../test/genesis.in");
@@ -887,17 +896,17 @@ mod test {
887896
for assignment in set {
888897
*assignment = assignment.commit_conceal();
889898
}
890-
},
899+
}
891900
Assignments::DiscreteFiniteField(set) => {
892901
for assignment in set {
893902
*assignment = assignment.commit_conceal();
894903
}
895-
},
904+
}
896905
Assignments::CustomData(set) => {
897906
for assignment in set {
898907
*assignment = assignment.commit_conceal();
899908
}
900-
},
909+
}
901910
}
902911
}
903912
}
@@ -1141,8 +1150,8 @@ mod test {
11411150
.unwrap()
11421151
);
11431152

1144-
genesis.conceal_all();
1145-
transition.conceal_all();
1153+
genesis.conceal_state();
1154+
transition.conceal_state();
11461155

11471156
assert_eq!(
11481157
genesis.clone().consensus_commit(),

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub mod prelude {
5959

6060
pub use super::bech32::{Bech32, FromBech32, ToBech32};
6161
pub use contract::{
62-
data, seal, value, Assignments, AtomicValue, AutoConceal,
62+
data, seal, value, Assignments, AtomicValue, ConcealState,
6363
ConfidentialState, ContractId, DeclarativeStrategy, Extension, Genesis,
6464
HashStrategy, Metadata, NoDataError, Node, NodeId, OwnedRights,
6565
OwnedState, ParentOwnedRights, ParentPublicRights, PedersenStrategy,

0 commit comments

Comments
 (0)