Support payment hub transfer#3836
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Pull request overview
This PR adds payment hub transfer functionality to enable direct transfers between payment hubs without going through account coin stores. The implementation follows the existing patterns for hub operations (deposit/withdraw) and includes both typed and generic coin transfer functions.
Key Changes
- Adds
PaymentHubTransferEventstruct to track transfer operations between payment hubs - Implements
transfer_to_hub,transfer_to_hub_entry, andtransfer_to_hub_genericfunctions to enable hub-to-hub transfers - Adds test coverage for basic success and insufficient balance scenarios
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| frameworks/rooch-framework/sources/payment_channel.move | Implements payment hub transfer functionality with event emission and balance validation |
| frameworks/rooch-framework/sources/tests/payment_channel_test.move | Adds Test Group 8 with tests for successful transfer and insufficient balance error |
| frameworks/rooch-framework/doc/payment_channel.md | Updates documentation to reflect new transfer functions and events |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| public fun transfer_to_hub_generic( | ||
| sender: &signer, | ||
| receiver: address, | ||
| amount: u256, | ||
| coin_type: String, | ||
| ) { | ||
| let sender_addr = signer::address_of(sender); | ||
|
|
||
| // Check unlocked balance | ||
| let unlocked = get_unlocked_balance_in_hub_with_name_internal(sender_addr, coin_type); | ||
| assert!(amount <= unlocked, ErrorInsufficientUnlockedBalance); | ||
|
|
||
| // Withdraw from sender's hub | ||
| let sender_hub_obj = borrow_or_create_payment_hub(sender_addr); | ||
| let sender_hub = object::borrow_mut(sender_hub_obj); | ||
| let coin = multi_coin_store::withdraw(&mut sender_hub.multi_coin_store, coin_type, amount); | ||
| let sender_hub_id = object::id(sender_hub_obj); | ||
|
|
||
| // Deposit to receiver's hub | ||
| let receiver_hub_obj = borrow_or_create_payment_hub(receiver); | ||
| let receiver_hub = object::borrow_mut(receiver_hub_obj); | ||
| multi_coin_store::deposit(&mut receiver_hub.multi_coin_store, coin); | ||
| let receiver_hub_id = object::id(receiver_hub_obj); | ||
|
|
||
| // Emit transfer event | ||
| let event_handle_id = hub_event_handle_id<PaymentHubTransferEvent>(sender_hub_id); | ||
| event::emit_with_handle(event_handle_id, PaymentHubTransferEvent { | ||
| sender_hub_id, | ||
| sender: sender_addr, | ||
| receiver_hub_id, | ||
| receiver, | ||
| coin_type, | ||
| amount, | ||
| }); | ||
| } |
There was a problem hiding this comment.
The transfer_to_hub_generic function lacks the same input validation as transfer_to_hub:
- Zero amount validation: Should reject
amount == 0transfers. - Self-transfer validation: Should reject transfers where
sender_addr == receiver.
These validations should be consistent across both the generic and typed versions of the function to prevent wasteful operations.
Summary
Summary about this PR