@@ -15,57 +15,15 @@ final class Emission(settings: MonetarySettings, reemission: ReemissionSettings)
15
15
getReemission(defaultReward)
16
16
}.sum / constants.Eip27ResidualEmission
17
17
18
- def issuedCoinsAfterHeight (h : Long ): Long =
19
- if (h < settings.fixedRatePeriod) {
20
- settings.fixedRate * h
21
- } else if (! reemission.applyReemissionRules || h < reemission.activationHeight) {
22
- val fixedRateEmission : Long = settings.fixedRate * (settings.fixedRatePeriod - 1 )
23
- val currentEpoch = epoch(h)
24
- val completeNonFixedRateEpochsEmission : Long = (1 to currentEpoch.toInt).map { e =>
25
- math.max(settings.fixedRate - settings.oneEpochReduction * e, 0 ) * settings.epochLength
26
- }.sum
27
- val heightInThisEpoch = (h - settings.fixedRatePeriod) % settings.epochLength + 1
28
- val rateThisEpoch = math.max(settings.fixedRate - settings.oneEpochReduction * (currentEpoch + 1 ), 0 )
29
- val incompleteEpochEmission = heightInThisEpoch * rateThisEpoch
30
-
31
- completeNonFixedRateEpochsEmission + fixedRateEmission + incompleteEpochEmission
32
- } else {
33
- val emissionBeforeEip27 = issuedCoinsAfterHeight(reemission.activationHeight - 1 )
34
- val firstEpochAfterActivation =
35
- (reemission.activationHeight - settings.fixedRatePeriod) / settings.epochLength + 1
36
- val firstReductionAfterActivation = firstEpochAfterActivation * settings.epochLength
37
- val currentEpoch = epoch(h)
38
- val defaultRewardPerBlockInCurrentEpoch =
39
- math.max(settings.fixedRate - settings.oneEpochReduction * currentEpoch, 0 )
40
- val adjustedReward = defaultRewardPerBlockInCurrentEpoch - getReemission(
41
- defaultRewardPerBlockInCurrentEpoch
42
- )
43
- if (h < firstReductionAfterActivation) {
44
- val blocksSinceActivation = h - reemission.activationHeight
45
- val accumulatedEmissionSinceActivation = blocksSinceActivation * adjustedReward
46
- emissionBeforeEip27 + accumulatedEmissionSinceActivation
47
- } else {
48
- val accumulatedEmissionSinceActivationBeforeFirstReduction =
49
- (firstReductionAfterActivation - reemission.activationHeight) * adjustedReward
50
- if (h < reemission.reemissionStartHeight) {
51
- val accumulatedEmissionSinceFirstReduction =
52
- (firstEpochAfterActivation to currentEpoch.toInt).map(e => getEpochEmissionAfterEip27(e)).sum
53
- val heightInThisEpoch = (h - settings.fixedRatePeriod) % settings.epochLength + 1
54
- val rateThisEpoch = math.max(settings.fixedRate - settings.oneEpochReduction * (currentEpoch + 1 ), 0 )
55
- val rateThisEpochWithReemission = rateThisEpoch - getReemission(rateThisEpoch)
56
- val incompleteEpochEmission = heightInThisEpoch * rateThisEpochWithReemission
57
- emissionBeforeEip27 + accumulatedEmissionSinceActivationBeforeFirstReduction + accumulatedEmissionSinceFirstReduction + incompleteEpochEmission
58
- } else {
59
- val lastEmissionEpoch =
60
- (reemission.reemissionStartHeight - settings.fixedRatePeriod) / settings.epochLength + 1
61
- val accumulatedEmissionSinceFirstReductionUntilReemission =
62
- (firstEpochAfterActivation to lastEmissionEpoch).map(e => getEpochEmissionAfterEip27(e)).sum
63
- val reemissionTail =
64
- math.min(h - reemission.reemissionStartHeight, reemissionLen) * constants.Eip27ResidualEmission
65
- emissionBeforeEip27 + accumulatedEmissionSinceActivationBeforeFirstReduction + accumulatedEmissionSinceFirstReductionUntilReemission + reemissionTail
66
- }
67
- }
18
+ def issuedCoinsAfterHeight (h : Long ): Long = {
19
+ var acc : Long = settings.fixedRate * settings.fixedRatePeriod
20
+ var i : Long = settings.fixedRatePeriod + 1
21
+ while (i <= h) {
22
+ acc += emissionAt(i)
23
+ i += 1
68
24
}
25
+ acc
26
+ }
69
27
70
28
def emissionAt (h : Long ): Long = {
71
29
val defaultReward = math.max(settings.fixedRate - settings.oneEpochReduction * epoch(h), 0 )
@@ -86,8 +44,10 @@ final class Emission(settings: MonetarySettings, reemission: ReemissionSettings)
86
44
1 + (h - settings.fixedRatePeriod) / settings.epochLength
87
45
88
46
private def getEpochEmissionAfterEip27 (e : Int ): Long = {
89
- val defaultRewardInEpoch = math.max(settings.fixedRate - settings.oneEpochReduction * e, 0 ) * settings.epochLength
90
- defaultRewardInEpoch - getReemission(defaultRewardInEpoch) * settings.epochLength
47
+ val defaultReward = math.max(settings.fixedRate - settings.oneEpochReduction * e, 0 )
48
+ val defaultRewardInEpoch = defaultReward * settings.epochLength
49
+ val reemissionInEpoch = getReemission(defaultReward) * settings.epochLength
50
+ defaultRewardInEpoch - reemissionInEpoch
91
51
}
92
52
93
53
private def getReemission (reward : Long ): Long =
0 commit comments