-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sigantures/Semantics bug fixes #59
Changes from 12 commits
e09323f
e433ba8
0157496
79c3e82
56d454a
420f57d
73351f4
b2b8620
5167328
ce7e70c
a8b2a70
8918163
4663a9c
076a7db
f4d9cc5
50d2999
8b17905
4ac8618
f2d0b97
07f8373
c6ca701
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,7 +206,6 @@ def _decode_transaction( | |
) | ||
raise e | ||
|
||
|
||
full_decoded_transaction.status = True | ||
|
||
return full_decoded_transaction |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2021 DAI Foundation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from abc import ABC | ||
from typing import Dict, Optional, Any, List | ||
|
||
|
||
class ISemanticsDatabase(ABC): | ||
"""Semantics Database. Represents raw interface required to be | ||
implemented by a database that provides persistent | ||
data about semantics""" | ||
|
||
def get_address_semantics(self, chain_id: str, address: str) -> Optional[Dict]: | ||
... | ||
|
||
def get_contract_semantics(self, code_hash: str) -> Optional[Dict]: | ||
... | ||
|
||
def get_signature_semantics(self, signature_hash: str) -> Optional[List[Dict]]: | ||
... | ||
|
||
def insert_contract(self, contract: dict, update_if_exist: bool = False) -> Any: | ||
... | ||
|
||
def insert_address(self, address: dict, update_if_exist: bool = False) -> Any: | ||
... | ||
|
||
def insert_signature(self, signature, update_if_exist: bool = False) -> Any: | ||
... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2021 DAI Foundation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from enum import Enum | ||
|
||
|
||
class MongoCollections(str, Enum): | ||
piotr-rudnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ADDRESSES = "addresses" | ||
CONTRACTS = "contracts" | ||
SIGNATURES = "signatures" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,54 +10,31 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from abc import ABC | ||
from typing import Dict, Optional, Any, List | ||
from typing import Dict, Optional | ||
|
||
import bson | ||
from pymongo.cursor import Cursor | ||
from pymongo.database import Database as MongoDatabase | ||
|
||
from .base import ISemanticsDatabase | ||
from .const import MongoCollections | ||
|
||
class ISemanticsDatabase(ABC): | ||
"""Semantics Database. Represents raw interface required to be | ||
implemented by a database that provides persistent | ||
data about semantics""" | ||
|
||
def get_address_semantics(self, chain_id: str, address: str) -> Optional[Dict]: | ||
... | ||
|
||
def get_contract_semantics(self, code_hash: str) -> Optional[Dict]: | ||
... | ||
|
||
def get_signature_semantics(self, signature_hash: str) -> Optional[List[Dict]]: | ||
... | ||
|
||
def insert_contract(self, contract: dict, update_if_exist: bool = False) -> Any: | ||
... | ||
|
||
def insert_address(self, address: dict, update_if_exist: bool = False) -> Any: | ||
... | ||
|
||
def insert_signature(self, signature, update_if_exist: bool = False) -> Any: | ||
... | ||
class MongoSemanticsDatabase(ISemanticsDatabase): | ||
_db: MongoDatabase | ||
|
||
def __init__(self, db: MongoDatabase): | ||
self._db = db | ||
|
||
class MongoCollections: | ||
ADDRESSES = "addresses" | ||
CONTRACTS = "contracts" | ||
SIGNATURES = "signatures" | ||
self._addresses = None | ||
self._contracts = None | ||
self._signatures = None | ||
|
||
self._init_collections() | ||
|
||
class MongoSemanticsDatabase(ISemanticsDatabase): | ||
def get_collection_count(self): | ||
def get_collection_count(self) -> int: | ||
return len(self._db.list_collection_names()) | ||
|
||
def __init__(self, db: MongoDatabase): | ||
self._db = db | ||
self._addresses = self._db["addresses"] | ||
self._contracts = self._db["contracts"] | ||
self._signatures = self._db["signatures"] | ||
|
||
def get_address_semantics(self, chain_id, address) -> Optional[Dict]: | ||
_id = f"{chain_id}-{address}" | ||
return self._addresses.find_one({"_id": _id}, {"_id": 0}) | ||
|
@@ -121,3 +98,18 @@ def insert_address(self, address, update_if_exist=False) -> Optional[bson.Object | |
|
||
inserted_address = self._addresses.insert_one(address_with_id) | ||
return inserted_address.inserted_id | ||
|
||
def _init_collections(self) -> None: | ||
if MongoCollections.ADDRESSES not in self._db.list_collection_names(): | ||
self._addresses = self._db[MongoCollections.ADDRESSES] | ||
|
||
if MongoCollections.CONTRACTS not in self._db.list_collection_names(): | ||
self._contracts = self._db[MongoCollections.CONTRACTS] | ||
|
||
if MongoCollections.SIGNATURES not in self._db.list_collection_names(): | ||
self._signatures = self._db[MongoCollections.SIGNATURES] | ||
self._signatures.create_index( | ||
[("signature_hash", "TEXT"), ("name", "TEXT")], | ||
background=True, | ||
unique=False, | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and unique shouldn't be True? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored. You are right, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better, but still if collections are not in db, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can only be a list or None, if it's none, there could be an information about this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed isinstance