Skip to content

Commit

Permalink
refactor(fee): factor out originated_account?/1
Browse files Browse the repository at this point in the history
  • Loading branch information
vhf committed May 22, 2024
1 parent a10ff52 commit 07211e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lib/fee.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ defmodule Tezex.Fee do

# size of serialized branch and signature + safe reserve
@extra_size 32 + 64

def extra_size, do: @extra_size

@default_gas_reserve 100

def default_gas_reserve, do: @default_gas_reserve

@spec calculate_fee(map(), pos_integer(),
Expand Down Expand Up @@ -57,7 +55,7 @@ defmodule Tezex.Fee do
@hard_gas_limit_per_operation

"transaction" ->
if String.starts_with?(content["destination"], "KT"),
if originated_account?(content["destination"]),
do: @hard_gas_limit_per_operation,
else: @default_transaction_gas_limit
end
Expand All @@ -75,7 +73,7 @@ defmodule Tezex.Fee do
@hard_storage_limit_per_operation

"transaction" ->
if String.starts_with?(content["destination"], "KT"),
if originated_account?(content["destination"]),
do: @hard_storage_limit_per_operation,
else: @default_transaction_storage_limit

Expand All @@ -84,4 +82,7 @@ defmodule Tezex.Fee do
@hard_storage_limit_per_operation
end
end

defp originated_account?("KT1" <> _), do: true
defp originated_account?(_), do: false
end
6 changes: 2 additions & 4 deletions lib/rpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ defmodule Tezex.Rpc do

content = Map.drop(content, ~w(metadata))

fee =
Fee.calculate_fee(content, gas_limit_new,
extra_size: 1 + div(Fee.extra_size(), number_contents)
)
extra_size = 1 + div(Fee.extra_size(), number_contents)
fee = Fee.calculate_fee(content, gas_limit_new, extra_size: extra_size)

%{
content
Expand Down

0 comments on commit 07211e1

Please sign in to comment.