Open jjcnn opened 5 years ago
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.
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.
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.