Skip to content

Commit

Permalink
feat: add support for Soroban-RPC 21 (#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored May 9, 2024
1 parent 2c79f92 commit 55cabf4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
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

0 comments on commit 55cabf4

Please sign in to comment.