@@ -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