Skip to content

TxResult and BridgeResult for deposit/withdraw feedback#35

Merged
8ball030 merged 15 commits intomainfrom
feat/TxResult
May 4, 2025
Merged

TxResult and BridgeResult for deposit/withdraw feedback#35
8ball030 merged 15 commits intomainfrom
feat/TxResult

Conversation

@Karrenbelt
Copy link
Copy Markdown
Collaborator

This PR introduces TxResult and BridgeResult to provide structured feedback for deposit and withdrawal operations to the caller

  • TxResult encapsulates transaction status and relevant transaction data.
  • BridgeResult wraps the TxResult and context (source and target chain, token, plus receiver and amount).

We could expose a method for clients to provide their BridgeResult to for a status update in case TxResult.status is TxStatus.PENDING. It contains all the necessary information for the Derive client to do so and removes the need for the caller (i.e. AssetBridgingInterface) to instantiate their own w3 instance and provide a correct RPC URL

Comment on lines +72 to +84
@dataclass
class TxResult:
tx_hash: str
tx_receipt: AttributeDict | None
exception: Exception | None

@property
def status(self) -> TxStatus:
if self.tx_receipt is not None:
return TxStatus(int(self.tx_receipt.status)) # ∈ {0, 1} (EIP-658)
if isinstance(self.exception, TimeoutError):
return TxStatus.PENDING
return TxStatus.ERROR
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the BridgeClient returns this from it's methods to deposit / withdraw with help of the send_and_confirm_tx function

Comment thread derive_client/data_types/models.py Outdated
Comment on lines +87 to +95
@dataclass
class BridgeResult:
source_chain: ChainID
target_chain: ChainID
source_token: Currency
target_token: Currency
amount: int
receiver: Address
tx_result: TxResult
Copy link
Copy Markdown
Collaborator Author

@Karrenbelt Karrenbelt May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BaseClient returns this from it's methods to deposit / withdraw. Keeping BridgeResult as a pure data container means we can cleanly add a method on BaseClient like check_bridge_result() to poll the latest tx status. This avoids forcing the caller to handle Web3 setup or determine RPC endpoints themselves.

Comment thread pyproject.toml Outdated
line-length = 120
skip-string-normalization = true
target-version = ['py37', 'py38', 'py39']
target-version = ['py310']
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't support 3.7 and 3.8. It looks like we support 3.9,

python = ">=3.9,<3.12"

but we are not compatible with 3.9 and we also don't run that in CI

python-version:
# - "3.9"
- "3.10"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to include all the versions of python we do support

@8ball030 8ball030 merged commit 4994243 into main May 4, 2025
1 check failed
@8ball030 8ball030 deleted the feat/TxResult branch May 4, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants