1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
//                              Næ§@@@ÑÉ©
//                        æ@@@@@@@@@@@@@@@@@@
//                    Ñ@@@@?.?@@@@@@@@@@@@@@@@@@@N
//                 ¶@@@@@?^%@@.=@@@@@@@@@@@@@@@@@@@@
//               N@@@@@@@?^@@@»^@@@@@@@@@@@@@@@@@@@@@@
//               @@@@@@@@?^@@@».............?@@@@@@@@@É
//              Ñ@@@@@@@@?^@@@@@@@@@@@@@@@@@@'?@@@@@@@@Ñ
//              @@@@@@@@@?^@@@»..............»@@@@@@@@@@
//              @@@@@@@@@?^@@@»^@@@@@@@@@@@@@@@@@@@@@@@@
//              @@@@@@@@@?^ë@@&.@@@@@@@@@@@@@@@@@@@@@@@@
//               @@@@@@@@?^´@@@o.%@@@@@@@@@@@@@@@@@@@@©
//                @@@@@@@?.´@@@@@ë.........*.±@@@@@@@æ
//                 @@@@@@@@?´.I@@@@@@@@@@@@@@.&@@@@@N
//                  N@@@@@@@@@@ë.*=????????=?@@@@@Ñ
//                    @@@@@@@@@@@@@@@@@@@@@@@@@@@¶
//                        É@@@@@@@@@@@@@@@@Ѷ
//                             Næ§@@@ÑÉ©

// Copyright 2020 Chris D'Costa
// This file is part of Totem Live Accounting.
// Authors:
// - Félix Daudré-Vignier   email: felix@totemaccounting.com
// - Chris D'Costa          email: chris.dcosta@totemaccounting.com

// Totem is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Totem 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 General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Totem.  If not, see <http://www.gnu.org/licenses/>.

#![cfg_attr(not(feature = "std"), no_std)]

pub mod accounting;
pub mod archive;
pub mod bonsai;
pub mod escrow;
pub mod funding;
pub mod orders;
pub mod prefunding;
pub mod teams;
pub mod timekeeping;
pub mod transfer;

use frame_support::{dispatch::EncodeLike, pallet_prelude::*};
use scale_info::TypeInfo;
use sp_std::vec::Vec;

/// Balance on an account can be negative.
pub type LedgerBalance = i128;

/// General ledger account number.
pub type Account = u64;

/// The index number for identifying the posting to ledgers.
pub type PostingIndex = u128;

/// Used for comparisons.
pub type ComparisonAmounts = u128;

#[derive(Decode, Encode, Debug, Clone, Copy, PartialEq, TypeInfo)]
pub enum RecordType {
    Teams,
    Timekeeping,
    Orders,
}

/// A collection based on `Vec` that guarantees that every member is unique.
#[derive(Decode, Encode, TypeInfo)]
pub struct Set<T>(Vec<T>);

// Implementations

impl EncodeLike<RecordType> for u8 {}

impl<T> Default for Set<T> {
    fn default() -> Self {
        Set(Default::default())
    }
}

impl<T> Set<T>
where
    T: Eq,
{
    pub fn new() -> Self {
        Default::default()
    }

    pub fn insert(&mut self, elem: T) {
        self.remove(&elem);
        self.0.push(elem)
    }

    pub fn remove(&mut self, elem: &T) {
        self.0.retain(|x| x != elem)
    }
}