Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions bindings/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,11 @@ func GetDistributionSummary(client *tnclient.Client, queryID int) (string, error
return "", errors.Wrap(err, "failed to get distribution summary")
}

// Safety: return empty string if no distribution found
if result == nil {
return "", nil
}

summary := map[string]any{
"distribution_id": result.DistributionID,
"total_fees_distributed": result.TotalFeesDistributed,
Expand Down Expand Up @@ -2429,9 +2434,9 @@ func DecodeMarketData(encoded []byte) (string, error) {
return "", err
}

// Re-map to local struct for JSON consistency if needed,
// or just return the contractsapi struct serialized.
// contractsapi.MarketData is already JSON-annotated.
// Re-map to local struct for JSON consistency if needed,
// or just return the contractsapi struct serialized.
// contractsapi.MarketData is already JSON-annotated.
jsonBytes, err := json.Marshal(market)
if err != nil {
return "", errors.Wrap(err, "failed to marshal market data")
Expand Down
6 changes: 3 additions & 3 deletions src/trufnetwork_sdk_py/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import trufnetwork_sdk_c_bindings.exports as truf_sdk
import trufnetwork_sdk_c_bindings.go as go

from typing import Any, TypedDict, Literal, cast, overload, Generic, TypeVar
from typing import Any, TypedDict, Literal, cast, overload, Generic, TypeVar, Optional

from pydantic import BaseModel

Expand Down Expand Up @@ -2624,12 +2624,12 @@ def sample_lp_rewards(self, query_id: int, block: int, wait: bool = True) -> str

return tx_hash

def get_distribution_summary(self, query_id: int) -> DistributionSummary:
def get_distribution_summary(self, query_id: int) -> Optional[DistributionSummary]:
"""Get fee distribution summary for a market."""
json_str = truf_sdk.GetDistributionSummary(self.client, query_id)

if not json_str:
raise RuntimeError(f"No distribution found for market {query_id}")
return None

return cast(DistributionSummary, json.loads(json_str))

Expand Down