Initial commit: Python SDK for Dragonchain (Prime)
Synchronous Python SDK modeled on prime-sdk-go. Provides DC1-HMAC-SHA256 auth, dataclass models, and resource clients for system, transaction, transaction-type, smart-contract, and block endpoints, plus a YAML credentials loader.
This commit is contained in:
49
prime_sdk/contract.py
Normal file
49
prime_sdk/contract.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""Smart-contract endpoints."""
|
||||
|
||||
from .client import CONTENT_TYPE_JSON, Client
|
||||
from .models import (
|
||||
ListResponse,
|
||||
SmartContract,
|
||||
SmartContractCreateRequest,
|
||||
SmartContractUpdateRequest,
|
||||
SuccessResponse,
|
||||
)
|
||||
|
||||
|
||||
class ContractClient:
|
||||
def __init__(self, client: Client):
|
||||
self._client = client
|
||||
|
||||
def create(self, req: SmartContractCreateRequest) -> SmartContract:
|
||||
return self._client.post(
|
||||
"/api/v1/contract", CONTENT_TYPE_JSON, req, SmartContract
|
||||
)
|
||||
|
||||
def get(self, contract_id: str) -> SmartContract:
|
||||
return self._client.get(f"/api/v1/contract/{contract_id}", SmartContract)
|
||||
|
||||
def list(self) -> ListResponse:
|
||||
return self._client.get("/api/v1/contract", ListResponse)
|
||||
|
||||
def update(
|
||||
self, contract_id: str, req: SmartContractUpdateRequest
|
||||
) -> SuccessResponse:
|
||||
return self._client.put(
|
||||
f"/api/v1/contract/{contract_id}", CONTENT_TYPE_JSON, req, SuccessResponse
|
||||
)
|
||||
|
||||
def upload(self, contract_id: str, filepath: str) -> SuccessResponse:
|
||||
"""Upload smart-contract code from a local file (raw octet-stream body)."""
|
||||
with open(filepath, "rb") as f:
|
||||
file_content = f.read()
|
||||
return self._client.put(
|
||||
f"/api/v1/contract/{contract_id}/upload",
|
||||
"application/octet-stream",
|
||||
file_content,
|
||||
SuccessResponse,
|
||||
)
|
||||
|
||||
def delete(self, contract_id: str) -> SuccessResponse:
|
||||
return self._client.delete(
|
||||
f"/api/v1/contract/{contract_id}", SuccessResponse
|
||||
)
|
||||
Reference in New Issue
Block a user