Skip to content
Closed
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
21 changes: 20 additions & 1 deletion packages/scripts/build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,32 @@ cd "$PACKAGE_DIR"

echo "Building $PACKAGE_NAME..."

# Helper function to set build-time environment variables
set_build_env_vars() {
GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GIT_BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

export GIT_COMMIT
export GIT_BRANCH
export BUILD_TIME

echo "Build info: commit=$GIT_COMMIT, branch=$GIT_BRANCH, time=$BUILD_TIME"
}

# Create pkg directory if it doesn't exist
mkdir -p pkg

if [ "$USE_WASM_PACK" = true ]; then
# Build using wasm-pack
echo "Building with wasm-pack..."

# Set build-time environment variables
set_build_env_vars

# Disable LTO for wasm-pack builds to avoid conflicts
export CARGO_PROFILE_RELEASE_LTO=false
export RUSTFLAGS="-C lto=off"
export RUSTFLAGS="-C lto=off --cfg=env_vars_set"

Comment on lines +124 to 125
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Preserve existing RUSTFLAGS instead of clobbering it

export RUSTFLAGS="-C lto=off --cfg=env_vars_set" overwrites any flags a caller might have set (e.g. -C target-cpu=native). Safer to append:

-export RUSTFLAGS="-C lto=off --cfg=env_vars_set"
+export RUSTFLAGS="${RUSTFLAGS:-} -C lto=off --cfg=env_vars_set"

This keeps the new switches while respecting upstream configuration.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export RUSTFLAGS="-C lto=off --cfg=env_vars_set"
export RUSTFLAGS="${RUSTFLAGS:-} -C lto=off --cfg=env_vars_set"
🤖 Prompt for AI Agents
In packages/scripts/build-wasm.sh at lines 124 to 125, the current export of
RUSTFLAGS overwrites any existing flags set by the caller. To fix this, modify
the export statement to append the new flags to the existing RUSTFLAGS variable
instead of replacing it, ensuring that any previously set flags are preserved
while adding "-C lto=off --cfg=env_vars_set".

# Add features if specified
FEATURES_ARG=""
Expand All @@ -124,6 +140,9 @@ else
# Build using cargo directly
echo "Building with cargo..."

# Set build-time environment variables
set_build_env_vars

# Add features if specified
FEATURES_ARG=""
if [ -n "${CARGO_BUILD_FEATURES:-}" ]; then
Expand Down
20 changes: 19 additions & 1 deletion packages/wasm-sdk/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,12 @@

<body>
<div class="header">
<h1>Dash Platform WASM JS SDK</h1>
<div>
<h1>Dash Platform WASM JS SDK</h1>
<div id="versionInfo" style="font-size: 0.8em; color: #b0b0b0; margin-top: -5px;">
Loading version info...
</div>
</div>
<nav class="header-nav">
<a href="docs.html">Documentation</a>
<a href="AI_REFERENCE.md">AI Reference</a>
Expand Down Expand Up @@ -3279,6 +3284,19 @@ <h2>Results</h2>
console.log(`Initialized ${network} SDK (${modeStr} mode):`, sdk);
updateStatus(`WASM SDK successfully loaded on ${network.toUpperCase()} (${modeStr} mode)`, 'success');

// Display version information in header
try {
const gitCommit = sdk.gitCommit();
const gitBranch = sdk.gitBranch();

const versionText = `Built from branch: ${gitBranch} (${gitCommit})`;
document.getElementById('versionInfo').textContent = versionText;
document.getElementById('versionInfo').title = `Branch: ${gitBranch}\nCommit: ${gitCommit}`;
} catch (error) {
console.warn('Failed to get version info:', error);
document.getElementById('versionInfo').textContent = 'Version info unavailable';
}

Comment on lines +3287 to +3299
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Expose all available build metadata & improve formatting/fallbacks.

Only branch/commit are surfaced; packageVersion() and buildTime() exported in sdk.rs remain unused.
Additionally, very long commit hashes reduce readability and empty/placeholder values aren’t handled.

