diff --git a/core/ic/Cargo.lock b/core/ic/Cargo.lock index 44e0e03c..9f6dcedf 100644 --- a/core/ic/Cargo.lock +++ b/core/ic/Cargo.lock @@ -647,6 +647,28 @@ dependencies = [ "wasi", ] +[[package]] +name = "git-version" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b0decc02f4636b9ccad390dcbe77b722a77efedfa393caf8379a51d5c61899" +dependencies = [ + "git-version-macro", + "proc-macro-hack", +] + +[[package]] +name = "git-version-macro" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe69f1cbdb6e28af2bac214e943b99ce8a0a06b447d15d3e61161b0423139f3f" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "gloo-timers" version = "0.2.2" @@ -1097,6 +1119,12 @@ dependencies = [ "toml", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + [[package]] name = "proc-macro2" version = "1.0.32" @@ -1284,6 +1312,7 @@ version = "0.1.0" dependencies = [ "async-std", "candid", + "git-version", "hex", "ic-cdk", "ic-cdk-macros", diff --git a/core/ic/src/tera/Cargo.toml b/core/ic/src/tera/Cargo.toml index 859951c8..716b18cc 100644 --- a/core/ic/src/tera/Cargo.toml +++ b/core/ic/src/tera/Cargo.toml @@ -17,6 +17,7 @@ ic-kit = "0.4.8" sha3 = "0.9.1" hex = "0.4.3" serde = "1.0.130" +git-version = "0.3.5" serde_bytes = "0.11.5" num-bigint = "0.4.3" diff --git a/core/ic/src/tera/src/api/mod.rs b/core/ic/src/tera/src/api/mod.rs index e0f53461..16247d89 100644 --- a/core/ic/src/tera/src/api/mod.rs +++ b/core/ic/src/tera/src/api/mod.rs @@ -6,3 +6,4 @@ pub mod messages; pub mod nonce; pub mod send_message; pub mod store_message; +pub mod version; diff --git a/core/ic/src/tera/src/api/version.rs b/core/ic/src/tera/src/api/version.rs new file mode 100644 index 00000000..49f037d4 --- /dev/null +++ b/core/ic/src/tera/src/api/version.rs @@ -0,0 +1,17 @@ +use candid::candid_method; +use ic_cdk_macros::query; + +use super::admin::is_authorized; +use crate::tera::{CURRENT_COMMIT, VERSION}; + +#[query(name = "get_version", guard = "is_authorized")] +#[candid_method(query, rename = "get_version")] +fn get_version() -> &'static str { + VERSION.with(|v| v.to_owned()) +} + +#[query(name = "get_current_commit", guard = "is_authorized")] +#[candid_method(query, rename = "get_current_commit")] +fn get_current_commit() -> &'static str { + CURRENT_COMMIT.with(|c| c.to_owned()) +} diff --git a/core/ic/src/tera/src/tera.rs b/core/ic/src/tera/src/tera.rs index 4b7977c5..468c1be6 100644 --- a/core/ic/src/tera/src/tera.rs +++ b/core/ic/src/tera/src/tera.rs @@ -1,5 +1,6 @@ use crate::common::types::{Nonce, NonceBytes, OutgoingMessage, OutgoingMessagePair}; use candid::{CandidType, Deserialize, Nat, Principal}; +use git_version::git_version; use ic_kit::ic::caller; use sha2::{Digest, Sha256}; use std::{ @@ -9,6 +10,8 @@ use std::{ thread_local! { pub static STATE: TerabetiaState = TerabetiaState::default(); + pub static VERSION: &'static str = env!("CARGO_PKG_VERSION"); + pub static CURRENT_COMMIT: &'static str = git_version!(args = ["--always", "--exclude", "*"], fallback = "unknown"); } #[derive(CandidType, Deserialize, Default)] diff --git a/core/ic/src/tera/tera.did b/core/ic/src/tera/tera.did index 43ec66bd..5601f75d 100644 --- a/core/ic/src/tera/tera.did +++ b/core/ic/src/tera/tera.did @@ -7,8 +7,10 @@ type StoreMessageResponse = variant { Ok : CallResult; Err : text }; service : { authorize : (principal) -> (); consume_message : (principal, vec nat8, vec nat) -> (ConsumeMessageResponse); + get_current_commit : () -> (text) query; get_messages : () -> (vec OutgoingMessagePair) query; get_nonces : () -> (vec nat) query; + get_version : () -> (text) query; remove_messages : (vec OutgoingMessagePair) -> (ConsumeMessageResponse); send_message : (principal, vec nat) -> (SendMessageResponse); store_message : (principal, principal, nat, vec nat) -> ( diff --git a/eth_bridge/ic/Cargo.lock b/eth_bridge/ic/Cargo.lock index 1667baf9..bcc41be8 100644 --- a/eth_bridge/ic/Cargo.lock +++ b/eth_bridge/ic/Cargo.lock @@ -555,6 +555,7 @@ version = "0.1.0" dependencies = [ "async-trait", "candid", + "git-version", "hex", "ic-cdk 0.5.1", "ic-cdk-macros 0.4.0", @@ -717,6 +718,28 @@ dependencies = [ "wasi", ] +[[package]] +name = "git-version" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b0decc02f4636b9ccad390dcbe77b722a77efedfa393caf8379a51d5c61899" +dependencies = [ + "git-version-macro", + "proc-macro-hack", +] + +[[package]] +name = "git-version-macro" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe69f1cbdb6e28af2bac214e943b99ce8a0a06b447d15d3e61161b0423139f3f" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "gloo-timers" version = "0.2.3" @@ -1203,6 +1226,12 @@ dependencies = [ "toml", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + [[package]] name = "proc-macro2" version = "1.0.36" diff --git a/eth_bridge/ic/src/eth_proxy/Cargo.toml b/eth_bridge/ic/src/eth_proxy/Cargo.toml index da09f3cc..f7bee302 100644 --- a/eth_bridge/ic/src/eth_proxy/Cargo.toml +++ b/eth_bridge/ic/src/eth_proxy/Cargo.toml @@ -14,6 +14,7 @@ candid = "0.7.4" ic-cdk-macros = "0.4" hex = "0.4.3" sha3 = "0.9.1" +git-version = "0.3.5" async-trait = "0.1.51" serde = "1.0.130" serde_bytes = "0.11.5" diff --git a/eth_bridge/ic/src/eth_proxy/eth_proxy.did b/eth_bridge/ic/src/eth_proxy/eth_proxy.did index 2711d000..923aa8f1 100644 --- a/eth_bridge/ic/src/eth_proxy/eth_proxy.did +++ b/eth_bridge/ic/src/eth_proxy/eth_proxy.did @@ -25,6 +25,8 @@ service : { get_all : (principal) -> (vec ClaimableMessage) query; get_all_token_balance : () -> (Result_1); get_balance : (principal) -> (opt nat); + get_current_commit : () -> (text) query; + get_version : () -> (text) query; handle_message : (principal, nat, vec nat) -> (Result); mint : (nat, vec nat) -> (Result); remove_claimable : (principal, nat) -> (Result_2); diff --git a/eth_bridge/ic/src/eth_proxy/src/api/mod.rs b/eth_bridge/ic/src/eth_proxy/src/api/mod.rs index b7b1ee17..3d1c4f40 100644 --- a/eth_bridge/ic/src/eth_proxy/src/api/mod.rs +++ b/eth_bridge/ic/src/eth_proxy/src/api/mod.rs @@ -6,4 +6,5 @@ mod handle_message; mod init; mod mint; mod upgrade; +mod version; mod withdraw; diff --git a/eth_bridge/ic/src/eth_proxy/src/api/version.rs b/eth_bridge/ic/src/eth_proxy/src/api/version.rs new file mode 100644 index 00000000..edae353d --- /dev/null +++ b/eth_bridge/ic/src/eth_proxy/src/api/version.rs @@ -0,0 +1,16 @@ +use ic_kit::{candid::candid_method, macros::query}; + +use super::admin::is_authorized; +use crate::proxy::{CURRENT_COMMIT, VERSION}; + +#[query(name = "get_version", guard = "is_authorized")] +#[candid_method(query, rename = "get_version")] +fn get_version() -> &'static str { + VERSION.with(|v| v.to_owned()) +} + +#[query(name = "get_current_commit", guard = "is_authorized")] +#[candid_method(query, rename = "get_current_commit")] +fn get_current_commit() -> &'static str { + CURRENT_COMMIT.with(|c| c.to_owned()) +} diff --git a/eth_bridge/ic/src/eth_proxy/src/proxy.rs b/eth_bridge/ic/src/eth_proxy/src/proxy.rs index 48565295..05f2ad60 100644 --- a/eth_bridge/ic/src/eth_proxy/src/proxy.rs +++ b/eth_bridge/ic/src/eth_proxy/src/proxy.rs @@ -1,5 +1,6 @@ use std::{collections::HashMap, ops::AddAssign}; +use git_version::git_version; use ic_cdk::export::candid::{Nat, Principal}; use ic_kit::ic; @@ -14,6 +15,8 @@ pub const WETH_ADDRESS_ETH: &str = "0x2e130e57021bb4dfb95eb4dd0dd8cfceb936148a"; thread_local! { pub static STATE: ProxyState = ProxyState::default(); + pub static VERSION: &'static str = env!("CARGO_PKG_VERSION"); + pub static CURRENT_COMMIT: &'static str = git_version!(args = ["--always", "--exclude", "*"], fallback = "unknown"); } impl ProxyState { diff --git a/magic_bridge/ic/Cargo.lock b/magic_bridge/ic/Cargo.lock index c961e3d3..012cd721 100644 --- a/magic_bridge/ic/Cargo.lock +++ b/magic_bridge/ic/Cargo.lock @@ -423,6 +423,7 @@ version = "0.1.0" dependencies = [ "async-trait", "candid", + "git-version", "hex", "ic-cdk 0.5.2", "ic-cdk-macros 0.4.0", @@ -632,6 +633,28 @@ dependencies = [ "wasi", ] +[[package]] +name = "git-version" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b0decc02f4636b9ccad390dcbe77b722a77efedfa393caf8379a51d5c61899" +dependencies = [ + "git-version-macro", + "proc-macro-hack", +] + +[[package]] +name = "git-version-macro" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe69f1cbdb6e28af2bac214e943b99ce8a0a06b447d15d3e61161b0423139f3f" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "gloo-timers" version = "0.2.4" @@ -914,6 +937,7 @@ name = "magic_bridge" version = "0.1.0" dependencies = [ "assert-panic", + "git-version", "ic-cdk 0.4.0", "ic-cdk-macros 0.3.3", "ic-kit", @@ -1119,6 +1143,12 @@ dependencies = [ "toml", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + [[package]] name = "proc-macro2" version = "1.0.40" diff --git a/magic_bridge/ic/src/dip20_proxy/Cargo.toml b/magic_bridge/ic/src/dip20_proxy/Cargo.toml index a1eecca6..bae13044 100644 --- a/magic_bridge/ic/src/dip20_proxy/Cargo.toml +++ b/magic_bridge/ic/src/dip20_proxy/Cargo.toml @@ -15,6 +15,7 @@ ic-cdk-macros = "0.4" hex = "0.4.3" sha3 = "0.9.1" async-trait = "0.1.51" +git-version = "0.3.5" serde = "1.0.130" serde_bytes = "0.11.5" num-bigint = "0.4.3" \ No newline at end of file diff --git a/magic_bridge/ic/src/dip20_proxy/dip20_proxy.did b/magic_bridge/ic/src/dip20_proxy/dip20_proxy.did index d9841d89..5f7ac439 100644 --- a/magic_bridge/ic/src/dip20_proxy/dip20_proxy.did +++ b/magic_bridge/ic/src/dip20_proxy/dip20_proxy.did @@ -25,6 +25,8 @@ service : { claimable_get_all : (principal) -> (vec ClaimableMessage) query; get_all_token_balance : () -> (Result_1); get_balance : (principal) -> (opt nat); + get_current_commit : () -> (text) query; + get_version : () -> (text) query; handle_message : (principal, nat, vec nat) -> (Result); mint : (principal, nat, vec nat) -> (Result); remove_claimable : (principal, principal, nat) -> (Result_2); diff --git a/magic_bridge/ic/src/dip20_proxy/src/api/mod.rs b/magic_bridge/ic/src/dip20_proxy/src/api/mod.rs index b7b1ee17..3d1c4f40 100644 --- a/magic_bridge/ic/src/dip20_proxy/src/api/mod.rs +++ b/magic_bridge/ic/src/dip20_proxy/src/api/mod.rs @@ -6,4 +6,5 @@ mod handle_message; mod init; mod mint; mod upgrade; +mod version; mod withdraw; diff --git a/magic_bridge/ic/src/dip20_proxy/src/api/version.rs b/magic_bridge/ic/src/dip20_proxy/src/api/version.rs new file mode 100644 index 00000000..edae353d --- /dev/null +++ b/magic_bridge/ic/src/dip20_proxy/src/api/version.rs @@ -0,0 +1,16 @@ +use ic_kit::{candid::candid_method, macros::query}; + +use super::admin::is_authorized; +use crate::proxy::{CURRENT_COMMIT, VERSION}; + +#[query(name = "get_version", guard = "is_authorized")] +#[candid_method(query, rename = "get_version")] +fn get_version() -> &'static str { + VERSION.with(|v| v.to_owned()) +} + +#[query(name = "get_current_commit", guard = "is_authorized")] +#[candid_method(query, rename = "get_current_commit")] +fn get_current_commit() -> &'static str { + CURRENT_COMMIT.with(|c| c.to_owned()) +} diff --git a/magic_bridge/ic/src/dip20_proxy/src/proxy.rs b/magic_bridge/ic/src/dip20_proxy/src/proxy.rs index a3d4fed7..e3f2e34e 100644 --- a/magic_bridge/ic/src/dip20_proxy/src/proxy.rs +++ b/magic_bridge/ic/src/dip20_proxy/src/proxy.rs @@ -1,5 +1,6 @@ use std::{collections::HashMap, ops::AddAssign}; +use git_version::git_version; use ic_cdk::export::candid::{Nat, Principal}; use ic_kit::ic; @@ -14,6 +15,8 @@ pub const ERC20_ADDRESS_ETH: &str = "0x8CA1651eadeF97D3aC36c25DAE4A552c1368F27d" thread_local! { pub static STATE: ProxyState = ProxyState::default(); + pub static VERSION: &'static str = env!("CARGO_PKG_VERSION"); + pub static CURRENT_COMMIT: &'static str = git_version!(args = ["--always", "--exclude", "*"], fallback = "unknown"); } impl ProxyState { diff --git a/magic_bridge/ic/src/magic_bridge/Cargo.toml b/magic_bridge/ic/src/magic_bridge/Cargo.toml index 74b17e06..682188e0 100644 --- a/magic_bridge/ic/src/magic_bridge/Cargo.toml +++ b/magic_bridge/ic/src/magic_bridge/Cargo.toml @@ -12,6 +12,7 @@ ic-kit = "0.4.4" ic-cdk = "0.4.0" serde = "1.0.133" ic-cdk-macros = "0.3" +git-version = "0.3.5" serde_cbor = "0.11.2" serde_bytes = "0.11.5" assert-panic = "1.0.1" diff --git a/magic_bridge/ic/src/magic_bridge/magic_bridge.did b/magic_bridge/ic/src/magic_bridge/magic_bridge.did index 845dff05..3a2ed67a 100644 --- a/magic_bridge/ic/src/magic_bridge/magic_bridge.did +++ b/magic_bridge/ic/src/magic_bridge/magic_bridge.did @@ -34,8 +34,10 @@ service : { flush_failed_registrations : () -> (); get_all : () -> (vec record { principal; principal }) query; get_canister : (principal) -> (opt principal) query; + get_current_commit : () -> (text) query; get_failed_registrations : () -> ( vec record { principal; record { CreateCanisterParam; nat8 } }, ) query; + get_version : () -> (text) query; upgrade_code : (principal, TokenType) -> (Result_1); } \ No newline at end of file diff --git a/magic_bridge/ic/src/magic_bridge/src/api/mod.rs b/magic_bridge/ic/src/magic_bridge/src/api/mod.rs index 8f9f9936..c3aa9cdd 100644 --- a/magic_bridge/ic/src/magic_bridge/src/api/mod.rs +++ b/magic_bridge/ic/src/magic_bridge/src/api/mod.rs @@ -6,3 +6,4 @@ mod init; mod inspect_message; mod install; mod upgrade; +mod version; diff --git a/magic_bridge/ic/src/magic_bridge/src/api/version.rs b/magic_bridge/ic/src/magic_bridge/src/api/version.rs new file mode 100644 index 00000000..0cfe98db --- /dev/null +++ b/magic_bridge/ic/src/magic_bridge/src/api/version.rs @@ -0,0 +1,16 @@ +use ic_kit::{candid::candid_method, macros::query}; + +use super::admin::is_authorized; +use crate::magic::{CURRENT_COMMIT, VERSION}; + +#[query(name = "get_version", guard = "is_authorized")] +#[candid_method(query, rename = "get_version")] +fn get_version() -> &'static str { + VERSION.with(|v| v.to_owned()) +} + +#[query(name = "get_current_commit", guard = "is_authorized")] +#[candid_method(query, rename = "get_current_commit")] +fn get_current_commit() -> &'static str { + CURRENT_COMMIT.with(|c| c.to_owned()) +} diff --git a/magic_bridge/ic/src/magic_bridge/src/magic.rs b/magic_bridge/ic/src/magic_bridge/src/magic.rs index 2f7d9018..f18bd906 100644 --- a/magic_bridge/ic/src/magic_bridge/src/magic.rs +++ b/magic_bridge/ic/src/magic_bridge/src/magic.rs @@ -1,5 +1,6 @@ use crate::factory::CreateCanisterParam; use crate::types::*; +use git_version::git_version; use ic_kit::candid::{CandidType, Deserialize}; use ic_kit::interfaces::management::{ CanisterStatus, CanisterStatusResponse, DeleteCanister, DepositCycles, StartCanister, @@ -14,6 +15,8 @@ use std::str; thread_local! { pub static STATE: MagicState = MagicState::default(); + pub static VERSION: &'static str = env!("CARGO_PKG_VERSION"); + pub static CURRENT_COMMIT: &'static str = git_version!(args = ["--always", "--exclude", "*"], fallback = "unknown"); } #[derive(CandidType, Deserialize, Default)]