From 721ea79cd3c4b95fdba641df49e6e9abc5f40931 Mon Sep 17 00:00:00 2001 From: mdjakovic0920 Date: Mon, 22 Jul 2024 06:37:22 +0000 Subject: [PATCH 1/9] feat: DateTime ADO that returns current time and day pf week specified to timezone --- Cargo.lock | 232 +++++++++++++++++- .../modules/andromeda-date-time/.cargo/config | 4 + .../modules/andromeda-date-time/Cargo.toml | 34 +++ .../andromeda-date-time/examples/schema.rs | 10 + .../andromeda-date-time/src/contract.rs | 129 ++++++++++ .../modules/andromeda-date-time/src/lib.rs | 6 + .../modules/andromeda-date-time/src/mock.rs | 58 +++++ .../andromeda-date-time/src/testing/mock.rs | 36 +++ .../andromeda-date-time/src/testing/mod.rs | 2 + .../andromeda-date-time/src/testing/tests.rs | 51 ++++ packages/andromeda-modules/src/date_time.rs | 59 +++++ packages/andromeda-modules/src/lib.rs | 1 + 12 files changed, 620 insertions(+), 2 deletions(-) create mode 100644 contracts/modules/andromeda-date-time/.cargo/config create mode 100644 contracts/modules/andromeda-date-time/Cargo.toml create mode 100644 contracts/modules/andromeda-date-time/examples/schema.rs create mode 100644 contracts/modules/andromeda-date-time/src/contract.rs create mode 100644 contracts/modules/andromeda-date-time/src/lib.rs create mode 100644 contracts/modules/andromeda-date-time/src/mock.rs create mode 100644 contracts/modules/andromeda-date-time/src/testing/mock.rs create mode 100644 contracts/modules/andromeda-date-time/src/testing/mod.rs create mode 100644 contracts/modules/andromeda-date-time/src/testing/tests.rs create mode 100644 packages/andromeda-modules/src/date_time.rs diff --git a/Cargo.lock b/Cargo.lock index b462121a7..14679aae7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,6 +22,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "andromeda-address-list" version = "2.0.0" @@ -63,7 +78,7 @@ dependencies = [ [[package]] name = "andromeda-app-contract" -version = "1.1.1" +version = "1.1.0" dependencies = [ "andromeda-app", "andromeda-std", @@ -218,6 +233,22 @@ dependencies = [ "serde", ] +[[package]] +name = "andromeda-date-time" +version = "1.0.0" +dependencies = [ + "andromeda-app", + "andromeda-modules", + "andromeda-std", + "andromeda-testing", + "chrono 0.4.38", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", +] + [[package]] name = "andromeda-economics" version = "1.1.0" @@ -535,7 +566,7 @@ dependencies = [ "andromeda-finance", "andromeda-std", "andromeda-testing", - "chrono", + "chrono 0.3.0", "cosmwasm-schema", "cosmwasm-std", "cw-multi-test", @@ -666,6 +697,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56953345e39537a3e18bdaeba4cb0c58a78c1f61f361dc0fa7c5c7340ae87c5f" +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "byteorder" version = "1.5.0" @@ -678,6 +715,12 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +[[package]] +name = "cc" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" + [[package]] name = "cfg-if" version = "1.0.0" @@ -694,12 +737,32 @@ dependencies = [ "time", ] +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets", +] + [[package]] name = "const-oid" version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + [[package]] name = "cosmwasm-crypto" version = "1.5.5" @@ -1359,6 +1422,29 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "itertools" version = "0.10.5" @@ -1392,6 +1478,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "k256" version = "0.13.1" @@ -1430,6 +1525,12 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + [[package]] name = "memchr" version = "2.7.4" @@ -2068,6 +2169,60 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.68", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + [[package]] name = "winapi" version = "0.3.9" @@ -2090,6 +2245,79 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "zeroize" version = "1.8.1" diff --git a/contracts/modules/andromeda-date-time/.cargo/config b/contracts/modules/andromeda-date-time/.cargo/config new file mode 100644 index 000000000..624255c74 --- /dev/null +++ b/contracts/modules/andromeda-date-time/.cargo/config @@ -0,0 +1,4 @@ +[alias] +wasm = "build --release --target wasm32-unknown-unknown" +unit-test = "test --lib" +schema = "run --example schema" \ No newline at end of file diff --git a/contracts/modules/andromeda-date-time/Cargo.toml b/contracts/modules/andromeda-date-time/Cargo.toml new file mode 100644 index 000000000..c50ddb216 --- /dev/null +++ b/contracts/modules/andromeda-date-time/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "andromeda-date-time" +version = "1.0.0" +edition = "2021" +rust-version = "1.75.0" + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] +testing = ["cw-multi-test", "andromeda-testing"] + + +[dependencies] +cosmwasm-std = { workspace = true } +cosmwasm-schema = { workspace = true } +cw-storage-plus = { workspace = true } +cw-utils = { workspace = true } + +andromeda-std = { workspace = true, features = [] } +andromeda-modules = { workspace = true } + +chrono = "0.4.38" + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +cw-multi-test = { workspace = true, optional = true } +andromeda-testing = { workspace = true, optional = true } + +[dev-dependencies] +andromeda-app = { workspace = true } diff --git a/contracts/modules/andromeda-date-time/examples/schema.rs b/contracts/modules/andromeda-date-time/examples/schema.rs new file mode 100644 index 000000000..4dd91526e --- /dev/null +++ b/contracts/modules/andromeda-date-time/examples/schema.rs @@ -0,0 +1,10 @@ +use andromeda_modules::date_time::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use cosmwasm_schema::write_api; +fn main() { + write_api! { + instantiate: InstantiateMsg, + query: QueryMsg, + execute: ExecuteMsg, + + } +} \ No newline at end of file diff --git a/contracts/modules/andromeda-date-time/src/contract.rs b/contracts/modules/andromeda-date-time/src/contract.rs new file mode 100644 index 000000000..223c3526a --- /dev/null +++ b/contracts/modules/andromeda-date-time/src/contract.rs @@ -0,0 +1,129 @@ +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response}; + +use andromeda_modules::date_time::{ExecuteMsg, InstantiateMsg, QueryMsg, Timezone}; +use andromeda_modules::date_time::GetDateTimeResponse; +use andromeda_std::{ + ado_base::{InstantiateMsg as BaseInstantiateMsg, MigrateMsg}, + ado_contract::ADOContract, + common::{ + context::ExecuteContext, encode_binary, + actions::call_action, + }, + error::ContractError, +}; +use chrono::{DateTime, Timelike, Weekday, Datelike}; + +// version info for migration info +const CONTRACT_NAME: &str = "crates.io:andromeda-date-time"; +const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: InstantiateMsg, +) -> Result { + let resp = ADOContract::default().instantiate( + deps.storage, + env, + deps.api, + &deps.querier, + info, + BaseInstantiateMsg { + ado_type: CONTRACT_NAME.to_string(), + ado_version: CONTRACT_VERSION.to_string(), + kernel_address: msg.kernel_address, + owner: msg.owner, + }, + )?; + + Ok(resp) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> Result { + let ctx = ExecuteContext::new(deps, info, env); + match msg { + ExecuteMsg::AMPReceive(pkt) => { + ADOContract::default().execute_amp_receive(ctx, pkt, handle_execute) + }, + _ => handle_execute(ctx, msg), + } +} + +fn handle_execute(mut ctx: ExecuteContext, msg: ExecuteMsg) -> Result { + + let action_response = call_action( + &mut ctx.deps, + &ctx.info, + &ctx.env, + &ctx.amp_ctx, + msg.as_ref(), + )?; + + let res = match msg { + _ => ADOContract::default().execute(ctx, msg), + }?; + + Ok(res + .add_submessages(action_response.messages) + .add_attributes(action_response.attributes) + .add_events(action_response.events)) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result { + match msg { + QueryMsg::GetDateTime { timezone } => encode_binary(&get_date_time(env, timezone)?), + _ => ADOContract::default().query(deps, env, msg), + } +} + +pub fn get_date_time( + env: Env, + timezone: Timezone, +) -> Result { + let timestamp = env.block.time.seconds() as i64; + let timezone_i64 = timezone as i64; + let offset = timezone_i64.checked_mul(3600).unwrap(); + let local_timestamp = timestamp.checked_add(offset).unwrap(); + let local_datetime = DateTime::from_timestamp(local_timestamp, 0).unwrap(); + + let day_of_week = match local_datetime.weekday() { + Weekday::Mon => "Mon", + Weekday::Tue => "Tue", + Weekday::Wed => "Wed", + Weekday::Thu => "Thu", + Weekday::Fri => "Fri", + Weekday::Sat => "Sat", + Weekday::Sun => "Sun", + }; + + let date_time = format!( + "{:04}-{:02}-{:02} {:02}-{:02}-{:02}", + local_datetime.year(), + local_datetime.month(), + local_datetime.day(), + local_datetime.hour(), + local_datetime.minute(), + local_datetime.second(), + ); + + Ok(GetDateTimeResponse { + day_of_week: day_of_week.to_string(), + date_time, + }) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + ADOContract::default().migrate(deps, CONTRACT_NAME, CONTRACT_VERSION) +} diff --git a/contracts/modules/andromeda-date-time/src/lib.rs b/contracts/modules/andromeda-date-time/src/lib.rs new file mode 100644 index 000000000..3a3593725 --- /dev/null +++ b/contracts/modules/andromeda-date-time/src/lib.rs @@ -0,0 +1,6 @@ +pub mod contract; +#[cfg(test)] +pub mod testing; + +#[cfg(all(not(target_arch = "wasm32"), feature = "testing"))] +pub mod mock; \ No newline at end of file diff --git a/contracts/modules/andromeda-date-time/src/mock.rs b/contracts/modules/andromeda-date-time/src/mock.rs new file mode 100644 index 000000000..173f4504c --- /dev/null +++ b/contracts/modules/andromeda-date-time/src/mock.rs @@ -0,0 +1,58 @@ +#![cfg(all(not(target_arch = "wasm32"), feature = "testing"))] +use crate::contract::{execute, instantiate, query}; +use andromeda_modules::date_time::{InstantiateMsg, QueryMsg, Timezone}; +use andromeda_modules::date_time::GetDateTimeResponse; +use andromeda_testing::mock::MockApp; +use andromeda_testing::{ + mock_ado, + mock_contract::{ExecuteResult, MockADO, MockContract}, +}; +use cosmwasm_std::{Addr, Empty}; +use cw_multi_test::{Contract, ContractWrapper, Executor}; + +pub struct MockDateTime(Addr); +mock_ado!(MockDateTime, ExecuteMsg, QueryMsg); + +impl MockDateTime { + pub fn instantiate( + code_id: u64, + sender: Addr, + app: &mut MockApp, + kernel_address: String, + owner: Option, + ) -> MockDateTime { + let msg = mock_date_time_instantiate_msg(kernel_address, owner); + let addr = app + .instantiate_contract( + code_id, + sender.clone(), + &msg, + &[], + "Date Time Contract", + Some(sender.to_string()), + ) + .unwrap(); + MockDateTime(Addr::unchecked(addr)) + } + + pub fn query_date_time(&self, app: &mut MockApp, timezone: Timezone) -> GetDateTimeResponse { + let msg = QueryMsg::GetDateTime { timezone }; + let res: GetDateTimeResponse = self.query(app, msg); + res + } +} + +pub fn mock_andromeda_date_time() -> Box> { + let contract = ContractWrapper::new_with_empty(execute, instantiate, query); + Box::new(contract) +} + +pub fn mock_date_time_instantiate_msg( + kernel_address: String, + owner: Option, +) -> InstantiateMsg { + InstantiateMsg { + kernel_address, + owner, + } +} diff --git a/contracts/modules/andromeda-date-time/src/testing/mock.rs b/contracts/modules/andromeda-date-time/src/testing/mock.rs new file mode 100644 index 000000000..7b018b722 --- /dev/null +++ b/contracts/modules/andromeda-date-time/src/testing/mock.rs @@ -0,0 +1,36 @@ +use andromeda_modules::date_time::{InstantiateMsg, QueryMsg}; +use andromeda_modules::date_time::{GetDateTimeResponse, Timezone}; +use andromeda_std::{ + error::ContractError, + testing::mock_querier::{mock_dependencies_custom, WasmMockQuerier, MOCK_KERNEL_CONTRACT}, +}; +use cosmwasm_std::{ + from_json, + testing::{mock_env, mock_info, MockApi, MockStorage}, + Deps, MessageInfo, OwnedDeps, +}; + +use crate::contract::{instantiate, query}; + +pub type MockDeps = OwnedDeps; + +pub fn proper_initialization() -> (MockDeps, MessageInfo) { + let mut deps = mock_dependencies_custom(&[]); + let info = mock_info("creator", &[]); + let msg = InstantiateMsg { + kernel_address: MOCK_KERNEL_CONTRACT.to_string(), + owner: None, + }; + let env = mock_env(); + let res = instantiate(deps.as_mut(), env, info.clone(), msg).unwrap(); + assert_eq!(0, res.messages.len()); + (deps, info) +} + +pub fn query_date_time(deps: Deps, timezone: Timezone) -> Result { + let res = query(deps, mock_env(), QueryMsg::GetDateTime { timezone }); + match res { + Ok(res) => Ok(from_json(res).unwrap()), + Err(err) => Err(err), + } +} diff --git a/contracts/modules/andromeda-date-time/src/testing/mod.rs b/contracts/modules/andromeda-date-time/src/testing/mod.rs new file mode 100644 index 000000000..aea717dc8 --- /dev/null +++ b/contracts/modules/andromeda-date-time/src/testing/mod.rs @@ -0,0 +1,2 @@ +mod mock; +mod tests; \ No newline at end of file diff --git a/contracts/modules/andromeda-date-time/src/testing/tests.rs b/contracts/modules/andromeda-date-time/src/testing/tests.rs new file mode 100644 index 000000000..a1e439e3b --- /dev/null +++ b/contracts/modules/andromeda-date-time/src/testing/tests.rs @@ -0,0 +1,51 @@ +use super::mock::{ + proper_initialization, query_date_time, +}; +use andromeda_modules::date_time::{Timezone, GetDateTimeResponse}; + +#[test] +fn test_instantiation() { + proper_initialization(); +} + +#[test] +fn test_query_date_time() { + let (deps, _) = proper_initialization(); + + // UTC+3 + let query_res = query_date_time(deps.as_ref(), Timezone::UtcPlus3).unwrap(); + assert_eq!( + query_res, + GetDateTimeResponse { + day_of_week: "Wed".to_string(), + date_time: "2019-10-23 05-23-39".to_string(), + }); + + + // UTC-9 + let query_res = query_date_time(deps.as_ref(), Timezone::UtcMinus9).unwrap(); + assert_eq!( + query_res, + GetDateTimeResponse { + day_of_week: "Tue".to_string(), + date_time: "2019-10-22 17-23-39".to_string(), + }); + + // UTC + let query_res = query_date_time(deps.as_ref(), Timezone::Utc).unwrap(); + assert_eq!( + query_res, + GetDateTimeResponse { + day_of_week: "Wed".to_string(), + date_time: "2019-10-23 02-23-39".to_string(), + }); + + // UTC+14 + let query_res = query_date_time(deps.as_ref(), Timezone::UtcPlus14).unwrap(); + assert_eq!( + query_res, + GetDateTimeResponse { + day_of_week: "Wed".to_string(), + date_time: "2019-10-23 16-23-39".to_string(), + }); +} diff --git a/packages/andromeda-modules/src/date_time.rs b/packages/andromeda-modules/src/date_time.rs new file mode 100644 index 000000000..09389d2e9 --- /dev/null +++ b/packages/andromeda-modules/src/date_time.rs @@ -0,0 +1,59 @@ +use andromeda_std::{ + andr_exec, andr_instantiate, andr_query, +}; +use cosmwasm_schema::{cw_serde, QueryResponses}; + +#[andr_instantiate] +#[cw_serde] +pub struct InstantiateMsg {} + +#[andr_exec] +#[cw_serde] +pub enum ExecuteMsg {} + +#[andr_query] +#[cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg { + #[returns(GetDateTimeResponse)] + GetDateTime { + timezone: Timezone, + }, +} + +#[cw_serde] +pub struct GetDateTimeResponse { + pub day_of_week: String, + pub date_time: String, +} + +#[cw_serde] +pub enum Timezone { + UtcMinus12 = -12, + UtcMinus11 = -11, + UtcMinus10 = -10, + UtcMinus9 = -9, + UtcMinus8 = -8, + UtcMinus7 = -7, + UtcMinus6 = -6, + UtcMinus5 = -5, + UtcMinus4 = -4, + UtcMinus3 = -3, + UtcMinus2 = -2, + UtcMinus1 = -1, + Utc = 0, + UtcPlus1 = 1, + UtcPlus2 = 2, + UtcPlus3 = 3, + UtcPlus4 = 4, + UtcPlus5 = 5, + UtcPlus6 = 6, + UtcPlus7 = 7, + UtcPlus8 = 8, + UtcPlus9 = 9, + UtcPlus10 = 10, + UtcPlus11 = 11, + UtcPlus12 = 12, + UtcPlus13 = 13, + UtcPlus14 = 14, +} diff --git a/packages/andromeda-modules/src/lib.rs b/packages/andromeda-modules/src/lib.rs index 6f71686a3..4996984d2 100644 --- a/packages/andromeda-modules/src/lib.rs +++ b/packages/andromeda-modules/src/lib.rs @@ -1,3 +1,4 @@ pub mod address_list; pub mod rates; pub mod shunting; +pub mod date_time; From 9e6a1a53576a440caf1935516cb537957957bb78 Mon Sep 17 00:00:00 2001 From: mdjakovic0920 Date: Mon, 22 Jul 2024 06:49:51 +0000 Subject: [PATCH 2/9] fix: add default timezone when user don't specify the timezone --- contracts/modules/andromeda-date-time/src/contract.rs | 4 ++-- contracts/modules/andromeda-date-time/src/testing/mock.rs | 2 +- .../modules/andromeda-date-time/src/testing/tests.rs | 8 ++++---- packages/andromeda-modules/src/date_time.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/contracts/modules/andromeda-date-time/src/contract.rs b/contracts/modules/andromeda-date-time/src/contract.rs index 223c3526a..8840d0f45 100644 --- a/contracts/modules/andromeda-date-time/src/contract.rs +++ b/contracts/modules/andromeda-date-time/src/contract.rs @@ -89,10 +89,10 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result, ) -> Result { let timestamp = env.block.time.seconds() as i64; - let timezone_i64 = timezone as i64; + let timezone_i64 = timezone.unwrap_or(Timezone::Utc) as i64; let offset = timezone_i64.checked_mul(3600).unwrap(); let local_timestamp = timestamp.checked_add(offset).unwrap(); let local_datetime = DateTime::from_timestamp(local_timestamp, 0).unwrap(); diff --git a/contracts/modules/andromeda-date-time/src/testing/mock.rs b/contracts/modules/andromeda-date-time/src/testing/mock.rs index 7b018b722..d4908f7fc 100644 --- a/contracts/modules/andromeda-date-time/src/testing/mock.rs +++ b/contracts/modules/andromeda-date-time/src/testing/mock.rs @@ -27,7 +27,7 @@ pub fn proper_initialization() -> (MockDeps, MessageInfo) { (deps, info) } -pub fn query_date_time(deps: Deps, timezone: Timezone) -> Result { +pub fn query_date_time(deps: Deps, timezone: Option) -> Result { let res = query(deps, mock_env(), QueryMsg::GetDateTime { timezone }); match res { Ok(res) => Ok(from_json(res).unwrap()), diff --git a/contracts/modules/andromeda-date-time/src/testing/tests.rs b/contracts/modules/andromeda-date-time/src/testing/tests.rs index a1e439e3b..08bb7f41b 100644 --- a/contracts/modules/andromeda-date-time/src/testing/tests.rs +++ b/contracts/modules/andromeda-date-time/src/testing/tests.rs @@ -13,7 +13,7 @@ fn test_query_date_time() { let (deps, _) = proper_initialization(); // UTC+3 - let query_res = query_date_time(deps.as_ref(), Timezone::UtcPlus3).unwrap(); + let query_res = query_date_time(deps.as_ref(), Some(Timezone::UtcPlus3)).unwrap(); assert_eq!( query_res, GetDateTimeResponse { @@ -23,7 +23,7 @@ fn test_query_date_time() { // UTC-9 - let query_res = query_date_time(deps.as_ref(), Timezone::UtcMinus9).unwrap(); + let query_res = query_date_time(deps.as_ref(), Some(Timezone::UtcMinus9)).unwrap(); assert_eq!( query_res, GetDateTimeResponse { @@ -32,7 +32,7 @@ fn test_query_date_time() { }); // UTC - let query_res = query_date_time(deps.as_ref(), Timezone::Utc).unwrap(); + let query_res = query_date_time(deps.as_ref(), None).unwrap(); assert_eq!( query_res, GetDateTimeResponse { @@ -41,7 +41,7 @@ fn test_query_date_time() { }); // UTC+14 - let query_res = query_date_time(deps.as_ref(), Timezone::UtcPlus14).unwrap(); + let query_res = query_date_time(deps.as_ref(), Some(Timezone::UtcPlus14)).unwrap(); assert_eq!( query_res, GetDateTimeResponse { diff --git a/packages/andromeda-modules/src/date_time.rs b/packages/andromeda-modules/src/date_time.rs index 09389d2e9..17fc7bf1e 100644 --- a/packages/andromeda-modules/src/date_time.rs +++ b/packages/andromeda-modules/src/date_time.rs @@ -17,7 +17,7 @@ pub enum ExecuteMsg {} pub enum QueryMsg { #[returns(GetDateTimeResponse)] GetDateTime { - timezone: Timezone, + timezone: Option, }, } From d0f974e43181f9c85a37884f7d7fce546f268527 Mon Sep 17 00:00:00 2001 From: mdjakovic0920 Date: Mon, 5 Aug 2024 14:33:41 +0000 Subject: [PATCH 3/9] fix: checked fmt --- .../andromeda-date-time/examples/schema.rs | 2 +- .../andromeda-date-time/src/contract.rs | 19 ++++++------- .../modules/andromeda-date-time/src/lib.rs | 2 +- .../modules/andromeda-date-time/src/mock.rs | 2 +- .../andromeda-date-time/src/testing/mock.rs | 7 +++-- .../andromeda-date-time/src/testing/mod.rs | 2 +- .../andromeda-date-time/src/testing/tests.rs | 27 ++++++++++--------- packages/andromeda-modules/src/date_time.rs | 8 ++---- packages/andromeda-modules/src/lib.rs | 2 +- 9 files changed, 34 insertions(+), 37 deletions(-) diff --git a/contracts/modules/andromeda-date-time/examples/schema.rs b/contracts/modules/andromeda-date-time/examples/schema.rs index 4dd91526e..ce974bc45 100644 --- a/contracts/modules/andromeda-date-time/examples/schema.rs +++ b/contracts/modules/andromeda-date-time/examples/schema.rs @@ -7,4 +7,4 @@ fn main() { execute: ExecuteMsg, } -} \ No newline at end of file +} diff --git a/contracts/modules/andromeda-date-time/src/contract.rs b/contracts/modules/andromeda-date-time/src/contract.rs index 8840d0f45..65d66db74 100644 --- a/contracts/modules/andromeda-date-time/src/contract.rs +++ b/contracts/modules/andromeda-date-time/src/contract.rs @@ -2,18 +2,15 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response}; -use andromeda_modules::date_time::{ExecuteMsg, InstantiateMsg, QueryMsg, Timezone}; use andromeda_modules::date_time::GetDateTimeResponse; +use andromeda_modules::date_time::{ExecuteMsg, InstantiateMsg, QueryMsg, Timezone}; use andromeda_std::{ ado_base::{InstantiateMsg as BaseInstantiateMsg, MigrateMsg}, ado_contract::ADOContract, - common::{ - context::ExecuteContext, encode_binary, - actions::call_action, - }, + common::{actions::call_action, context::ExecuteContext, encode_binary}, error::ContractError, }; -use chrono::{DateTime, Timelike, Weekday, Datelike}; +use chrono::{DateTime, Datelike, Timelike, Weekday}; // version info for migration info const CONTRACT_NAME: &str = "crates.io:andromeda-date-time"; @@ -54,13 +51,13 @@ pub fn execute( match msg { ExecuteMsg::AMPReceive(pkt) => { ADOContract::default().execute_amp_receive(ctx, pkt, handle_execute) - }, + } _ => handle_execute(ctx, msg), } } +#[allow(clippy::match_single_binding)] fn handle_execute(mut ctx: ExecuteContext, msg: ExecuteMsg) -> Result { - let action_response = call_action( &mut ctx.deps, &ctx.info, @@ -108,9 +105,9 @@ pub fn get_date_time( }; let date_time = format!( - "{:04}-{:02}-{:02} {:02}-{:02}-{:02}", - local_datetime.year(), - local_datetime.month(), + "{:04}-{:02}-{:02} {:02}-{:02}-{:02}", + local_datetime.year(), + local_datetime.month(), local_datetime.day(), local_datetime.hour(), local_datetime.minute(), diff --git a/contracts/modules/andromeda-date-time/src/lib.rs b/contracts/modules/andromeda-date-time/src/lib.rs index 3a3593725..b0b35c28c 100644 --- a/contracts/modules/andromeda-date-time/src/lib.rs +++ b/contracts/modules/andromeda-date-time/src/lib.rs @@ -3,4 +3,4 @@ pub mod contract; pub mod testing; #[cfg(all(not(target_arch = "wasm32"), feature = "testing"))] -pub mod mock; \ No newline at end of file +pub mod mock; diff --git a/contracts/modules/andromeda-date-time/src/mock.rs b/contracts/modules/andromeda-date-time/src/mock.rs index 173f4504c..46b6b2419 100644 --- a/contracts/modules/andromeda-date-time/src/mock.rs +++ b/contracts/modules/andromeda-date-time/src/mock.rs @@ -1,7 +1,7 @@ #![cfg(all(not(target_arch = "wasm32"), feature = "testing"))] use crate::contract::{execute, instantiate, query}; -use andromeda_modules::date_time::{InstantiateMsg, QueryMsg, Timezone}; use andromeda_modules::date_time::GetDateTimeResponse; +use andromeda_modules::date_time::{InstantiateMsg, QueryMsg, Timezone}; use andromeda_testing::mock::MockApp; use andromeda_testing::{ mock_ado, diff --git a/contracts/modules/andromeda-date-time/src/testing/mock.rs b/contracts/modules/andromeda-date-time/src/testing/mock.rs index d4908f7fc..f51556bb0 100644 --- a/contracts/modules/andromeda-date-time/src/testing/mock.rs +++ b/contracts/modules/andromeda-date-time/src/testing/mock.rs @@ -1,5 +1,5 @@ -use andromeda_modules::date_time::{InstantiateMsg, QueryMsg}; use andromeda_modules::date_time::{GetDateTimeResponse, Timezone}; +use andromeda_modules::date_time::{InstantiateMsg, QueryMsg}; use andromeda_std::{ error::ContractError, testing::mock_querier::{mock_dependencies_custom, WasmMockQuerier, MOCK_KERNEL_CONTRACT}, @@ -27,7 +27,10 @@ pub fn proper_initialization() -> (MockDeps, MessageInfo) { (deps, info) } -pub fn query_date_time(deps: Deps, timezone: Option) -> Result { +pub fn query_date_time( + deps: Deps, + timezone: Option, +) -> Result { let res = query(deps, mock_env(), QueryMsg::GetDateTime { timezone }); match res { Ok(res) => Ok(from_json(res).unwrap()), diff --git a/contracts/modules/andromeda-date-time/src/testing/mod.rs b/contracts/modules/andromeda-date-time/src/testing/mod.rs index aea717dc8..3bfda2893 100644 --- a/contracts/modules/andromeda-date-time/src/testing/mod.rs +++ b/contracts/modules/andromeda-date-time/src/testing/mod.rs @@ -1,2 +1,2 @@ mod mock; -mod tests; \ No newline at end of file +mod tests; diff --git a/contracts/modules/andromeda-date-time/src/testing/tests.rs b/contracts/modules/andromeda-date-time/src/testing/tests.rs index 08bb7f41b..27e52611e 100644 --- a/contracts/modules/andromeda-date-time/src/testing/tests.rs +++ b/contracts/modules/andromeda-date-time/src/testing/tests.rs @@ -1,7 +1,5 @@ -use super::mock::{ - proper_initialization, query_date_time, -}; -use andromeda_modules::date_time::{Timezone, GetDateTimeResponse}; +use super::mock::{proper_initialization, query_date_time}; +use andromeda_modules::date_time::{GetDateTimeResponse, Timezone}; #[test] fn test_instantiation() { @@ -15,37 +13,40 @@ fn test_query_date_time() { // UTC+3 let query_res = query_date_time(deps.as_ref(), Some(Timezone::UtcPlus3)).unwrap(); assert_eq!( - query_res, + query_res, GetDateTimeResponse { day_of_week: "Wed".to_string(), date_time: "2019-10-23 05-23-39".to_string(), - }); - + } + ); // UTC-9 let query_res = query_date_time(deps.as_ref(), Some(Timezone::UtcMinus9)).unwrap(); assert_eq!( - query_res, + query_res, GetDateTimeResponse { day_of_week: "Tue".to_string(), date_time: "2019-10-22 17-23-39".to_string(), - }); + } + ); // UTC let query_res = query_date_time(deps.as_ref(), None).unwrap(); assert_eq!( - query_res, + query_res, GetDateTimeResponse { day_of_week: "Wed".to_string(), date_time: "2019-10-23 02-23-39".to_string(), - }); + } + ); // UTC+14 let query_res = query_date_time(deps.as_ref(), Some(Timezone::UtcPlus14)).unwrap(); assert_eq!( - query_res, + query_res, GetDateTimeResponse { day_of_week: "Wed".to_string(), date_time: "2019-10-23 16-23-39".to_string(), - }); + } + ); } diff --git a/packages/andromeda-modules/src/date_time.rs b/packages/andromeda-modules/src/date_time.rs index 17fc7bf1e..d49f40f6f 100644 --- a/packages/andromeda-modules/src/date_time.rs +++ b/packages/andromeda-modules/src/date_time.rs @@ -1,6 +1,4 @@ -use andromeda_std::{ - andr_exec, andr_instantiate, andr_query, -}; +use andromeda_std::{andr_exec, andr_instantiate, andr_query}; use cosmwasm_schema::{cw_serde, QueryResponses}; #[andr_instantiate] @@ -16,9 +14,7 @@ pub enum ExecuteMsg {} #[derive(QueryResponses)] pub enum QueryMsg { #[returns(GetDateTimeResponse)] - GetDateTime { - timezone: Option, - }, + GetDateTime { timezone: Option }, } #[cw_serde] diff --git a/packages/andromeda-modules/src/lib.rs b/packages/andromeda-modules/src/lib.rs index 4996984d2..becf45359 100644 --- a/packages/andromeda-modules/src/lib.rs +++ b/packages/andromeda-modules/src/lib.rs @@ -1,4 +1,4 @@ pub mod address_list; +pub mod date_time; pub mod rates; pub mod shunting; -pub mod date_time; From 7c5eb5eae6b20c25e3774eafc54acb9155f575b3 Mon Sep 17 00:00:00 2001 From: mdjakovic0920 Date: Mon, 5 Aug 2024 14:37:15 +0000 Subject: [PATCH 4/9] feat: added log to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 691b5fe16..99830c676 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added Expiry Enum [(#419)](https://github.com/andromedaprotocol/andromeda-core/pull/419) - Added Conditional Splitter [(#441)](https://github.com/andromedaprotocol/andromeda-core/pull/441) - Validator Staking: Added the option to set an amount while unstaking [(#458)](https://github.com/andromedaprotocol/andromeda-core/pull/458) +- Added Date Time ADO [(#519)](https://github.com/andromedaprotocol/andromeda-core/pull/519) ### Changed From 9de45bd1d780d52ae143e5d6aa36923b05be0703 Mon Sep 17 00:00:00 2001 From: mdjakovic0920 Date: Mon, 5 Aug 2024 14:50:54 +0000 Subject: [PATCH 5/9] fix: improved err handling --- .../andromeda-date-time/src/contract.rs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/contracts/modules/andromeda-date-time/src/contract.rs b/contracts/modules/andromeda-date-time/src/contract.rs index 65d66db74..c7eebe24e 100644 --- a/contracts/modules/andromeda-date-time/src/contract.rs +++ b/contracts/modules/andromeda-date-time/src/contract.rs @@ -1,6 +1,6 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response}; +use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError}; use andromeda_modules::date_time::GetDateTimeResponse; use andromeda_modules::date_time::{ExecuteMsg, InstantiateMsg, QueryMsg, Timezone}; @@ -90,9 +90,22 @@ pub fn get_date_time( ) -> Result { let timestamp = env.block.time.seconds() as i64; let timezone_i64 = timezone.unwrap_or(Timezone::Utc) as i64; - let offset = timezone_i64.checked_mul(3600).unwrap(); - let local_timestamp = timestamp.checked_add(offset).unwrap(); - let local_datetime = DateTime::from_timestamp(local_timestamp, 0).unwrap(); + let offset = match timezone_i64.checked_mul(3600) { + Some(offset) => offset, + None => return Err(ContractError::Std(StdError::generic_err("Overflow error"))), + }; + let local_timestamp = match timestamp.checked_add(offset) { + Some(local_timestamp) => local_timestamp, + None => return Err(ContractError::Std(StdError::generic_err("Overflow error"))), + }; + let local_datetime = match DateTime::from_timestamp(local_timestamp, 0) { + Some(local_datetime) => local_datetime, + None => { + return Err(ContractError::Std(StdError::generic_err( + "Timestamp conversion error", + ))) + } + }; let day_of_week = match local_datetime.weekday() { Weekday::Mon => "Mon", From 844b40e9f6e19c0897eb9a37ebf1ccbe88440c60 Mon Sep 17 00:00:00 2001 From: mdjakovic0920 Date: Tue, 27 Aug 2024 19:37:20 +0000 Subject: [PATCH 6/9] feat: added half and quarter hour time zones --- .../andromeda-date-time/src/contract.rs | 2 +- .../andromeda-date-time/src/testing/tests.rs | 30 +++++++++ packages/andromeda-modules/src/date_time.rs | 63 +++++++++++-------- 3 files changed, 68 insertions(+), 27 deletions(-) diff --git a/contracts/modules/andromeda-date-time/src/contract.rs b/contracts/modules/andromeda-date-time/src/contract.rs index c7eebe24e..807940cdb 100644 --- a/contracts/modules/andromeda-date-time/src/contract.rs +++ b/contracts/modules/andromeda-date-time/src/contract.rs @@ -90,7 +90,7 @@ pub fn get_date_time( ) -> Result { let timestamp = env.block.time.seconds() as i64; let timezone_i64 = timezone.unwrap_or(Timezone::Utc) as i64; - let offset = match timezone_i64.checked_mul(3600) { + let offset = match timezone_i64.checked_mul(36) { Some(offset) => offset, None => return Err(ContractError::Std(StdError::generic_err("Overflow error"))), }; diff --git a/contracts/modules/andromeda-date-time/src/testing/tests.rs b/contracts/modules/andromeda-date-time/src/testing/tests.rs index 27e52611e..5fab309e7 100644 --- a/contracts/modules/andromeda-date-time/src/testing/tests.rs +++ b/contracts/modules/andromeda-date-time/src/testing/tests.rs @@ -30,6 +30,16 @@ fn test_query_date_time() { } ); + // UTC-2:30 + let query_res = query_date_time(deps.as_ref(), Some(Timezone::UtcMinus2_30)).unwrap(); + assert_eq!( + query_res, + GetDateTimeResponse { + day_of_week: "Tue".to_string(), + date_time: "2019-10-22 23-53-39".to_string(), + } + ); + // UTC let query_res = query_date_time(deps.as_ref(), None).unwrap(); assert_eq!( @@ -40,6 +50,26 @@ fn test_query_date_time() { } ); + // UTC+10:30 + let query_res = query_date_time(deps.as_ref(), Some(Timezone::UtcPlus10_30)).unwrap(); + assert_eq!( + query_res, + GetDateTimeResponse { + day_of_week: "Wed".to_string(), + date_time: "2019-10-23 12-53-39".to_string(), + } + ); + + // UTC+12:45 + let query_res = query_date_time(deps.as_ref(), Some(Timezone::UtcPlus12_45)).unwrap(); + assert_eq!( + query_res, + GetDateTimeResponse { + day_of_week: "Wed".to_string(), + date_time: "2019-10-23 15-08-39".to_string(), + } + ); + // UTC+14 let query_res = query_date_time(deps.as_ref(), Some(Timezone::UtcPlus14)).unwrap(); assert_eq!( diff --git a/packages/andromeda-modules/src/date_time.rs b/packages/andromeda-modules/src/date_time.rs index d49f40f6f..89ded88b1 100644 --- a/packages/andromeda-modules/src/date_time.rs +++ b/packages/andromeda-modules/src/date_time.rs @@ -25,31 +25,42 @@ pub struct GetDateTimeResponse { #[cw_serde] pub enum Timezone { - UtcMinus12 = -12, - UtcMinus11 = -11, - UtcMinus10 = -10, - UtcMinus9 = -9, - UtcMinus8 = -8, - UtcMinus7 = -7, - UtcMinus6 = -6, - UtcMinus5 = -5, - UtcMinus4 = -4, - UtcMinus3 = -3, - UtcMinus2 = -2, - UtcMinus1 = -1, + UtcMinus12 = -1200, + UtcMinus11 = -1100, + UtcMinus10 = -1000, + UtcMinus9_30 = -950, + UtcMinus9 = -900, + UtcMinus8 = -800, + UtcMinus7 = -700, + UtcMinus6 = -600, + UtcMinus5 = -500, + UtcMinus4 = -400, + UtcMinus3 = -300, + UtcMinus2_30 = -250, + UtcMinus2 = -200, + UtcMinus1 = -100, Utc = 0, - UtcPlus1 = 1, - UtcPlus2 = 2, - UtcPlus3 = 3, - UtcPlus4 = 4, - UtcPlus5 = 5, - UtcPlus6 = 6, - UtcPlus7 = 7, - UtcPlus8 = 8, - UtcPlus9 = 9, - UtcPlus10 = 10, - UtcPlus11 = 11, - UtcPlus12 = 12, - UtcPlus13 = 13, - UtcPlus14 = 14, + UtcPlus1 = 100, + UtcPlus2 = 200, + UtcPlus3 = 300, + UtcPlus3_30 = 350, + UtcPlus4 = 400, + UtcPlus4_30 = 450, + UtcPlus5 = 500, + UtcPlus5_45 = 575, + UtcPlus5_30 = 550, + UtcPlus6 = 600, + UtcPlus6_30 = 650, + UtcPlus7 = 700, + UtcPlus8 = 800, + UtcPlus8_45 = 875, + UtcPlus9 = 900, + UtcPlus9_30 = 950, + UtcPlus10 = 1000, + UtcPlus10_30 = 1050, + UtcPlus11 = 1100, + UtcPlus12 = 1200, + UtcPlus12_45 = 1275, + UtcPlus13 = 1300, + UtcPlus14 = 1400, } From 1b64b05ecaf18f7222db7eaac917333316feff1c Mon Sep 17 00:00:00 2001 From: mdjakovic0920 Date: Tue, 27 Aug 2024 19:47:58 +0000 Subject: [PATCH 7/9] changed CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99830c676..79911b14e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added Expiry Enum [(#419)](https://github.com/andromedaprotocol/andromeda-core/pull/419) - Added Conditional Splitter [(#441)](https://github.com/andromedaprotocol/andromeda-core/pull/441) - Validator Staking: Added the option to set an amount while unstaking [(#458)](https://github.com/andromedaprotocol/andromeda-core/pull/458) +- Added String Storage ADO [(#512)](https://github.com/andromedaprotocol/andromeda-core/pull/512) +- Added Counter ADO [(#514)](https://github.com/andromedaprotocol/andromeda-core/pull/514) - Added Date Time ADO [(#519)](https://github.com/andromedaprotocol/andromeda-core/pull/519) ### Changed @@ -30,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Crowdfund Internal Audit [(#485)](https://github.com/andromedaprotocol/andromeda-core/pull/485) - Auction: Minimum Raise [(#486)](https://github.com/andromedaprotocol/andromeda-core/pull/486) - Version Bump [(#488)](https://github.com/andromedaprotocol/andromeda-core/pull/488) +- Made Some CampaignConfig Fields Optional [(#541)](https://github.com/andromedaprotocol/andromeda-core/pull/541) ### Fixed From d54eced2806c855a96ae7d72d1281de3dd1098e8 Mon Sep 17 00:00:00 2001 From: mdjakovic0920 Date: Mon, 2 Sep 2024 15:16:56 +0000 Subject: [PATCH 8/9] fix: removed unexpected file --- DEADJOE | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 DEADJOE diff --git a/DEADJOE b/DEADJOE deleted file mode 100644 index d750520bb..000000000 --- a/DEADJOE +++ /dev/null @@ -1,20 +0,0 @@ - -*** These modified files were found in JOE when it aborted on Tue Aug 27 19:41:17 2024 -*** JOE was aborted by UNIX signal 1 - -*** File '(Unnamed)' -/home/paperspace/WorkSpace/rust/perf/andromeda-date-time/.git/MERGE_MSG - -*** File '/home/paperspace/WorkSpace/rust/perf/andromeda-date-time/.git/MERGE_MSG' -Merge branch 'mdjakovic/date-time' of https://github.com/mdjakovic0920/andromeda-core into mdjakovic/date-time -# Please enter a commit message to explain why this merge is necessary, -# especially if it merges an updated upstream into a topic branch. -# -# Lines starting with '#' will be ignored, and an empty message aborts -# the commit. - -*** File '* Startup Log *' -Processing '/etc/joe/editorrc'... -Processing '/etc/joe/ftyperc'... -Finished processing /etc/joe/ftyperc -Finished processing /etc/joe/editorrc From b75b849299a9fae3a5dfb2b7e8abe8a57e3d2c75 Mon Sep 17 00:00:00 2001 From: mdjakovic0920 Date: Mon, 2 Sep 2024 15:32:26 +0000 Subject: [PATCH 9/9] fix: simplify overflow check --- .../modules/andromeda-date-time/Cargo.toml | 2 +- .../andromeda-date-time/src/contract.rs | 21 ++++--------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/contracts/modules/andromeda-date-time/Cargo.toml b/contracts/modules/andromeda-date-time/Cargo.toml index c50ddb216..ff548c5d3 100644 --- a/contracts/modules/andromeda-date-time/Cargo.toml +++ b/contracts/modules/andromeda-date-time/Cargo.toml @@ -21,7 +21,7 @@ cosmwasm-schema = { workspace = true } cw-storage-plus = { workspace = true } cw-utils = { workspace = true } -andromeda-std = { workspace = true, features = [] } +andromeda-std = { workspace = true } andromeda-modules = { workspace = true } chrono = "0.4.38" diff --git a/contracts/modules/andromeda-date-time/src/contract.rs b/contracts/modules/andromeda-date-time/src/contract.rs index 807940cdb..ed31698dc 100644 --- a/contracts/modules/andromeda-date-time/src/contract.rs +++ b/contracts/modules/andromeda-date-time/src/contract.rs @@ -1,6 +1,6 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError}; +use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response}; use andromeda_modules::date_time::GetDateTimeResponse; use andromeda_modules::date_time::{ExecuteMsg, InstantiateMsg, QueryMsg, Timezone}; @@ -90,22 +90,9 @@ pub fn get_date_time( ) -> Result { let timestamp = env.block.time.seconds() as i64; let timezone_i64 = timezone.unwrap_or(Timezone::Utc) as i64; - let offset = match timezone_i64.checked_mul(36) { - Some(offset) => offset, - None => return Err(ContractError::Std(StdError::generic_err("Overflow error"))), - }; - let local_timestamp = match timestamp.checked_add(offset) { - Some(local_timestamp) => local_timestamp, - None => return Err(ContractError::Std(StdError::generic_err("Overflow error"))), - }; - let local_datetime = match DateTime::from_timestamp(local_timestamp, 0) { - Some(local_datetime) => local_datetime, - None => { - return Err(ContractError::Std(StdError::generic_err( - "Timestamp conversion error", - ))) - } - }; + let offset = timezone_i64.checked_mul(36).unwrap(); + let local_timestamp = timestamp.checked_add(offset).unwrap(); + let local_datetime = DateTime::from_timestamp(local_timestamp, 0).unwrap(); let day_of_week = match local_datetime.weekday() { Weekday::Mon => "Mon",