gusto b1e13f79c5
Initial DA API Spec structure (#72)
* Initial da_api spec structure

* Node definition for testing different actors in da api

* Connect zone, producer and da nodes in tests

* Remove da mock module

* Add da api module with flow tests

* Comments for read and write methods in BlobStore

* Fix nitpicks (formatting and typing)

---------

Co-authored-by: Daniel Sanchez Quiros <sanchez.quiros.daniel@gmail.com>
2024-03-15 12:37:56 +02:00

51 lines
1.6 KiB
Python

from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Optional, List, Sequence
from da.common import Certificate
from da.verifier import DABlob
@dataclass
class Metadata:
# index of VID certificate blob
index: int
# app identifier
app_id: bytes
class BlobStore(ABC):
@abstractmethod
def add(self, certificate: Certificate, metadata: Metadata):
"""
Raises: ValueError if there is already a registered certificate fot the given metadata
"""
pass
@abstractmethod
def get_multiple(self, app_id: bytes, indexes: Sequence[int]) -> List[Optional[DABlob]]:
pass
class DAApi:
def __init__(self, bs: BlobStore):
self.store = bs
def write(self, certificate: Certificate, metadata: Metadata):
"""
Write method should be used by a service that is able to retrieve verified certificates
from the latest Block. Once a certificate is retrieved, api creates a relation between
the blob of an original data, certificate and index for the app_id of the certificate.
Raises: ValueError if there is already a registered certificate for a given metadata
"""
self.store.add(certificate, metadata)
def read(self, app_id, indexes) -> List[Optional[DABlob]]:
"""
Read method should accept only `app_id` and a list of indexes. The returned list of
blobs should be ordered in the same sequence as `indexes` in a request.
If node does not have the blob for some indexes, then it should add None object as an
item.
"""
return self.store.get_multiple(app_id, indexes)