Skip to content
Snippets Groups Projects
Commit 0d0b9c01 authored by ABDELGHANI Nassim's avatar ABDELGHANI Nassim Committed by ABDELGHANI Nassim
Browse files

add doc for local validation

parent 92a5d9c4
Branches
Tags
1 merge request!46Resolve "Validation locale"
Showing
with 70 additions and 1 deletion
defmodule Block.Validation.Local.BlockSignature do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#signature
"""
require Logger
def invalid_g1_block() do
......
defmodule Block.Validation.Local.BlockTime do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#dates-1
"""
require Logger
# @default_avg_gen_time 16 * 60
......
defmodule Block.Validation.Local.PreIssuer do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#previousissuer
"""
def valid(block) do
not (block["number"] == 0 and
block["previousIssuer"] != nil) and
......
defmodule Block.Validation.Local.UnitBase do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#unitbase
"""
def valid(block) do
not (block["unitbase"] != 0 and block["number"] == 0)
end
......
defmodule Block.Validation.Local.IdentitySignature do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#identities
"""
def valid(block) do
Doc.Identity.local_validation(block["identities"], block["currency"])
end
......
defmodule Block.Validation.Local.InnerHash do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#innerhash
"""
def valid(block) do
computed_hash =
:crypto.hash(:sha256, _get_raw_inner_part(block))
......
defmodule Block.Validation.Local.MembershipSig do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#memberships-joiners-actives-leavers
"""
def valid(block) do
Doc.Membership.local_validation(
block["joiners"],
......
defmodule Block.Validation.Local.Nonce do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#nonce
"""
def valid(block) do
block["nonce"] >= 0
end
......
defmodule Block.Validation.Local.Parameters do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#parameters
"""
def valid(block) do
(block["number"] == 0 and block["parameters"] != "") or
(block["number"] > 0 and block["parameters"] == "")
......
defmodule Block.Validation.Local.PreviousHash do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#previoushash
"""
def valid(block) do
cond do
block["number"] > 0 ->
......
defmodule Block.Validation.Local.ProofOfWork do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#proof-of-work
"""
def valid(block) do
required_zeros = div(block["powMin"], 16)
String.match?(block["hash"], ~r/^0{#{required_zeros}}/)
......
defmodule Block.Validation.Local.TransactionCount do
@moduledoc """
Signatures count must be the same as issuers count
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#transactions
"""
def valid(block) do
Enum.all?(block["transactions"], fn element ->
length(element["signatures"]) == length(element["issuers"])
......
defmodule Block.Validation.Local.TxInfNbIssuers do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#transactions
"""
def valid(block) do
case block["transactions"] do
# Since there is no transaction field, there is no transaction to check
......
defmodule Block.Validation.Local.TransactionInput do
@moduledoc """
A transaction must have at least 1 source
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#transactions
"""
def valid(block) do
case block["transactions"] do
[] ->
......
defmodule Block.Validation.Local.TransactionNumberOfLines do
@moduledoc """
A transaction in compact format cannot measure more than 100 lines
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#transactions
"""
def valid(block) do
length(block["transactions"]) < 100
end
......
defmodule Block.Validation.Local.TransactionVersion do
@moduledoc """
Transaction's version must be equal to 10.
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#transactions
"""
def valid(block) do
Enum.all?(block["transactions"], fn element -> element["version"] == 10 end)
end
......
defmodule Block.Validation.Local.TxSigOrdered do
@moduledoc """
Signatures are ordered by issuer
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#transactions
"""
def valid(block) do
_valid_tx(block["transactions"])
end
......
defmodule Block.Validation.Local.UniversalDividend do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#universal-dividend
"""
def valid(block) do
block["number"] === 0 and block["dividend"] === nil
end
......
defmodule Block.Validation.Local.Version do
@moduledoc """
https://git.duniter.org/documents/rfcs/-/blob/master/rfc/0010_Duniter_Blockchain_Protocol_V12.md#version
"""
def valid(block) do
block["version"] >= 10
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment