-
Notifications
You must be signed in to change notification settings - Fork 58
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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
bdd0c07
to
3d666e1
Compare
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.
3d666e1
to
635107e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 theTransferToContract
structure, which will be passed to the receiving contract using a field of the same name inReceiveFromContract
. This allows for acceptance/rejection of the transfer based on arbitrary data, as opposed to just the sender and amount transferred.