Skip to content

Commit b58b278

Browse files
authored
chore: remove all consistency credo warnings (#1490)
1 parent e26a2a7 commit b58b278

File tree

9 files changed

+59
-43
lines changed

9 files changed

+59
-43
lines changed

lib/ae_mdw/contract.ex

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ defmodule AeMdw.Contract do
3434
# for balances or balance
3535
@type serialized_call :: map()
3636
# fcode or aevm info
37-
@type type_info :: {:fcode, map(), map(), map()} | list()
37+
@type fhash() :: binary()
38+
@type is_payable() :: boolean()
39+
@type type_info ::
40+
{:fcode, map(), map(), map()} | [{fhash(), fname(), is_payable(), binary(), binary()}]
3841
@type compiler_vsn :: String.t()
3942
@type source_hash :: <<_::256>>
4043
@type ct_info :: {type_info(), compiler_vsn(), source_hash()}
@@ -160,7 +163,7 @@ defmodule AeMdw.Contract do
160163
defp decode_call_data(contract, call_data),
161164
do: decode_call_data(contract, call_data, &id/1)
162165

163-
defp decode_call_data({:fcode, _, _, _} = fate_info, call_data, mapper) do
166+
defp decode_call_data({:fcode, _funs, _syms, _annotations} = fate_info, call_data, mapper) do
164167
{:tuple, {fun_hash, {:tuple, tup_args}}} = :aeb_fate_encoding.deserialize(call_data)
165168

166169
# sample fun_hash not matching: <<74, 202, 20, 78, 108, 15, 83, 141, 70, 92, 69, 235, 191, 127, 43, 123, 21, 80, 189, 1, 86, 76, 125, 166, 246, 81, 67, 150, 69, 95, 156, 6>>
@@ -176,26 +179,38 @@ defmodule AeMdw.Contract do
176179
defp decode_call_data([_ | _] = aevm_info, call_data, mapper) do
177180
{:ok, fun_hash} = :aeb_aevm_abi.get_function_hash_from_calldata(call_data)
178181
{:ok, fun_name} = :aeb_aevm_abi.function_name_from_type_hash(fun_hash, aevm_info)
179-
{:ok, arg_type, _} = :aeb_aevm_abi.typereps_from_type_hash(fun_hash, aevm_info)
180-
{:ok, {_, vm_args}} = :aeb_heap.from_binary({:tuple, [:word, arg_type]}, call_data)
182+
{:ok, arg_type, _type_rep} = :aeb_aevm_abi.typereps_from_type_hash(fun_hash, aevm_info)
183+
{:ok, {_arg_type, vm_args}} = :aeb_heap.from_binary({:tuple, [:word, arg_type]}, call_data)
181184
{fun_name, aevm_val({arg_type, vm_args}, mapper)}
182185
end
183186

184187
defp decode_call_result(_info, _fun_name, :error, value, mapper),
185188
do: mapper.(%{error: [value]})
186189

187-
defp decode_call_result({:fcode, _, _, _}, _fun_name, :revert, value, mapper),
188-
do: mapper.(%{abort: [:aeb_fate_encoding.deserialize(value)]})
190+
defp decode_call_result(
191+
{:fcode, _functions, _symbols, _annotations},
192+
_fun_name,
193+
:revert,
194+
value,
195+
mapper
196+
),
197+
do: mapper.(%{abort: [:aeb_fate_encoding.deserialize(value)]})
189198

190-
defp decode_call_result([_ | _], _fun_name, :revert, value, mapper),
199+
defp decode_call_result([_arg_type, _ret_type], _fun_name, :revert, value, mapper),
191200
do: mapper.(%{abort: [ok!(:aeb_heap.from_binary(:string, value))]})
192201

193-
defp decode_call_result({:fcode, _, _, _}, _fun_name, :ok, value, mapper),
194-
do: fate_val(:aeb_fate_encoding.deserialize(value), mapper)
202+
defp decode_call_result(
203+
{:fcode, _functions, _symbols, _annotations},
204+
_fun_name,
205+
:ok,
206+
value,
207+
mapper
208+
),
209+
do: fate_val(:aeb_fate_encoding.deserialize(value), mapper)
195210

196-
defp decode_call_result([_ | _] = info, fun_name, :ok, value, mapper) do
211+
defp decode_call_result([_arg_type | _ret_type] = info, fun_name, :ok, value, mapper) do
197212
{:ok, hash} = :aeb_aevm_abi.type_hash_from_function_name(fun_name, info)
198-
{:ok, _, res_type} = :aeb_aevm_abi.typereps_from_type_hash(hash, info)
213+
{:ok, _type_rep, res_type} = :aeb_aevm_abi.typereps_from_type_hash(hash, info)
199214
{:ok, vm_res} = :aeb_heap.from_binary(res_type, value)
200215
aevm_val({res_type, vm_res}, mapper)
201216
end
@@ -365,7 +380,7 @@ defmodule AeMdw.Contract do
365380
defp fate_val(x, f) when is_map(x),
366381
do: f.({:map, Enum.map(x, fn {k, v} -> %{key: fate_val(k, f), val: fate_val(v, f)} end)})
367382

368-
defp fate_val({:variant, _, tag, args}, f),
383+
defp fate_val({:variant, _bytecode, tag, args}, f),
369384
do: f.({:variant, [tag | Enum.map(tuple_to_list(args), &fate_val(&1, f))]})
370385

371386
defp aevm_val({:word, x}, f) when is_integer(x), do: f.({:word, x})
@@ -424,7 +439,7 @@ defmodule AeMdw.Contract do
424439
trees_in = consensus.state_pre_transform_micro_node(node, trees_in)
425440
env = :aetx_env.tx_env_from_key_header(prev_key_header, prev_key_hash, time, prev_hash)
426441

427-
{:ok, _, _, events} =
442+
{:ok, _sigs, _trees, events} =
428443
:aec_block_micro_candidate.apply_block_txs_strict(txs_taken, trees_in, env)
429444

430445
events

lib/ae_mdw/db/mutations/write_fields_mutation.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule AeMdw.Db.WriteFieldsMutation do
4545
tx_type
4646
|> Node.tx_ids()
4747
|> Enum.reduce(state, fn {field, pos}, state ->
48-
<<_::256>> = pk = resolve_pubkey(state, elem(tx, pos), tx_type, field, block_index)
48+
<<_pk::256>> = pk = resolve_pubkey(state, elem(tx, pos), tx_type, field, block_index)
4949
field_pos = AeMdw.Fields.field_pos_mask(wrap_tx, pos)
5050
{tx_type, pos} = if wrap_tx, do: {wrap_tx, field_pos}, else: {tx_type, pos}
5151
write_field(state, tx_type, pos, pk, txi)

lib/ae_mdw/db/sync/id_counter.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ defmodule AeMdw.Db.Sync.IdCounter do
99
require Model
1010

1111
@spec incr_count(State.t(), Model.id_count_index()) :: State.t()
12-
def incr_count(state, {_, _, _} = field_key) do
12+
def incr_count(state, {_tx_type, _pos, _pk} = field_key) do
1313
update_count(state, field_key, 1)
1414
end
1515

1616
@spec update_count(State.t(), Model.id_count_index(), integer()) :: State.t()
17-
def update_count(state, {_, _, _} = field_key, delta) do
18-
case State.get(state, AeMdw.Db.Model.IdCount, field_key) do
17+
def update_count(state, {_tx_type, _pos, _pk} = field_key, delta) do
18+
case State.get(state, Model.IdCount, field_key) do
1919
:not_found ->
2020
model = Model.id_count(index: field_key, count: 0)
2121
write_count(state, model, 1)
@@ -31,6 +31,6 @@ defmodule AeMdw.Db.Sync.IdCounter do
3131
@spec write_count(State.t(), Model.id_count(), integer()) :: State.t()
3232
defp write_count(state, Model.id_count(count: total) = model, delta) do
3333
model = Model.id_count(model, count: total + delta)
34-
State.put(state, AeMdw.Db.Model.IdCount, model)
34+
State.put(state, Model.IdCount, model)
3535
end
3636
end

lib/ae_mdw/extract.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# credo:disable-for-this-file Credo.Check.Consistency.UnusedVariableNames
12
defmodule AeMdw.Extract do
23
@moduledoc "currently we require that AE node is compiled with debug_info"
34

lib/ae_mdw/node/db.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,22 @@ defmodule AeMdw.Node.Db do
129129

130130
@spec get_tx_data(binary()) ::
131131
{Blocks.block_hash(), Node.tx_type(), Node.signed_tx(), Node.tx()}
132-
def get_tx_data(<<_::256>> = tx_hash) do
132+
def get_tx_data(<<_pk::256>> = tx_hash) do
133133
{block_hash, signed_tx} = :aec_db.find_tx_with_location(tx_hash)
134134
{type, tx_rec} = :aetx.specialize_type(:aetx_sign.tx(signed_tx))
135135
{block_hash, type, signed_tx, tx_rec}
136136
end
137137

138138
@spec get_tx(binary()) :: Node.tx()
139-
def get_tx(<<_::256>> = tx_hash) do
140-
{_, signed_tx} = :aec_db.find_tx_with_location(tx_hash)
141-
{_, tx_rec} = :aetx.specialize_type(:aetx_sign.tx(signed_tx))
139+
def get_tx(<<_pk::256>> = tx_hash) do
140+
{_block_hash, signed_tx} = :aec_db.find_tx_with_location(tx_hash)
141+
{_type, tx_rec} = :aetx.specialize_type(:aetx_sign.tx(signed_tx))
142142
tx_rec
143143
end
144144

145145
@spec get_signed_tx(binary()) :: tuple()
146-
def get_signed_tx(<<_::256>> = tx_hash) do
147-
{_, signed_tx} = :aec_db.find_tx_with_location(tx_hash)
146+
def get_signed_tx(<<_pk::256>> = tx_hash) do
147+
{_block_hash, signed_tx} = :aec_db.find_tx_with_location(tx_hash)
148148
signed_tx
149149
end
150150

@@ -158,7 +158,7 @@ defmodule AeMdw.Node.Db do
158158
def top_height_hash(true = _the_very_top?) do
159159
{type, header} =
160160
case :aec_chain.top_block() do
161-
{:mic_block, header, _txs, _} -> {:micro, header}
161+
{:mic_block, header, _txs, _pof} -> {:micro, header}
162162
{:key_block, header} -> {:key, header}
163163
end
164164

lib/ae_mdw/validate.ex

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ defmodule AeMdw.Validate do
44
alias :aeser_api_encoder, as: Enc
55

66
# returns pubkey
7-
def id(<<_::256>> = id),
7+
def id(<<_pk::256>> = id),
88
do: {:ok, id}
99

10-
def id(<<_prefix::2-binary, "_", _::binary>> = id) do
10+
def id(<<_prefix::2-binary, "_", _pk::binary>> = id) do
1111
try do
1212
{_id_type, pk} = Enc.decode(id)
1313
{:ok, pk}
1414
rescue
15-
_ -> {:error, {ErrInput.Id, id}}
15+
_error -> {:error, {ErrInput.Id, id}}
1616
end
1717
end
1818

19-
def id({:id, _, <<_::256>> = pk}),
19+
def id({:id, _tag, <<_pk::256>> = pk}),
2020
do: {:ok, pk}
2121

2222
def id(id),
2323
do: {:error, {ErrInput.Id, id}}
2424

2525
def id!(id), do: unwrap!(&id/1, id)
2626

27-
def id(<<prefix::2-binary, "_", _::binary>> = ident, [_ | _] = allowed_types) do
27+
def id(<<prefix::2-binary, "_", _pk::binary>> = ident, [_type1 | _rest_types] = allowed_types) do
2828
case prefix in AE.id_prefixes() do
2929
true ->
3030
case Enc.safe_decode({:id_hash, allowed_types}, ident) do
@@ -40,13 +40,13 @@ defmodule AeMdw.Validate do
4040
end
4141
end
4242

43-
def id({:id, hash_type, <<_::256>> = pk} = id, [_ | _] = allowed_types),
43+
def id({:id, hash_type, <<_pk::256>> = pk} = id, [_type1 | _rest_types] = allowed_types),
4444
do: (AE.id_type(hash_type) in allowed_types && {:ok, pk}) || {:error, {ErrInput.Id, id}}
4545

46-
def id(<<_::256>> = pk, [_ | _] = _allowed_types),
46+
def id(<<_pk::256>> = pk, [_type1 | _rest_types] = _allowed_types),
4747
do: {:ok, pk}
4848

49-
def id(id, _),
49+
def id(id, _allowed_types),
5050
do: {:error, {ErrInput.Id, id}}
5151

5252
def id!(id, allowed_types), do: unwrap!(&id(&1, allowed_types), id)
@@ -77,7 +77,7 @@ defmodule AeMdw.Validate do
7777
nil -> {:error, {ErrInput.NotFound, name_ident}}
7878
end
7979

80-
_ ->
80+
_error ->
8181
ok? = is_binary(name_ident) and name_ident != "" and String.printable?(name_ident)
8282

8383
case ok? do
@@ -141,7 +141,7 @@ defmodule AeMdw.Validate do
141141
def nonneg_int(s) when is_binary(s) do
142142
case Integer.parse(s, 10) do
143143
{i, ""} when i >= 0 -> {:ok, i}
144-
_ -> {:error, {ErrInput.NonnegInt, s}}
144+
_error_or_invalid -> {:error, {ErrInput.NonnegInt, s}}
145145
end
146146
end
147147

@@ -155,7 +155,7 @@ defmodule AeMdw.Validate do
155155
map_nni = fn s, f ->
156156
case nonneg_int(s) do
157157
{:ok, i} -> f.(i)
158-
_ -> {:error, {ErrInput.BlockIndex, x}}
158+
_error -> {:error, {ErrInput.BlockIndex, x}}
159159
end
160160
end
161161

@@ -165,14 +165,14 @@ defmodule AeMdw.Validate do
165165
{:ok, mbi} <- map_nni.(mbi, &{:ok, &1}) do
166166
{:ok, {kbi, mbi}}
167167
else
168-
_ ->
168+
_invalid ->
169169
{:error, {ErrInput.BlockIndex, x}}
170170
end
171171

172172
[kbi | rem] when rem in [[], ["-1"]] ->
173173
map_nni.(kbi, &{:ok, {&1, -1}})
174174

175-
_ ->
175+
_invalid ->
176176
{:error, {ErrInput.BlockIndex, x}}
177177
end
178178
end

lib/ae_mdw_web/benchmark/aggregator.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defmodule AeMdwWeb.Benchmark.Aggregator do
2222
end
2323
end
2424

25-
def extract_values([], _, acc), do: acc
25+
def extract_values([], _key, acc), do: acc
2626

2727
def extract_values([h | t], key, acc) do
2828
time = h[key].time

lib/ae_mdw_web/benchmark/bench.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ defmodule Mix.Tasks.Bench do
9090
end)
9191
end
9292

93-
defp percentile([], _), do: nil
94-
defp percentile([x], _), do: x
93+
defp percentile([], _n), do: nil
94+
defp percentile([x], _n), do: x
9595

9696
defp percentile(list, n) when is_list(list) and is_number(n) do
9797
s = Enum.sort(list)
@@ -119,7 +119,7 @@ defmodule Mix.Tasks.Bench do
119119
200, acc ->
120120
%{acc | successful_requests: acc[:successful_requests] + 1}
121121

122-
_, acc ->
122+
_status, acc ->
123123
%{acc | failed_requests: acc[:failed_requests] + 1}
124124
end)
125125
end

test/integration/ae_mdw_web/controllers/util_controller_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule Integration.AeMdwWeb.UtilControllerTest do
1111
test "get middleware status", %{conn: conn} do
1212
state = State.new()
1313
{:ok, top_kb} = :aec_chain.top_key_block()
14-
{_, _, node_vsn} = Application.started_applications() |> List.keyfind(:aecore, 0)
14+
{_app, _desc, node_vsn} = Application.started_applications() |> List.keyfind(:aecore, 0)
1515
node_height = :aec_blocks.height(top_kb)
1616
{:ok, mdw_tx_index} = DbUtil.last_txi(state)
1717

0 commit comments

Comments
 (0)