Skip to content
Snippets Groups Projects
Select Git revision
  • f83cf9bc4a2b6706e372bf7112f00f5bfbea2ddf
  • 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
  • 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
  • runtime-401 protected
  • v0.4.0 protected
41 results

build-for-arm.md

Blame
  • entities.rs 4.07 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/>.
    
    pub mod block_gva;
    pub mod idty_gva;
    pub mod network;
    pub mod tx_gva;
    pub mod ud_gva;
    pub mod utxos_gva;
    pub mod wallet_gva;
    
    use crate::*;
    
    #[derive(Default, async_graphql::SimpleObject)]
    pub(crate) struct AggregateSum {
        pub(crate) aggregate: Sum,
    }
    
    #[derive(Clone, Copy, Debug, Default, async_graphql::SimpleObject)]
    pub(crate) struct AmountWithBase {
        pub(crate) amount: i32,
        pub(crate) base: i32,
    }
    impl AmountWithBase {
        fn increment_base(self) -> Self {
            Self {
                amount: self.amount / 10,
                base: self.base + 1,
            }
        }
    }
    impl std::ops::Add for AmountWithBase {
        type Output = Self;
    
        fn add(self, rhs: Self) -> Self::Output {
            #[allow(clippy::comparison_chain)]
            if self.base == rhs.base {
                Self {
                    amount: self.amount + rhs.amount,
                    base: self.base,
                }
            } else if self.base > rhs.base {
                self.add(rhs.increment_base())
            } else {
                self.increment_base().add(rhs)
            }
        }
    }
    impl From<SourceAmount> for AmountWithBase {
        fn from(sa: SourceAmount) -> Self {
            Self {
                amount: sa.amount() as i32,
                base: sa.base() as i32,
            }
        }
    }
    impl std::iter::Sum for AmountWithBase {
        fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
            iter.fold(AmountWithBase::default(), std::ops::Add::add)
        }
    }
    
    #[derive(async_graphql::SimpleObject)]
    pub(crate) struct EdgeTx {
        pub(crate) direction: TxDirection,
    }
    
    pub(crate) enum RawTxOrChanges {
        FinalTx(String),
        Changes(Vec<String>),
    }
    #[async_graphql::Object]
    impl RawTxOrChanges {
        /// Intermediate transactions documents for compacting sources (`null` if not needed)
        async fn changes(&self) -> Option<&Vec<String>> {
            if let Self::Changes(changes) = self {
                Some(changes)
            } else {
                None
            }
        }
        /// Transaction document that carries out the requested transfer (`null` if the amount to be sent requires too many sources)
        async fn tx(&self) -> Option<&str> {
            if let Self::FinalTx(raw_tx) = self {
                Some(raw_tx.as_str())
            } else {
                None
            }
        }
    }
    
    #[derive(Default, async_graphql::SimpleObject)]
    pub(crate) struct Sum {
        pub(crate) sum: AmountWithBase,
    }
    
    #[derive(Clone, Copy, Eq, PartialEq, async_graphql::Enum)]
    pub(crate) enum TxDirection {
        /// Received
        Received,
        /// Sent
        Sent,
    }
    
    #[derive(async_graphql::SimpleObject)]
    pub(crate) struct TxsHistoryMempool {
        /// Transactions sending
        pub(crate) sending: Vec<PendingTxGva>,
        /// Transactions receiving
        pub(crate) receiving: Vec<PendingTxGva>,
    }
    
    #[derive(Clone, async_graphql::SimpleObject)]
    pub(crate) struct UtxoGva {
        /// Source amount
        pub(crate) amount: i64,
        /// Source base
        pub(crate) base: i64,
        /// Hash of origin transaction
        pub(crate) tx_hash: String,
        /// Index of output in origin transaction
        pub(crate) output_index: u32,
    }
    
    #[derive(Clone, async_graphql::SimpleObject)]
    pub(crate) struct UtxoTimedGva {
        /// Source amount
        pub(crate) amount: i64,
        /// Source base
        pub(crate) base: i64,
        /// Hash of origin transaction
        pub(crate) tx_hash: String,
        /// Index of output in origin transaction
        pub(crate) output_index: u32,
        /// Written block
        pub(crate) written_block: u32,
        /// Written time
        pub(crate) written_time: u64,
    }