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
// Copyright (c) 2023, MaidSafe.
// All rights reserved.
//
// This SAFE Network Software is licensed under the BSD-3-Clause license.
// Please see the LICENSE file for more details.
use crate::{Hash, Token};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct FeeOutput {
/// The id is expected (in order to be accepted by the network) to be built from: hash(root_hash + inputs' ids).
/// This requirement makes it possible for this output to be used as an input in a rewards/farming
/// claiming Tx, by making its spend location deterministic, analogous to how any other output
/// is spent using its id to determine the location to store the signed spend.
pub id: Hash,
/// Amount being paid as storage fee to the network.
pub token: Token,
/// The root hash of the proof's Merkletree corresponding to the content being paid for.
pub root_hash: Hash,
}
impl Default for FeeOutput {
fn default() -> Self {
Self {
id: Hash::default(),
token: Token::zero(),
root_hash: Hash::default(),
}
}
}
impl FeeOutput {
pub fn new(id: Hash, amount: u64, root_hash: Hash) -> Self {
Self {
id,
token: Token::from_nano(amount),
root_hash,
}
}
pub fn is_free(&self) -> bool {
self.token.is_zero()
}
pub fn to_bytes(&self) -> Vec<u8> {
let mut v = Vec::<u8>::new();
v.extend(self.id.slice());
v.extend(self.token.to_bytes());
v.extend(self.root_hash.slice());
v
}
}