Skip to content
Snippets Groups Projects
Commit d06e33ae authored by ROUSSET Noemie's avatar ROUSSET Noemie
Browse files

hardship test qui marche pas encore

parent d0cb829a
No related branches found
No related tags found
No related merge requests found
......@@ -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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment