Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Goshimmer_without_tipselection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COLLET Ismael
Goshimmer_without_tipselection
Commits
d24a9065
Commit
d24a9065
authored
5 years ago
by
Hans Moog
Browse files
Options
Downloads
Patches
Plain Diff
Feat: added formula to calculate mana of transfer
parent
e4472909
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/mana/mana.go
+23
-12
23 additions, 12 deletions
packages/mana/mana.go
packages/mana/mana_test.go
+7
-5
7 additions, 5 deletions
packages/mana/mana_test.go
with
30 additions
and
17 deletions
packages/mana/mana.go
+
23
−
12
View file @
d24a9065
package
mana
package
mana
import
"math"
import
(
"math"
)
func
CoinTimeDestroyed
(
transferredValue
uint64
,
parkedTime
uint64
)
uint64
{
func
CoinTimeDestroyed
(
transferredValue
uint64
,
parkedTime
uint64
)
uint64
{
return
transferredValue
*
parkedTime
return
transferredValue
*
parkedTime
}
}
func
ErodedGains
(
gainsPerInterval
uint64
,
elapsedIntervals
uint64
)
uint64
{
func
ManaOfTransfer
(
value
uint64
,
receivedTime
uint64
,
spentTime
uint64
)
(
result
uint64
)
{
return
uint64
(
float64
(
gainsPerInterval
)
*
DECAY_FACTOR
*
(
1
-
math
.
Pow
(
DECAY_FACTOR
,
float64
(
elapsedIntervals
)))
/
(
1
-
DECAY_FACTOR
))
firstIntervalDuration
:=
DECAY_INTERVAL
-
receivedTime
%
DECAY_INTERVAL
}
lastIntervalDuration
:=
spentTime
%
DECAY_INTERVAL
erosionCount
:=
(
spentTime
-
receivedTime
)
/
DECAY_INTERVAL
gainsInFirstInterval
:=
CoinTimeDestroyed
(
value
,
firstIntervalDuration
)
gainsInLastInterval
:=
CoinTimeDestroyed
(
value
,
lastIntervalDuration
)
gainsPerConsecutiveInterval
:=
CoinTimeDestroyed
(
value
,
DECAY_INTERVAL
)
func
ManaOfTransfer
(
value
uint64
,
parkedTime
uint64
)
uint64
{
scaleFactor
:=
1
-
DECAY_RATE
fullErosionIntervals
:=
parkedTime
/
DECAY_INTERVAL
if
fullErosionIntervals
>=
1
{
erodedGainsOfFirstInterval
:=
uint64
(
float64
(
gainsInFirstInterval
)
*
math
.
Pow
(
scaleFactor
,
float64
(
erosionCount
)))
gainsPerInterval
:=
CoinTimeDestroyed
(
value
,
DECAY_INTERVAL
)
return
E
rodedGains
(
gainsPerInterval
,
fullErosionIntervals
)
+
CoinTimeDestroyed
(
value
,
(
parkedTime
-
fullErosionIntervals
*
DECAY_INTERVAL
))
var
e
rodedGains
OfConsecutiveIntervals
uint64
}
else
{
if
erosionCount
>=
1
{
return
CoinTimeDestroyed
(
value
,
parkedTime
)
erodedGainsOfConsecutiveIntervals
=
uint64
(
float64
(
gainsPerConsecutiveInterval
)
*
scaleFactor
*
(
1
-
math
.
Pow
(
scaleFactor
,
float64
(
erosionCount
-
1
)))
/
(
1
-
scaleFactor
)
)
}
}
result
+=
erodedGainsOfFirstInterval
result
+=
erodedGainsOfConsecutiveIntervals
result
+=
gainsInLastInterval
return
}
}
const
(
const
(
DECAY_INTERVAL
=
100
DECAY_INTERVAL
=
100
DECAY_
FACTOR
=
0.
9
DECAY_
RATE
=
0.
5
)
)
This diff is collapsed.
Click to expand it.
packages/mana/mana_test.go
+
7
−
5
View file @
d24a9065
...
@@ -6,9 +6,11 @@ import (
...
@@ -6,9 +6,11 @@ import (
)
)
func
TestManaOfTransfer
(
t
*
testing
.
T
)
{
func
TestManaOfTransfer
(
t
*
testing
.
T
)
{
fmt
.
Println
(
ManaOfTransfer
(
50
,
99
))
fmt
.
Println
(
ManaOfTransfer
(
50
,
10
,
110
))
fmt
.
Println
(
ManaOfTransfer
(
50
,
100
))
fmt
.
Println
(
ManaOfTransfer
(
50
,
0
,
190
))
fmt
.
Println
(
ManaOfTransfer
(
50
,
200
))
fmt
.
Println
(
ManaOfTransfer
(
50
,
0
,
200
))
fmt
.
Println
(
ManaOfTransfer
(
50
,
290
))
fmt
.
Println
(
ManaOfTransfer
(
50
,
0
,
290
))
fmt
.
Println
(
ManaOfTransfer
(
50
,
300
))
fmt
.
Println
(
ManaOfTransfer
(
50
,
0
,
300
))
fmt
.
Println
(
ManaOfTransfer
(
50
,
0
,
390
))
fmt
.
Println
(
ManaOfTransfer
(
50
,
0
,
400
))
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment