From 4ce40a98dbc3cb3241e6d91817a8753a9be95ee8 Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Sat, 15 May 2021 18:08:15 +0200 Subject: [PATCH] feat(dbs):bc_v2: add fields created_on & signature for IdtyDbV2 --- dbs-write-ops/src/bc.rs | 1 + dbs-write-ops/src/bc/identities.rs | 26 ++++++++++---------------- dbs/src/values/block_meta.rs | 2 +- dbs/src/values/idty_db.rs | 2 ++ 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/dbs-write-ops/src/bc.rs b/dbs-write-ops/src/bc.rs index 17b2c1b..2c4892f 100644 --- a/dbs-write-ops/src/bc.rs +++ b/dbs-write-ops/src/bc.rs @@ -177,6 +177,7 @@ mod tests { version: 10, median_time: 5_243, dividend: Some(1000), + identities: vec!["D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx:Ydnclvw76/JHcKSmU9kl9Ie0ne5/X8NYOqPqbGnufIK3eEPRYYdEYaQh+zffuFhbtIRjv6m/DkVLH5cLy/IyAg==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:elois".to_owned()], joiners: vec!["D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx:FFeyrvYio9uYwY5aMcDGswZPNjGLrl8THn9l3EPKSNySD3SDSHjCljSfFEwb87sroyzJQoVzPwER0sW/cbZMDg==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:elois".to_owned()], inner_hash: Some("0000000A65A12DB95B3153BCD05DB4D5C30CC7F0B1292D9FFBC3DE67F72F6040".to_owned()), signature: "7B0hvcfajE2G8nBLp0vLVaQcQdQIyli21Gu8F2l+nimKHRe+fUNi+MWd1e/u29BYZa+RZ1yxhbHIbFzytg7fAA==".to_owned(), diff --git a/dbs-write-ops/src/bc/identities.rs b/dbs-write-ops/src/bc/identities.rs index 0249308..4eea2fb 100644 --- a/dbs-write-ops/src/bc/identities.rs +++ b/dbs-write-ops/src/bc/identities.rs @@ -27,21 +27,19 @@ pub(crate) fn update_identities<B: Backend>( identities.upsert( PubKeyKeyV2(pubkey), IdtyDbV2 { + created_on: idty.blockstamp(), is_member: true, username, + signature: idty.signatures()[0], }, ) } for mb in block.joiners() { let pubkey = mb.issuers()[0]; - let username = mb.identity_username().to_owned(); - identities.upsert( - PubKeyKeyV2(pubkey), - IdtyDbV2 { - is_member: true, - username, - }, - ) + if let Some(mut idty) = identities.get(&PubKeyKeyV2(pubkey))? { + idty.is_member = true; + identities.upsert(PubKeyKeyV2(pubkey), idty) + } } for revo in block.revoked() { let pubkey = revo.issuer; @@ -65,14 +63,10 @@ pub(crate) fn revert_identities<B: Backend>( ) -> KvResult<()> { for mb in block.joiners() { let pubkey = mb.issuers()[0]; - let username = mb.identity_username().to_owned(); - identities.upsert( - PubKeyKeyV2(pubkey), - IdtyDbV2 { - is_member: false, - username, - }, - ) + if let Some(mut idty) = identities.get(&PubKeyKeyV2(pubkey))? { + idty.is_member = false; + identities.upsert(PubKeyKeyV2(pubkey), idty) + } } for idty in block.identities() { let pubkey = idty.issuers()[0]; diff --git a/dbs/src/values/block_meta.rs b/dbs/src/values/block_meta.rs index 92eaee0..9c42e26 100644 --- a/dbs/src/values/block_meta.rs +++ b/dbs/src/values/block_meta.rs @@ -39,7 +39,7 @@ pub struct BlockMetaV2 { pub nonce: u64, // 8 pub monetary_mass: u64, // 8 pub unit_base: u32, // 4 - pub dividend: Option<SourceAmount>, // 17 -> TOTAL SIZE == 335 bytes + pub dividend: Option<SourceAmount>, // 17 -> TOTAL SIZE == 323 bytes } impl BlockMetaV2 { pub fn blockstamp(&self) -> Blockstamp { diff --git a/dbs/src/values/idty_db.rs b/dbs/src/values/idty_db.rs index 688e1f9..2a63384 100644 --- a/dbs/src/values/idty_db.rs +++ b/dbs/src/values/idty_db.rs @@ -17,8 +17,10 @@ use crate::*; #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct IdtyDbV2 { + pub created_on: Blockstamp, pub is_member: bool, pub username: String, + pub signature: Signature, } impl AsBytes for IdtyDbV2 { -- GitLab