Skip to content
Snippets Groups Projects
Select Git revision
  • 5dd416576931cad7bf6cec31163a1d01f8aacdbc
  • master default protected
  • elois-ci-refactor protected
  • gtest
  • hugo/gtest
  • json-output
  • nostr
  • 48-error-base-58-requirement-is-violated
  • no-rename
  • hugo/tx-comments
  • poka/dev
  • hugo/dev
  • tuxmain/mail
  • test-gtest
  • 0.4.3-gtest-RC1
  • 0.4.3-RC2
  • 0.4.3-RC1
  • 0.4.2
  • 0.4.1
  • 0.4.0
  • 0.3.0
  • 0.2.17
  • 0.2.16
  • 0.2.15
  • 0.2.14
  • 0.2.13
  • 0.2.12
  • 0.2.10
  • 0.2.9
  • 0.2.8
  • 0.2.7
  • 0.2.6
  • 0.2.5
33 results

identity.rs

Blame
    • Nicolas80's avatar
      07ea8692
      * Adapted data::keypair() method so it doesn't block the user's terminal anymore · 07ea8692
      Nicolas80 authored
         * Now checking if GcliError Input message was for doing "ctrl+c" or "Esc" key in a prompt; in wich case we terminate the execution with the message.
         * Small correction in vault_account::compute_suri_account_tree_node where it's better to return GcliError instead of panic using unwrap if the password was incorrect.
      * Renamed `clap` arguments "value_name" in different places where it wasn't clear what kind of value was expected.
         * Using "ADDRESS" everytime we expect an AccountId
         * Using "USERNAME" everytime we expect a Username (most were requesting "TARGET")
      * Small corrections in `clap` help messages for `vault derive`
      * Added print of selected Vault item when using vault::try_fetch_key_pair method; just before requesting it's associated password (whenever we will try to sign for an action mostly)
      07ea8692
      History
      * Adapted data::keypair() method so it doesn't block the user's terminal anymore
      Nicolas80 authored
         * Now checking if GcliError Input message was for doing "ctrl+c" or "Esc" key in a prompt; in wich case we terminate the execution with the message.
         * Small correction in vault_account::compute_suri_account_tree_node where it's better to return GcliError instead of panic using unwrap if the password was incorrect.
      * Renamed `clap` arguments "value_name" in different places where it wasn't clear what kind of value was expected.
         * Using "ADDRESS" everytime we expect an AccountId
         * Using "USERNAME" everytime we expect a Username (most were requesting "TARGET")
      * Small corrections in `clap` help messages for `vault derive`
      * Added print of selected Vault item when using vault::try_fetch_key_pair method; just before requesting it's associated password (whenever we will try to sign for an action mostly)
    traits.rs 4.43 KiB
    //  Copyright (C) 2017-2019  The AXIOM TEAM Association.
    //
    // This program is free software: you can redistribute it and/or modify
    // it under the terms of the GNU Affero General Public License as
    // published by the Free Software Foundation, either version 3 of the
    // License, or (at your option) any later version.
    //
    // This program is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU Affero General Public License for more details.
    //
    // You should have received a copy of the GNU Affero General Public License
    // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    
    //! BlockChain Datas Access Layer in Read-Only mode.
    // ! Define read only trait
    
    use crate::blocks::BlockDb;
    use crate::indexes::identities::{IdentityDb, IdentityStateDb};
    use crate::{BcDbWithReaderStruct, DbReadable, DbReader};
    use dubp_common_doc::{BlockNumber, Blockstamp};
    use dup_crypto::keys::PubKey;
    use durs_dbs_tools::DbError;
    #[cfg(feature = "mock")]
    use mockall::*;
    
    pub trait BcDbRead<DB>
    where
        DB: DbReadable,
    {
        /// Read datas in Db
        fn r<D, F>(&self, f: F) -> Result<D, DbError>
        where
            DB: DbReadable,
            F: FnOnce(&BcDbWithReaderStruct<DB>) -> Result<D, DbError>;
    }
    
    impl<DB> BcDbRead<DB> for DB
    where
        DB: DbReadable,
    {
        fn r<D, F>(&self, f: F) -> Result<D, DbError>
        where
            DB: DbReadable,
            F: FnOnce(&BcDbWithReaderStruct<DB>) -> Result<D, DbError>,
        {
            self.read(|r| f(&BcDbWithReaderStruct { db: self, r }))
        }
    }
    
    pub trait BcDbWithReader {
        type DB: DbReadable;
        type R: DbReader;
    
        fn db(&self) -> &Self::DB;
        fn r(&self) -> &Self::R;
    }
    
    #[cfg(feature = "mock")]
    impl<'a> BcDbWithReader for MockBcDbInReadTx {
        type DB = crate::BcDbRo;
        type R = durs_dbs_tools::kv_db::MockKvFileDbReader;
    
        fn db(&self) -> &Self::DB {
            unreachable!()
        }
        fn r(&self) -> &Self::R {
            unreachable!()
        }
    }
    
    #[cfg_attr(feature = "mock", automock)]
    pub trait BcDbInReadTx: BcDbWithReader {
        fn get_current_blockstamp(&self) -> Result<Option<Blockstamp>, DbError>;
        fn get_current_block(&self) -> Result<Option<BlockDb>, DbError>;
        fn get_db_block_in_local_blockchain(
            &self,
            block_number: BlockNumber,
        ) -> Result<Option<BlockDb>, DbError>;
        #[cfg(feature = "client-indexer")]
        fn get_db_blocks_in_local_blockchain(
            &self,
            numbers: Vec<BlockNumber>,
        ) -> Result<Vec<BlockDb>, DbError>;
        fn get_uid_from_pubkey(&self, pubkey: &PubKey) -> Result<Option<String>, DbError>;
        fn get_idty_state_by_pubkey(&self, pubkey: &PubKey)
            -> Result<Option<IdentityStateDb>, DbError>;
        fn get_identity_by_pubkey(&self, pubkey: &PubKey) -> Result<Option<IdentityDb>, DbError>;
    }
    
    impl<T> BcDbInReadTx for T
    where
        T: BcDbWithReader + durs_common_tools::traits::NotMock,
    {
        #[inline]
        fn get_current_blockstamp(&self) -> Result<Option<Blockstamp>, DbError> {
            crate::current_meta_datas::get_current_blockstamp(self)
        }
        #[inline]
        fn get_current_block(&self) -> Result<Option<BlockDb>, DbError> {
            if let Some(current_blockstamp) = crate::current_meta_datas::get_current_blockstamp(self)? {
                crate::blocks::get_db_block_in_local_blockchain(self, current_blockstamp.id)
            } else {
                Ok(None)
            }
        }
        #[inline]
        fn get_db_block_in_local_blockchain(
            &self,
            block_number: BlockNumber,
        ) -> Result<Option<BlockDb>, DbError> {
            crate::blocks::get_db_block_in_local_blockchain(self, block_number)
        }
        #[cfg(feature = "client-indexer")]
        #[inline]
        fn get_db_blocks_in_local_blockchain(
            &self,
            numbers: Vec<BlockNumber>,
        ) -> Result<Vec<BlockDb>, DbError> {
            crate::blocks::get_blocks_in_local_blockchain_by_numbers(self, numbers)
        }
        #[inline]
        fn get_uid_from_pubkey(&self, pubkey: &PubKey) -> Result<Option<String>, DbError> {
            crate::indexes::identities::get_uid(self, pubkey)
        }
        #[inline]
        fn get_idty_state_by_pubkey(
            &self,
            pubkey: &PubKey,
        ) -> Result<Option<IdentityStateDb>, DbError> {
            crate::indexes::identities::get_idty_state_by_pubkey(self, pubkey)
        }
        #[inline]
        fn get_identity_by_pubkey(&self, pubkey: &PubKey) -> Result<Option<IdentityDb>, DbError> {
            crate::indexes::identities::get_identity_by_pubkey(self, pubkey)
        }
    }