Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocol 22 Soroban RPC changes #984

Merged
merged 6 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Release History
#### Update
- feat!: support constructors in contract creation via `TransactionBuilder.append_create_contract_op`, the signature of the function has been changed.
- refactor!: Updated `signer` parameter in auth to accept a callable returning (public_key, signatures) instead of just public_key.
- feat: add support for Soroban PRC's `getVersionInfo` API interfaces.
- refactor!: The `paging_token` field has been removed from `EventInfo`, use the `cursor` in `GetEventsResponse` instead.
- refactor!: The legacy `cost` field has been removed from `SimulateTransactionResponse`, parse it from `transaction_data` instead.
- feat: Add `transaction_hash` to `GetTransactionResponse` and `GetTransactionsResponse`.

### Version 11.1.0

Expand Down
32 changes: 14 additions & 18 deletions stellar_sdk/soroban_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class EventInfo(BaseModel):
ledger_close_at: datetime = Field(alias="ledgerClosedAt")
contract_id: str = Field(alias="contractId")
id: str = Field(alias="id")
paging_token: str = Field(alias="pagingToken")
topic: List[str] = Field(alias="topic")
value: str = Field(alias="value")
in_successful_contract_call: bool = Field(alias="inSuccessfulContractCall")
Expand Down Expand Up @@ -93,6 +92,7 @@ class GetEventsResponse(BaseModel):

events: List[EventInfo] = Field(alias="events")
latest_ledger: int = Field(alias="latestLedger")
cursor: str


# get_ledger_entries
Expand Down Expand Up @@ -226,10 +226,6 @@ class SimulateTransactionResponse(BaseModel):
events: Optional[List[str]] = None
# DiagnosticEvent XDR in base64
results: Optional[List[SimulateHostFunctionResult]] = None
# 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
Expand Down Expand Up @@ -274,6 +270,7 @@ class GetTransactionResponse(BaseModel):
more information."""

status: GetTransactionStatus
transaction_hash: str = Field(alias="txHash")
latest_ledger: int = Field(alias="latestLedger")
latest_ledger_close_time: int = Field(alias="latestLedgerCloseTime")
oldest_ledger: int = Field(alias="oldestLedger")
Expand Down Expand Up @@ -387,6 +384,7 @@ class GetTransactionsRequest(BaseModel):

class Transaction(BaseModel):
status: str
transaction_hash: str = Field(alias="txHash")
application_order: int = Field(alias="applicationOrder")
fee_bump: bool = Field(alias="feeBump")
envelope_xdr: str = Field(alias="envelopeXdr")
Expand Down Expand Up @@ -414,16 +412,14 @@ class GetTransactionsResponse(BaseModel):


# get_version_info
# TODO: To avoid breaking change, let's add it later.
# See: https://github.com/stellar/soroban-rpc/pull/164
# class GetVersionInfoResponse(BaseModel):
# """Response for JSON-RPC method getVersionInfo.
#
# See `getVersionInfo documentation <https://developers.stellar.org/docs/data/rpc/api-reference/methods/getVersionInfo>`__ for
# more information."""
#
# version: str
# commit_hash: str = Field(alias="commitHash")
# build_time_stamp: str = Field(alias="buildTimeStamp")
# captive_core_version: str = Field(alias="captiveCoreVersion")
# protocol_version: int = Field(alias="protocolVersion")
class GetVersionInfoResponse(BaseModel):
"""Response for JSON-RPC method getVersionInfo.

See `getVersionInfo documentation <https://developers.stellar.org/docs/data/rpc/api-reference/methods/getVersionInfo>`__ for
more information."""

version: str
commit_hash: str = Field(alias="commitHash")
build_time_stamp: str = Field(alias="buildTimestamp")
captive_core_version: str = Field(alias="captiveCoreVersion")
protocol_version: int = Field(alias="protocolVersion")
17 changes: 16 additions & 1 deletion stellar_sdk/soroban_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_ledger_entries(
See `Soroban RPC Documentation - getLedgerEntries <https://developers.stellar.org/docs/data/rpc/api-reference/methods/getLedgerEntries>`_

:param keys: The ledger keys to fetch.
:return: A :class:`GetLedgerEntriesResponse <stellar_sdk.soroban_rpc.GetLedgerEntryResponse>` object.
:return: A :class:`GetLedgerEntriesResponse <stellar_sdk.soroban_rpc.GetLedgerEntriesResponse>` object.
:raises: :exc:`SorobanRpcErrorResponse <stellar_sdk.exceptions.SorobanRpcErrorResponse>` - If the Soroban-RPC instance returns an error response.
"""
request = Request[GetLedgerEntriesRequest](
Expand Down Expand Up @@ -327,6 +327,21 @@ def get_contract_data(
return None
return entries[0]

def get_version_info(self) -> GetVersionInfoResponse:
"""Version information about the RPC and Captive core.

See `Soroban RPC Documentation - getVersionInfo <https://developers.stellar.org/docs/data/rpc/api-reference/methods/getVersionInfo>`_

:return: A :class:`GetVersionInfoResponse <stellar_sdk.soroban_rpc.GetVersionInfoResponse>` object.
:raises: :exc:`SorobanRpcErrorResponse <stellar_sdk.exceptions.SorobanRpcErrorResponse>` - If the Soroban-RPC instance returns an error response.
"""
request: Request = Request(
id=_generate_unique_request_id(),
method="getVersionInfo",
params=None,
)
return self._post(request, GetVersionInfoResponse)

def prepare_transaction(
self,
transaction_envelope: TransactionEnvelope,
Expand Down
17 changes: 16 additions & 1 deletion stellar_sdk/soroban_server_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def get_ledger_entries(
See `Soroban RPC Documentation - getLedgerEntries <https://developers.stellar.org/docs/data/rpc/api-reference/methods/getLedgerEntries>`_

:param keys: The ledger keys to fetch.
:return: A :class:`GetLedgerEntriesResponse <stellar_sdk.soroban_rpc.GetLedgerEntryResponse>` object.
:return: A :class:`GetLedgerEntriesResponse <stellar_sdk.soroban_rpc.GetLedgerEntriesResponse>` object.
:raises: :exc:`SorobanRpcErrorResponse <stellar_sdk.exceptions.SorobanRpcErrorResponse>` - If the Soroban-RPC instance returns an error response.
"""
request = Request[GetLedgerEntriesRequest](
Expand Down Expand Up @@ -326,6 +326,21 @@ async def get_contract_data(
return None
return entries[0]

async def get_version_info(self) -> GetVersionInfoResponse:
"""Version information about the RPC and Captive core.

See `Soroban RPC Documentation - getVersionInfo <https://developers.stellar.org/docs/data/rpc/api-reference/methods/getVersionInfo>`_

:return: A :class:`GetVersionInfoResponse <stellar_sdk.soroban_rpc.GetVersionInfoResponse>` object.
:raises: :exc:`SorobanRpcErrorResponse <stellar_sdk.exceptions.SorobanRpcErrorResponse>` - If the Soroban-RPC instance returns an error response.
"""
request: Request = Request(
id=_generate_unique_request_id(),
method="getVersionInfo",
params=None,
)
return await self._post(request, GetVersionInfoResponse)

async def prepare_transaction(
self,
transaction_envelope: TransactionEnvelope,
Expand Down
Loading
Loading