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

Pattern/anti-pattern guide #2

Open
jjcnn opened this issue Jul 30, 2019 · 2 comments
Open

Pattern/anti-pattern guide #2

jjcnn opened this issue Jul 30, 2019 · 2 comments

Comments

@jjcnn
Copy link

jjcnn commented Jul 30, 2019

We could use a guide to patterns/antipatterns in Scilla.

Examples:

  • Don't use ping-pong between contracts. Instead, attempt to complete everything in one contract before invoking transitions on the other contract. If the second contract for some reason discovers a problem, then throw an exception (or otherwise cause an execution error), so that the entire chain of invocations are rolled back.

  • Avoid using the size operation, as it requires reading the entire map from the state. Instead, manually maintain a size counter, and use a dedicated procedure to update the map and the counter together, so that they are always kept in sync.

@jjcnn
Copy link
Author

jjcnn commented Jul 30, 2019

Another example: Attempt to keep contracts reactive rather than active. If someone wants something from the contract, they should invoke an appropriate transition themselves. For instance, if the owners of a multi-signature wallet have approved the transfer of some money to a recipient, rather than transferring the money upon the last signature, one should let the recipient invoke the transition that executes the transfer.

@edison0xyz
Copy link
Contributor

Good point on the part that the recipient should invoke the transition that executes the transfer.

It helps to ensure that the recipient has access to the wallet address during the withdrawal process, and prevents the possibility of funds being sent to an address that no one has access to. Always favour pulls over push if possible.

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

No branches or pull requests

2 participants