-const gitCommit = sdk.gitCommit();
-const gitBranch = sdk.gitBranch();
-
-const versionText = `Built from branch: ${gitBranch} (${gitCommit})`;
-document.getElementById('versionInfo').textContent = versionText;
-document.getElementById('versionInfo').title = `Branch: ${gitBranch}\nCommit: ${gitCommit}`;
+const gitCommit  = sdk.gitCommit?.()  ?? '';
+const gitBranch  = sdk.gitBranch?.()  ?? '';
+const pkgVer     = sdk.packageVersion?.() ?? '';
+const buildTime  = sdk.buildTime?.()  ?? '';
+
+// keep first 9 chars of hash for compactness
+const shortCommit = gitCommit.slice(0, 9);
+
+let header = [];
+if (pkgVer)        header.push(`v${pkgVer}`);
+if (shortCommit)   header.push(shortCommit + (gitBranch ? `@${gitBranch}` : ''));
+if (buildTime)     header.push(`• Built ${buildTime}`);
+
+const versionText = header.join(' ');
+
+const tooltip = `Package: ${pkgVer || 'unknown'}\nBranch: ${gitBranch || 'unknown'}\nCommit: ${gitCommit || 'unknown'}\nBuilt: ${buildTime || 'unknown'}`;
+
+const versionElem = document.getElementById('versionInfo');
+versionElem.textContent = versionText || 'Version info unavailable';
+versionElem.title       = tooltip;

Benefits:

  1. Surfaces all metadata the build script provides.
  2. Shortens the commit hash for UX while retaining full hash in tooltip.
  3. Gracefully degrades if any field is missing.
  4. Guards against optional chaining runtime errors on older builds.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Display version information in header
try {
const gitCommit = sdk.gitCommit();
const gitBranch = sdk.gitBranch();
const versionText = `Built from branch: ${gitBranch} (${gitCommit})`;
document.getElementById('versionInfo').textContent = versionText;
document.getElementById('versionInfo').title = `Branch: ${gitBranch}\nCommit: ${gitCommit}`;
} catch (error) {
console.warn('Failed to get version info:', error);
document.getElementById('versionInfo').textContent = 'Version info unavailable';
}
// Display version information in header
try {
const gitCommit = sdk.gitCommit?.() ?? '';
const gitBranch = sdk.gitBranch?.() ?? '';
const pkgVer = sdk.packageVersion?.() ?? '';
const buildTime = sdk.buildTime?.() ?? '';
// keep first 9 chars of hash for compactness
const shortCommit = gitCommit.slice(0, 9);
let header = [];
if (pkgVer) header.push(`v${pkgVer}`);
if (shortCommit) header.push(shortCommit + (gitBranch ? `@${gitBranch}` : ''));
if (buildTime) header.push(`• Built ${buildTime}`);
const versionText = header.join(' ');
const tooltip =
`Package: ${pkgVer || 'unknown'}\n` +
`Branch: ${gitBranch || 'unknown'}\n` +
`Commit: ${gitCommit || 'unknown'}\n` +
`Built: ${buildTime || 'unknown'}`;
const versionElem = document.getElementById('versionInfo');
versionElem.textContent = versionText || 'Version info unavailable';
versionElem.title = tooltip;
} catch (error) {
console.warn('Failed to get version info:', error);
document.getElementById('versionInfo').textContent = 'Version info unavailable';
}
🤖 Prompt for AI Agents
In packages/wasm-sdk/index.html around lines 2997 to 3009, enhance the version
info display by including packageVersion() and buildTime() from sdk.rs along
with gitBranch() and gitCommit(). Shorten the displayed commit hash for
readability but keep the full hash in the tooltip. Add checks to handle missing
or empty values gracefully to avoid runtime errors, and ensure all metadata
fields are shown with proper formatting and fallback text if unavailable.

// Proof support is available for all queries - internally all queries use proof verification
// When the proof toggle is ON (checked), queries return verified data WITH proof information displayed
// When the proof toggle is OFF (unchecked), queries return verified data WITHOUT proof information displayed
Expand Down
24 changes: 24 additions & 0 deletions packages/wasm-sdk/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ impl WasmSdk {
self.0.version().protocol_version
}

/// Get the package version of the SDK
#[wasm_bindgen(js_name = packageVersion)]
pub fn package_version(&self) -> String {
env!("CARGO_PKG_VERSION", "Package version not available").to_string()
}

/// Get the git commit hash this build was created from
#[wasm_bindgen(js_name = gitCommit)]
pub fn git_commit(&self) -> String {
option_env!("GIT_COMMIT").unwrap_or("unknown").to_string()
}

/// Get the git branch this build was created from
#[wasm_bindgen(js_name = gitBranch)]
pub fn git_branch(&self) -> String {
option_env!("GIT_BRANCH").unwrap_or("unknown").to_string()
}

/// Get the build timestamp
#[wasm_bindgen(js_name = buildTime)]
pub fn build_time(&self) -> String {
option_env!("BUILD_TIME").unwrap_or("unknown").to_string()
}

/// Get the network this SDK is configured for
pub(crate) fn network(&self) -> dash_sdk::dpp::dashcore::Network {
self.0.network
Expand Down
Loading