From 5fbfdfb241af1d57ac7a76738b2ac933dfa1c2b8 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 14 Nov 2023 10:56:10 +0100 Subject: [PATCH] Add set_wasm_version! to create custom Wasm section --- contracts/cyberpunk/Cargo.lock | 9 ++++++++- contracts/cyberpunk/Cargo.toml | 3 ++- contracts/cyberpunk/src/contract.rs | 6 ++++++ contracts/cyberpunk/src/lib.rs | 2 ++ contracts/cyberpunk/src/set_version.rs | 15 +++++++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 contracts/cyberpunk/src/set_version.rs diff --git a/contracts/cyberpunk/Cargo.lock b/contracts/cyberpunk/Cargo.lock index 44a1aec8ac..c3f9c59df8 100644 --- a/contracts/cyberpunk/Cargo.lock +++ b/contracts/cyberpunk/Cargo.lock @@ -202,6 +202,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "795bc6e66a8e340f075fcf6227e417a2dc976b92b91f3cdc778bb858778b6747" +[[package]] +name = "const-str" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aca749d3d3f5b87a0d6100509879f9cf486ab510803a4a4e1001da1ff61c2bd6" + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -504,8 +510,9 @@ dependencies = [ [[package]] name = "cyberpunk" -version = "0.0.0" +version = "0.12.345" dependencies = [ + "const-str", "cosmwasm-schema", "cosmwasm-std", "cosmwasm-vm", diff --git a/contracts/cyberpunk/Cargo.toml b/contracts/cyberpunk/Cargo.toml index c2db096f28..e468abcb8e 100644 --- a/contracts/cyberpunk/Cargo.toml +++ b/contracts/cyberpunk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cyberpunk" -version = "0.0.0" +version = "0.12.345" authors = ["Tomasz Kurcz "] edition = "2021" publish = false @@ -33,6 +33,7 @@ cosmwasm-schema = { path = "../../packages/schema" } cosmwasm-std = { path = "../../packages/std", default-features = false, features = ["abort", "cosmwasm_1_3"] } rust-argon2 = "0.8" thiserror = "1.0.26" +const-str = "0.5.6" [dev-dependencies] cosmwasm-vm = { path = "../../packages/vm", default-features = false } diff --git a/contracts/cyberpunk/src/contract.rs b/contracts/cyberpunk/src/contract.rs index 2084f630df..f66a6b5346 100644 --- a/contracts/cyberpunk/src/contract.rs +++ b/contracts/cyberpunk/src/contract.rs @@ -5,6 +5,12 @@ use cosmwasm_std::{ use crate::errors::ContractError; use crate::msg::{ExecuteMsg, QueryMsg}; +use crate::set_wasm_version; + +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); +const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + +set_wasm_version!(CONTRACT_NAME, CONTRACT_VERSION); #[entry_point] pub fn instantiate( diff --git a/contracts/cyberpunk/src/lib.rs b/contracts/cyberpunk/src/lib.rs index 9ef0427925..a318aa7826 100644 --- a/contracts/cyberpunk/src/lib.rs +++ b/contracts/cyberpunk/src/lib.rs @@ -1,3 +1,5 @@ pub mod contract; pub mod errors; pub mod msg; + +mod set_version; diff --git a/contracts/cyberpunk/src/set_version.rs b/contracts/cyberpunk/src/set_version.rs new file mode 100644 index 0000000000..be89f8a234 --- /dev/null +++ b/contracts/cyberpunk/src/set_version.rs @@ -0,0 +1,15 @@ +#[macro_export] +macro_rules! set_wasm_version { + ($s1: expr, $s2: expr) => { + /// Private module with no stability guarantees + mod __cw5 { + use super::*; + + const FULL: &str = const_str::concat!("/", $s1, "/", $s2); + + #[link_section = "cw5"] + #[allow(unused)] + static AS_BYTES: [u8; FULL.len()] = const_str::to_byte_array!(FULL); + } + }; +}