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

feat: add support for Soroban-RPC 21 #933

Merged
merged 2 commits into from
May 9, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Release History

### Pending
#### Update
- feat: add support for Soroban-RPC 21.
- improve: The function in `stellar_xdr.scval` can accept `sc_val` of `base64` and `bytes` types.

### Version 9.4.0
Expand Down
23 changes: 23 additions & 0 deletions stellar_sdk/soroban_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class EventInfo(BaseModel):
topic: List[str] = Field(alias="topic")
value: str = Field(alias="value")
in_successful_contract_call: bool = Field(alias="inSuccessfulContractCall")
transaction_hash: str = Field(alias="txHash")


class PaginationOptions(BaseModel):
Expand Down Expand Up @@ -142,6 +143,9 @@ class GetHealthResponse(BaseModel):
"""

status: str
latest_ledger: int = Field(alias="latestLedger")
oldest_ledger: int = Field(alias="oldestLedger")
ledger_retention_window: int = Field(alias="ledgerRetentionWindow")


# simulate_transaction
Expand Down Expand Up @@ -194,6 +198,21 @@ class RestorePreamble(BaseModel):
min_resource_fee: int = Field(alias="minResourceFee")


class LedgerEntryChange(BaseModel):
"""LedgerEntryChange designates a change in a ledger entry. Before and After cannot be omitted at the same time.
If Before is omitted, it constitutes a creation, if After is omitted, it constitutes a deletion.
"""

# LedgerEntryChangeType
type: str
# LedgerEntryKey in base64
key: str
# LedgerEntry XDR in base64
before: Optional[str] = None
# LedgerEntry XDR in base64
after: Optional[str] = None


class SimulateTransactionResponse(BaseModel):
"""Response for JSON-RPC method simulateTransaction.

Expand All @@ -215,6 +234,10 @@ class SimulateTransactionResponse(BaseModel):
restore_preamble: Optional[RestorePreamble] = Field(
alias="restorePreamble", default=None
)
# If present, it indicates how the state (ledger entries) will change as a result of the transaction execution.
state_changes: Optional[List[LedgerEntryChange]] = Field(
alias="stateChanges", default=None
)
# If present, it indicates that a prior RestoreFootprint is required
latest_ledger: int = Field(alias="latestLedger")

Expand Down
17 changes: 16 additions & 1 deletion tests/test_soroban_server_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ async def test_load_account_not_found_raise(self):
}

async def test_get_health(self):
result = {"status": "healthy"}
result = {
"status": "healthy",
"latestLedger": 50000,
"oldestLedger": 1,
"ledgerRetentionWindow": 10000,
}
data = {
"jsonrpc": "2.0",
"id": "198cb1a8-9104-4446-a269-88bf000c2721",
Expand Down Expand Up @@ -293,6 +298,7 @@ async def test_get_events(self):
],
"value": "AAAAAwAAAAE=",
"inSuccessfulContractCall": True,
"txHash": "db86e94aa98b7d38213c041ebbb727fbaabf0b7c435de594f36c2d51fc61926d",
},
{
"type": "contract",
Expand All @@ -307,6 +313,7 @@ async def test_get_events(self):
],
"value": "AAAAAwAAAAI=",
"inSuccessfulContractCall": True,
"txHash": "db86e94aa98b7d38213c041ebbb727fbaabf0b7c435de594f36c2d51fc61926d",
},
],
"latestLedger": "187",
Expand Down Expand Up @@ -400,6 +407,14 @@ async def test_simulate_transaction(self):
}
],
"cost": {"cpuInsns": "1240100", "memBytes": "161637"},
"stateChanges": [
{
"type": "created",
"key": "AAAAAAAAAABuaCbVXZ2DlXWarV6UxwbW3GNJgpn3ASChIFp5bxSIWg==",
"before": None,
"after": "AAAAZAAAAAAAAAAAbmgm1V2dg5V1mq1elMcG1txjSYKZ9wEgoSBaeW8UiFoAAAAAAAAAZAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
}
],
"latestLedger": "1479",
}
data = {
Expand Down
17 changes: 16 additions & 1 deletion tests/test_soroban_server_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ def test_load_account_not_found_raise(self):
}

def test_get_health(self):
result = {"status": "healthy"}
result = {
"status": "healthy",
"latestLedger": 50000,
"oldestLedger": 1,
"ledgerRetentionWindow": 10000,
}
data = {
"jsonrpc": "2.0",
"id": "198cb1a8-9104-4446-a269-88bf000c2721",
Expand Down Expand Up @@ -285,6 +290,7 @@ def test_get_events(self):
],
"value": "AAAAAwAAAAE=",
"inSuccessfulContractCall": True,
"txHash": "db86e94aa98b7d38213c041ebbb727fbaabf0b7c435de594f36c2d51fc61926d",
},
{
"type": "contract",
Expand All @@ -299,6 +305,7 @@ def test_get_events(self):
],
"value": "AAAAAwAAAAI=",
"inSuccessfulContractCall": True,
"txHash": "db86e94aa98b7d38213c041ebbb727fbaabf0b7c435de594f36c2d51fc61926d",
},
],
"latestLedger": "187",
Expand Down Expand Up @@ -390,6 +397,14 @@ def test_simulate_transaction(self):
}
],
"cost": {"cpuInsns": "1240100", "memBytes": "161637"},
"stateChanges": [
{
"type": "created",
"key": "AAAAAAAAAABuaCbVXZ2DlXWarV6UxwbW3GNJgpn3ASChIFp5bxSIWg==",
"before": None,
"after": "AAAAZAAAAAAAAAAAbmgm1V2dg5V1mq1elMcG1txjSYKZ9wEgoSBaeW8UiFoAAAAAAAAAZAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
}
],
"latestLedger": "1479",
}
data = {
Expand Down
Loading