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
3
Merged
JAUJAY Augustin
requested to merge
186-recuperation-des-blocs
into
dev
3 years ago
Overview
0
Commits
9
Pipelines
10
Changes
3
Closes
#186 (closed)
Edited
3 years ago
by
JAUJAY Augustin
0
0
Merge request reports
Compare
dev
version 9
db645a7d
3 years ago
version 8
36b3090d
3 years ago
version 7
800b7f76
3 years ago
version 6
8beda6bd
3 years ago
version 5
ddf3389d
3 years ago
version 4
08b0292f
3 years ago
version 3
6d1bf6ca
3 years ago
version 2
0fda0678
3 years ago
version 1
11df4a2b
3 years ago
dev (base)
and
latest version
latest version
db645a7d
9 commits,
3 years ago
version 9
db645a7d
9 commits,
3 years ago
version 8
36b3090d
8 commits,
3 years ago
version 7
800b7f76
7 commits,
3 years ago
version 6
8beda6bd
6 commits,
3 years ago
version 5
ddf3389d
5 commits,
3 years ago
version 4
08b0292f
4 commits,
3 years ago
version 3
6d1bf6ca
3 commits,
3 years ago
version 2
0fda0678
2 commits,
3 years ago
version 1
11df4a2b
1 commit,
3 years ago
3 files
+
52
−
62
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
lib/dunixir/create_bdd.ex
+
50
−
60
View file @ db645a7d
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,75 +9,65 @@ 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
}])
:dets
.
close
(
:global_iindex
)
:dets
.
close
(
:global_bindex
)
:dets
.
close
(
:global_mindex
)
:dets
.
close
(
:global_cindex
)
:dets
.
close
(
:global_sindex
)
:dets
.
close
(
:block
)
:dets
.
close
(
:wallet
)
:dets
.
close
(
:meta
)
:dets
.
close
(
:peer
)
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
{
:ok
,
resp
}
->
Logger
.
info
(
'data received'
)
# Getting current block from the remote node of the blockchain
currentBlock
=
case
:httpc
.
request
(
:get
,
{
@base_url
++
'/blockchain/current'
,
[]},
[],
[])
do
{
:ok
,
{{
_
,
200
,
'OK'
},
_headers
,
body
}}
->
Poison
.
decode!
(
body
)
case
resp
do
{{
_
,
200
,
'OK'
},
_headers
,
'[]'
}
->
Logger
.
info
(
'---DONE---'
)
_
->
Logger
.
info
(
'Filling DB : Failing when getting current block'
)
end
{{
_
,
200
,
'OK'
},
_headers
,
body
}
->
Poison
.
decode!
(
body
)
|>
Enum
.
map
(
fn
b
->
:dets
.
insert
(
:block
,
{
b
[
"number"
],
b
})
end
)
:dets
.
info
(
:block
)[
:size
]
..
50
# currentBlock["number"] # TODO : Fetch all the blocks
|>
Enum
.
chunk_every
(
5000
)
|>
Enum
.
map
(
fn
chk
->
# Putting the new blocks in the local database
case
:httpc
.
request
(
:get
,
{
@base_url
++
'/blockchain/blocks/'
++
to_charlist
(
List
.
last
(
chk
)
-
List
.
first
(
chk
))
++
'/'
++
to_charlist
(
List
.
first
(
chk
)),
[]},
[],
[])
do
{
:ok
,
{{
_
,
200
,
'OK'
},
_headers
,
'[]'
}}
->
Logger
.
info
(
'Filling DB : No blocks to get from remote g1-test node'
)
{
:ok
,
{{
_
,
200
,
'OK'
},
_headers
,
body
}}
->
Logger
.
info
(
'Filling DB : Successfully got blocks '
++
to_charlist
(
List
.
first
(
chk
))
++
' to '
++
to_charlist
(
List
.
last
(
chk
))
++
' from '
++
@base_url
)
Poison
.
decode!
(
body
)
|>
Enum
.
map
(
fn
b
->
:dets
.
insert
(
:block
,
{
b
[
"number"
],
b
})
end
)
_
->
Logger
.
info
(
'---Failed when filling DataBase---'
)
end
end
)
_
->
Logger
.
info
(
'---Failed---'
)
end
end
:dets
.
close
(
:block
)
end
end
@@ -90,7 +80,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