Пример #1
0
def _generate_smart_contract_indexes() -> None:
    delete_index(Indexes.smartcontract.value)  # Always generate smart contract indexes from scratch by dropping existing ones
    client = _get_redisearch_index_client(Indexes.smartcontract.value)
    client.create_index([redisearch.TagField("sc_name")])
    # Find what smart contracts exist in storage
    _log.info("Listing all smart contracts in storage")
    sc_object_paths = storage.list_objects("SMARTCONTRACT/")
    pattern = re.compile(r"SMARTCONTRACT\/.{36}\/metadata\.json$")
    for sc in sc_object_paths:
        if re.search(pattern, sc):
            sc_model = smart_contract_model.new_from_at_rest(storage.get_json_from_object(sc))
            _log.info(f"Adding index for smart contract {sc_model.id} ({sc_model.txn_type})")
            put_document(Indexes.smartcontract.value, sc_model.id, sc_model.export_as_search_index())
Пример #2
0
 def test_from_input(self):
     meta = {
         "version": "3",
         "env": {
             "a_variable": "a value"
         },
         "txn_type": "an txn_type",
         "id": "an id",
         "image": "docker/image:1.0.0",
         "status": "a status",
         "cmd": "none?",
         "execution_order": "serial",
     }
     fastjsonschema.validate(schema.smart_contract_create_schema_v1, meta)
     test = smart_contract_model.new_contract_from_user(meta)
     for key in meta.keys():
         if key != "id" and key != "status" and key != "version":
             self.assertEqual(test.__dict__[key], meta[key])
     meta["version"] = "1"
     test = smart_contract_model.new_from_at_rest(meta)
     del meta["version"]
     for key in meta.keys():
         self.assertEqual(test.__dict__[key], meta[key])
Пример #3
0
def get_contract_by_id(
        contract_id: str) -> smart_contract_model.SmartContractModel:
    """Searches for a contract by contract_id"""
    return smart_contract_model.new_from_at_rest(
        storage.get_json_from_object(f"{FOLDER}/{contract_id}/metadata.json"))
Пример #4
0
def get_contract_by_txn_type(
        txn_type: str) -> smart_contract_model.SmartContractModel:
    """Searches for a contract by txn_type"""
    return smart_contract_model.new_from_at_rest(
        storage.get_json_from_object(
            f"{FOLDER}/{get_contract_id_by_txn_type(txn_type)}/metadata.json"))