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:
145
prime_sdk/__init__.py
Normal file
145
prime_sdk/__init__.py
Normal file
@@ -0,0 +1,145 @@
|
||||
"""Python SDK for interacting with Dragonchain (Prime) nodes.
|
||||
|
||||
Example — fire and forget (most use cases)::
|
||||
|
||||
from prime_sdk import DragonchainSDK, TransactionCreateRequest
|
||||
|
||||
client = DragonchainSDK(
|
||||
"your-public-id",
|
||||
"your-auth-key-id",
|
||||
"your-auth-key",
|
||||
"https://your-dragonchain-endpoint.com",
|
||||
)
|
||||
|
||||
resp = client.transaction.create(
|
||||
TransactionCreateRequest(
|
||||
txn_type="my-transaction-type",
|
||||
payload='{"message": "Hello Dragonchain"}',
|
||||
)
|
||||
)
|
||||
print("Transaction ID:", resp.transaction_id)
|
||||
# Done — no need to wait for a block.
|
||||
|
||||
Example — wait for block inclusion (interchain / Daria)::
|
||||
|
||||
import time
|
||||
|
||||
resp = client.transaction.create(
|
||||
TransactionCreateRequest(
|
||||
txn_type="my-transaction-type",
|
||||
payload='{"message": "Hello Dragonchain"}',
|
||||
)
|
||||
)
|
||||
|
||||
while True:
|
||||
txn = client.transaction.get(resp.transaction_id)
|
||||
if txn.header.block_id:
|
||||
print("Block ID:", txn.header.block_id)
|
||||
break
|
||||
time.sleep(2)
|
||||
"""
|
||||
|
||||
from .block import BlockClient
|
||||
from .client import CONTENT_TYPE_JSON, Client
|
||||
from .contract import ContractClient
|
||||
from .errors import DragonchainAPIError, DragonchainError
|
||||
from .models import (
|
||||
Block,
|
||||
BlockProof,
|
||||
GrpcConnectionInfo,
|
||||
ListResponse,
|
||||
ListTransactionsResponse,
|
||||
SmartContract,
|
||||
SmartContractCreateRequest,
|
||||
SmartContractExecutionInfo,
|
||||
SmartContractUpdateRequest,
|
||||
SuccessResponse,
|
||||
SystemStatus,
|
||||
Transaction,
|
||||
TransactionBulkRequest,
|
||||
TransactionBulkResponse,
|
||||
TransactionCreateRequest,
|
||||
TransactionCreateResponse,
|
||||
TransactionHeader,
|
||||
TransactionListResponse,
|
||||
TransactionProof,
|
||||
TransactionType,
|
||||
TransactionTypeCreateRequest,
|
||||
TransactionTypeCreateResponse,
|
||||
)
|
||||
from .system import SystemClient
|
||||
from .transaction import TransactionClient
|
||||
from .transaction_type import TransactionTypeClient
|
||||
|
||||
__version__ = "0.1.0"
|
||||
|
||||
|
||||
class DragonchainSDK:
|
||||
"""Main SDK client for interacting with Dragonchain nodes.
|
||||
|
||||
Provides access to all API endpoints through specialized client instances:
|
||||
``system``, ``transaction``, ``transaction_type``, ``contract``, ``block``.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
public_id: str,
|
||||
auth_key_id: str,
|
||||
auth_key: str,
|
||||
base_url: str,
|
||||
):
|
||||
"""Create a new Dragonchain SDK client.
|
||||
|
||||
Args:
|
||||
public_id: Your Dragonchain public ID.
|
||||
auth_key_id: Your authentication key ID.
|
||||
auth_key: Your authentication key.
|
||||
base_url: Base URL of your node (e.g. "https://chains.dragonchain.com").
|
||||
"""
|
||||
self._client = Client(public_id, auth_key_id, auth_key, base_url)
|
||||
self.transaction = TransactionClient(self._client)
|
||||
self.transaction_type = TransactionTypeClient(self._client)
|
||||
self.contract = ContractClient(self._client)
|
||||
self.block = BlockClient(self._client)
|
||||
self.system = SystemClient(self._client)
|
||||
|
||||
def get_client(self) -> Client:
|
||||
"""Return the underlying HTTP client (advanced use)."""
|
||||
return self._client
|
||||
|
||||
|
||||
__all__ = [
|
||||
"DragonchainSDK",
|
||||
"Client",
|
||||
"CONTENT_TYPE_JSON",
|
||||
"DragonchainError",
|
||||
"DragonchainAPIError",
|
||||
"BlockClient",
|
||||
"ContractClient",
|
||||
"SystemClient",
|
||||
"TransactionClient",
|
||||
"TransactionTypeClient",
|
||||
# models
|
||||
"Block",
|
||||
"BlockProof",
|
||||
"GrpcConnectionInfo",
|
||||
"ListResponse",
|
||||
"ListTransactionsResponse",
|
||||
"SmartContract",
|
||||
"SmartContractCreateRequest",
|
||||
"SmartContractExecutionInfo",
|
||||
"SmartContractUpdateRequest",
|
||||
"SuccessResponse",
|
||||
"SystemStatus",
|
||||
"Transaction",
|
||||
"TransactionBulkRequest",
|
||||
"TransactionBulkResponse",
|
||||
"TransactionCreateRequest",
|
||||
"TransactionCreateResponse",
|
||||
"TransactionHeader",
|
||||
"TransactionListResponse",
|
||||
"TransactionProof",
|
||||
"TransactionType",
|
||||
"TransactionTypeCreateRequest",
|
||||
"TransactionTypeCreateResponse",
|
||||
]
|
||||
Reference in New Issue
Block a user