Skip to content

Commit

Permalink
Add timestamp in the conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmanzanera committed Oct 14, 2022
1 parent 38e42d1 commit 85ac272
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/archethic/contracts/contract/conditions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule Archethic.Contracts.Contract.Conditions do
:uco_transfers,
:token_transfers,
:previous_public_key,
:timestamp,
origin_family: :all
]

Expand All @@ -27,7 +28,8 @@ defmodule Archethic.Contracts.Contract.Conditions do
uco_transfers: map() | Macro.t() | nil,
token_transfers: map() | Macro.t() | nil,
previous_public_key: binary() | Macro.t() | nil,
origin_family: SharedSecrets.origin_family() | :all
origin_family: SharedSecrets.origin_family() | :all,
timestamp: DateTime.t() | nil
}

def empty?(%__MODULE__{
Expand All @@ -38,7 +40,8 @@ defmodule Archethic.Contracts.Contract.Conditions do
secrets: nil,
uco_transfers: nil,
token_transfers: nil,
previous_public_key: nil
previous_public_key: nil,
timestamp: nil
}),
do: true

Expand Down
5 changes: 5 additions & 0 deletions lib/archethic/contracts/interpreter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,11 @@ defmodule Archethic.Contracts.Interpreter do
{:previous_public_key, true}
end

defp validate_condition({:timestamp, nil}, _) do
# Skip the verification as timestamp change for each transaction
{:timestamp, true}
end

# Validation rules for inherit constraints
defp validate_condition({field, nil}, %{"previous" => prev, "next" => next}) do
{field, Map.get(prev, Atom.to_string(field)) == Map.get(next, Atom.to_string(field))}
Expand Down

0 comments on commit 85ac272

Please sign in to comment.