/ src / sdk / src / blockchain.rs
blockchain.rs
 1  /* This file is part of DarkFi (https://dark.fi)
 2   *
 3   * Copyright (C) 2020-2025 Dyne.org foundation
 4   *
 5   * This program is free software: you can redistribute it and/or modify
 6   * it under the terms of the GNU Affero General Public License as
 7   * published by the Free Software Foundation, either version 3 of the
 8   * License, or (at your option) any later version.
 9   *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU Affero General Public License for more details.
14   *
15   * You should have received a copy of the GNU Affero General Public License
16   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17   */
18  
19  /// Auxiliary function to calculate provided block height block version.
20  /// Currently, a single version(1) exists.
21  pub fn block_version(_height: u32) -> u8 {
22      1
23  }
24  
25  /// Auxiliary function to calculate provided block height epoch.
26  /// Each epoch is defined by the fixed intervals rewards change.
27  /// Genesis block is on epoch 0.
28  pub fn block_epoch(height: u32) -> u8 {
29      match height {
30          0 => 0,
31          1..=1000 => 1,
32          1001..=2000 => 2,
33          2001..=3000 => 3,
34          3001..=4000 => 4,
35          4001..=5000 => 5,
36          5001..=6000 => 6,
37          6001..=7000 => 7,
38          7001..=8000 => 8,
39          8001..=9000 => 9,
40          9001..=10000 => 10,
41          10001.. => 11,
42      }
43  }
44  
45  /// Auxiliary function to calculate provided block height expected reward value.
46  ///
47  /// Genesis block always returns reward value 0. Rewards are halfed at fixed intervals,
48  /// called epochs. After last epoch has started, reward value is based on DARK token-economics.
49  pub fn expected_reward(height: u32) -> u64 {
50      // Grab block height epoch
51      let epoch = block_epoch(height);
52  
53      // TODO (res) implement reward mechanism with accord to DRK, DARK token-economics.
54      // Configured block rewards (1 DRK == 1 * 10^8)
55      match epoch {
56          0 => 0,
57          1 => 2_000_000_000, // 20 DRK
58          2 => 1_800_000_000, // 18 DRK
59          3 => 1_600_000_000, // 16 DRK
60          4 => 1_400_000_000, // 14 DRK
61          5 => 1_200_000_000, // 12 DRK
62          6 => 1_000_000_000, // 10 DRK
63          7 => 800_000_000,   // 8 DRK
64          8 => 600_000_000,   // 6 DRK
65          9 => 400_000_000,   // 4 DRK
66          10 => 200_000_000,  // 2 DRK
67          _ => 100_000_000,   // 1 DRK
68      }
69  }