2021-06-25 02:33:40 -07:00
|
|
|
|
# # ⚠ Warning
|
|
|
|
|
#
|
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
|
|
|
# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
|
# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
|
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
|
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
#
|
|
|
|
|
# [🥭 Mango Markets](https://mango.markets/) support is available at:
|
|
|
|
|
# [Docs](https://docs.mango.markets/)
|
|
|
|
|
# [Discord](https://discord.gg/67jySBhxrg)
|
|
|
|
|
# [Twitter](https://twitter.com/mangomarkets)
|
|
|
|
|
# [Github](https://github.com/blockworks-foundation)
|
|
|
|
|
# [Email](mailto:hello@blockworks.foundation)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import logging
|
2021-08-27 12:37:23 -07:00
|
|
|
|
import typing
|
2021-06-25 02:33:40 -07:00
|
|
|
|
|
|
|
|
|
from .version import Version
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 🥭 Metadata class
|
|
|
|
|
#
|
|
|
|
|
class Metadata():
|
2021-11-09 05:23:36 -08:00
|
|
|
|
def __init__(self, data_type: typing.Any, version: Version, is_initialized: bool) -> None:
|
2021-06-25 02:33:40 -07:00
|
|
|
|
self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)
|
2021-08-27 12:37:23 -07:00
|
|
|
|
self.data_type: typing.Any = data_type
|
2021-06-25 02:33:40 -07:00
|
|
|
|
self.version: Version = version
|
|
|
|
|
self.is_initialized: bool = is_initialized
|
|
|
|
|
|
2021-08-27 12:37:23 -07:00
|
|
|
|
def from_layout(layout: typing.Any) -> "Metadata":
|
2021-06-25 02:33:40 -07:00
|
|
|
|
version = Version(layout.version + 1)
|
|
|
|
|
is_initialized = bool(layout.is_initialized)
|
|
|
|
|
return Metadata(layout.data_type, version, is_initialized)
|
|
|
|
|
|
2021-08-01 10:03:46 -07:00
|
|
|
|
def __str__(self) -> str:
|
2021-06-25 02:33:40 -07:00
|
|
|
|
init = "Initialized" if self.is_initialized else "Not Initialized"
|
|
|
|
|
return f"« 𝙼𝚎𝚝𝚊𝚍𝚊𝚝𝚊 {self.version} - {self.data_type}: {init} »"
|
|
|
|
|
|
|
|
|
|
def __repr__(self) -> str:
|
|
|
|
|
return f"{self}"
|