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
Merge requests
!6
Implements inner hash validation
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Implements inner hash validation
inner-hash-validator
into
dev
Overview
0
Commits
1
Pipelines
3
Changes
3
Merged
MATEU Bruno
requested to merge
inner-hash-validator
into
dev
4 years ago
Overview
0
Commits
1
Pipelines
3
Changes
3
Expand
Implements:
#15 (closed)
0
0
Merge request reports
Viewing commit
0a48a498
Show latest version
3 files
+
166
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
0a48a498
Implements inner hash validation
· 0a48a498
Bruno MATEU
authored
4 years ago
Implements: #15
lib/block/validation/local/inner_hash.ex
0 → 100644
+
67
−
0
Options
defmodule
Block
.
Validation
.
Local
.
InnerHash
do
def
valid
(
block
)
do
computed_hash
=
:crypto
.
hash
(
:sha256
,
_get_raw_inner_part
(
block
))
|>
Base
.
encode16
()
|>
String
.
upcase
()
computed_hash
==
block
[
"inner_hash"
]
end
@doc
"""
Convert the given `list` into suitable format for hashing
Concat a '\n' at the end of each element from `list` and joins the table.
Returns: string
"""
def
_string_of_list
(
list
)
do
(
list
||
[])
|>
Enum
.
map
(
fn
i
->
i
<>
"
\n
"
end
)
|>
Enum
.
join
end
@doc
"""
Prepare given `block` for hashing and return computed string
Returns: string
"""
def
_get_raw_inner_part
(
block
)
do
"""
Version: #{block["version"]}
Type: Block
Currency: #{block["currency"]}
Number: #{block["number"]}
PoWMin: #{block["powMin"]}
Time: #{block["time"]}
MedianTime: #{block["medianTime"]}
#{ if block["dividend"] do "UniversalDividend: #{block["dividend"]}\n" end }\
UnitBase: #{block["unitBase"]}
Issuer: #{block["issuer"]}
IssuersFrame: #{block["issuersFrame"]}
IssuersFrameVar: #{block["issuersFrameVar"]}
DifferentIssuersCount: #{block["issuersCount"]}
#{ if block["previousHash"] do "PreviousHash: #{block["previousHash"]}\n" end }\
#{ if block["previousIssuer"] do "PreviousIssuer: #{block["previousIssuer"]}\n" end }\
#{ if block["parameters"] do "Parameters: #{block["parameters"]}\n" end }\
MembersCount: #{block["membersCount"]}
Identities:
#{_string_of_list block["identities"]}\
Joiners:
#{_string_of_list block["joiners"]}\
Actives:
#{_string_of_list block["actives"]}\
Leavers:
#{_string_of_list block["leavers"]}\
Revoked:
#{_string_of_list block["revoked"]}\
Excluded:
#{_string_of_list block["excluded"]}\
Certifications:
#{_string_of_list block["certifications"]}\
Transactions:
#{_string_of_list block["transactions"]}\
"""
end
end
Loading