Check lock and account transactions in regard to height

parent c55a3536
Pipeline #31588390 failed with stages
in 4 minutes and 47 seconds
......@@ -208,30 +208,42 @@ error_code_1(Tx=#transfer_tx{to=To}, Data, #account{locked_until=LockedUntil}) -
true ->
?ALREADY_EXECUTED
end;
error_code_1(#account_tx{valid_until=ValidUntil, to=To, from=From}, Data, _) ->
case From =:= To orelse not ercoin_account:is_locked(ercoin_account:get(From, Data)) of
error_code_1(#account_tx{valid_until=ValidUntil, to=To, from=From}, Data=#data{height=Height}, FromAccount) ->
case ValidUntil > Height of
true ->
case ercoin_account:get(To, Data) of
none ->
?OK;
#account{valid_until=CurrentValidUntil} ->
case ValidUntil > CurrentValidUntil of
true ->
case From =:= To orelse not ercoin_account:is_locked(FromAccount) of
true ->
case ercoin_account:get(To, Data) of
none ->
?OK;
false ->
?FORBIDDEN
end
#account{valid_until=CurrentValidUntil} ->
case ValidUntil > CurrentValidUntil of
true ->
?OK;
false ->
?FORBIDDEN
end
end;
false ->
?FORBIDDEN
end;
false ->
?FORBIDDEN
?INVALID_TIMESTAMP
end;
error_code_1(#lock_tx{address=Address, locked_until=LockedUntil}, Data, _) ->
#account{locked_until=CurrentLockedUntil, valid_until=ValidUntil} = ercoin_account:get(Address, Data),
case (CurrentLockedUntil =:= none orelse LockedUntil > CurrentLockedUntil) andalso LockedUntil =< ValidUntil of
error_code_1(
#lock_tx{address=Address, locked_until=LockedUntil},
#data{height=Height},
#account{locked_until=CurrentLockedUntil, valid_until=ValidUntil}) ->
case LockedUntil > Height of
true ->
?OK;
case (CurrentLockedUntil =:= none orelse LockedUntil > CurrentLockedUntil) andalso LockedUntil =< ValidUntil of
true ->
?OK;
false ->
?FORBIDDEN
end;
false ->
?FORBIDDEN
?INVALID_TIMESTAMP
end;
error_code_1(Tx=#vote_tx{address=Address}, Data=#data{validators=Validators, future_validators=FutureValidators}, _) ->
case in_fresh_txs(Tx, Data) of
......
......@@ -330,6 +330,11 @@ data_with_invalid_tx_bin() ->
To = ercoin_account:get(Tx#account_tx.to, Data),
{ercoin_account:put(To#account{valid_until=Tx#account_tx.valid_until + ShorterFor}, Data), ercoin_tx:serialize(Tx)}
end),
%% Valid until not greater than block height.
?LET(
{{{Data=#data{height=Height}, SKs}, Tx}, ShorterFor},
{data_sks_and_account_tx(), non_neg_integer()},
{Data, ercoin_tx:serialize(sign_tx(Tx#account_tx{valid_until=max(0, Height - ShorterFor)}, SKs))}),
%% Account tx: From locked and To other than From.
?LET(
{{{Data, _}, Tx}, LockedFor, ValidatorPK},
......@@ -348,6 +353,11 @@ data_with_invalid_tx_bin() ->
Data),
ercoin_tx:serialize(Tx)}
end),
%% Locked until not greater than block height.
?LET(
{{{Data=#data{height=Height}, SKs}, Tx}, ShorterFor},
{data_sks_and_lock_tx(), non_neg_integer()},
{Data, ercoin_tx:serialize(sign_tx(Tx#lock_tx{locked_until=max(0, Height - ShorterFor)}, SKs))}),
%% Lock tx: Locked until longer than valid until.
?LET(
{{{Data, SKs}, Tx}, LongerFor},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment