def make_update(key: MichelsonType, val: Optional[MichelsonType]) -> dict: update = { 'key': key.to_micheline_value(mode=mode), 'key_hash': forge_script_expr(key.pack(legacy=True)) } if val is not None: update['value'] = val.to_micheline_value(mode=mode) return update
def get(self, key: MichelsonType, dup=True) -> Optional[MichelsonType]: self.args[0].assert_type_equal(type(key)) val = next((v for k, v in self if k == key), Undefined) # search in diff if val is Undefined: assert self.context, f'context is not attached' key_hash = forge_script_expr(key.pack(legacy=True)) val_expr = self.context.get_big_map_value(self.ptr, key_hash) if val_expr is None: return None else: return self.args[1].from_micheline_value(val_expr) else: return val
def get_key_hash(self, key_obj): key = self.args[0].from_python_object(key_obj) return forge_script_expr(key.pack(legacy=True))
def test_get_key_hash(self, val_expr, type_expr, expected): ty = MichelsonType.match(type_expr) key = ty.from_micheline_value(val_expr).pack(legacy=True) self.assertEqual(expected, forge_script_expr(key))