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
!42
Resolve "Récupération des blocs"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Resolve "Récupération des blocs"
186-recuperation-des-blocs
into
dev
Overview
0
Commits
9
Pipelines
10
Changes
2
Merged
JAUJAY Augustin
requested to merge
186-recuperation-des-blocs
into
dev
3 years ago
Overview
0
Commits
9
Pipelines
10
Changes
2
Closes
#186 (closed)
Edited
3 years ago
by
JAUJAY Augustin
0
0
Merge request reports
Viewing commit
11df4a2b
Prev
Next
Show latest version
2 files
+
15
−
51
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
11df4a2b
Cleaning open_file calls and fill_with_blocks calls
· 11df4a2b
Augustin Jaujay
authored
3 years ago
lib/dunixir/create_bdd.ex
+
13
−
49
View file @ 11df4a2b
Edit in single-file editor
Open in Web IDE
Show full file
defmodule
BDD
do
require
Logger
@base_url
'https://g1-test.duniter.org
/blockchain/blocks/
'
@base_url
'https://g1-test.duniter.org'
@doc
"""
Create some of the needeed dets table after checking if they already exist
@@ -9,61 +9,25 @@ defmodule BDD do
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
}])
:dets
.
open_file
(
:wallet
,
[{
:file
,
'data/wallet'
},
{
:type
,
:set
}])
:dets
.
open_file
(
:meta
,
[{
:file
,
'data/meta'
},
{
:type
,
:set
}])
:dets
.
open_file
(
:peer
,
[{
:file
,
'data/peer'
},
{
: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
if
not
File
.
exists?
(
'data/meta'
)
do
:dets
.
open_file
(
:meta
,
[{
:file
,
'data/meta'
},
{
:type
,
:set
}])
end
if
not
File
.
exists?
(
'data/wallet'
)
do
:dets
.
open_file
(
:wallet
,
[{
:file
,
'data/wallet'
},
{
:type
,
:set
}])
end
if
not
File
.
exists?
(
'data/peer'
)
do
:dets
.
open_file
(
:peer
,
[{
:file
,
'data/peer'
},
{
:type
,
:set
}])
end
end
: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
}])
:dets
.
open_file
(
:wallet
,
[{
:file
,
'data/wallet'
},
{
:type
,
:set
}])
:dets
.
open_file
(
:meta
,
[{
:file
,
'data/meta'
},
{
:type
,
:set
}])
:dets
.
open_file
(
:peer
,
[{
:file
,
'data/peer'
},
{
:type
,
:set
}])
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
def
fill_with_block
()
do
{
:ok
,
:block
}
=
:dets
.
open_file
(
:block
,
[{
:file
,
'data/block'
},
{
:type
,
:set
}])
case
:httpc
.
request
(
:get
,
{
@base_url
++
to_charlist
(
n
)
++
'/0'
,
[]},
[],
[])
do
case
:httpc
.
request
(
:get
,
{
@base_url
++
'/blockchain/blocks/'
++
to_charlist
(
50
)
++
'/0'
,
[]},
[],
[])
do
{
:ok
,
resp
}
->
Logger
.
info
(
'data received'
)
@@ -90,7 +54,7 @@ defmodule BDD.Create do
def
init
(
_
)
do
BDD
.
create_if_not_created
()
BDD
.
fill_with_block
(
50
)
BDD
.
fill_with_block
()
# TODO indexation
{
:ok
,
nil
}
end
Loading