diff --git a/Makefile b/Makefile index a0078b12..c7d49c0a 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ xdr/Stellar-contract-config-setting.x XDRGEN_REPO=overcat/xdrgen XDRGEN_COMMIT=c98916346eeea7e37aaea039de03c1e5ea0a116a -XDRNEXT_COMMIT=e372df9f677961aac04c5a4cc80a3667f310b29f +XDRNEXT_COMMIT=9ac02641139e6717924fdad716f6e958d0168491 UNAME := $(shell uname) SED := sed @@ -87,7 +87,7 @@ xdr/%.x: .PHONY: xdr xdr-clean: - rm .xdr/*.x || true + rm xdr/*.x || true rm stellar_sdk/xdr/*.py || true .PHONY: xdr-clean diff --git a/docs/en/api.rst b/docs/en/api.rst index cbf29c88..957af526 100644 --- a/docs/en/api.rst +++ b/docs/en/api.rst @@ -1158,6 +1158,10 @@ ConfigSettingContractComputeV0 ------------------------------ .. autoclass:: stellar_sdk.xdr.config_setting_contract_compute_v0.ConfigSettingContractComputeV0 +ConfigSettingContractEventsV0 +----------------------------- +.. autoclass:: stellar_sdk.xdr.config_setting_contract_events_v0.ConfigSettingContractEventsV0 + ConfigSettingContractExecutionLanesV0 ------------------------------------- .. autoclass:: stellar_sdk.xdr.config_setting_contract_execution_lanes_v0.ConfigSettingContractExecutionLanesV0 @@ -1170,10 +1174,6 @@ ConfigSettingContractLedgerCostV0 --------------------------------- .. autoclass:: stellar_sdk.xdr.config_setting_contract_ledger_cost_v0.ConfigSettingContractLedgerCostV0 -ConfigSettingContractMetaDataV0 -------------------------------- -.. autoclass:: stellar_sdk.xdr.config_setting_contract_meta_data_v0.ConfigSettingContractMetaDataV0 - ConfigSettingEntry ------------------ .. autoclass:: stellar_sdk.xdr.config_setting_entry.ConfigSettingEntry @@ -1194,10 +1194,6 @@ ContractCodeEntry ----------------- .. autoclass:: stellar_sdk.xdr.contract_code_entry.ContractCodeEntry -ContractCodeEntryBody ---------------------- -.. autoclass:: stellar_sdk.xdr.contract_code_entry_body.ContractCodeEntryBody - ContractCostParamEntry ---------------------- .. autoclass:: stellar_sdk.xdr.contract_cost_param_entry.ContractCostParamEntry @@ -1218,22 +1214,6 @@ ContractDataEntry ----------------- .. autoclass:: stellar_sdk.xdr.contract_data_entry.ContractDataEntry -ContractDataEntryBody ---------------------- -.. autoclass:: stellar_sdk.xdr.contract_data_entry_body.ContractDataEntryBody - -ContractDataEntryData ---------------------- -.. autoclass:: stellar_sdk.xdr.contract_data_entry_data.ContractDataEntryData - -ContractDataFlags ------------------ -.. autoclass:: stellar_sdk.xdr.contract_data_flags.ContractDataFlags - -ContractEntryBodyType ---------------------- -.. autoclass:: stellar_sdk.xdr.contract_entry_body_type.ContractEntryBodyType - ContractEvent ------------- .. autoclass:: stellar_sdk.xdr.contract_event.ContractEvent @@ -1370,6 +1350,14 @@ ErrorCode --------- .. autoclass:: stellar_sdk.xdr.error_code.ErrorCode +EvictionIterator +---------------- +.. autoclass:: stellar_sdk.xdr.eviction_iterator.EvictionIterator + +ExpirationEntry +--------------- +.. autoclass:: stellar_sdk.xdr.expiration_entry.ExpirationEntry + ExtensionPoint -------------- .. autoclass:: stellar_sdk.xdr.extension_point.ExtensionPoint @@ -1506,6 +1494,10 @@ Integer ------- .. autoclass:: stellar_sdk.xdr.base.Integer +InvokeContractArgs +------------------ +.. autoclass:: stellar_sdk.xdr.invoke_contract_args.InvokeContractArgs + InvokeHostFunctionOp -------------------- .. autoclass:: stellar_sdk.xdr.invoke_host_function_op.InvokeHostFunctionOp @@ -1642,6 +1634,10 @@ LedgerKeyData ------------- .. autoclass:: stellar_sdk.xdr.ledger_key_data.LedgerKeyData +LedgerKeyExpiration +------------------- +.. autoclass:: stellar_sdk.xdr.ledger_key_expiration.LedgerKeyExpiration + LedgerKeyLiquidityPool ---------------------- .. autoclass:: stellar_sdk.xdr.ledger_key_liquidity_pool.LedgerKeyLiquidityPool @@ -2114,10 +2110,6 @@ SCSpecTypeResult ---------------- .. autoclass:: stellar_sdk.xdr.sc_spec_type_result.SCSpecTypeResult -SCSpecTypeSet -------------- -.. autoclass:: stellar_sdk.xdr.sc_spec_type_set.SCSpecTypeSet - SCSpecTypeTuple --------------- .. autoclass:: stellar_sdk.xdr.sc_spec_type_tuple.SCSpecTypeTuple @@ -2274,10 +2266,6 @@ SorobanAuthorizationEntry ------------------------- .. autoclass:: stellar_sdk.xdr.soroban_authorization_entry.SorobanAuthorizationEntry -SorobanAuthorizedContractFunction ---------------------------------- -.. autoclass:: stellar_sdk.xdr.soroban_authorized_contract_function.SorobanAuthorizedContractFunction - SorobanAuthorizedFunction ------------------------- .. autoclass:: stellar_sdk.xdr.soroban_authorized_function.SorobanAuthorizedFunction @@ -2602,7 +2590,6 @@ Constants .. autodata:: stellar_sdk.xdr.constants.MASK_ACCOUNT_FLAGS .. autodata:: stellar_sdk.xdr.constants.MASK_ACCOUNT_FLAGS_V17 .. autodata:: stellar_sdk.xdr.constants.MASK_CLAIMABLE_BALANCE_FLAGS -.. autodata:: stellar_sdk.xdr.constants.MASK_CONTRACT_DATA_FLAGS_V20 .. autodata:: stellar_sdk.xdr.constants.MASK_LEDGER_HEADER_FLAGS .. autodata:: stellar_sdk.xdr.constants.MASK_OFFERENTRY_FLAGS .. autodata:: stellar_sdk.xdr.constants.MASK_TRUSTLINE_FLAGS @@ -2614,3 +2601,5 @@ Constants .. autodata:: stellar_sdk.xdr.constants.SC_SPEC_DOC_LIMIT .. autodata:: stellar_sdk.xdr.constants.TX_ADVERT_VECTOR_MAX_SIZE .. autodata:: stellar_sdk.xdr.constants.TX_DEMAND_VECTOR_MAX_SIZE +(stellar-sdk-py3.10) py-stellar-base [soroban-update●●] + diff --git a/examples/soroban_bump_footprint_expiration.py b/examples/soroban_bump_footprint_expiration.py index 5096d072..2fad2029 100644 --- a/examples/soroban_bump_footprint_expiration.py +++ b/examples/soroban_bump_footprint_expiration.py @@ -31,7 +31,6 @@ contract=Address(contract_id).to_xdr_sc_address(), key=stellar_xdr.SCVal(stellar_xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_INSTANCE), durability=stellar_xdr.ContractDataDurability.PERSISTENT, - body_type=stellar_xdr.ContractEntryBodyType.DATA_ENTRY, ), ) soroban_data = SorobanDataBuilder().set_read_only([ledger_key]).build() diff --git a/examples/soroban_restore_footprint.py b/examples/soroban_restore_footprint.py index 5c019d3c..38b2e9d4 100644 --- a/examples/soroban_restore_footprint.py +++ b/examples/soroban_restore_footprint.py @@ -31,7 +31,6 @@ contract=Address(contract_id).to_xdr_sc_address(), key=stellar_xdr.SCVal(stellar_xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_INSTANCE), durability=stellar_xdr.ContractDataDurability.PERSISTENT, - body_type=stellar_xdr.ContractEntryBodyType.DATA_ENTRY, ), ) soroban_data = SorobanDataBuilder().set_read_only([ledger_key]).build() diff --git a/stellar_sdk/soroban_data_builder.py b/stellar_sdk/soroban_data_builder.py index dc549f1d..15e4d6e8 100644 --- a/stellar_sdk/soroban_data_builder.py +++ b/stellar_sdk/soroban_data_builder.py @@ -27,7 +27,6 @@ def __init__(self): read_only=[], read_write=[], ), - extended_meta_data_size_bytes=stellar_xdr.Uint32(0), read_bytes=stellar_xdr.Uint32(0), write_bytes=stellar_xdr.Uint32(0), instructions=stellar_xdr.Uint32(0), @@ -84,7 +83,7 @@ def set_read_write( return self def set_resources( - self, instructions: int, read_bytes: int, write_bytes: int, metadata_bytes: int + self, instructions: int, read_bytes: int, write_bytes: int ) -> SorobanDataBuilder: """Sets up the resource metrics. @@ -94,15 +93,11 @@ def set_resources( :param instructions: Number of CPU instructions (uint32) :param read_bytes: Number of bytes being read (uint32) :param write_bytes: Number of bytes being written (uint32) - :param metadata_bytes: Number of extended metadata bytes (uint32) :return: This builder. """ self._data.resources.instructions = stellar_xdr.Uint32(instructions) self._data.resources.read_bytes = stellar_xdr.Uint32(read_bytes) self._data.resources.write_bytes = stellar_xdr.Uint32(write_bytes) - self._data.resources.extended_meta_data_size_bytes = stellar_xdr.Uint32( - metadata_bytes - ) return self def build(self): diff --git a/stellar_sdk/soroban_rpc.py b/stellar_sdk/soroban_rpc.py index 1f40608f..a79f5d1b 100644 --- a/stellar_sdk/soroban_rpc.py +++ b/stellar_sdk/soroban_rpc.py @@ -49,8 +49,8 @@ class EventFilterType(Enum): class EventFilter(BaseModel): event_type: Optional[EventFilterType] = Field(alias="type", default=None) - contract_ids: Optional[List[str]] = Field(alias="contractIds", default=None) - topics: Optional[List[List[str]]] = None + contract_ids: Optional[Sequence[str]] = Field(alias="contractIds", default=None) + topics: Optional[Sequence[Sequence[str]]] = None model_config = ConfigDict(populate_by_name=True) @@ -65,7 +65,7 @@ class EventInfo(BaseModel): contract_id: str = Field(alias="contractId") id: str = Field(alias="id") paging_token: str = Field(alias="pagingToken") - topic: Sequence[str] = Field(alias="topic") + topic: List[str] = Field(alias="topic") value: EventInfoValue = Field(alias="value") in_successful_contract_call: bool = Field(alias="inSuccessfulContractCall") @@ -94,7 +94,7 @@ class GetEventsResponse(BaseModel): more information. """ - events: Sequence[EventInfo] = Field(alias="events") + events: List[EventInfo] = Field(alias="events") latest_ledger: int = Field(alias="latestLedger") @@ -105,7 +105,7 @@ class GetLedgerEntriesRequest(BaseModel): See `getLedgerEntries documentation `__ for more information.""" - keys: List[str] + keys: Sequence[str] class LedgerEntryResult(BaseModel): @@ -175,6 +175,11 @@ class SimulateHostFunctionResult(BaseModel): xdr: str +class RestorePreamble(BaseModel): + transaction_data: str = Field(alias="transactionData") + min_resource_fee: int = Field(alias="minResourceFee") + + class SimulateTransactionResponse(BaseModel): """Response for JSON-RPC method simulateTransaction. @@ -182,12 +187,21 @@ class SimulateTransactionResponse(BaseModel): more information.""" error: Optional[str] = None - # Empty string? - transaction_data: str = Field(alias="transactionData") + transaction_data: Optional[str] = Field(alias="transactionData", default=None) + # SorobanTransactionData XDR in base64 + min_resource_fee: Optional[int] = Field(alias="minResourceFee", default=None) events: Optional[List[str]] = None - min_resource_fee: int = Field(alias="minResourceFee") + # DiagnosticEvent XDR in base64 results: Optional[List[SimulateHostFunctionResult]] = None - cost: SimulateTransactionCost + # an array of the individual host function call results. + # This will only contain a single element if present, because only a single invokeHostFunctionOperation + # is supported per transaction. + cost: Optional[SimulateTransactionCost] = None + # the effective cpu and memory cost of the invoked transaction execution. + restore_preamble: Optional[RestorePreamble] = Field( + alias="restorePreamble", default=None + ) + # If present, it indicates that a prior RestoreFootprint is required latest_ledger: int = Field(alias="latestLedger") diff --git a/stellar_sdk/soroban_server.py b/stellar_sdk/soroban_server.py index 86ccf342..560b855f 100644 --- a/stellar_sdk/soroban_server.py +++ b/stellar_sdk/soroban_server.py @@ -3,7 +3,7 @@ import copy import json import uuid -from typing import TYPE_CHECKING, Type +from typing import TYPE_CHECKING, Sequence, Type from . import Keypair from . import xdr as stellar_xdr @@ -260,7 +260,6 @@ def get_contract_data( contract=sc_address, key=key, durability=xdr_durability, - body_type=stellar_xdr.ContractEntryBodyType.DATA_ENTRY, ), ) resp = self.get_ledger_entries([contract_key]) @@ -309,10 +308,6 @@ def prepare_transaction( "Simulation transaction failed, the response contains error information.", resp, ) - if not resp.results or len(resp.results) != 1: - raise PrepareTransactionException( - f'Simulation transaction failed, the "results" field is invalid.', resp - ) te = _assemble_transaction(transaction_envelope, resp) return te @@ -358,30 +353,26 @@ def _assemble_transaction( "type RestoreFootprint, InvokeHostFunction or BumpFootprintExpiration" ) - if not simulation.results or len(simulation.results) != 1: - raise ValueError(f"Simulation results invalid: {simulation.results}") - min_resource_fee = simulation.min_resource_fee + assert simulation.transaction_data is not None soroban_data = stellar_xdr.SorobanTransactionData.from_xdr( simulation.transaction_data ) - - # TODO: https://discord.com/channels/897514728459468821/1112853306881081354/1112853306881081354 - # soroban_data.resources.instructions = stellar_xdr.Uint32(soroban_data.resources.instructions.uint32 * 2) - te = copy.deepcopy(transaction_envelope) te.signatures = [] + assert min_resource_fee is not None te.transaction.fee += min_resource_fee te.transaction.soroban_data = soroban_data op = te.transaction.operations[0] - if ( - isinstance(op, InvokeHostFunction) - and not op.auth - and simulation.results[0].auth - ): - op.auth = [ - stellar_xdr.SorobanAuthorizationEntry.from_xdr(xdr) - for xdr in simulation.results[0].auth - ] + + if isinstance(op, InvokeHostFunction): + if not simulation.results or len(simulation.results) != 1: + raise ValueError(f"Simulation results invalid: {simulation.results}") + + if not op.auth and simulation.results[0].auth: + op.auth = [ + stellar_xdr.SorobanAuthorizationEntry.from_xdr(xdr) + for xdr in simulation.results[0].auth + ] return te diff --git a/stellar_sdk/transaction_builder.py b/stellar_sdk/transaction_builder.py index 07e1d4b4..edee5446 100644 --- a/stellar_sdk/transaction_builder.py +++ b/stellar_sdk/transaction_builder.py @@ -1249,18 +1249,15 @@ def append_invoke_contract_function_op( if not StrKey.is_valid_contract(contract_id): raise ValueError("`contract_id` is invalid.") - invoke_params = [ - Address(contract_id).to_xdr_sc_val(), - stellar_xdr.SCVal( - stellar_xdr.SCValType.SCV_SYMBOL, - sym=stellar_xdr.SCSymbol(sc_symbol=function_name.encode("utf-8")), - ), - *parameters, - ] - host_function = stellar_xdr.HostFunction( stellar_xdr.HostFunctionType.HOST_FUNCTION_TYPE_INVOKE_CONTRACT, - invoke_contract=stellar_xdr.SCVec(invoke_params), + invoke_contract=stellar_xdr.InvokeContractArgs( + contract_address=Address(contract_id).to_xdr_sc_address(), + function_name=stellar_xdr.SCSymbol( + sc_symbol=function_name.encode("utf-8") + ), + args=list(parameters), + ), ) op = InvokeHostFunction(host_function=host_function, auth=auth, source=source) return self.append_operation(op) diff --git a/stellar_sdk/xdr/__init__.py b/stellar_sdk/xdr/__init__.py index 929a4e93..c3015fd6 100644 --- a/stellar_sdk/xdr/__init__.py +++ b/stellar_sdk/xdr/__init__.py @@ -75,6 +75,7 @@ from .clawback_result_code import ClawbackResultCode from .config_setting_contract_bandwidth_v0 import ConfigSettingContractBandwidthV0 from .config_setting_contract_compute_v0 import ConfigSettingContractComputeV0 +from .config_setting_contract_events_v0 import ConfigSettingContractEventsV0 from .config_setting_contract_execution_lanes_v0 import ( ConfigSettingContractExecutionLanesV0, ) @@ -82,23 +83,17 @@ ConfigSettingContractHistoricalDataV0, ) from .config_setting_contract_ledger_cost_v0 import ConfigSettingContractLedgerCostV0 -from .config_setting_contract_meta_data_v0 import ConfigSettingContractMetaDataV0 from .config_setting_entry import ConfigSettingEntry from .config_setting_id import ConfigSettingID from .config_upgrade_set import ConfigUpgradeSet from .config_upgrade_set_key import ConfigUpgradeSetKey from .constants import * from .contract_code_entry import ContractCodeEntry -from .contract_code_entry_body import ContractCodeEntryBody from .contract_cost_param_entry import ContractCostParamEntry from .contract_cost_params import ContractCostParams from .contract_cost_type import ContractCostType from .contract_data_durability import ContractDataDurability from .contract_data_entry import ContractDataEntry -from .contract_data_entry_body import ContractDataEntryBody -from .contract_data_entry_data import ContractDataEntryData -from .contract_data_flags import ContractDataFlags -from .contract_entry_body_type import ContractEntryBodyType from .contract_event import ContractEvent from .contract_event_body import ContractEventBody from .contract_event_type import ContractEventType @@ -134,6 +129,8 @@ from .envelope_type import EnvelopeType from .error import Error from .error_code import ErrorCode +from .eviction_iterator import EvictionIterator +from .expiration_entry import ExpirationEntry from .extension_point import ExtensionPoint from .fee_bump_transaction import FeeBumpTransaction from .fee_bump_transaction_envelope import FeeBumpTransactionEnvelope @@ -164,6 +161,7 @@ from .int64 import Int64 from .int128_parts import Int128Parts from .int256_parts import Int256Parts +from .invoke_contract_args import InvokeContractArgs from .invoke_host_function_op import InvokeHostFunctionOp from .invoke_host_function_result import InvokeHostFunctionResult from .invoke_host_function_result_code import InvokeHostFunctionResultCode @@ -199,6 +197,7 @@ from .ledger_key_contract_code import LedgerKeyContractCode from .ledger_key_contract_data import LedgerKeyContractData from .ledger_key_data import LedgerKeyData +from .ledger_key_expiration import LedgerKeyExpiration from .ledger_key_liquidity_pool import LedgerKeyLiquidityPool from .ledger_key_offer import LedgerKeyOffer from .ledger_key_trust_line import LedgerKeyTrustLine @@ -308,7 +307,6 @@ from .sc_spec_type_map import SCSpecTypeMap from .sc_spec_type_option import SCSpecTypeOption from .sc_spec_type_result import SCSpecTypeResult -from .sc_spec_type_set import SCSpecTypeSet from .sc_spec_type_tuple import SCSpecTypeTuple from .sc_spec_type_udt import SCSpecTypeUDT from .sc_spec_type_vec import SCSpecTypeVec @@ -360,7 +358,6 @@ from .simple_payment_result import SimplePaymentResult from .soroban_address_credentials import SorobanAddressCredentials from .soroban_authorization_entry import SorobanAuthorizationEntry -from .soroban_authorized_contract_function import SorobanAuthorizedContractFunction from .soroban_authorized_function import SorobanAuthorizedFunction from .soroban_authorized_function_type import SorobanAuthorizedFunctionType from .soroban_authorized_invocation import SorobanAuthorizedInvocation diff --git a/stellar_sdk/xdr/bump_footprint_expiration_result.py b/stellar_sdk/xdr/bump_footprint_expiration_result.py index 1257d67a..1606bbd9 100644 --- a/stellar_sdk/xdr/bump_footprint_expiration_result.py +++ b/stellar_sdk/xdr/bump_footprint_expiration_result.py @@ -21,6 +21,7 @@ class BumpFootprintExpirationResult: void; case BUMP_FOOTPRINT_EXPIRATION_MALFORMED: case BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED: + case BUMP_FOOTPRINT_EXPIRATION_INSUFFICIENT_REFUNDABLE_FEE: void; }; """ @@ -48,6 +49,11 @@ def pack(self, packer: Packer) -> None: == BumpFootprintExpirationResultCode.BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED ): return + if ( + self.code + == BumpFootprintExpirationResultCode.BUMP_FOOTPRINT_EXPIRATION_INSUFFICIENT_REFUNDABLE_FEE + ): + return @classmethod def unpack(cls, unpacker: Unpacker) -> BumpFootprintExpirationResult: @@ -64,6 +70,11 @@ def unpack(cls, unpacker: Unpacker) -> BumpFootprintExpirationResult: == BumpFootprintExpirationResultCode.BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED ): return cls(code=code) + if ( + code + == BumpFootprintExpirationResultCode.BUMP_FOOTPRINT_EXPIRATION_INSUFFICIENT_REFUNDABLE_FEE + ): + return cls(code=code) return cls(code=code) def to_xdr_bytes(self) -> bytes: diff --git a/stellar_sdk/xdr/bump_footprint_expiration_result_code.py b/stellar_sdk/xdr/bump_footprint_expiration_result_code.py index 78377fd5..52330e97 100644 --- a/stellar_sdk/xdr/bump_footprint_expiration_result_code.py +++ b/stellar_sdk/xdr/bump_footprint_expiration_result_code.py @@ -21,13 +21,15 @@ class BumpFootprintExpirationResultCode(IntEnum): // codes considered as "failure" for the operation BUMP_FOOTPRINT_EXPIRATION_MALFORMED = -1, - BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED = -2 + BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED = -2, + BUMP_FOOTPRINT_EXPIRATION_INSUFFICIENT_REFUNDABLE_FEE = -3 }; """ BUMP_FOOTPRINT_EXPIRATION_SUCCESS = 0 BUMP_FOOTPRINT_EXPIRATION_MALFORMED = -1 BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED = -2 + BUMP_FOOTPRINT_EXPIRATION_INSUFFICIENT_REFUNDABLE_FEE = -3 def pack(self, packer: Packer) -> None: packer.pack_int(self.value) diff --git a/stellar_sdk/xdr/config_setting_contract_bandwidth_v0.py b/stellar_sdk/xdr/config_setting_contract_bandwidth_v0.py index ab71f244..0b907612 100644 --- a/stellar_sdk/xdr/config_setting_contract_bandwidth_v0.py +++ b/stellar_sdk/xdr/config_setting_contract_bandwidth_v0.py @@ -18,40 +18,40 @@ class ConfigSettingContractBandwidthV0: struct ConfigSettingContractBandwidthV0 { - // Maximum size in bytes to propagate per ledger - uint32 ledgerMaxPropagateSizeBytes; + // Maximum sum of all transaction sizes in the ledger in bytes + uint32 ledgerMaxTxsSizeBytes; // Maximum size in bytes for a transaction uint32 txMaxSizeBytes; - // Fee for propagating 1KB of data - int64 feePropagateData1KB; + // Fee for 1 KB of transaction size + int64 feeTxSize1KB; }; """ def __init__( self, - ledger_max_propagate_size_bytes: Uint32, + ledger_max_txs_size_bytes: Uint32, tx_max_size_bytes: Uint32, - fee_propagate_data1_kb: Int64, + fee_tx_size1_kb: Int64, ) -> None: - self.ledger_max_propagate_size_bytes = ledger_max_propagate_size_bytes + self.ledger_max_txs_size_bytes = ledger_max_txs_size_bytes self.tx_max_size_bytes = tx_max_size_bytes - self.fee_propagate_data1_kb = fee_propagate_data1_kb + self.fee_tx_size1_kb = fee_tx_size1_kb def pack(self, packer: Packer) -> None: - self.ledger_max_propagate_size_bytes.pack(packer) + self.ledger_max_txs_size_bytes.pack(packer) self.tx_max_size_bytes.pack(packer) - self.fee_propagate_data1_kb.pack(packer) + self.fee_tx_size1_kb.pack(packer) @classmethod def unpack(cls, unpacker: Unpacker) -> ConfigSettingContractBandwidthV0: - ledger_max_propagate_size_bytes = Uint32.unpack(unpacker) + ledger_max_txs_size_bytes = Uint32.unpack(unpacker) tx_max_size_bytes = Uint32.unpack(unpacker) - fee_propagate_data1_kb = Int64.unpack(unpacker) + fee_tx_size1_kb = Int64.unpack(unpacker) return cls( - ledger_max_propagate_size_bytes=ledger_max_propagate_size_bytes, + ledger_max_txs_size_bytes=ledger_max_txs_size_bytes, tx_max_size_bytes=tx_max_size_bytes, - fee_propagate_data1_kb=fee_propagate_data1_kb, + fee_tx_size1_kb=fee_tx_size1_kb, ) def to_xdr_bytes(self) -> bytes: @@ -76,9 +76,9 @@ def from_xdr(cls, xdr: str) -> ConfigSettingContractBandwidthV0: def __hash__(self): return hash( ( - self.ledger_max_propagate_size_bytes, + self.ledger_max_txs_size_bytes, self.tx_max_size_bytes, - self.fee_propagate_data1_kb, + self.fee_tx_size1_kb, ) ) @@ -86,16 +86,15 @@ def __eq__(self, other: object): if not isinstance(other, self.__class__): return NotImplemented return ( - self.ledger_max_propagate_size_bytes - == other.ledger_max_propagate_size_bytes + self.ledger_max_txs_size_bytes == other.ledger_max_txs_size_bytes and self.tx_max_size_bytes == other.tx_max_size_bytes - and self.fee_propagate_data1_kb == other.fee_propagate_data1_kb + and self.fee_tx_size1_kb == other.fee_tx_size1_kb ) def __str__(self): out = [ - f"ledger_max_propagate_size_bytes={self.ledger_max_propagate_size_bytes}", + f"ledger_max_txs_size_bytes={self.ledger_max_txs_size_bytes}", f"tx_max_size_bytes={self.tx_max_size_bytes}", - f"fee_propagate_data1_kb={self.fee_propagate_data1_kb}", + f"fee_tx_size1_kb={self.fee_tx_size1_kb}", ] return f"" diff --git a/stellar_sdk/xdr/config_setting_contract_events_v0.py b/stellar_sdk/xdr/config_setting_contract_events_v0.py new file mode 100644 index 00000000..8705cd43 --- /dev/null +++ b/stellar_sdk/xdr/config_setting_contract_events_v0.py @@ -0,0 +1,90 @@ +# This is an automatically generated file. +# DO NOT EDIT or your changes may be overwritten +from __future__ import annotations + +import base64 + +from xdrlib3 import Packer, Unpacker + +from .int64 import Int64 +from .uint32 import Uint32 + +__all__ = ["ConfigSettingContractEventsV0"] + + +class ConfigSettingContractEventsV0: + """ + XDR Source Code:: + + struct ConfigSettingContractEventsV0 + { + // Maximum size of events that a contract call can emit. + uint32 txMaxContractEventsSizeBytes; + // Fee for generating 1KB of contract events. + int64 feeContractEvents1KB; + }; + """ + + def __init__( + self, + tx_max_contract_events_size_bytes: Uint32, + fee_contract_events1_kb: Int64, + ) -> None: + self.tx_max_contract_events_size_bytes = tx_max_contract_events_size_bytes + self.fee_contract_events1_kb = fee_contract_events1_kb + + def pack(self, packer: Packer) -> None: + self.tx_max_contract_events_size_bytes.pack(packer) + self.fee_contract_events1_kb.pack(packer) + + @classmethod + def unpack(cls, unpacker: Unpacker) -> ConfigSettingContractEventsV0: + tx_max_contract_events_size_bytes = Uint32.unpack(unpacker) + fee_contract_events1_kb = Int64.unpack(unpacker) + return cls( + tx_max_contract_events_size_bytes=tx_max_contract_events_size_bytes, + fee_contract_events1_kb=fee_contract_events1_kb, + ) + + def to_xdr_bytes(self) -> bytes: + packer = Packer() + self.pack(packer) + return packer.get_buffer() + + @classmethod + def from_xdr_bytes(cls, xdr: bytes) -> ConfigSettingContractEventsV0: + unpacker = Unpacker(xdr) + return cls.unpack(unpacker) + + def to_xdr(self) -> str: + xdr_bytes = self.to_xdr_bytes() + return base64.b64encode(xdr_bytes).decode() + + @classmethod + def from_xdr(cls, xdr: str) -> ConfigSettingContractEventsV0: + xdr_bytes = base64.b64decode(xdr.encode()) + return cls.from_xdr_bytes(xdr_bytes) + + def __hash__(self): + return hash( + ( + self.tx_max_contract_events_size_bytes, + self.fee_contract_events1_kb, + ) + ) + + def __eq__(self, other: object): + if not isinstance(other, self.__class__): + return NotImplemented + return ( + self.tx_max_contract_events_size_bytes + == other.tx_max_contract_events_size_bytes + and self.fee_contract_events1_kb == other.fee_contract_events1_kb + ) + + def __str__(self): + out = [ + f"tx_max_contract_events_size_bytes={self.tx_max_contract_events_size_bytes}", + f"fee_contract_events1_kb={self.fee_contract_events1_kb}", + ] + return f"" diff --git a/stellar_sdk/xdr/config_setting_contract_ledger_cost_v0.py b/stellar_sdk/xdr/config_setting_contract_ledger_cost_v0.py index 541f7a96..4ad0ee14 100644 --- a/stellar_sdk/xdr/config_setting_contract_ledger_cost_v0.py +++ b/stellar_sdk/xdr/config_setting_contract_ledger_cost_v0.py @@ -40,16 +40,16 @@ class ConfigSettingContractLedgerCostV0: int64 feeWriteLedgerEntry; // Fee per ledger entry write int64 feeRead1KB; // Fee for reading 1KB - int64 feeWrite1KB; // Fee for writing 1KB - - // Bucket list fees grow slowly up to that size - int64 bucketListSizeBytes; - // Fee rate in stroops when the bucket list is empty - int64 bucketListFeeRateLow; - // Fee rate in stroops when the bucket list reached bucketListSizeBytes - int64 bucketListFeeRateHigh; - // Rate multiplier for any additional data past the first bucketListSizeBytes - uint32 bucketListGrowthFactor; + + // The following parameters determine the write fee per 1KB. + // Write fee grows linearly until bucket list reaches this size + int64 bucketListTargetSizeBytes; + // Fee per 1KB write when the bucket list is empty + int64 writeFee1KBBucketListLow; + // Fee per 1KB write when the bucket list has reached `bucketListTargetSizeBytes` + int64 writeFee1KBBucketListHigh; + // Write fee multiplier for any additional data past the first `bucketListTargetSizeBytes` + uint32 bucketListWriteFeeGrowthFactor; }; """ @@ -66,11 +66,10 @@ def __init__( fee_read_ledger_entry: Int64, fee_write_ledger_entry: Int64, fee_read1_kb: Int64, - fee_write1_kb: Int64, - bucket_list_size_bytes: Int64, - bucket_list_fee_rate_low: Int64, - bucket_list_fee_rate_high: Int64, - bucket_list_growth_factor: Uint32, + bucket_list_target_size_bytes: Int64, + write_fee1_kb_bucket_list_low: Int64, + write_fee1_kb_bucket_list_high: Int64, + bucket_list_write_fee_growth_factor: Uint32, ) -> None: self.ledger_max_read_ledger_entries = ledger_max_read_ledger_entries self.ledger_max_read_bytes = ledger_max_read_bytes @@ -83,11 +82,10 @@ def __init__( self.fee_read_ledger_entry = fee_read_ledger_entry self.fee_write_ledger_entry = fee_write_ledger_entry self.fee_read1_kb = fee_read1_kb - self.fee_write1_kb = fee_write1_kb - self.bucket_list_size_bytes = bucket_list_size_bytes - self.bucket_list_fee_rate_low = bucket_list_fee_rate_low - self.bucket_list_fee_rate_high = bucket_list_fee_rate_high - self.bucket_list_growth_factor = bucket_list_growth_factor + self.bucket_list_target_size_bytes = bucket_list_target_size_bytes + self.write_fee1_kb_bucket_list_low = write_fee1_kb_bucket_list_low + self.write_fee1_kb_bucket_list_high = write_fee1_kb_bucket_list_high + self.bucket_list_write_fee_growth_factor = bucket_list_write_fee_growth_factor def pack(self, packer: Packer) -> None: self.ledger_max_read_ledger_entries.pack(packer) @@ -101,11 +99,10 @@ def pack(self, packer: Packer) -> None: self.fee_read_ledger_entry.pack(packer) self.fee_write_ledger_entry.pack(packer) self.fee_read1_kb.pack(packer) - self.fee_write1_kb.pack(packer) - self.bucket_list_size_bytes.pack(packer) - self.bucket_list_fee_rate_low.pack(packer) - self.bucket_list_fee_rate_high.pack(packer) - self.bucket_list_growth_factor.pack(packer) + self.bucket_list_target_size_bytes.pack(packer) + self.write_fee1_kb_bucket_list_low.pack(packer) + self.write_fee1_kb_bucket_list_high.pack(packer) + self.bucket_list_write_fee_growth_factor.pack(packer) @classmethod def unpack(cls, unpacker: Unpacker) -> ConfigSettingContractLedgerCostV0: @@ -120,11 +117,10 @@ def unpack(cls, unpacker: Unpacker) -> ConfigSettingContractLedgerCostV0: fee_read_ledger_entry = Int64.unpack(unpacker) fee_write_ledger_entry = Int64.unpack(unpacker) fee_read1_kb = Int64.unpack(unpacker) - fee_write1_kb = Int64.unpack(unpacker) - bucket_list_size_bytes = Int64.unpack(unpacker) - bucket_list_fee_rate_low = Int64.unpack(unpacker) - bucket_list_fee_rate_high = Int64.unpack(unpacker) - bucket_list_growth_factor = Uint32.unpack(unpacker) + bucket_list_target_size_bytes = Int64.unpack(unpacker) + write_fee1_kb_bucket_list_low = Int64.unpack(unpacker) + write_fee1_kb_bucket_list_high = Int64.unpack(unpacker) + bucket_list_write_fee_growth_factor = Uint32.unpack(unpacker) return cls( ledger_max_read_ledger_entries=ledger_max_read_ledger_entries, ledger_max_read_bytes=ledger_max_read_bytes, @@ -137,11 +133,10 @@ def unpack(cls, unpacker: Unpacker) -> ConfigSettingContractLedgerCostV0: fee_read_ledger_entry=fee_read_ledger_entry, fee_write_ledger_entry=fee_write_ledger_entry, fee_read1_kb=fee_read1_kb, - fee_write1_kb=fee_write1_kb, - bucket_list_size_bytes=bucket_list_size_bytes, - bucket_list_fee_rate_low=bucket_list_fee_rate_low, - bucket_list_fee_rate_high=bucket_list_fee_rate_high, - bucket_list_growth_factor=bucket_list_growth_factor, + bucket_list_target_size_bytes=bucket_list_target_size_bytes, + write_fee1_kb_bucket_list_low=write_fee1_kb_bucket_list_low, + write_fee1_kb_bucket_list_high=write_fee1_kb_bucket_list_high, + bucket_list_write_fee_growth_factor=bucket_list_write_fee_growth_factor, ) def to_xdr_bytes(self) -> bytes: @@ -177,11 +172,10 @@ def __hash__(self): self.fee_read_ledger_entry, self.fee_write_ledger_entry, self.fee_read1_kb, - self.fee_write1_kb, - self.bucket_list_size_bytes, - self.bucket_list_fee_rate_low, - self.bucket_list_fee_rate_high, - self.bucket_list_growth_factor, + self.bucket_list_target_size_bytes, + self.write_fee1_kb_bucket_list_low, + self.write_fee1_kb_bucket_list_high, + self.bucket_list_write_fee_growth_factor, ) ) @@ -201,11 +195,14 @@ def __eq__(self, other: object): and self.fee_read_ledger_entry == other.fee_read_ledger_entry and self.fee_write_ledger_entry == other.fee_write_ledger_entry and self.fee_read1_kb == other.fee_read1_kb - and self.fee_write1_kb == other.fee_write1_kb - and self.bucket_list_size_bytes == other.bucket_list_size_bytes - and self.bucket_list_fee_rate_low == other.bucket_list_fee_rate_low - and self.bucket_list_fee_rate_high == other.bucket_list_fee_rate_high - and self.bucket_list_growth_factor == other.bucket_list_growth_factor + and self.bucket_list_target_size_bytes + == other.bucket_list_target_size_bytes + and self.write_fee1_kb_bucket_list_low + == other.write_fee1_kb_bucket_list_low + and self.write_fee1_kb_bucket_list_high + == other.write_fee1_kb_bucket_list_high + and self.bucket_list_write_fee_growth_factor + == other.bucket_list_write_fee_growth_factor ) def __str__(self): @@ -221,10 +218,9 @@ def __str__(self): f"fee_read_ledger_entry={self.fee_read_ledger_entry}", f"fee_write_ledger_entry={self.fee_write_ledger_entry}", f"fee_read1_kb={self.fee_read1_kb}", - f"fee_write1_kb={self.fee_write1_kb}", - f"bucket_list_size_bytes={self.bucket_list_size_bytes}", - f"bucket_list_fee_rate_low={self.bucket_list_fee_rate_low}", - f"bucket_list_fee_rate_high={self.bucket_list_fee_rate_high}", - f"bucket_list_growth_factor={self.bucket_list_growth_factor}", + f"bucket_list_target_size_bytes={self.bucket_list_target_size_bytes}", + f"write_fee1_kb_bucket_list_low={self.write_fee1_kb_bucket_list_low}", + f"write_fee1_kb_bucket_list_high={self.write_fee1_kb_bucket_list_high}", + f"bucket_list_write_fee_growth_factor={self.bucket_list_write_fee_growth_factor}", ] return f"" diff --git a/stellar_sdk/xdr/config_setting_contract_meta_data_v0.py b/stellar_sdk/xdr/config_setting_contract_meta_data_v0.py deleted file mode 100644 index 105edbc8..00000000 --- a/stellar_sdk/xdr/config_setting_contract_meta_data_v0.py +++ /dev/null @@ -1,90 +0,0 @@ -# This is an automatically generated file. -# DO NOT EDIT or your changes may be overwritten -from __future__ import annotations - -import base64 - -from xdrlib3 import Packer, Unpacker - -from .int64 import Int64 -from .uint32 import Uint32 - -__all__ = ["ConfigSettingContractMetaDataV0"] - - -class ConfigSettingContractMetaDataV0: - """ - XDR Source Code:: - - struct ConfigSettingContractMetaDataV0 - { - // Maximum size of extended meta data produced by a transaction - uint32 txMaxExtendedMetaDataSizeBytes; - // Fee for generating 1KB of extended meta data - int64 feeExtendedMetaData1KB; - }; - """ - - def __init__( - self, - tx_max_extended_meta_data_size_bytes: Uint32, - fee_extended_meta_data1_kb: Int64, - ) -> None: - self.tx_max_extended_meta_data_size_bytes = tx_max_extended_meta_data_size_bytes - self.fee_extended_meta_data1_kb = fee_extended_meta_data1_kb - - def pack(self, packer: Packer) -> None: - self.tx_max_extended_meta_data_size_bytes.pack(packer) - self.fee_extended_meta_data1_kb.pack(packer) - - @classmethod - def unpack(cls, unpacker: Unpacker) -> ConfigSettingContractMetaDataV0: - tx_max_extended_meta_data_size_bytes = Uint32.unpack(unpacker) - fee_extended_meta_data1_kb = Int64.unpack(unpacker) - return cls( - tx_max_extended_meta_data_size_bytes=tx_max_extended_meta_data_size_bytes, - fee_extended_meta_data1_kb=fee_extended_meta_data1_kb, - ) - - def to_xdr_bytes(self) -> bytes: - packer = Packer() - self.pack(packer) - return packer.get_buffer() - - @classmethod - def from_xdr_bytes(cls, xdr: bytes) -> ConfigSettingContractMetaDataV0: - unpacker = Unpacker(xdr) - return cls.unpack(unpacker) - - def to_xdr(self) -> str: - xdr_bytes = self.to_xdr_bytes() - return base64.b64encode(xdr_bytes).decode() - - @classmethod - def from_xdr(cls, xdr: str) -> ConfigSettingContractMetaDataV0: - xdr_bytes = base64.b64decode(xdr.encode()) - return cls.from_xdr_bytes(xdr_bytes) - - def __hash__(self): - return hash( - ( - self.tx_max_extended_meta_data_size_bytes, - self.fee_extended_meta_data1_kb, - ) - ) - - def __eq__(self, other: object): - if not isinstance(other, self.__class__): - return NotImplemented - return ( - self.tx_max_extended_meta_data_size_bytes - == other.tx_max_extended_meta_data_size_bytes - and self.fee_extended_meta_data1_kb == other.fee_extended_meta_data1_kb - ) - - def __str__(self): - out = [ - f"tx_max_extended_meta_data_size_bytes={self.tx_max_extended_meta_data_size_bytes}", - f"fee_extended_meta_data1_kb={self.fee_extended_meta_data1_kb}", - ] - return f"" diff --git a/stellar_sdk/xdr/config_setting_entry.py b/stellar_sdk/xdr/config_setting_entry.py index 08d233ee..59e77d1f 100644 --- a/stellar_sdk/xdr/config_setting_entry.py +++ b/stellar_sdk/xdr/config_setting_entry.py @@ -9,6 +9,7 @@ from .config_setting_contract_bandwidth_v0 import ConfigSettingContractBandwidthV0 from .config_setting_contract_compute_v0 import ConfigSettingContractComputeV0 +from .config_setting_contract_events_v0 import ConfigSettingContractEventsV0 from .config_setting_contract_execution_lanes_v0 import ( ConfigSettingContractExecutionLanesV0, ) @@ -16,9 +17,9 @@ ConfigSettingContractHistoricalDataV0, ) from .config_setting_contract_ledger_cost_v0 import ConfigSettingContractLedgerCostV0 -from .config_setting_contract_meta_data_v0 import ConfigSettingContractMetaDataV0 from .config_setting_id import ConfigSettingID from .contract_cost_params import ContractCostParams +from .eviction_iterator import EvictionIterator from .state_expiration_settings import StateExpirationSettings from .uint32 import Uint32 from .uint64 import Uint64 @@ -40,8 +41,8 @@ class ConfigSettingEntry: ConfigSettingContractLedgerCostV0 contractLedgerCost; case CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0: ConfigSettingContractHistoricalDataV0 contractHistoricalData; - case CONFIG_SETTING_CONTRACT_META_DATA_V0: - ConfigSettingContractMetaDataV0 contractMetaData; + case CONFIG_SETTING_CONTRACT_EVENTS_V0: + ConfigSettingContractEventsV0 contractEvents; case CONFIG_SETTING_CONTRACT_BANDWIDTH_V0: ConfigSettingContractBandwidthV0 contractBandwidth; case CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS: @@ -58,6 +59,8 @@ class ConfigSettingEntry: ConfigSettingContractExecutionLanesV0 contractExecutionLanes; case CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW: uint64 bucketListSizeWindow<>; + case CONFIG_SETTING_EVICTION_ITERATOR: + EvictionIterator evictionIterator; }; """ @@ -68,7 +71,7 @@ def __init__( contract_compute: ConfigSettingContractComputeV0 = None, contract_ledger_cost: ConfigSettingContractLedgerCostV0 = None, contract_historical_data: ConfigSettingContractHistoricalDataV0 = None, - contract_meta_data: ConfigSettingContractMetaDataV0 = None, + contract_events: ConfigSettingContractEventsV0 = None, contract_bandwidth: ConfigSettingContractBandwidthV0 = None, contract_cost_params_cpu_insns: ContractCostParams = None, contract_cost_params_mem_bytes: ContractCostParams = None, @@ -77,6 +80,7 @@ def __init__( state_expiration_settings: StateExpirationSettings = None, contract_execution_lanes: ConfigSettingContractExecutionLanesV0 = None, bucket_list_size_window: List[Uint64] = None, + eviction_iterator: EvictionIterator = None, ) -> None: _expect_max_length = 4294967295 if ( @@ -91,7 +95,7 @@ def __init__( self.contract_compute = contract_compute self.contract_ledger_cost = contract_ledger_cost self.contract_historical_data = contract_historical_data - self.contract_meta_data = contract_meta_data + self.contract_events = contract_events self.contract_bandwidth = contract_bandwidth self.contract_cost_params_cpu_insns = contract_cost_params_cpu_insns self.contract_cost_params_mem_bytes = contract_cost_params_mem_bytes @@ -100,6 +104,7 @@ def __init__( self.state_expiration_settings = state_expiration_settings self.contract_execution_lanes = contract_execution_lanes self.bucket_list_size_window = bucket_list_size_window + self.eviction_iterator = eviction_iterator def pack(self, packer: Packer) -> None: self.config_setting_id.pack(packer) @@ -132,13 +137,10 @@ def pack(self, packer: Packer) -> None: raise ValueError("contract_historical_data should not be None.") self.contract_historical_data.pack(packer) return - if ( - self.config_setting_id - == ConfigSettingID.CONFIG_SETTING_CONTRACT_META_DATA_V0 - ): - if self.contract_meta_data is None: - raise ValueError("contract_meta_data should not be None.") - self.contract_meta_data.pack(packer) + if self.config_setting_id == ConfigSettingID.CONFIG_SETTING_CONTRACT_EVENTS_V0: + if self.contract_events is None: + raise ValueError("contract_events should not be None.") + self.contract_events.pack(packer) return if ( self.config_setting_id @@ -203,6 +205,11 @@ def pack(self, packer: Packer) -> None: for bucket_list_size_window_item in self.bucket_list_size_window: bucket_list_size_window_item.pack(packer) return + if self.config_setting_id == ConfigSettingID.CONFIG_SETTING_EVICTION_ITERATOR: + if self.eviction_iterator is None: + raise ValueError("eviction_iterator should not be None.") + self.eviction_iterator.pack(packer) + return @classmethod def unpack(cls, unpacker: Unpacker) -> ConfigSettingEntry: @@ -235,11 +242,10 @@ def unpack(cls, unpacker: Unpacker) -> ConfigSettingEntry: config_setting_id=config_setting_id, contract_historical_data=contract_historical_data, ) - if config_setting_id == ConfigSettingID.CONFIG_SETTING_CONTRACT_META_DATA_V0: - contract_meta_data = ConfigSettingContractMetaDataV0.unpack(unpacker) + if config_setting_id == ConfigSettingID.CONFIG_SETTING_CONTRACT_EVENTS_V0: + contract_events = ConfigSettingContractEventsV0.unpack(unpacker) return cls( - config_setting_id=config_setting_id, - contract_meta_data=contract_meta_data, + config_setting_id=config_setting_id, contract_events=contract_events ) if config_setting_id == ConfigSettingID.CONFIG_SETTING_CONTRACT_BANDWIDTH_V0: contract_bandwidth = ConfigSettingContractBandwidthV0.unpack(unpacker) @@ -306,6 +312,11 @@ def unpack(cls, unpacker: Unpacker) -> ConfigSettingEntry: config_setting_id=config_setting_id, bucket_list_size_window=bucket_list_size_window, ) + if config_setting_id == ConfigSettingID.CONFIG_SETTING_EVICTION_ITERATOR: + eviction_iterator = EvictionIterator.unpack(unpacker) + return cls( + config_setting_id=config_setting_id, eviction_iterator=eviction_iterator + ) return cls(config_setting_id=config_setting_id) def to_xdr_bytes(self) -> bytes: @@ -335,7 +346,7 @@ def __hash__(self): self.contract_compute, self.contract_ledger_cost, self.contract_historical_data, - self.contract_meta_data, + self.contract_events, self.contract_bandwidth, self.contract_cost_params_cpu_insns, self.contract_cost_params_mem_bytes, @@ -344,6 +355,7 @@ def __hash__(self): self.state_expiration_settings, self.contract_execution_lanes, self.bucket_list_size_window, + self.eviction_iterator, ) ) @@ -356,7 +368,7 @@ def __eq__(self, other: object): and self.contract_compute == other.contract_compute and self.contract_ledger_cost == other.contract_ledger_cost and self.contract_historical_data == other.contract_historical_data - and self.contract_meta_data == other.contract_meta_data + and self.contract_events == other.contract_events and self.contract_bandwidth == other.contract_bandwidth and self.contract_cost_params_cpu_insns == other.contract_cost_params_cpu_insns @@ -368,6 +380,7 @@ def __eq__(self, other: object): and self.state_expiration_settings == other.state_expiration_settings and self.contract_execution_lanes == other.contract_execution_lanes and self.bucket_list_size_window == other.bucket_list_size_window + and self.eviction_iterator == other.eviction_iterator ) def __str__(self): @@ -386,8 +399,8 @@ def __str__(self): f"contract_historical_data={self.contract_historical_data}" ) if self.contract_historical_data is not None else None out.append( - f"contract_meta_data={self.contract_meta_data}" - ) if self.contract_meta_data is not None else None + f"contract_events={self.contract_events}" + ) if self.contract_events is not None else None out.append( f"contract_bandwidth={self.contract_bandwidth}" ) if self.contract_bandwidth is not None else None @@ -412,4 +425,7 @@ def __str__(self): out.append( f"bucket_list_size_window={self.bucket_list_size_window}" ) if self.bucket_list_size_window is not None else None + out.append( + f"eviction_iterator={self.eviction_iterator}" + ) if self.eviction_iterator is not None else None return f"" diff --git a/stellar_sdk/xdr/config_setting_id.py b/stellar_sdk/xdr/config_setting_id.py index e1c582eb..c176dc4b 100644 --- a/stellar_sdk/xdr/config_setting_id.py +++ b/stellar_sdk/xdr/config_setting_id.py @@ -20,7 +20,7 @@ class ConfigSettingID(IntEnum): CONFIG_SETTING_CONTRACT_COMPUTE_V0 = 1, CONFIG_SETTING_CONTRACT_LEDGER_COST_V0 = 2, CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0 = 3, - CONFIG_SETTING_CONTRACT_META_DATA_V0 = 4, + CONFIG_SETTING_CONTRACT_EVENTS_V0 = 4, CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 = 5, CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS = 6, CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES = 7, @@ -28,7 +28,8 @@ class ConfigSettingID(IntEnum): CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES = 9, CONFIG_SETTING_STATE_EXPIRATION = 10, CONFIG_SETTING_CONTRACT_EXECUTION_LANES = 11, - CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW = 12 + CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW = 12, + CONFIG_SETTING_EVICTION_ITERATOR = 13 }; """ @@ -36,7 +37,7 @@ class ConfigSettingID(IntEnum): CONFIG_SETTING_CONTRACT_COMPUTE_V0 = 1 CONFIG_SETTING_CONTRACT_LEDGER_COST_V0 = 2 CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0 = 3 - CONFIG_SETTING_CONTRACT_META_DATA_V0 = 4 + CONFIG_SETTING_CONTRACT_EVENTS_V0 = 4 CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 = 5 CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS = 6 CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES = 7 @@ -45,6 +46,7 @@ class ConfigSettingID(IntEnum): CONFIG_SETTING_STATE_EXPIRATION = 10 CONFIG_SETTING_CONTRACT_EXECUTION_LANES = 11 CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW = 12 + CONFIG_SETTING_EVICTION_ITERATOR = 13 def pack(self, packer: Packer) -> None: packer.pack_int(self.value) diff --git a/stellar_sdk/xdr/constants.py b/stellar_sdk/xdr/constants.py index b7e9a4b5..6b9e14dd 100644 --- a/stellar_sdk/xdr/constants.py +++ b/stellar_sdk/xdr/constants.py @@ -16,10 +16,8 @@ MASK_OFFERENTRY_FLAGS: int = 1 #: const MASK_CLAIMABLE_BALANCE_FLAGS = 0x1; MASK_CLAIMABLE_BALANCE_FLAGS: int = 0x1 -#: const MASK_CONTRACT_DATA_FLAGS_V20 = 0x1; -MASK_CONTRACT_DATA_FLAGS_V20: int = 0x1 -#: const MASK_LEDGER_HEADER_FLAGS = 0x7F; -MASK_LEDGER_HEADER_FLAGS: int = 0x7F +#: const MASK_LEDGER_HEADER_FLAGS = 0x7; +MASK_LEDGER_HEADER_FLAGS: int = 0x7 #: const AUTH_MSG_FLAG_FLOW_CONTROL_BYTES_REQUESTED = 200; AUTH_MSG_FLAG_FLOW_CONTROL_BYTES_REQUESTED: int = 200 #: const TX_ADVERT_VECTOR_MAX_SIZE = 1000; diff --git a/stellar_sdk/xdr/contract_code_entry.py b/stellar_sdk/xdr/contract_code_entry.py index fc697dfb..f2ea28b3 100644 --- a/stellar_sdk/xdr/contract_code_entry.py +++ b/stellar_sdk/xdr/contract_code_entry.py @@ -6,10 +6,9 @@ from xdrlib3 import Packer, Unpacker -from .contract_code_entry_body import ContractCodeEntryBody +from .base import Opaque from .extension_point import ExtensionPoint from .hash import Hash -from .uint32 import Uint32 __all__ = ["ContractCodeEntry"] @@ -22,15 +21,7 @@ class ContractCodeEntry: ExtensionPoint ext; Hash hash; - union switch (ContractEntryBodyType bodyType) - { - case DATA_ENTRY: - opaque code<>; - case EXPIRATION_EXTENSION: - void; - } body; - - uint32 expirationLedgerSeq; + opaque code<>; }; """ @@ -38,31 +29,26 @@ def __init__( self, ext: ExtensionPoint, hash: Hash, - body: ContractCodeEntryBody, - expiration_ledger_seq: Uint32, + code: bytes, ) -> None: self.ext = ext self.hash = hash - self.body = body - self.expiration_ledger_seq = expiration_ledger_seq + self.code = code def pack(self, packer: Packer) -> None: self.ext.pack(packer) self.hash.pack(packer) - self.body.pack(packer) - self.expiration_ledger_seq.pack(packer) + Opaque(self.code, 4294967295, False).pack(packer) @classmethod def unpack(cls, unpacker: Unpacker) -> ContractCodeEntry: ext = ExtensionPoint.unpack(unpacker) hash = Hash.unpack(unpacker) - body = ContractCodeEntryBody.unpack(unpacker) - expiration_ledger_seq = Uint32.unpack(unpacker) + code = Opaque.unpack(unpacker, 4294967295, False) return cls( ext=ext, hash=hash, - body=body, - expiration_ledger_seq=expiration_ledger_seq, + code=code, ) def to_xdr_bytes(self) -> bytes: @@ -89,8 +75,7 @@ def __hash__(self): ( self.ext, self.hash, - self.body, - self.expiration_ledger_seq, + self.code, ) ) @@ -100,15 +85,13 @@ def __eq__(self, other: object): return ( self.ext == other.ext and self.hash == other.hash - and self.body == other.body - and self.expiration_ledger_seq == other.expiration_ledger_seq + and self.code == other.code ) def __str__(self): out = [ f"ext={self.ext}", f"hash={self.hash}", - f"body={self.body}", - f"expiration_ledger_seq={self.expiration_ledger_seq}", + f"code={self.code}", ] return f"" diff --git a/stellar_sdk/xdr/contract_code_entry_body.py b/stellar_sdk/xdr/contract_code_entry_body.py deleted file mode 100644 index 6c30e7fe..00000000 --- a/stellar_sdk/xdr/contract_code_entry_body.py +++ /dev/null @@ -1,92 +0,0 @@ -# This is an automatically generated file. -# DO NOT EDIT or your changes may be overwritten -from __future__ import annotations - -import base64 - -from xdrlib3 import Packer, Unpacker - -from .base import Opaque -from .contract_entry_body_type import ContractEntryBodyType - -__all__ = ["ContractCodeEntryBody"] - - -class ContractCodeEntryBody: - """ - XDR Source Code:: - - union switch (ContractEntryBodyType bodyType) - { - case DATA_ENTRY: - opaque code<>; - case EXPIRATION_EXTENSION: - void; - } - """ - - def __init__( - self, - body_type: ContractEntryBodyType, - code: bytes = None, - ) -> None: - self.body_type = body_type - self.code = code - - def pack(self, packer: Packer) -> None: - self.body_type.pack(packer) - if self.body_type == ContractEntryBodyType.DATA_ENTRY: - if self.code is None: - raise ValueError("code should not be None.") - Opaque(self.code, 4294967295, False).pack(packer) - return - if self.body_type == ContractEntryBodyType.EXPIRATION_EXTENSION: - return - - @classmethod - def unpack(cls, unpacker: Unpacker) -> ContractCodeEntryBody: - body_type = ContractEntryBodyType.unpack(unpacker) - if body_type == ContractEntryBodyType.DATA_ENTRY: - code = Opaque.unpack(unpacker, 4294967295, False) - return cls(body_type=body_type, code=code) - if body_type == ContractEntryBodyType.EXPIRATION_EXTENSION: - return cls(body_type=body_type) - return cls(body_type=body_type) - - def to_xdr_bytes(self) -> bytes: - packer = Packer() - self.pack(packer) - return packer.get_buffer() - - @classmethod - def from_xdr_bytes(cls, xdr: bytes) -> ContractCodeEntryBody: - unpacker = Unpacker(xdr) - return cls.unpack(unpacker) - - def to_xdr(self) -> str: - xdr_bytes = self.to_xdr_bytes() - return base64.b64encode(xdr_bytes).decode() - - @classmethod - def from_xdr(cls, xdr: str) -> ContractCodeEntryBody: - xdr_bytes = base64.b64decode(xdr.encode()) - return cls.from_xdr_bytes(xdr_bytes) - - def __hash__(self): - return hash( - ( - self.body_type, - self.code, - ) - ) - - def __eq__(self, other: object): - if not isinstance(other, self.__class__): - return NotImplemented - return self.body_type == other.body_type and self.code == other.code - - def __str__(self): - out = [] - out.append(f"body_type={self.body_type}") - out.append(f"code={self.code}") if self.code is not None else None - return f"" diff --git a/stellar_sdk/xdr/contract_cost_type.py b/stellar_sdk/xdr/contract_cost_type.py index 012a62d2..afbb30e1 100644 --- a/stellar_sdk/xdr/contract_cost_type.py +++ b/stellar_sdk/xdr/contract_cost_type.py @@ -25,61 +25,56 @@ class ContractCostType(IntEnum): HostMemCpy = 3, // Cost of comparing two slices of host memory HostMemCmp = 4, - // Cost of a host function invocation, not including the actual work done by the function - InvokeHostFunction = 5, - // Cost of visiting a host object from the host object storage - // Only thing to make sure is the guest can't visitObject repeatly without incurring some charges elsewhere. + // Cost of a host function dispatch, not including the actual work done by + // the function nor the cost of VM invocation machinary + DispatchHostFunction = 5, + // Cost of visiting a host object from the host object storage. Exists to + // make sure some baseline cost coverage, i.e. repeatly visiting objects + // by the guest will always incur some charges. VisitObject = 6, - // Tracks a single Val (RawVal or primative Object like U64) <=> ScVal - // conversion cost. Most of these Val counterparts in ScVal (except e.g. - // Symbol) consumes a single int64 and therefore is a constant overhead. - ValXdrConv = 7, // Cost of serializing an xdr object to bytes - ValSer = 8, + ValSer = 7, // Cost of deserializing an xdr object from bytes - ValDeser = 9, + ValDeser = 8, // Cost of computing the sha256 hash from bytes - ComputeSha256Hash = 10, + ComputeSha256Hash = 9, // Cost of computing the ed25519 pubkey from bytes - ComputeEd25519PubKey = 11, + ComputeEd25519PubKey = 10, // Cost of accessing an entry in a Map. - MapEntry = 12, + MapEntry = 11, // Cost of accessing an entry in a Vec - VecEntry = 13, - // Cost of guarding a frame, which involves pushing and poping a frame and capturing a rollback point. - GuardFrame = 14, + VecEntry = 12, // Cost of verifying ed25519 signature of a payload. - VerifyEd25519Sig = 15, + VerifyEd25519Sig = 13, // Cost of reading a slice of vm linear memory - VmMemRead = 16, + VmMemRead = 14, // Cost of writing to a slice of vm linear memory - VmMemWrite = 17, + VmMemWrite = 15, // Cost of instantiation a VM from wasm bytes code. - VmInstantiation = 18, + VmInstantiation = 16, // Cost of instantiation a VM from a cached state. - VmCachedInstantiation = 19, - // Roundtrip cost of invoking a VM function from the host. - InvokeVmFunction = 20, - // Cost of charging a value to the budgeting system. - ChargeBudget = 21, + VmCachedInstantiation = 17, + // Cost of invoking a function on the VM. If the function is a host function, + // additional cost will be covered by `DispatchHostFunction`. + InvokeVmFunction = 18, // Cost of computing a keccak256 hash from bytes. - ComputeKeccak256Hash = 22, + ComputeKeccak256Hash = 19, // Cost of computing an ECDSA secp256k1 pubkey from bytes. - ComputeEcdsaSecp256k1Key = 23, + ComputeEcdsaSecp256k1Key = 20, // Cost of computing an ECDSA secp256k1 signature from bytes. - ComputeEcdsaSecp256k1Sig = 24, + ComputeEcdsaSecp256k1Sig = 21, // Cost of recovering an ECDSA secp256k1 key from a signature. - RecoverEcdsaSecp256k1Key = 25, + RecoverEcdsaSecp256k1Key = 22, // Cost of int256 addition (`+`) and subtraction (`-`) operations - Int256AddSub = 26, + Int256AddSub = 23, // Cost of int256 multiplication (`*`) operation - Int256Mul = 27, + Int256Mul = 24, // Cost of int256 division (`/`) operation - Int256Div = 28, + Int256Div = 25, // Cost of int256 power (`exp`) operation - Int256Pow = 29, + Int256Pow = 26, // Cost of int256 shift (`shl`, `shr`) operation - Int256Shift = 30 + Int256Shift = 27 }; """ @@ -88,32 +83,29 @@ class ContractCostType(IntEnum): HostMemAlloc = 2 HostMemCpy = 3 HostMemCmp = 4 - InvokeHostFunction = 5 + DispatchHostFunction = 5 VisitObject = 6 - ValXdrConv = 7 - ValSer = 8 - ValDeser = 9 - ComputeSha256Hash = 10 - ComputeEd25519PubKey = 11 - MapEntry = 12 - VecEntry = 13 - GuardFrame = 14 - VerifyEd25519Sig = 15 - VmMemRead = 16 - VmMemWrite = 17 - VmInstantiation = 18 - VmCachedInstantiation = 19 - InvokeVmFunction = 20 - ChargeBudget = 21 - ComputeKeccak256Hash = 22 - ComputeEcdsaSecp256k1Key = 23 - ComputeEcdsaSecp256k1Sig = 24 - RecoverEcdsaSecp256k1Key = 25 - Int256AddSub = 26 - Int256Mul = 27 - Int256Div = 28 - Int256Pow = 29 - Int256Shift = 30 + 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 def pack(self, packer: Packer) -> None: packer.pack_int(self.value) diff --git a/stellar_sdk/xdr/contract_data_entry.py b/stellar_sdk/xdr/contract_data_entry.py index f288a517..11ef3a86 100644 --- a/stellar_sdk/xdr/contract_data_entry.py +++ b/stellar_sdk/xdr/contract_data_entry.py @@ -7,10 +7,9 @@ from xdrlib3 import Packer, Unpacker from .contract_data_durability import ContractDataDurability -from .contract_data_entry_body import ContractDataEntryBody +from .extension_point import ExtensionPoint from .sc_address import SCAddress from .sc_val import SCVal -from .uint32 import Uint32 __all__ = ["ContractDataEntry"] @@ -20,60 +19,49 @@ class ContractDataEntry: XDR Source Code:: struct ContractDataEntry { + ExtensionPoint ext; + SCAddress contract; SCVal key; ContractDataDurability durability; - - union switch (ContractEntryBodyType bodyType) - { - case DATA_ENTRY: - struct - { - uint32 flags; - SCVal val; - } data; - case EXPIRATION_EXTENSION: - void; - } body; - - uint32 expirationLedgerSeq; + SCVal val; }; """ def __init__( self, + ext: ExtensionPoint, contract: SCAddress, key: SCVal, durability: ContractDataDurability, - body: ContractDataEntryBody, - expiration_ledger_seq: Uint32, + val: SCVal, ) -> None: + self.ext = ext self.contract = contract self.key = key self.durability = durability - self.body = body - self.expiration_ledger_seq = expiration_ledger_seq + self.val = val def pack(self, packer: Packer) -> None: + self.ext.pack(packer) self.contract.pack(packer) self.key.pack(packer) self.durability.pack(packer) - self.body.pack(packer) - self.expiration_ledger_seq.pack(packer) + self.val.pack(packer) @classmethod def unpack(cls, unpacker: Unpacker) -> ContractDataEntry: + ext = ExtensionPoint.unpack(unpacker) contract = SCAddress.unpack(unpacker) key = SCVal.unpack(unpacker) durability = ContractDataDurability.unpack(unpacker) - body = ContractDataEntryBody.unpack(unpacker) - expiration_ledger_seq = Uint32.unpack(unpacker) + val = SCVal.unpack(unpacker) return cls( + ext=ext, contract=contract, key=key, durability=durability, - body=body, - expiration_ledger_seq=expiration_ledger_seq, + val=val, ) def to_xdr_bytes(self) -> bytes: @@ -98,11 +86,11 @@ def from_xdr(cls, xdr: str) -> ContractDataEntry: def __hash__(self): return hash( ( + self.ext, self.contract, self.key, self.durability, - self.body, - self.expiration_ledger_seq, + self.val, ) ) @@ -110,19 +98,19 @@ def __eq__(self, other: object): if not isinstance(other, self.__class__): return NotImplemented return ( - self.contract == other.contract + self.ext == other.ext + and self.contract == other.contract and self.key == other.key and self.durability == other.durability - and self.body == other.body - and self.expiration_ledger_seq == other.expiration_ledger_seq + and self.val == other.val ) def __str__(self): out = [ + f"ext={self.ext}", f"contract={self.contract}", f"key={self.key}", f"durability={self.durability}", - f"body={self.body}", - f"expiration_ledger_seq={self.expiration_ledger_seq}", + f"val={self.val}", ] return f"" diff --git a/stellar_sdk/xdr/contract_data_entry_body.py b/stellar_sdk/xdr/contract_data_entry_body.py deleted file mode 100644 index 6dec2a27..00000000 --- a/stellar_sdk/xdr/contract_data_entry_body.py +++ /dev/null @@ -1,96 +0,0 @@ -# This is an automatically generated file. -# DO NOT EDIT or your changes may be overwritten -from __future__ import annotations - -import base64 - -from xdrlib3 import Packer, Unpacker - -from .contract_data_entry_data import ContractDataEntryData -from .contract_entry_body_type import ContractEntryBodyType - -__all__ = ["ContractDataEntryBody"] - - -class ContractDataEntryBody: - """ - XDR Source Code:: - - union switch (ContractEntryBodyType bodyType) - { - case DATA_ENTRY: - struct - { - uint32 flags; - SCVal val; - } data; - case EXPIRATION_EXTENSION: - void; - } - """ - - def __init__( - self, - body_type: ContractEntryBodyType, - data: ContractDataEntryData = None, - ) -> None: - self.body_type = body_type - self.data = data - - def pack(self, packer: Packer) -> None: - self.body_type.pack(packer) - if self.body_type == ContractEntryBodyType.DATA_ENTRY: - if self.data is None: - raise ValueError("data should not be None.") - self.data.pack(packer) - return - if self.body_type == ContractEntryBodyType.EXPIRATION_EXTENSION: - return - - @classmethod - def unpack(cls, unpacker: Unpacker) -> ContractDataEntryBody: - body_type = ContractEntryBodyType.unpack(unpacker) - if body_type == ContractEntryBodyType.DATA_ENTRY: - data = ContractDataEntryData.unpack(unpacker) - return cls(body_type=body_type, data=data) - if body_type == ContractEntryBodyType.EXPIRATION_EXTENSION: - return cls(body_type=body_type) - return cls(body_type=body_type) - - def to_xdr_bytes(self) -> bytes: - packer = Packer() - self.pack(packer) - return packer.get_buffer() - - @classmethod - def from_xdr_bytes(cls, xdr: bytes) -> ContractDataEntryBody: - unpacker = Unpacker(xdr) - return cls.unpack(unpacker) - - def to_xdr(self) -> str: - xdr_bytes = self.to_xdr_bytes() - return base64.b64encode(xdr_bytes).decode() - - @classmethod - def from_xdr(cls, xdr: str) -> ContractDataEntryBody: - xdr_bytes = base64.b64decode(xdr.encode()) - return cls.from_xdr_bytes(xdr_bytes) - - def __hash__(self): - return hash( - ( - self.body_type, - self.data, - ) - ) - - def __eq__(self, other: object): - if not isinstance(other, self.__class__): - return NotImplemented - return self.body_type == other.body_type and self.data == other.data - - def __str__(self): - out = [] - out.append(f"body_type={self.body_type}") - out.append(f"data={self.data}") if self.data is not None else None - return f"" diff --git a/stellar_sdk/xdr/contract_data_entry_data.py b/stellar_sdk/xdr/contract_data_entry_data.py deleted file mode 100644 index 86dfd5f7..00000000 --- a/stellar_sdk/xdr/contract_data_entry_data.py +++ /dev/null @@ -1,84 +0,0 @@ -# This is an automatically generated file. -# DO NOT EDIT or your changes may be overwritten -from __future__ import annotations - -import base64 - -from xdrlib3 import Packer, Unpacker - -from .sc_val import SCVal -from .uint32 import Uint32 - -__all__ = ["ContractDataEntryData"] - - -class ContractDataEntryData: - """ - XDR Source Code:: - - struct - { - uint32 flags; - SCVal val; - } - """ - - def __init__( - self, - flags: Uint32, - val: SCVal, - ) -> None: - self.flags = flags - self.val = val - - def pack(self, packer: Packer) -> None: - self.flags.pack(packer) - self.val.pack(packer) - - @classmethod - def unpack(cls, unpacker: Unpacker) -> ContractDataEntryData: - flags = Uint32.unpack(unpacker) - val = SCVal.unpack(unpacker) - return cls( - flags=flags, - val=val, - ) - - def to_xdr_bytes(self) -> bytes: - packer = Packer() - self.pack(packer) - return packer.get_buffer() - - @classmethod - def from_xdr_bytes(cls, xdr: bytes) -> ContractDataEntryData: - unpacker = Unpacker(xdr) - return cls.unpack(unpacker) - - def to_xdr(self) -> str: - xdr_bytes = self.to_xdr_bytes() - return base64.b64encode(xdr_bytes).decode() - - @classmethod - def from_xdr(cls, xdr: str) -> ContractDataEntryData: - xdr_bytes = base64.b64decode(xdr.encode()) - return cls.from_xdr_bytes(xdr_bytes) - - def __hash__(self): - return hash( - ( - self.flags, - self.val, - ) - ) - - def __eq__(self, other: object): - if not isinstance(other, self.__class__): - return NotImplemented - return self.flags == other.flags and self.val == other.val - - def __str__(self): - out = [ - f"flags={self.flags}", - f"val={self.val}", - ] - return f"" diff --git a/stellar_sdk/xdr/contract_data_flags.py b/stellar_sdk/xdr/contract_data_flags.py deleted file mode 100644 index 0cf5abde..00000000 --- a/stellar_sdk/xdr/contract_data_flags.py +++ /dev/null @@ -1,51 +0,0 @@ -# This is an automatically generated file. -# DO NOT EDIT or your changes may be overwritten -from __future__ import annotations - -import base64 -from enum import IntEnum - -from xdrlib3 import Packer, Unpacker - -__all__ = ["ContractDataFlags"] - - -class ContractDataFlags(IntEnum): - """ - XDR Source Code:: - - enum ContractDataFlags { - // When set, the given entry does not recieve automatic expiration bumps - // on access. Note that entries can still be bumped manually via the footprint. - NO_AUTOBUMP = 0x1 - }; - """ - - NO_AUTOBUMP = 1 - - def pack(self, packer: Packer) -> None: - packer.pack_int(self.value) - - @classmethod - def unpack(cls, unpacker: Unpacker) -> ContractDataFlags: - value = unpacker.unpack_int() - return cls(value) - - def to_xdr_bytes(self) -> bytes: - packer = Packer() - self.pack(packer) - return packer.get_buffer() - - @classmethod - def from_xdr_bytes(cls, xdr: bytes) -> ContractDataFlags: - unpacker = Unpacker(xdr) - return cls.unpack(unpacker) - - def to_xdr(self) -> str: - xdr_bytes = self.to_xdr_bytes() - return base64.b64encode(xdr_bytes).decode() - - @classmethod - def from_xdr(cls, xdr: str) -> ContractDataFlags: - xdr_bytes = base64.b64decode(xdr.encode()) - return cls.from_xdr_bytes(xdr_bytes) diff --git a/stellar_sdk/xdr/contract_entry_body_type.py b/stellar_sdk/xdr/contract_entry_body_type.py deleted file mode 100644 index 7e9c8d2c..00000000 --- a/stellar_sdk/xdr/contract_entry_body_type.py +++ /dev/null @@ -1,51 +0,0 @@ -# This is an automatically generated file. -# DO NOT EDIT or your changes may be overwritten -from __future__ import annotations - -import base64 -from enum import IntEnum - -from xdrlib3 import Packer, Unpacker - -__all__ = ["ContractEntryBodyType"] - - -class ContractEntryBodyType(IntEnum): - """ - XDR Source Code:: - - enum ContractEntryBodyType { - DATA_ENTRY = 0, - EXPIRATION_EXTENSION = 1 - }; - """ - - DATA_ENTRY = 0 - EXPIRATION_EXTENSION = 1 - - def pack(self, packer: Packer) -> None: - packer.pack_int(self.value) - - @classmethod - def unpack(cls, unpacker: Unpacker) -> ContractEntryBodyType: - value = unpacker.unpack_int() - return cls(value) - - def to_xdr_bytes(self) -> bytes: - packer = Packer() - self.pack(packer) - return packer.get_buffer() - - @classmethod - def from_xdr_bytes(cls, xdr: bytes) -> ContractEntryBodyType: - unpacker = Unpacker(xdr) - return cls.unpack(unpacker) - - def to_xdr(self) -> str: - xdr_bytes = self.to_xdr_bytes() - return base64.b64encode(xdr_bytes).decode() - - @classmethod - def from_xdr(cls, xdr: str) -> ContractEntryBodyType: - xdr_bytes = base64.b64decode(xdr.encode()) - return cls.from_xdr_bytes(xdr_bytes) diff --git a/stellar_sdk/xdr/contract_event.py b/stellar_sdk/xdr/contract_event.py index 0da1b34a..fd1c92f7 100644 --- a/stellar_sdk/xdr/contract_event.py +++ b/stellar_sdk/xdr/contract_event.py @@ -33,7 +33,7 @@ class ContractEvent: case 0: struct { - SCVec topics; + SCVal topics<>; SCVal data; } v0; } diff --git a/stellar_sdk/xdr/contract_event_body.py b/stellar_sdk/xdr/contract_event_body.py index 95a0ada4..378ad283 100644 --- a/stellar_sdk/xdr/contract_event_body.py +++ b/stellar_sdk/xdr/contract_event_body.py @@ -21,7 +21,7 @@ class ContractEventBody: case 0: struct { - SCVec topics; + SCVal topics<>; SCVal data; } v0; } diff --git a/stellar_sdk/xdr/contract_event_v0.py b/stellar_sdk/xdr/contract_event_v0.py index 7e4bff0f..37da76f6 100644 --- a/stellar_sdk/xdr/contract_event_v0.py +++ b/stellar_sdk/xdr/contract_event_v0.py @@ -3,11 +3,11 @@ from __future__ import annotations import base64 +from typing import List from xdrlib3 import Packer, Unpacker from .sc_val import SCVal -from .sc_vec import SCVec __all__ = ["ContractEventV0"] @@ -18,26 +18,36 @@ class ContractEventV0: struct { - SCVec topics; + SCVal topics<>; SCVal data; } """ def __init__( self, - topics: SCVec, + topics: List[SCVal], data: SCVal, ) -> None: + _expect_max_length = 4294967295 + if topics and len(topics) > _expect_max_length: + raise ValueError( + f"The maximum length of `topics` should be {_expect_max_length}, but got {len(topics)}." + ) self.topics = topics self.data = data def pack(self, packer: Packer) -> None: - self.topics.pack(packer) + packer.pack_uint(len(self.topics)) + for topics_item in self.topics: + topics_item.pack(packer) self.data.pack(packer) @classmethod def unpack(cls, unpacker: Unpacker) -> ContractEventV0: - topics = SCVec.unpack(unpacker) + length = unpacker.unpack_uint() + topics = [] + for _ in range(length): + topics.append(SCVal.unpack(unpacker)) data = SCVal.unpack(unpacker) return cls( topics=topics, diff --git a/stellar_sdk/xdr/eviction_iterator.py b/stellar_sdk/xdr/eviction_iterator.py new file mode 100644 index 00000000..e47ca840 --- /dev/null +++ b/stellar_sdk/xdr/eviction_iterator.py @@ -0,0 +1,96 @@ +# This is an automatically generated file. +# DO NOT EDIT or your changes may be overwritten +from __future__ import annotations + +import base64 + +from xdrlib3 import Packer, Unpacker + +from .base import Boolean +from .uint32 import Uint32 +from .uint64 import Uint64 + +__all__ = ["EvictionIterator"] + + +class EvictionIterator: + """ + XDR Source Code:: + + struct EvictionIterator { + uint32 bucketListLevel; + bool isCurrBucket; + uint64 bucketFileOffset; + }; + """ + + def __init__( + self, + bucket_list_level: Uint32, + is_curr_bucket: bool, + bucket_file_offset: Uint64, + ) -> None: + self.bucket_list_level = bucket_list_level + self.is_curr_bucket = is_curr_bucket + self.bucket_file_offset = bucket_file_offset + + def pack(self, packer: Packer) -> None: + self.bucket_list_level.pack(packer) + Boolean(self.is_curr_bucket).pack(packer) + self.bucket_file_offset.pack(packer) + + @classmethod + def unpack(cls, unpacker: Unpacker) -> EvictionIterator: + bucket_list_level = Uint32.unpack(unpacker) + is_curr_bucket = Boolean.unpack(unpacker) + bucket_file_offset = Uint64.unpack(unpacker) + return cls( + bucket_list_level=bucket_list_level, + is_curr_bucket=is_curr_bucket, + bucket_file_offset=bucket_file_offset, + ) + + def to_xdr_bytes(self) -> bytes: + packer = Packer() + self.pack(packer) + return packer.get_buffer() + + @classmethod + def from_xdr_bytes(cls, xdr: bytes) -> EvictionIterator: + unpacker = Unpacker(xdr) + return cls.unpack(unpacker) + + def to_xdr(self) -> str: + xdr_bytes = self.to_xdr_bytes() + return base64.b64encode(xdr_bytes).decode() + + @classmethod + def from_xdr(cls, xdr: str) -> EvictionIterator: + xdr_bytes = base64.b64decode(xdr.encode()) + return cls.from_xdr_bytes(xdr_bytes) + + def __hash__(self): + return hash( + ( + self.bucket_list_level, + self.is_curr_bucket, + self.bucket_file_offset, + ) + ) + + def __eq__(self, other: object): + if not isinstance(other, self.__class__): + return NotImplemented + return ( + self.bucket_list_level == other.bucket_list_level + and self.is_curr_bucket == other.is_curr_bucket + and self.bucket_file_offset == other.bucket_file_offset + ) + + def __str__(self): + out = [ + f"bucket_list_level={self.bucket_list_level}", + f"is_curr_bucket={self.is_curr_bucket}", + f"bucket_file_offset={self.bucket_file_offset}", + ] + return f"" diff --git a/stellar_sdk/xdr/expiration_entry.py b/stellar_sdk/xdr/expiration_entry.py new file mode 100644 index 00000000..ee4c3a85 --- /dev/null +++ b/stellar_sdk/xdr/expiration_entry.py @@ -0,0 +1,87 @@ +# This is an automatically generated file. +# DO NOT EDIT or your changes may be overwritten +from __future__ import annotations + +import base64 + +from xdrlib3 import Packer, Unpacker + +from .hash import Hash +from .uint32 import Uint32 + +__all__ = ["ExpirationEntry"] + + +class ExpirationEntry: + """ + XDR Source Code:: + + struct ExpirationEntry { + // Hash of the LedgerKey that is associated with this ExpirationEntry + Hash keyHash; + uint32 expirationLedgerSeq; + }; + """ + + def __init__( + self, + key_hash: Hash, + expiration_ledger_seq: Uint32, + ) -> None: + self.key_hash = key_hash + self.expiration_ledger_seq = expiration_ledger_seq + + def pack(self, packer: Packer) -> None: + self.key_hash.pack(packer) + self.expiration_ledger_seq.pack(packer) + + @classmethod + def unpack(cls, unpacker: Unpacker) -> ExpirationEntry: + key_hash = Hash.unpack(unpacker) + expiration_ledger_seq = Uint32.unpack(unpacker) + return cls( + key_hash=key_hash, + expiration_ledger_seq=expiration_ledger_seq, + ) + + def to_xdr_bytes(self) -> bytes: + packer = Packer() + self.pack(packer) + return packer.get_buffer() + + @classmethod + def from_xdr_bytes(cls, xdr: bytes) -> ExpirationEntry: + unpacker = Unpacker(xdr) + return cls.unpack(unpacker) + + def to_xdr(self) -> str: + xdr_bytes = self.to_xdr_bytes() + return base64.b64encode(xdr_bytes).decode() + + @classmethod + def from_xdr(cls, xdr: str) -> ExpirationEntry: + xdr_bytes = base64.b64decode(xdr.encode()) + return cls.from_xdr_bytes(xdr_bytes) + + def __hash__(self): + return hash( + ( + self.key_hash, + self.expiration_ledger_seq, + ) + ) + + def __eq__(self, other: object): + if not isinstance(other, self.__class__): + return NotImplemented + return ( + self.key_hash == other.key_hash + and self.expiration_ledger_seq == other.expiration_ledger_seq + ) + + def __str__(self): + out = [ + f"key_hash={self.key_hash}", + f"expiration_ledger_seq={self.expiration_ledger_seq}", + ] + return f"" diff --git a/stellar_sdk/xdr/host_function.py b/stellar_sdk/xdr/host_function.py index 3dbd8746..c4436bea 100644 --- a/stellar_sdk/xdr/host_function.py +++ b/stellar_sdk/xdr/host_function.py @@ -9,7 +9,7 @@ from .base import Opaque from .create_contract_args import CreateContractArgs from .host_function_type import HostFunctionType -from .sc_vec import SCVec +from .invoke_contract_args import InvokeContractArgs __all__ = ["HostFunction"] @@ -21,7 +21,7 @@ class HostFunction: union HostFunction switch (HostFunctionType type) { case HOST_FUNCTION_TYPE_INVOKE_CONTRACT: - SCVec invokeContract; + InvokeContractArgs invokeContract; case HOST_FUNCTION_TYPE_CREATE_CONTRACT: CreateContractArgs createContract; case HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM: @@ -32,7 +32,7 @@ class HostFunction: def __init__( self, type: HostFunctionType, - invoke_contract: SCVec = None, + invoke_contract: InvokeContractArgs = None, create_contract: CreateContractArgs = None, wasm: bytes = None, ) -> None: @@ -63,7 +63,7 @@ def pack(self, packer: Packer) -> None: def unpack(cls, unpacker: Unpacker) -> HostFunction: type = HostFunctionType.unpack(unpacker) if type == HostFunctionType.HOST_FUNCTION_TYPE_INVOKE_CONTRACT: - invoke_contract = SCVec.unpack(unpacker) + invoke_contract = InvokeContractArgs.unpack(unpacker) return cls(type=type, invoke_contract=invoke_contract) if type == HostFunctionType.HOST_FUNCTION_TYPE_CREATE_CONTRACT: create_contract = CreateContractArgs.unpack(unpacker) diff --git a/stellar_sdk/xdr/inner_transaction_result.py b/stellar_sdk/xdr/inner_transaction_result.py index f073b2ef..ac6e4fc5 100644 --- a/stellar_sdk/xdr/inner_transaction_result.py +++ b/stellar_sdk/xdr/inner_transaction_result.py @@ -43,7 +43,7 @@ class InnerTransactionResult: case txBAD_SPONSORSHIP: case txBAD_MIN_SEQ_AGE_OR_GAP: case txMALFORMED: - case txSOROBAN_RESOURCE_LIMIT_EXCEEDED: + case txSOROBAN_INVALID: void; } result; diff --git a/stellar_sdk/xdr/inner_transaction_result_result.py b/stellar_sdk/xdr/inner_transaction_result_result.py index 8214acf6..1f065ca0 100644 --- a/stellar_sdk/xdr/inner_transaction_result_result.py +++ b/stellar_sdk/xdr/inner_transaction_result_result.py @@ -38,7 +38,7 @@ class InnerTransactionResultResult: case txBAD_SPONSORSHIP: case txBAD_MIN_SEQ_AGE_OR_GAP: case txMALFORMED: - case txSOROBAN_RESOURCE_LIMIT_EXCEEDED: + case txSOROBAN_INVALID: void; } """ @@ -100,7 +100,7 @@ def pack(self, packer: Packer) -> None: return if self.code == TransactionResultCode.txMALFORMED: return - if self.code == TransactionResultCode.txSOROBAN_RESOURCE_LIMIT_EXCEEDED: + if self.code == TransactionResultCode.txSOROBAN_INVALID: return @classmethod @@ -146,7 +146,7 @@ def unpack(cls, unpacker: Unpacker) -> InnerTransactionResultResult: return cls(code=code) if code == TransactionResultCode.txMALFORMED: return cls(code=code) - if code == TransactionResultCode.txSOROBAN_RESOURCE_LIMIT_EXCEEDED: + if code == TransactionResultCode.txSOROBAN_INVALID: return cls(code=code) return cls(code=code) diff --git a/stellar_sdk/xdr/soroban_authorized_contract_function.py b/stellar_sdk/xdr/invoke_contract_args.py similarity index 69% rename from stellar_sdk/xdr/soroban_authorized_contract_function.py rename to stellar_sdk/xdr/invoke_contract_args.py index 73e02fa0..f57811c1 100644 --- a/stellar_sdk/xdr/soroban_authorized_contract_function.py +++ b/stellar_sdk/xdr/invoke_contract_args.py @@ -3,25 +3,25 @@ from __future__ import annotations import base64 +from typing import List from xdrlib3 import Packer, Unpacker from .sc_address import SCAddress from .sc_symbol import SCSymbol -from .sc_vec import SCVec +from .sc_val import SCVal -__all__ = ["SorobanAuthorizedContractFunction"] +__all__ = ["InvokeContractArgs"] -class SorobanAuthorizedContractFunction: +class InvokeContractArgs: """ XDR Source Code:: - struct SorobanAuthorizedContractFunction - { + struct InvokeContractArgs { SCAddress contractAddress; SCSymbol functionName; - SCVec args; + SCVal args<>; }; """ @@ -29,8 +29,13 @@ def __init__( self, contract_address: SCAddress, function_name: SCSymbol, - args: SCVec, + args: List[SCVal], ) -> None: + _expect_max_length = 4294967295 + if args and len(args) > _expect_max_length: + raise ValueError( + f"The maximum length of `args` should be {_expect_max_length}, but got {len(args)}." + ) self.contract_address = contract_address self.function_name = function_name self.args = args @@ -38,13 +43,18 @@ def __init__( def pack(self, packer: Packer) -> None: self.contract_address.pack(packer) self.function_name.pack(packer) - self.args.pack(packer) + packer.pack_uint(len(self.args)) + for args_item in self.args: + args_item.pack(packer) @classmethod - def unpack(cls, unpacker: Unpacker) -> SorobanAuthorizedContractFunction: + def unpack(cls, unpacker: Unpacker) -> InvokeContractArgs: contract_address = SCAddress.unpack(unpacker) function_name = SCSymbol.unpack(unpacker) - args = SCVec.unpack(unpacker) + length = unpacker.unpack_uint() + args = [] + for _ in range(length): + args.append(SCVal.unpack(unpacker)) return cls( contract_address=contract_address, function_name=function_name, @@ -57,7 +67,7 @@ def to_xdr_bytes(self) -> bytes: return packer.get_buffer() @classmethod - def from_xdr_bytes(cls, xdr: bytes) -> SorobanAuthorizedContractFunction: + def from_xdr_bytes(cls, xdr: bytes) -> InvokeContractArgs: unpacker = Unpacker(xdr) return cls.unpack(unpacker) @@ -66,7 +76,7 @@ def to_xdr(self) -> str: return base64.b64encode(xdr_bytes).decode() @classmethod - def from_xdr(cls, xdr: str) -> SorobanAuthorizedContractFunction: + def from_xdr(cls, xdr: str) -> InvokeContractArgs: xdr_bytes = base64.b64decode(xdr.encode()) return cls.from_xdr_bytes(xdr_bytes) @@ -94,4 +104,4 @@ def __str__(self): f"function_name={self.function_name}", f"args={self.args}", ] - return f"" + return f"" diff --git a/stellar_sdk/xdr/invoke_host_function_result.py b/stellar_sdk/xdr/invoke_host_function_result.py index 6294a671..5449d9e7 100644 --- a/stellar_sdk/xdr/invoke_host_function_result.py +++ b/stellar_sdk/xdr/invoke_host_function_result.py @@ -23,6 +23,8 @@ class InvokeHostFunctionResult: case INVOKE_HOST_FUNCTION_MALFORMED: case INVOKE_HOST_FUNCTION_TRAPPED: case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: + case INVOKE_HOST_FUNCTION_ENTRY_EXPIRED: + case INVOKE_HOST_FUNCTION_INSUFFICIENT_REFUNDABLE_FEE: void; }; """ @@ -51,6 +53,13 @@ def pack(self, packer: Packer) -> None: == InvokeHostFunctionResultCode.INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED ): return + if self.code == InvokeHostFunctionResultCode.INVOKE_HOST_FUNCTION_ENTRY_EXPIRED: + return + if ( + self.code + == InvokeHostFunctionResultCode.INVOKE_HOST_FUNCTION_INSUFFICIENT_REFUNDABLE_FEE + ): + return @classmethod def unpack(cls, unpacker: Unpacker) -> InvokeHostFunctionResult: @@ -67,6 +76,13 @@ def unpack(cls, unpacker: Unpacker) -> InvokeHostFunctionResult: == InvokeHostFunctionResultCode.INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED ): return cls(code=code) + if code == InvokeHostFunctionResultCode.INVOKE_HOST_FUNCTION_ENTRY_EXPIRED: + return cls(code=code) + if ( + code + == InvokeHostFunctionResultCode.INVOKE_HOST_FUNCTION_INSUFFICIENT_REFUNDABLE_FEE + ): + return cls(code=code) return cls(code=code) def to_xdr_bytes(self) -> bytes: diff --git a/stellar_sdk/xdr/invoke_host_function_result_code.py b/stellar_sdk/xdr/invoke_host_function_result_code.py index b24fa45a..0989d21c 100644 --- a/stellar_sdk/xdr/invoke_host_function_result_code.py +++ b/stellar_sdk/xdr/invoke_host_function_result_code.py @@ -22,7 +22,9 @@ class InvokeHostFunctionResultCode(IntEnum): // codes considered as "failure" for the operation INVOKE_HOST_FUNCTION_MALFORMED = -1, INVOKE_HOST_FUNCTION_TRAPPED = -2, - INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED = -3 + INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED = -3, + INVOKE_HOST_FUNCTION_ENTRY_EXPIRED = -4, + INVOKE_HOST_FUNCTION_INSUFFICIENT_REFUNDABLE_FEE = -5 }; """ @@ -30,6 +32,8 @@ class InvokeHostFunctionResultCode(IntEnum): 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_INSUFFICIENT_REFUNDABLE_FEE = -5 def pack(self, packer: Packer) -> None: packer.pack_int(self.value) diff --git a/stellar_sdk/xdr/ledger_entry.py b/stellar_sdk/xdr/ledger_entry.py index bfc03fc6..22240fcc 100644 --- a/stellar_sdk/xdr/ledger_entry.py +++ b/stellar_sdk/xdr/ledger_entry.py @@ -41,6 +41,8 @@ class LedgerEntry: ContractCodeEntry contractCode; case CONFIG_SETTING: ConfigSettingEntry configSetting; + case EXPIRATION: + ExpirationEntry expiration; } data; diff --git a/stellar_sdk/xdr/ledger_entry_data.py b/stellar_sdk/xdr/ledger_entry_data.py index 9c1a9522..004e70c3 100644 --- a/stellar_sdk/xdr/ledger_entry_data.py +++ b/stellar_sdk/xdr/ledger_entry_data.py @@ -12,6 +12,7 @@ from .contract_code_entry import ContractCodeEntry from .contract_data_entry import ContractDataEntry from .data_entry import DataEntry +from .expiration_entry import ExpirationEntry from .ledger_entry_type import LedgerEntryType from .liquidity_pool_entry import LiquidityPoolEntry from .offer_entry import OfferEntry @@ -44,6 +45,8 @@ class LedgerEntryData: ContractCodeEntry contractCode; case CONFIG_SETTING: ConfigSettingEntry configSetting; + case EXPIRATION: + ExpirationEntry expiration; } """ @@ -59,6 +62,7 @@ def __init__( contract_data: ContractDataEntry = None, contract_code: ContractCodeEntry = None, config_setting: ConfigSettingEntry = None, + expiration: ExpirationEntry = None, ) -> None: self.type = type self.account = account @@ -70,6 +74,7 @@ def __init__( self.contract_data = contract_data self.contract_code = contract_code self.config_setting = config_setting + self.expiration = expiration def pack(self, packer: Packer) -> None: self.type.pack(packer) @@ -118,6 +123,11 @@ def pack(self, packer: Packer) -> None: raise ValueError("config_setting should not be None.") self.config_setting.pack(packer) return + if self.type == LedgerEntryType.EXPIRATION: + if self.expiration is None: + raise ValueError("expiration should not be None.") + self.expiration.pack(packer) + return @classmethod def unpack(cls, unpacker: Unpacker) -> LedgerEntryData: @@ -149,6 +159,9 @@ def unpack(cls, unpacker: Unpacker) -> LedgerEntryData: if type == LedgerEntryType.CONFIG_SETTING: config_setting = ConfigSettingEntry.unpack(unpacker) return cls(type=type, config_setting=config_setting) + if type == LedgerEntryType.EXPIRATION: + expiration = ExpirationEntry.unpack(unpacker) + return cls(type=type, expiration=expiration) return cls(type=type) def to_xdr_bytes(self) -> bytes: @@ -183,6 +196,7 @@ def __hash__(self): self.contract_data, self.contract_code, self.config_setting, + self.expiration, ) ) @@ -200,6 +214,7 @@ def __eq__(self, other: object): and self.contract_data == other.contract_data and self.contract_code == other.contract_code and self.config_setting == other.config_setting + and self.expiration == other.expiration ) def __str__(self): @@ -226,4 +241,7 @@ def __str__(self): out.append( f"config_setting={self.config_setting}" ) if self.config_setting is not None else None + out.append( + f"expiration={self.expiration}" + ) if self.expiration is not None else None return f"" diff --git a/stellar_sdk/xdr/ledger_entry_type.py b/stellar_sdk/xdr/ledger_entry_type.py index fd9e075d..19b1a0fd 100644 --- a/stellar_sdk/xdr/ledger_entry_type.py +++ b/stellar_sdk/xdr/ledger_entry_type.py @@ -24,7 +24,8 @@ class LedgerEntryType(IntEnum): LIQUIDITY_POOL = 5, CONTRACT_DATA = 6, CONTRACT_CODE = 7, - CONFIG_SETTING = 8 + CONFIG_SETTING = 8, + EXPIRATION = 9 }; """ @@ -37,6 +38,7 @@ class LedgerEntryType(IntEnum): CONTRACT_DATA = 6 CONTRACT_CODE = 7 CONFIG_SETTING = 8 + EXPIRATION = 9 def pack(self, packer: Packer) -> None: packer.pack_int(self.value) diff --git a/stellar_sdk/xdr/ledger_header_flags.py b/stellar_sdk/xdr/ledger_header_flags.py index 368cf9d0..22e69a3b 100644 --- a/stellar_sdk/xdr/ledger_header_flags.py +++ b/stellar_sdk/xdr/ledger_header_flags.py @@ -18,21 +18,13 @@ class LedgerHeaderFlags(IntEnum): { DISABLE_LIQUIDITY_POOL_TRADING_FLAG = 0x1, DISABLE_LIQUIDITY_POOL_DEPOSIT_FLAG = 0x2, - DISABLE_LIQUIDITY_POOL_WITHDRAWAL_FLAG = 0x4, - DISABLE_CONTRACT_CREATE = 0x8, - DISABLE_CONTRACT_UPDATE = 0x10, - DISABLE_CONTRACT_REMOVE = 0x20, - DISABLE_CONTRACT_INVOKE = 0x40 + DISABLE_LIQUIDITY_POOL_WITHDRAWAL_FLAG = 0x4 }; """ DISABLE_LIQUIDITY_POOL_TRADING_FLAG = 1 DISABLE_LIQUIDITY_POOL_DEPOSIT_FLAG = 2 DISABLE_LIQUIDITY_POOL_WITHDRAWAL_FLAG = 4 - DISABLE_CONTRACT_CREATE = 8 - DISABLE_CONTRACT_UPDATE = 16 - DISABLE_CONTRACT_REMOVE = 32 - DISABLE_CONTRACT_INVOKE = 64 def pack(self, packer: Packer) -> None: packer.pack_int(self.value) diff --git a/stellar_sdk/xdr/ledger_key.py b/stellar_sdk/xdr/ledger_key.py index 2d7f2e80..be975004 100644 --- a/stellar_sdk/xdr/ledger_key.py +++ b/stellar_sdk/xdr/ledger_key.py @@ -13,6 +13,7 @@ from .ledger_key_contract_code import LedgerKeyContractCode from .ledger_key_contract_data import LedgerKeyContractData from .ledger_key_data import LedgerKeyData +from .ledger_key_expiration import LedgerKeyExpiration from .ledger_key_liquidity_pool import LedgerKeyLiquidityPool from .ledger_key_offer import LedgerKeyOffer from .ledger_key_trust_line import LedgerKeyTrustLine @@ -70,19 +71,23 @@ class LedgerKey: SCAddress contract; SCVal key; ContractDataDurability durability; - ContractEntryBodyType bodyType; } contractData; case CONTRACT_CODE: struct { Hash hash; - ContractEntryBodyType bodyType; } contractCode; case CONFIG_SETTING: struct { ConfigSettingID configSettingID; } configSetting; + case EXPIRATION: + struct + { + // Hash of the LedgerKey that is associated with this ExpirationEntry + Hash keyHash; + } expiration; }; """ @@ -98,6 +103,7 @@ def __init__( contract_data: LedgerKeyContractData = None, contract_code: LedgerKeyContractCode = None, config_setting: LedgerKeyConfigSetting = None, + expiration: LedgerKeyExpiration = None, ) -> None: self.type = type self.account = account @@ -109,6 +115,7 @@ def __init__( self.contract_data = contract_data self.contract_code = contract_code self.config_setting = config_setting + self.expiration = expiration def pack(self, packer: Packer) -> None: self.type.pack(packer) @@ -157,6 +164,11 @@ def pack(self, packer: Packer) -> None: raise ValueError("config_setting should not be None.") self.config_setting.pack(packer) return + if self.type == LedgerEntryType.EXPIRATION: + if self.expiration is None: + raise ValueError("expiration should not be None.") + self.expiration.pack(packer) + return @classmethod def unpack(cls, unpacker: Unpacker) -> LedgerKey: @@ -188,6 +200,9 @@ def unpack(cls, unpacker: Unpacker) -> LedgerKey: if type == LedgerEntryType.CONFIG_SETTING: config_setting = LedgerKeyConfigSetting.unpack(unpacker) return cls(type=type, config_setting=config_setting) + if type == LedgerEntryType.EXPIRATION: + expiration = LedgerKeyExpiration.unpack(unpacker) + return cls(type=type, expiration=expiration) return cls(type=type) def to_xdr_bytes(self) -> bytes: @@ -222,6 +237,7 @@ def __hash__(self): self.contract_data, self.contract_code, self.config_setting, + self.expiration, ) ) @@ -239,6 +255,7 @@ def __eq__(self, other: object): and self.contract_data == other.contract_data and self.contract_code == other.contract_code and self.config_setting == other.config_setting + and self.expiration == other.expiration ) def __str__(self): @@ -265,4 +282,7 @@ def __str__(self): out.append( f"config_setting={self.config_setting}" ) if self.config_setting is not None else None + out.append( + f"expiration={self.expiration}" + ) if self.expiration is not None else None return f"" diff --git a/stellar_sdk/xdr/ledger_key_contract_code.py b/stellar_sdk/xdr/ledger_key_contract_code.py index a5746293..71f0a1b7 100644 --- a/stellar_sdk/xdr/ledger_key_contract_code.py +++ b/stellar_sdk/xdr/ledger_key_contract_code.py @@ -6,7 +6,6 @@ from xdrlib3 import Packer, Unpacker -from .contract_entry_body_type import ContractEntryBodyType from .hash import Hash __all__ = ["LedgerKeyContractCode"] @@ -19,29 +18,23 @@ class LedgerKeyContractCode: struct { Hash hash; - ContractEntryBodyType bodyType; } """ def __init__( self, hash: Hash, - body_type: ContractEntryBodyType, ) -> None: self.hash = hash - self.body_type = body_type def pack(self, packer: Packer) -> None: self.hash.pack(packer) - self.body_type.pack(packer) @classmethod def unpack(cls, unpacker: Unpacker) -> LedgerKeyContractCode: hash = Hash.unpack(unpacker) - body_type = ContractEntryBodyType.unpack(unpacker) return cls( hash=hash, - body_type=body_type, ) def to_xdr_bytes(self) -> bytes: @@ -64,21 +57,15 @@ def from_xdr(cls, xdr: str) -> LedgerKeyContractCode: return cls.from_xdr_bytes(xdr_bytes) def __hash__(self): - return hash( - ( - self.hash, - self.body_type, - ) - ) + return hash((self.hash,)) def __eq__(self, other: object): if not isinstance(other, self.__class__): return NotImplemented - return self.hash == other.hash and self.body_type == other.body_type + return self.hash == other.hash def __str__(self): out = [ f"hash={self.hash}", - f"body_type={self.body_type}", ] return f"" diff --git a/stellar_sdk/xdr/ledger_key_contract_data.py b/stellar_sdk/xdr/ledger_key_contract_data.py index 6b3ef992..7f3c25ba 100644 --- a/stellar_sdk/xdr/ledger_key_contract_data.py +++ b/stellar_sdk/xdr/ledger_key_contract_data.py @@ -7,7 +7,6 @@ from xdrlib3 import Packer, Unpacker from .contract_data_durability import ContractDataDurability -from .contract_entry_body_type import ContractEntryBodyType from .sc_address import SCAddress from .sc_val import SCVal @@ -23,7 +22,6 @@ class LedgerKeyContractData: SCAddress contract; SCVal key; ContractDataDurability durability; - ContractEntryBodyType bodyType; } """ @@ -32,30 +30,25 @@ def __init__( contract: SCAddress, key: SCVal, durability: ContractDataDurability, - body_type: ContractEntryBodyType, ) -> None: self.contract = contract self.key = key self.durability = durability - self.body_type = body_type def pack(self, packer: Packer) -> None: self.contract.pack(packer) self.key.pack(packer) self.durability.pack(packer) - self.body_type.pack(packer) @classmethod def unpack(cls, unpacker: Unpacker) -> LedgerKeyContractData: contract = SCAddress.unpack(unpacker) key = SCVal.unpack(unpacker) durability = ContractDataDurability.unpack(unpacker) - body_type = ContractEntryBodyType.unpack(unpacker) return cls( contract=contract, key=key, durability=durability, - body_type=body_type, ) def to_xdr_bytes(self) -> bytes: @@ -83,7 +76,6 @@ def __hash__(self): self.contract, self.key, self.durability, - self.body_type, ) ) @@ -94,7 +86,6 @@ def __eq__(self, other: object): self.contract == other.contract and self.key == other.key and self.durability == other.durability - and self.body_type == other.body_type ) def __str__(self): @@ -102,6 +93,5 @@ def __str__(self): f"contract={self.contract}", f"key={self.key}", f"durability={self.durability}", - f"body_type={self.body_type}", ] return f"" diff --git a/stellar_sdk/xdr/sc_spec_type_set.py b/stellar_sdk/xdr/ledger_key_expiration.py similarity index 56% rename from stellar_sdk/xdr/sc_spec_type_set.py rename to stellar_sdk/xdr/ledger_key_expiration.py index 3f5b5508..fead22d1 100644 --- a/stellar_sdk/xdr/sc_spec_type_set.py +++ b/stellar_sdk/xdr/ledger_key_expiration.py @@ -6,35 +6,36 @@ from xdrlib3 import Packer, Unpacker -from .sc_spec_type_def import SCSpecTypeDef +from .hash import Hash -__all__ = ["SCSpecTypeSet"] +__all__ = ["LedgerKeyExpiration"] -class SCSpecTypeSet: +class LedgerKeyExpiration: """ XDR Source Code:: - struct SCSpecTypeSet - { - SCSpecTypeDef elementType; - }; + struct + { + // Hash of the LedgerKey that is associated with this ExpirationEntry + Hash keyHash; + } """ def __init__( self, - element_type: SCSpecTypeDef, + key_hash: Hash, ) -> None: - self.element_type = element_type + self.key_hash = key_hash def pack(self, packer: Packer) -> None: - self.element_type.pack(packer) + self.key_hash.pack(packer) @classmethod - def unpack(cls, unpacker: Unpacker) -> SCSpecTypeSet: - element_type = SCSpecTypeDef.unpack(unpacker) + def unpack(cls, unpacker: Unpacker) -> LedgerKeyExpiration: + key_hash = Hash.unpack(unpacker) return cls( - element_type=element_type, + key_hash=key_hash, ) def to_xdr_bytes(self) -> bytes: @@ -43,7 +44,7 @@ def to_xdr_bytes(self) -> bytes: return packer.get_buffer() @classmethod - def from_xdr_bytes(cls, xdr: bytes) -> SCSpecTypeSet: + def from_xdr_bytes(cls, xdr: bytes) -> LedgerKeyExpiration: unpacker = Unpacker(xdr) return cls.unpack(unpacker) @@ -52,20 +53,20 @@ def to_xdr(self) -> str: return base64.b64encode(xdr_bytes).decode() @classmethod - def from_xdr(cls, xdr: str) -> SCSpecTypeSet: + def from_xdr(cls, xdr: str) -> LedgerKeyExpiration: xdr_bytes = base64.b64decode(xdr.encode()) return cls.from_xdr_bytes(xdr_bytes) def __hash__(self): - return hash((self.element_type,)) + return hash((self.key_hash,)) def __eq__(self, other: object): if not isinstance(other, self.__class__): return NotImplemented - return self.element_type == other.element_type + return self.key_hash == other.key_hash def __str__(self): out = [ - f"element_type={self.element_type}", + f"key_hash={self.key_hash}", ] - return f"" + return f"" diff --git a/stellar_sdk/xdr/ledger_upgrade.py b/stellar_sdk/xdr/ledger_upgrade.py index 5bc50623..092b70f7 100644 --- a/stellar_sdk/xdr/ledger_upgrade.py +++ b/stellar_sdk/xdr/ledger_upgrade.py @@ -30,7 +30,12 @@ class LedgerUpgrade: case LEDGER_UPGRADE_FLAGS: uint32 newFlags; // update flags case LEDGER_UPGRADE_CONFIG: + // Update arbitrary `ConfigSetting` entries identified by the key. ConfigUpgradeSetKey newConfig; + case LEDGER_UPGRADE_MAX_SOROBAN_TX_SET_SIZE: + // Update ConfigSettingContractExecutionLanesV0.ledgerMaxTxCount without + // using `LEDGER_UPGRADE_CONFIG`. + uint32 newMaxSorobanTxSetSize; }; """ @@ -43,6 +48,7 @@ def __init__( new_base_reserve: Uint32 = None, new_flags: Uint32 = None, new_config: ConfigUpgradeSetKey = None, + new_max_soroban_tx_set_size: Uint32 = None, ) -> None: self.type = type self.new_ledger_version = new_ledger_version @@ -51,6 +57,7 @@ def __init__( self.new_base_reserve = new_base_reserve self.new_flags = new_flags self.new_config = new_config + self.new_max_soroban_tx_set_size = new_max_soroban_tx_set_size def pack(self, packer: Packer) -> None: self.type.pack(packer) @@ -84,6 +91,11 @@ def pack(self, packer: Packer) -> None: raise ValueError("new_config should not be None.") self.new_config.pack(packer) return + if self.type == LedgerUpgradeType.LEDGER_UPGRADE_MAX_SOROBAN_TX_SET_SIZE: + if self.new_max_soroban_tx_set_size is None: + raise ValueError("new_max_soroban_tx_set_size should not be None.") + self.new_max_soroban_tx_set_size.pack(packer) + return @classmethod def unpack(cls, unpacker: Unpacker) -> LedgerUpgrade: @@ -106,6 +118,11 @@ def unpack(cls, unpacker: Unpacker) -> LedgerUpgrade: if type == LedgerUpgradeType.LEDGER_UPGRADE_CONFIG: new_config = ConfigUpgradeSetKey.unpack(unpacker) return cls(type=type, new_config=new_config) + if type == LedgerUpgradeType.LEDGER_UPGRADE_MAX_SOROBAN_TX_SET_SIZE: + new_max_soroban_tx_set_size = Uint32.unpack(unpacker) + return cls( + type=type, new_max_soroban_tx_set_size=new_max_soroban_tx_set_size + ) return cls(type=type) def to_xdr_bytes(self) -> bytes: @@ -137,6 +154,7 @@ def __hash__(self): self.new_base_reserve, self.new_flags, self.new_config, + self.new_max_soroban_tx_set_size, ) ) @@ -151,6 +169,7 @@ def __eq__(self, other: object): and self.new_base_reserve == other.new_base_reserve and self.new_flags == other.new_flags and self.new_config == other.new_config + and self.new_max_soroban_tx_set_size == other.new_max_soroban_tx_set_size ) def __str__(self): @@ -174,4 +193,7 @@ def __str__(self): out.append( f"new_config={self.new_config}" ) if self.new_config is not None else None + out.append( + f"new_max_soroban_tx_set_size={self.new_max_soroban_tx_set_size}" + ) if self.new_max_soroban_tx_set_size is not None else None return f"" diff --git a/stellar_sdk/xdr/ledger_upgrade_type.py b/stellar_sdk/xdr/ledger_upgrade_type.py index a29a49ad..5441d7a8 100644 --- a/stellar_sdk/xdr/ledger_upgrade_type.py +++ b/stellar_sdk/xdr/ledger_upgrade_type.py @@ -21,7 +21,8 @@ class LedgerUpgradeType(IntEnum): LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3, LEDGER_UPGRADE_BASE_RESERVE = 4, LEDGER_UPGRADE_FLAGS = 5, - LEDGER_UPGRADE_CONFIG = 6 + LEDGER_UPGRADE_CONFIG = 6, + LEDGER_UPGRADE_MAX_SOROBAN_TX_SET_SIZE = 7 }; """ @@ -31,6 +32,7 @@ class LedgerUpgradeType(IntEnum): LEDGER_UPGRADE_BASE_RESERVE = 4 LEDGER_UPGRADE_FLAGS = 5 LEDGER_UPGRADE_CONFIG = 6 + LEDGER_UPGRADE_MAX_SOROBAN_TX_SET_SIZE = 7 def pack(self, packer: Packer) -> None: packer.pack_int(self.value) diff --git a/stellar_sdk/xdr/restore_footprint_result.py b/stellar_sdk/xdr/restore_footprint_result.py index a9c34732..4ba6c7ae 100644 --- a/stellar_sdk/xdr/restore_footprint_result.py +++ b/stellar_sdk/xdr/restore_footprint_result.py @@ -21,6 +21,7 @@ class RestoreFootprintResult: void; case RESTORE_FOOTPRINT_MALFORMED: case RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED: + case RESTORE_FOOTPRINT_INSUFFICIENT_REFUNDABLE_FEE: void; }; """ @@ -42,6 +43,11 @@ def pack(self, packer: Packer) -> None: == RestoreFootprintResultCode.RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED ): return + if ( + self.code + == RestoreFootprintResultCode.RESTORE_FOOTPRINT_INSUFFICIENT_REFUNDABLE_FEE + ): + return @classmethod def unpack(cls, unpacker: Unpacker) -> RestoreFootprintResult: @@ -52,6 +58,11 @@ def unpack(cls, unpacker: Unpacker) -> RestoreFootprintResult: return cls(code=code) if code == RestoreFootprintResultCode.RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED: return cls(code=code) + if ( + code + == RestoreFootprintResultCode.RESTORE_FOOTPRINT_INSUFFICIENT_REFUNDABLE_FEE + ): + return cls(code=code) return cls(code=code) def to_xdr_bytes(self) -> bytes: diff --git a/stellar_sdk/xdr/restore_footprint_result_code.py b/stellar_sdk/xdr/restore_footprint_result_code.py index 792f8f76..783e14e8 100644 --- a/stellar_sdk/xdr/restore_footprint_result_code.py +++ b/stellar_sdk/xdr/restore_footprint_result_code.py @@ -21,13 +21,15 @@ class RestoreFootprintResultCode(IntEnum): // codes considered as "failure" for the operation RESTORE_FOOTPRINT_MALFORMED = -1, - RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED = -2 + RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED = -2, + RESTORE_FOOTPRINT_INSUFFICIENT_REFUNDABLE_FEE = -3 }; """ RESTORE_FOOTPRINT_SUCCESS = 0 RESTORE_FOOTPRINT_MALFORMED = -1 RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED = -2 + RESTORE_FOOTPRINT_INSUFFICIENT_REFUNDABLE_FEE = -3 def pack(self, packer: Packer) -> None: packer.pack_int(self.value) diff --git a/stellar_sdk/xdr/sc_error.py b/stellar_sdk/xdr/sc_error.py index 113d0276..f8d6b8d7 100644 --- a/stellar_sdk/xdr/sc_error.py +++ b/stellar_sdk/xdr/sc_error.py @@ -8,6 +8,7 @@ from .sc_error_code import SCErrorCode from .sc_error_type import SCErrorType +from .uint32 import Uint32 __all__ = ["SCError"] @@ -16,9 +17,19 @@ class SCError: """ XDR Source Code:: - struct SCError + union SCError switch (SCErrorType type) { - SCErrorType type; + case SCE_CONTRACT: + uint32 contractCode; + case SCE_WASM_VM: + case SCE_CONTEXT: + case SCE_STORAGE: + case SCE_OBJECT: + case SCE_CRYPTO: + case SCE_EVENTS: + case SCE_BUDGET: + case SCE_VALUE: + case SCE_AUTH: SCErrorCode code; }; """ @@ -26,23 +37,100 @@ class SCError: def __init__( self, type: SCErrorType, - code: SCErrorCode, + contract_code: Uint32 = None, + code: SCErrorCode = None, ) -> None: self.type = type + self.contract_code = contract_code self.code = code def pack(self, packer: Packer) -> None: self.type.pack(packer) - self.code.pack(packer) + if self.type == SCErrorType.SCE_CONTRACT: + if self.contract_code is None: + raise ValueError("contract_code should not be None.") + self.contract_code.pack(packer) + return + if self.type == SCErrorType.SCE_WASM_VM: + if self.code is None: + raise ValueError("code should not be None.") + self.code.pack(packer) + return + if self.type == SCErrorType.SCE_CONTEXT: + if self.code is None: + raise ValueError("code should not be None.") + self.code.pack(packer) + return + if self.type == SCErrorType.SCE_STORAGE: + if self.code is None: + raise ValueError("code should not be None.") + self.code.pack(packer) + return + if self.type == SCErrorType.SCE_OBJECT: + if self.code is None: + raise ValueError("code should not be None.") + self.code.pack(packer) + return + if self.type == SCErrorType.SCE_CRYPTO: + if self.code is None: + raise ValueError("code should not be None.") + self.code.pack(packer) + return + if self.type == SCErrorType.SCE_EVENTS: + if self.code is None: + raise ValueError("code should not be None.") + self.code.pack(packer) + return + if self.type == SCErrorType.SCE_BUDGET: + if self.code is None: + raise ValueError("code should not be None.") + self.code.pack(packer) + return + if self.type == SCErrorType.SCE_VALUE: + if self.code is None: + raise ValueError("code should not be None.") + self.code.pack(packer) + return + if self.type == SCErrorType.SCE_AUTH: + if self.code is None: + raise ValueError("code should not be None.") + self.code.pack(packer) + return @classmethod def unpack(cls, unpacker: Unpacker) -> SCError: type = SCErrorType.unpack(unpacker) - code = SCErrorCode.unpack(unpacker) - return cls( - type=type, - code=code, - ) + if type == SCErrorType.SCE_CONTRACT: + contract_code = Uint32.unpack(unpacker) + return cls(type=type, contract_code=contract_code) + if type == SCErrorType.SCE_WASM_VM: + code = SCErrorCode.unpack(unpacker) + return cls(type=type, code=code) + if type == SCErrorType.SCE_CONTEXT: + code = SCErrorCode.unpack(unpacker) + return cls(type=type, code=code) + if type == SCErrorType.SCE_STORAGE: + code = SCErrorCode.unpack(unpacker) + return cls(type=type, code=code) + if type == SCErrorType.SCE_OBJECT: + code = SCErrorCode.unpack(unpacker) + return cls(type=type, code=code) + if type == SCErrorType.SCE_CRYPTO: + code = SCErrorCode.unpack(unpacker) + return cls(type=type, code=code) + if type == SCErrorType.SCE_EVENTS: + code = SCErrorCode.unpack(unpacker) + return cls(type=type, code=code) + if type == SCErrorType.SCE_BUDGET: + code = SCErrorCode.unpack(unpacker) + return cls(type=type, code=code) + if type == SCErrorType.SCE_VALUE: + code = SCErrorCode.unpack(unpacker) + return cls(type=type, code=code) + if type == SCErrorType.SCE_AUTH: + code = SCErrorCode.unpack(unpacker) + return cls(type=type, code=code) + return cls(type=type) def to_xdr_bytes(self) -> bytes: packer = Packer() @@ -67,6 +155,7 @@ def __hash__(self): return hash( ( self.type, + self.contract_code, self.code, ) ) @@ -74,11 +163,17 @@ def __hash__(self): def __eq__(self, other: object): if not isinstance(other, self.__class__): return NotImplemented - return self.type == other.type and self.code == other.code + return ( + self.type == other.type + and self.contract_code == other.contract_code + and self.code == other.code + ) def __str__(self): - out = [ - f"type={self.type}", - f"code={self.code}", - ] + out = [] + out.append(f"type={self.type}") + out.append( + f"contract_code={self.contract_code}" + ) if self.contract_code is not None else None + out.append(f"code={self.code}") if self.code is not None else None return f"" diff --git a/stellar_sdk/xdr/sc_error_code.py b/stellar_sdk/xdr/sc_error_code.py index 6e1283fb..d2593af1 100644 --- a/stellar_sdk/xdr/sc_error_code.py +++ b/stellar_sdk/xdr/sc_error_code.py @@ -16,16 +16,16 @@ class SCErrorCode(IntEnum): enum SCErrorCode { - SCEC_ARITH_DOMAIN = 0, // some arithmetic wasn't defined (overflow, divide-by-zero) - SCEC_INDEX_BOUNDS = 1, // something was indexed beyond its bounds - SCEC_INVALID_INPUT = 2, // user provided some otherwise-bad data - SCEC_MISSING_VALUE = 3, // some value was required but not provided - SCEC_EXISTING_VALUE = 4, // some value was provided where not allowed - SCEC_EXCEEDED_LIMIT = 5, // some arbitrary limit -- gas or otherwise -- was hit - SCEC_INVALID_ACTION = 6, // data was valid but action requested was not - SCEC_INTERNAL_ERROR = 7, // the internal state of the host was otherwise-bad - SCEC_UNEXPECTED_TYPE = 8, // some type wasn't as expected - SCEC_UNEXPECTED_SIZE = 9 // something's size wasn't as expected + SCEC_ARITH_DOMAIN = 0, // Some arithmetic was undefined (overflow, divide-by-zero). + SCEC_INDEX_BOUNDS = 1, // Something was indexed beyond its bounds. + SCEC_INVALID_INPUT = 2, // User provided some otherwise-bad data. + SCEC_MISSING_VALUE = 3, // Some value was required but not provided. + SCEC_EXISTING_VALUE = 4, // Some value was provided where not allowed. + SCEC_EXCEEDED_LIMIT = 5, // Some arbitrary limit -- gas or otherwise -- was hit. + SCEC_INVALID_ACTION = 6, // Data was valid but action requested was not. + SCEC_INTERNAL_ERROR = 7, // The host detected an error in its own logic. + SCEC_UNEXPECTED_TYPE = 8, // Some type wasn't as expected. + SCEC_UNEXPECTED_SIZE = 9 // Something's size wasn't as expected. }; """ diff --git a/stellar_sdk/xdr/sc_error_type.py b/stellar_sdk/xdr/sc_error_type.py index 62a6cfa8..e1016eb0 100644 --- a/stellar_sdk/xdr/sc_error_type.py +++ b/stellar_sdk/xdr/sc_error_type.py @@ -16,16 +16,16 @@ class SCErrorType(IntEnum): enum SCErrorType { - SCE_CONTRACT = 0, - SCE_WASM_VM = 1, - SCE_CONTEXT = 2, - SCE_STORAGE = 3, - SCE_OBJECT = 4, - SCE_CRYPTO = 5, - SCE_EVENTS = 6, - SCE_BUDGET = 7, - SCE_VALUE = 8, - SCE_AUTH = 9 + SCE_CONTRACT = 0, // Contract-specific, user-defined codes. + SCE_WASM_VM = 1, // Errors while interpreting WASM bytecode. + SCE_CONTEXT = 2, // Errors in the contract's host context. + SCE_STORAGE = 3, // Errors accessing host storage. + SCE_OBJECT = 4, // Errors working with host objects. + SCE_CRYPTO = 5, // Errors in cryptographic operations. + SCE_EVENTS = 6, // Errors while emitting events. + SCE_BUDGET = 7, // Errors relating to budget limits. + SCE_VALUE = 8, // Errors working with host values or SCVals. + SCE_AUTH = 9 // Errors from the authentication subsystem. }; """ diff --git a/stellar_sdk/xdr/sc_spec_type.py b/stellar_sdk/xdr/sc_spec_type.py index b4b608f0..84a1525c 100644 --- a/stellar_sdk/xdr/sc_spec_type.py +++ b/stellar_sdk/xdr/sc_spec_type.py @@ -41,7 +41,6 @@ class SCSpecType(IntEnum): SC_SPEC_TYPE_OPTION = 1000, SC_SPEC_TYPE_RESULT = 1001, SC_SPEC_TYPE_VEC = 1002, - SC_SPEC_TYPE_SET = 1003, SC_SPEC_TYPE_MAP = 1004, SC_SPEC_TYPE_TUPLE = 1005, SC_SPEC_TYPE_BYTES_N = 1006, @@ -72,7 +71,6 @@ class SCSpecType(IntEnum): SC_SPEC_TYPE_OPTION = 1000 SC_SPEC_TYPE_RESULT = 1001 SC_SPEC_TYPE_VEC = 1002 - SC_SPEC_TYPE_SET = 1003 SC_SPEC_TYPE_MAP = 1004 SC_SPEC_TYPE_TUPLE = 1005 SC_SPEC_TYPE_BYTES_N = 1006 diff --git a/stellar_sdk/xdr/sc_spec_type_def.py b/stellar_sdk/xdr/sc_spec_type_def.py index 5b37783b..27d9f552 100644 --- a/stellar_sdk/xdr/sc_spec_type_def.py +++ b/stellar_sdk/xdr/sc_spec_type_def.py @@ -14,7 +14,6 @@ from .sc_spec_type_map import SCSpecTypeMap from .sc_spec_type_option import SCSpecTypeOption from .sc_spec_type_result import SCSpecTypeResult - from .sc_spec_type_set import SCSpecTypeSet from .sc_spec_type_tuple import SCSpecTypeTuple from .sc_spec_type_udt import SCSpecTypeUDT from .sc_spec_type_vec import SCSpecTypeVec @@ -54,8 +53,6 @@ class SCSpecTypeDef: SCSpecTypeVec vec; case SC_SPEC_TYPE_MAP: SCSpecTypeMap map; - case SC_SPEC_TYPE_SET: - SCSpecTypeSet set; case SC_SPEC_TYPE_TUPLE: SCSpecTypeTuple tuple; case SC_SPEC_TYPE_BYTES_N: @@ -72,7 +69,6 @@ def __init__( result: SCSpecTypeResult = None, vec: SCSpecTypeVec = None, map: SCSpecTypeMap = None, - set: SCSpecTypeSet = None, tuple: SCSpecTypeTuple = None, bytes_n: SCSpecTypeBytesN = None, udt: SCSpecTypeUDT = None, @@ -82,7 +78,6 @@ def __init__( self.result = result self.vec = vec self.map = map - self.set = set self.tuple = tuple self.bytes_n = bytes_n self.udt = udt @@ -145,11 +140,6 @@ def pack(self, packer: Packer) -> None: raise ValueError("map should not be None.") self.map.pack(packer) return - if self.type == SCSpecType.SC_SPEC_TYPE_SET: - if self.set is None: - raise ValueError("set should not be None.") - self.set.pack(packer) - return if self.type == SCSpecType.SC_SPEC_TYPE_TUPLE: if self.tuple is None: raise ValueError("tuple should not be None.") @@ -225,11 +215,6 @@ def unpack(cls, unpacker: Unpacker) -> SCSpecTypeDef: map = SCSpecTypeMap.unpack(unpacker) return cls(type=type, map=map) - if type == SCSpecType.SC_SPEC_TYPE_SET: - from .sc_spec_type_set import SCSpecTypeSet - - set = SCSpecTypeSet.unpack(unpacker) - return cls(type=type, set=set) if type == SCSpecType.SC_SPEC_TYPE_TUPLE: from .sc_spec_type_tuple import SCSpecTypeTuple @@ -274,7 +259,6 @@ def __hash__(self): self.result, self.vec, self.map, - self.set, self.tuple, self.bytes_n, self.udt, @@ -290,7 +274,6 @@ def __eq__(self, other: object): and self.result == other.result and self.vec == other.vec and self.map == other.map - and self.set == other.set and self.tuple == other.tuple and self.bytes_n == other.bytes_n and self.udt == other.udt @@ -303,7 +286,6 @@ def __str__(self): out.append(f"result={self.result}") if self.result is not None else None out.append(f"vec={self.vec}") if self.vec is not None else None out.append(f"map={self.map}") if self.map is not None else None - out.append(f"set={self.set}") if self.set is not None else None out.append(f"tuple={self.tuple}") if self.tuple is not None else None out.append(f"bytes_n={self.bytes_n}") if self.bytes_n is not None else None out.append(f"udt={self.udt}") if self.udt is not None else None diff --git a/stellar_sdk/xdr/sc_val_type.py b/stellar_sdk/xdr/sc_val_type.py index 3e9cb23b..aef93dae 100644 --- a/stellar_sdk/xdr/sc_val_type.py +++ b/stellar_sdk/xdr/sc_val_type.py @@ -34,8 +34,7 @@ class SCValType(IntEnum): // 128 bits is naturally supported by Rust and we use it for Soroban // fixed-point arithmetic prices / balances / similar "quantities". These - // are represented in XDR as a pair of 2 u64s, unlike {u,i}256 which is - // represented as an array of 32 bytes. + // are represented in XDR as a pair of 2 u64s. SCV_U128 = 9, SCV_I128 = 10, diff --git a/stellar_sdk/xdr/soroban_address_credentials.py b/stellar_sdk/xdr/soroban_address_credentials.py index 38f1de68..17a7c445 100644 --- a/stellar_sdk/xdr/soroban_address_credentials.py +++ b/stellar_sdk/xdr/soroban_address_credentials.py @@ -8,7 +8,7 @@ from .int64 import Int64 from .sc_address import SCAddress -from .sc_vec import SCVec +from .sc_val import SCVal from .uint32 import Uint32 __all__ = ["SorobanAddressCredentials"] @@ -23,7 +23,7 @@ class SorobanAddressCredentials: SCAddress address; int64 nonce; uint32 signatureExpirationLedger; - SCVec signatureArgs; + SCVal signature; }; """ @@ -32,30 +32,30 @@ def __init__( address: SCAddress, nonce: Int64, signature_expiration_ledger: Uint32, - signature_args: SCVec, + signature: SCVal, ) -> None: self.address = address self.nonce = nonce self.signature_expiration_ledger = signature_expiration_ledger - self.signature_args = signature_args + self.signature = signature def pack(self, packer: Packer) -> None: self.address.pack(packer) self.nonce.pack(packer) self.signature_expiration_ledger.pack(packer) - self.signature_args.pack(packer) + self.signature.pack(packer) @classmethod def unpack(cls, unpacker: Unpacker) -> SorobanAddressCredentials: address = SCAddress.unpack(unpacker) nonce = Int64.unpack(unpacker) signature_expiration_ledger = Uint32.unpack(unpacker) - signature_args = SCVec.unpack(unpacker) + signature = SCVal.unpack(unpacker) return cls( address=address, nonce=nonce, signature_expiration_ledger=signature_expiration_ledger, - signature_args=signature_args, + signature=signature, ) def to_xdr_bytes(self) -> bytes: @@ -83,7 +83,7 @@ def __hash__(self): self.address, self.nonce, self.signature_expiration_ledger, - self.signature_args, + self.signature, ) ) @@ -94,7 +94,7 @@ def __eq__(self, other: object): self.address == other.address and self.nonce == other.nonce and self.signature_expiration_ledger == other.signature_expiration_ledger - and self.signature_args == other.signature_args + and self.signature == other.signature ) def __str__(self): @@ -102,6 +102,6 @@ def __str__(self): f"address={self.address}", f"nonce={self.nonce}", f"signature_expiration_ledger={self.signature_expiration_ledger}", - f"signature_args={self.signature_args}", + f"signature={self.signature}", ] return f"" diff --git a/stellar_sdk/xdr/soroban_authorized_function.py b/stellar_sdk/xdr/soroban_authorized_function.py index 306adde4..1cdbab2f 100644 --- a/stellar_sdk/xdr/soroban_authorized_function.py +++ b/stellar_sdk/xdr/soroban_authorized_function.py @@ -7,7 +7,7 @@ from xdrlib3 import Packer, Unpacker from .create_contract_args import CreateContractArgs -from .soroban_authorized_contract_function import SorobanAuthorizedContractFunction +from .invoke_contract_args import InvokeContractArgs from .soroban_authorized_function_type import SorobanAuthorizedFunctionType __all__ = ["SorobanAuthorizedFunction"] @@ -20,7 +20,7 @@ class SorobanAuthorizedFunction: union SorobanAuthorizedFunction switch (SorobanAuthorizedFunctionType type) { case SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN: - SorobanAuthorizedContractFunction contractFn; + InvokeContractArgs contractFn; case SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN: CreateContractArgs createContractHostFn; }; @@ -29,7 +29,7 @@ class SorobanAuthorizedFunction: def __init__( self, type: SorobanAuthorizedFunctionType, - contract_fn: SorobanAuthorizedContractFunction = None, + contract_fn: InvokeContractArgs = None, create_contract_host_fn: CreateContractArgs = None, ) -> None: self.type = type @@ -62,7 +62,7 @@ def unpack(cls, unpacker: Unpacker) -> SorobanAuthorizedFunction: type == SorobanAuthorizedFunctionType.SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN ): - contract_fn = SorobanAuthorizedContractFunction.unpack(unpacker) + contract_fn = InvokeContractArgs.unpack(unpacker) return cls(type=type, contract_fn=contract_fn) if ( type diff --git a/stellar_sdk/xdr/soroban_resources.py b/stellar_sdk/xdr/soroban_resources.py index 67446219..d74f4440 100644 --- a/stellar_sdk/xdr/soroban_resources.py +++ b/stellar_sdk/xdr/soroban_resources.py @@ -27,10 +27,6 @@ class SorobanResources: uint32 readBytes; // The maximum number of bytes this transaction can write to ledger uint32 writeBytes; - - // Maximum size of dynamic metadata produced by this contract ( - // currently only includes the events). - uint32 extendedMetaDataSizeBytes; }; """ @@ -40,20 +36,17 @@ def __init__( instructions: Uint32, read_bytes: Uint32, write_bytes: Uint32, - extended_meta_data_size_bytes: Uint32, ) -> None: self.footprint = footprint self.instructions = instructions self.read_bytes = read_bytes self.write_bytes = write_bytes - self.extended_meta_data_size_bytes = extended_meta_data_size_bytes def pack(self, packer: Packer) -> None: self.footprint.pack(packer) self.instructions.pack(packer) self.read_bytes.pack(packer) self.write_bytes.pack(packer) - self.extended_meta_data_size_bytes.pack(packer) @classmethod def unpack(cls, unpacker: Unpacker) -> SorobanResources: @@ -61,13 +54,11 @@ def unpack(cls, unpacker: Unpacker) -> SorobanResources: instructions = Uint32.unpack(unpacker) read_bytes = Uint32.unpack(unpacker) write_bytes = Uint32.unpack(unpacker) - extended_meta_data_size_bytes = Uint32.unpack(unpacker) return cls( footprint=footprint, instructions=instructions, read_bytes=read_bytes, write_bytes=write_bytes, - extended_meta_data_size_bytes=extended_meta_data_size_bytes, ) def to_xdr_bytes(self) -> bytes: @@ -96,7 +87,6 @@ def __hash__(self): self.instructions, self.read_bytes, self.write_bytes, - self.extended_meta_data_size_bytes, ) ) @@ -108,8 +98,6 @@ def __eq__(self, other: object): and self.instructions == other.instructions and self.read_bytes == other.read_bytes and self.write_bytes == other.write_bytes - and self.extended_meta_data_size_bytes - == other.extended_meta_data_size_bytes ) def __str__(self): @@ -118,6 +106,5 @@ def __str__(self): f"instructions={self.instructions}", f"read_bytes={self.read_bytes}", f"write_bytes={self.write_bytes}", - f"extended_meta_data_size_bytes={self.extended_meta_data_size_bytes}", ] return f"" diff --git a/stellar_sdk/xdr/state_expiration_settings.py b/stellar_sdk/xdr/state_expiration_settings.py index d2a6b461..0b4f6729 100644 --- a/stellar_sdk/xdr/state_expiration_settings.py +++ b/stellar_sdk/xdr/state_expiration_settings.py @@ -21,7 +21,6 @@ class StateExpirationSettings: uint32 maxEntryExpiration; uint32 minTempEntryExpiration; uint32 minPersistentEntryExpiration; - uint32 autoBumpLedgers; // rent_fee = wfee_rate_average / rent_rate_denominator_for_type int64 persistentRentRateDenominator; @@ -35,6 +34,9 @@ class StateExpirationSettings: // Maximum number of bytes that we scan for eviction per ledger uint64 evictionScanSize; + + // Lowest BucketList level to be scanned to evict entries + uint32 startingEvictionScanLevel; }; """ @@ -43,55 +45,55 @@ def __init__( max_entry_expiration: Uint32, min_temp_entry_expiration: Uint32, min_persistent_entry_expiration: Uint32, - auto_bump_ledgers: Uint32, persistent_rent_rate_denominator: Int64, temp_rent_rate_denominator: Int64, max_entries_to_expire: Uint32, bucket_list_size_window_sample_size: Uint32, eviction_scan_size: Uint64, + starting_eviction_scan_level: Uint32, ) -> None: self.max_entry_expiration = max_entry_expiration self.min_temp_entry_expiration = min_temp_entry_expiration self.min_persistent_entry_expiration = min_persistent_entry_expiration - self.auto_bump_ledgers = auto_bump_ledgers self.persistent_rent_rate_denominator = persistent_rent_rate_denominator self.temp_rent_rate_denominator = temp_rent_rate_denominator self.max_entries_to_expire = max_entries_to_expire self.bucket_list_size_window_sample_size = bucket_list_size_window_sample_size self.eviction_scan_size = eviction_scan_size + self.starting_eviction_scan_level = starting_eviction_scan_level def pack(self, packer: Packer) -> None: self.max_entry_expiration.pack(packer) self.min_temp_entry_expiration.pack(packer) self.min_persistent_entry_expiration.pack(packer) - self.auto_bump_ledgers.pack(packer) self.persistent_rent_rate_denominator.pack(packer) self.temp_rent_rate_denominator.pack(packer) self.max_entries_to_expire.pack(packer) self.bucket_list_size_window_sample_size.pack(packer) self.eviction_scan_size.pack(packer) + self.starting_eviction_scan_level.pack(packer) @classmethod def unpack(cls, unpacker: Unpacker) -> StateExpirationSettings: max_entry_expiration = Uint32.unpack(unpacker) min_temp_entry_expiration = Uint32.unpack(unpacker) min_persistent_entry_expiration = Uint32.unpack(unpacker) - auto_bump_ledgers = Uint32.unpack(unpacker) persistent_rent_rate_denominator = Int64.unpack(unpacker) temp_rent_rate_denominator = Int64.unpack(unpacker) max_entries_to_expire = Uint32.unpack(unpacker) bucket_list_size_window_sample_size = Uint32.unpack(unpacker) eviction_scan_size = Uint64.unpack(unpacker) + starting_eviction_scan_level = Uint32.unpack(unpacker) return cls( max_entry_expiration=max_entry_expiration, min_temp_entry_expiration=min_temp_entry_expiration, min_persistent_entry_expiration=min_persistent_entry_expiration, - auto_bump_ledgers=auto_bump_ledgers, persistent_rent_rate_denominator=persistent_rent_rate_denominator, temp_rent_rate_denominator=temp_rent_rate_denominator, max_entries_to_expire=max_entries_to_expire, 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, ) def to_xdr_bytes(self) -> bytes: @@ -119,12 +121,12 @@ def __hash__(self): self.max_entry_expiration, self.min_temp_entry_expiration, self.min_persistent_entry_expiration, - self.auto_bump_ledgers, self.persistent_rent_rate_denominator, self.temp_rent_rate_denominator, self.max_entries_to_expire, self.bucket_list_size_window_sample_size, self.eviction_scan_size, + self.starting_eviction_scan_level, ) ) @@ -136,7 +138,6 @@ def __eq__(self, other: object): and self.min_temp_entry_expiration == other.min_temp_entry_expiration and self.min_persistent_entry_expiration == other.min_persistent_entry_expiration - and self.auto_bump_ledgers == other.auto_bump_ledgers and self.persistent_rent_rate_denominator == other.persistent_rent_rate_denominator and self.temp_rent_rate_denominator == other.temp_rent_rate_denominator @@ -144,6 +145,7 @@ def __eq__(self, other: object): and self.bucket_list_size_window_sample_size == other.bucket_list_size_window_sample_size and self.eviction_scan_size == other.eviction_scan_size + and self.starting_eviction_scan_level == other.starting_eviction_scan_level ) def __str__(self): @@ -151,11 +153,11 @@ def __str__(self): f"max_entry_expiration={self.max_entry_expiration}", f"min_temp_entry_expiration={self.min_temp_entry_expiration}", f"min_persistent_entry_expiration={self.min_persistent_entry_expiration}", - f"auto_bump_ledgers={self.auto_bump_ledgers}", f"persistent_rent_rate_denominator={self.persistent_rent_rate_denominator}", f"temp_rent_rate_denominator={self.temp_rent_rate_denominator}", f"max_entries_to_expire={self.max_entries_to_expire}", f"bucket_list_size_window_sample_size={self.bucket_list_size_window_sample_size}", f"eviction_scan_size={self.eviction_scan_size}", + f"starting_eviction_scan_level={self.starting_eviction_scan_level}", ] return f"" diff --git a/stellar_sdk/xdr/transaction_result.py b/stellar_sdk/xdr/transaction_result.py index 862f2ae0..40372275 100644 --- a/stellar_sdk/xdr/transaction_result.py +++ b/stellar_sdk/xdr/transaction_result.py @@ -44,7 +44,7 @@ class TransactionResult: case txBAD_SPONSORSHIP: case txBAD_MIN_SEQ_AGE_OR_GAP: case txMALFORMED: - case txSOROBAN_RESOURCE_LIMIT_EXCEEDED: + case txSOROBAN_INVALID: void; } result; diff --git a/stellar_sdk/xdr/transaction_result_code.py b/stellar_sdk/xdr/transaction_result_code.py index 15fb10b2..0c88a6df 100644 --- a/stellar_sdk/xdr/transaction_result_code.py +++ b/stellar_sdk/xdr/transaction_result_code.py @@ -33,14 +33,12 @@ class TransactionResultCode(IntEnum): txBAD_AUTH_EXTRA = -10, // unused signatures attached to transaction txINTERNAL_ERROR = -11, // an unknown error occurred - txNOT_SUPPORTED = -12, // transaction type not supported - txFEE_BUMP_INNER_FAILED = -13, // fee bump inner transaction failed - txBAD_SPONSORSHIP = -14, // sponsorship not confirmed - txBAD_MIN_SEQ_AGE_OR_GAP = - -15, // minSeqAge or minSeqLedgerGap conditions not met - txMALFORMED = -16, // precondition is invalid - // declared Soroban resource usage exceeds the network limit - txSOROBAN_RESOURCE_LIMIT_EXCEEDED = -17 + txNOT_SUPPORTED = -12, // transaction type not supported + txFEE_BUMP_INNER_FAILED = -13, // fee bump inner transaction failed + txBAD_SPONSORSHIP = -14, // sponsorship not confirmed + txBAD_MIN_SEQ_AGE_OR_GAP = -15, // minSeqAge or minSeqLedgerGap conditions not met + txMALFORMED = -16, // precondition is invalid + txSOROBAN_INVALID = -17 // soroban-specific preconditions were not met }; """ @@ -62,7 +60,7 @@ class TransactionResultCode(IntEnum): txBAD_SPONSORSHIP = -14 txBAD_MIN_SEQ_AGE_OR_GAP = -15 txMALFORMED = -16 - txSOROBAN_RESOURCE_LIMIT_EXCEEDED = -17 + txSOROBAN_INVALID = -17 def pack(self, packer: Packer) -> None: packer.pack_int(self.value) diff --git a/stellar_sdk/xdr/transaction_result_result.py b/stellar_sdk/xdr/transaction_result_result.py index 0e00ad60..d42178cf 100644 --- a/stellar_sdk/xdr/transaction_result_result.py +++ b/stellar_sdk/xdr/transaction_result_result.py @@ -41,7 +41,7 @@ class TransactionResultResult: case txBAD_SPONSORSHIP: case txBAD_MIN_SEQ_AGE_OR_GAP: case txMALFORMED: - case txSOROBAN_RESOURCE_LIMIT_EXCEEDED: + case txSOROBAN_INVALID: void; } """ @@ -115,7 +115,7 @@ def pack(self, packer: Packer) -> None: return if self.code == TransactionResultCode.txMALFORMED: return - if self.code == TransactionResultCode.txSOROBAN_RESOURCE_LIMIT_EXCEEDED: + if self.code == TransactionResultCode.txSOROBAN_INVALID: return @classmethod @@ -167,7 +167,7 @@ def unpack(cls, unpacker: Unpacker) -> TransactionResultResult: return cls(code=code) if code == TransactionResultCode.txMALFORMED: return cls(code=code) - if code == TransactionResultCode.txSOROBAN_RESOURCE_LIMIT_EXCEEDED: + if code == TransactionResultCode.txSOROBAN_INVALID: return cls(code=code) return cls(code=code) diff --git a/tests/operation/test_invoke_host_function.py b/tests/operation/test_invoke_host_function.py index 361ef156..daa08a3b 100644 --- a/tests/operation/test_invoke_host_function.py +++ b/tests/operation/test_invoke_host_function.py @@ -10,17 +10,15 @@ class TestInvokeHostFunction: def test_xdr_without_auth(self): contract_id = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW" function_name = "increment" - invoke_params = [ - Address(contract_id).to_xdr_sc_val(), - stellar_xdr.SCVal( - stellar_xdr.SCValType.SCV_SYMBOL, - sym=stellar_xdr.SCSymbol(sc_symbol=function_name.encode("utf-8")), - ), - scval.to_int256(234325465), - ] host_function = stellar_xdr.HostFunction( stellar_xdr.HostFunctionType.HOST_FUNCTION_TYPE_INVOKE_CONTRACT, - invoke_contract=stellar_xdr.SCVec(invoke_params), + invoke_contract=stellar_xdr.InvokeContractArgs( + contract_address=Address(contract_id).to_xdr_sc_address(), + function_name=stellar_xdr.SCSymbol( + sc_symbol=function_name.encode("utf-8") + ), + args=[scval.to_int256(234325465)], + ), ) op = InvokeHostFunction(host_function, [], source=kp1.public_key) assert op.host_function == host_function @@ -32,17 +30,15 @@ def test_xdr_without_auth(self): def test_xdr_auth(self): contract_id = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW" function_name = "increment" - invoke_params = [ - Address(contract_id).to_xdr_sc_val(), - stellar_xdr.SCVal( - stellar_xdr.SCValType.SCV_SYMBOL, - sym=stellar_xdr.SCSymbol(sc_symbol=function_name.encode("utf-8")), - ), - scval.to_int256(234325465), - ] host_function = stellar_xdr.HostFunction( stellar_xdr.HostFunctionType.HOST_FUNCTION_TYPE_INVOKE_CONTRACT, - invoke_contract=stellar_xdr.SCVec(invoke_params), + invoke_contract=stellar_xdr.InvokeContractArgs( + contract_address=Address(contract_id).to_xdr_sc_address(), + function_name=stellar_xdr.SCSymbol( + sc_symbol=function_name.encode("utf-8") + ), + args=[scval.to_int256(234325465)], + ), ) auth = [ @@ -53,12 +49,12 @@ def test_xdr_auth(self): root_invocation=stellar_xdr.SorobanAuthorizedInvocation( function=stellar_xdr.SorobanAuthorizedFunction( type=stellar_xdr.SorobanAuthorizedFunctionType.SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN, - contract_fn=stellar_xdr.SorobanAuthorizedContractFunction( + contract_fn=stellar_xdr.InvokeContractArgs( contract_address=Address( "CDCYWK73YTYFJZZSJ5V7EDFNHYBG4QN3VUNG2IGD27KJDDPNCZKBCBXK" ).to_xdr_sc_address(), function_name=stellar_xdr.SCSymbol(b"increment"), - args=stellar_xdr.SCVec([]), + args=[], ), ), sub_invocations=[], diff --git a/tests/test_soroban_data_builder.py b/tests/test_soroban_data_builder.py index e5a167be..6a944a95 100644 --- a/tests/test_soroban_data_builder.py +++ b/tests/test_soroban_data_builder.py @@ -12,7 +12,6 @@ class TestSorobanDataBuilder: read_only=[], read_write=[], ), - extended_meta_data_size_bytes=stellar_xdr.Uint32(0), read_bytes=stellar_xdr.Uint32(0), write_bytes=stellar_xdr.Uint32(0), instructions=stellar_xdr.Uint32(0), @@ -33,7 +32,6 @@ def test_from_xdr_object(self): read_only=[], read_write=[], ), - extended_meta_data_size_bytes=stellar_xdr.Uint32(1), read_bytes=stellar_xdr.Uint32(2), write_bytes=stellar_xdr.Uint32(3), instructions=stellar_xdr.Uint32(4), @@ -53,7 +51,6 @@ def test_from_xdr_base64(self): read_only=[], read_write=[], ), - extended_meta_data_size_bytes=stellar_xdr.Uint32(1), read_bytes=stellar_xdr.Uint32(2), write_bytes=stellar_xdr.Uint32(3), instructions=stellar_xdr.Uint32(4), @@ -70,7 +67,7 @@ def test_set_refundable_fee(self): assert builder.build().refundable_fee.int64 == 100 def test_set_resources(self): - data = SorobanDataBuilder().set_resources(1, 2, 3, 4).build() + data = SorobanDataBuilder().set_resources(1, 2, 3).build() assert data == stellar_xdr.SorobanTransactionData( ext=stellar_xdr.ExtensionPoint(0), refundable_fee=stellar_xdr.Int64(0), @@ -82,7 +79,6 @@ def test_set_resources(self): instructions=stellar_xdr.Uint32(1), read_bytes=stellar_xdr.Uint32(2), write_bytes=stellar_xdr.Uint32(3), - extended_meta_data_size_bytes=stellar_xdr.Uint32(4), ), ) @@ -104,7 +100,6 @@ def test_set_read_only(self): read_only=[ledger_key], read_write=[], ), - extended_meta_data_size_bytes=stellar_xdr.Uint32(0), read_bytes=stellar_xdr.Uint32(0), write_bytes=stellar_xdr.Uint32(0), instructions=stellar_xdr.Uint32(0), @@ -129,7 +124,6 @@ def test_set_read_write(self): read_only=[], read_write=[ledger_key], ), - extended_meta_data_size_bytes=stellar_xdr.Uint32(0), read_bytes=stellar_xdr.Uint32(0), write_bytes=stellar_xdr.Uint32(0), instructions=stellar_xdr.Uint32(0), diff --git a/tests/test_soroban_server.py b/tests/test_soroban_server.py index e3d192cd..d5f09330 100644 --- a/tests/test_soroban_server.py +++ b/tests/test_soroban_server.py @@ -120,19 +120,20 @@ def test_get_contract_data(self): result = { "entries": [ { - "key": "AAAABgAAAAFgdoLyR3pr6M3w/fMr4T1fJaaGzAlP2T1ao9e2gjLQwAAAABQAAAABAAAAAA==", - "xdr": "AAAABgAAAAFgdoLyR3pr6M3w/fMr4T1fJaaGzAlP2T1ao9e2gjLQwAAAABQAAAABAAAAAAAAAAAAAAATAAAAALnBupvoT7RHZ+oTeaPHSiSufpac3O3mc0u663Kqbko/AAAAAQAAAAEAAAAPAAAAB0NPVU5URVIAAAAAAwAAAAEAABD1", - "lastModifiedLedgerSeq": "290", + "key": "AAAABgAAAAFbihjlAiytnchoNOQZzgshTg9sfCxcBnTGO2xwtRu0awAAABQAAAAB", + "xdr": "AAAABgAAAAAAAAABW4oY5QIsrZ3IaDTkGc4LIU4PbHwsXAZ0xjtscLUbtGsAAAAUAAAAAQAAABMAAAAAJEKO7o0EZBi/DpFId2xLI1yGppi+ADrnh9IIE/CfJEcAAAAA", + "lastModifiedLedgerSeq": "11715", } ], - "latestLedger": "296", + "latestLedger": "12551", } + data = { "jsonrpc": "2.0", "id": "839c6c921d40456db5ba8a1c4e1a0e70", "result": result, } - contract_id = "CBQHNAXSI55GX2GN6D67GK7BHVPSLJUGZQEU7WJ5LKR5PNUCGLIMAO4K" + contract_id = "CBNYUGHFAIWK3HOINA2OIGOOBMQU4D3MPQWFYBTUYY5WY4FVDO2GWXUY" key = stellar_xdr.SCVal(stellar_xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_INSTANCE) with requests_mock.Mocker() as m: m.post(PRC_URL, json=data) @@ -149,9 +150,7 @@ def test_get_contract_data(self): stellar_xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_INSTANCE ) assert request_data["params"] == { - "keys": [ - "AAAABgAAAAFgdoLyR3pr6M3w/fMr4T1fJaaGzAlP2T1ao9e2gjLQwAAAABQAAAABAAAAAA==" - ] + "keys": ["AAAABgAAAAFbihjlAiytnchoNOQZzgshTg9sfCxcBnTGO2xwtRu0awAAABQAAAAB"] } def test_get_contract_data_not_found(self): @@ -161,7 +160,7 @@ def test_get_contract_data_not_found(self): "id": "839c6c921d40456db5ba8a1c4e1a0e70", "result": result, } - contract_id = "CBQHNAXSI55GX2GN6D67GK7BHVPSLJUGZQEU7WJ5LKR5PNUCGLIMAO4K" + contract_id = "CBNYUGHFAIWK3HOINA2OIGOOBMQU4D3MPQWFYBTUYY5WY4FVDO2GWXUY" key = stellar_xdr.SCVal(stellar_xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_INSTANCE) with requests_mock.Mocker() as m: m.post(PRC_URL, json=data) @@ -175,9 +174,7 @@ def test_get_contract_data_not_found(self): stellar_xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_INSTANCE ) assert request_data["params"] == { - "keys": [ - "AAAABgAAAAFgdoLyR3pr6M3w/fMr4T1fJaaGzAlP2T1ao9e2gjLQwAAAABQAAAABAAAAAA==" - ] + "keys": ["AAAABgAAAAFbihjlAiytnchoNOQZzgshTg9sfCxcBnTGO2xwtRu0awAAABQAAAAB"] } def test_get_ledger_entries(self): @@ -270,30 +267,30 @@ def test_get_events(self): "events": [ { "type": "contract", - "ledger": "107", - "ledgerClosedAt": "2023-07-28T14:57:02Z", - "contractId": "607682f2477a6be8cdf0fdf32be13d5f25a686cc094fd93d5aa3d7b68232d0c0", - "id": "0000000459561504768-0000000000", - "pagingToken": "0000000459561504768-0000000000", + "ledger": "12739", + "ledgerClosedAt": "2023-09-16T06:23:57Z", + "contractId": "CBNYUGHFAIWK3HOINA2OIGOOBMQU4D3MPQWFYBTUYY5WY4FVDO2GWXUY", + "id": "0000054713588387840-0000000000", + "pagingToken": "0000054713588387840-0000000000", "topic": [ "AAAADwAAAAdDT1VOVEVSAA==", "AAAADwAAAAlpbmNyZW1lbnQAAAA=", ], - "value": {"xdr": "AAAAAwAAAAQ="}, + "value": {"xdr": "AAAAAwAAAAE="}, "inSuccessfulContractCall": True, }, { "type": "contract", - "ledger": "109", - "ledgerClosedAt": "2023-07-28T14:57:04Z", - "contractId": "607682f2477a6be8cdf0fdf32be13d5f25a686cc094fd93d5aa3d7b68232d0c0", - "id": "0000000468151439360-0000000000", - "pagingToken": "0000000468151439360-0000000000", + "ledger": "12747", + "ledgerClosedAt": "2023-09-16T06:24:05Z", + "contractId": "CBNYUGHFAIWK3HOINA2OIGOOBMQU4D3MPQWFYBTUYY5WY4FVDO2GWXUY", + "id": "0000054747948126208-0000000000", + "pagingToken": "0000054747948126208-0000000000", "topic": [ "AAAADwAAAAdDT1VOVEVSAA==", "AAAADwAAAAlpbmNyZW1lbnQAAAA=", ], - "value": {"xdr": "AAAAAwAAAAU="}, + "value": {"xdr": "AAAAAwAAAAI="}, "inSuccessfulContractCall": True, }, ], @@ -310,7 +307,7 @@ def test_get_events(self): EventFilter( event_type=EventFilterType.CONTRACT, contract_ids=[ - "607682f2477a6be8cdf0fdf32be13d5f25a686cc094fd93d5aa3d7b68232d0c0" + "CBNYUGHFAIWK3HOINA2OIGOOBMQU4D3MPQWFYBTUYY5WY4FVDO2GWXUY" ], topics=[ ["AAAADwAAAAdDT1VOVEVSAA==", "AAAADwAAAAlpbmNyZW1lbnQAAAA="], @@ -318,7 +315,7 @@ def test_get_events(self): ) ] GetEventsResponse.model_validate(result) - cursor = "0000007799660613632-0000000000" + cursor = "0000054713588387839-0000000000" limit = 10 with requests_mock.Mocker() as m: m.post(PRC_URL, json=data) @@ -334,7 +331,7 @@ def test_get_events(self): "filters": [ { "contractIds": [ - "607682f2477a6be8cdf0fdf32be13d5f25a686cc094fd93d5aa3d7b68232d0c0" + "CBNYUGHFAIWK3HOINA2OIGOOBMQU4D3MPQWFYBTUYY5WY4FVDO2GWXUY" ], "topics": [ ["AAAADwAAAAdDT1VOVEVSAA==", "AAAADwAAAAlpbmNyZW1lbnQAAAA="] @@ -342,7 +339,7 @@ def test_get_events(self): "type": "contract", } ], - "pagination": {"cursor": "0000007799660613632-0000000000", "limit": 10}, + "pagination": {"cursor": "0000054713588387839-0000000000", "limit": 10}, "startLedger": "100", } @@ -409,24 +406,24 @@ def test_simulate_transaction(self): def test_prepare_transaction_without_auth_and_soroban_data(self): data = { "jsonrpc": "2.0", - "id": "e1fabdcdf0244a2a9adfab94d7748b6c", + "id": "7a469b9d6ed4444893491be530862ce3", "result": { - "transactionData": "AAAAAAAAAAIAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAFAAAAAEAAAAAAAAAB300Hyg0HZG+Qie3zvsxLvugrNtFqd3AIntWy9bg2YvZAAAAAAAAAAEAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAEAAAAAEAAAACAAAADwAAAAdDb3VudGVyAAAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAQAAAAAAFcLDAAAF8AAAAQgAAAMcAAAAAAAAAJw=", + "transactionData": "AAAAAAAAAAIAAAAGAAAAAem354u9STQWq5b3Ed1j9tOemvL7xV0NPwhn4gXg0AP8AAAAFAAAAAEAAAAH8dTe2OoI0BnhlDbH0fWvXmvprkBvBAgKIcL9busuuMEAAAABAAAABgAAAAHpt+eLvUk0FquW9xHdY/bTnpry+8VdDT8IZ+IF4NAD/AAAABAAAAABAAAAAgAAAA8AAAAHQ291bnRlcgAAAAASAAAAAAAAAABYt8SiyPKXqo89JHEoH9/M7K/kjlZjMT7BjhKnPsqYoQAAAAEAHifGAAAFlAAAAIgAAAAAAAAAAg==", + "minResourceFee": "58181", "events": [ - "AAAAAQAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAAPAAAACWluY3JlbWVudAAAAAAAABAAAAABAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAo=", - "AAAAAQAAAAAAAAABxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAACAAAAAAAAAAIAAAAPAAAACWZuX3JldHVybgAAAAAAAA8AAAAJaW5jcmVtZW50AAAAAAAAAwAAABQ=", + "AAAAAQAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAg6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAAPAAAACWluY3JlbWVudAAAAAAAABAAAAABAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAo=", + "AAAAAQAAAAAAAAAB6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAACAAAAAAAAAAIAAAAPAAAACWZuX3JldHVybgAAAAAAAA8AAAAJaW5jcmVtZW50AAAAAAAAAwAAABQ=", ], - "minResourceFee": "58595", "results": [ { "auth": [ - "AAAAAAAAAAAAAAABxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA" + "AAAAAAAAAAAAAAAB6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA" ], "xdr": "AAAAAwAAABQ=", } ], - "cost": {"cpuInsns": "1240100", "memBytes": "161637"}, - "latestLedger": "1479", + "cost": {"cpuInsns": "1646885", "memBytes": "1296481"}, + "latestLedger": "14245", }, } @@ -451,24 +448,24 @@ def test_prepare_transaction_without_auth_and_soroban_data(self): def test_prepare_transaction_with_soroban_data(self): data = { "jsonrpc": "2.0", - "id": "e1fabdcdf0244a2a9adfab94d7748b6c", + "id": "7a469b9d6ed4444893491be530862ce3", "result": { - "transactionData": "AAAAAAAAAAIAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAFAAAAAEAAAAAAAAAB300Hyg0HZG+Qie3zvsxLvugrNtFqd3AIntWy9bg2YvZAAAAAAAAAAEAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAEAAAAAEAAAACAAAADwAAAAdDb3VudGVyAAAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAQAAAAAAFcLDAAAF8AAAAQgAAAMcAAAAAAAAAJw=", + "transactionData": "AAAAAAAAAAIAAAAGAAAAAem354u9STQWq5b3Ed1j9tOemvL7xV0NPwhn4gXg0AP8AAAAFAAAAAEAAAAH8dTe2OoI0BnhlDbH0fWvXmvprkBvBAgKIcL9busuuMEAAAABAAAABgAAAAHpt+eLvUk0FquW9xHdY/bTnpry+8VdDT8IZ+IF4NAD/AAAABAAAAABAAAAAgAAAA8AAAAHQ291bnRlcgAAAAASAAAAAAAAAABYt8SiyPKXqo89JHEoH9/M7K/kjlZjMT7BjhKnPsqYoQAAAAEAHifGAAAFlAAAAIgAAAAAAAAAAg==", + "minResourceFee": "58181", "events": [ - "AAAAAQAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAAPAAAACWluY3JlbWVudAAAAAAAABAAAAABAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAo=", - "AAAAAQAAAAAAAAABxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAACAAAAAAAAAAIAAAAPAAAACWZuX3JldHVybgAAAAAAAA8AAAAJaW5jcmVtZW50AAAAAAAAAwAAABQ=", + "AAAAAQAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAg6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAAPAAAACWluY3JlbWVudAAAAAAAABAAAAABAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAo=", + "AAAAAQAAAAAAAAAB6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAACAAAAAAAAAAIAAAAPAAAACWZuX3JldHVybgAAAAAAAA8AAAAJaW5jcmVtZW50AAAAAAAAAwAAABQ=", ], - "minResourceFee": "58595", "results": [ { "auth": [ - "AAAAAAAAAAAAAAABxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA" + "AAAAAAAAAAAAAAAB6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA" ], "xdr": "AAAAAwAAABQ=", } ], - "cost": {"cpuInsns": "1240100", "memBytes": "161637"}, - "latestLedger": "1479", + "cost": {"cpuInsns": "1646885", "memBytes": "1296481"}, + "latestLedger": "14245", }, } @@ -480,7 +477,6 @@ def test_prepare_transaction_with_soroban_data(self): read_only=[], read_write=[], ), - extended_meta_data_size_bytes=stellar_xdr.Uint32(1), read_bytes=stellar_xdr.Uint32(2), write_bytes=stellar_xdr.Uint32(3), instructions=stellar_xdr.Uint32(4), @@ -507,24 +503,24 @@ def test_prepare_transaction_with_soroban_data(self): def test_prepare_transaction_with_auth(self): data = { "jsonrpc": "2.0", - "id": "e1fabdcdf0244a2a9adfab94d7748b6c", + "id": "7a469b9d6ed4444893491be530862ce3", "result": { - "transactionData": "AAAAAAAAAAIAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAFAAAAAEAAAAAAAAAB300Hyg0HZG+Qie3zvsxLvugrNtFqd3AIntWy9bg2YvZAAAAAAAAAAEAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAEAAAAAEAAAACAAAADwAAAAdDb3VudGVyAAAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAQAAAAAAFcLDAAAF8AAAAQgAAAMcAAAAAAAAAJw=", + "transactionData": "AAAAAAAAAAIAAAAGAAAAAem354u9STQWq5b3Ed1j9tOemvL7xV0NPwhn4gXg0AP8AAAAFAAAAAEAAAAH8dTe2OoI0BnhlDbH0fWvXmvprkBvBAgKIcL9busuuMEAAAABAAAABgAAAAHpt+eLvUk0FquW9xHdY/bTnpry+8VdDT8IZ+IF4NAD/AAAABAAAAABAAAAAgAAAA8AAAAHQ291bnRlcgAAAAASAAAAAAAAAABYt8SiyPKXqo89JHEoH9/M7K/kjlZjMT7BjhKnPsqYoQAAAAEAHifGAAAFlAAAAIgAAAAAAAAAAg==", + "minResourceFee": "58181", "events": [ - "AAAAAQAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAAPAAAACWluY3JlbWVudAAAAAAAABAAAAABAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAo=", - "AAAAAQAAAAAAAAABxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAACAAAAAAAAAAIAAAAPAAAACWZuX3JldHVybgAAAAAAAA8AAAAJaW5jcmVtZW50AAAAAAAAAwAAABQ=", + "AAAAAQAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAg6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAAPAAAACWluY3JlbWVudAAAAAAAABAAAAABAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAo=", + "AAAAAQAAAAAAAAAB6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAACAAAAAAAAAAIAAAAPAAAACWZuX3JldHVybgAAAAAAAA8AAAAJaW5jcmVtZW50AAAAAAAAAwAAABQ=", ], - "minResourceFee": "58595", "results": [ { "auth": [ - "AAAAAAAAAAAAAAABxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA" + "AAAAAAAAAAAAAAAB6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA" ], "xdr": "AAAAAwAAABQ=", } ], - "cost": {"cpuInsns": "1240100", "memBytes": "161637"}, - "latestLedger": "1479", + "cost": {"cpuInsns": "1646885", "memBytes": "1296481"}, + "latestLedger": "14245", }, } @@ -535,12 +531,12 @@ def test_prepare_transaction_with_auth(self): root_invocation=stellar_xdr.SorobanAuthorizedInvocation( function=stellar_xdr.SorobanAuthorizedFunction( type=stellar_xdr.SorobanAuthorizedFunctionType.SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN, - contract_fn=stellar_xdr.SorobanAuthorizedContractFunction( + contract_fn=stellar_xdr.InvokeContractArgs( contract_address=Address( "CDCYWK73YTYFJZZSJ5V7EDFNHYBG4QN3VUNG2IGD27KJDDPNCZKBCBXK" ).to_xdr_sc_address(), function_name=stellar_xdr.SCSymbol(b"increment"), - args=stellar_xdr.SCVec([]), + args=[], ), ), sub_invocations=[], @@ -588,54 +584,38 @@ def test_prepare_transaction_error_resp_prepare_transaction_exception_raise(self == SimulateTransactionResponse.model_validate(data["result"]) ) - def test_prepare_transaction_invalid_results_prepare_transaction_exception_raise( + def test_prepare_transaction_invalid_results_value_raise( self, ): + # this error should not happen data = { "jsonrpc": "2.0", - "id": "e1fabdcdf0244a2a9adfab94d7748b6c", + "id": "7a469b9d6ed4444893491be530862ce3", "result": { - "transactionData": "AAAAAAAAAAIAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAFAAAAAEAAAAAAAAAB300Hyg0HZG+Qie3zvsxLvugrNtFqd3AIntWy9bg2YvZAAAAAAAAAAEAAAAGAAAAAcWLK/vE8FTnMk9r8gytPgJuQbutGm0gw9fUkY3tFlQRAAAAEAAAAAEAAAACAAAADwAAAAdDb3VudGVyAAAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAQAAAAAAFcLDAAAF8AAAAQgAAAMcAAAAAAAAAJw=", + "transactionData": "AAAAAAAAAAIAAAAGAAAAAem354u9STQWq5b3Ed1j9tOemvL7xV0NPwhn4gXg0AP8AAAAFAAAAAEAAAAH8dTe2OoI0BnhlDbH0fWvXmvprkBvBAgKIcL9busuuMEAAAABAAAABgAAAAHpt+eLvUk0FquW9xHdY/bTnpry+8VdDT8IZ+IF4NAD/AAAABAAAAABAAAAAgAAAA8AAAAHQ291bnRlcgAAAAASAAAAAAAAAABYt8SiyPKXqo89JHEoH9/M7K/kjlZjMT7BjhKnPsqYoQAAAAEAHifGAAAFlAAAAIgAAAAAAAAAAg==", + "minResourceFee": "58181", "events": [ - "AAAAAQAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAAPAAAACWluY3JlbWVudAAAAAAAABAAAAABAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAo=", - "AAAAAQAAAAAAAAABxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAACAAAAAAAAAAIAAAAPAAAACWZuX3JldHVybgAAAAAAAA8AAAAJaW5jcmVtZW50AAAAAAAAAwAAABQ=", + "AAAAAQAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAg6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAAPAAAACWluY3JlbWVudAAAAAAAABAAAAABAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAo=", + "AAAAAQAAAAAAAAAB6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAACAAAAAAAAAAIAAAAPAAAACWZuX3JldHVybgAAAAAAAA8AAAAJaW5jcmVtZW50AAAAAAAAAwAAABQ=", ], - "minResourceFee": "58595", - "results": [ - { - "auth": [ - "AAAAAAAAAAAAAAABxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA" - ], - "xdr": "AAAAAwAAABQ=", - }, - { - "auth": [ - "AAAAAAAAAAAAAAABxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA" - ], - "xdr": "AAAAAwAAABQ=", - }, - ], - "cost": {"cpuInsns": "1240100", "memBytes": "161637"}, - "latestLedger": "1479", + "results": [], + "cost": {"cpuInsns": "1646885", "memBytes": "1296481"}, + "latestLedger": "14245", }, } transaction = _build_soroban_transaction(None, []) with requests_mock.Mocker() as m: m.post(PRC_URL, json=data) with pytest.raises( - PrepareTransactionException, - match='Simulation transaction failed, the "results" field is invalid.', + ValueError, + match="Simulation results invalid", ) as e: SorobanServer(PRC_URL).prepare_transaction(transaction) - assert ( - e.value.simulate_transaction_response - == SimulateTransactionResponse.model_validate(data["result"]) - ) def test_send_transaction(self): result = { "status": "PENDING", - "hash": "f59636c3bb27ad958c599632405ed657c3d7d55c717dbfd2644a68625e9d9e7e", + "hash": "64977cc4bb7f8bf75bdc47570548a994667899d3319b72f95cb2a64e567ad52c", "latestLedger": "1479", "latestLedgerCloseTime": "1690594566", } @@ -682,7 +662,9 @@ def _build_soroban_transaction( soroban_data: Optional[stellar_xdr.SorobanTransactionData], auth: List[stellar_xdr.SorobanAuthorizationEntry], ): - contract_id = "CDCYWK73YTYFJZZSJ5V7EDFNHYBG4QN3VUNG2IGD27KJDDPNCZKBCBXK" + contract_id = ( + "CDU3PZ4LXVETIFVLS33RDXLD63JZ5GXS7PCV2DJ7BBT6EBPA2AB7YR5H" # auth contract + ) tx_submitter_kp = Keypair.from_secret( "SAAPYAPTTRZMCUZFPG3G66V4ZMHTK4TWA6NS7U4F7Z3IMUD52EK4DDEV" @@ -690,7 +672,7 @@ def _build_soroban_transaction( op_invoker_kp = Keypair.from_secret( "SAEZSI6DY7AXJFIYA4PM6SIBNEYYXIEM2MSOTHFGKHDW32MBQ7KVO6EN" ) - source = Account(tx_submitter_kp.public_key, 6171868004355) + source = Account(tx_submitter_kp.public_key, 3053721747476) tx_builder = ( TransactionBuilder( source_account=source, diff --git a/xdr/Stellar-contract-config-setting.x b/xdr/Stellar-contract-config-setting.x index 00fa376a..9512f0c4 100644 --- a/xdr/Stellar-contract-config-setting.x +++ b/xdr/Stellar-contract-config-setting.x @@ -48,16 +48,16 @@ struct ConfigSettingContractLedgerCostV0 int64 feeWriteLedgerEntry; // Fee per ledger entry write int64 feeRead1KB; // Fee for reading 1KB - int64 feeWrite1KB; // Fee for writing 1KB - - // Bucket list fees grow slowly up to that size - int64 bucketListSizeBytes; - // Fee rate in stroops when the bucket list is empty - int64 bucketListFeeRateLow; - // Fee rate in stroops when the bucket list reached bucketListSizeBytes - int64 bucketListFeeRateHigh; - // Rate multiplier for any additional data past the first bucketListSizeBytes - uint32 bucketListGrowthFactor; + + // The following parameters determine the write fee per 1KB. + // Write fee grows linearly until bucket list reaches this size + int64 bucketListTargetSizeBytes; + // Fee per 1KB write when the bucket list is empty + int64 writeFee1KBBucketListLow; + // Fee per 1KB write when the bucket list has reached `bucketListTargetSizeBytes` + int64 writeFee1KBBucketListHigh; + // Write fee multiplier for any additional data past the first `bucketListTargetSizeBytes` + uint32 bucketListWriteFeeGrowthFactor; }; // Historical data (pushed to core archives) settings for contracts. @@ -66,25 +66,27 @@ struct ConfigSettingContractHistoricalDataV0 int64 feeHistorical1KB; // Fee for storing 1KB in archives }; -// Meta data (pushed to downstream systems) settings for contracts. -struct ConfigSettingContractMetaDataV0 +// Contract event-related settings. +struct ConfigSettingContractEventsV0 { - // Maximum size of extended meta data produced by a transaction - uint32 txMaxExtendedMetaDataSizeBytes; - // Fee for generating 1KB of extended meta data - int64 feeExtendedMetaData1KB; + // Maximum size of events that a contract call can emit. + uint32 txMaxContractEventsSizeBytes; + // Fee for generating 1KB of contract events. + int64 feeContractEvents1KB; }; -// Bandwidth related data settings for contracts +// Bandwidth related data settings for contracts. +// We consider bandwidth to only be consumed by the transaction envelopes, hence +// this concerns only transaction sizes. struct ConfigSettingContractBandwidthV0 { - // Maximum size in bytes to propagate per ledger - uint32 ledgerMaxPropagateSizeBytes; + // Maximum sum of all transaction sizes in the ledger in bytes + uint32 ledgerMaxTxsSizeBytes; // Maximum size in bytes for a transaction uint32 txMaxSizeBytes; - // Fee for propagating 1KB of data - int64 feePropagateData1KB; + // Fee for 1 KB of transaction size + int64 feeTxSize1KB; }; enum ContractCostType { @@ -98,61 +100,56 @@ enum ContractCostType { HostMemCpy = 3, // Cost of comparing two slices of host memory HostMemCmp = 4, - // Cost of a host function invocation, not including the actual work done by the function - InvokeHostFunction = 5, - // Cost of visiting a host object from the host object storage - // Only thing to make sure is the guest can't visitObject repeatly without incurring some charges elsewhere. + // Cost of a host function dispatch, not including the actual work done by + // the function nor the cost of VM invocation machinary + DispatchHostFunction = 5, + // Cost of visiting a host object from the host object storage. Exists to + // make sure some baseline cost coverage, i.e. repeatly visiting objects + // by the guest will always incur some charges. VisitObject = 6, - // Tracks a single Val (RawVal or primative Object like U64) <=> ScVal - // conversion cost. Most of these Val counterparts in ScVal (except e.g. - // Symbol) consumes a single int64 and therefore is a constant overhead. - ValXdrConv = 7, // Cost of serializing an xdr object to bytes - ValSer = 8, + ValSer = 7, // Cost of deserializing an xdr object from bytes - ValDeser = 9, + ValDeser = 8, // Cost of computing the sha256 hash from bytes - ComputeSha256Hash = 10, + ComputeSha256Hash = 9, // Cost of computing the ed25519 pubkey from bytes - ComputeEd25519PubKey = 11, + ComputeEd25519PubKey = 10, // Cost of accessing an entry in a Map. - MapEntry = 12, + MapEntry = 11, // Cost of accessing an entry in a Vec - VecEntry = 13, - // Cost of guarding a frame, which involves pushing and poping a frame and capturing a rollback point. - GuardFrame = 14, + VecEntry = 12, // Cost of verifying ed25519 signature of a payload. - VerifyEd25519Sig = 15, + VerifyEd25519Sig = 13, // Cost of reading a slice of vm linear memory - VmMemRead = 16, + VmMemRead = 14, // Cost of writing to a slice of vm linear memory - VmMemWrite = 17, + VmMemWrite = 15, // Cost of instantiation a VM from wasm bytes code. - VmInstantiation = 18, + VmInstantiation = 16, // Cost of instantiation a VM from a cached state. - VmCachedInstantiation = 19, - // Roundtrip cost of invoking a VM function from the host. - InvokeVmFunction = 20, - // Cost of charging a value to the budgeting system. - ChargeBudget = 21, + VmCachedInstantiation = 17, + // Cost of invoking a function on the VM. If the function is a host function, + // additional cost will be covered by `DispatchHostFunction`. + InvokeVmFunction = 18, // Cost of computing a keccak256 hash from bytes. - ComputeKeccak256Hash = 22, + ComputeKeccak256Hash = 19, // Cost of computing an ECDSA secp256k1 pubkey from bytes. - ComputeEcdsaSecp256k1Key = 23, + ComputeEcdsaSecp256k1Key = 20, // Cost of computing an ECDSA secp256k1 signature from bytes. - ComputeEcdsaSecp256k1Sig = 24, + ComputeEcdsaSecp256k1Sig = 21, // Cost of recovering an ECDSA secp256k1 key from a signature. - RecoverEcdsaSecp256k1Key = 25, + RecoverEcdsaSecp256k1Key = 22, // Cost of int256 addition (`+`) and subtraction (`-`) operations - Int256AddSub = 26, + Int256AddSub = 23, // Cost of int256 multiplication (`*`) operation - Int256Mul = 27, + Int256Mul = 24, // Cost of int256 division (`/`) operation - Int256Div = 28, + Int256Div = 25, // Cost of int256 power (`exp`) operation - Int256Pow = 29, + Int256Pow = 26, // Cost of int256 shift (`shl`, `shr`) operation - Int256Shift = 30 + Int256Shift = 27 }; struct ContractCostParamEntry { @@ -167,7 +164,6 @@ struct StateExpirationSettings { uint32 maxEntryExpiration; uint32 minTempEntryExpiration; uint32 minPersistentEntryExpiration; - uint32 autoBumpLedgers; // rent_fee = wfee_rate_average / rent_rate_denominator_for_type int64 persistentRentRateDenominator; @@ -181,6 +177,15 @@ struct StateExpirationSettings { // Maximum number of bytes that we scan for eviction per ledger uint64 evictionScanSize; + + // Lowest BucketList level to be scanned to evict entries + uint32 startingEvictionScanLevel; +}; + +struct EvictionIterator { + uint32 bucketListLevel; + bool isCurrBucket; + uint64 bucketFileOffset; }; // limits the ContractCostParams size to 20kB @@ -195,7 +200,7 @@ enum ConfigSettingID CONFIG_SETTING_CONTRACT_COMPUTE_V0 = 1, CONFIG_SETTING_CONTRACT_LEDGER_COST_V0 = 2, CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0 = 3, - CONFIG_SETTING_CONTRACT_META_DATA_V0 = 4, + CONFIG_SETTING_CONTRACT_EVENTS_V0 = 4, CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 = 5, CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS = 6, CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES = 7, @@ -203,7 +208,8 @@ enum ConfigSettingID CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES = 9, CONFIG_SETTING_STATE_EXPIRATION = 10, CONFIG_SETTING_CONTRACT_EXECUTION_LANES = 11, - CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW = 12 + CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW = 12, + CONFIG_SETTING_EVICTION_ITERATOR = 13 }; union ConfigSettingEntry switch (ConfigSettingID configSettingID) @@ -216,8 +222,8 @@ case CONFIG_SETTING_CONTRACT_LEDGER_COST_V0: ConfigSettingContractLedgerCostV0 contractLedgerCost; case CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0: ConfigSettingContractHistoricalDataV0 contractHistoricalData; -case CONFIG_SETTING_CONTRACT_META_DATA_V0: - ConfigSettingContractMetaDataV0 contractMetaData; +case CONFIG_SETTING_CONTRACT_EVENTS_V0: + ConfigSettingContractEventsV0 contractEvents; case CONFIG_SETTING_CONTRACT_BANDWIDTH_V0: ConfigSettingContractBandwidthV0 contractBandwidth; case CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS: @@ -234,5 +240,7 @@ case CONFIG_SETTING_CONTRACT_EXECUTION_LANES: ConfigSettingContractExecutionLanesV0 contractExecutionLanes; case CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW: uint64 bucketListSizeWindow<>; +case CONFIG_SETTING_EVICTION_ITERATOR: + EvictionIterator evictionIterator; }; } diff --git a/xdr/Stellar-contract-spec.x b/xdr/Stellar-contract-spec.x index a3145896..6988a633 100644 --- a/xdr/Stellar-contract-spec.x +++ b/xdr/Stellar-contract-spec.x @@ -39,7 +39,6 @@ enum SCSpecType SC_SPEC_TYPE_OPTION = 1000, SC_SPEC_TYPE_RESULT = 1001, SC_SPEC_TYPE_VEC = 1002, - SC_SPEC_TYPE_SET = 1003, SC_SPEC_TYPE_MAP = 1004, SC_SPEC_TYPE_TUPLE = 1005, SC_SPEC_TYPE_BYTES_N = 1006, @@ -70,11 +69,6 @@ struct SCSpecTypeMap SCSpecTypeDef valueType; }; -struct SCSpecTypeSet -{ - SCSpecTypeDef elementType; -}; - struct SCSpecTypeTuple { SCSpecTypeDef valueTypes<12>; @@ -119,8 +113,6 @@ case SC_SPEC_TYPE_VEC: SCSpecTypeVec vec; case SC_SPEC_TYPE_MAP: SCSpecTypeMap map; -case SC_SPEC_TYPE_SET: - SCSpecTypeSet set; case SC_SPEC_TYPE_TUPLE: SCSpecTypeTuple tuple; case SC_SPEC_TYPE_BYTES_N: diff --git a/xdr/Stellar-contract.x b/xdr/Stellar-contract.x index 9867ce3c..7c7469c7 100644 --- a/xdr/Stellar-contract.x +++ b/xdr/Stellar-contract.x @@ -38,8 +38,7 @@ enum SCValType // 128 bits is naturally supported by Rust and we use it for Soroban // fixed-point arithmetic prices / balances / similar "quantities". These - // are represented in XDR as a pair of 2 u64s, unlike {u,i}256 which is - // represented as an array of 32 bytes. + // are represented in XDR as a pair of 2 u64s. SCV_U128 = 9, SCV_I128 = 10, @@ -76,35 +75,58 @@ enum SCValType enum SCErrorType { - SCE_CONTRACT = 0, - SCE_WASM_VM = 1, - SCE_CONTEXT = 2, - SCE_STORAGE = 3, - SCE_OBJECT = 4, - SCE_CRYPTO = 5, - SCE_EVENTS = 6, - SCE_BUDGET = 7, - SCE_VALUE = 8, - SCE_AUTH = 9 + SCE_CONTRACT = 0, // Contract-specific, user-defined codes. + SCE_WASM_VM = 1, // Errors while interpreting WASM bytecode. + SCE_CONTEXT = 2, // Errors in the contract's host context. + SCE_STORAGE = 3, // Errors accessing host storage. + SCE_OBJECT = 4, // Errors working with host objects. + SCE_CRYPTO = 5, // Errors in cryptographic operations. + SCE_EVENTS = 6, // Errors while emitting events. + SCE_BUDGET = 7, // Errors relating to budget limits. + SCE_VALUE = 8, // Errors working with host values or SCVals. + SCE_AUTH = 9 // Errors from the authentication subsystem. }; enum SCErrorCode { - SCEC_ARITH_DOMAIN = 0, // some arithmetic wasn't defined (overflow, divide-by-zero) - SCEC_INDEX_BOUNDS = 1, // something was indexed beyond its bounds - SCEC_INVALID_INPUT = 2, // user provided some otherwise-bad data - SCEC_MISSING_VALUE = 3, // some value was required but not provided - SCEC_EXISTING_VALUE = 4, // some value was provided where not allowed - SCEC_EXCEEDED_LIMIT = 5, // some arbitrary limit -- gas or otherwise -- was hit - SCEC_INVALID_ACTION = 6, // data was valid but action requested was not - SCEC_INTERNAL_ERROR = 7, // the internal state of the host was otherwise-bad - SCEC_UNEXPECTED_TYPE = 8, // some type wasn't as expected - SCEC_UNEXPECTED_SIZE = 9 // something's size wasn't as expected + SCEC_ARITH_DOMAIN = 0, // Some arithmetic was undefined (overflow, divide-by-zero). + SCEC_INDEX_BOUNDS = 1, // Something was indexed beyond its bounds. + SCEC_INVALID_INPUT = 2, // User provided some otherwise-bad data. + SCEC_MISSING_VALUE = 3, // Some value was required but not provided. + SCEC_EXISTING_VALUE = 4, // Some value was provided where not allowed. + SCEC_EXCEEDED_LIMIT = 5, // Some arbitrary limit -- gas or otherwise -- was hit. + SCEC_INVALID_ACTION = 6, // Data was valid but action requested was not. + SCEC_INTERNAL_ERROR = 7, // The host detected an error in its own logic. + SCEC_UNEXPECTED_TYPE = 8, // Some type wasn't as expected. + SCEC_UNEXPECTED_SIZE = 9 // Something's size wasn't as expected. }; -struct SCError +// Smart contract errors are split into a type (SCErrorType) and a code. When an +// error is of type SCE_CONTRACT it carries a user-defined uint32 code that +// Soroban assigns no specific meaning to. In all other cases, the type +// specifies a subsystem of the Soroban host where the error originated, and the +// accompanying code is an SCErrorCode, each of which specifies a slightly more +// precise class of errors within that subsystem. +// +// Error types and codes are not maximally precise; there is a tradeoff between +// precision and flexibility in the implementation, and the granularity here is +// chosen to be adequate for most purposes while not placing a burden on future +// system evolution and maintenance. When additional precision is needed for +// debugging, Soroban can be run with diagnostic events enabled. + +union SCError switch (SCErrorType type) { - SCErrorType type; +case SCE_CONTRACT: + uint32 contractCode; +case SCE_WASM_VM: +case SCE_CONTEXT: +case SCE_STORAGE: +case SCE_OBJECT: +case SCE_CRYPTO: +case SCE_EVENTS: +case SCE_BUDGET: +case SCE_VALUE: +case SCE_AUTH: SCErrorCode code; }; diff --git a/xdr/Stellar-ledger-entries.x b/xdr/Stellar-ledger-entries.x index 5eaccacc..f0664840 100644 --- a/xdr/Stellar-ledger-entries.x +++ b/xdr/Stellar-ledger-entries.x @@ -100,7 +100,8 @@ enum LedgerEntryType LIQUIDITY_POOL = 5, CONTRACT_DATA = 6, CONTRACT_CODE = 7, - CONFIG_SETTING = 8 + CONFIG_SETTING = 8, + EXPIRATION = 9 }; struct Signer @@ -493,60 +494,33 @@ struct LiquidityPoolEntry body; }; -enum ContractEntryBodyType { - DATA_ENTRY = 0, - EXPIRATION_EXTENSION = 1 -}; - -const MASK_CONTRACT_DATA_FLAGS_V20 = 0x1; - -enum ContractDataFlags { - // When set, the given entry does not recieve automatic expiration bumps - // on access. Note that entries can still be bumped manually via the footprint. - NO_AUTOBUMP = 0x1 -}; - enum ContractDataDurability { TEMPORARY = 0, PERSISTENT = 1 }; struct ContractDataEntry { + ExtensionPoint ext; + SCAddress contract; SCVal key; ContractDataDurability durability; - - union switch (ContractEntryBodyType bodyType) - { - case DATA_ENTRY: - struct - { - uint32 flags; - SCVal val; - } data; - case EXPIRATION_EXTENSION: - void; - } body; - - uint32 expirationLedgerSeq; + SCVal val; }; struct ContractCodeEntry { ExtensionPoint ext; Hash hash; - union switch (ContractEntryBodyType bodyType) - { - case DATA_ENTRY: - opaque code<>; - case EXPIRATION_EXTENSION: - void; - } body; + opaque code<>; +}; +struct ExpirationEntry { + // Hash of the LedgerKey that is associated with this ExpirationEntry + Hash keyHash; uint32 expirationLedgerSeq; }; - struct LedgerEntryExtensionV1 { SponsorshipDescriptor sponsoringID; @@ -583,6 +557,8 @@ struct LedgerEntry ContractCodeEntry contractCode; case CONFIG_SETTING: ConfigSettingEntry configSetting; + case EXPIRATION: + ExpirationEntry expiration; } data; @@ -643,19 +619,23 @@ case CONTRACT_DATA: SCAddress contract; SCVal key; ContractDataDurability durability; - ContractEntryBodyType bodyType; } contractData; case CONTRACT_CODE: struct { Hash hash; - ContractEntryBodyType bodyType; } contractCode; case CONFIG_SETTING: struct { ConfigSettingID configSettingID; } configSetting; +case EXPIRATION: + struct + { + // Hash of the LedgerKey that is associated with this ExpirationEntry + Hash keyHash; + } expiration; }; // list of all envelope types used in the application diff --git a/xdr/Stellar-ledger.x b/xdr/Stellar-ledger.x index e42e738a..a1bbac4b 100644 --- a/xdr/Stellar-ledger.x +++ b/xdr/Stellar-ledger.x @@ -47,17 +47,13 @@ struct StellarValue ext; }; -const MASK_LEDGER_HEADER_FLAGS = 0x7F; +const MASK_LEDGER_HEADER_FLAGS = 0x7; enum LedgerHeaderFlags { DISABLE_LIQUIDITY_POOL_TRADING_FLAG = 0x1, DISABLE_LIQUIDITY_POOL_DEPOSIT_FLAG = 0x2, - DISABLE_LIQUIDITY_POOL_WITHDRAWAL_FLAG = 0x4, - DISABLE_CONTRACT_CREATE = 0x8, - DISABLE_CONTRACT_UPDATE = 0x10, - DISABLE_CONTRACT_REMOVE = 0x20, - DISABLE_CONTRACT_INVOKE = 0x40 + DISABLE_LIQUIDITY_POOL_WITHDRAWAL_FLAG = 0x4 }; struct LedgerHeaderExtensionV1 @@ -127,7 +123,8 @@ enum LedgerUpgradeType LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3, LEDGER_UPGRADE_BASE_RESERVE = 4, LEDGER_UPGRADE_FLAGS = 5, - LEDGER_UPGRADE_CONFIG = 6 + LEDGER_UPGRADE_CONFIG = 6, + LEDGER_UPGRADE_MAX_SOROBAN_TX_SET_SIZE = 7 }; struct ConfigUpgradeSetKey { @@ -148,7 +145,12 @@ case LEDGER_UPGRADE_BASE_RESERVE: case LEDGER_UPGRADE_FLAGS: uint32 newFlags; // update flags case LEDGER_UPGRADE_CONFIG: + // Update arbitrary `ConfigSetting` entries identified by the key. ConfigUpgradeSetKey newConfig; +case LEDGER_UPGRADE_MAX_SOROBAN_TX_SET_SIZE: + // Update ConfigSettingContractExecutionLanesV0.ledgerMaxTxCount without + // using `LEDGER_UPGRADE_CONFIG`. + uint32 newMaxSorobanTxSetSize; }; struct ConfigUpgradeSet { @@ -385,7 +387,7 @@ struct ContractEvent case 0: struct { - SCVec topics; + SCVal topics<>; SCVal data; } v0; } diff --git a/xdr/Stellar-transaction.x b/xdr/Stellar-transaction.x index afd0a08c..366f3b03 100644 --- a/xdr/Stellar-transaction.x +++ b/xdr/Stellar-transaction.x @@ -503,10 +503,16 @@ struct CreateContractArgs ContractExecutable executable; }; +struct InvokeContractArgs { + SCAddress contractAddress; + SCSymbol functionName; + SCVal args<>; +}; + union HostFunction switch (HostFunctionType type) { case HOST_FUNCTION_TYPE_INVOKE_CONTRACT: - SCVec invokeContract; + InvokeContractArgs invokeContract; case HOST_FUNCTION_TYPE_CREATE_CONTRACT: CreateContractArgs createContract; case HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM: @@ -519,17 +525,10 @@ enum SorobanAuthorizedFunctionType SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN = 1 }; -struct SorobanAuthorizedContractFunction -{ - SCAddress contractAddress; - SCSymbol functionName; - SCVec args; -}; - union SorobanAuthorizedFunction switch (SorobanAuthorizedFunctionType type) { case SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN: - SorobanAuthorizedContractFunction contractFn; + InvokeContractArgs contractFn; case SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN: CreateContractArgs createContractHostFn; }; @@ -545,7 +544,7 @@ struct SorobanAddressCredentials SCAddress address; int64 nonce; uint32 signatureExpirationLedger; - SCVec signatureArgs; + SCVal signature; }; enum SorobanCredentialsType @@ -815,10 +814,6 @@ struct SorobanResources uint32 readBytes; // The maximum number of bytes this transaction can write to ledger uint32 writeBytes; - - // Maximum size of dynamic metadata produced by this contract ( - // currently only includes the events). - uint32 extendedMetaDataSizeBytes; }; // The transaction extension for Soroban. @@ -1793,7 +1788,9 @@ enum InvokeHostFunctionResultCode // codes considered as "failure" for the operation INVOKE_HOST_FUNCTION_MALFORMED = -1, INVOKE_HOST_FUNCTION_TRAPPED = -2, - INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED = -3 + INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED = -3, + INVOKE_HOST_FUNCTION_ENTRY_EXPIRED = -4, + INVOKE_HOST_FUNCTION_INSUFFICIENT_REFUNDABLE_FEE = -5 }; union InvokeHostFunctionResult switch (InvokeHostFunctionResultCode code) @@ -1803,6 +1800,8 @@ case INVOKE_HOST_FUNCTION_SUCCESS: case INVOKE_HOST_FUNCTION_MALFORMED: case INVOKE_HOST_FUNCTION_TRAPPED: case INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: +case INVOKE_HOST_FUNCTION_ENTRY_EXPIRED: +case INVOKE_HOST_FUNCTION_INSUFFICIENT_REFUNDABLE_FEE: void; }; @@ -1813,7 +1812,8 @@ enum BumpFootprintExpirationResultCode // codes considered as "failure" for the operation BUMP_FOOTPRINT_EXPIRATION_MALFORMED = -1, - BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED = -2 + BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED = -2, + BUMP_FOOTPRINT_EXPIRATION_INSUFFICIENT_REFUNDABLE_FEE = -3 }; union BumpFootprintExpirationResult switch (BumpFootprintExpirationResultCode code) @@ -1822,6 +1822,7 @@ case BUMP_FOOTPRINT_EXPIRATION_SUCCESS: void; case BUMP_FOOTPRINT_EXPIRATION_MALFORMED: case BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED: +case BUMP_FOOTPRINT_EXPIRATION_INSUFFICIENT_REFUNDABLE_FEE: void; }; @@ -1832,7 +1833,8 @@ enum RestoreFootprintResultCode // codes considered as "failure" for the operation RESTORE_FOOTPRINT_MALFORMED = -1, - RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED = -2 + RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED = -2, + RESTORE_FOOTPRINT_INSUFFICIENT_REFUNDABLE_FEE = -3 }; union RestoreFootprintResult switch (RestoreFootprintResultCode code) @@ -1841,6 +1843,7 @@ case RESTORE_FOOTPRINT_SUCCESS: void; case RESTORE_FOOTPRINT_MALFORMED: case RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED: +case RESTORE_FOOTPRINT_INSUFFICIENT_REFUNDABLE_FEE: void; }; @@ -1946,14 +1949,12 @@ enum TransactionResultCode txBAD_AUTH_EXTRA = -10, // unused signatures attached to transaction txINTERNAL_ERROR = -11, // an unknown error occurred - txNOT_SUPPORTED = -12, // transaction type not supported - txFEE_BUMP_INNER_FAILED = -13, // fee bump inner transaction failed - txBAD_SPONSORSHIP = -14, // sponsorship not confirmed - txBAD_MIN_SEQ_AGE_OR_GAP = - -15, // minSeqAge or minSeqLedgerGap conditions not met - txMALFORMED = -16, // precondition is invalid - // declared Soroban resource usage exceeds the network limit - txSOROBAN_RESOURCE_LIMIT_EXCEEDED = -17 + txNOT_SUPPORTED = -12, // transaction type not supported + txFEE_BUMP_INNER_FAILED = -13, // fee bump inner transaction failed + txBAD_SPONSORSHIP = -14, // sponsorship not confirmed + txBAD_MIN_SEQ_AGE_OR_GAP = -15, // minSeqAge or minSeqLedgerGap conditions not met + txMALFORMED = -16, // precondition is invalid + txSOROBAN_INVALID = -17 // soroban-specific preconditions were not met }; // InnerTransactionResult must be binary compatible with TransactionResult @@ -1984,7 +1985,7 @@ struct InnerTransactionResult case txBAD_SPONSORSHIP: case txBAD_MIN_SEQ_AGE_OR_GAP: case txMALFORMED: - case txSOROBAN_RESOURCE_LIMIT_EXCEEDED: + case txSOROBAN_INVALID: void; } result; @@ -2031,7 +2032,7 @@ struct TransactionResult case txBAD_SPONSORSHIP: case txBAD_MIN_SEQ_AGE_OR_GAP: case txMALFORMED: - case txSOROBAN_RESOURCE_LIMIT_EXCEEDED: + case txSOROBAN_INVALID: void; } result;