The on-chain view provides a synchronous way for a contract to fetch the data from another contract. This, however, doesn’t benefit legacy contracts that is originated before Protocol Hangzhou.
Ideally one can re-originate the contract with an updated contract script. This, however, is hard for contracts holding large contract storage and can add more burden to DApp developers.
To provide a solution to read necessary information from a legacy contract and thus improve the UX of Tezos contract interaction, we propose to have a new mechanism for “patching ” an on-chain view onto an existing contract.
Adding a default view to all existing contracts. Just like calling a pre-declared on-chain view, by calling this default view, the caller contract would get the entire storage of the callee contract. The default view should be handled on-the-fly so don’t need to store a new view definition in the storage.
This solution might be quite challenging because the caller contract needs to know the storage type of the callee contract in advance. And such storage might contain a data type, such as bigmap and ticket, which is not returnable via view.
This is an extended version of the previous one. We still add a default view to all the existing contracts. Yet, this default view requires a lambda function of type
s -> v as its argument, where
s is the storage type of the callee contract; and,
v is a value that is either part of
s or can be computed from
s. In other words, this lambda function would define how to fetch a value from the callee storage. With the dynamic view, a contract can easily read information from another contract without requiring it to pre-define any views.
Another direction of solving this is to add a new manage operation to allow the contract owner to “inject” a new view declaration into an existing contract. Notice that, this should not allow modifying any existing views.
All solution has their pros/cons, please read proposal for more details. All kinds of feedback and inputs are welcomed. Please leave a comment on our proposal or on this thread.