Skip to content

Commit e71fb8c

Browse files
authored
feat(sp-tool): add full PDP offering updates and capabilities (#294)
* feat(sp-tool): add full PDP offering updates and capabilities - Support all PDP offering fields (location, price, piece sizes, IPNI, etc) - Add --capability key=value flag for arbitrary metadata - Fix SDK to fetch capability values from contract Builds on and Closes: #234
1 parent 5a35d43 commit e71fb8c

File tree

2 files changed

+462
-52
lines changed

2 files changed

+462
-52
lines changed

packages/synapse-sdk/src/sp-registry/service.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,18 @@ export class SPRegistryService {
433433
return null
434434
}
435435

436+
// Fetch capability values using the keys
437+
let capabilities: Record<string, string> = {}
438+
if (result.capabilityKeys && result.capabilityKeys.length > 0) {
439+
// Convert to plain array to avoid ethers.js frozen array issues
440+
const keys = Array.from(result.capabilityKeys) as string[]
441+
const capResult = await contract.getProductCapabilities(providerId, 0, keys) // 0 = ProductType.PDP
442+
// getProductCapabilities returns tuple: (bool[] exists, string[] values)
443+
// Access as capResult[1] for values array
444+
const values = Array.from(capResult[1] || []) as string[]
445+
capabilities = this._convertCapabilitiesToObject(keys, values)
446+
}
447+
436448
return {
437449
offering: {
438450
serviceURL: result.pdpOffering.serviceURL,
@@ -445,7 +457,7 @@ export class SPRegistryService {
445457
location: result.pdpOffering.location,
446458
paymentTokenAddress: result.pdpOffering.paymentTokenAddress,
447459
},
448-
capabilities: this._convertCapabilitiesToObject(result.capabilityKeys, result.capabilityValues || []),
460+
capabilities,
449461
isActive: result.isActive,
450462
}
451463
} catch {
@@ -569,6 +581,8 @@ export class SPRegistryService {
569581

570582
/**
571583
* Extract products from multicall PDP service result
584+
* Note: For multicall batching, capability values are set to empty strings for performance.
585+
* Use getProvider() or getPDPService() for full capability values.
572586
*/
573587
private _extractProductsFromMulticallResult(pdpServiceResult: any, iface: ethers.Interface): ServiceProduct[] {
574588
const products: ServiceProduct[] = []
@@ -588,7 +602,9 @@ export class SPRegistryService {
588602
return products
589603
}
590604

591-
// Build capabilities object
605+
// Note: Capability values are not included in multicall for performance
606+
// They would require additional contract calls per provider
607+
// Use getProvider() or getPDPService() for full capability values
592608
const capabilities = this._buildCapabilitiesFromKeys(capabilityKeys)
593609

594610
// Build PDP product
@@ -616,15 +632,16 @@ export class SPRegistryService {
616632
}
617633

618634
/**
619-
* Build capabilities object from keys array
635+
* Build capabilities object from keys array (values set to empty for multicall performance)
636+
* For full capability values, use getProvider() or getPDPService()
620637
*/
621638
private _buildCapabilitiesFromKeys(capabilityKeys: any): Record<string, string> {
622639
const capabilities: Record<string, string> = {}
623640

624641
if (capabilityKeys && Array.isArray(capabilityKeys)) {
625642
for (const key of capabilityKeys) {
626-
// For getPDPService, capabilities are returned as keys only
627-
// Values would need to be fetched separately if needed
643+
// For multicall batching, we only get keys to avoid N additional contract calls
644+
// Values would need separate getProductCapabilities() calls per provider
628645
capabilities[key] = ''
629646
}
630647
}

0 commit comments

Comments
 (0)