forked from GravityProtocol/singularity
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemission.cpp
82 lines (70 loc) · 2.37 KB
/
emission.cpp
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
#include "include/emission.hpp"
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <fstream>
using namespace singularity;
double_type emission_calculator::get_emission_limit(
double_type current_total_supply
) const
{
double_type emission_event_count_per_year = double_type(31536000) / parameters_.emission_period_seconds;
return current_total_supply * (boost::multiprecision::pow((1 + parameters_.yearly_emission_percent / 100), 1.0 / emission_event_count_per_year) - 1);
}
double_type emission_calculator::get_target_emission(
double_type current_activity,
double_type max_activity
) const
{
if (current_activity > max_activity) {
return parameters_.activity_monetary_value * (current_activity - max_activity);
} else {
return 0;
}
}
double_type emission_calculator::get_resulting_emission(
double_type target_emission,
double_type emission_limit
) const
{
if (target_emission > 0) {
return emission_limit * tanh(parameters_.delay_koefficient * target_emission / emission_limit);
} else {
return 0;
}
}
double_type emission_calculator::get_next_max_activity(
double_type max_activity,
double_type resulting_emission
) const
{
return max_activity + resulting_emission / parameters_.activity_monetary_value;
}
unsigned int activity_period_new::activity_period_new::get_handled_block_count() const
{
return handled_blocks_count;
}
void activity_period_new::add_block(
const std::vector<std::shared_ptr<relation_t> >& relations
)
{
handled_blocks_count++;
for(auto relation: relations) {
auto transaction = std::dynamic_pointer_cast<transaction_t>(relation);
if(transaction) {
uint64_t period_index = transaction->get_height() / period_length;
if (period_index < period_count) {
(*p_account_keepers)[period_index].get_account_id(transaction->get_source(), true);
(*p_account_keepers)[period_index].get_account_id(transaction->get_target(), true);
}
}
}
}
double_type activity_period_new::get_activity() const
{
double_type result;
for(uint32_t period_index=0; period_index < period_count; period_index++) {
result += (*p_account_keepers)[period_index].get_account_count();
}
result /= period_count;
return result;
}