Skip to content

Commit

Permalink
Add support for ink!'s version metadata field (#641)
Browse files Browse the repository at this point in the history
* Format `transcode`'s `lib.rs`

* Use `InkProject` directly instead of `MetadataVersioned`

* Patch ink dependencies to point to development branch

* Use same nightly compiler as CI to format code

* Use updated ink! dependences in template

* Bump lockfile

* Bump expected metadata version to V4

* Bump to V4 in a couple more places

* Clear cache before running tests

* Add missing colon

* Looks like the directory doesn't want to be cleaned

* Bump to ink! 4.0 pre-release

* Bump ink! version

* Remove metadata version check

There's only one metadata version that can be constructed,
so the check doesn't totally make sense.

In the future if we support both V4 and V5 metadata formats it would
make sense to add such a check back.

* Appease Clippy

* Move away from ink!'s `hc-versioned-metadata` branch

* Remove metadata version check (again)

There's only one metadata version that can be constructed,
so the check doesn't totally make sense.

In the future if we support both V4 and V5 metadata formats it would
make sense to add such a check back.

* RustFmt

* Remove another irrefutable `if let`

* Bump ink! versions to `4.0.0-alpha.1`

* Deny `unused_crate_dependencies` again
  • Loading branch information
HCastano authored Aug 24, 2022
1 parent 8708023 commit f903c03
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 55 deletions.
50 changes: 25 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions templates/new/_Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ authors = ["[your_name] <[your_email]>"]
edition = "2021"

[dependencies]
ink_primitives = { version = "3.3", default-features = false }
ink_metadata = { version = "3.3", default-features = false, features = ["derive"], optional = true }
ink_env = { version = "3.3", default-features = false }
ink_storage = { version = "3.3", default-features = false }
ink_lang = { version = "3.3", default-features = false }
ink_primitives = { version = "4.0.0-alpha.1", default-features = false }
ink_metadata = { version = "4.0.0-alpha.1", default-features = false, features = ["derive"], optional = true }
ink_env = { version = "4.0.0-alpha.1", default-features = false }
ink_storage = { version = "4.0.0-alpha.1", default-features = false }
ink_lang = { version = "4.0.0-alpha.1", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }
Expand Down
12 changes: 7 additions & 5 deletions templates/tools/generate-metadata/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
extern crate contract;

extern "Rust" {
fn __ink_generate_metadata() -> ink_metadata::MetadataVersioned;
// Note: The ink! metdata codegen generates an implementation for this function,
// which is what we end up linking to here.
fn __ink_generate_metadata() -> ink_metadata::InkProject;
}

fn main() -> Result<(), std::io::Error> {
let metadata = unsafe { __ink_generate_metadata() };
let contents = serde_json::to_string_pretty(&metadata)?;
print!("{}", contents);
Ok(())
let metadata = unsafe { __ink_generate_metadata() };
let contents = serde_json::to_string_pretty(&metadata)?;
print!("{}", contents);
Ok(())
}
12 changes: 6 additions & 6 deletions transcode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ env_logger = "0.9.0"
escape8259 = "0.5.2"
hex = "0.4.3"
indexmap = "1.9.1"
ink_env = "3.3"
ink_metadata = { version = "3.3", features = ["derive"] }
ink_env = "4.0.0-alpha.1"
ink_metadata = { version = "4.0.0-alpha.1", features = ["derive"] }
itertools = "0.10.3"
tracing = "0.1.36"
nom = "7.1.1"
Expand All @@ -38,12 +38,12 @@ sp-runtime = "6.0.0"

[dev-dependencies]
assert_matches = "1.5.0"
ink_lang = "3.3"
ink_primitives = "3.3"
ink_storage = "3.3"
ink_lang = "4.0.0-alpha.1"
ink_primitives = "4.0.0-alpha.1"
ink_storage = "4.0.0-alpha.1"

[features]
# This `std` feature is required for testing using an inline contract's metadata, because `ink!` annotates the metadata
# generation code with `#[cfg(feature = "std")]`.
default = ["std"]
std = []
std = []
20 changes: 6 additions & 14 deletions transcode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,8 @@ impl ContractMessageTranscoder {
"Failed to deserialize ink project metadata from file {}",
path.display()
))?;
if let ink_metadata::MetadataVersioned::V3(ink_project) = ink_metadata {
Ok(Self::new(ink_project))
} else {
Err(anyhow::anyhow!(
"Unsupported ink metadata version. Expected V1"
))
}

Ok(Self::new(ink_metadata))
}

pub fn encode<I, S>(&self, name: &str, args: I) -> Result<Vec<u8>>
Expand Down Expand Up @@ -481,14 +476,11 @@ mod tests {

fn generate_metadata() -> ink_metadata::InkProject {
extern "Rust" {
fn __ink_generate_metadata() -> ink_metadata::MetadataVersioned;
}
let metadata_versioned = unsafe { __ink_generate_metadata() };
if let ink_metadata::MetadataVersioned::V3(ink_project) = metadata_versioned {
ink_project
} else {
panic!("Expected metadata V3");
fn __ink_generate_metadata() -> ink_metadata::InkProject;
}

let ink_project = unsafe { __ink_generate_metadata() };
ink_project
}

#[test]
Expand Down

0 comments on commit f903c03

Please sign in to comment.