ENTITY Documentation Portal
Recipe 8

Export, verify and restore complete market/economic state

This recipe assumes your deployment already has compatible populated exchange and economic-participation SQLite databases. It demonstrates the recovery contract; it does not invent those schemas.

from pathlib import Path
import importlib.util

ROOT=Path.cwd()
def load_source(path,name):
    spec=importlib.util.spec_from_file_location(name,ROOT/path)
    mod=importlib.util.module_from_spec(spec); spec.loader.exec_module(mod); return mod

recovery_mod=load_source("src/34_Market_Recovery/market_recovery.py","entity_market_recovery")
MarketStateRecovery=recovery_mod.MarketStateRecovery

bundle=MarketStateRecovery.export(
    exchange_path=EXCHANGE_DB,
    economic_path=ECONOMIC_DB,
    identity=identity,
    core_bundles=[core_bundle],
)

check=MarketStateRecovery.verify(
    bundle,
    verify_manifest=identity.verify_manifest,
    verify_signature=VERIFY_SIGNATURE,
    verify_core_bundle=fabric.verify_bundle,
)
assert check["valid"] is True
print(check["exchange_state_sha256"])
print(check["economic_state_sha256"])

restore=MarketStateRecovery.restore(
    bundle,
    NEW_EMPTY_EXCHANGE_DB,
    NEW_EMPTY_ECONOMIC_DB,
    verify_manifest=identity.verify_manifest,
    verify_signature=VERIFY_SIGNATURE,
    verify_core_bundle=fabric.verify_bundle,
)
print(restore)

VERIFY_SIGNATURE should be the deployment's ENTITY signature-verification callback matching the identity implementation. The recovery implementation requires compatible empty destinations and complete required table sets.

Do not restore a partial bundle as a complete market. Missing required tables, semantic-hash mismatch, bad identity material or missing controller attestations must fail verification.