-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdigibyte_subsidy.cpp
99 lines (81 loc) · 2.74 KB
/
digibyte_subsidy.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <Python.h>
static const long long COIN = 100000000;
static const long long nDiffChangeTarget = 67200; // Patch effective @ block 67200
static const long long patchBlockRewardDuration = 10080; // 10080 blocks main net change
static const long long patchBlockRewardDuration2 = 80160; // 80160 blocks main net change
static const long long patchBlockRewardDuration3 = 400000; // block 400000 after which all difficulties are updated on every block
double ConvertBitsToDouble(unsigned int nBits)
{
int nShift = (nBits >> 24) & 0xff;
double dDiff =
(double)0x0000ffff / (double)(nBits & 0x00ffffff);
while (nShift < 29)
{
dDiff *= 256.0;
nShift++;
}
while (nShift > 29)
{
dDiff /= 256.0;
nShift--;
}
return dDiff;
}
long long GetDGBSubsidy(int nHeight) {
long long qSubsidy;
if (nHeight < patchBlockRewardDuration3)
{
long long qSubsidy = 8000*COIN;
int blocks = nHeight - nDiffChangeTarget;
int weeks = (blocks / patchBlockRewardDuration)+1;
//decrease reward by 0.5% every 10080 blocks
for(int i = 0; i < weeks; i++) qSubsidy -= (qSubsidy/200);
}
else
{
long long qSubsidy = 2459*COIN;
int blocks = nHeight - patchBlockRewardDuration3;
int weeks = (blocks / patchBlockRewardDuration2)+1;
//decrease reward by 1% every month
for(int i = 0; i < weeks; i++) qSubsidy -= (qSubsidy/100);
}
return qSubsidy;
}
long long static GetBlockBaseValue(int nHeight) {
long long nSubsidy = COIN;
if(nHeight < nDiffChangeTarget) {
//this is pre-patch, reward is 8000.
nSubsidy = 8000 * COIN;
if(nHeight < 1440) //1440
{
nSubsidy = 72000 * COIN;
}
else if(nHeight < 5760) //5760
{
nSubsidy = 16000 * COIN;
}
} else {
//patch takes effect after 67,200 blocks solved
nSubsidy = GetDGBSubsidy(nHeight);
}
//make sure the reward is at least 1 DGB
if(nSubsidy < COIN) {
nSubsidy = COIN;
}
return nSubsidy;
}
static PyObject *digibyte_subsidy_getblockbasevalue(PyObject *self, PyObject *args)
{
int input_height;
if (!PyArg_ParseTuple(args, "i", &input_height))
return NULL;
long long output = GetBlockBaseValue(input_height);
return Py_BuildValue("L", output);
}
static PyMethodDef digibyte_subsidy_methods[] = {
{ "GetBlockBaseValue", digibyte_subsidy_getblockbasevalue, METH_VARARGS, "Returns the block value" },
{ NULL, NULL, 0, NULL }
};
PyMODINIT_FUNC initdigibyte_subsidy(void) {
(void) Py_InitModule("digibyte_subsidy", digibyte_subsidy_methods);
}