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

Rename metadata.json to {contract_name}.json #952

Merged
merged 2 commits into from
Feb 7, 2023
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Rename `metadata.json` to `{contract_name}.json` - [#952](https://github.com/paritytech/cargo-contract/pull/952)

### Fixed
- Respect the lockfile [#948](https://github.com/paritytech/cargo-contract/pull/948)
Expand Down
5 changes: 2 additions & 3 deletions crates/build/src/crate_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ use std::{
use toml::value;
use url::Url;

const METADATA_FILE: &str = "metadata.json";

/// Relevant metadata obtained from Cargo.toml.
#[derive(Debug)]
pub struct CrateMetadata {
Expand Down Expand Up @@ -147,7 +145,8 @@ impl CrateMetadata {

/// Get the path of the contract metadata file
pub fn metadata_path(&self) -> PathBuf {
self.target_directory.join(METADATA_FILE)
let metadata_file = format!("{}.json", self.contract_artifact_name);
self.target_directory.join(metadata_file)
}

/// Get the path of the contract bundle, containing metadata + code.
Expand Down
4 changes: 2 additions & 2 deletions crates/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ mod unit_tests {
let raw_result = r#"{
"dest_wasm": "/path/to/contract.wasm",
"metadata_result": {
"dest_metadata": "/path/to/metadata.json",
"dest_metadata": "/path/to/contract.json",
"dest_bundle": "/path/to/contract.contract"
},
"target_directory": "/path/to/target",
Expand All @@ -844,7 +844,7 @@ mod unit_tests {
let build_result = BuildResult {
dest_wasm: Some(PathBuf::from("/path/to/contract.wasm")),
metadata_result: Some(MetadataResult {
dest_metadata: PathBuf::from("/path/to/metadata.json"),
dest_metadata: PathBuf::from("/path/to/contract.json"),
dest_bundle: PathBuf::from("/path/to/contract.contract"),
}),
target_directory: PathBuf::from("/path/to/target"),
Expand Down
2 changes: 0 additions & 2 deletions crates/build/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ use std::{
};
use url::Url;

pub const METADATA_FILE: &str = "metadata.json";

/// Metadata generation result.
#[derive(serde::Serialize)]
pub struct MetadataResult {
Expand Down
7 changes: 5 additions & 2 deletions crates/cargo-contract/src/cmd/extrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ pub use balance::{
TokenMetadata,
};
pub use call::CallCommand;
use contract_build::metadata::METADATA_FILE;
use contract_metadata::ContractMetadata;
pub use contract_transcode::ContractMessageTranscoder;
pub use error::ErrorVariant;
Expand Down Expand Up @@ -224,9 +223,13 @@ impl ContractArtifacts {
(PathBuf::from(path), Some(metadata), code)
}
Some("wasm") => {
let file_name = path.file_stem()
.context("WASM bundle file has unreadable name")?
.to_str()
.context("Error parsing filename string")?;
let code = Some(WasmCode(std::fs::read(path)?));
let dir = path.parent().map_or_else(PathBuf::new, PathBuf::from);
let metadata_path = dir.join(METADATA_FILE);
let metadata_path = dir.join(format!("{file_name}.json"));
if !metadata_path.exists() {
(metadata_path, None, code)
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/transcode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
//! # use contract_metadata::ContractMetadata;
//! # use contract_transcode::ContractMessageTranscoder;
//! # use std::{path::Path, fs::File};
//! let metadata_path = Path::new("/path/to/metadata.json");
//! let metadata_path = Path::new("/path/to/contract.json");
//! let transcoder = ContractMessageTranscoder::load(metadata_path).unwrap();
//!
//! let constructor = "new";
Expand Down
20 changes: 10 additions & 10 deletions docs/extrinsics.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Extrinsics
`cargo-contract` provides CLI support for uploading, instantiating and calling your contracts directly from the command
`cargo-contract` provides CLI support for uploading, instantiating and calling your contracts directly from the command
line.

## Common arguments
Expand Down Expand Up @@ -27,13 +27,13 @@ bearing chains.
```
--manifest-path
```
*Optional*. The path to the `Cargo.toml` of the contract crate. Use this to run commands on a contract from outside of
*Optional*. The path to the `Cargo.toml` of the contract crate. Use this to run commands on a contract from outside of
its project directory.

```
--url
```
*Optional*. The websockets url of an RPC node on the target chain. Defaults to a locally running node at
*Optional*. The websockets url of an RPC node on the target chain. Defaults to a locally running node at
"ws://localhost:9944".

```
Expand All @@ -60,10 +60,10 @@ Assumes that `cargo contract build` has already been run to produce the contract

### `instantiate`

Create an instance of a contract on chain. If the code has already been uploaded via `upload`, specify the resulting
Create an instance of a contract on chain. If the code has already been uploaded via `upload`, specify the resulting
`--code-hash` which will result in a call to [`instantiate`](https://github.com/paritytech/substrate/blob/master/frame/contracts/src/lib.rs#L460).
If no `--code-hash` is specified it will attempt to both upload the code and instantiate via the
[`instantiate_with_code`](https://github.com/paritytech/substrate/blob/master/frame/contracts/src/lib.rs#L419)
If no `--code-hash` is specified it will attempt to both upload the code and instantiate via the
[`instantiate_with_code`](https://github.com/paritytech/substrate/blob/master/frame/contracts/src/lib.rs#L419)
dispatchable.

e.g.
Expand All @@ -75,7 +75,7 @@ cargo contract instantiate \
--code-hash 0xbc1b42256696c8a4187ec3ed79fc602789fc11287c4c30926f5e31ed8169574e
```
- `--constructor` the name of the contract constructor method to invoke.
- `--args` accepts a space separated list of values, encoded in order as the arguments of the constructor to invoke.
- `--args` accepts a space separated list of values, encoded in order as the arguments of the constructor to invoke.
- `--code-hash` the hash of the uploaded code, returned from a call to `contract upload` or a previous
`contract instantiate`

Expand All @@ -95,18 +95,18 @@ cargo contract call \

- `--contract` the account id of the contract to invoke, returned after a successful `contract instantiate`.
- `--message` the name of the contract message to invoke.
- `--args` accepts a space separated list of values, encoded in order as the arguments of the message to invoke.
- `--args` accepts a space separated list of values, encoded in order as the arguments of the message to invoke.

## Specifying the contract artifact

The above examples assume the working directory is the contract source code where the `Cargo.toml` file is located.
This is used to determine the location of the contract artifacts. Alternatively, there is an optional positional
This is used to determine the location of the contract artifacts. Alternatively, there is an optional positional
argument to each of the extrinsic commands which allows specifying the contract artifact file directly. E.g.


`cargo upload ../path/to/mycontract.wasm`
`cargo instantiate ../path/to/mycontract.contract`
`cargo call ..path/to/metadata.json`
`cargo call ..path/to/mycontract.json`



Expand Down