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
Merge requests
!18
Ajout d'API HTTP BMA
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Closed
Ajout d'API HTTP BMA
thomas
into
dev
Overview
0
Commits
12
Pipelines
1
Changes
1
Closed
BARBIER Thomas
requested to merge
thomas
into
dev
4 years ago
Overview
0
Commits
12
Pipelines
1
Changes
1
0
0
Merge request reports
Viewing commit
60986006
Prev
Next
Show latest version
1 file
+
59
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
60986006
create_bdd.ex added
· 60986006
BARBIER Thomas
authored
4 years ago
lib/dunixir/create_bdd.ex
0 → 100644
+
59
−
0
View file @ 60986006
Edit in single-file editor
Open in Web IDE
defmodule
CreateBDD
do
require
Logger
@base_url
'https://g1-test.duniter.org/blockchain/blocks/'
@doc
"""
Create some of the needeed dets table after checking if they already exist
"""
def
create_if_not_created
do
if
not
File
.
dir?
(
'data'
)
do
File
.
mkdir
(
'data'
)
:dets
.
open_file
(
:global_iindex
,
[{
:file
,
'data/global_iindex'
}
,
{
:type
,
:set
}])
:dets
.
open_file
(
:global_bindex
,
[{
:file
,
'data/global_bindex'
}
,
{
:type
,
:set
}])
:dets
.
open_file
(
:global_mindex
,
[{
:file
,
'data/global_mindex'
}
,
{
:type
,
:set
}])
:dets
.
open_file
(
:global_cindex
,
[{
:file
,
'data/global_cindex'
}
,
{
:type
,
:set
}])
:dets
.
open_file
(
:global_sindex
,
[{
:file
,
'data/global_sindex'
}
,
{
:type
,
:set
}])
:dets
.
open_file
(
:block
,
[{
:file
,
'data/block'
}
,
{
:type
,
:set
}])
else
if
not
File
.
exists?
(
'data/block'
)
do
:dets
.
open_file
(
:block
,
[{
:file
,
'data/block'
}
,
{
:type
,
:set
}])
end
if
not
File
.
exists?
(
'data/global_iindex'
)
do
:dets
.
open_file
(
:global_iindex
,
[{
:file
,
'data/global_iindex'
}
,
{
:type
,
:set
}])
end
if
not
File
.
exists?
(
'data/global_bindex'
)
do
:dets
.
open_file
(
:global_bindex
,
[{
:file
,
'data/global_bindex'
}
,
{
:type
,
:set
}])
end
if
not
File
.
exists?
(
'data/global_sindex'
)
do
:dets
.
open_file
(
:global_sindex
,
[{
:file
,
'data/global_sindex'
}
,
{
:type
,
:set
}])
end
if
not
File
.
exists?
(
'data/global_cindex'
)
do
:dets
.
open_file
(
:global_cindex
,
[{
:file
,
'data/global_cindex'
}
,
{
:type
,
:set
}])
end
if
not
File
.
exists?
(
'data/global_mindex'
)
do
:dets
.
open_file
(
:global_mindex
,
[{
:file
,
'data/global_mindex'
}
,
{
:type
,
:set
}])
end
end
end
@doc
"""
Insert in the block dets table the n fisrt block of the bockchain, get throught an http request """
def
fill_with_block
(
n
)
do
{
:ok
,
:block
}
=
:dets
.
open_file
(
:block
,
[{
:file
,
'data/block'
}
,
{
:type
,
:set
}])
case
:httpc
.
request
(
:get
,
{
@base_url
++
to_charlist
(
n
)
++
'/0'
,
[]},
[],
[])
do
{
:ok
,
resp
}
->
Logger
.
info
(
'data received'
)
case
resp
do
{{
_
,
200
,
'OK'
},
_headers
,
'[]'
}
->
Logger
.
info
(
'---DONE---'
)
{{
_
,
200
,
'OK'
},
_headers
,
body
}
->
Poison
.
decode!
(
body
)
|>
Enum
.
map
(
fn
b
->
:dets
.
insert
(
:block
,
{
b
[
"number"
],
b
})
end
)
_
->
Logger
.
info
(
'---Failed---'
)
end
end
end
end
\ No newline at end of file
Loading