-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcertificates_on_solana.py
More file actions
66 lines (57 loc) · 2.07 KB
/
certificates_on_solana.py
File metadata and controls
66 lines (57 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import logging
import httpx
from retry import retry
from pydantic import BaseModel
from config import config
logger = logging.getLogger(__name__)
class CertificatesOnSolanaException(Exception):
"""Custom exception for CertificatesOnSolana errors."""
def __init__(
self,
message: str = "Error registering certificate on Solana",
details: str = "",
cause: Exception = None,
):
super().__init__(message)
self.details = details
self.cause = cause
class CertificatesOnSolana:
"""
A class to manage certificates on the Solana blockchain Service."""
@staticmethod
@retry(
tries=3,
delay=3,
backoff=2,
exceptions=(httpx.RequestError, CertificatesOnSolanaException, Exception),
logger=logger,
)
def register_certificate_on_solana(certificate_data: dict) -> dict:
logger.info(
"Registering certificate on Solana blockchain with data: %s",
certificate_data,
)
"""
Registers a certificate on the Solana blockchain.
Args:
certificate_data (dict): A dictionary containing certificate details.
Returns:
dict: A dictionary with the registration result.
"""
try:
with httpx.Client(timeout=60.0) as client:
response = client.post(
url=config.SERVICE_URL_REGISTRATION_API_SOLANA,
headers={
"x-api-key": config.SERVICE_API_KEY_REGISTRATION_API_SOLANA,
"Content-Type": "application/json",
},
json=certificate_data,
)
logger.info(f"Solana response status code: {response.status_code}")
response.raise_for_status()
solana_response = response.json()
return solana_response
except Exception as e:
logger.error(f"Error registering certificate on Solana: {str(e)}")
raise CertificatesOnSolanaException(details=str(e), cause=e)