Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ink!'s version metadata field #641

Merged
merged 26 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a18476b
Format `transcode`'s `lib.rs`
HCastano Jul 11, 2022
2f203c4
Use `InkProject` directly instead of `MetadataVersioned`
HCastano Jul 11, 2022
a684e1b
Patch ink dependencies to point to development branch
HCastano Jul 11, 2022
02dd06c
Merge branch 'master' into hc-versioned-metadata
HCastano Jul 14, 2022
7472a76
Use same nightly compiler as CI to format code
HCastano Jul 14, 2022
f728a5f
Use updated ink! dependences in template
HCastano Jul 14, 2022
7bb61dd
Bump lockfile
HCastano Jul 14, 2022
e24996d
Bump expected metadata version to V4
HCastano Jul 14, 2022
1cb063e
Bump to V4 in a couple more places
HCastano Jul 14, 2022
befcc3b
Clear cache before running tests
HCastano Jul 14, 2022
b797c3e
Add missing colon
HCastano Jul 14, 2022
17612e2
Looks like the directory doesn't want to be cleaned
HCastano Jul 14, 2022
c55b719
Bump to ink! 4.0 pre-release
HCastano Jul 15, 2022
c98e911
Merge branch 'master' into hc-versioned-metadata
HCastano Aug 9, 2022
66cf72f
Bump ink! version
HCastano Aug 9, 2022
a1c354b
Remove metadata version check
HCastano Aug 9, 2022
636e200
Merge branch 'master' into hc-versioned-metadata
HCastano Aug 23, 2022
732e9f3
Appease Clippy
HCastano Aug 23, 2022
cb45b64
Move away from ink!'s `hc-versioned-metadata` branch
HCastano Aug 23, 2022
6655ca3
Merge branch 'master' into hc-versioned-metadata
HCastano Aug 24, 2022
8f0684a
Merge branch 'master' into hc-versioned-metadata
HCastano Aug 24, 2022
cfdd262
Remove metadata version check (again)
HCastano Aug 24, 2022
ade9566
RustFmt
HCastano Aug 24, 2022
227523c
Remove another irrefutable `if let`
HCastano Aug 24, 2022
023bb89
Bump ink! versions to `4.0.0-alpha.1`
HCastano Aug 24, 2022
ed493d0
Deny `unused_crate_dependencies` again
HCastano Aug 24, 2022
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: 25 additions & 37 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ regex = "1.6.0"

# dependencies for extrinsics (deploying and calling a contract)
async-std = { version = "1.12.0", features = ["attributes", "tokio1"] }
ink_metadata = { version = "3.3", features = ["derive"] }
ink_metadata = { version = "4", features = ["derive"], git = "https://github.com/paritytech/ink" }
sp-core = "6.0.0"
pallet-contracts-primitives = "6.0.0"
subxt = "0.23.0"
Expand Down
20 changes: 9 additions & 11 deletions src/cmd/extrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ use scale::{
Decode,
Encode,
};
use serde_json::Value;
use sp_core::{
crypto::Pair,
sr25519,
Expand Down Expand Up @@ -166,16 +165,15 @@ pub fn load_metadata(
"Failed to deserialize metadata file {}",
path.display()
))?;
let ink_metadata =
serde_json::from_value(Value::Object(metadata.abi)).context(format!(
"Failed to deserialize ink project metadata from file {}",
path.display()
))?;
if let ink_metadata::MetadataVersioned::V3(ink_project) = ink_metadata {
Ok((crate_metadata, ink_project))
} else {
Err(anyhow!("Unsupported ink metadata version. Expected V1"))
}
let ink_metadata: ink_metadata::InkProject = serde_json::from_value(
serde_json::Value::Object(metadata.abi),
)
.context(format!(
"Failed to deserialize ink! project metadata from file {}",
path.display()
))?;

Ok((crate_metadata, ink_metadata))
}

/// Parse Rust style integer balance literals which can contain underscores.
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with cargo-contract. If not, see <http://www.gnu.org/licenses/>.

#![deny(unused_crate_dependencies)]
// #![deny(unused_crate_dependencies)]

mod cmd;
mod crate_metadata;
Expand Down
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", default-features = false, git = "https://github.com/paritytech/ink" }
ink_metadata = { version = "4", default-features = false, features = ["derive"], optional = true }
ink_env = { version = "4", default-features = false, git = "https://github.com/paritytech/ink" }
ink_storage = { version = "4", default-features = false, git = "https://github.com/paritytech/ink" }
ink_lang = { version = "4", default-features = false, git = "https://github.com/paritytech/ink" }

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.1"
hex = "0.4.3"
indexmap = "1.9.1"
ink_env = "3.3"
ink_metadata = { version = "3.3", features = ["derive"] }
ink_env = { version = "4", git = "https://github.com/paritytech/ink" }
ink_metadata = { version = "4", features = ["derive"], git = "https://github.com/paritytech/ink" }
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 = { version = "4", git = "https://github.com/paritytech/ink" }
ink_primitives = { version = "4", git = "https://github.com/paritytech/ink" }
ink_storage = { version = "4", git = "https://github.com/paritytech/ink" }

[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 = []
12 changes: 7 additions & 5 deletions transcode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ fn load_metadata(path: &Path) -> anyhow::Result<ink_metadata::InkProject> {
let file = File::open(&path).expect("Failed to open metadata file");
let metadata: ContractMetadata =
serde_json::from_reader(file).expect("Failed to deserialize metadata file");
let ink_metadata = serde_json::from_value(serde_json::Value::Object(metadata.abi))
.expect("Failed to deserialize ink project metadata");

if let ink_metadata::MetadataVersioned::V3(ink_project) = ink_metadata {
Ok(ink_project)
let ink_metadata: ink_metadata::InkProject = serde_json::from_value(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice that you fixed this example in the README, however it is quite brittle for the code to be here in the first place. See #705

serde_json::Value::Object(metadata.abi),
).expect("Failed to deserialize ink project metadata");

if let ink_metadata::MetadataVersion::V4 = ink_metadata.version() {
Ok(ink_metadata)
} else {
Err(anyhow!("Unsupported ink metadata version. Expected V3"))
Err(anyhow!("Unsupported ink metadata version. Expected V4"))
}
}

Expand Down
9 changes: 5 additions & 4 deletions transcode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,14 @@ mod tests {

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

let ink_project = unsafe { __ink_generate_metadata() };
if let ink_metadata::MetadataVersion::V4 = ink_project.version() {
ink_project
} else {
panic!("Expected metadata V3");
panic!("Expected metadata V4");
}
}

Expand Down