Skip to content

Commit

Permalink
Generate Solidity compatible metadata (#1930)
Browse files Browse the repository at this point in the history
* Generate Solidity compatible metadata

* Update changelog

* Fix tests

* Add test

* Add support for structured primitive types

* Use default constructor

* Output copy

* Add build info

* Clarify NatSpec user docs

* Update type mapping

* Fix test

* Refactor metadata artifacts representation

* Fix test

* Add more build info

* Update Solidity metadata representation

* Fix tests

* Update type mapping

* Notes on unit-only enums and doc comments for function params

* ink dependency updates
  • Loading branch information
davidsemakula authored Feb 11, 2025
1 parent 94d7ce1 commit 85828bc
Show file tree
Hide file tree
Showing 17 changed files with 1,507 additions and 78 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[Unreleased]

### Added
- Add option to generate Solidity compatible metadata (via `cargo contract build ---metadata <ink|solidity>`) - [1930](https://github.com/use-ink/cargo-contract/pull/1930)
- Deny overflowing (and lossy) integer type cast operations - [#1895](https://github.com/use-ink/cargo-contract/pull/1895)

### Changed
Expand Down
109 changes: 95 additions & 14 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions crates/build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ rustc_version = "0.4.1"
scale = { package = "parity-scale-codec", version = "3.6.12", features = [
"derive",
] }
scale-info = "2.11.6"
toml = "0.8.19"
tracing = "0.1.41"
semver = { version = "1.0.25", features = ["serde"] }
Expand All @@ -42,10 +43,13 @@ tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
tokio-stream = "0.1.17"
bollard = "0.18.1"
crossterm = "0.28.1"
itertools = "0.13.0"
alloy-json-abi = "0.8.20"

polkavm-linker = "0.18.0"

contract-metadata = { version = "6.0.0-alpha", path = "../metadata" }
ink_metadata = { git = "https://github.com/use-ink/ink", branch = "master" }
sha3 = "0.11.0-pre.4"

[target.'cfg(unix)'.dependencies]
Expand Down
2 changes: 2 additions & 0 deletions crates/build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use contract_build::{
BuildArtifacts,
BuildMode,
Features,
MetadataSpec,
Network,
OutputType,
UnstableFlags,
Expand All @@ -34,6 +35,7 @@ let args = contract_build::ExecuteArgs {
output_type: OutputType::Json,
skip_clippy_and_linting: false,
image: ImageVariant::Default,
metadata_spec: MetadataSpec::Ink,
};

contract_build::execute(args);
Expand Down
35 changes: 34 additions & 1 deletion crates/build/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::{
path::Path,
};

#[derive(Default, Clone, Debug, Args)]
#[derive(Default, Clone, Copy, Debug, Args)]
pub struct VerbosityFlags {
/// No output printed to stdout
#[clap(long)]
Expand Down Expand Up @@ -272,3 +272,36 @@ impl Features {
}
}
}

/// Specification to use for contract metadata.
#[derive(
Debug,
Default,
Clone,
Copy,
PartialEq,
Eq,
clap::ValueEnum,
serde::Serialize,
serde::Deserialize,
)]
#[serde(rename_all = "lowercase")]
pub enum MetadataSpec {
/// ink!
#[clap(name = "ink")]
#[serde(rename = "ink!")]
#[default]
Ink,
/// Solidity
#[clap(name = "solidity")]
Solidity,
}

impl fmt::Display for MetadataSpec {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Ink => write!(f, "ink"),
Self::Solidity => write!(f, "solidity"),
}
}
}
2 changes: 2 additions & 0 deletions crates/build/src/crate_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct CrateMetadata {
pub user: Option<Map<String, Value>>,
pub target_directory: PathBuf,
pub target_file_path: PathBuf,
pub metadata_spec_path: PathBuf,
}

impl CrateMetadata {
Expand Down Expand Up @@ -144,6 +145,7 @@ impl CrateMetadata {
homepage,
user,
target_file_path: target_directory.join(".target").into(),
metadata_spec_path: target_directory.join(".metadata_spec").into(),
target_directory: target_directory.into(),
};
Ok(crate_metadata)
Expand Down
Loading

0 comments on commit 85828bc

Please sign in to comment.