Skip to content

Align the code to the newRust SDK#16

Open
smiasojed wants to merge 8 commits into
mainfrom
sm/new-sdk
Open

Align the code to the newRust SDK#16
smiasojed wants to merge 8 commits into
mainfrom
sm/new-sdk

Conversation

@smiasojed
Copy link
Copy Markdown

@smiasojed smiasojed commented May 12, 2026

Open issues:

  1. Mapping<K, V> silently corrupts when V::ENCODED_SIZE > 32. Mapping::get on sm/cdm@059bb9ee still uses storage_get_32 (single-slot read). CDM workaround in place: split NamedContractInfo → owner_of + version_count_of.
  2. No OrderedIndex in pvm-storage. The pre-port registry had O(log n) prefix lookup via OrderedIndex<String, u32, 2>. The new SDK doesn't expose one, so search_contract_names is now an O(n) linear scan.

@smiasojed smiasojed changed the title WIP: Align the code to the newRust SDK Align the code to the newRust SDK May 18, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the Rust contract examples, registry, and CDM tooling toward the new pvm-contract-sdk flow, replacing old CDM annotations with Cargo metadata and adding a new pvm-cdm reference macro layer.

Changes:

  • Migrates contracts/templates from pvm_contract storage/macros to pvm-contract-sdk.
  • Adds pvm-cdm macro crates and an import test harness for cdm::import!.
  • Updates contract detection/build paths and adds an ABI round-trip test.

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 18 comments.

Show a summary per file
File Description
Cargo.toml Updates workspace dependencies and members for the new SDK/CDM macro crates.
src/contract/Cargo.toml Migrates registry crate dependencies and adds CDM package metadata.
src/contract/src/lib.rs Rewrites the registry contract using the new SDK storage/API model.
src/lib/cdm/import-test/.cargo/config.toml Adds test-specific Cargo environment configuration.
src/lib/cdm/import-test/Cargo.toml Adds a Rust import-test contract crate.
src/lib/cdm/import-test/cdm.json Adds fixture CDM dependency metadata.
src/lib/cdm/import-test/fixtures/.cdm/test/contracts/@test/sample/1/abi.json Adds fixture ABI for import macro testing.
src/lib/cdm/import-test/lib.rs Adds an end-to-end cdm::import! compile harness.
src/lib/cdm/rust-macros/pvm-cdm-macros/Cargo.toml Adds the proc-macro crate manifest.
src/lib/cdm/rust-macros/pvm-cdm-macros/src/lib.rs Implements the pvm_cdm::reference! macro.
src/lib/cdm/rust-macros/pvm-cdm/Cargo.toml Adds the public pvm-cdm crate manifest.
src/lib/cdm/rust-macros/pvm-cdm/src/lib.rs Re-exports the reference macro and documents usage.
src/lib/cdm/rust-macros/pvm-cdm/tests/reference_shape.rs Adds a compile-shape test for generated reference methods.
src/lib/cdm/rust-macros/src/lib.rs Updates cdm::import! to emit SDK ABI imports plus CDM references.
src/lib/contracts/src/detection.ts Reads CDM package names from Cargo metadata.
src/lib/contracts/src/index.ts Removes readCdmPackage from public exports.
src/lib/contracts/src/pipeline.ts Updates Rust artifact paths and removes post-build CDM package discovery.
src/lib/contracts/tests/install-roundtrip.test.ts Adds ABI/metadata save round-trip coverage.
src/templates/guide/Cargo.toml Updates guide workspace dependencies to the new SDK/CDM crates.
src/templates/guide/contracts/app-api/Cargo.toml Migrates app-api dependencies and CDM metadata.
src/templates/guide/contracts/app-api/lib.rs Rewrites app-api counter contract with new SDK macros/storage.
src/templates/guide/contracts/support-contract/Cargo.toml Migrates support contract dependencies and metadata.
src/templates/guide/contracts/support-contract/lib.rs Rewrites support contract to call app-api via CDM import.
src/templates/instagram/Cargo.toml Updates Instagram workspace dependencies.
src/templates/instagram/contracts/instagram/Cargo.toml Migrates Instagram contract dependencies and metadata.
src/templates/instagram/contracts/instagram/lib.rs Rewrites Instagram contract using new SDK storage patterns.
src/templates/shared-counter/Cargo.toml Updates shared-counter workspace dependencies.
src/templates/shared-counter/contracts/counter/Cargo.toml Migrates counter dependencies and CDM metadata.
src/templates/shared-counter/contracts/counter/lib.rs Rewrites counter contract with new SDK storage/macros.
src/templates/shared-counter/contracts/counter-reader/Cargo.toml Migrates reader dependencies and metadata.
src/templates/shared-counter/contracts/counter-reader/lib.rs Rewrites reader to use CDM import and SDK calls.
src/templates/shared-counter/contracts/counter-writer/Cargo.toml Migrates writer dependencies and metadata.
src/templates/shared-counter/contracts/counter-writer/lib.rs Rewrites writer to use CDM import and SDK calls.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Cargo.toml
[workspace]
resolver = "2"
members = ["src/contract", "src/lib/cdm/rust", "src/lib/cdm/rust-macros"]
members = ["src/contract", "src/lib/cdm/rust", "src/lib/cdm/rust-macros", "src/lib/cdm/import-test"]
Comment thread Cargo.toml
[workspace]
resolver = "2"
members = ["src/contract", "src/lib/cdm/rust", "src/lib/cdm/rust-macros"]
members = ["src/contract", "src/lib/cdm/rust", "src/lib/cdm/rust-macros", "src/lib/cdm/import-test"]
Comment thread src/contract/src/lib.rs Outdated
Comment on lines +190 to +198
/// Returns `Address::ZERO` when the name is unregistered.
#[pvm_contract_sdk::method]
pub fn get_address(&self, contract_name: String) -> Address {
let info = self.info.get(&contract_name);
if info.version_count == 0 {
return Address::ZERO;
}
let latest = info.version_count - 1;
self.published_address.get(&(contract_name, latest))
Comment thread src/contract/src/lib.rs Outdated
Comment on lines +201 to +205
/// Metadata URI of the latest published version of `contract_name`.
/// Returns the empty string when the name is unregistered.
#[pvm_contract_sdk::method]
pub fn get_metadata_uri(&self, contract_name: String) -> String {
let info = self.info.get(&contract_name);
Comment thread src/contract/src/lib.rs
Comment on lines +213 to +217
/// Address of a specific version of `contract_name`.
/// Returns `Address::ZERO` when the version is unregistered.
#[pvm_contract_sdk::method]
pub fn get_address_at_version(&self, contract_name: String, version: Version) -> Address {
self.published_address.get(&(contract_name, version))
detectDeploymentOrder,
detectDeploymentOrderLayered,
readCdmPackage,
getGitRemoteUrl,
Comment thread src/contract/Cargo.toml
Comment on lines +9 to +11
[package.metadata.cdm-package]
name = "@cdm/contract-registry"

#![cfg_attr(not(feature = "abi-gen"), no_main, no_std)]

use pvm_contract as pvm;
cdm::import!("@example/counter");
#![cfg_attr(not(feature = "abi-gen"), no_main, no_std)]

use pvm_contract as pvm;
cdm::import!("@example/counter");
#![cfg_attr(not(feature = "abi-gen"), no_main, no_std)]

use pvm_contract as pvm;
cdm::import!("@example/app-api");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants