Skip to content
Snippets Groups Projects
Select Git revision
  • 7e56b688bc75301f0ddfa8da0eea92a3bf60ddc3
  • dev default protected
  • release/1.9.1 protected
  • pini-1.8-docker
  • pini-sync-onlypeers
  • duniter-v2s-issue-123-industrialize-releases
  • feature/build-aarch64-nodejs16
  • release/1.8 protected
  • pini-docker
  • ci_tags
  • fix/1448/1.8/txs_not_stored
  • feature/node-20
  • fix/1441/node_summary_with_storage
  • fix/1442/improve_bma_tx_history
  • feature/wotwizard-1.8
  • release/1.9 protected
  • 1.7 protected
  • feature/docker-set-latest protected
  • feature/fast-docker-build-1.8.4
  • fast-docker-build protected
  • feature/dump-distance
  • v1.8.7 protected
  • v1.8.7-rc4 protected
  • v1.8.7-rc3 protected
  • v1.8.7-rc2 protected
  • v1.8.7-rc1 protected
  • v1.8.6 protected
  • v1.7.23 protected
  • v1.8.5 protected
  • v1.8.4 protected
  • v1.8.3 protected
  • v1.8.2 protected
  • v1.8.1 protected
  • v1.8.0 protected
  • v1.8.0-rc1 protected
  • v1.8.0-beta5 protected
  • v1.8.0-beta4 protected
  • v1.8.0-beta3 protected
  • v1.8.0-beta2 protected
  • v1.8.0-beta protected
  • v1.7.21 protected
41 results

server.js

Blame
  • mock.rs 3.73 KiB
    // Copyright 2023 Axiom-Team
    //
    // This file is part of Duniter-v2S.
    //
    // Duniter-v2S 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, version 3 of the License.
    //
    // Duniter-v2S 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 Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
    
    use crate::runtime::runtime_types::{
        pallet_distance::median::MedianAcc, sp_arithmetic::per_things::Perbill,
    };
    
    use dubp_wot::{data::rusty::RustyWebOfTrust, WebOfTrust, WotId};
    use std::collections::BTreeSet;
    
    pub struct Client {
        wot: RustyWebOfTrust,
        pub pool_len: usize,
    }
    pub type AccountId = sp_runtime::AccountId32;
    pub type IdtyIndex = u32;
    pub type H256 = subxt::utils::H256;
    
    pub struct EvaluationPool {
        pub evaluations: (Vec<(IdtyIndex, MedianAcc<Perbill>)>,),
        pub evaluators: BTreeSet<AccountId>,
    }
    
    pub async fn client(_rpc_url: impl AsRef<str>) -> Client {
        unimplemented!()
    }
    
    pub fn client_from_wot(wot: RustyWebOfTrust) -> Client {
        Client { wot, pool_len: 1 }
    }
    
    pub async fn parent_hash(_client: &Client) -> H256 {
        Default::default()
    }
    
    pub async fn current_period_index(_client: &Client, _parent_hash: H256) -> u32 {
        0
    }
    
    pub async fn current_pool(
        client: &Client,
        _parent_hash: H256,
        _current_session: u32,
    ) -> Option<EvaluationPool> {
        Some(EvaluationPool {
            evaluations: (client
                .wot
                .get_enabled()
                .into_iter()
                .chain(client.wot.get_disabled().into_iter())
                .zip(0..client.pool_len)
                .map(|(wot_id, _)| {
                    (wot_id.0 as IdtyIndex, unsafe {
                        std::mem::transmute::<
                            (std::vec::Vec<()>, std::option::Option<u32>, i32),
                            MedianAcc<Perbill>,
                        >((Vec::<()>::new(), Option::<u32>::None, 0))
                    })
                })
                .collect(),),
            evaluators: BTreeSet::new(),
        })
    }
    
    pub async fn evaluation_block(_client: &Client, _parent_hash: H256) -> H256 {
        Default::default()
    }
    
    pub async fn max_referee_distance(_client: &Client) -> u32 {
        5
    }
    
    pub async fn member_iter(client: &Client, _evaluation_block: H256) -> MemberIter {
        MemberIter(client.wot.get_enabled().into_iter())
    }
    
    pub struct MemberIter(std::vec::IntoIter<WotId>);
    
    impl MemberIter {
        pub async fn next(&mut self) -> Result<Option<IdtyIndex>, subxt::error::Error> {
            Ok(self.0.next().map(|wot_id| wot_id.0 as u32))
        }
    }
    
    pub async fn cert_iter(client: &Client, _evaluation_block: H256) -> CertIter {
        CertIter(
            client
                .wot
                .get_enabled()
                .iter()
                .chain(client.wot.get_disabled().iter())
                .map(|wot_id| {
                    (
                        wot_id.0 as IdtyIndex,
                        client
                            .wot
                            .get_links_source(*wot_id)
                            .unwrap_or_default()
                            .into_iter()
                            .map(|wot_id| (wot_id.0 as IdtyIndex, 0))
                            .collect::<Vec<(IdtyIndex, u32)>>(),
                    )
                })
                .collect::<Vec<_>>()
                .into_iter(),
        )
    }
    
    pub struct CertIter(std::vec::IntoIter<(IdtyIndex, Vec<(IdtyIndex, u32)>)>);
    
    impl CertIter {
        pub async fn next(&mut self) -> Result<Option<(u32, Vec<(u32, u32)>)>, subxt::error::Error> {
            Ok(self.0.next())
        }
    }