Skip to content

Commit 7a624ab

Browse files
committed
fix(rpc): return error from get_next_counter_for_account/2
1 parent 245d46c commit 7a624ab

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

lib/forge.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ defmodule Tezex.Forge do
355355
[address, entrypoint] = String.split(value, "%", parts: 2)
356356
address_bytes = forge_address(address)
357357

358-
if entrypoint != nil && entrypoint != "default" do
358+
if entrypoint != "default" do
359359
address_bytes <> entrypoint
360360
else
361361
address_bytes

lib/rpc.ex

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ defmodule Tezex.Rpc do
191191
with {:ok, block_head} <- get_block_at_offset(rpc, offset),
192192
branch = binary_part(block_head["hash"], 0, 51),
193193
protocol = block_head["protocol"],
194-
counter = get_next_counter_for_account(rpc, wallet_address),
194+
{:ok, counter} <- get_next_counter_for_account(rpc, wallet_address),
195195
operation = prepare_operation(transactions, wallet_address, counter, branch),
196196
{:ok, preapplied_operations} <-
197197
preapply_operation(rpc, operation, encoded_private_key, protocol),
@@ -296,9 +296,13 @@ defmodule Tezex.Rpc do
296296
end
297297
end
298298

299-
@spec get_next_counter_for_account(t(), nonempty_binary()) :: integer()
299+
@spec get_next_counter_for_account(t(), nonempty_binary()) ::
300+
{:ok, integer()} | {:error, :not_integer} | {:error, Finch.Error.t()}
300301
def get_next_counter_for_account(%Rpc{} = rpc, address) do
301-
get_counter_for_account(rpc, address) + 1
302+
case get_counter_for_account(rpc, address) do
303+
{:error, _} = err -> err
304+
n -> {:ok, n + 1}
305+
end
302306
end
303307

304308
@spec get_block(t()) ::

0 commit comments

Comments
 (0)