Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dunixir
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
teaching
dunixir
Commits
d06e33ae
Commit
d06e33ae
authored
3 years ago
by
ROUSSET Noemie
Browse files
Options
Downloads
Patches
Plain Diff
hardship test qui marche pas encore
parent
d0cb829a
No related branches found
No related tags found
No related merge requests found
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/bma/blockchain/hardship.ex
+7
-10
7 additions, 10 deletions
lib/bma/blockchain/hardship.ex
test/http/blockchain/hardship_get_test.exs
+790
-0
790 additions, 0 deletions
test/http/blockchain/hardship_get_test.exs
with
797 additions
and
10 deletions
lib/bma/blockchain/hardship.ex
+
7
−
10
View file @
d06e33ae
...
...
@@ -7,14 +7,15 @@ defmodule BMA.Blockchain.Hardship do
@doc
"""
Calculate and return the hardship of the issuer given in search with its public key
"""
def
get
(
search
)
do
{
:ok
,
:block
}
=
:dets
.
open_file
(
:block
,
[{
:file
,
'data/block'
},
{
:type
,
:set
}])
case
:dets
.
match
(
:block
,
{
:"$1"
,
%{
issuer:
search
}})
do
[{
_key
,
block_searched
}]
->
def
get
(
search
,
db_block
\\
'data/block'
,
db_global_bindex
\\
'data/global_bindex'
)
do
#last block of the blockchain
{
:ok
,
:global_bindex
}
=
:dets
.
open_file
(
:global_bindex
,
[{
:file
,
'data/global_bindex'
},
{
:type
,
:set
}])
last_block
=
:ets
.
match
(
:global_bindex
,
{
:last_block
,
:"$1"
})
{
:ok
,
:global_bindex
}
=
:dets
.
open_file
(
:global_bindex
,
[{
:file
,
db_global_bindex
},
{
:type
,
:set
}])
last_block_id
=
:dets
.
match
(
:global_bindex
,
{
:last_block
,
:"$1"
})
last_block
=
:dets
.
match
(
:block
,
{
last_block_id
,
:"$1"
})
{
:ok
,
:block
}
=
:dets
.
open_file
(
:block
,
[{
:file
,
db_block
},
{
:type
,
:set
}])
case
:dets
.
match
(
:block
,
{
:"$1"
,
%{
issuer:
search
}})
do
[{
_key
,
block_searched
}]
->
#exclusion factor calculation
nbPreviousIssuers
=
last_block
.
issuersCount
nbBlocksSince
=
last_block
.
number
-
block_searched
.
number
...
...
@@ -26,10 +27,6 @@ defmodule BMA.Blockchain.Hardship do
Poison
.
encode!
(
getHardship
(
exFact
,
last_block
[
:powMin
],
handicap
,
last_block
))
_
->
#last block of the blockchain
{
:ok
,
:global_bindex
}
=
:dets
.
open_file
(
:global_bindex
,
[{
:file
,
'data/global_bindex'
},
{
:type
,
:set
}])
last_block
=
:ets
.
match
(
:global_bindex
,
{
:last_block
,
:"$1"
})
exFact
=
1
powMin
=
last_block
[
:powMin
]
handicap
=
getHandicap
(
last_block
,
search
)
...
...
This diff is collapsed.
Click to expand it.
test/http/blockchain/hardship_get_test.exs
0 → 100644
+
790
−
0
View file @
d06e33ae
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