From dcdf0687e6c1ed25b8a265c812e5e87938eff375 Mon Sep 17 00:00:00 2001 From: victor felder Date: Wed, 22 May 2024 13:46:29 +0200 Subject: [PATCH] refactor(fee): factor out originated_account?/1 --- lib/fee.ex | 9 +++++---- lib/rpc.ex | 6 ++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/fee.ex b/lib/fee.ex index 8e9dbd7..48923dc 100644 --- a/lib/fee.ex +++ b/lib/fee.ex @@ -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(), @@ -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 @@ -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 @@ -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 diff --git a/lib/rpc.ex b/lib/rpc.ex index b72943e..c3686c7 100644 --- a/lib/rpc.ex +++ b/lib/rpc.ex @@ -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