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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
teaching
dunixir
Commits
d2b1f041
Commit
d2b1f041
authored
3 years ago
by
TEMBOU NZUDIE Theo
Browse files
Options
Downloads
Patches
Plain Diff
ajout de wot/certifiers_of
parent
d6d71854
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/bma/wot/certifiersof.ex
+82
-2
82 additions, 2 deletions
lib/bma/wot/certifiersof.ex
test/http/wot/members_test.exs
+0
-2
0 additions, 2 deletions
test/http/wot/members_test.exs
with
82 additions
and
4 deletions
lib/bma/wot/certifiersof.ex
+
82
−
2
View file @
d2b1f041
defmodule
BMA
.
Wot
.
CertifiersOf
do
def
get
(
search
)
do
Poison
.
encode!
(
"#TODO "
<>
search
)
defp
get_id_entry
(
pub
,
entries_id
)
do
Enum
.
reduce
(
entries_id
,
nil
,
fn
entry
,
acc
->
case
Map
.
get
(
entry
,
:pub
)
==
pub
do
true
->
entry
false
->
acc
end
end
)
end
def
get
(
search
,
db_id
\\
'data/global_iindex'
,
db_cert
\\
'data/global_cindex'
,
db_block
\\
'data/global_bindex'
)
do
{
_
,
:iindex
}
=
:dets
.
open_file
(
:iindex
,
[{
:file
,
db_id
},
{
:type
,
:set
}])
entries_id
=
:dets
.
match
(
:iindex
,
{
:_
,
:"$2"
})
|>
Enum
.
map
(
fn
x
->
List
.
first
(
x
)
end
)
{
_
,
:cindex
}
=
:dets
.
open_file
(
:cindex
,
[{
:file
,
db_cert
},
{
:type
,
:set
}])
entries_cert
=
:dets
.
match
(
:cindex
,
{
:_
,
:"$2"
})
|>
Enum
.
map
(
fn
x
->
List
.
first
(
x
)
end
)
{
_
,
:bindex
}
=
:dets
.
open_file
(
:bindex
,
[{
:file
,
db_block
},
{
:type
,
:set
}])
entries_block
=
:dets
.
match
(
:bindex
,
{
:_
,
:"$2"
})
|>
Enum
.
map
(
fn
x
->
List
.
first
(
x
)
end
)
# entry de iindex correspondant à search
entry_id
=
Enum
.
reduce
(
entries_id
,
nil
,
fn
entry
,
acc
->
case
Map
.
get
(
entry
,
:pub
)
==
search
or
Map
.
get
(
entry
,
:id
)
==
search
do
true
->
entry
false
->
acc
end
end
)
# liste des certifications dont search est le receiver
certs
=
Enum
.
filter
(
entries_cert
,
fn
cert
->
Map
.
get
(
cert
,
:receiver
)
==
Map
.
get
(
entry_id
,
:pub
)
end
)
# creation de la liste du champ "certifications" de la requete
list_certs
=
Enum
.
reduce
(
certs
,
[],
fn
cert
,
acc
->
# entry de iindex correspondant au issuer de la certification
entry_id_
=
get_id_entry
(
Map
.
get
(
cert
,
:pub
),
entries_id
)
[
number
,
hash
]
=
String
.
split
(
Map
.
get
(
cert
,
:written_on
),
"-"
)
# numéro de block sur lequel est crée la certification
block_cert_time
=
String
.
split
(
Map
.
get
(
cert
,
:created_on
),
"-"
)
|>
List
.
first
()
|>
String
.
to_integer
()
# medianTime block sur lequel est crée la certification
medianTime
=
Enum
.
reduce
(
entries_block
,
nil
,
fn
block
,
acc
->
case
Map
.
get
(
block
,
:number
)
==
block_cert_time
do
true
->
Map
.
get
(
block
,
:medianTime
)
_
->
acc
end
end
)
[
%{
pubKey:
Map
.
get
(
cert
,
:pub
),
uid:
Map
.
get
(
entry_id_
,
:uid
),
isMember:
Map
.
get
(
entry_id_
,
:isMember
),
wasMember:
Map
.
get
(
entry_id_
,
:wasMember
),
sigDate:
Map
.
get
(
entry_id_
,
:written_on
),
written:
%{
number:
String
.
to_integer
(
number
),
hash:
hash
},
cert_time:
%{
block:
block_cert_time
,
medianTime:
medianTime
},
signature:
Map
.
get
(
cert
,
:sig
)
}
|
acc
]
end
)
map_to_return
=
%{
pubKey:
Map
.
get
(
entry_id
,
:pub
),
uid:
Map
.
get
(
entry_id
,
:uid
),
sigDate:
Map
.
get
(
entry_id
,
:written_on
),
isMember:
Map
.
get
(
entry_id
,
:isMember
),
certifications:
list_certs
}
Poison
.
encode
(
map_to_return
)
end
end
This diff is collapsed.
Click to expand it.
test/http/wot/members_test.exs
+
0
−
2
View file @
d2b1f041
...
...
@@ -91,8 +91,6 @@ defmodule BMA.Wot.MembersTest do
:file
.
delete
(
"test/global_iindex"
)
{
:ok
,
json:
BMA
.
Wot
.
Members
.
get
(
'test/global_iindex'
)}
end
test
"members query"
,
state
do
...
...
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