Example #1
0
    def _internal_contract_delete(self, script_hash: types.UInt160, batch=None):
        if batch:
            db = batch
        else:
            db = self._real_db

        db.delete(DBPrefixes.CONTRACTS + script_hash.to_array())
Example #2
0
    def is_valid(self, contract_hash: types.UInt160) -> bool:
        """
        Validate if the group has agreed on allowing the specific contract_hash.

        Args:
            contract_hash:
        """
        return cryptography.verify_signature(contract_hash.to_array(),
                                             self.signature,
                                             self.public_key.encode_point(False))
Example #3
0
 def get_events(self,
                event_name: str,
                origin: UInt160 = None) -> List[Notification]:
     if origin is None:
         return [n for n in self._notifications if n.name == event_name]
     else:
         origin_bytes = origin.to_array() if isinstance(
             origin, UInt160) else bytes(origin)
         return [
             n for n in self._notifications
             if n.name == event_name and n.origin == origin_bytes
         ]
Example #4
0
    def _internal_storage_find(self, contract_script_hash: types.UInt160, key_prefix: bytes):
        prefix = DBPrefixes.STORAGES + contract_script_hash.to_array() + key_prefix

        res = {}
        with self._real_db.iterator(prefix=prefix, include_key=True, include_value=True) as it:
            for key, value in it:
                # strip off prefix
                k = storage.StorageKey.deserialize_from_bytes(key[1:])
                v = storage.StorageItem.deserialize_from_bytes(value)
                res[k] = v

        # yielding outside of iterator to make sure the LevelDB iterator is closed and not leaking resources
        for k, v in res.items():
            yield k, v
Example #5
0
    def _internal_contract_get(self, script_hash: types.UInt160):
        contract_bytes = self._real_db.get(DBPrefixes.CONTRACTS + script_hash.to_array())
        if contract_bytes is None:
            raise KeyError

        return storage.ContractState.deserialize_from_bytes(contract_bytes)