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

Add transfers between contracts #2252

Merged
merged 4 commits into from
Sep 4, 2024
Merged

Add transfers between contracts #2252

merged 4 commits into from
Sep 4, 2024

Conversation

ureeves
Copy link
Member

@ureeves ureeves commented Sep 3, 2024

This PR adds transfers between contracts. It is achieved by adding a new function to the transfer contract - transfer_to_contract - that is callable by other contracts to signify their intent to transfer Dusk to another contract. Contracts receiving Dusk via this function will then be called using a function specified by the sender contract, and can choose to either accept or reject the transfer based on the data they receive.

The basic assumption with this feature is that contracts wishing to transfer Dusk to another contract will be aware of the function the contract uses to receive funds. It is possible to send extra data together with transfer using the data field of the TransferToContract structure, which will be passed to the receiving contract using a field of the same name in ReceiveFromContract. This allows for acceptance/rejection of the transfer based on arbitrary data, as opposed to just the sender and amount transferred.

HDauven
HDauven previously approved these changes Sep 3, 2024
Copy link
Member

@HDauven HDauven left a comment

Choose a reason for hiding this comment

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

LGTM

moCello
moCello previously approved these changes Sep 4, 2024
Copy link
Member

@moCello moCello left a comment

Choose a reason for hiding this comment

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

Nice! Just a tiny comment on a comment

contracts/transfer/src/state.rs Outdated Show resolved Hide resolved
@ureeves ureeves dismissed stale reviews from moCello and HDauven via 3d666e1 September 4, 2024 09:59
Eduardo Leegwater Simões added 4 commits September 4, 2024 16:04
The `TransferToContract` is sent by a sender contract to the transfer
contract, signifying the sender's intent to send Dusk to a receiver
contract. `ReceiveFromContract` is used by the transfer contract to
inform the receiver of the sender and the amount being sent.
The `transfer_to_contract` function can be called by a sender contract
to transfer Dusk to a receiver contract. Once called, a function
specified by the sender is called on the receiver contract to inform it
of the sender's ID and the amount of Dusk sent. The receiver can choose
to accept the transfer, by successfully concluding the execution of the
function called to inform it, or it can panic and effectively reject the
transfer.

The `TransferToContract` is used as an argument to the `transfer_to_contract`,
and is constructed by the contract calling it. `ReceiveFromContract` is the
ata the receiver contract *must* accept for a function to be able to
successfully receive funds from another contract. If a contract wished
to expose one or more of these functions, it is heavily recommended that
they panic if called by anyone else apart from the transfer contract.
@ureeves ureeves requested review from HDauven and moCello September 4, 2024 14:23
Copy link
Member

@moCello moCello left a comment

Choose a reason for hiding this comment

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

LGTM

@ureeves ureeves merged commit 92179d3 into master Sep 4, 2024
15 checks passed
@ureeves ureeves deleted the contract-transfers branch September 4, 2024 14:43
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.

3 participants