From 93eb06096b5ef266649792ed6e156a0b4c8e23c7 Mon Sep 17 00:00:00 2001 From: Awea Date: Mon, 10 Jun 2024 10:21:06 +0200 Subject: [PATCH] fix(fee): default gas and storage limit --- lib/fee.ex | 8 ++++++-- lib/rpc.ex | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/fee.ex b/lib/fee.ex index 48923dc..dbb71e9 100644 --- a/lib/fee.ex +++ b/lib/fee.ex @@ -3,13 +3,17 @@ defmodule Tezex.Fee do @default_transaction_gas_limit 1451 @default_transaction_storage_limit 257 - @hard_gas_limit_per_operation 1_040_000 - @hard_storage_limit_per_operation 60000 @minimal_fees 100 @minimal_mutez_per_byte 1 @minimal_nanotez_per_gas_unit 100 @reserve 10 + @hard_gas_limit_per_operation 1_040_000 + def hard_gas_limit_per_operation, do: @hard_gas_limit_per_operation + + @hard_storage_limit_per_operation 60000 + def hard_storage_limit_per_operation, do: @hard_storage_limit_per_operation + # size of serialized branch and signature + safe reserve @extra_size 32 + 64 def extra_size, do: @extra_size diff --git a/lib/rpc.ex b/lib/rpc.ex index f976e32..96ba364 100644 --- a/lib/rpc.ex +++ b/lib/rpc.ex @@ -23,15 +23,21 @@ defmodule Tezex.Rpc do @spec prepare_operation(list(op()), nonempty_binary(), integer(), nonempty_binary()) :: op() def prepare_operation(contents, wallet_address, counter, branch) do + hard_gas_limit_per_content = div(Fee.hard_gas_limit_per_operation(), length(contents)) + hard_storage_limit_per_content = div(Fee.hard_storage_limit_per_operation(), length(contents)) + contents = contents |> Enum.with_index(counter) |> Enum.map(fn {content, counter} -> + gas_limit = min(hard_gas_limit_per_content, Fee.default_gas_limit(content)) + storage_limit = min(hard_storage_limit_per_content, Fee.default_storage_limit(content)) + Map.merge(content, %{ "counter" => Integer.to_string(counter), "source" => wallet_address, - "gas_limit" => Integer.to_string(Fee.default_gas_limit(content)), - "storage_limit" => Integer.to_string(Fee.default_storage_limit(content)), + "gas_limit" => Integer.to_string(gas_limit), + "storage_limit" => Integer.to_string(storage_limit), "fee" => "0" }) end)