From 4821227eeab34f5b7a7b447f717aaa43e10f9ee6 Mon Sep 17 00:00:00 2001 From: CristhianRodriguezMolina <50219561+CristhianRodriguezMolina@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:01:40 -0500 Subject: [PATCH 1/5] Support stellar contract config settings Co-authored-by: norn --- .../config_setting/config_setting_entry.ex | 6 +- .../config_setting/config_setting_id.ex | 2 +- .../config_setting/contract_cost_type.ex | 49 ++++--- .../state_expiration_settings.ex | 124 +++++++++--------- .../contract_cost_type_test.exs | 22 +--- .../state_expiration_settings_test.exs | 104 +++++++-------- 6 files changed, 146 insertions(+), 161 deletions(-) diff --git a/lib/xdr/contract/config_setting/config_setting_entry.ex b/lib/xdr/contract/config_setting/config_setting_entry.ex index f21e8e7..0102ff3 100644 --- a/lib/xdr/contract/config_setting/config_setting_entry.ex +++ b/lib/xdr/contract/config_setting/config_setting_entry.ex @@ -19,7 +19,7 @@ defmodule StellarBase.XDR.ConfigSettingEntry do ConfigSettingContractEventsV0, ConfigSettingContractBandwidthV0, ContractCostParams, - StateExpirationSettings, + StateArchivalSettings, ConfigSettingContractExecutionLanesV0, UInt64List, EvictionIterator @@ -36,7 +36,7 @@ defmodule StellarBase.XDR.ConfigSettingEntry do CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES: ContractCostParams, CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES: UInt32, CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES: UInt32, - CONFIG_SETTING_STATE_EXPIRATION: StateExpirationSettings, + CONFIG_SETTING_STATE_ARCHIVAL: StateArchivalSettings, CONFIG_SETTING_CONTRACT_EXECUTION_LANES: ConfigSettingContractExecutionLanesV0, CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW: UInt64List, CONFIG_SETTING_EVICTION_ITERATOR: EvictionIterator @@ -50,7 +50,7 @@ defmodule StellarBase.XDR.ConfigSettingEntry do | ConfigSettingContractEventsV0.t() | ConfigSettingContractBandwidthV0.t() | ContractCostParams.t() - | StateExpirationSettings.t() + | StateArchivalSettings.t() | ConfigSettingContractExecutionLanesV0.t() | UInt64List.t() | EvictionIterator.t() diff --git a/lib/xdr/contract/config_setting/config_setting_id.ex b/lib/xdr/contract/config_setting/config_setting_id.ex index d1defb9..215f6f9 100644 --- a/lib/xdr/contract/config_setting/config_setting_id.ex +++ b/lib/xdr/contract/config_setting/config_setting_id.ex @@ -21,7 +21,7 @@ defmodule StellarBase.XDR.ConfigSettingID do CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES: 7, CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES: 8, CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES: 9, - CONFIG_SETTING_STATE_EXPIRATION: 10, + CONFIG_SETTING_STATE_ARCHIVAL: 10, CONFIG_SETTING_CONTRACT_EXECUTION_LANES: 11, CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW: 12, CONFIG_SETTING_EVICTION_ITERATOR: 13 diff --git a/lib/xdr/contract/config_setting/contract_cost_type.ex b/lib/xdr/contract/config_setting/contract_cost_type.ex index 5106b72..5c84ba0 100644 --- a/lib/xdr/contract/config_setting/contract_cost_type.ex +++ b/lib/xdr/contract/config_setting/contract_cost_type.ex @@ -12,33 +12,28 @@ defmodule StellarBase.XDR.ContractCostType do @declarations [ WasmInsnExec: 0, - WasmMemAlloc: 1, - HostMemAlloc: 2, - HostMemCpy: 3, - HostMemCmp: 4, - DispatchHostFunction: 5, - VisitObject: 6, - ValSer: 7, - ValDeser: 8, - ComputeSha256Hash: 9, - ComputeEd25519PubKey: 10, - MapEntry: 11, - VecEntry: 12, - VerifyEd25519Sig: 13, - VmMemRead: 14, - VmMemWrite: 15, - VmInstantiation: 16, - VmCachedInstantiation: 17, - InvokeVmFunction: 18, - ComputeKeccak256Hash: 19, - ComputeEcdsaSecp256k1Key: 20, - ComputeEcdsaSecp256k1Sig: 21, - RecoverEcdsaSecp256k1Key: 22, - Int256AddSub: 23, - Int256Mul: 24, - Int256Div: 25, - Int256Pow: 26, - Int256Shift: 27 + MemAlloc: 1, + MemCpy: 2, + MemCmp: 3, + DispatchHostFunction: 4, + VisitObject: 5, + ValSer: 6, + ValDeser: 7, + ComputeSha256Hash: 8, + ComputeEd25519PubKey: 9, + VerifyEd25519Sig: 10, + VmInstantiation: 11, + VmCachedInstantiation: 12, + InvokeVmFunction: 13, + ComputeKeccak256Hash: 14, + ComputeEcdsaSecp256k1Sig: 15, + RecoverEcdsaSecp256k1Key: 16, + Int256AddSub: 17, + Int256Mul: 18, + Int256Div: 19, + Int256Pow: 20, + Int256Shift: 21, + ChaCha20DrawBytes: 22 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} diff --git a/lib/xdr/contract/config_setting/state_expiration_settings.ex b/lib/xdr/contract/config_setting/state_expiration_settings.ex index 2131e1b..067f3b1 100644 --- a/lib/xdr/contract/config_setting/state_expiration_settings.ex +++ b/lib/xdr/contract/config_setting/state_expiration_settings.ex @@ -1,11 +1,11 @@ -defmodule StellarBase.XDR.StateExpirationSettings do +defmodule StellarBase.XDR.StateArchivalSettings do @moduledoc """ Automatically generated by xdrgen DO NOT EDIT or your changes may be overwritten Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - Representation of Stellar `StateExpirationSettings` type. + Representation of Stellar `StateArchivalSettings` type. """ @behaviour XDR.Declaration @@ -17,80 +17,80 @@ defmodule StellarBase.XDR.StateExpirationSettings do } @struct_spec XDR.Struct.new( - max_entry_expiration: UInt32, - min_temp_entry_expiration: UInt32, - min_persistent_entry_expiration: UInt32, + max_entry_ttl: UInt32, + min_temporary_ttl: UInt32, + min_persistent_ttl: UInt32, persistent_rent_rate_denominator: Int64, temp_rent_rate_denominator: Int64, - max_entries_to_expire: UInt32, + max_entries_to_archive: UInt32, bucket_list_size_window_sample_size: UInt32, eviction_scan_size: UInt64, starting_eviction_scan_level: UInt32 ) - @type max_entry_expiration_type :: UInt32.t() - @type min_temp_entry_expiration_type :: UInt32.t() - @type min_persistent_entry_expiration_type :: UInt32.t() + @type max_entry_ttl_type :: UInt32.t() + @type min_temporary_ttl_type :: UInt32.t() + @type min_persistent_ttl_type :: UInt32.t() @type persistent_rent_rate_denominator_type :: Int64.t() @type temp_rent_rate_denominator_type :: Int64.t() - @type max_entries_to_expire_type :: UInt32.t() + @type max_entries_to_archive_type :: UInt32.t() @type bucket_list_size_window_sample_size_type :: UInt32.t() @type eviction_scan_size_type :: UInt64.t() @type starting_eviction_scan_level_type :: UInt32.t() @type t :: %__MODULE__{ - max_entry_expiration: max_entry_expiration_type(), - min_temp_entry_expiration: min_temp_entry_expiration_type(), - min_persistent_entry_expiration: min_persistent_entry_expiration_type(), + max_entry_ttl: max_entry_ttl_type(), + min_temporary_ttl: min_temporary_ttl_type(), + min_persistent_ttl: min_persistent_ttl_type(), persistent_rent_rate_denominator: persistent_rent_rate_denominator_type(), temp_rent_rate_denominator: temp_rent_rate_denominator_type(), - max_entries_to_expire: max_entries_to_expire_type(), + max_entries_to_archive: max_entries_to_archive_type(), bucket_list_size_window_sample_size: bucket_list_size_window_sample_size_type(), eviction_scan_size: eviction_scan_size_type(), starting_eviction_scan_level: starting_eviction_scan_level_type() } defstruct [ - :max_entry_expiration, - :min_temp_entry_expiration, - :min_persistent_entry_expiration, + :max_entry_ttl, + :min_temporary_ttl, + :min_persistent_ttl, :persistent_rent_rate_denominator, :temp_rent_rate_denominator, - :max_entries_to_expire, + :max_entries_to_archive, :bucket_list_size_window_sample_size, :eviction_scan_size, :starting_eviction_scan_level ] @spec new( - max_entry_expiration :: max_entry_expiration_type(), - min_temp_entry_expiration :: min_temp_entry_expiration_type(), - min_persistent_entry_expiration :: min_persistent_entry_expiration_type(), + max_entry_ttl :: max_entry_ttl_type(), + min_temporary_ttl :: min_temporary_ttl_type(), + min_persistent_ttl :: min_persistent_ttl_type(), persistent_rent_rate_denominator :: persistent_rent_rate_denominator_type(), temp_rent_rate_denominator :: temp_rent_rate_denominator_type(), - max_entries_to_expire :: max_entries_to_expire_type(), + max_entries_to_archive :: max_entries_to_archive_type(), bucket_list_size_window_sample_size :: bucket_list_size_window_sample_size_type(), eviction_scan_size :: eviction_scan_size_type(), starting_eviction_scan_level :: starting_eviction_scan_level_type() ) :: t() def new( - %UInt32{} = max_entry_expiration, - %UInt32{} = min_temp_entry_expiration, - %UInt32{} = min_persistent_entry_expiration, + %UInt32{} = max_entry_ttl, + %UInt32{} = min_temporary_ttl, + %UInt32{} = min_persistent_ttl, %Int64{} = persistent_rent_rate_denominator, %Int64{} = temp_rent_rate_denominator, - %UInt32{} = max_entries_to_expire, + %UInt32{} = max_entries_to_archive, %UInt32{} = bucket_list_size_window_sample_size, %UInt64{} = eviction_scan_size, %UInt32{} = starting_eviction_scan_level ), do: %__MODULE__{ - max_entry_expiration: max_entry_expiration, - min_temp_entry_expiration: min_temp_entry_expiration, - min_persistent_entry_expiration: min_persistent_entry_expiration, + max_entry_ttl: max_entry_ttl, + min_temporary_ttl: min_temporary_ttl, + min_persistent_ttl: min_persistent_ttl, persistent_rent_rate_denominator: persistent_rent_rate_denominator, temp_rent_rate_denominator: temp_rent_rate_denominator, - max_entries_to_expire: max_entries_to_expire, + max_entries_to_archive: max_entries_to_archive, bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, eviction_scan_size: eviction_scan_size, starting_eviction_scan_level: starting_eviction_scan_level @@ -98,23 +98,23 @@ defmodule StellarBase.XDR.StateExpirationSettings do @impl true def encode_xdr(%__MODULE__{ - max_entry_expiration: max_entry_expiration, - min_temp_entry_expiration: min_temp_entry_expiration, - min_persistent_entry_expiration: min_persistent_entry_expiration, + max_entry_ttl: max_entry_ttl, + min_temporary_ttl: min_temporary_ttl, + min_persistent_ttl: min_persistent_ttl, persistent_rent_rate_denominator: persistent_rent_rate_denominator, temp_rent_rate_denominator: temp_rent_rate_denominator, - max_entries_to_expire: max_entries_to_expire, + max_entries_to_archive: max_entries_to_archive, bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, eviction_scan_size: eviction_scan_size, starting_eviction_scan_level: starting_eviction_scan_level }) do [ - max_entry_expiration: max_entry_expiration, - min_temp_entry_expiration: min_temp_entry_expiration, - min_persistent_entry_expiration: min_persistent_entry_expiration, + max_entry_ttl: max_entry_ttl, + min_temporary_ttl: min_temporary_ttl, + min_persistent_ttl: min_persistent_ttl, persistent_rent_rate_denominator: persistent_rent_rate_denominator, temp_rent_rate_denominator: temp_rent_rate_denominator, - max_entries_to_expire: max_entries_to_expire, + max_entries_to_archive: max_entries_to_archive, bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, eviction_scan_size: eviction_scan_size, starting_eviction_scan_level: starting_eviction_scan_level @@ -125,23 +125,23 @@ defmodule StellarBase.XDR.StateExpirationSettings do @impl true def encode_xdr!(%__MODULE__{ - max_entry_expiration: max_entry_expiration, - min_temp_entry_expiration: min_temp_entry_expiration, - min_persistent_entry_expiration: min_persistent_entry_expiration, + max_entry_ttl: max_entry_ttl, + min_temporary_ttl: min_temporary_ttl, + min_persistent_ttl: min_persistent_ttl, persistent_rent_rate_denominator: persistent_rent_rate_denominator, temp_rent_rate_denominator: temp_rent_rate_denominator, - max_entries_to_expire: max_entries_to_expire, + max_entries_to_archive: max_entries_to_archive, bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, eviction_scan_size: eviction_scan_size, starting_eviction_scan_level: starting_eviction_scan_level }) do [ - max_entry_expiration: max_entry_expiration, - min_temp_entry_expiration: min_temp_entry_expiration, - min_persistent_entry_expiration: min_persistent_entry_expiration, + max_entry_ttl: max_entry_ttl, + min_temporary_ttl: min_temporary_ttl, + min_persistent_ttl: min_persistent_ttl, persistent_rent_rate_denominator: persistent_rent_rate_denominator, temp_rent_rate_denominator: temp_rent_rate_denominator, - max_entries_to_expire: max_entries_to_expire, + max_entries_to_archive: max_entries_to_archive, bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, eviction_scan_size: eviction_scan_size, starting_eviction_scan_level: starting_eviction_scan_level @@ -158,12 +158,12 @@ defmodule StellarBase.XDR.StateExpirationSettings do {:ok, {%XDR.Struct{ components: [ - max_entry_expiration: max_entry_expiration, - min_temp_entry_expiration: min_temp_entry_expiration, - min_persistent_entry_expiration: min_persistent_entry_expiration, + max_entry_ttl: max_entry_ttl, + min_temporary_ttl: min_temporary_ttl, + min_persistent_ttl: min_persistent_ttl, persistent_rent_rate_denominator: persistent_rent_rate_denominator, temp_rent_rate_denominator: temp_rent_rate_denominator, - max_entries_to_expire: max_entries_to_expire, + max_entries_to_archive: max_entries_to_archive, bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, eviction_scan_size: eviction_scan_size, starting_eviction_scan_level: starting_eviction_scan_level @@ -171,12 +171,12 @@ defmodule StellarBase.XDR.StateExpirationSettings do }, rest}} -> {:ok, {new( - max_entry_expiration, - min_temp_entry_expiration, - min_persistent_entry_expiration, + max_entry_ttl, + min_temporary_ttl, + min_persistent_ttl, persistent_rent_rate_denominator, temp_rent_rate_denominator, - max_entries_to_expire, + max_entries_to_archive, bucket_list_size_window_sample_size, eviction_scan_size, starting_eviction_scan_level @@ -193,12 +193,12 @@ defmodule StellarBase.XDR.StateExpirationSettings do def decode_xdr!(bytes, struct) do {%XDR.Struct{ components: [ - max_entry_expiration: max_entry_expiration, - min_temp_entry_expiration: min_temp_entry_expiration, - min_persistent_entry_expiration: min_persistent_entry_expiration, + max_entry_ttl: max_entry_ttl, + min_temporary_ttl: min_temporary_ttl, + min_persistent_ttl: min_persistent_ttl, persistent_rent_rate_denominator: persistent_rent_rate_denominator, temp_rent_rate_denominator: temp_rent_rate_denominator, - max_entries_to_expire: max_entries_to_expire, + max_entries_to_archive: max_entries_to_archive, bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, eviction_scan_size: eviction_scan_size, starting_eviction_scan_level: starting_eviction_scan_level @@ -206,12 +206,12 @@ defmodule StellarBase.XDR.StateExpirationSettings do }, rest} = XDR.Struct.decode_xdr!(bytes, struct) {new( - max_entry_expiration, - min_temp_entry_expiration, - min_persistent_entry_expiration, + max_entry_ttl, + min_temporary_ttl, + min_persistent_ttl, persistent_rent_rate_denominator, temp_rent_rate_denominator, - max_entries_to_expire, + max_entries_to_archive, bucket_list_size_window_sample_size, eviction_scan_size, starting_eviction_scan_level diff --git a/test/xdr/contract/config_setting/contract_cost_type_test.exs b/test/xdr/contract/config_setting/contract_cost_type_test.exs index 519691b..4f5e4dc 100644 --- a/test/xdr/contract/config_setting/contract_cost_type_test.exs +++ b/test/xdr/contract/config_setting/contract_cost_type_test.exs @@ -5,33 +5,28 @@ defmodule StellarBase.XDR.ContractCostTypeTest do @codes [ :WasmInsnExec, - :WasmMemAlloc, - :HostMemAlloc, - :HostMemCpy, - :HostMemCmp, + :MemAlloc, + :MemCpy, + :MemCmp, :DispatchHostFunction, :VisitObject, :ValSer, :ValDeser, :ComputeSha256Hash, :ComputeEd25519PubKey, - :MapEntry, - :VecEntry, :VerifyEd25519Sig, - :VmMemRead, - :VmMemWrite, :VmInstantiation, :VmCachedInstantiation, :InvokeVmFunction, :ComputeKeccak256Hash, - :ComputeEcdsaSecp256k1Key, :ComputeEcdsaSecp256k1Sig, :RecoverEcdsaSecp256k1Key, :Int256AddSub, :Int256Mul, :Int256Div, :Int256Pow, - :Int256Shift + :Int256Shift, + :ChaCha20DrawBytes ] @binaries [ @@ -57,12 +52,7 @@ defmodule StellarBase.XDR.ContractCostTypeTest do <<0, 0, 0, 19>>, <<0, 0, 0, 20>>, <<0, 0, 0, 21>>, - <<0, 0, 0, 22>>, - <<0, 0, 0, 23>>, - <<0, 0, 0, 24>>, - <<0, 0, 0, 25>>, - <<0, 0, 0, 26>>, - <<0, 0, 0, 27>> + <<0, 0, 0, 22>> ] describe "ContractCostType" do diff --git a/test/xdr/contract/config_setting/state_expiration_settings_test.exs b/test/xdr/contract/config_setting/state_expiration_settings_test.exs index f1ccd29..83977a6 100644 --- a/test/xdr/contract/config_setting/state_expiration_settings_test.exs +++ b/test/xdr/contract/config_setting/state_expiration_settings_test.exs @@ -1,21 +1,21 @@ -defmodule StellarBase.XDR.StateExpirationSettingsTest do +defmodule StellarBase.XDR.StateArchivalSettingsTest do use ExUnit.Case alias StellarBase.XDR.{ - StateExpirationSettings, + StateArchivalSettings, UInt32, Int64, UInt64 } setup do - max_entry_expiration = UInt32.new(100) - min_temp_entry_expiration = UInt32.new(50) - min_persistent_entry_expiration = UInt32.new(60) + max_entry_ttl = UInt32.new(100) + min_temporary_ttl = UInt32.new(50) + min_persistent_ttl = UInt32.new(60) starting_eviction_scan_level = UInt32.new(5) persistent_rent_rate_denominator = Int64.new(100) temp_rent_rate_denominator = Int64.new(200) - max_entries_to_expire = UInt32.new(500) + max_entries_to_archive = UInt32.new(500) bucket_list_size_window_sample_size = UInt32.new(1000) eviction_scan_size = UInt64.new(5000) @@ -24,26 +24,26 @@ defmodule StellarBase.XDR.StateExpirationSettingsTest do 200, 0, 0, 1, 244, 0, 0, 3, 232, 0, 0, 0, 0, 0, 0, 19, 136, 0, 0, 0, 5>> state_expiration_settings = - StateExpirationSettings.new( - max_entry_expiration, - min_temp_entry_expiration, - min_persistent_entry_expiration, + StateArchivalSettings.new( + max_entry_ttl, + min_temporary_ttl, + min_persistent_ttl, persistent_rent_rate_denominator, temp_rent_rate_denominator, - max_entries_to_expire, + max_entries_to_archive, bucket_list_size_window_sample_size, eviction_scan_size, starting_eviction_scan_level ) %{ - max_entry_expiration: max_entry_expiration, - min_temp_entry_expiration: min_temp_entry_expiration, - min_persistent_entry_expiration: min_persistent_entry_expiration, + max_entry_ttl: max_entry_ttl, + min_temporary_ttl: min_temporary_ttl, + min_persistent_ttl: min_persistent_ttl, starting_eviction_scan_level: starting_eviction_scan_level, persistent_rent_rate_denominator: persistent_rent_rate_denominator, temp_rent_rate_denominator: temp_rent_rate_denominator, - max_entries_to_expire: max_entries_to_expire, + max_entries_to_archive: max_entries_to_archive, bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, eviction_scan_size: eviction_scan_size, binary: binary, @@ -52,34 +52,34 @@ defmodule StellarBase.XDR.StateExpirationSettingsTest do end test "new/1", %{ - max_entry_expiration: max_entry_expiration, - min_temp_entry_expiration: min_temp_entry_expiration, - min_persistent_entry_expiration: min_persistent_entry_expiration, + max_entry_ttl: max_entry_ttl, + min_temporary_ttl: min_temporary_ttl, + min_persistent_ttl: min_persistent_ttl, starting_eviction_scan_level: starting_eviction_scan_level, persistent_rent_rate_denominator: persistent_rent_rate_denominator, temp_rent_rate_denominator: temp_rent_rate_denominator, - max_entries_to_expire: max_entries_to_expire, + max_entries_to_archive: max_entries_to_archive, bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, eviction_scan_size: eviction_scan_size } do - %StateExpirationSettings{ - max_entry_expiration: ^max_entry_expiration, - min_temp_entry_expiration: ^min_temp_entry_expiration, - min_persistent_entry_expiration: ^min_persistent_entry_expiration, + %StateArchivalSettings{ + max_entry_ttl: ^max_entry_ttl, + min_temporary_ttl: ^min_temporary_ttl, + min_persistent_ttl: ^min_persistent_ttl, persistent_rent_rate_denominator: ^persistent_rent_rate_denominator, temp_rent_rate_denominator: ^temp_rent_rate_denominator, - max_entries_to_expire: ^max_entries_to_expire, + max_entries_to_archive: ^max_entries_to_archive, bucket_list_size_window_sample_size: ^bucket_list_size_window_sample_size, eviction_scan_size: ^eviction_scan_size, starting_eviction_scan_level: ^starting_eviction_scan_level } = - StateExpirationSettings.new( - max_entry_expiration, - min_temp_entry_expiration, - min_persistent_entry_expiration, + StateArchivalSettings.new( + max_entry_ttl, + min_temporary_ttl, + min_persistent_ttl, persistent_rent_rate_denominator, temp_rent_rate_denominator, - max_entries_to_expire, + max_entries_to_archive, bucket_list_size_window_sample_size, eviction_scan_size, starting_eviction_scan_level @@ -88,67 +88,67 @@ defmodule StellarBase.XDR.StateExpirationSettingsTest do test "encode_xdr/1", %{ binary: binary, - max_entry_expiration: max_entry_expiration, - min_temp_entry_expiration: min_temp_entry_expiration, - min_persistent_entry_expiration: min_persistent_entry_expiration, + max_entry_ttl: max_entry_ttl, + min_temporary_ttl: min_temporary_ttl, + min_persistent_ttl: min_persistent_ttl, starting_eviction_scan_level: starting_eviction_scan_level, persistent_rent_rate_denominator: persistent_rent_rate_denominator, temp_rent_rate_denominator: temp_rent_rate_denominator, - max_entries_to_expire: max_entries_to_expire, + max_entries_to_archive: max_entries_to_archive, bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, eviction_scan_size: eviction_scan_size } do {:ok, ^binary} = - StateExpirationSettings.new( - max_entry_expiration, - min_temp_entry_expiration, - min_persistent_entry_expiration, + StateArchivalSettings.new( + max_entry_ttl, + min_temporary_ttl, + min_persistent_ttl, persistent_rent_rate_denominator, temp_rent_rate_denominator, - max_entries_to_expire, + max_entries_to_archive, bucket_list_size_window_sample_size, eviction_scan_size, starting_eviction_scan_level ) - |> StateExpirationSettings.encode_xdr() + |> StateArchivalSettings.encode_xdr() end test "encode_xdr!/1", %{ binary: binary, - max_entry_expiration: max_entry_expiration, - min_temp_entry_expiration: min_temp_entry_expiration, - min_persistent_entry_expiration: min_persistent_entry_expiration, + max_entry_ttl: max_entry_ttl, + min_temporary_ttl: min_temporary_ttl, + min_persistent_ttl: min_persistent_ttl, starting_eviction_scan_level: starting_eviction_scan_level, persistent_rent_rate_denominator: persistent_rent_rate_denominator, temp_rent_rate_denominator: temp_rent_rate_denominator, - max_entries_to_expire: max_entries_to_expire, + max_entries_to_archive: max_entries_to_archive, bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, eviction_scan_size: eviction_scan_size } do ^binary = - StateExpirationSettings.new( - max_entry_expiration, - min_temp_entry_expiration, - min_persistent_entry_expiration, + StateArchivalSettings.new( + max_entry_ttl, + min_temporary_ttl, + min_persistent_ttl, persistent_rent_rate_denominator, temp_rent_rate_denominator, - max_entries_to_expire, + max_entries_to_archive, bucket_list_size_window_sample_size, eviction_scan_size, starting_eviction_scan_level ) - |> StateExpirationSettings.encode_xdr!() + |> StateArchivalSettings.encode_xdr!() end test "decode_xdr/2", %{binary: binary, state_expiration_settings: state_expiration_settings} do - {:ok, {^state_expiration_settings, ""}} = StateExpirationSettings.decode_xdr(binary) + {:ok, {^state_expiration_settings, ""}} = StateArchivalSettings.decode_xdr(binary) end test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = StateExpirationSettings.decode_xdr(123) + {:error, :not_binary} = StateArchivalSettings.decode_xdr(123) end test "decode_xdr!/2", %{binary: binary, state_expiration_settings: state_expiration_settings} do - {^state_expiration_settings, ^binary} = StateExpirationSettings.decode_xdr!(binary <> binary) + {^state_expiration_settings, ^binary} = StateArchivalSettings.decode_xdr!(binary <> binary) end end From 8e028324fd4d31c517765cc8a284d84b25084df3 Mon Sep 17 00:00:00 2001 From: CristhianRodriguezMolina <50219561+CristhianRodriguezMolina@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:05:59 -0500 Subject: [PATCH 2/5] Support stellar contract Co-authored-by: norn --- lib/xdr/contract/contract_executable.ex | 2 +- lib/xdr/contract/contract_executable_type.ex | 2 +- test/xdr/contract/contract_executable_test.exs | 2 +- test/xdr/contract/contract_executable_type_test.exs | 8 ++++---- test/xdr/contract/sc_contract_instance_test.exs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/xdr/contract/contract_executable.ex b/lib/xdr/contract/contract_executable.ex index da324e3..da136b1 100644 --- a/lib/xdr/contract/contract_executable.ex +++ b/lib/xdr/contract/contract_executable.ex @@ -18,7 +18,7 @@ defmodule StellarBase.XDR.ContractExecutable do @arms [ CONTRACT_EXECUTABLE_WASM: Hash, - CONTRACT_EXECUTABLE_TOKEN: Void + CONTRACT_EXECUTABLE_STELLAR_ASSET: Void ] @type value :: diff --git a/lib/xdr/contract/contract_executable_type.ex b/lib/xdr/contract/contract_executable_type.ex index 056c180..54a424f 100644 --- a/lib/xdr/contract/contract_executable_type.ex +++ b/lib/xdr/contract/contract_executable_type.ex @@ -12,7 +12,7 @@ defmodule StellarBase.XDR.ContractExecutableType do @declarations [ CONTRACT_EXECUTABLE_WASM: 0, - CONTRACT_EXECUTABLE_TOKEN: 1 + CONTRACT_EXECUTABLE_STELLAR_ASSET: 1 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} diff --git a/test/xdr/contract/contract_executable_test.exs b/test/xdr/contract/contract_executable_test.exs index 6a1839d..7e3e38b 100644 --- a/test/xdr/contract/contract_executable_test.exs +++ b/test/xdr/contract/contract_executable_test.exs @@ -21,7 +21,7 @@ defmodule StellarBase.XDR.ContractExecutableTest do wasm_value = Hash.new(binary_wasm) token_value = Void.new() wasm_type = %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_WASM} - token_type = %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_TOKEN} + token_type = %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_STELLAR_ASSET} contract_executable_wasm = ContractExecutable.new(wasm_value, wasm_type) contract_executable_token = ContractExecutable.new(token_value, token_type) diff --git a/test/xdr/contract/contract_executable_type_test.exs b/test/xdr/contract/contract_executable_type_test.exs index 8f06207..7a996ef 100644 --- a/test/xdr/contract/contract_executable_type_test.exs +++ b/test/xdr/contract/contract_executable_type_test.exs @@ -6,13 +6,13 @@ defmodule StellarBase.XDR.ContractExecutableTypeTest do setup do %{ wasm: :CONTRACT_EXECUTABLE_WASM, - token: :CONTRACT_EXECUTABLE_TOKEN, + token: :CONTRACT_EXECUTABLE_STELLAR_ASSET, binary_wasm: <<0, 0, 0, 0>>, binary_token: <<0, 0, 0, 1>>, wasm_identifier: :CONTRACT_EXECUTABLE_WASM, - token_identifier: :CONTRACT_EXECUTABLE_TOKEN, + token_identifier: :CONTRACT_EXECUTABLE_STELLAR_ASSET, wasm_type: %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_WASM}, - token_type: %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_TOKEN} + token_type: %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_STELLAR_ASSET} } end @@ -23,7 +23,7 @@ defmodule StellarBase.XDR.ContractExecutableTypeTest do test "new/1 with token identifier", %{token_identifier: token_identifier} do %ContractExecutableType{identifier: ^token_identifier} = - ContractExecutableType.new(:CONTRACT_EXECUTABLE_TOKEN) + ContractExecutableType.new(:CONTRACT_EXECUTABLE_STELLAR_ASSET) end test "encode_xdr/1 with wasm identifier", %{binary_wasm: binary_wasm, wasm_type: wasm_type} do diff --git a/test/xdr/contract/sc_contract_instance_test.exs b/test/xdr/contract/sc_contract_instance_test.exs index b1c2625..1d35f8b 100644 --- a/test/xdr/contract/sc_contract_instance_test.exs +++ b/test/xdr/contract/sc_contract_instance_test.exs @@ -23,7 +23,7 @@ defmodule StellarBase.XDR.SCContractInstanceTest do wasm_value = Hash.new(binary_wasm) token_value = Void.new() wasm_type = %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_WASM} - token_type = %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_TOKEN} + token_type = %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_STELLAR_ASSET} contract_executable_wasm = ContractExecutable.new(wasm_value, wasm_type) contract_executable_token = ContractExecutable.new(token_value, token_type) From 677bcdc6c8f9d74e587be74fb51b05e5d23015d7 Mon Sep 17 00:00:00 2001 From: CristhianRodriguezMolina <50219561+CristhianRodriguezMolina@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:22:57 -0500 Subject: [PATCH 3/5] Support stellar ledger entries and update file names Co-authored-by: norn --- ...settings.ex => state_archival_settings.ex} | 0 lib/xdr/ledger_entries/expiration_entry.ex | 78 ------------------- lib/xdr/ledger_entries/ledger_entry_data.ex | 6 +- lib/xdr/ledger_entries/ledger_entry_type.ex | 2 +- lib/xdr/ledger_entries/ledger_key.ex | 6 +- ...er_key_expiration.ex => ledger_key_ttl.ex} | 4 +- lib/xdr/ledger_entries/ttl_entry.ex | 78 +++++++++++++++++++ ...t.exs => state_archival_settings_test.exs} | 0 .../ledger_entries/ledger_entry_type_test.exs | 7 +- ...ation_test.exs => ledger_key_ttl_test.exs} | 20 ++--- ...tion_entry_test.exs => ttl_entry_test.exs} | 30 +++---- 11 files changed, 117 insertions(+), 114 deletions(-) rename lib/xdr/contract/config_setting/{state_expiration_settings.ex => state_archival_settings.ex} (100%) delete mode 100644 lib/xdr/ledger_entries/expiration_entry.ex rename lib/xdr/ledger_entries/{ledger_key_expiration.ex => ledger_key_ttl.ex} (92%) create mode 100644 lib/xdr/ledger_entries/ttl_entry.ex rename test/xdr/contract/config_setting/{state_expiration_settings_test.exs => state_archival_settings_test.exs} (100%) rename test/xdr/ledger_entries/{ledger_key_expiration_test.exs => ledger_key_ttl_test.exs} (51%) rename test/xdr/ledger_entries/{expiration_entry_test.exs => ttl_entry_test.exs} (50%) diff --git a/lib/xdr/contract/config_setting/state_expiration_settings.ex b/lib/xdr/contract/config_setting/state_archival_settings.ex similarity index 100% rename from lib/xdr/contract/config_setting/state_expiration_settings.ex rename to lib/xdr/contract/config_setting/state_archival_settings.ex diff --git a/lib/xdr/ledger_entries/expiration_entry.ex b/lib/xdr/ledger_entries/expiration_entry.ex deleted file mode 100644 index c40c532..0000000 --- a/lib/xdr/ledger_entries/expiration_entry.ex +++ /dev/null @@ -1,78 +0,0 @@ -defmodule StellarBase.XDR.ExpirationEntry do - @moduledoc """ - Automatically generated by xdrgen - DO NOT EDIT or your changes may be overwritten - Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - Representation of Stellar `ExpirationEntry` type. - """ - - @behaviour XDR.Declaration - - alias StellarBase.XDR.{ - Hash, - UInt32 - } - - @struct_spec XDR.Struct.new( - key_hash: Hash, - expiration_ledger_seq: UInt32 - ) - - @type key_hash_type :: Hash.t() - @type expiration_ledger_seq_type :: UInt32.t() - - @type t :: %__MODULE__{ - key_hash: key_hash_type(), - expiration_ledger_seq: expiration_ledger_seq_type() - } - - defstruct [:key_hash, :expiration_ledger_seq] - - @spec new(key_hash :: key_hash_type(), expiration_ledger_seq :: expiration_ledger_seq_type()) :: - t() - def new( - %Hash{} = key_hash, - %UInt32{} = expiration_ledger_seq - ), - do: %__MODULE__{key_hash: key_hash, expiration_ledger_seq: expiration_ledger_seq} - - @impl true - def encode_xdr(%__MODULE__{key_hash: key_hash, expiration_ledger_seq: expiration_ledger_seq}) do - [key_hash: key_hash, expiration_ledger_seq: expiration_ledger_seq] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{key_hash: key_hash, expiration_ledger_seq: expiration_ledger_seq}) do - [key_hash: key_hash, expiration_ledger_seq: expiration_ledger_seq] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, struct \\ @struct_spec) - - def decode_xdr(bytes, struct) do - case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, - {%XDR.Struct{ - components: [key_hash: key_hash, expiration_ledger_seq: expiration_ledger_seq] - }, rest}} -> - {:ok, {new(key_hash, expiration_ledger_seq), rest}} - - error -> - error - end - end - - @impl true - def decode_xdr!(bytes, struct \\ @struct_spec) - - def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [key_hash: key_hash, expiration_ledger_seq: expiration_ledger_seq]}, - rest} = XDR.Struct.decode_xdr!(bytes, struct) - - {new(key_hash, expiration_ledger_seq), rest} - end -end diff --git a/lib/xdr/ledger_entries/ledger_entry_data.ex b/lib/xdr/ledger_entries/ledger_entry_data.ex index 4331659..b65b43c 100644 --- a/lib/xdr/ledger_entries/ledger_entry_data.ex +++ b/lib/xdr/ledger_entries/ledger_entry_data.ex @@ -16,7 +16,7 @@ defmodule StellarBase.XDR.LedgerEntryData do ClaimableBalanceEntry, LiquidityPoolEntry, LedgerEntryType, - ExpirationEntry + TTLEntry } @behaviour XDR.Declaration @@ -31,7 +31,7 @@ defmodule StellarBase.XDR.LedgerEntryData do CONTRACT_DATA: ContractDataEntry, CONTRACT_CODE: ContractCodeEntry, CONFIG_SETTING: ConfigSettingEntry, - EXPIRATION: ExpirationEntry + TTL: TTLEntry ] @type entry :: @@ -44,7 +44,7 @@ defmodule StellarBase.XDR.LedgerEntryData do | ContractDataEntry.t() | ContractCodeEntry.t() | ConfigSettingEntry.t() - | ExpirationEntry.t() + | TTLEntry.t() @type t :: %__MODULE__{entry: entry(), type: LedgerEntryType.t()} diff --git a/lib/xdr/ledger_entries/ledger_entry_type.ex b/lib/xdr/ledger_entries/ledger_entry_type.ex index dc15d95..4fb8750 100644 --- a/lib/xdr/ledger_entries/ledger_entry_type.ex +++ b/lib/xdr/ledger_entries/ledger_entry_type.ex @@ -15,7 +15,7 @@ defmodule StellarBase.XDR.LedgerEntryType do CONTRACT_DATA: 6, CONTRACT_CODE: 7, CONFIG_SETTING: 8, - EXPIRATION: 9 + TTL: 9 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} diff --git a/lib/xdr/ledger_entries/ledger_key.ex b/lib/xdr/ledger_entries/ledger_key.ex index af047c3..e2305e4 100644 --- a/lib/xdr/ledger_entries/ledger_key.ex +++ b/lib/xdr/ledger_entries/ledger_key.ex @@ -15,7 +15,7 @@ defmodule StellarBase.XDR.LedgerKey do LedgerKeyContractData, LedgerKeyContractCode, LedgerKeyConfigSetting, - LedgerKeyExpiration + LedgerKeyTTL } @behaviour XDR.Declaration @@ -30,7 +30,7 @@ defmodule StellarBase.XDR.LedgerKey do CONTRACT_DATA: LedgerKeyContractData, CONTRACT_CODE: LedgerKeyContractCode, CONFIG_SETTING: LedgerKeyConfigSetting, - EXPIRATION: LedgerKeyExpiration + TTL: LedgerKeyTTL ] @type entry :: @@ -43,7 +43,7 @@ defmodule StellarBase.XDR.LedgerKey do | LedgerKeyContractData.t() | LedgerKeyContractCode.t() | LedgerKeyConfigSetting.t() - | LedgerKeyExpiration.t() + | LedgerKeyTTL.t() @type t :: %__MODULE__{entry: entry(), type: LedgerEntryType.t()} diff --git a/lib/xdr/ledger_entries/ledger_key_expiration.ex b/lib/xdr/ledger_entries/ledger_key_ttl.ex similarity index 92% rename from lib/xdr/ledger_entries/ledger_key_expiration.ex rename to lib/xdr/ledger_entries/ledger_key_ttl.ex index 9a36232..2b3c3f5 100644 --- a/lib/xdr/ledger_entries/ledger_key_expiration.ex +++ b/lib/xdr/ledger_entries/ledger_key_ttl.ex @@ -1,9 +1,9 @@ -defmodule StellarBase.XDR.LedgerKeyExpiration do +defmodule StellarBase.XDR.LedgerKeyTTL do @moduledoc """ Automatically generated by xdrgen DO NOT EDIT or your changes may be overwritten Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - Representation of Stellar `LedgerKeyExpiration` type. + Representation of Stellar `LedgerKeyTTL` type. """ @behaviour XDR.Declaration diff --git a/lib/xdr/ledger_entries/ttl_entry.ex b/lib/xdr/ledger_entries/ttl_entry.ex new file mode 100644 index 0000000..d28d29e --- /dev/null +++ b/lib/xdr/ledger_entries/ttl_entry.ex @@ -0,0 +1,78 @@ +defmodule StellarBase.XDR.TTLEntry do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `TTLEntry` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + Hash, + UInt32 + } + + @struct_spec XDR.Struct.new( + key_hash: Hash, + live_until_ledger_seq: UInt32 + ) + + @type key_hash_type :: Hash.t() + @type live_until_ledger_seq_type :: UInt32.t() + + @type t :: %__MODULE__{ + key_hash: key_hash_type(), + live_until_ledger_seq: live_until_ledger_seq_type() + } + + defstruct [:key_hash, :live_until_ledger_seq] + + @spec new(key_hash :: key_hash_type(), live_until_ledger_seq :: live_until_ledger_seq_type()) :: + t() + def new( + %Hash{} = key_hash, + %UInt32{} = live_until_ledger_seq + ), + do: %__MODULE__{key_hash: key_hash, live_until_ledger_seq: live_until_ledger_seq} + + @impl true + def encode_xdr(%__MODULE__{key_hash: key_hash, live_until_ledger_seq: live_until_ledger_seq}) do + [key_hash: key_hash, live_until_ledger_seq: live_until_ledger_seq] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{key_hash: key_hash, live_until_ledger_seq: live_until_ledger_seq}) do + [key_hash: key_hash, live_until_ledger_seq: live_until_ledger_seq] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, + {%XDR.Struct{ + components: [key_hash: key_hash, live_until_ledger_seq: live_until_ledger_seq] + }, rest}} -> + {:ok, {new(key_hash, live_until_ledger_seq), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [key_hash: key_hash, live_until_ledger_seq: live_until_ledger_seq]}, + rest} = XDR.Struct.decode_xdr!(bytes, struct) + + {new(key_hash, live_until_ledger_seq), rest} + end +end diff --git a/test/xdr/contract/config_setting/state_expiration_settings_test.exs b/test/xdr/contract/config_setting/state_archival_settings_test.exs similarity index 100% rename from test/xdr/contract/config_setting/state_expiration_settings_test.exs rename to test/xdr/contract/config_setting/state_archival_settings_test.exs diff --git a/test/xdr/ledger_entries/ledger_entry_type_test.exs b/test/xdr/ledger_entries/ledger_entry_type_test.exs index 897649d..396458c 100644 --- a/test/xdr/ledger_entries/ledger_entry_type_test.exs +++ b/test/xdr/ledger_entries/ledger_entry_type_test.exs @@ -12,7 +12,8 @@ defmodule StellarBase.XDR.LedgerEntryTypeTest do :LIQUIDITY_POOL, :CONTRACT_DATA, :CONTRACT_CODE, - :CONFIG_SETTING + :CONFIG_SETTING, + :TTL ] @binaries [ @@ -23,7 +24,9 @@ defmodule StellarBase.XDR.LedgerEntryTypeTest do <<0, 0, 0, 4>>, <<0, 0, 0, 5>>, <<0, 0, 0, 6>>, - <<0, 0, 0, 7>> + <<0, 0, 0, 7>>, + <<0, 0, 0, 8>>, + <<0, 0, 0, 9>> ] describe "LedgerEntryType" do diff --git a/test/xdr/ledger_entries/ledger_key_expiration_test.exs b/test/xdr/ledger_entries/ledger_key_ttl_test.exs similarity index 51% rename from test/xdr/ledger_entries/ledger_key_expiration_test.exs rename to test/xdr/ledger_entries/ledger_key_ttl_test.exs index e0306db..2a7604d 100644 --- a/test/xdr/ledger_entries/ledger_key_expiration_test.exs +++ b/test/xdr/ledger_entries/ledger_key_ttl_test.exs @@ -1,41 +1,41 @@ -defmodule StellarBase.XDR.LedgerKeyExpirationTest do +defmodule StellarBase.XDR.LedgerKeyTTLTest do use ExUnit.Case - alias StellarBase.XDR.{Hash, LedgerKeyExpiration} + alias StellarBase.XDR.{Hash, LedgerKeyTTL} - describe "LedgerKeyExpiration" do + describe "LedgerKeyTTL" do setup do hash = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") %{ hash: hash, - ledger_expiration: LedgerKeyExpiration.new(hash), + ledger_expiration: LedgerKeyTTL.new(hash), binary: "GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN" } end test "new/1", %{hash: hash} do - %LedgerKeyExpiration{key_hash: ^hash} = LedgerKeyExpiration.new(hash) + %LedgerKeyTTL{key_hash: ^hash} = LedgerKeyTTL.new(hash) end test "encode_xdr/1", %{ledger_expiration: ledger_expiration, binary: binary} do - {:ok, ^binary} = LedgerKeyExpiration.encode_xdr(ledger_expiration) + {:ok, ^binary} = LedgerKeyTTL.encode_xdr(ledger_expiration) end test "encode_xdr!/1", %{ledger_expiration: ledger_expiration, binary: binary} do - ^binary = LedgerKeyExpiration.encode_xdr!(ledger_expiration) + ^binary = LedgerKeyTTL.encode_xdr!(ledger_expiration) end test "decode_xdr/2", %{ledger_expiration: ledger_expiration, binary: binary} do - {:ok, {^ledger_expiration, ""}} = LedgerKeyExpiration.decode_xdr(binary) + {:ok, {^ledger_expiration, ""}} = LedgerKeyTTL.decode_xdr(binary) end test "decode_xdr!/2", %{ledger_expiration: ledger_expiration, binary: binary} do - {^ledger_expiration, ^binary} = LedgerKeyExpiration.decode_xdr!(binary <> binary) + {^ledger_expiration, ^binary} = LedgerKeyTTL.decode_xdr!(binary <> binary) end test "decode_xdr/2 with invalid binary" do - {:error, :not_binary} = LedgerKeyExpiration.decode_xdr(123) + {:error, :not_binary} = LedgerKeyTTL.decode_xdr(123) end end end diff --git a/test/xdr/ledger_entries/expiration_entry_test.exs b/test/xdr/ledger_entries/ttl_entry_test.exs similarity index 50% rename from test/xdr/ledger_entries/expiration_entry_test.exs rename to test/xdr/ledger_entries/ttl_entry_test.exs index cfa5be0..af8443f 100644 --- a/test/xdr/ledger_entries/expiration_entry_test.exs +++ b/test/xdr/ledger_entries/ttl_entry_test.exs @@ -1,13 +1,13 @@ -defmodule StellarBase.XDR.ExpirationEntryTest do +defmodule StellarBase.XDR.TTLEntryTest do use ExUnit.Case - alias StellarBase.XDR.ExpirationEntry + alias StellarBase.XDR.TTLEntry alias StellarBase.XDR.{Hash, UInt32} - describe "ExpirationEntry" do + describe "TTLEntry" do setup do key_hash = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - expiration_ledger_seq = UInt32.new(123) - expiration_entry = ExpirationEntry.new(key_hash, expiration_ledger_seq) + live_until_ledger_seq = UInt32.new(123) + expiration_entry = TTLEntry.new(key_hash, live_until_ledger_seq) binary = <<71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, @@ -15,37 +15,37 @@ defmodule StellarBase.XDR.ExpirationEntryTest do %{ key_hash: key_hash, - expiration_ledger_seq: expiration_ledger_seq, + live_until_ledger_seq: live_until_ledger_seq, expiration_entry: expiration_entry, binary: binary } end - test "new/2", %{key_hash: key_hash, expiration_ledger_seq: expiration_ledger_seq} do - %StellarBase.XDR.ExpirationEntry{ + test "new/2", %{key_hash: key_hash, live_until_ledger_seq: live_until_ledger_seq} do + %StellarBase.XDR.TTLEntry{ key_hash: ^key_hash, - expiration_ledger_seq: ^expiration_ledger_seq - } = ExpirationEntry.new(key_hash, expiration_ledger_seq) + live_until_ledger_seq: ^live_until_ledger_seq + } = TTLEntry.new(key_hash, live_until_ledger_seq) end test "encode_xdr/1", %{expiration_entry: expiration_entry, binary: binary} do - {:ok, ^binary} = ExpirationEntry.encode_xdr(expiration_entry) + {:ok, ^binary} = TTLEntry.encode_xdr(expiration_entry) end test "encode_xdr!/1", %{expiration_entry: expiration_entry, binary: binary} do - ^binary = ExpirationEntry.encode_xdr!(expiration_entry) + ^binary = TTLEntry.encode_xdr!(expiration_entry) end test "decode_xdr/2", %{binary: binary, expiration_entry: expiration_entry} do - {:ok, {^expiration_entry, ""}} = ExpirationEntry.decode_xdr(binary) + {:ok, {^expiration_entry, ""}} = TTLEntry.decode_xdr(binary) end test "decode_xdr!/2", %{binary: binary, expiration_entry: expiration_entry} do - {^expiration_entry, ""} = ExpirationEntry.decode_xdr!(binary) + {^expiration_entry, ""} = TTLEntry.decode_xdr!(binary) end test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = ExpirationEntry.decode_xdr(123) + {:error, :not_binary} = TTLEntry.decode_xdr(123) end end end From d6786c964d4734f82a56bcd2fdd43511bff6cd16 Mon Sep 17 00:00:00 2001 From: CristhianRodriguezMolina <50219561+CristhianRodriguezMolina@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:40:56 -0500 Subject: [PATCH 4/5] Support stellar transaction Co-authored-by: norn --- lib/xdr/transactions/operation_body.ex | 6 +- lib/xdr/transactions/operation_result_tr.ex | 6 +- lib/xdr/transactions/operation_type.ex | 2 +- .../operations/bump_footprint_expiration.ex | 73 ------------------- .../operations/extend_footprint_ttl.ex | 73 +++++++++++++++++++ ...sult.ex => extend_footprint_ttl_result.ex} | 22 +++--- ...ex => extend_footprint_ttl_result_code.ex} | 14 ++-- .../operations/invoke_host_function_result.ex | 2 +- .../invoke_host_function_result_code.ex | 2 +- .../transactions/soroban_transaction_data.ex | 32 ++++---- ..._footprint_expiration_result_code_test.exs | 72 ------------------ .../bump_footprint_expiration_result_test.exs | 61 ---------------- .../bump_footprint_expiration_test.exs | 51 ------------- .../extend_footprint_ttl_result_code_test.exs | 72 ++++++++++++++++++ .../extend_footprint_ttl_result_test.exs | 61 ++++++++++++++++ .../operations/extend_footprint_ttl_test.exs | 51 +++++++++++++ .../soroban_transaction_data_test.exs | 12 +-- 17 files changed, 306 insertions(+), 306 deletions(-) delete mode 100644 lib/xdr/transactions/operations/bump_footprint_expiration.ex create mode 100644 lib/xdr/transactions/operations/extend_footprint_ttl.ex rename lib/xdr/transactions/operations/{bump_footprint_expiration_result.ex => extend_footprint_ttl_result.ex} (63%) rename lib/xdr/transactions/operations/{bump_footprint_expiration_result_code.ex => extend_footprint_ttl_result_code.ex} (72%) delete mode 100644 test/xdr/transactions/operations/bump_footprint_expiration_result_code_test.exs delete mode 100644 test/xdr/transactions/operations/bump_footprint_expiration_result_test.exs delete mode 100644 test/xdr/transactions/operations/bump_footprint_expiration_test.exs create mode 100644 test/xdr/transactions/operations/extend_footprint_ttl_result_code_test.exs create mode 100644 test/xdr/transactions/operations/extend_footprint_ttl_result_test.exs create mode 100644 test/xdr/transactions/operations/extend_footprint_ttl_test.exs diff --git a/lib/xdr/transactions/operation_body.ex b/lib/xdr/transactions/operation_body.ex index 0b320e0..d5c0d0f 100644 --- a/lib/xdr/transactions/operation_body.ex +++ b/lib/xdr/transactions/operation_body.ex @@ -19,7 +19,7 @@ defmodule StellarBase.XDR.OperationBody do alias StellarBase.XDR.Operations.{ AllowTrust, BeginSponsoringFutureReserves, - BumpFootprintExpiration, + ExtendFootprintTTL, BumpSequence, ChangeTrust, Clawback, @@ -69,7 +69,7 @@ defmodule StellarBase.XDR.OperationBody do LIQUIDITY_POOL_DEPOSIT: LiquidityPoolDeposit, LIQUIDITY_POOL_WITHDRAW: LiquidityPoolWithdraw, INVOKE_HOST_FUNCTION: InvokeHostFunction, - BUMP_FOOTPRINT_EXPIRATION: BumpFootprintExpiration, + EXTEND_FOOTPRINT_TTL: ExtendFootprintTTL, RESTORE_FOOTPRINT: RestoreFootprint ] @@ -98,7 +98,7 @@ defmodule StellarBase.XDR.OperationBody do | LiquidityPoolDeposit.t() | LiquidityPoolWithdraw.t() | InvokeHostFunction.t() - | BumpFootprintExpiration.t() + | ExtendFootprintTTL.t() | RestoreFootprint.t() @type t :: %__MODULE__{value: value(), type: OperationType.t()} diff --git a/lib/xdr/transactions/operation_result_tr.ex b/lib/xdr/transactions/operation_result_tr.ex index 518884f..2537bfe 100644 --- a/lib/xdr/transactions/operation_result_tr.ex +++ b/lib/xdr/transactions/operation_result_tr.ex @@ -16,7 +16,7 @@ defmodule StellarBase.XDR.OperationResultTr do AccountMergeResult, AllowTrustResult, BeginSponsoringFutureReservesResult, - BumpFootprintExpirationResult, + ExtendFootprintTTLResult, BumpSequenceResult, ChangeTrustResult, ClaimClaimableBalanceResult, @@ -67,7 +67,7 @@ defmodule StellarBase.XDR.OperationResultTr do LIQUIDITY_POOL_DEPOSIT: LiquidityPoolDepositResult, LIQUIDITY_POOL_WITHDRAW: LiquidityPoolWithdrawResult, INVOKE_HOST_FUNCTION: InvokeHostFunctionResult, - BUMP_FOOTPRINT_EXPIRATION: BumpFootprintExpirationResult, + EXTEND_FOOTPRINT_TTL: ExtendFootprintTTLResult, RESTORE_FOOTPRINT: RestoreFootprintResult ] @@ -96,7 +96,7 @@ defmodule StellarBase.XDR.OperationResultTr do | LiquidityPoolDepositResult.t() | LiquidityPoolWithdrawResult.t() | InvokeHostFunctionResult.t() - | BumpFootprintExpirationResult.t() + | ExtendFootprintTTLResult.t() | RestoreFootprintResult.t() @type t :: %__MODULE__{value: value(), type: OperationType.t()} diff --git a/lib/xdr/transactions/operation_type.ex b/lib/xdr/transactions/operation_type.ex index 50e0e8b..99a56d6 100644 --- a/lib/xdr/transactions/operation_type.ex +++ b/lib/xdr/transactions/operation_type.ex @@ -36,7 +36,7 @@ defmodule StellarBase.XDR.OperationType do LIQUIDITY_POOL_DEPOSIT: 22, LIQUIDITY_POOL_WITHDRAW: 23, INVOKE_HOST_FUNCTION: 24, - BUMP_FOOTPRINT_EXPIRATION: 25, + EXTEND_FOOTPRINT_TTL: 25, RESTORE_FOOTPRINT: 26 ] diff --git a/lib/xdr/transactions/operations/bump_footprint_expiration.ex b/lib/xdr/transactions/operations/bump_footprint_expiration.ex deleted file mode 100644 index 53f962f..0000000 --- a/lib/xdr/transactions/operations/bump_footprint_expiration.ex +++ /dev/null @@ -1,73 +0,0 @@ -defmodule StellarBase.XDR.Operations.BumpFootprintExpiration do - @moduledoc """ - Automatically generated by xdrgen - DO NOT EDIT or your changes may be overwritten - - Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - - Representation of Stellar `BumpFootprintExpiration` type. - """ - - @behaviour XDR.Declaration - - alias StellarBase.XDR.{ - ExtensionPoint, - UInt32 - } - - @struct_spec XDR.Struct.new( - ext: ExtensionPoint, - ledgers_to_expire: UInt32 - ) - - @type ext_type :: ExtensionPoint.t() - @type ledgers_to_expire_type :: UInt32.t() - - @type t :: %__MODULE__{ext: ext_type(), ledgers_to_expire: ledgers_to_expire_type()} - - defstruct [:ext, :ledgers_to_expire] - - @spec new(ext :: ext_type(), ledgers_to_expire :: ledgers_to_expire_type()) :: t() - def new( - %ExtensionPoint{} = ext, - %UInt32{} = ledgers_to_expire - ), - do: %__MODULE__{ext: ext, ledgers_to_expire: ledgers_to_expire} - - @impl true - def encode_xdr(%__MODULE__{ext: ext, ledgers_to_expire: ledgers_to_expire}) do - [ext: ext, ledgers_to_expire: ledgers_to_expire] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{ext: ext, ledgers_to_expire: ledgers_to_expire}) do - [ext: ext, ledgers_to_expire: ledgers_to_expire] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, struct \\ @struct_spec) - - def decode_xdr(bytes, struct) do - case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, {%XDR.Struct{components: [ext: ext, ledgers_to_expire: ledgers_to_expire]}, rest}} -> - {:ok, {new(ext, ledgers_to_expire), rest}} - - error -> - error - end - end - - @impl true - def decode_xdr!(bytes, struct \\ @struct_spec) - - def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [ext: ext, ledgers_to_expire: ledgers_to_expire]}, rest} = - XDR.Struct.decode_xdr!(bytes, struct) - - {new(ext, ledgers_to_expire), rest} - end -end diff --git a/lib/xdr/transactions/operations/extend_footprint_ttl.ex b/lib/xdr/transactions/operations/extend_footprint_ttl.ex new file mode 100644 index 0000000..6a39c3f --- /dev/null +++ b/lib/xdr/transactions/operations/extend_footprint_ttl.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.Operations.ExtendFootprintTTL do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `ExtendFootprintTTL` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + ExtensionPoint, + UInt32 + } + + @struct_spec XDR.Struct.new( + ext: ExtensionPoint, + extend_to: UInt32 + ) + + @type ext_type :: ExtensionPoint.t() + @type extend_to_type :: UInt32.t() + + @type t :: %__MODULE__{ext: ext_type(), extend_to: extend_to_type()} + + defstruct [:ext, :extend_to] + + @spec new(ext :: ext_type(), extend_to :: extend_to_type()) :: t() + def new( + %ExtensionPoint{} = ext, + %UInt32{} = extend_to + ), + do: %__MODULE__{ext: ext, extend_to: extend_to} + + @impl true + def encode_xdr(%__MODULE__{ext: ext, extend_to: extend_to}) do + [ext: ext, extend_to: extend_to] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{ext: ext, extend_to: extend_to}) do + [ext: ext, extend_to: extend_to] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, {%XDR.Struct{components: [ext: ext, extend_to: extend_to]}, rest}} -> + {:ok, {new(ext, extend_to), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [ext: ext, extend_to: extend_to]}, rest} = + XDR.Struct.decode_xdr!(bytes, struct) + + {new(ext, extend_to), rest} + end +end diff --git a/lib/xdr/transactions/operations/bump_footprint_expiration_result.ex b/lib/xdr/transactions/operations/extend_footprint_ttl_result.ex similarity index 63% rename from lib/xdr/transactions/operations/bump_footprint_expiration_result.ex rename to lib/xdr/transactions/operations/extend_footprint_ttl_result.ex index b4ced23..999d51c 100644 --- a/lib/xdr/transactions/operations/bump_footprint_expiration_result.ex +++ b/lib/xdr/transactions/operations/extend_footprint_ttl_result.ex @@ -1,34 +1,34 @@ -defmodule StellarBase.XDR.Operations.BumpFootprintExpirationResult do +defmodule StellarBase.XDR.Operations.ExtendFootprintTTLResult do @moduledoc """ Automatically generated by xdrgen DO NOT EDIT or your changes may be overwritten Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - Representation of Stellar `BumpFootprintExpirationResult` type. + Representation of Stellar `ExtendFootprintTTLResult` type. """ @behaviour XDR.Declaration alias StellarBase.XDR.Void - alias StellarBase.XDR.Operations.BumpFootprintExpirationResultCode + alias StellarBase.XDR.Operations.ExtendFootprintTTLResultCode @arms [ - BUMP_FOOTPRINT_EXPIRATION_SUCCESS: Void, - BUMP_FOOTPRINT_EXPIRATION_MALFORMED: Void, - BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED: Void, - BUMP_FOOTPRINT_EXPIRATION_INSUFFICIENT_REFUNDABLE_FEE: Void + EXTEND_FOOTPRINT_TTL_SUCCESS: Void, + EXTEND_FOOTPRINT_TTL_MALFORMED: Void, + EXTEND_FOOTPRINT_TTL_RESOURCE_LIMIT_EXCEEDED: Void, + EXTEND_FOOTPRINT_TTL_INSUFFICIENT_REFUNDABLE_FEE: Void ] @type value :: Void.t() - @type t :: %__MODULE__{value: value(), type: BumpFootprintExpirationResultCode.t()} + @type t :: %__MODULE__{value: value(), type: ExtendFootprintTTLResultCode.t()} defstruct [:value, :type] - @spec new(value :: value(), type :: BumpFootprintExpirationResultCode.t()) :: t() - def new(value, %BumpFootprintExpirationResultCode{} = type), + @spec new(value :: value(), type :: ExtendFootprintTTLResultCode.t()) :: t() + def new(value, %ExtendFootprintTTLResultCode{} = type), do: %__MODULE__{value: value, type: type} @impl true @@ -66,7 +66,7 @@ defmodule StellarBase.XDR.Operations.BumpFootprintExpirationResult do @spec union_spec() :: XDR.Union.t() defp union_spec do nil - |> BumpFootprintExpirationResultCode.new() + |> ExtendFootprintTTLResultCode.new() |> XDR.Union.new(@arms) end end diff --git a/lib/xdr/transactions/operations/bump_footprint_expiration_result_code.ex b/lib/xdr/transactions/operations/extend_footprint_ttl_result_code.ex similarity index 72% rename from lib/xdr/transactions/operations/bump_footprint_expiration_result_code.ex rename to lib/xdr/transactions/operations/extend_footprint_ttl_result_code.ex index 757e56e..57ca708 100644 --- a/lib/xdr/transactions/operations/bump_footprint_expiration_result_code.ex +++ b/lib/xdr/transactions/operations/extend_footprint_ttl_result_code.ex @@ -1,20 +1,20 @@ -defmodule StellarBase.XDR.Operations.BumpFootprintExpirationResultCode do +defmodule StellarBase.XDR.Operations.ExtendFootprintTTLResultCode do @moduledoc """ Automatically generated by xdrgen DO NOT EDIT or your changes may be overwritten Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - Representation of Stellar `BumpFootprintExpirationResultCode` type. + Representation of Stellar `ExtendFootprintTTLResultCode` type. """ @behaviour XDR.Declaration @declarations [ - BUMP_FOOTPRINT_EXPIRATION_SUCCESS: 0, - BUMP_FOOTPRINT_EXPIRATION_MALFORMED: -1, - BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED: -2, - BUMP_FOOTPRINT_EXPIRATION_INSUFFICIENT_REFUNDABLE_FEE: -3 + EXTEND_FOOTPRINT_TTL_SUCCESS: 0, + EXTEND_FOOTPRINT_TTL_MALFORMED: -1, + EXTEND_FOOTPRINT_TTL_RESOURCE_LIMIT_EXCEEDED: -2, + EXTEND_FOOTPRINT_TTL_INSUFFICIENT_REFUNDABLE_FEE: -3 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} @@ -24,7 +24,7 @@ defmodule StellarBase.XDR.Operations.BumpFootprintExpirationResultCode do defstruct [:identifier] @spec new(type :: atom()) :: t() - def new(type \\ :BUMP_FOOTPRINT_EXPIRATION_SUCCESS), do: %__MODULE__{identifier: type} + def new(type \\ :EXTEND_FOOTPRINT_TTL_SUCCESS), do: %__MODULE__{identifier: type} @impl true def encode_xdr(%__MODULE__{identifier: type}) do diff --git a/lib/xdr/transactions/operations/invoke_host_function_result.ex b/lib/xdr/transactions/operations/invoke_host_function_result.ex index af4c951..20eb882 100644 --- a/lib/xdr/transactions/operations/invoke_host_function_result.ex +++ b/lib/xdr/transactions/operations/invoke_host_function_result.ex @@ -18,7 +18,7 @@ defmodule StellarBase.XDR.Operations.InvokeHostFunctionResult do INVOKE_HOST_FUNCTION_MALFORMED: Void, INVOKE_HOST_FUNCTION_TRAPPED: Void, INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: Void, - INVOKE_HOST_FUNCTION_ENTRY_EXPIRED: Void, + INVOKE_HOST_FUNCTION_ENTRY_ARCHIVED: Void, INVOKE_HOST_FUNCTION_INSUFFICIENT_REFUNDABLE_FEE: Void ] diff --git a/lib/xdr/transactions/operations/invoke_host_function_result_code.ex b/lib/xdr/transactions/operations/invoke_host_function_result_code.ex index b7d0d4c..554357f 100644 --- a/lib/xdr/transactions/operations/invoke_host_function_result_code.ex +++ b/lib/xdr/transactions/operations/invoke_host_function_result_code.ex @@ -15,7 +15,7 @@ defmodule StellarBase.XDR.Operations.InvokeHostFunctionResultCode do INVOKE_HOST_FUNCTION_MALFORMED: -1, INVOKE_HOST_FUNCTION_TRAPPED: -2, INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: -3, - INVOKE_HOST_FUNCTION_ENTRY_EXPIRED: -4, + INVOKE_HOST_FUNCTION_ENTRY_ARCHIVED: -4, INVOKE_HOST_FUNCTION_INSUFFICIENT_REFUNDABLE_FEE: -5 ] diff --git a/lib/xdr/transactions/soroban_transaction_data.ex b/lib/xdr/transactions/soroban_transaction_data.ex index abf65ba..ce4989d 100644 --- a/lib/xdr/transactions/soroban_transaction_data.ex +++ b/lib/xdr/transactions/soroban_transaction_data.ex @@ -19,43 +19,43 @@ defmodule StellarBase.XDR.SorobanTransactionData do @struct_spec XDR.Struct.new( ext: ExtensionPoint, resources: SorobanResources, - refundable_fee: Int64 + resource_fee: Int64 ) @type ext_type :: ExtensionPoint.t() @type resources_type :: SorobanResources.t() - @type refundable_fee_type :: Int64.t() + @type resource_fee_type :: Int64.t() @type t :: %__MODULE__{ ext: ext_type(), resources: resources_type(), - refundable_fee: refundable_fee_type() + resource_fee: resource_fee_type() } - defstruct [:ext, :resources, :refundable_fee] + defstruct [:ext, :resources, :resource_fee] @spec new( ext :: ext_type(), resources :: resources_type(), - refundable_fee :: refundable_fee_type() + resource_fee :: resource_fee_type() ) :: t() def new( %ExtensionPoint{} = ext, %SorobanResources{} = resources, - %Int64{} = refundable_fee + %Int64{} = resource_fee ), - do: %__MODULE__{ext: ext, resources: resources, refundable_fee: refundable_fee} + do: %__MODULE__{ext: ext, resources: resources, resource_fee: resource_fee} @impl true - def encode_xdr(%__MODULE__{ext: ext, resources: resources, refundable_fee: refundable_fee}) do - [ext: ext, resources: resources, refundable_fee: refundable_fee] + def encode_xdr(%__MODULE__{ext: ext, resources: resources, resource_fee: resource_fee}) do + [ext: ext, resources: resources, resource_fee: resource_fee] |> XDR.Struct.new() |> XDR.Struct.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{ext: ext, resources: resources, refundable_fee: refundable_fee}) do - [ext: ext, resources: resources, refundable_fee: refundable_fee] + def encode_xdr!(%__MODULE__{ext: ext, resources: resources, resource_fee: resource_fee}) do + [ext: ext, resources: resources, resource_fee: resource_fee] |> XDR.Struct.new() |> XDR.Struct.encode_xdr!() end @@ -66,9 +66,9 @@ defmodule StellarBase.XDR.SorobanTransactionData do def decode_xdr(bytes, struct) do case XDR.Struct.decode_xdr(bytes, struct) do {:ok, - {%XDR.Struct{components: [ext: ext, resources: resources, refundable_fee: refundable_fee]}, + {%XDR.Struct{components: [ext: ext, resources: resources, resource_fee: resource_fee]}, rest}} -> - {:ok, {new(ext, resources, refundable_fee), rest}} + {:ok, {new(ext, resources, resource_fee), rest}} error -> error @@ -79,9 +79,9 @@ defmodule StellarBase.XDR.SorobanTransactionData do def decode_xdr!(bytes, struct \\ @struct_spec) def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [ext: ext, resources: resources, refundable_fee: refundable_fee]}, - rest} = XDR.Struct.decode_xdr!(bytes, struct) + {%XDR.Struct{components: [ext: ext, resources: resources, resource_fee: resource_fee]}, rest} = + XDR.Struct.decode_xdr!(bytes, struct) - {new(ext, resources, refundable_fee), rest} + {new(ext, resources, resource_fee), rest} end end diff --git a/test/xdr/transactions/operations/bump_footprint_expiration_result_code_test.exs b/test/xdr/transactions/operations/bump_footprint_expiration_result_code_test.exs deleted file mode 100644 index 5578149..0000000 --- a/test/xdr/transactions/operations/bump_footprint_expiration_result_code_test.exs +++ /dev/null @@ -1,72 +0,0 @@ -defmodule StellarBase.XDR.Operations.BumpFootprintExpirationResultCodeTest do - use ExUnit.Case - - alias StellarBase.XDR.Operations.BumpFootprintExpirationResultCode - - @codes [ - :BUMP_FOOTPRINT_EXPIRATION_SUCCESS, - :BUMP_FOOTPRINT_EXPIRATION_MALFORMED, - :BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED - ] - - @binaries [ - <<0, 0, 0, 0>>, - <<255, 255, 255, 255>>, - <<255, 255, 255, 254>> - ] - - describe "BumpFootprintExpirationResultCode" do - setup do - %{ - codes: @codes, - results: @codes |> Enum.map(fn code -> BumpFootprintExpirationResultCode.new(code) end), - binaries: @binaries - } - end - - test "new/1", %{codes: types} do - for type <- types, - do: - %BumpFootprintExpirationResultCode{identifier: ^type} = - BumpFootprintExpirationResultCode.new(type) - end - - test "encode_xdr/1", %{results: results, binaries: binaries} do - for {result, binary} <- Enum.zip(results, binaries), - do: {:ok, ^binary} = BumpFootprintExpirationResultCode.encode_xdr(result) - end - - test "encode_xdr/1 with an invalid code" do - {:error, :invalid_key} = - BumpFootprintExpirationResultCode.encode_xdr(%BumpFootprintExpirationResultCode{ - identifier: :TEST - }) - end - - test "encode_xdr!/1", %{results: results, binaries: binaries} do - for {result, binary} <- Enum.zip(results, binaries), - do: ^binary = BumpFootprintExpirationResultCode.encode_xdr!(result) - end - - test "decode_xdr/2", %{results: results, binaries: binaries} do - for {result, binary} <- Enum.zip(results, binaries), - do: {:ok, {^result, ""}} = BumpFootprintExpirationResultCode.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid declaration" do - {:error, :invalid_key} = BumpFootprintExpirationResultCode.decode_xdr(<<1, 0, 0, 1>>) - end - - test "decode_xdr!/2", %{results: results, binaries: binaries} do - for {result, binary} <- Enum.zip(results, binaries), - do: {^result, ^binary} = BumpFootprintExpirationResultCode.decode_xdr!(binary <> binary) - end - - test "decode_xdr!/2 with an error code", %{binaries: binaries} do - for binary <- binaries, - do: - {%BumpFootprintExpirationResultCode{identifier: _}, ""} = - BumpFootprintExpirationResultCode.decode_xdr!(binary) - end - end -end diff --git a/test/xdr/transactions/operations/bump_footprint_expiration_result_test.exs b/test/xdr/transactions/operations/bump_footprint_expiration_result_test.exs deleted file mode 100644 index 1dba871..0000000 --- a/test/xdr/transactions/operations/bump_footprint_expiration_result_test.exs +++ /dev/null @@ -1,61 +0,0 @@ -defmodule StellarBase.XDR.Operations.BumpFootprintExpirationResultTest do - use ExUnit.Case - - alias StellarBase.XDR.Void - - alias StellarBase.XDR.Operations.{ - BumpFootprintExpirationResult, - BumpFootprintExpirationResultCode - } - - describe "BumpFootprintExpirationResult" do - setup do - type = BumpFootprintExpirationResultCode.new(:BUMP_FOOTPRINT_EXPIRATION_SUCCESS) - - %{ - type: type, - value: Void.new(), - result: BumpFootprintExpirationResult.new(Void.new(), type), - binary: <<0, 0, 0, 0>> - } - end - - test "new/1", %{type: type, value: value} do - %BumpFootprintExpirationResult{type: ^type, value: ^value} = - BumpFootprintExpirationResult.new(value, type) - end - - test "encode_xdr/1", %{result: result, binary: binary} do - {:ok, ^binary} = BumpFootprintExpirationResult.encode_xdr(result) - end - - test "encode_xdr!/1", %{result: result, binary: binary} do - ^binary = BumpFootprintExpirationResult.encode_xdr!(result) - end - - test "encode_xdr!/1 with a default value", %{type: type, binary: binary} do - result = BumpFootprintExpirationResult.new("TEST", type) - ^binary = BumpFootprintExpirationResult.encode_xdr!(result) - end - - test "decode_xdr/2", %{result: result, binary: binary} do - {:ok, {^result, ""}} = BumpFootprintExpirationResult.decode_xdr(binary) - end - - test "decode_xdr!/2", %{result: result, binary: binary} do - {^result, ^binary} = BumpFootprintExpirationResult.decode_xdr!(binary <> binary) - end - - test "decode_xdr!/2 an error type" do - {%BumpFootprintExpirationResult{ - type: %BumpFootprintExpirationResultCode{ - identifier: :BUMP_FOOTPRINT_EXPIRATION_MALFORMED - } - }, ""} = BumpFootprintExpirationResult.decode_xdr!(<<255, 255, 255, 255>>) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = BumpFootprintExpirationResult.decode_xdr(123) - end - end -end diff --git a/test/xdr/transactions/operations/bump_footprint_expiration_test.exs b/test/xdr/transactions/operations/bump_footprint_expiration_test.exs deleted file mode 100644 index c773d64..0000000 --- a/test/xdr/transactions/operations/bump_footprint_expiration_test.exs +++ /dev/null @@ -1,51 +0,0 @@ -defmodule StellarBase.XDR.Operations.BumpFootprintExpirationTest do - use ExUnit.Case - - alias StellarBase.XDR.{ - ExtensionPoint, - Operations.BumpFootprintExpiration, - UInt32, - Void - } - - describe "BumpFootprintExpiration Operation" do - setup do - ext = ExtensionPoint.new(Void.new(), 0) - ledgers_to_expire = UInt32.new(105_255) - - %{ - ext: ext, - ledgers_to_expire: ledgers_to_expire, - bump_footprint_exp: BumpFootprintExpiration.new(ext, ledgers_to_expire), - binary: <<0, 0, 0, 0, 0, 1, 155, 39>> - } - end - - test "new/1", %{ext: ext, ledgers_to_expire: ledgers_to_expire} do - %BumpFootprintExpiration{ - ext: ^ext, - ledgers_to_expire: ^ledgers_to_expire - } = BumpFootprintExpiration.new(ext, ledgers_to_expire) - end - - test "encode_xdr/1", %{bump_footprint_exp: bump_footprint_exp, binary: binary} do - {:ok, ^binary} = BumpFootprintExpiration.encode_xdr(bump_footprint_exp) - end - - test "encode_xdr!/1", %{bump_footprint_exp: bump_footprint_exp, binary: binary} do - ^binary = BumpFootprintExpiration.encode_xdr!(bump_footprint_exp) - end - - test "decode_xdr/2", %{bump_footprint_exp: bump_footprint_exp, binary: binary} do - {:ok, {^bump_footprint_exp, ""}} = BumpFootprintExpiration.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = BumpFootprintExpiration.decode_xdr(123) - end - - test "decode_xdr!/2", %{bump_footprint_exp: bump_footprint_exp, binary: binary} do - {^bump_footprint_exp, ^binary} = BumpFootprintExpiration.decode_xdr!(binary <> binary) - end - end -end diff --git a/test/xdr/transactions/operations/extend_footprint_ttl_result_code_test.exs b/test/xdr/transactions/operations/extend_footprint_ttl_result_code_test.exs new file mode 100644 index 0000000..95f252d --- /dev/null +++ b/test/xdr/transactions/operations/extend_footprint_ttl_result_code_test.exs @@ -0,0 +1,72 @@ +defmodule StellarBase.XDR.Operations.ExtendFootprintTTLResultCodeTest do + use ExUnit.Case + + alias StellarBase.XDR.Operations.ExtendFootprintTTLResultCode + + @codes [ + :EXTEND_FOOTPRINT_TTL_SUCCESS, + :EXTEND_FOOTPRINT_TTL_MALFORMED, + :EXTEND_FOOTPRINT_TTL_RESOURCE_LIMIT_EXCEEDED + ] + + @binaries [ + <<0, 0, 0, 0>>, + <<255, 255, 255, 255>>, + <<255, 255, 255, 254>> + ] + + describe "ExtendFootprintTTLResultCode" do + setup do + %{ + codes: @codes, + results: @codes |> Enum.map(fn code -> ExtendFootprintTTLResultCode.new(code) end), + binaries: @binaries + } + end + + test "new/1", %{codes: types} do + for type <- types, + do: + %ExtendFootprintTTLResultCode{identifier: ^type} = + ExtendFootprintTTLResultCode.new(type) + end + + test "encode_xdr/1", %{results: results, binaries: binaries} do + for {result, binary} <- Enum.zip(results, binaries), + do: {:ok, ^binary} = ExtendFootprintTTLResultCode.encode_xdr(result) + end + + test "encode_xdr/1 with an invalid code" do + {:error, :invalid_key} = + ExtendFootprintTTLResultCode.encode_xdr(%ExtendFootprintTTLResultCode{ + identifier: :TEST + }) + end + + test "encode_xdr!/1", %{results: results, binaries: binaries} do + for {result, binary} <- Enum.zip(results, binaries), + do: ^binary = ExtendFootprintTTLResultCode.encode_xdr!(result) + end + + test "decode_xdr/2", %{results: results, binaries: binaries} do + for {result, binary} <- Enum.zip(results, binaries), + do: {:ok, {^result, ""}} = ExtendFootprintTTLResultCode.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid declaration" do + {:error, :invalid_key} = ExtendFootprintTTLResultCode.decode_xdr(<<1, 0, 0, 1>>) + end + + test "decode_xdr!/2", %{results: results, binaries: binaries} do + for {result, binary} <- Enum.zip(results, binaries), + do: {^result, ^binary} = ExtendFootprintTTLResultCode.decode_xdr!(binary <> binary) + end + + test "decode_xdr!/2 with an error code", %{binaries: binaries} do + for binary <- binaries, + do: + {%ExtendFootprintTTLResultCode{identifier: _}, ""} = + ExtendFootprintTTLResultCode.decode_xdr!(binary) + end + end +end diff --git a/test/xdr/transactions/operations/extend_footprint_ttl_result_test.exs b/test/xdr/transactions/operations/extend_footprint_ttl_result_test.exs new file mode 100644 index 0000000..1e542bd --- /dev/null +++ b/test/xdr/transactions/operations/extend_footprint_ttl_result_test.exs @@ -0,0 +1,61 @@ +defmodule StellarBase.XDR.Operations.ExtendFootprintTTLResultTest do + use ExUnit.Case + + alias StellarBase.XDR.Void + + alias StellarBase.XDR.Operations.{ + ExtendFootprintTTLResult, + ExtendFootprintTTLResultCode + } + + describe "ExtendFootprintTTLResult" do + setup do + type = ExtendFootprintTTLResultCode.new(:EXTEND_FOOTPRINT_TTL_SUCCESS) + + %{ + type: type, + value: Void.new(), + result: ExtendFootprintTTLResult.new(Void.new(), type), + binary: <<0, 0, 0, 0>> + } + end + + test "new/1", %{type: type, value: value} do + %ExtendFootprintTTLResult{type: ^type, value: ^value} = + ExtendFootprintTTLResult.new(value, type) + end + + test "encode_xdr/1", %{result: result, binary: binary} do + {:ok, ^binary} = ExtendFootprintTTLResult.encode_xdr(result) + end + + test "encode_xdr!/1", %{result: result, binary: binary} do + ^binary = ExtendFootprintTTLResult.encode_xdr!(result) + end + + test "encode_xdr!/1 with a default value", %{type: type, binary: binary} do + result = ExtendFootprintTTLResult.new("TEST", type) + ^binary = ExtendFootprintTTLResult.encode_xdr!(result) + end + + test "decode_xdr/2", %{result: result, binary: binary} do + {:ok, {^result, ""}} = ExtendFootprintTTLResult.decode_xdr(binary) + end + + test "decode_xdr!/2", %{result: result, binary: binary} do + {^result, ^binary} = ExtendFootprintTTLResult.decode_xdr!(binary <> binary) + end + + test "decode_xdr!/2 an error type" do + {%ExtendFootprintTTLResult{ + type: %ExtendFootprintTTLResultCode{ + identifier: :EXTEND_FOOTPRINT_TTL_MALFORMED + } + }, ""} = ExtendFootprintTTLResult.decode_xdr!(<<255, 255, 255, 255>>) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = ExtendFootprintTTLResult.decode_xdr(123) + end + end +end diff --git a/test/xdr/transactions/operations/extend_footprint_ttl_test.exs b/test/xdr/transactions/operations/extend_footprint_ttl_test.exs new file mode 100644 index 0000000..599e350 --- /dev/null +++ b/test/xdr/transactions/operations/extend_footprint_ttl_test.exs @@ -0,0 +1,51 @@ +defmodule StellarBase.XDR.Operations.ExtendFootprintTTLTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + ExtensionPoint, + Operations.ExtendFootprintTTL, + UInt32, + Void + } + + describe "ExtendFootprintTTL Operation" do + setup do + ext = ExtensionPoint.new(Void.new(), 0) + extend_to = UInt32.new(105_255) + + %{ + ext: ext, + extend_to: extend_to, + bump_footprint_exp: ExtendFootprintTTL.new(ext, extend_to), + binary: <<0, 0, 0, 0, 0, 1, 155, 39>> + } + end + + test "new/1", %{ext: ext, extend_to: extend_to} do + %ExtendFootprintTTL{ + ext: ^ext, + extend_to: ^extend_to + } = ExtendFootprintTTL.new(ext, extend_to) + end + + test "encode_xdr/1", %{bump_footprint_exp: bump_footprint_exp, binary: binary} do + {:ok, ^binary} = ExtendFootprintTTL.encode_xdr(bump_footprint_exp) + end + + test "encode_xdr!/1", %{bump_footprint_exp: bump_footprint_exp, binary: binary} do + ^binary = ExtendFootprintTTL.encode_xdr!(bump_footprint_exp) + end + + test "decode_xdr/2", %{bump_footprint_exp: bump_footprint_exp, binary: binary} do + {:ok, {^bump_footprint_exp, ""}} = ExtendFootprintTTL.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = ExtendFootprintTTL.decode_xdr(123) + end + + test "decode_xdr!/2", %{bump_footprint_exp: bump_footprint_exp, binary: binary} do + {^bump_footprint_exp, ^binary} = ExtendFootprintTTL.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/soroban_transaction_data_test.exs b/test/xdr/transactions/soroban_transaction_data_test.exs index 0daed66..3768699 100644 --- a/test/xdr/transactions/soroban_transaction_data_test.exs +++ b/test/xdr/transactions/soroban_transaction_data_test.exs @@ -18,7 +18,7 @@ defmodule StellarBase.XDR.SorobanTransactionDataTest do describe "SorobanResources" do setup do - refundable_fee = Int64.new(10) + resource_fee = Int64.new(10) ext = ExtensionPoint.new(Void.new(), 0) hash = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") type = LedgerEntryType.new(:CONTRACT_CODE) @@ -40,11 +40,11 @@ defmodule StellarBase.XDR.SorobanTransactionDataTest do write_bytes ) - soroban_transaction_data = SorobanTransactionData.new(ext, resources, refundable_fee) + soroban_transaction_data = SorobanTransactionData.new(ext, resources, resource_fee) %{ resources: resources, - refundable_fee: refundable_fee, + resource_fee: resource_fee, ext: ext, soroban_transaction_data: soroban_transaction_data, binary: @@ -58,14 +58,14 @@ defmodule StellarBase.XDR.SorobanTransactionDataTest do test "new/1", %{ resources: resources, - refundable_fee: refundable_fee, + resource_fee: resource_fee, ext: ext } do %SorobanTransactionData{ ext: ^ext, resources: ^resources, - refundable_fee: ^refundable_fee - } = SorobanTransactionData.new(ext, resources, refundable_fee) + resource_fee: ^resource_fee + } = SorobanTransactionData.new(ext, resources, resource_fee) end test "encode_xdr/1", %{soroban_transaction_data: soroban_transaction_data, binary: binary} do From dce2f745f378f734e6c9ba1f282c34a20d555560 Mon Sep 17 00:00:00 2001 From: Kelium Jojoa Urrutia Date: Thu, 26 Oct 2023 17:25:13 -0500 Subject: [PATCH 5/5] Review with xdrgen --- lib/xdr/ledger_entries/ledger_entry_data.ex | 45 ++++++++++--------- lib/xdr/ledger_entries/ledger_entry_type.ex | 9 +++- .../ledger_entries/ledger_entry_data_test.exs | 2 +- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/lib/xdr/ledger_entries/ledger_entry_data.ex b/lib/xdr/ledger_entries/ledger_entry_data.ex index b65b43c..b161f38 100644 --- a/lib/xdr/ledger_entries/ledger_entry_data.ex +++ b/lib/xdr/ledger_entries/ledger_entry_data.ex @@ -1,40 +1,43 @@ defmodule StellarBase.XDR.LedgerEntryData do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `LedgerEntryData` type. """ + @behaviour XDR.Declaration + alias StellarBase.XDR.{ + LedgerEntryType, AccountEntry, TrustLineEntry, OfferEntry, DataEntry, - ClaimableBalance, - LiquidityPool, + ClaimableBalanceEntry, + LiquidityPoolEntry, ContractDataEntry, ContractCodeEntry, ConfigSettingEntry, - ClaimableBalanceEntry, - LiquidityPoolEntry, - LedgerEntryType, TTLEntry } - @behaviour XDR.Declaration - @arms [ ACCOUNT: AccountEntry, TRUSTLINE: TrustLineEntry, OFFER: OfferEntry, DATA: DataEntry, - CLAIMABLE_BALANCE: ClaimableBalance, - LIQUIDITY_POOL: LiquidityPool, + CLAIMABLE_BALANCE: ClaimableBalanceEntry, + LIQUIDITY_POOL: LiquidityPoolEntry, CONTRACT_DATA: ContractDataEntry, CONTRACT_CODE: ContractCodeEntry, CONFIG_SETTING: ConfigSettingEntry, TTL: TTLEntry ] - @type entry :: + @type value :: AccountEntry.t() | TrustLineEntry.t() | OfferEntry.t() @@ -46,24 +49,24 @@ defmodule StellarBase.XDR.LedgerEntryData do | ConfigSettingEntry.t() | TTLEntry.t() - @type t :: %__MODULE__{entry: entry(), type: LedgerEntryType.t()} + @type t :: %__MODULE__{value: value(), type: LedgerEntryType.t()} - defstruct [:entry, :type] + defstruct [:value, :type] - @spec new(entry :: entry(), type :: LedgerEntryType.t()) :: t() - def new(entry, %LedgerEntryType{} = type), do: %__MODULE__{entry: entry, type: type} + @spec new(value :: value(), type :: LedgerEntryType.t()) :: t() + def new(value, %LedgerEntryType{} = type), do: %__MODULE__{value: value, type: type} @impl true - def encode_xdr(%__MODULE__{entry: entry, type: type}) do + def encode_xdr(%__MODULE__{value: value, type: type}) do type - |> XDR.Union.new(@arms, entry) + |> XDR.Union.new(@arms, value) |> XDR.Union.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{entry: entry, type: type}) do + def encode_xdr!(%__MODULE__{value: value, type: type}) do type - |> XDR.Union.new(@arms, entry) + |> XDR.Union.new(@arms, value) |> XDR.Union.encode_xdr!() end @@ -72,7 +75,7 @@ defmodule StellarBase.XDR.LedgerEntryData do def decode_xdr(bytes, spec) do case XDR.Union.decode_xdr(bytes, spec) do - {:ok, {{type, key}, rest}} -> {:ok, {new(key, type), rest}} + {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}} error -> error end end @@ -81,8 +84,8 @@ defmodule StellarBase.XDR.LedgerEntryData do def decode_xdr!(bytes, spec \\ union_spec()) def decode_xdr!(bytes, spec) do - {{type, key}, rest} = XDR.Union.decode_xdr!(bytes, spec) - {new(key, type), rest} + {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec) + {new(value, type), rest} end @spec union_spec() :: XDR.Union.t() diff --git a/lib/xdr/ledger_entries/ledger_entry_type.ex b/lib/xdr/ledger_entries/ledger_entry_type.ex index 4fb8750..98c0687 100644 --- a/lib/xdr/ledger_entries/ledger_entry_type.ex +++ b/lib/xdr/ledger_entries/ledger_entry_type.ex @@ -1,5 +1,10 @@ defmodule StellarBase.XDR.LedgerEntryType do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `LedgerEntryType` type. """ @@ -24,8 +29,8 @@ defmodule StellarBase.XDR.LedgerEntryType do defstruct [:identifier] - @spec new(type :: atom() | nil) :: t() - def new(type \\ nil), do: %__MODULE__{identifier: type} + @spec new(type :: atom()) :: t() + def new(type \\ :ACCOUNT), do: %__MODULE__{identifier: type} @impl true def encode_xdr(%__MODULE__{identifier: type}) do diff --git a/test/xdr/ledger_entries/ledger_entry_data_test.exs b/test/xdr/ledger_entries/ledger_entry_data_test.exs index d26b679..558e30f 100644 --- a/test/xdr/ledger_entries/ledger_entry_data_test.exs +++ b/test/xdr/ledger_entries/ledger_entry_data_test.exs @@ -218,7 +218,7 @@ defmodule StellarBase.XDR.LedgerEntryDataTest do test "new/1", %{discriminants: discriminants} do for %{type: type, ledger_entry_data: ledger_entry_data} <- discriminants do - %LedgerEntryData{entry: ^ledger_entry_data, type: ^type} = + %LedgerEntryData{value: ^ledger_entry_data, type: ^type} = LedgerEntryData.new(ledger_entry_data, type) end end