Skip to content
Snippets Groups Projects
Select Git revision
  • c4bdceaf4f9d2f044e09c4fa91e5120683b55715
  • master default protected
  • WIP-buggy-mywallets-riverpod
  • polkadart-stuff
  • provider-to-riverpod
  • implementLightnode
  • hugo_RML16
  • refactorOnboardingSlideshow
  • duniterV1Latest
  • scanNetwork
  • dubp_rs
  • v0.2.17+140
  • v0.2.16+139
  • v0.2.16+138
  • v0.2.15+137
  • v0.2.14+134
  • v0.2.13+133
  • v0.2.13+132
  • v0.2.12+131
  • v0.2.11+130
  • v0.2.10+129
  • v0.2.9+128
  • v0.2.8+127
  • v0.2.7+125
  • v0.2.6+124
  • v0.2.5+123
  • v0.2.4+122
  • v0.2.3+119
  • v0.2.2+118
  • v0.2.1+113
  • polkawallet-sdk-latest
31 results

transaction_status.dart

Blame
  • traits.rs 3.70 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::DbBlock;
    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<DbBlock>, DbError>;
        fn get_db_block_in_local_blockchain(
            &self,
            block_number: BlockNumber,
        ) -> Result<Option<DbBlock>, DbError>;
        #[cfg(feature = "client-indexer")]
        fn get_db_blocks_in_local_blockchain(
            &self,
            numbers: Vec<BlockNumber>,
        ) -> Result<Vec<DbBlock>, DbError>;
        fn get_uid_from_pubkey(&self, pubkey: &PubKey) -> Result<Option<String>, DbError>;
    }
    
    impl<T> BcDbInReadTx for T
    where
        T: BcDbWithReader + durs_common_tools::traits::NotMock,
    {
        fn get_current_blockstamp(&self) -> Result<Option<Blockstamp>, DbError> {
            crate::current_meta_datas::get_current_blockstamp(self)
        }
        fn get_current_block(&self) -> Result<Option<DbBlock>, 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)
            }
        }
        fn get_db_block_in_local_blockchain(
            &self,
            block_number: BlockNumber,
        ) -> Result<Option<DbBlock>, DbError> {
            crate::blocks::get_db_block_in_local_blockchain(self, block_number)
        }
        #[cfg(feature = "client-indexer")]
        fn get_db_blocks_in_local_blockchain(
            &self,
            numbers: Vec<BlockNumber>,
        ) -> Result<Vec<DbBlock>, DbError> {
            crate::blocks::get_blocks_in_local_blockchain_by_numbers(self, numbers)
        }
        fn get_uid_from_pubkey(&self, pubkey: &PubKey) -> Result<Option<String>, DbError> {
            crate::indexes::identities::get_uid_(self, pubkey)
        }
    }