Skip to content

Commit

Permalink
New modules + allowance management (#18)
Browse files Browse the repository at this point in the history
- Added assertion/network modules
- Allowance management function
- Extended demo.py
  • Loading branch information
u-hubar authored Oct 3, 2023
2 parents 4965f07 + 46b6996 commit b128ae1
Show file tree
Hide file tree
Showing 12 changed files with 954 additions and 644 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ ___

### Prerequisites

* python `>=3.11`
* python `>=3.10`
* poetry `>=1.5.1`


Expand Down Expand Up @@ -256,6 +256,11 @@ This roadmap outlines the goals for the first major release of the `dkg.py`. Eac

| Feature | Status | Tests coverage |
|:-:|:-:|:-:|
| Get Allowance | 🟩 Completed ||
| Set Allowance | 🟩 Completed ||
| Increase Allowance | 🟩 Completed ||
| Decrease Allowance | 🟩 Completed ||
| Get Bid Suggestion | 🟩 Completed ||
| Create | 🟩 Completed ||
| Transfer | 🟩 Completed ||
| Update | 🟩 Completed ||
Expand Down
65 changes: 65 additions & 0 deletions dkg/assertion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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 typing import Literal

from dkg.manager import DefaultRequestManager
from dkg.module import Module
from dkg.types import JSONLD, HexStr
from dkg.utils.merkle import MerkleTree, hash_assertion_with_indexes
from dkg.utils.metadata import generate_assertion_metadata
from dkg.utils.rdf import format_content


class Assertion(Module):
def __init__(self, manager: DefaultRequestManager):
self.manager = manager

def format_graph(self, content: dict[Literal["public", "private"], JSONLD]):
return format_content(content)

def get_public_assertion_id(
self, content: dict[Literal["public", "private"], JSONLD]
) -> HexStr:
assertions = format_content(content)

return MerkleTree(
hash_assertion_with_indexes(assertions["public"]),
sort_pairs=True,
).root

def get_size(self, content: dict[Literal["public", "private"], JSONLD]) -> int:
assertions = format_content(content)
public_assertion_metadata = generate_assertion_metadata(assertions["public"])

return public_assertion_metadata["size"]

def get_triples_number(
self, content: dict[Literal["public", "private"], JSONLD]
) -> int:
assertions = format_content(content)
public_assertion_metadata = generate_assertion_metadata(assertions["public"])

return public_assertion_metadata["triples_number"]

def get_chunks_number(
self, content: dict[Literal["public", "private"], JSONLD]
) -> int:
assertions = format_content(content)
public_assertion_metadata = generate_assertion_metadata(assertions["public"])

return public_assertion_metadata["chunks_number"]
Loading

0 comments on commit b128ae1

Please sign in to comment.