Skip to content
Snippets Groups Projects
Select Git revision
  • 06e775d6057b657d0806a0a2c066861484b2f940
  • master default protected
  • network/gtest-1000 protected
  • upgradable-multisig
  • runtime/gtest-1000
  • network/gdev-800 protected
  • cgeek/issue-297-cpu
  • gdev-800-tests
  • update-docker-compose-rpc-squid-names
  • fix-252
  • 1000i100-test
  • hugo/tmp-0.9.1
  • network/gdev-803 protected
  • hugo/endpoint-gossip
  • network/gdev-802 protected
  • hugo/distance-precompute
  • network/gdev-900 protected
  • tuxmain/anonymous-tx
  • debug/podman
  • hugo/195-doc
  • hugo/195-graphql-schema
  • gtest-1000-0.11.0 protected
  • gtest-1000 protected
  • gdev-900-0.10.1 protected
  • gdev-900-0.10.0 protected
  • gdev-900-0.9.2 protected
  • gdev-800-0.8.0 protected
  • gdev-900-0.9.1 protected
  • gdev-900-0.9.0 protected
  • gdev-803 protected
  • gdev-802 protected
  • runtime-801 protected
  • gdev-800 protected
  • runtime-800-bis protected
  • runtime-800 protected
  • runtime-800-backup protected
  • runtime-701 protected
  • runtime-700 protected
  • runtime-600 protected
  • runtime-500 protected
  • v0.4.1 protected
41 results

rust-toolchain

Blame
  • gva_block_db.rs 1.84 KiB
    //  Copyright (C) 2020 Éloïs SANCHEZ.
    //
    // 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/>.
    
    use crate::*;
    use dubp::block::{DubpBlock, DubpBlockV10};
    
    #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
    #[repr(transparent)]
    pub struct GvaBlockDbV1(pub DubpBlock);
    
    impl Default for GvaBlockDbV1 {
        fn default() -> Self {
            Self(DubpBlock::V10(DubpBlockV10::default()))
        }
    }
    
    impl AsBytes for GvaBlockDbV1 {
        fn as_bytes<T, F: FnMut(&[u8]) -> T>(&self, mut f: F) -> T {
            f(&bincode::serialize(&self).unwrap_or_else(|_| unreachable!()))
        }
    }
    
    impl kv_typed::prelude::FromBytes for GvaBlockDbV1 {
        type Err = bincode::Error;
    
        fn from_bytes(bytes: &[u8]) -> std::result::Result<Self, Self::Err> {
            bincode::deserialize(bytes)
        }
    }
    
    impl ToDumpString for GvaBlockDbV1 {
        fn to_dump_string(&self) -> String {
            todo!()
        }
    }
    
    #[cfg(feature = "explorer")]
    impl ExplorableValue for GvaBlockDbV1 {
        fn from_explorer_str(source: &str) -> Result<Self, FromExplorerValueErr> {
            serde_json::from_str(source).map_err(|e| FromExplorerValueErr(e.into()))
        }
        fn to_explorer_json(&self) -> KvResult<serde_json::Value> {
            serde_json::to_value(&self).map_err(|e| KvError::DeserError(e.into()))
        }
    }