Skip to content
Merged
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
62 changes: 62 additions & 0 deletions packages/wasm-sdk/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,14 @@ <h2>Results</h2>
inputs: [
{ name: "name", type: "text", label: "DPNS Name", required: true, placeholder: "Enter name (e.g., alice or alice.dash)" }
]
},
dpnsSearch: {
label: "DPNS Search Name",
description: "Search for DPNS names that start with a given prefix",
inputs: [
{ name: "prefix", type: "text", label: "Name Prefix", required: true, placeholder: "Enter prefix (e.g., ali)" },
{ name: "limit", type: "number", label: "Limit", required: false, placeholder: "Default: 10" }
]
}
}
},
Expand Down Expand Up @@ -3473,6 +3481,60 @@ <h2>Results</h2>
identityId: resolvedIdentityId,
message: resolvedIdentityId ? `Resolved to identity: ${resolvedIdentityId}` : `Name "${values.name}" not found`
};
} else if (queryType === 'dpnsSearch') {
// Handle DPNS name search with starts-with query
const limit = values.limit || 10;

// DPNS contract ID on testnet
const DPNS_CONTRACT_ID = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec";
const DPNS_DOCUMENT_TYPE = "domain";

// Build where clause for starts-with query on normalizedLabel
const whereClause = JSON.stringify([
["normalizedLabel", "startsWith", values.prefix.toLowerCase()],
["normalizedParentDomainName", "==", "dash"]
]);

// Order by normalizedLabel ascending
const orderBy = JSON.stringify([
["normalizedLabel", "asc"]
]);

// Execute the document query
const documents = await get_documents(
sdk,
DPNS_CONTRACT_ID,
DPNS_DOCUMENT_TYPE,
whereClause,
orderBy,
limit,
null, // startAfter
null // startAt
);

// Transform the results to show username and owner identity
const searchResults = documents.map(doc => {
// Access the data field which contains the DPNS document fields
const data = doc.data || doc;

return {
username: `${data.normalizedLabel || data.label || 'unknown'}.${data.normalizedParentDomainName || 'dash'}`,
label: data.label || '',
normalizedLabel: data.normalizedLabel || '',
ownerId: doc.ownerId || doc.$ownerId || '',
documentId: doc.id || doc.$id || ''
};
});

result = {
prefix: values.prefix,
totalResults: searchResults.length,
limit: limit,
results: searchResults,
message: searchResults.length > 0
? `Found ${searchResults.length} name(s) starting with "${values.prefix}"`
: `No names found starting with "${values.prefix}"`
};
}
// Protocol/Version queries
else if (queryType === 'getProtocolVersionUpgradeState') {
Expand Down
Loading