From ebcebad4e08239c11a7762fea3da2f2d05ce1463 Mon Sep 17 00:00:00 2001 From: "Bob(xsb.near)" <389483673@qq.com> Date: Mon, 9 Sep 2024 19:42:15 +0800 Subject: [PATCH] Move the POC of cosmwasm to a separate repository (#126) --- canister_ids.json | 3 - customs/icp/src/lib.rs | 4 +- customs/icp/src/updates/generate_ticket.rs | 4 +- dfx.json | 12 - route/cosmwasm/Cargo.lock | 2168 ----------------- route/cosmwasm/Cargo.toml | 56 - route/cosmwasm/cosmwasm_route.did | 103 - route/cosmwasm/src/business.rs | 4 - route/cosmwasm/src/business/mint_token.rs | 13 - .../src/business/process_directive.rs | 85 - route/cosmwasm/src/business/redeem_token.rs | 103 - route/cosmwasm/src/business/ticket_task.rs | 98 - route/cosmwasm/src/cosmwasm.rs | 5 - route/cosmwasm/src/cosmwasm/client.rs | 363 --- route/cosmwasm/src/cosmwasm/port.rs | 398 --- route/cosmwasm/src/cosmwasm/rpc/mod.rs | 5 - route/cosmwasm/src/cosmwasm/rpc/response.rs | 34 - .../src/cosmwasm/rpc/response_error.rs | 208 -- route/cosmwasm/src/cosmwasm/rpc/tx.rs | 40 - route/cosmwasm/src/cosmwasm/rpc/version.rs | 56 - route/cosmwasm/src/cosmwasm/rpc/wrapper.rs | 61 - route/cosmwasm/src/error.rs | 32 - route/cosmwasm/src/guard.rs | 25 - route/cosmwasm/src/hub.rs | 102 - route/cosmwasm/src/lib.rs | 70 - route/cosmwasm/src/lifecycle.rs | 2 - route/cosmwasm/src/lifecycle/init.rs | 23 - route/cosmwasm/src/lifecycle/upgrade.rs | 2 - route/cosmwasm/src/memory.rs | 189 -- route/cosmwasm/src/periodic_jobs.rs | 49 - route/cosmwasm/src/service.rs | 172 -- route/cosmwasm/src/state.rs | 77 - route/cosmwasm/src/utils.rs | 132 - route/cosmwasm/tests/pocket.rs | 211 -- route/cosmwasm/tests/tests.rs | 134 - 35 files changed, 5 insertions(+), 5038 deletions(-) delete mode 100644 route/cosmwasm/Cargo.lock delete mode 100644 route/cosmwasm/Cargo.toml delete mode 100644 route/cosmwasm/cosmwasm_route.did delete mode 100644 route/cosmwasm/src/business.rs delete mode 100644 route/cosmwasm/src/business/mint_token.rs delete mode 100644 route/cosmwasm/src/business/process_directive.rs delete mode 100644 route/cosmwasm/src/business/redeem_token.rs delete mode 100644 route/cosmwasm/src/business/ticket_task.rs delete mode 100644 route/cosmwasm/src/cosmwasm.rs delete mode 100644 route/cosmwasm/src/cosmwasm/client.rs delete mode 100644 route/cosmwasm/src/cosmwasm/port.rs delete mode 100644 route/cosmwasm/src/cosmwasm/rpc/mod.rs delete mode 100644 route/cosmwasm/src/cosmwasm/rpc/response.rs delete mode 100644 route/cosmwasm/src/cosmwasm/rpc/response_error.rs delete mode 100644 route/cosmwasm/src/cosmwasm/rpc/tx.rs delete mode 100644 route/cosmwasm/src/cosmwasm/rpc/version.rs delete mode 100644 route/cosmwasm/src/cosmwasm/rpc/wrapper.rs delete mode 100644 route/cosmwasm/src/error.rs delete mode 100644 route/cosmwasm/src/guard.rs delete mode 100644 route/cosmwasm/src/hub.rs delete mode 100644 route/cosmwasm/src/lib.rs delete mode 100644 route/cosmwasm/src/lifecycle.rs delete mode 100644 route/cosmwasm/src/lifecycle/init.rs delete mode 100644 route/cosmwasm/src/lifecycle/upgrade.rs delete mode 100644 route/cosmwasm/src/memory.rs delete mode 100644 route/cosmwasm/src/periodic_jobs.rs delete mode 100644 route/cosmwasm/src/service.rs delete mode 100644 route/cosmwasm/src/state.rs delete mode 100644 route/cosmwasm/src/utils.rs delete mode 100644 route/cosmwasm/tests/pocket.rs delete mode 100644 route/cosmwasm/tests/tests.rs diff --git a/canister_ids.json b/canister_ids.json index dc03247f..1b1480a0 100644 --- a/canister_ids.json +++ b/canister_ids.json @@ -14,9 +14,6 @@ "cosmwasm_proxy": { "ic": "ncfbq-kyaaa-aaaar-qah3a-cai" }, - "cosmwasm_route_osmosis_testnet": { - "ic": "nfehe-haaaa-aaaar-qah3q-cai" - }, "icp_customs": { "ic": "nlgkm-4qaaa-aaaar-qah2q-cai" }, diff --git a/customs/icp/src/lib.rs b/customs/icp/src/lib.rs index bed58214..812619bf 100644 --- a/customs/icp/src/lib.rs +++ b/customs/icp/src/lib.rs @@ -92,8 +92,8 @@ async fn process_tickets() { Ok(tickets) => { for (seq, ticket) in &tickets { match handle_redeem_ticket(ticket).await { - Ok(_) => { - log!(P0, "[process tickets] process successful for ticket{}", ticket); + Ok(block_index) => { + log!(P0, "[process tickets] process successful for ticket{}, block_index: {}", ticket, block_index); mutate_state(|s| s.next_ticket_seq = seq+1) }, Err(e) => { diff --git a/customs/icp/src/updates/generate_ticket.rs b/customs/icp/src/updates/generate_ticket.rs index 2541006a..a9be2340 100644 --- a/customs/icp/src/updates/generate_ticket.rs +++ b/customs/icp/src/updates/generate_ticket.rs @@ -6,8 +6,9 @@ use icrc_ledger_types::{ }; use ic_ledger_types::{AccountIdentifier, Subaccount as IcSubaccount, Tokens, DEFAULT_SUBACCOUNT, MAINNET_LEDGER_CANISTER_ID}; use num_traits::cast::ToPrimitive; -use omnity_types::{Ticket, TxAction}; +use omnity_types::{ic_log::P0, Ticket, TxAction}; use serde::Serialize; +use ic_canister_log::log; use crate::{hub, state::{get_counterparty, get_token_principal, is_icp, read_state}, utils::convert_u128_u64, ICP_TRANSFER_FEE}; @@ -94,6 +95,7 @@ pub async fn generate_ticket( ) .await .map_err(|err| GenerateTicketError::SendTicketErr(format!("{}", err)))?; + log!(P0, "Success to generate ticket: {}", ticket_id); Ok(GenerateTicketOk { ticket_id }) } diff --git a/dfx.json b/dfx.json index bf76fcba..5388941a 100644 --- a/dfx.json +++ b/dfx.json @@ -70,18 +70,6 @@ } ] }, - "cosmwasm_route_osmosis_testnet": { - "gzip": true, - "candid": "route/cosmwasm/cosmwasm_route.did", - "wasm": "route/cosmwasm/target/wasm32-unknown-unknown/release/cosmwasm_route.wasm", - "package": "cosmwasm_route", - "type": "custom", - "metadata": [ - { - "name": "candid:service" - } - ] - }, "cosmwasm_proxy": { "gzip": true, "candid": "proxy/cosmwasm/cosmwasm_proxy.did", diff --git a/route/cosmwasm/Cargo.lock b/route/cosmwasm/Cargo.lock deleted file mode 100644 index 798f1f4c..00000000 --- a/route/cosmwasm/Cargo.lock +++ /dev/null @@ -1,2168 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -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 = "anyhow" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" - -[[package]] -name = "arc-swap" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" - -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "base16ct" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" - -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - -[[package]] -name = "binread" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16598dfc8e6578e9b597d9910ba2e73618385dc9f4b1d43dd92c349d6be6418f" -dependencies = [ - "binread_derive", - "lazy_static", - "rustversion", -] - -[[package]] -name = "binread_derive" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d9672209df1714ee804b1f4d4f68c8eb2a90b1f7a07acf472f88ce198ef1fed" -dependencies = [ - "either", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "bip32" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa13fae8b6255872fd86f7faf4b41168661d7d78609f7bfe6771b85c6739a15b" -dependencies = [ - "bs58", - "hmac", - "k256 0.13.3", - "rand_core", - "ripemd", - "sha2 0.10.8", - "subtle", - "zeroize", -] - -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bs58" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" -dependencies = [ - "sha2 0.10.8", -] - -[[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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "bytes" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" -dependencies = [ - "serde", -] - -[[package]] -name = "candid" -version = "0.10.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c30ee7f886f296b6422c0ff017e89dd4f831521dfdcc76f3f71aae1ce817222" -dependencies = [ - "anyhow", - "binread", - "byteorder", - "candid_derive", - "hex", - "ic_principal", - "leb128", - "num-bigint", - "num-traits", - "paste", - "pretty", - "serde", - "serde_bytes", - "stacker", - "thiserror", -] - -[[package]] -name = "candid_derive" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3de398570c386726e7a59d9887b68763c481477f9a043fb998a2e09d428df1a9" -dependencies = [ - "lazy_static", - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "cc" -version = "1.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48" -dependencies = [ - "shlex", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[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", - "num-traits", - "serde", - "windows-targets", -] - -[[package]] -name = "ciborium" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" -dependencies = [ - "ciborium-io", - "ciborium-ll", - "serde", -] - -[[package]] -name = "ciborium-io" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" - -[[package]] -name = "ciborium-ll" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" -dependencies = [ - "ciborium-io", - "half 2.4.1", -] - -[[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.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - -[[package]] -name = "cosmos-sdk-proto" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d1a42d9ef55bb4e84b48ce29860f55859e52e0088ebdb1371cedd62f2b78cc" -dependencies = [ - "prost", - "prost-types", - "tendermint-proto", -] - -[[package]] -name = "cosmrs" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85efbd5a3487e52ccd77897ef8f97b077a015953b46623fabc939f39d9c501fc" -dependencies = [ - "bip32", - "cosmos-sdk-proto", - "ecdsa 0.16.9", - "eyre", - "k256 0.13.3", - "rand_core", - "serde", - "serde_json", - "signature", - "subtle-encoding", - "tendermint", - "thiserror", -] - -[[package]] -name = "cosmwasm-schema" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bc0d4d85e83438ab9a0fea9348446f7268bc016aacfebce37e998559f151294" -dependencies = [ - "cosmwasm-schema-derive", - "schemars", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "cosmwasm-schema-derive" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edf5c8adac41bb7751c050d7c4c18675be19ee128714454454575e894424eeef" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "cosmwasm_route" -version = "0.1.9" -dependencies = [ - "anyhow", - "base64", - "candid", - "ciborium", - "cosmrs", - "cosmwasm-schema", - "flate2", - "futures", - "hex", - "ic-canisters-http-types", - "ic-cdk 0.12.2", - "ic-cdk-macros 0.8.4", - "ic-cdk-timers 0.7.0", - "ic-log", - "ic-stable-structures", - "ic0 0.18.11", - "itertools 0.13.0", - "log", - "num-traits", - "omnity_types", - "rand", - "serde", - "serde_bytes", - "serde_cbor", - "serde_json", - "sha2 0.10.8", - "thiserror", - "uuid", -] - -[[package]] -name = "cpufeatures" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" -dependencies = [ - "libc", -] - -[[package]] -name = "crc32fast" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - -[[package]] -name = "crypto-bigint" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "curve25519-dalek-ng" -version = "4.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c359b7249347e46fb28804470d071c921156ad62b3eef5d34e2ba867533dec8" -dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core", - "subtle-ng", - "zeroize", -] - -[[package]] -name = "darling" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 2.0.75", -] - -[[package]] -name = "darling_macro" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" -dependencies = [ - "darling_core", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "data-encoding" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" - -[[package]] -name = "der" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" -dependencies = [ - "const-oid", - "zeroize", -] - -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - -[[package]] -name = "deranged" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" -dependencies = [ - "powerfmt", - "serde", -] - -[[package]] -name = "derive_more" -version = "0.99.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer 0.10.4", - "const-oid", - "crypto-common", - "subtle", -] - -[[package]] -name = "dyn-clone" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" - -[[package]] -name = "ecdsa" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12844141594ad74185a926d030f3b605f6a903b4e3fec351f3ea338ac5b7637e" -dependencies = [ - "der 0.6.1", - "elliptic-curve 0.12.3", - "rfc6979 0.3.1", - "signature", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der 0.7.9", - "digest 0.10.7", - "elliptic-curve 0.13.8", - "rfc6979 0.4.0", - "signature", - "spki 0.7.3", -] - -[[package]] -name = "ed25519" -version = "2.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" -dependencies = [ - "pkcs8 0.10.2", - "signature", -] - -[[package]] -name = "ed25519-consensus" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c8465edc8ee7436ffea81d21a019b16676ee3db267aa8d5a8d729581ecf998b" -dependencies = [ - "curve25519-dalek-ng", - "hex", - "rand_core", - "sha2 0.9.9", - "zeroize", -] - -[[package]] -name = "either" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" - -[[package]] -name = "elliptic-curve" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" -dependencies = [ - "base16ct 0.1.1", - "crypto-bigint 0.4.9", - "der 0.6.1", - "digest 0.10.7", - "ff 0.12.1", - "generic-array", - "group 0.12.1", - "pkcs8 0.9.0", - "rand_core", - "sec1 0.3.0", - "subtle", - "zeroize", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct 0.2.0", - "crypto-bigint 0.5.5", - "digest 0.10.7", - "ff 0.13.0", - "generic-array", - "group 0.13.0", - "pkcs8 0.10.2", - "rand_core", - "sec1 0.7.3", - "subtle", - "zeroize", -] - -[[package]] -name = "env_filter" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6dc8c8ff84895b051f07a0e65f975cf225131742531338752abfb324e4449ff" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "eyre" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" -dependencies = [ - "indenter", - "once_cell", -] - -[[package]] -name = "ff" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" -dependencies = [ - "rand_core", - "subtle", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "rand_core", - "subtle", -] - -[[package]] -name = "flate2" -version = "1.0.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f211bbe8e69bbd0cfdea405084f128ae8b4aaa6b0b522fc8f2b009084797920" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - -[[package]] -name = "flex-error" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c606d892c9de11507fa0dcffc116434f94e105d0bbdc4e405b61519464c49d7b" -dependencies = [ - "paste", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", - "zeroize", -] - -[[package]] -name = "getrandom" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "group" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" -dependencies = [ - "ff 0.12.1", - "rand_core", - "subtle", -] - -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff 0.13.0", - "rand_core", - "subtle", -] - -[[package]] -name = "half" -version = "1.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" - -[[package]] -name = "half" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" -dependencies = [ - "cfg-if", - "crunchy", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest 0.10.7", -] - -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - -[[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 = "ic-canister-log" -version = "0.2.0" -source = "git+https://github.com/dfinity/ic?tag=release-2024-01-18_23-01#a7862784e8da4a97a1d608fd5b3db365de41a2d7" -dependencies = [ - "serde", -] - -[[package]] -name = "ic-canisters-http-types" -version = "0.9.0" -source = "git+https://github.com/dfinity/ic?tag=release-2024-03-06_23-01+p2p#fff20526e154f8b8d24373efd9b50f588d147e91" -dependencies = [ - "candid", - "serde", - "serde_bytes", -] - -[[package]] -name = "ic-cdk" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e908da565d9e304e83732500069ebb959e3d2cad80f894889ea37207112c7a0" -dependencies = [ - "candid", - "ic-cdk-macros 0.8.4", - "ic0 0.21.1", - "serde", - "serde_bytes", -] - -[[package]] -name = "ic-cdk" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b1da6a25b045f9da3c9459c0cb2b0700ac368ee16382975a17185a23b9c18ab" -dependencies = [ - "candid", - "ic-cdk-macros 0.13.2", - "ic0 0.21.1", - "serde", - "serde_bytes", -] - -[[package]] -name = "ic-cdk-macros" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5a618e4020cea88e933d8d2f8c7f86d570ec06213506a80d4f2c520a9bba512" -dependencies = [ - "candid", - "proc-macro2", - "quote", - "serde", - "serde_tokenstream", - "syn 1.0.109", -] - -[[package]] -name = "ic-cdk-macros" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a45800053d80a6df839a71aaea5797e723188c0b992618208ca3b941350c7355" -dependencies = [ - "candid", - "proc-macro2", - "quote", - "serde", - "serde_tokenstream", - "syn 1.0.109", -] - -[[package]] -name = "ic-cdk-timers" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c43b9706fef3ad10c4192a14801d16bd9539068239f0f06f257857441364329" -dependencies = [ - "futures", - "ic-cdk 0.12.2", - "ic0 0.21.1", - "serde", - "serde_bytes", - "slotmap", -] - -[[package]] -name = "ic-cdk-timers" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "054727a3a1c486528b96349817d54290ff70df6addf417def456ea708a16f7fb" -dependencies = [ - "futures", - "ic-cdk 0.13.5", - "ic0 0.21.1", - "serde", - "serde_bytes", - "slotmap", -] - -[[package]] -name = "ic-crypto-getrandom-for-wasm" -version = "0.13.0" -source = "git+https://github.com/octopus-network/canister-sdk.git?branch=v0.12.x-stablelog#ae820df9d166b605b12f1e5f992f09ab892fe145" -dependencies = [ - "getrandom", -] - -[[package]] -name = "ic-exports" -version = "0.13.0" -source = "git+https://github.com/octopus-network/canister-sdk.git?branch=v0.12.x-stablelog#ae820df9d166b605b12f1e5f992f09ab892fe145" -dependencies = [ - "candid", - "ic-cdk 0.12.2", - "ic-cdk-macros 0.8.4", - "ic-cdk-timers 0.6.0", - "ic-crypto-getrandom-for-wasm", - "ic-kit", - "serde", -] - -[[package]] -name = "ic-kit" -version = "0.13.0" -source = "git+https://github.com/octopus-network/canister-sdk.git?branch=v0.12.x-stablelog#ae820df9d166b605b12f1e5f992f09ab892fe145" -dependencies = [ - "candid", - "futures", - "ic-cdk 0.12.2", - "ic-cdk-macros 0.8.4", - "serde", - "serde_bytes", -] - -[[package]] -name = "ic-log" -version = "0.13.0" -source = "git+https://github.com/octopus-network/canister-sdk.git?branch=v0.12.x-stablelog#ae820df9d166b605b12f1e5f992f09ab892fe145" -dependencies = [ - "anyhow", - "arc-swap", - "candid", - "env_filter", - "humantime", - "ic-exports", - "log", - "ringbuffer", - "serde", -] - -[[package]] -name = "ic-stable-structures" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03f3044466a69802de74e710dc0300b706a05696a0531c942ca856751a13b0db" -dependencies = [ - "ic_principal", -] - -[[package]] -name = "ic0" -version = "0.18.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576c539151d4769fb4d1a0c25c4108dd18facd04c5695b02cf2d226ab4e43aa5" - -[[package]] -name = "ic0" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a54b5297861c651551676e8c43df805dad175cc33bc97dbd992edbbb85dcbcdf" - -[[package]] -name = "ic_principal" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1762deb6f7c8d8c2bdee4b6c5a47b60195b74e9b5280faa5ba29692f8e17429c" -dependencies = [ - "crc32fast", - "data-encoding", - "serde", - "sha2 0.10.8", - "thiserror", -] - -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - -[[package]] -name = "indenter" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" - -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", - "serde", -] - -[[package]] -name = "indexmap" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" -dependencies = [ - "equivalent", - "hashbrown 0.14.5", - "serde", -] - -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "js-sys" -version = "0.3.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "k256" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92a55e0ff3b72c262bcf041d9e97f1b84492b68f1c1a384de2323d3dc9403397" -dependencies = [ - "cfg-if", - "ecdsa 0.15.1", - "elliptic-curve 0.12.3", - "once_cell", - "sha2 0.10.8", - "signature", -] - -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa 0.16.9", - "elliptic-curve 0.13.8", - "sha2 0.10.8", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "libc" -version = "0.2.157" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374af5f94e54fa97cf75e945cce8a6b201e88a1a07e688b47dfd2a59c66dbd86" - -[[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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - -[[package]] -name = "num-bigint" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" -dependencies = [ - "num-integer", - "num-traits", - "serde", -] - -[[package]] -name = "num-conv" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] - -[[package]] -name = "omnity_types" -version = "0.1.0" -dependencies = [ - "candid", - "ciborium", - "derive_more", - "env_filter", - "getrandom", - "hex", - "humantime", - "ic-canister-log", - "ic-canisters-http-types", - "ic-cdk 0.12.2", - "ic-log", - "ic-stable-structures", - "k256 0.12.0", - "lazy_static", - "log", - "serde", - "serde_derive", - "serde_json", - "serde_with", - "sha2 0.10.8", - "thiserror", - "time", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "opaque-debug" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" - -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pkcs8" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" -dependencies = [ - "der 0.6.1", - "spki 0.6.0", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der 0.7.9", - "spki 0.7.3", -] - -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "pretty" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b55c4d17d994b637e2f4daf6e5dc5d660d209d5642377d675d7a1c3ab69fa579" -dependencies = [ - "arrayvec", - "typed-arena", - "unicode-width", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "prost" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" -dependencies = [ - "bytes", - "prost-derive", -] - -[[package]] -name = "prost-derive" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" -dependencies = [ - "anyhow", - "itertools 0.12.1", - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "prost-types" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0" -dependencies = [ - "prost", -] - -[[package]] -name = "psm" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" -dependencies = [ - "cc", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "regex" -version = "1.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" - -[[package]] -name = "rfc6979" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" -dependencies = [ - "crypto-bigint 0.4.9", - "hmac", - "zeroize", -] - -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "ringbuffer" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3df6368f71f205ff9c33c076d170dd56ebf68e8161c733c0caa07a7a5509ed53" - -[[package]] -name = "ripemd" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" -dependencies = [ - "digest 0.10.7", -] - -[[package]] -name = "rustversion" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" - -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - -[[package]] -name = "schemars" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" -dependencies = [ - "dyn-clone", - "schemars_derive", - "serde", - "serde_json", -] - -[[package]] -name = "schemars_derive" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" -dependencies = [ - "proc-macro2", - "quote", - "serde_derive_internals", - "syn 2.0.75", -] - -[[package]] -name = "sec1" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" -dependencies = [ - "base16ct 0.1.1", - "der 0.6.1", - "generic-array", - "pkcs8 0.9.0", - "subtle", - "zeroize", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct 0.2.0", - "der 0.7.9", - "generic-array", - "pkcs8 0.10.2", - "subtle", - "zeroize", -] - -[[package]] -name = "serde" -version = "1.0.208" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_bytes" -version = "0.11.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_cbor" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" -dependencies = [ - "half 1.8.3", - "serde", -] - -[[package]] -name = "serde_derive" -version = "1.0.208" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "serde_derive_internals" -version = "0.29.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "serde_json" -version = "1.0.125" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - -[[package]] -name = "serde_repr" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "serde_tokenstream" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "797ba1d80299b264f3aac68ab5d12e5825a561749db4df7cd7c8083900c5d4e9" -dependencies = [ - "proc-macro2", - "serde", - "syn 1.0.109", -] - -[[package]] -name = "serde_with" -version = "3.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cecfa94848272156ea67b2b1a53f20fc7bc638c4a46d2f8abde08f05f4b857" -dependencies = [ - "base64", - "chrono", - "hex", - "indexmap 1.9.3", - "indexmap 2.4.0", - "serde", - "serde_derive", - "serde_json", - "serde_with_macros", - "time", -] - -[[package]] -name = "serde_with_macros" -version = "3.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8fee4991ef4f274617a51ad4af30519438dacb2f56ac773b08a1922ff743350" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.7", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "signature" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fe458c98333f9c8152221191a77e2a44e8325d0193484af2e9421a53019e57d" -dependencies = [ - "digest 0.10.7", - "rand_core", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "slotmap" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbff4acf519f630b3a3ddcfaea6c06b42174d9a44bc70c620e9ed1649d58b82a" -dependencies = [ - "version_check", -] - -[[package]] -name = "spki" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" -dependencies = [ - "base64ct", - "der 0.6.1", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der 0.7.9", -] - -[[package]] -name = "stacker" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce" -dependencies = [ - "cc", - "cfg-if", - "libc", - "psm", - "winapi", -] - -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "subtle-encoding" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dcb1ed7b8330c5eed5441052651dd7a12c75e2ed88f2ec024ae1fa3a5e59945" -dependencies = [ - "zeroize", -] - -[[package]] -name = "subtle-ng" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tendermint" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "954496fbc9716eb4446cdd6d00c071a3e2f22578d62aa03b40c7e5b4fda3ed42" -dependencies = [ - "bytes", - "digest 0.10.7", - "ed25519", - "ed25519-consensus", - "flex-error", - "futures", - "k256 0.13.3", - "num-traits", - "once_cell", - "prost", - "prost-types", - "ripemd", - "serde", - "serde_bytes", - "serde_json", - "serde_repr", - "sha2 0.10.8", - "signature", - "subtle", - "subtle-encoding", - "tendermint-proto", - "time", - "zeroize", -] - -[[package]] -name = "tendermint-proto" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc87024548c7f3da479885201e3da20ef29e85a3b13d04606b380ac4c7120d87" -dependencies = [ - "bytes", - "flex-error", - "prost", - "prost-types", - "serde", - "serde_bytes", - "subtle-encoding", - "time", -] - -[[package]] -name = "thiserror" -version = "1.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "time" -version = "0.3.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" -dependencies = [ - "deranged", - "itoa", - "num-conv", - "powerfmt", - "serde", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" - -[[package]] -name = "time-macros" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" -dependencies = [ - "num-conv", - "time-core", -] - -[[package]] -name = "typed-arena" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-width" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" - -[[package]] -name = "uuid" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wasi" -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.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" -dependencies = [ - "cfg-if", - "once_cell", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.75", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -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 = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] diff --git a/route/cosmwasm/Cargo.toml b/route/cosmwasm/Cargo.toml deleted file mode 100644 index ddb36713..00000000 --- a/route/cosmwasm/Cargo.toml +++ /dev/null @@ -1,56 +0,0 @@ -[package] -name = "cosmwasm_route" -version = "0.1.9" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -candid = "0.10" -ciborium = "0.2.1" -ic-cdk = "^0.12.0" -ic-cdk-macros = "0.8.3" -log = "0.4" -thiserror = "1" -anyhow = "1.0.80" - -serde = { version = "1", features = ["derive"] } -serde_bytes = "0.11" -serde_cbor = "0.11" -serde_json = { version = "1", features = ["std"] } - - -ic0 = "0.18.9" -ic-cdk-timers = "0.7.0" -num-traits = "0.2.17" -ic-log = { git = "https://github.com/octopus-network/canister-sdk.git", branch = "v0.12.x-stablelog" } - -ic-canisters-http-types = { git = "https://github.com/dfinity/ic", tag = "release-2024-03-06_23-01+p2p" } -ic-stable-structures = "0.6" - - -omnity_types = { path = "../../types" } - -hex = "0.4.3" - -cosmrs = {version = "0.17.0", features = ["cosmwasm"]} -cosmwasm-schema = "2.0.1" - -base64 = "0.22.1" -rand = "0.8.5" -uuid = "1.10.0" - -sha2 = "0.10.6" -itertools = "0.13.0" -futures = "0.3.30" - -[dev-dependencies] -# ic-state-machine-tests = { git = "https://github.com/dfinity/ic", tag = "release-2024-01-18_23-01" } -# ic-test-utilities-load-wasm = { git = "https://github.com/dfinity/ic", tag = "release-2024-01-18_23-01" } -# pocket-ic = "3.1.0" -flate2 = "1.0.30" -# icp-ledger = { git = "https://github.com/dfinity/ic", tag = "release-2024-01-18_23-01" } -# dfn_candid = { git = "https://github.com/dfinity/ic", tag = "release-2024-01-18_23-01" } - -[workspace] \ No newline at end of file diff --git a/route/cosmwasm/cosmwasm_route.did b/route/cosmwasm/cosmwasm_route.did deleted file mode 100644 index 230067e1..00000000 --- a/route/cosmwasm/cosmwasm_route.did +++ /dev/null @@ -1,103 +0,0 @@ -type Chain = record { - fee_token : opt text; - canister_id : text; - chain_id : text; - counterparties : opt vec text; - chain_state : ChainState; - chain_type : ChainType; - contract_address : opt text; -}; -type ChainState = variant { Active; Deactive }; -type ChainType = variant { SettlementChain; ExecutionChain }; -type Directive = variant { - UpdateChain : Chain; - UpdateFee : Factor; - AddToken : Token; - AddChain : Chain; - ToggleChainState : ToggleState; - UpdateToken : Token; -}; -type Factor = variant { - UpdateFeeTokenFactor : FeeTokenFactor; - UpdateTargetChainFactor : TargetChainFactor; -}; -type FeeTokenFactor = record { fee_token : text; fee_token_factor : nat }; -type IcpChainKeyToken = variant { CKBTC }; -type InitArgs = record { - hub_principal : principal; - cw_rpc_url : text; - cw_rest_url : text; - chain_id : text; - cosmwasm_port_contract_address : text; -}; -type MultiRpcConfig = record { - rpc_list : vec text; - minimum_response_count : nat32; -}; -type Result = variant { Ok : text; Err : text }; -type RouteState = record { - hub_principal : principal; - cw_rpc_url : text; - cw_chain_key_derivation_path : vec blob; - next_directive_seq : nat64; - cw_rest_url : text; - cw_public_key_vec : opt blob; - chain_id : text; - cw_port_contract_address : text; - multi_rpc_config : MultiRpcConfig; - processing_tickets : vec record { nat64; Ticket }; - next_ticket_seq : nat64; - chain_state : ChainState; - processing_directive : vec record { nat64; Directive }; -}; -type TargetChainFactor = record { - target_chain_id : text; - target_chain_factor : nat; -}; -type Ticket = record { - token : text; - action : TxAction; - dst_chain : text; - memo : opt blob; - ticket_id : text; - sender : opt text; - ticket_time : nat64; - ticket_type : TicketType; - src_chain : text; - amount : text; - receiver : text; -}; -type TicketType = variant { Resubmit; Normal }; -type ToggleAction = variant { Deactivate; Activate }; -type ToggleState = record { action : ToggleAction; chain_id : text }; -type Token = record { - decimals : nat8; - token_id : text; - metadata : vec record { text; text }; - icon : opt text; - name : text; - symbol : text; -}; -type TxAction = variant { - Burn; - Redeem; - Mint; - RedeemIcpChainKeyAssets : IcpChainKeyToken; - Transfer; -}; -type UpdateCwSettingsArgs = record { - cw_rpc_url : opt text; - cw_rest_url : opt text; - cw_port_contract_address : opt text; - multi_rpc_config : opt MultiRpcConfig; -}; -service : (InitArgs) -> { - cache_public_key : () -> (); - osmosis_account_id : () -> (Result); - query_redeemed_tickets : () -> (vec record { text; text }) query; - redeem : (text) -> (Result); - route_state : () -> (RouteState, text, vec text) query; - start_process_directive : () -> (); - start_process_ticket : () -> (); - update_cw_settings : (UpdateCwSettingsArgs) -> (); -} diff --git a/route/cosmwasm/src/business.rs b/route/cosmwasm/src/business.rs deleted file mode 100644 index c6cde718..00000000 --- a/route/cosmwasm/src/business.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod mint_token; -pub mod process_directive; -pub mod redeem_token; -pub mod ticket_task; diff --git a/route/cosmwasm/src/business/mint_token.rs b/route/cosmwasm/src/business/mint_token.rs deleted file mode 100644 index e807ac19..00000000 --- a/route/cosmwasm/src/business/mint_token.rs +++ /dev/null @@ -1,13 +0,0 @@ -use candid::CandidType; -use omnity_types::Account; - -use crate::*; - -#[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] -pub struct MintTokenRequest { - pub ticket_id: TicketId, - pub token_id: String, - /// The owner of the account on the ledger. - pub receiver: Account, - pub amount: u128, -} diff --git a/route/cosmwasm/src/business/process_directive.rs b/route/cosmwasm/src/business/process_directive.rs deleted file mode 100644 index cd590216..00000000 --- a/route/cosmwasm/src/business/process_directive.rs +++ /dev/null @@ -1,85 +0,0 @@ -use cosmwasm::port::PortContractExecutor; -use memory::{get_periodic_job_manager, insert_periodic_job_manager, set_route_state, take_state}; - -use crate::*; -use omnity_types::ChainState; - -pub fn process_directive_task() { - ic_cdk::spawn(async { - let job_name = const_args::PROCESS_DIRECTIVE_JOB_NAME; - match get_periodic_job_manager(job_name) { - Some(mut periodic_job_manager) => { - if !periodic_job_manager.should_execute() { - return; - } - periodic_job_manager.is_running = true; - insert_periodic_job_manager(job_name.to_string(), periodic_job_manager.clone()); - match process_directives().await { - Ok(_) => { - periodic_job_manager.job_execute_success(); - } - Err(e) => { - periodic_job_manager.job_execute_failed(); - log::error!("failed to process directives, err: {:?}", e); - } - } - insert_periodic_job_manager(job_name.to_string(), periodic_job_manager.clone()); - } - None => { - log::error!( - "periodic job({}) manager is none", - job_name - ); - return; - } - } - }); -} - -async fn process_directives() -> Result<()> { - let mut state = take_state(); - if state.chain_state == ChainState::Deactive { - return Ok(()); - } - - if state.processing_directive.is_empty() { - let directives = hub::query_directives( - state.hub_principal, - state.next_directive_seq, - const_args::BATCH_QUERY_LIMIT, - ) - .await?; - state.processing_directive = directives.clone(); - } - - let port_contract_executor = PortContractExecutor::from_state()?; - state - .processing_directive - .sort_by(|(seq1, _), (seq2, _)| seq2.cmp(seq1)); - - while !state.processing_directive.is_empty() { - let (seq, directive) = state.processing_directive.pop().unwrap(); - match port_contract_executor - .execute_directive(seq, directive.clone().into()) - .await - { - Ok(_) => { - state.next_directive_seq = seq + 1; - set_route_state(state.clone()); - log::info!( - "[process directives] success to execute directive, seq: {}, directive: {:?}", - seq, - directive - ); - } - Err(err) => { - log::error!("[process directives] failed to execute directive, seq: {}, directive: {:?}, err: {:?}", seq, directive, err); - state.processing_directive.push((seq, directive)); - set_route_state(state.clone()); - break; - } - } - } - - Ok(()) -} diff --git a/route/cosmwasm/src/business/redeem_token.rs b/route/cosmwasm/src/business/redeem_token.rs deleted file mode 100644 index 6ff4f777..00000000 --- a/route/cosmwasm/src/business/redeem_token.rs +++ /dev/null @@ -1,103 +0,0 @@ -use cosmwasm::port::{PortContractExecutor, REDEEM_EVENT_KIND}; -use memory::{get_redeem_ticket, insert_redeem_ticket, read_state}; -use tendermint::abci::Event; - -use crate::*; - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct RedeemEvent { - pub token_id: String, - pub sender: String, - pub receiver: String, - pub amount: u128, - pub target_chain: String, -} - -pub async fn redeem_token_and_send_ticket(tx_hash: String)->Result { - match get_redeem_ticket(&tx_hash) { - Some(ticket_id) => { - return Err(RouteError::CustomError(format!("ticket already redeemed, ticket_id: {:?}", ticket_id))) - }, - None => {}, - } - let port_contract_executor = PortContractExecutor::from_state()?; - let event = port_contract_executor - .query_redeem_token_event(tx_hash.clone()) - .await?; - - let (hub_principal, chain_id) = read_state(|s| (s.hub_principal, s.chain_id.clone())); - let ticket = Ticket { - ticket_id: tx_hash.clone(), - ticket_type: omnity_types::TicketType::Normal, - ticket_time: ic_cdk::api::time(), - src_chain: chain_id, - dst_chain: event.target_chain.clone(), - action: omnity_types::TxAction::RedeemIcpChainKeyAssets(omnity_types::IcpChainKeyToken::CKBTC), - token: event.token_id.clone(), - amount: event.amount.to_string(), - sender: Some(event.sender), - receiver: event.receiver, - memo: None, - }; - - log::info!( - "try to send redeem ticket: {:?}, tx_hash: {:?}", - ticket, - tx_hash - ); - - hub::send_ticket(hub_principal, ticket.clone()) - .await?; - - - insert_redeem_ticket(tx_hash, ticket.ticket_id.clone()); - - Ok(ticket.ticket_id) - -} - -pub fn parse_redeem_event(redeem_event: Event) -> Result { - assert_eq!( - redeem_event.kind, - REDEEM_EVENT_KIND.to_string(), - "Event kind is not RedeemRequested" - ); - let token_id = find_attribute(&redeem_event, "token_id")?; - let sender = find_attribute(&redeem_event, "sender")?; - let receiver = find_attribute(&redeem_event, "receiver")?; - let amount = find_attribute(&redeem_event, "amount")? - .parse() - .map_err(|e| RouteError::CustomError(format!("amount parse error: {}", e)))?; - let target_chain = find_attribute(&redeem_event, "target_chain")?; - Ok(RedeemEvent { - token_id, - sender, - receiver, - amount, - target_chain, - }) -} - -fn find_attribute(event: &Event, key: &str) -> Result { - for attr in &event.attributes { - let key_str = attr.key_str().map_err(|e| { - RouteError::AttributeParseError(event.kind.to_string(), key.to_string(), e.to_string()) - })?; - if key_str.eq(key) { - return attr - .value_str() - .map_err(|e| { - RouteError::AttributeParseError( - event.kind.to_string(), - key.to_string(), - e.to_string(), - ) - }) - .map(|v| v.to_string()); - } - } - Err(RouteError::AttributeNotFound( - key.to_string(), - event.kind.to_string(), - )) -} diff --git a/route/cosmwasm/src/business/ticket_task.rs b/route/cosmwasm/src/business/ticket_task.rs deleted file mode 100644 index 6f58c76d..00000000 --- a/route/cosmwasm/src/business/ticket_task.rs +++ /dev/null @@ -1,98 +0,0 @@ -use business::mint_token::MintTokenRequest; -use cosmwasm::port::PortContractExecutor; -use memory::{get_periodic_job_manager, insert_periodic_job_manager, set_route_state, take_state}; - -use crate::*; -use omnity_types::ChainState; - -pub fn process_ticket_task() { - ic_cdk::spawn(async { - let job_name = const_args::PROCESS_TICKET_JOB_NAME; - match get_periodic_job_manager(job_name) { - Some(mut periodic_job_manager) => { - if !periodic_job_manager.should_execute() { - return; - } - periodic_job_manager.is_running = true; - insert_periodic_job_manager(job_name.to_string(), periodic_job_manager.clone()); - match process_tickets().await { - Ok(_) => { - periodic_job_manager.job_execute_success(); - } - Err(e) => { - periodic_job_manager.job_execute_failed(); - log::error!("failed to process directives, err: {:?}", e); - } - } - insert_periodic_job_manager(job_name.to_string(), periodic_job_manager.clone()); - } - None => { - log::error!( - "periodic job({}) manager is none", - job_name - ); - return; - } - } - }); -} - -async fn process_tickets() -> Result<()> { - let mut state = take_state(); - if state.chain_state == ChainState::Deactive { - return Ok(()); - } - - // fetch tickets from hub if processing_tickets is empty - if state.processing_tickets.is_empty() { - let tickets = hub::query_tickets( - state.hub_principal, - state.next_ticket_seq, - const_args::BATCH_QUERY_LIMIT, - ) - .await?; - state.processing_tickets = tickets.clone(); - } - let port_contract_executor = PortContractExecutor::from_state()?; - - // Descending order - state - .processing_tickets - .sort_by(|(seq1, _), (seq2, _)| seq2.cmp(seq1)); - - while !state.processing_tickets.is_empty() { - let (seq, ticket) = state.processing_tickets.pop().unwrap(); - match port_contract_executor - .mint_token(MintTokenRequest { - ticket_id: ticket.ticket_id.clone(), - token_id: ticket.token.clone(), - receiver: ticket.receiver.clone(), - amount: ticket.amount.parse().unwrap(), - }) - .await - { - Ok(_) => { - state.next_ticket_seq = seq + 1; - set_route_state(state.clone()); - log::info!( - "[process tickets] success to mint token, seq: {}, ticket: {:?}", - seq, - ticket - ); - } - Err(err) => { - log::error!( - "[process tickets] failed to mint token, seq: {}, ticket: {:?}, err: {:?}", - seq, - ticket, - err - ); - state.processing_tickets.push((seq, ticket)); - set_route_state(state.clone()); - break; - } - } - } - - Ok(()) -} diff --git a/route/cosmwasm/src/cosmwasm.rs b/route/cosmwasm/src/cosmwasm.rs deleted file mode 100644 index bd333e92..00000000 --- a/route/cosmwasm/src/cosmwasm.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod client; -pub mod port; -pub mod rpc; - -pub type TxHash = String; diff --git a/route/cosmwasm/src/cosmwasm/client.rs b/route/cosmwasm/src/cosmwasm/client.rs deleted file mode 100644 index fbf8e4d0..00000000 --- a/route/cosmwasm/src/cosmwasm/client.rs +++ /dev/null @@ -1,363 +0,0 @@ -use candid::CandidType; -use cosmwasm::port::ExecuteMsg; - -use crate::*; - -pub const OSMO_ACCOUNT_PREFIX: &str = "osmo"; -const DENOM: &str = "uosmo"; -const MEMO: &str = "memo"; - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct CosmWasmClient { - pub rpc_url: String, - pub rest_url: String, - pub chain_id: ChainId, -} - -impl CosmWasmClient { - pub fn new(rpc_url: String, rest_url: String, chain_id: ChainId) -> Self { - Self { - rpc_url, - rest_url, - chain_id, - } - } - - pub fn cosmos_wasm_port_client() -> CosmWasmClient { - let (rpc_url, rest_url, chain_id) = memory::read_state(|state| { - ( - state.cw_rpc_url.clone(), - state.cw_rest_url.clone(), - state.chain_id.clone(), - ) - }); - let client = CosmWasmClient::new(rpc_url, rest_url, chain_id); - client - } - - pub async fn query_account_number_and_sequence( - &self, - address: String, - ) -> Result<(AccountNumber, u64)> { - // eg: https://lcd.testnet.osmosis.zone/cosmos/auth/v1beta1/account_info/osmo1x6ctqf5fwy37tx9vdhh9y7kxk5puvwsdnl0acw - let full_url = format!( - "{}/cosmos/auth/v1beta1/account_info/{}", - self.rest_url, address - ) - .to_string(); - log::info!("full_url: {:?}", full_url); - - let request_headers = vec![HttpHeader { - name: "content-type".to_string(), - value: "application/json".to_string(), - }]; - - let request = CanisterHttpRequestArgument { - url: full_url, - max_response_bytes: None, - method: HttpMethod::GET, - headers: request_headers, - body: None, - transform: None, - }; - - let response = http_request_with_status_check(request).await?; - - log::info!("response: {:?}", response); - - let json_value: Value = serde_json::from_slice(&response.body).map_err(|e| { - RouteError::CustomError(format!("Failed to parse account info: {:?}", e.to_string())) - })?; - - let account_number = json_value["info"]["account_number"] - .as_str() - .ok_or_else(|| RouteError::CustomError("Failed to parse account number".to_string()))? - .parse::() - .map_err(|e| { - RouteError::CustomError(format!( - "Failed to parse account number: {:?}", - e.to_string() - )) - })?; - - let sequence = json_value["info"]["sequence"] - .as_str() - .ok_or_else(|| RouteError::CustomError("Failed to parse sequence".to_string()))? - .parse::() - .map_err(|e| { - RouteError::CustomError(format!("Failed to parse sequence: {:?}", e.to_string())) - })?; - - Ok((account_number, sequence)) - } - - pub async fn broadcast_tx_commit(&self, raw: Raw) -> Result { - let raw_bytes = raw.to_bytes().unwrap(); - let raw_base64 = bytes_to_base64(&raw_bytes); - - let request_headers = vec![HttpHeader { - name: "content-type".to_string(), - value: "application/json".to_string(), - }]; - - let request_body = json!({ - "jsonrpc": "2.0", - "method": "broadcast_tx_async", - "params": { - "tx": raw_base64, - }, - "id": Id::uuid_v4(), - }); - - let request = CanisterHttpRequestArgument { - url: self.rpc_url.clone(), - max_response_bytes: None, - method: HttpMethod::POST, - headers: request_headers, - body: Some(request_body.to_string().into_bytes()), - transform: None, - }; - - http_request_with_status_check(request).await - } - - pub async fn query_tx_by_hash_from_multi_rpc( - &self, - tx_hash: TxHash, - rpc_url_vec: Vec, - ) -> Vec> { - let mut fut = Vec::with_capacity(rpc_url_vec.len()); - for rpc_url in rpc_url_vec { - fut.push(async { self.query_tx_by_hash(tx_hash.clone(), rpc_url).await }); - } - futures::future::join_all(fut).await - } - - pub async fn query_tx_by_hash(&self, tx_hash: TxHash, rpc_url: String) -> Result { - // https://rpc.testnet.osmosis.zone/tx?hash=0xFE14C9EAD18A6990FF426F4782894C1719A4A2C4B62D2F6B8A53AD945D7FFE34 - let request_url = format!("{}/tx?hash=0x{}", rpc_url, tx_hash); - let request_headers = vec![HttpHeader { - name: "content-type".to_string(), - value: "application/json".to_string(), - }]; - - let request = CanisterHttpRequestArgument { - url: request_url, - max_response_bytes: None, - method: HttpMethod::POST, - headers: request_headers, - body: None, - transform: None, - }; - - http_request_with_status_check(request).await - } - - pub async fn execute_msg( - &self, - contract_id: AccountId, - msg: ExecuteMsg, - tendermint_public_key: tendermint::public_key::PublicKey, - ) -> Result { - let sender_public_key = cosmrs::crypto::PublicKey::from(tendermint_public_key); - let sender_account_id = sender_public_key.account_id(OSMO_ACCOUNT_PREFIX).unwrap(); - - let (account_number, sequence) = self - .query_account_number_and_sequence(sender_account_id.to_string()) - .await?; - - log::info!( - "account_number: {:?}, sequence: {:?}", - account_number, - sequence - ); - // let sequence_number = 0u64; - let gas = 2_000_000u64; - let amount = Coin { - amount: 10000u128.into(), - denom: DENOM.parse().unwrap(), - }; - let fee = Fee::from_amount_and_gas(amount, gas); - let msg_execute = MsgExecuteContract { - sender: sender_account_id, - contract: contract_id, - msg: serde_json::to_string(&msg).unwrap().into_bytes(), - funds: vec![], - } - .to_any() - .unwrap(); - - let tx_body = tx::BodyBuilder::new().msg(msg_execute).memo(MEMO).finish(); - let auth_info = SignerInfo::single_direct(Some(sender_public_key), sequence).auth_info(fee); - - let chain_id = self - .chain_id - .clone() - .parse::() - .map_err(|e| { - RouteError::CustomError(format!("Failed to parse chain id: {:?}", e.to_string())) - })?; - let sign_doc = SignDoc::new(&tx_body, &auth_info, &chain_id, account_number).unwrap(); - let sign_result = sign_with_cw_key( - sign_doc - .clone() - .into_bytes() - .expect("Sign doc into bytes failed"), - ) - .await?; - - let raw: Raw = proto::cosmos::tx::v1beta1::TxRaw { - body_bytes: sign_doc.body_bytes.clone(), - auth_info_bytes: sign_doc.auth_info_bytes.clone(), - signatures: vec![sign_result.signature.to_vec()], - } - .into(); - - let tx_hash = raw.to_bytes().map_err(|e| { - RouteError::CustomError(format!( - "Failed to convert raw to bytes: {:?}", - e.to_string() - )) - })?; - let http_response = self.broadcast_tx_commit(raw).await?; - log::info!("http_response: {:?}", http_response); - - Ok(bytes_to_hex(&sha256(tx_hash))) - } -} - -pub async fn cw_chain_key_arg() -> EcdsaChainKeyArg { - let key_id = EcdsaKeyIds::ProductionKey1.to_key_id(); - let cw_chain_key_derivation_path = - memory::read_state(|state| state.cw_chain_key_derivation_path.clone()); - - EcdsaChainKeyArg { - derivation_path: cw_chain_key_derivation_path - .iter() - .map(|e| e.clone().into_vec()) - .collect(), - key_id: EcdsaKeyId { - curve: ic_cdk::api::management_canister::ecdsa::EcdsaCurve::Secp256k1, - name: key_id.name, - }, - } -} - -pub async fn query_cw_public_key() -> Result { - let key_arg = cw_chain_key_arg().await; - - let request = EcdsaPublicKeyArgument { - canister_id: ic_cdk::api::id().into(), - derivation_path: key_arg.derivation_path, - key_id: key_arg.key_id, - }; - - let (response,) = ecdsa_public_key(request).await.map_err(|(code, msg)| { - RouteError::CallError( - "ecdsa_public_key".to_string(), - Principal::management_canister(), - format!("{:?}", code).to_string(), - msg, - ) - })?; - - Ok(response) -} - -pub async fn sign_with_cw_key(message: Vec) -> Result { - let key_arg = cw_chain_key_arg().await; - let request = SignWithEcdsaArgument { - message_hash: sha256(message).to_vec(), - derivation_path: key_arg.derivation_path, - key_id: key_arg.key_id, - }; - - let (response,) = sign_with_ecdsa(request) - .await - .map_err(|e| RouteError::SignWithEcdsaError(format!("{:?}", e.0), e.1))?; - Ok(response) -} - -#[derive(CandidType, Clone, Debug, Deserialize, Serialize, Default)] -pub struct MultiRpcConfig { - pub rpc_list: Vec, - pub minimum_response_count: u32, -} - -impl MultiRpcConfig { - pub fn new(rpc_list: Vec, minimum_response_count: u32) -> Result { - - let s = Self { - rpc_list, - minimum_response_count, - }; - s.check_config_valid()?; - - Ok(s) - } - - pub fn check_config_valid(&self)->Result<()> { - if self.minimum_response_count == 0 { - return Err(RouteError::CustomError( - "minimum_response_count should be greater than 0".to_string(), - )); - } - if self.rpc_list.len() < self.minimum_response_count as usize { - return Err(RouteError::CustomError( - "rpc_list length should be greater than minimum_response_count".to_string(), - )); - } - Ok(()) - } - - pub fn valid_and_get_result<'a, T>( - &self, - response_list: &'a Vec>, - ) -> Result - where - T: Serialize + Deserialize<'a> + Clone, - { - self.check_config_valid()?; - let mut success_response_list = vec![]; - let mut success_response_body_list = vec![]; - - for response in response_list { - if response.is_err() { - continue; - } - match response { - Ok(res) => match serde_json::from_slice::(&res.body) { - Ok(t) => { - success_response_list.push(t); - success_response_body_list.push(res.body.clone()); - } - Err(_) => { - continue; - } - }, - Err(_) => { - continue; - } - } - } - - if success_response_list.len() < self.minimum_response_count as usize { - return Err(RouteError::CustomError(format!( - "Not enough valid response, expected: {}, actual: {}", - self.minimum_response_count, - success_response_list.len() - ))); - } - - // The minimum_response_count should greater than 0 - let mut i = 1; - while i < success_response_list.len() { - if success_response_body_list[i - 1] != success_response_body_list[i] { - return Err(RouteError::CustomError("Response mismatch".to_string())); - } - i += 1; - } - - Ok(success_response_list[0].clone()) - } -} diff --git a/route/cosmwasm/src/cosmwasm/port.rs b/route/cosmwasm/src/cosmwasm/port.rs deleted file mode 100644 index 0264432d..00000000 --- a/route/cosmwasm/src/cosmwasm/port.rs +++ /dev/null @@ -1,398 +0,0 @@ -use crate::*; -use business::{ - mint_token::MintTokenRequest, - redeem_token::{parse_redeem_event, RedeemEvent}, -}; -use cosmrs::{ - tendermint::{ - self, - abci::{Event, EventAttributeIndexExt}, - }, - AccountId, -}; -use cosmwasm::rpc::tx::TxResultByHashResponse; -use cosmwasm_schema::cw_serde; -use memory::read_state; -use std::collections::HashMap; - -use crate::{cosmwasm::rpc::wrapper::Wrapper, CosmWasmClient}; - -use super::TxHash; - -pub type ChainId = String; -pub type TokenId = String; - -pub const REDEEM_EVENT_KIND: &str = "wasm-RedeemRequested"; -pub const DIRECTIVE_EXECUTED_EVENT_KIND: &str = "wasm-DirectiveExecuted"; -pub const TOKEN_MINTED_EVENT_KIND: &str = "wasm-TokenMinted"; - -#[derive(Debug, Clone)] -pub struct PortContractExecutor { - pub client: CosmWasmClient, - pub contract_id: AccountId, - pub tendermint_public_key: tendermint::public_key::PublicKey, -} - -impl PortContractExecutor { - pub fn new( - client: CosmWasmClient, - contract_id: AccountId, - tendermint_public_key: tendermint::public_key::PublicKey, - ) -> Self { - Self { - client, - contract_id, - tendermint_public_key, - } - } - - pub fn from_state() -> Result { - let client = CosmWasmClient::cosmos_wasm_port_client(); - let contract_id = get_contract_id(); - // let public_key_response = query_cw_public_key().await?; - let public_key_vec = read_state(|s| { - s.cw_public_key_vec.clone().ok_or(RouteError::CustomError( - "cw_public_key_vec not found".to_string(), - )) - // .expect("cw_public_key_vec not found") - })?; - - let tendermint_public_key = - tendermint::public_key::PublicKey::from_raw_secp256k1(public_key_vec.as_slice()) - .ok_or(RouteError::CustomError( - "failed to init tendermint public key".to_string(), - ))?; - - Ok(Self::new(client, contract_id, tendermint_public_key)) - } - - pub async fn execute_directive(&self, seq: u64, directive: Directive) -> Result { - let msg = ExecuteMsg::ExecDirective { seq, directive }; - - let tx_hash = self - .client - .execute_msg( - self.contract_id.clone(), - msg, - self.tendermint_public_key.clone(), - ) - .await?; - - log::info!("execute directive tx_hash: {:?}", tx_hash); - - let mut times: i32 = 3; - while times > 0 { - match self.confirm_execute_directive(seq, tx_hash.clone()).await { - Ok(_) => { - return Ok(tx_hash); - } - Err(_) => {} - } - times -= 1; - } - - Err(RouteError::ConfirmExecuteDirectiveErr(seq, tx_hash)) - } - - pub async fn query_redeem_token_event(&self, tx_hash: TxHash) -> Result { - // let = MultiRpcRule - let multi_rpc_config = read_state(|s| s.multi_rpc_config.clone()); - multi_rpc_config.check_config_valid()?; - let tx_response = self.client.query_tx_by_hash_from_multi_rpc(tx_hash, multi_rpc_config.rpc_list.clone()).await; - - let wrapper = multi_rpc_config.valid_and_get_result::>(&tx_response)?; - // let wrapper: Wrapper = - // serde_json::from_slice(&tx_response.body).unwrap(); - - let result: TxResultByHashResponse = wrapper.into_result()?; - log::info!("tx_result: {:?}", result); - let event = result - .find_first_event_by_kind(REDEEM_EVENT_KIND.to_string()) - .ok_or(RouteError::EventNotFound("RedeemRequested".to_string()))?; - log::info!("event: {:?}", event); - let redeem_event = parse_redeem_event(event)?; - Ok(redeem_event) - } - - pub async fn confirm_execute_directive(&self, seq: u64, tx_hash: TxHash) -> Result<()> { - let tx_response = self.client.query_tx_by_hash(tx_hash, self.client.rpc_url.clone()).await?; - let wrapper: Wrapper = - serde_json::from_slice(&tx_response.body).unwrap(); - - let result: TxResultByHashResponse = wrapper.into_result()?; - log::info!("tx_result: {:?}", result); - - let expect_event = Event::new( - DIRECTIVE_EXECUTED_EVENT_KIND, - [("sequence", seq.to_string()).no_index()], - ); - result.assert_event_exist(&expect_event)?; - Ok(()) - } - - pub async fn confirm_mint_token( - &self, - mint_token_request: MintTokenRequest, - tx_hash: TxHash, - ) -> Result<()> { - let tx_response = self.client.query_tx_by_hash(tx_hash, self.client.rpc_url.clone()).await?; - let wrapper: Wrapper = - serde_json::from_slice(&tx_response.body).unwrap(); - - let result: TxResultByHashResponse = wrapper.into_result()?; - log::info!("tx_result: {:?}", result); - - let expect_event = Event::new( - TOKEN_MINTED_EVENT_KIND, - [ - ("ticket_id", mint_token_request.ticket_id).no_index(), - ("token_id", mint_token_request.token_id).no_index(), - ("receiver", mint_token_request.receiver).no_index(), - ("amount", mint_token_request.amount.to_string()).no_index(), - ], - ); - result.assert_event_exist(&expect_event)?; - Ok(()) - } - - pub async fn mint_token(&self, mint_token_request: MintTokenRequest) -> Result { - let msg = ExecuteMsg::PrivilegeMintToken { - ticket_id: mint_token_request.ticket_id.clone(), - token_id: mint_token_request.token_id.clone(), - receiver: mint_token_request.receiver.clone(), - amount: mint_token_request.amount.clone().to_string(), - }; - - let tx_hash = self - .client - .execute_msg( - self.contract_id.clone(), - msg, - self.tendermint_public_key.clone(), - ) - .await?; - - log::info!("mint token tx_hash: {:?}", tx_hash); - - let mut times = 3; - while times > 0 { - match self - .confirm_mint_token(mint_token_request.clone(), tx_hash.clone()) - .await - { - Ok(_) => { - return Ok(tx_hash); - } - Err(_) => {} - } - times -= 1; - } - Err(RouteError::ConfirmMintTokenErr( - format!("{:?}", mint_token_request).to_string(), - tx_hash, - )) - } -} - -#[cw_serde] -pub enum ExecuteMsg { - ExecDirective { - seq: u64, - directive: Directive, - }, - PrivilegeMintToken { - ticket_id: String, - token_id: String, - receiver: String, - amount: String, - }, -} - -#[cw_serde] -pub struct Chain { - pub chain_id: ChainId, - pub canister_id: String, - pub chain_type: ChainType, - // the chain default state is true - pub chain_state: ChainState, - // settlement chain: export contract address - // execution chain: port contract address - pub contract_address: Option, - - // optional counterparty chains - pub counterparties: Option>, - // fee token - pub fee_token: Option, -} - -impl From for Chain { - fn from(value: omnity_types::Chain) -> Self { - Self { - chain_id: value.chain_id, - canister_id: value.canister_id, - chain_type: value.chain_type.into(), - chain_state: value.chain_state.into(), - contract_address: value.contract_address, - counterparties: value.counterparties, - fee_token: value.fee_token, - } - } -} - -#[cw_serde] -pub enum ChainType { - SettlementChain, - ExecutionChain, -} - -impl From for ChainType { - fn from(value: omnity_types::ChainType) -> Self { - match value { - omnity_types::ChainType::SettlementChain => Self::SettlementChain, - omnity_types::ChainType::ExecutionChain => Self::ExecutionChain, - } - } -} - -#[cw_serde] -pub enum ChainState { - Active, - Deactive, -} - -impl From for ChainState { - fn from(value: omnity_types::ChainState) -> Self { - match value { - omnity_types::ChainState::Active => Self::Active, - omnity_types::ChainState::Deactive => Self::Deactive, - } - } -} - -#[cw_serde] -pub enum Directive { - AddChain(Chain), - AddToken(Token), - UpdateChain(Chain), - UpdateToken(Token), - ToggleChainState(ToggleState), - UpdateFee(Factor), -} - -impl From for Directive { - fn from(value: omnity_types::Directive) -> Self { - match value { - omnity_types::Directive::AddChain(chain) => Self::AddChain(chain.into()), - omnity_types::Directive::AddToken(token) => Self::AddToken(token.into()), - omnity_types::Directive::UpdateChain(chain) => Self::UpdateChain(chain.into()), - omnity_types::Directive::UpdateToken(token) => Self::UpdateToken(token.into()), - omnity_types::Directive::ToggleChainState(toggle) => { - Self::ToggleChainState(toggle.into()) - } - omnity_types::Directive::UpdateFee(factor) => Self::UpdateFee(factor.into()), - } - } -} - -#[cw_serde] -pub struct ToggleState { - pub chain_id: ChainId, - pub action: ToggleAction, -} - -impl From for ToggleState { - fn from(value: omnity_types::ToggleState) -> Self { - Self { - chain_id: value.chain_id, - action: value.action.into(), - } - } -} - -#[cw_serde] -pub enum ToggleAction { - Activate, - Deactivate, -} - -impl From for ToggleAction { - fn from(value: omnity_types::ToggleAction) -> Self { - match value { - omnity_types::ToggleAction::Activate => Self::Activate, - omnity_types::ToggleAction::Deactivate => Self::Deactivate, - } - } -} - -#[cw_serde] -pub struct Token { - pub token_id: String, - pub name: String, - pub symbol: String, - - pub decimals: u8, - pub icon: Option, - pub metadata: HashMap, -} - -impl From for Token { - fn from(value: omnity_types::Token) -> Self { - Self { - token_id: value.token_id, - name: value.name, - symbol: value.symbol, - decimals: value.decimals, - icon: value.icon, - metadata: value.metadata, - } - } -} - -#[cw_serde] -pub enum Factor { - UpdateTargetChainFactor(TargetChainFactor), - UpdateFeeTokenFactor(FeeTokenFactor), -} - -impl From for Factor { - fn from(value: omnity_types::Factor) -> Self { - match value { - omnity_types::Factor::UpdateTargetChainFactor(factor) => { - Self::UpdateTargetChainFactor(factor.into()) - } - omnity_types::Factor::UpdateFeeTokenFactor(factor) => { - Self::UpdateFeeTokenFactor(factor.into()) - } - } - } -} - -#[cw_serde] -pub struct TargetChainFactor { - pub target_chain_id: ChainId, - pub target_chain_factor: u128, -} - -impl From for TargetChainFactor { - fn from(value: omnity_types::TargetChainFactor) -> Self { - Self { - target_chain_id: value.target_chain_id, - target_chain_factor: value.target_chain_factor, - } - } -} - -#[cw_serde] -pub struct FeeTokenFactor { - pub fee_token: TokenId, - pub fee_token_factor: u128, -} - -impl From for FeeTokenFactor { - fn from(value: omnity_types::FeeTokenFactor) -> Self { - Self { - fee_token: value.fee_token, - fee_token_factor: value.fee_token_factor, - } - } -} diff --git a/route/cosmwasm/src/cosmwasm/rpc/mod.rs b/route/cosmwasm/src/cosmwasm/rpc/mod.rs deleted file mode 100644 index d4ca0d4e..00000000 --- a/route/cosmwasm/src/cosmwasm/rpc/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod response; -pub mod response_error; -pub mod tx; -pub mod version; -pub mod wrapper; diff --git a/route/cosmwasm/src/cosmwasm/rpc/response.rs b/route/cosmwasm/src/cosmwasm/rpc/response.rs deleted file mode 100644 index aa49afbd..00000000 --- a/route/cosmwasm/src/cosmwasm/rpc/response.rs +++ /dev/null @@ -1,34 +0,0 @@ -use crate::*; -use tendermint::{ - abci::{self, Event}, - block, Hash, -}; - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct TxCommitResponse { - /// `CheckTx` result - pub check_tx: abci::response::CheckTx, - - /// Result of executing the transaction. - /// - /// The JSON field carrying this data is named `deliver_tx` in - /// CometBFT versions before 0.38. - #[serde(alias = "deliver_tx")] - pub tx_result: abci::types::ExecTxResult, - - /// Transaction - pub hash: Hash, - - /// Height - pub height: block::Height, -} - -impl TxCommitResponse { - pub fn assert_event_exist(&self, event: &Event) -> Result<&Event> { - self.tx_result - .events - .iter() - .find(|&e| e.kind.eq(&event.kind)) - .ok_or(RouteError::EventNotFound(event.kind.clone())) - } -} diff --git a/route/cosmwasm/src/cosmwasm/rpc/response_error.rs b/route/cosmwasm/src/cosmwasm/rpc/response_error.rs deleted file mode 100644 index f632d5ca..00000000 --- a/route/cosmwasm/src/cosmwasm/rpc/response_error.rs +++ /dev/null @@ -1,208 +0,0 @@ -use core::fmt::Display; - -use serde::{Deserialize, Deserializer, Serialize, Serializer}; - -#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] -pub struct ResponseError { - /// Error code - code: Code, - - /// Error message - message: String, - - /// Additional data about the error - data: Option, -} - -// /// Tendermint RPC error codes. -// /// -/// See `func RPC*Error()` definitions in: -/// -#[derive(Copy, Clone, Debug, Eq, thiserror::Error, Hash, PartialEq, PartialOrd, Ord)] -pub enum Code { - /// Low-level HTTP error - #[error("HTTP error")] - HttpError, - - /// Low-level WebSocket error - #[error("WebSocket Error")] - WebSocketError, - - /// An internal error occurred within the client. - /// - /// This is an error unique to this client, and is not available in the - /// [Go client]. - /// - /// [Go client]: https://github.com/tendermint/tendermint/tree/main/rpc/jsonrpc/client - #[error("Client internal error")] - ClientInternalError, - - /// Parse error i.e. invalid JSON (-32700) - #[error("Parse error. Invalid JSON")] - ParseError, - - /// Invalid request (-32600) - #[error("Invalid Request")] - InvalidRequest, - - /// Method not found error (-32601) - #[error("Method not found")] - MethodNotFound, - - /// Invalid parameters (-32602) - #[error("Invalid params")] - InvalidParams, - - /// Internal RPC server error (-32603) - #[error("Internal error")] - InternalError, - - /// Server error (-32000) - #[error("Server error")] - ServerError, - - /// Other error types - #[error("Error (code: {})", 0)] - Other(i32), -} - -impl Code { - /// Get the integer error value for this code - pub fn value(self) -> i32 { - i32::from(self) - } -} - -impl From for Code { - fn from(value: i32) -> Code { - match value { - 0 => Code::HttpError, - 1 => Code::WebSocketError, - 2 => Code::ClientInternalError, - -32700 => Code::ParseError, - -32600 => Code::InvalidRequest, - -32601 => Code::MethodNotFound, - -32602 => Code::InvalidParams, - -32603 => Code::InternalError, - -32000 => Code::ServerError, - other => Code::Other(other), - } - } -} - -impl From for i32 { - fn from(code: Code) -> i32 { - match code { - Code::HttpError => 0, - Code::WebSocketError => 1, - Code::ClientInternalError => 2, - Code::ParseError => -32700, - Code::InvalidRequest => -32600, - Code::MethodNotFound => -32601, - Code::InvalidParams => -32602, - Code::InternalError => -32603, - Code::ServerError => -32000, - Code::Other(other) => other, - } - } -} - -impl Display for ResponseError { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match &self.data { - Some(data) => write!( - f, - "{}: {} (code: {})", - self.message, - data, - self.code.value() - ), - None => write!(f, "{} (code: {})", self.message, self.code.value()), - } - } -} - -impl ResponseError { - /// Create a new RPC error - pub fn new(code: Code, data: Option) -> ResponseError { - let message = code.to_string(); - - ResponseError { - code, - message, - data, - } - } - - // / Create a low-level HTTP error - pub fn http_error(message: impl Into) -> ResponseError { - ResponseError { - code: Code::HttpError, - message: message.into(), - data: None, - } - } - - /// Create a new invalid parameter error - pub fn invalid_params(data: &str) -> ResponseError { - ResponseError::new(Code::InvalidParams, Some(data.to_string())) - } - - /// Create a new websocket error - pub fn websocket_error(cause: impl Into) -> ResponseError { - ResponseError::new(Code::WebSocketError, Some(cause.into())) - } - - /// Create a new method-not-found error - pub fn method_not_found(name: &str) -> ResponseError { - ResponseError::new(Code::MethodNotFound, Some(name.to_string())) - } - - /// Create a new parse error - pub fn parse_error(error: E) -> ResponseError - where - E: Display, - { - ResponseError::new(Code::ParseError, Some(error.to_string())) - } - - /// Create a new server error - pub fn server_error(data: D) -> ResponseError - where - D: Display, - { - ResponseError::new(Code::ServerError, Some(data.to_string())) - } - - /// An internal error occurred within the client. - pub fn client_internal_error(cause: impl Into) -> ResponseError { - ResponseError::new(Code::ClientInternalError, Some(cause.into())) - } - - /// Obtain the `rpc::error::Code` for this error - pub fn code(&self) -> Code { - self.code - } - - /// Borrow the error message (if available) - pub fn message(&self) -> &str { - &self.message - } - - /// Optional additional error message (if available) - pub fn data(&self) -> Option<&str> { - self.data.as_ref().map(AsRef::as_ref) - } -} - -impl<'de> Deserialize<'de> for Code { - fn deserialize>(deserializer: D) -> Result { - Ok(Code::from(i32::deserialize(deserializer)?)) - } -} - -impl Serialize for Code { - fn serialize(&self, serializer: S) -> Result { - self.value().serialize(serializer) - } -} diff --git a/route/cosmwasm/src/cosmwasm/rpc/tx.rs b/route/cosmwasm/src/cosmwasm/rpc/tx.rs deleted file mode 100644 index b5a0f3ac..00000000 --- a/route/cosmwasm/src/cosmwasm/rpc/tx.rs +++ /dev/null @@ -1,40 +0,0 @@ -use crate::*; -use tendermint::{ - abci::{self, Event}, - block, serializers, tx, Hash, -}; - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct TxResultByHashResponse { - /// The hash of the transaction. - /// - /// Deserialized from a hex-encoded string (there is a discrepancy between - /// the format used for the request and the format used for the response in - /// the Tendermint RPC). - pub hash: Hash, - pub height: block::Height, - pub index: u32, - pub tx_result: abci::types::ExecTxResult, - #[serde(with = "serializers::bytes::base64string")] - pub tx: Vec, - #[serde(skip_serializing_if = "Option::is_none")] - pub proof: Option, -} - -impl TxResultByHashResponse { - pub fn find_first_event_by_kind(&self, kind: String) -> Option { - self.tx_result - .events - .iter() - .find(|&e| e.kind.eq(&kind)) - .cloned() - } - - pub fn assert_event_exist(&self, event: &Event) -> Result<&Event> { - self.tx_result - .events - .iter() - .find(|&e| e.kind.eq(&event.kind)) - .ok_or(RouteError::EventNotFound(event.kind.clone())) - } -} diff --git a/route/cosmwasm/src/cosmwasm/rpc/version.rs b/route/cosmwasm/src/cosmwasm/rpc/version.rs deleted file mode 100644 index 6c55df7b..00000000 --- a/route/cosmwasm/src/cosmwasm/rpc/version.rs +++ /dev/null @@ -1,56 +0,0 @@ -//! JSON-RPC versions - -use core::{ - fmt::{self, Display}, - str::FromStr, -}; - -use serde::{Deserialize, Serialize}; - -use crate::error::RouteError; - -/// Supported JSON-RPC version -const SUPPORTED_VERSION: &str = "2.0"; - -/// JSON-RPC version -// TODO(tarcieri): add restrictions/validations on these formats? Use an `enum`? -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, PartialOrd, Ord, Serialize)] -pub struct Version(String); - -impl Version { - /// Get the currently supported JSON-RPC version - pub fn current() -> Self { - Version(SUPPORTED_VERSION.to_owned()) - } - - /// Is this JSON-RPC version supported? - pub fn is_supported(&self) -> bool { - self.0.eq(SUPPORTED_VERSION) - } - - /// Ensure we have a supported version or return an error - pub fn ensure_supported(&self) -> Result<(), RouteError> { - if self.is_supported() { - Ok(()) - } else { - Err(RouteError::CustomError(format!( - "Unsupported JSON-RPC version: {}", - self.0 - ))) - } - } -} - -impl Display for Version { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.0) - } -} - -impl FromStr for Version { - type Err = RouteError; - - fn from_str(s: &str) -> Result { - Ok(Version(s.to_owned())) - } -} diff --git a/route/cosmwasm/src/cosmwasm/rpc/wrapper.rs b/route/cosmwasm/src/cosmwasm/rpc/wrapper.rs deleted file mode 100644 index cbc7d3c6..00000000 --- a/route/cosmwasm/src/cosmwasm/rpc/wrapper.rs +++ /dev/null @@ -1,61 +0,0 @@ -use crate::*; - -use super::{response_error::ResponseError, version::Version}; - -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct Wrapper { - /// JSON-RPC version - pub jsonrpc: Version, - - /// Identifier included in request - pub id: Id, - - /// Results of request (if successful) - pub result: Option, - - /// Error message if unsuccessful - pub error: Option, -} - -impl Wrapper { - /// Get JSON-RPC version - pub fn version(&self) -> &Version { - &self.jsonrpc - } - - /// Get JSON-RPC ID - #[allow(dead_code)] - pub fn id(&self) -> &Id { - &self.id - } - - /// Convert this wrapper into the underlying error, if any - pub fn into_error(self) -> Option { - self.error.map(|e| RouteError::CustomError(e.to_string())) - } - - /// Convert this wrapper into a result type - pub fn into_result(self) -> Result { - // Ensure we're using a supported RPC version - self.version().ensure_supported()?; - - if let Some(e) = self.error { - Err(RouteError::CustomError(e.to_string())) - } else if let Some(result) = self.result { - Ok(result) - } else { - Err(RouteError::CustomError( - "No result or error in response".to_string(), - )) - } - } - - pub fn new_with_id(id: Id, result: Option, error: Option) -> Self { - Self { - jsonrpc: Version::current(), - id, - result, - error, - } - } -} diff --git a/route/cosmwasm/src/error.rs b/route/cosmwasm/src/error.rs deleted file mode 100644 index 6a977832..00000000 --- a/route/cosmwasm/src/error.rs +++ /dev/null @@ -1,32 +0,0 @@ -use candid::{CandidType, Nat, Principal}; -use serde::{Deserialize, Serialize}; - -pub type Result = std::result::Result; - -#[derive(thiserror::Error, Debug, CandidType, Serialize, Deserialize)] -pub enum RouteError { - #[error("Call {0} of {1} failed, code: {2:?}, message: {3}")] - CallError(String, Principal, String, String), - #[error("Http out call failed, code: {0:?}, message: {1}, request: {2}")] - HttpOutCallError(String, String, String), - #[error("Http status code: {0:?}, url: {1}, body: {2}")] - HttpStatusError(Nat, String, String), - #[error("Sign with ecdsa error, reject code {0}, message: {1}")] - SignWithEcdsaError(String, String), - #[error("Query ecdsa public key error, reject code {0}, message: {1}")] - QueryEcdsaPublicKeyError(String, String), - #[error("Event not found, kind: {0}")] - EventNotFound(String), - #[error("Attribute parse error, key: {0}, event kind: {1}, error: {2}")] - AttributeParseError(String, String, String), - #[error("Attribute not found, key: {0}, event kind: {1}")] - AttributeNotFound(String, String), - #[error("Failed to send ticket, error: {0}")] - SendTicketErr(String), - #[error("Failed to confirm mint token, seq: {0}, tx_hash: {1}")] - ConfirmExecuteDirectiveErr(u64, String), - #[error("Failed to confirm mint token, mint_token_request: {0}, tx_hash: {1}")] - ConfirmMintTokenErr(String, String), - #[error("{0}")] - CustomError(String), -} diff --git a/route/cosmwasm/src/guard.rs b/route/cosmwasm/src/guard.rs deleted file mode 100644 index ffa8a982..00000000 --- a/route/cosmwasm/src/guard.rs +++ /dev/null @@ -1,25 +0,0 @@ -use crate::memory::mutate_guard_running_task; - -#[must_use] -pub struct LogicGuard(String); - -impl LogicGuard { - pub fn new(task_name: String) -> Option { - mutate_guard_running_task(|s| { - if s.contains(&task_name) { - return None::; - } - - s.insert(task_name.clone()); - Some(LogicGuard(task_name)) - }) - } -} - -impl Drop for LogicGuard { - fn drop(&mut self) { - mutate_guard_running_task(|s| { - s.remove(&self.0); - }); - } -} diff --git a/route/cosmwasm/src/hub.rs b/route/cosmwasm/src/hub.rs deleted file mode 100644 index 8b2f0318..00000000 --- a/route/cosmwasm/src/hub.rs +++ /dev/null @@ -1,102 +0,0 @@ -use crate::*; -use omnity_types::Directive; - -pub async fn send_ticket(hub_principal: Principal, ticket: Ticket) -> Result<()> { - // TODO determine how many cycle it will cost. - let cost_cycles = 4_000_000_000_u64; - - let resp: (std::result::Result<(), omnity_types::Error>,) = - ic_cdk::api::call::call_with_payment(hub_principal, "send_ticket", (ticket,), cost_cycles) - .await - .map_err(|(code, message)| { - RouteError::CallError( - "send_ticket".to_string(), - hub_principal, - format!("{:?}", code).to_string(), - message, - ) - })?; - let data = resp - .0 - .map_err(|err| RouteError::CustomError(format!("Error calling send_ticket: {:?}", err)))?; - Ok(data) -} - -pub async fn query_tickets( - hub_principal: Principal, - offset: u64, - limit: u64, -) -> Result> { - let resp: (std::result::Result, omnity_types::Error>,) = - ic_cdk::api::call::call( - hub_principal, - "query_tickets", - (None::>, offset, limit), - ) - .await - .map_err(|(code, message)| { - RouteError::CallError( - "query_tickets".to_string(), - hub_principal, - format!("{:?}", code).to_string(), - message, - ) - })?; - - resp.0.map_err(|err| { - RouteError::CustomError(format!("Error calling query_tickets: {:?}", err).to_string()) - }) -} - -pub async fn query_directives( - hub_principal: Principal, - offset: u64, - limit: u64, -) -> Result> { - let resp: (std::result::Result, omnity_types::Error>,) = - ic_cdk::api::call::call( - hub_principal, - "query_directives", - ( - None::>, - None::>, - offset, - limit, - ), - ) - .await - .map_err(|(code, message)| { - RouteError::CallError( - "query_directives".to_string(), - hub_principal, - format!("{:?}", code).to_string(), - message, - ) - })?; - let data = resp.0.map_err(|err| { - RouteError::CustomError(format!("Error calling query_directives: {:?}", err).to_string()) - })?; - Ok(data) -} - -pub async fn update_tx_hash( - hub_principal: Principal, - ticket_id: TicketId, - mint_tx_hash: String, -) -> Result<()> { - let resp: (std::result::Result<(), omnity_types::Error>,) = - ic_cdk::api::call::call(hub_principal, "update_tx_hash", (ticket_id, mint_tx_hash)) - .await - .map_err(|(code, message)| { - RouteError::CallError( - "update_tx_hash".to_string(), - hub_principal, - format!("{:?}", code).to_string(), - message, - ) - })?; - resp.0.map_err(|err| { - RouteError::CustomError(format!("Error calling update_tx_hash: {:?}", err).to_string()) - })?; - Ok(()) -} diff --git a/route/cosmwasm/src/lib.rs b/route/cosmwasm/src/lib.rs deleted file mode 100644 index cf648fec..00000000 --- a/route/cosmwasm/src/lib.rs +++ /dev/null @@ -1,70 +0,0 @@ -pub mod business; -pub mod cosmwasm; -pub mod error; -pub mod guard; -pub mod hub; -pub mod lifecycle; -pub mod memory; -pub mod service; -pub mod state; -pub mod utils; -pub mod periodic_jobs; - -pub use candid::Principal; -pub use error::Result; -pub use error::RouteError; -pub use serde::{Deserialize, Serialize}; - -pub use cosmrs::{ - cosmwasm::MsgExecuteContract, - proto, tendermint, - tx::{self, AccountNumber, Fee, Msg, Raw, SignDoc, SignerInfo}, - AccountId, Coin, -}; -pub use ic_cdk::api::{ - call::RejectionCode, - management_canister::http_request::{ - http_request, CanisterHttpRequestArgument, HttpHeader, HttpMethod, - }, -}; -pub use num_traits::sign; -pub use omnity_types::Token; -pub use serde_bytes::ByteBuf; -pub use serde_json::json; -pub use state::*; - -pub use crate::utils::Id; -pub use cosmwasm::TxHash; - -pub use omnity_types::TicketId; -pub use omnity_types::Topic; -pub use omnity_types::{self, ChainId, Seq, Ticket}; - -pub use ic_cdk::api::management_canister::{ - ecdsa::{ - ecdsa_public_key, sign_with_ecdsa, EcdsaKeyId, EcdsaPublicKeyArgument, - EcdsaPublicKeyResponse, SignWithEcdsaArgument, SignWithEcdsaResponse, - }, - http_request::HttpResponse, -}; -pub use omnity_types::EcdsaKeyIds; -pub use serde_json::Value; -pub use utils::*; - -pub use cosmwasm::client::{cw_chain_key_arg, query_cw_public_key, CosmWasmClient}; -pub use memory::get_contract_id; - -pub type DerivationPath = Vec>; -pub type JobName = String; -pub struct EcdsaChainKeyArg { - pub derivation_path: DerivationPath, - pub key_id: EcdsaKeyId, -} - -pub mod const_args { - pub const PROCESS_TICKET_JOB_NAME: &str = "PROCESS_TICKET_JOB_NAME"; - pub const PROCESS_DIRECTIVE_JOB_NAME: &str = "PROCESS_DIRECTIVE_JOB_NAME"; - pub const BATCH_QUERY_LIMIT: u64 = 20; - pub const INTERVAL_QUERY_DIRECTIVE: u64 = 60; - pub const INTERVAL_QUERY_TICKET: u64 = 60; -} diff --git a/route/cosmwasm/src/lifecycle.rs b/route/cosmwasm/src/lifecycle.rs deleted file mode 100644 index 3df01522..00000000 --- a/route/cosmwasm/src/lifecycle.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod init; -pub mod upgrade; diff --git a/route/cosmwasm/src/lifecycle/init.rs b/route/cosmwasm/src/lifecycle/init.rs deleted file mode 100644 index dbfb3f2e..00000000 --- a/route/cosmwasm/src/lifecycle/init.rs +++ /dev/null @@ -1,23 +0,0 @@ -use candid::{CandidType, Principal}; -use serde::{Deserialize, Serialize}; - -use crate::{memory::set_route_state, state::RouteState}; - -#[derive(CandidType, serde::Deserialize)] -pub enum RouteArg { - Init(InitArgs), -} - -#[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] -pub struct InitArgs { - pub cosmwasm_port_contract_address: String, - pub chain_id: String, - pub cw_rpc_url: String, - pub cw_rest_url: String, - pub hub_principal: Principal, -} - -pub fn init(args: InitArgs) { - let state = RouteState::from(args); - set_route_state(state); -} diff --git a/route/cosmwasm/src/lifecycle/upgrade.rs b/route/cosmwasm/src/lifecycle/upgrade.rs deleted file mode 100644 index ba2ed011..00000000 --- a/route/cosmwasm/src/lifecycle/upgrade.rs +++ /dev/null @@ -1,2 +0,0 @@ -#[allow(unused)] -pub fn post_upgrade() {} diff --git a/route/cosmwasm/src/memory.rs b/route/cosmwasm/src/memory.rs deleted file mode 100644 index 29972836..00000000 --- a/route/cosmwasm/src/memory.rs +++ /dev/null @@ -1,189 +0,0 @@ -use cosmrs::AccountId; -use ic_cdk_timers::TimerId; -use ic_stable_structures::{ - memory_manager::{MemoryId, MemoryManager, VirtualMemory}, - DefaultMemoryImpl, -}; -use ic_stable_structures::{Cell, StableBTreeMap}; -use omnity_types::TicketId; -use std::{cell::RefCell, collections::{HashMap, HashSet}}; - -use crate::{cosmwasm::TxHash, get_chain_time_seconds, JobName}; -use crate::RouteState; - -const LOG_MEMORY_ID: MemoryId = MemoryId::new(2); -const REDEEM_TICKETS_MEMORY_ID: MemoryId = MemoryId::new(3); -const ROUTE_STATE_MEMORY_ID: MemoryId = MemoryId::new(4); - -type InnerMemory = DefaultMemoryImpl; - -pub type Memory = VirtualMemory; - - - -thread_local! { - // static MEMORY: RefCell> = RefCell::new(Some(InnerMemory::default())); - - pub static PERIODIC_JOB_MANAGER_MAP: RefCell> = RefCell::default(); - - pub static GUARD_RUNNING_TASK: RefCell> = RefCell::default(); - - static MEMORY_MANAGER: RefCell> = - RefCell::new(MemoryManager::init(DefaultMemoryImpl::default())); - - static REDEEM_TICKETS: RefCell> = RefCell::new( - StableBTreeMap::init( - MEMORY_MANAGER.with(|m| m.borrow().get(REDEEM_TICKETS_MEMORY_ID)), - ) - ); - - static ROUTE_STATE: RefCell, Memory>> = RefCell::new( - Cell::init( - MEMORY_MANAGER.with(|m| m.borrow().get(ROUTE_STATE_MEMORY_ID)), - None - ).expect("Failed to init route state") - ); - -} - -pub fn insert_periodic_job_manager(job_name: JobName, periodic_job_manager: PeriodicJobManager) { - PERIODIC_JOB_MANAGER_MAP.with(|p| p.borrow_mut().insert(job_name, periodic_job_manager)); -} - -pub fn get_periodic_job_manager(job_name: &str) -> Option { - PERIODIC_JOB_MANAGER_MAP.with(|p| p.borrow().get(job_name).map(|e| e.clone())) -} - -pub fn mutate_periodic_job_manager(job_name: &str, f: F) -> R -where - F: FnOnce(&mut PeriodicJobManager) -> R, -{ - let mut periodic_job_manager = get_periodic_job_manager(job_name).expect("Failed to get periodic job manager"); - let r = f(&mut periodic_job_manager); - PERIODIC_JOB_MANAGER_MAP.with(|p| p.borrow_mut().insert(job_name.to_string(), periodic_job_manager)); - r -} - -#[derive(Debug, Clone)] -pub struct PeriodicJobManager { - pub job_name: JobName, - pub timer_id: TimerId, - pub is_running: bool, - pub create_time: u64, - pub last_execute_time: u64, - pub failed_times: u32, - pub next_execute_time: u64, - pub job_interval: u64, -} - -impl PeriodicJobManager { - pub fn new( - job_name: JobName, - timer_id: TimerId, - job_interval: u64, - )->PeriodicJobManager{ - Self { - job_name, - timer_id: timer_id, - is_running: false, - create_time: get_chain_time_seconds(), - last_execute_time: 0, - failed_times: 0, - next_execute_time: get_chain_time_seconds() + job_interval, - job_interval: job_interval, - } - } - - pub fn job_execute_success(&mut self) { - self.failed_times = 0; - self.last_execute_time = get_chain_time_seconds(); - self.next_execute_time = get_chain_time_seconds() + self.job_interval; - self.is_running = false; - } - pub fn job_execute_failed(&mut self) { - self.failed_times += 1; - self.last_execute_time = get_chain_time_seconds(); - self.next_execute_time = get_chain_time_seconds() + 2_u64.pow(self.failed_times) * self.job_interval; - self.is_running = false; - } - - pub fn should_execute(&self) -> bool { - self.is_running && get_chain_time_seconds() >= self.next_execute_time - } -} - -pub fn init_stable_log() -> StableBTreeMap, Vec, Memory> { - StableBTreeMap::init(MEMORY_MANAGER.with(|m| m.borrow().get(LOG_MEMORY_ID))) -} - -pub fn insert_redeem_ticket(tx_hash: TxHash, ticket_id: TicketId) { - REDEEM_TICKETS.with(|r| r.borrow_mut().insert(tx_hash, ticket_id)); -} - -pub fn get_redeem_tickets() -> HashMap { - REDEEM_TICKETS - .with_borrow(|r| - r.iter().collect() - ) -} - -pub fn get_redeem_ticket(tx_hash: &TxHash) -> Option { - REDEEM_TICKETS.with(|r| r.borrow().get(tx_hash).clone()) -} - -pub fn set_route_state(state: RouteState) { - ROUTE_STATE - .with(|r| r.borrow_mut().set(Some(state))) - .expect("Failed to set route state"); -} - -pub fn take_state() -> RouteState { - ROUTE_STATE.with(|r| { - r.borrow_mut() - .get() - .clone() - .expect("Failed to take route state") - }) -} - -pub fn read_state(f: F) -> R -where - F: FnOnce(&RouteState) -> R, -{ - ROUTE_STATE.with(|r| { - f(r.borrow() - .get() - .as_ref() - .expect("Failed to read route state")) - }) -} - -pub fn mutate_state(f: F) -> R -where - F: FnOnce(&mut RouteState) -> R, -{ - let mut route_state = ROUTE_STATE.with(|r| { - r.borrow_mut() - .get() - .clone() - .expect("Failed to mutate route state") - }); - let r = f(&mut route_state); - ROUTE_STATE - .with(|r| r.borrow_mut().set(Some(route_state))) - .expect("Failed to set route state"); - r -} - -pub fn mutate_guard_running_task(f: F) -> R -where - F: FnOnce(&mut HashSet) -> R, -{ - GUARD_RUNNING_TASK.with(|g| f(&mut *g.borrow_mut())) -} - -pub fn get_contract_id() -> AccountId { - read_state(|state| state.cw_port_contract_address.clone()) - .parse() - .unwrap() -} diff --git a/route/cosmwasm/src/periodic_jobs.rs b/route/cosmwasm/src/periodic_jobs.rs deleted file mode 100644 index 232d39ee..00000000 --- a/route/cosmwasm/src/periodic_jobs.rs +++ /dev/null @@ -1,49 +0,0 @@ -use std::time::Duration; - -use ic_cdk_timers::set_timer_interval; - -use crate::{business::{process_directive::process_directive_task, ticket_task::process_ticket_task}, const_args, memory::{insert_periodic_job_manager, PeriodicJobManager}}; - -pub fn start_all_periodic_jobs() { - start_process_directive_job(); - start_process_ticket_job(); -} - -pub fn start_process_directive_job() { - let interval = Duration::from_secs(const_args::INTERVAL_QUERY_DIRECTIVE); - let timer_id = set_timer_interval( - interval, - process_directive_task, - ); - - let job_name = const_args::PROCESS_DIRECTIVE_JOB_NAME.to_string(); - insert_periodic_job_manager( - job_name, - PeriodicJobManager::new( - const_args::PROCESS_DIRECTIVE_JOB_NAME.to_string(), - timer_id, - const_args::INTERVAL_QUERY_DIRECTIVE - ) - ); - -} - -pub fn start_process_ticket_job() { - let interval = Duration::from_secs(const_args::INTERVAL_QUERY_TICKET); - let timer_id = set_timer_interval( - interval, - process_ticket_task, - ); - - let job_name = const_args::PROCESS_TICKET_JOB_NAME.to_string(); - - insert_periodic_job_manager( - job_name, - PeriodicJobManager::new( - const_args::PROCESS_TICKET_JOB_NAME.to_string(), - timer_id, - const_args::INTERVAL_QUERY_DIRECTIVE - ) - ); - -} \ No newline at end of file diff --git a/route/cosmwasm/src/service.rs b/route/cosmwasm/src/service.rs deleted file mode 100644 index 6b98bdfb..00000000 --- a/route/cosmwasm/src/service.rs +++ /dev/null @@ -1,172 +0,0 @@ -use crate::memory::{get_redeem_tickets, init_stable_log, mutate_state, read_state, GUARD_RUNNING_TASK, PERIODIC_JOB_MANAGER_MAP }; -use crate::periodic_jobs::{start_process_directive_job, start_process_ticket_job}; -use crate::{ - business::redeem_token::redeem_token_and_send_ticket, - cosmwasm::{ - client::{query_cw_public_key, OSMO_ACCOUNT_PREFIX}, - TxHash, - }, -}; -use cosmrs::tendermint; -use ic_canisters_http_types::{HttpRequest, HttpResponse}; -use ic_cdk::{ - api::management_canister::http_request::TransformArgs, init, post_upgrade, query, update, -}; -use lifecycle::init::InitArgs; -use omnity_types::{ - log::{init_log, StableLogWriter}, - TicketId, -}; -use std::collections::{HashMap, HashSet}; - -use crate::{lifecycle, RouteState, UpdateCwSettingsArgs}; - -#[init] -pub async fn init(args: InitArgs) { - lifecycle::init::init(args); - - init_log(Some(init_stable_log())); -} - -pub fn is_controller() -> std::result::Result<(), String> { - if ic_cdk::api::is_controller(&ic_cdk::caller()) { - Ok(()) - } else { - Err("caller is not controller".to_string()) - } -} - -#[update(guard = "is_controller")] -pub async fn cache_public_key() { - let public_key_response = query_cw_public_key() - .await - .expect("failed to query cw public key"); - - mutate_state(|state| { - state.cw_public_key_vec = Some(public_key_response.public_key.clone()); - }); -} - -#[update(guard = "is_controller")] -pub async fn start_process_directive() { - start_process_directive_job(); -} - -#[update(guard = "is_controller")] -pub async fn start_process_ticket() { - start_process_ticket_job(); -} - -#[update] -pub async fn redeem(tx_hash: TxHash) -> std::result::Result { - let _ = match crate::guard::LogicGuard::new(format!("redeem_{}", tx_hash)) { - Some(guard) => guard, - None => return Err("redeem task is running".to_string()), - }; - - match redeem_token_and_send_ticket(tx_hash.clone()).await { - Ok(ticket_id) => { - log::info!( - "send redeem ticket success: {:?}, tx_hash: {:?}", - ticket_id, - tx_hash - ); - - Ok(ticket_id) - } - Err(error) => { - log::error!( - "send redeem ticket failed: {:?}, tx_hash: {:?}", - error, - tx_hash - ); - Err(error.to_string()) - } - } -} - -#[update(guard = "is_controller")] -pub async fn osmosis_account_id() -> std::result::Result { - let public_key_response = query_cw_public_key() - .await - .expect("failed to query cw public key"); - - let tendermint_public_key = tendermint::public_key::PublicKey::from_raw_secp256k1( - public_key_response.public_key.as_slice(), - ) - .expect("failed to init tendermint public key"); - - let sender_public_key = cosmrs::crypto::PublicKey::from(tendermint_public_key); - let sender_account_id = sender_public_key.account_id(OSMO_ACCOUNT_PREFIX).unwrap(); - Ok(sender_account_id.to_string()) -} - -#[query(guard = "is_controller")] -pub fn route_state() -> (RouteState, String, HashSet) { - ( - read_state(|s| s.clone()), - PERIODIC_JOB_MANAGER_MAP.with(|m| format!("{:?}", m.borrow()).to_string()), - GUARD_RUNNING_TASK.with(|g| g.borrow().clone()), - ) -} - -#[update(guard = "is_controller")] -pub fn update_cw_settings(args: UpdateCwSettingsArgs) { - mutate_state(|state| { - if let Some(cw_rpc_url) = args.cw_rpc_url { - state.cw_rpc_url = cw_rpc_url; - } - - if let Some(cw_rest_url) = args.cw_rest_url { - state.cw_rest_url = cw_rest_url; - } - - if let Some(cw_port_contract_address) = args.cw_port_contract_address { - state.cw_port_contract_address = cw_port_contract_address; - } - - if let Some(multi_rpc_config) = args.multi_rpc_config { - state.multi_rpc_config = multi_rpc_config; - } - log::info!("update cw settings, new state: {:?}", state); - }); -} - -#[query(hidden = true)] -fn http_request(req: HttpRequest) -> HttpResponse { - StableLogWriter::http_request(req) -} - -#[query(hidden = true)] -fn cleanup_response( - mut args: TransformArgs, -) -> ic_cdk::api::management_canister::http_request::HttpResponse { - // The response header contains non-deterministic fields that make it impossible to reach consensus! - // Errors seem deterministic and do not contain data that can break consensus. - // Clear non-deterministic fields from the response headers. - - args.response.headers.clear(); - args.response -} - -#[query(guard = "is_controller")] -fn query_redeemed_tickets() -> HashMap { - get_redeem_tickets() -} - -#[post_upgrade] -fn post_upgrade() { - init_log(Some(init_stable_log())); - - lifecycle::upgrade::post_upgrade(); - - start_process_directive_job(); - start_process_ticket_job(); - - log::info!( - "Finish Upgrade current version: {}", - env!("CARGO_PKG_VERSION") - ); -} - -ic_cdk::export_candid!(); diff --git a/route/cosmwasm/src/state.rs b/route/cosmwasm/src/state.rs deleted file mode 100644 index 1ca64a5e..00000000 --- a/route/cosmwasm/src/state.rs +++ /dev/null @@ -1,77 +0,0 @@ - -use candid::{CandidType, Principal}; -use ic_stable_structures::storable::Bound; -use ic_stable_structures::Storable; -use omnity_types::{ChainState, Directive, Seq, Ticket}; -use serde::{Deserialize, Serialize}; -use serde_bytes::ByteBuf; - -use crate::{cosmwasm::client::MultiRpcConfig, lifecycle::init::InitArgs}; - -#[derive(CandidType, Clone, Debug, Deserialize, Serialize)] -pub struct RouteState { - pub cw_port_contract_address: String, - pub cw_chain_key_derivation_path: Vec, - pub chain_id: String, - pub cw_rpc_url: String, - pub cw_rest_url: String, - pub hub_principal: Principal, - pub next_directive_seq: u64, - - pub chain_state: ChainState, - pub next_ticket_seq: u64, - - pub cw_public_key_vec: Option>, - - #[serde(default)] - pub processing_tickets: Vec<(Seq, Ticket)>, - #[serde(default)] - pub processing_directive: Vec<(Seq, Directive)>, - #[serde(default)] - pub multi_rpc_config: MultiRpcConfig, -} - -impl Storable for RouteState { - const BOUND: Bound = Bound::Unbounded; - - fn to_bytes(&self) -> std::borrow::Cow<[u8]> { - serde_cbor::to_vec(self) - .expect("Failed to serialize token ledger.") - .into() - } - - fn from_bytes(bytes: std::borrow::Cow<[u8]>) -> Self { - serde_cbor::from_slice(&bytes).expect("Failed to deserialize token ledger.") - } -} - -impl From for RouteState { - fn from(args: InitArgs) -> Self { - Self { - cw_port_contract_address: args.cosmwasm_port_contract_address, - cw_chain_key_derivation_path: [vec![1u8; 4]] // Example derivation path for signing - .iter() - .map(|v| ByteBuf::from(v.clone())) - .collect(), - chain_id: args.chain_id, - cw_rpc_url: args.cw_rpc_url, - cw_rest_url: args.cw_rest_url, - hub_principal: args.hub_principal, - next_directive_seq: 0, - chain_state: ChainState::Active, - next_ticket_seq: 0, - cw_public_key_vec: None, - processing_tickets: Vec::default(), - processing_directive: Vec::default(), - multi_rpc_config: MultiRpcConfig::default(), - } - } -} - -#[derive(CandidType, Clone, Debug, Deserialize, Serialize)] -pub struct UpdateCwSettingsArgs { - pub cw_rpc_url: Option, - pub cw_rest_url: Option, - pub cw_port_contract_address: Option, - pub multi_rpc_config: Option -} diff --git a/route/cosmwasm/src/utils.rs b/route/cosmwasm/src/utils.rs deleted file mode 100644 index bea30449..00000000 --- a/route/cosmwasm/src/utils.rs +++ /dev/null @@ -1,132 +0,0 @@ -use crate::*; -use base64::engine::general_purpose; -use candid::Nat; -use ic_cdk::api::management_canister::http_request::{HttpResponse, TransformContext}; -use serde::{Deserialize, Serialize}; - -pub fn get_chain_time_seconds() -> u64 { - ic_cdk::api::time() / 1_000_000_000 -} - -/// JSON-RPC ID: request-specific identifier -#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd)] -#[serde(untagged)] -pub enum Id { - /// Numerical JSON ID - Num(i64), - /// String JSON ID - Str(String), - /// null JSON ID - None, -} - -impl Id { - /// Create a JSON-RPC ID containing a UUID v4 (i.e. random) - pub fn uuid_v4() -> Self { - Self::Str(uuid_str()) - } -} - -pub fn uuid_str() -> String { - // let bytes: [u8; 16] = rand::thread_rng().gen(); - // todo use icp native random number generator - let bytes: [u8; 16] = [1; 16]; - let uuid = uuid::Builder::from_random_bytes(bytes).into_uuid(); - uuid.to_string() -} - -pub fn bytes_to_base64(bytes: &[u8]) -> String { - base64::Engine::encode(&general_purpose::STANDARD, bytes) -} - -pub fn bytes_to_hex(bytes: &[u8]) -> String { - bytes.iter().map(|b| format!("{:02x}", b)).collect() -} - -pub async fn http_request_with_status_check( - mut request: CanisterHttpRequestArgument, -) -> Result { - request.transform = Some(TransformContext::from_name( - "cleanup_response".to_owned(), - vec![], - )); - - // let cycles = http_request_required_cycles(&request, 13); - let response = http_request(request.clone(), 50_000_000_000) - .await - .map_err(|(code, message)| { - RouteError::HttpOutCallError( - format!("{:?}", code).to_string(), - message, - format!("{:?}", request), - ) - })? - .0; - log::info!( - "Http status code: {:?}, url: {}, response body: {}", - response.status, - request.url, - String::from_utf8_lossy(&response.body) - ); - if response.status != Nat::from(200u64) { - return Err(RouteError::HttpStatusError( - response.status.clone(), - request.url.clone(), - String::from_utf8_lossy(&response.body).to_string(), - )); - } - Ok(response) -} - -pub fn sha256(input: Vec) -> [u8; 32] { - use sha2::Digest; - let mut hasher = sha2::Sha256::new(); - hasher.update(input); - hasher.finalize().into() -} - -/// Calculates the baseline cost of sending a JSON-RPC request using HTTP outcalls. -pub fn http_request_required_cycles( - arg: &CanisterHttpRequestArgument, - nodes_in_subnet: u32, -) -> u128 { - const HTTP_OUTCALL_REQUEST_BASE_COST: u128 = 3_000_000; - const HTTP_OUTCALL_REQUEST_PER_NODE_COST: u128 = 60_000; - const HTTP_OUTCALL_REQUEST_COST_PER_BYTE: u128 = 400; - const HTTP_OUTCALL_RESPONSE_COST_PER_BYTE: u128 = 800; - let max_response_bytes = match arg.max_response_bytes { - Some(ref n) => *n as u128, - None => 2 * 1024 * 1024, // default 2MiB - }; - let nodes_in_subnet = nodes_in_subnet as u128; - - // The coefficients can be found in [this page](https://internetcomputer.org/docs/current/developer-docs/production/computation-and-storage-costs). - // 12 is "http_request".len(). - - let request_bytes = candid::utils::encode_args((arg,)) - .expect("Failed to encode arguments.") - .len() as u128 - + 12; - - (HTTP_OUTCALL_REQUEST_BASE_COST - + HTTP_OUTCALL_REQUEST_PER_NODE_COST * nodes_in_subnet - + HTTP_OUTCALL_REQUEST_COST_PER_BYTE * request_bytes - + HTTP_OUTCALL_RESPONSE_COST_PER_BYTE * max_response_bytes) - * nodes_in_subnet - * 3 -} - -#[test] -pub fn test_show_address() { - #[derive(Serialize, Deserialize)] - struct Account { - pub address: String, - }; - - let account = Account { - address: "osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks".to_string(), - }; - let bytes = serde_json::to_string(&account).unwrap().into_bytes(); - let hex = bytes_to_hex(&bytes); - dbg!(&hex); -} diff --git a/route/cosmwasm/tests/pocket.rs b/route/cosmwasm/tests/pocket.rs deleted file mode 100644 index 7fdf9e82..00000000 --- a/route/cosmwasm/tests/pocket.rs +++ /dev/null @@ -1,211 +0,0 @@ -// use candid::{decode_one, encode_one, types::principal, CandidType, Encode, Principal}; -// use cosmoswasm_route::{ -// lifecycle::init::InitArgs, -// schnorr::{SchnorrKeyIds, SchnorrPublicKeyArgs, SchnorrPublicKeyResult}, -// RouteError, -// }; -// use ic_cdk::api::management_canister::http_request::HttpResponse; -// // use ic_base_types::{CanisterId, PrincipalId}; -// // use ic_stable_structures::vec; -// use pocket_ic::{PocketIc, PocketIcBuilder, WasmResult}; -// use serde::Deserialize; -// use serde_bytes::ByteBuf; -// use std::path::Path; - -// const SCHNORR_WASM: &[u8] = include_bytes!("../schnorr_canister.wasm"); -// const CW_ROUTE_WASM: &[u8] = include_bytes!("../cosmoswasm_route.wasm"); - -// fn load_schnorr_canister_wasm() -> Vec { -// use flate2::write::GzEncoder; -// use flate2::Compression; -// use std::io::prelude::*; - -// // let wasm_path = Path::new("../schnorr_canister.wasm"); -// dbg!(&SCHNORR_WASM.len()); -// let wasm_bytes = SCHNORR_WASM.to_vec(); -// // let wasm_bytes: Vec = vec![]; - -// let mut e = GzEncoder::new(Vec::new(), Compression::default()); -// e.write_all(wasm_bytes.as_slice()).unwrap(); -// let zipped_bytes = e.finish().unwrap(); - -// zipped_bytes -// } - -// fn load_cw_route_canister_wasm() -> Vec { -// use flate2::write::GzEncoder; -// use flate2::Compression; -// use std::io::prelude::*; - -// // let wasm_path = Path::new("../schnorr_canister.wasm"); -// dbg!(&CW_ROUTE_WASM.len()); -// let wasm_bytes = CW_ROUTE_WASM.to_vec(); -// // let wasm_bytes: Vec = vec![]; - -// let mut e = GzEncoder::new(Vec::new(), Compression::default()); -// e.write_all(wasm_bytes.as_slice()).unwrap(); -// let zipped_bytes = e.finish().unwrap(); - -// zipped_bytes -// } - -// pub struct Setup { -// pub cosmoswasm_route: Principal, -// pub schnorr_canister: Principal, -// pub pic: PocketIc, -// pub caller: Principal, -// } - -// // pub fn principal_to_canister_id(principal: Principal) -> CanisterId { -// // let principal_id: PrincipalId = principal.into(); -// // CanisterId::unchecked_from_principal(principal_id) -// // } - -// pub fn fast_forward(ic: &PocketIc, ticks: u64) { -// for _ in 0..ticks - 1 { -// ic.tick(); -// } -// } - -// pub fn update Deserialize<'de>>( -// ic: &PocketIc, -// sender: Principal, -// receiver: Principal, -// method: &str, -// args: Vec, -// ) -> Result { -// match ic.update_call(receiver, sender, method, args) { -// Ok(WasmResult::Reply(data)) => { -// dbg!(&data); -// Ok(decode_one(&data).unwrap()) -// } -// Ok(WasmResult::Reject(error_message)) => Err(error_message.to_string()), -// Err(user_error) => Err(user_error.to_string()), -// } -// } - -// const INIT_CYCLES: u128 = 2_000_000_000_000; - -// pub fn create_canister(ic: &PocketIc, env_key: &str) -> Principal { -// let canister_id = ic.create_canister(); -// ic.add_cycles(canister_id, INIT_CYCLES); - -// let wasm_path = -// std::env::var_os(env_key).unwrap_or_else(|| panic!("Missing `{}` env variable", env_key)); - -// // let wasm_module = std::fs::read(wasm_path).unwrap(); -// let wasm_module = load_schnorr_canister_wasm(); - -// ic.install_canister(canister_id, wasm_module, vec![], None); -// canister_id -// } - -// impl Setup { -// pub fn new() -> Self { -// let pic = PocketIcBuilder::new().with_application_subnet().build(); - -// let schnorr_canister_id = pic.create_canister(); -// pic.add_cycles(schnorr_canister_id, 2_000_000_000_000); -// pic.install_canister( -// schnorr_canister_id.clone().into(), -// load_schnorr_canister_wasm(), -// vec![], -// None, -// ); -// fast_forward(&pic, 5); - -// dbg!("Schnorr canister installed"); - -// let cosmoswasm_route_principal = pic.create_canister(); -// pic.add_cycles(cosmoswasm_route_principal, 2_000_000_000_000); -// let arg = InitArgs { -// schnorr_canister_principal: schnorr_canister_id, -// cosmoswasm_port_contract_address: "osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks" -// .to_string(), -// chain_id: "localosmosis".to_string(), -// cw_rpc_url: "http://localhost:26657".to_string(), -// }; -// pic.install_canister( -// cosmoswasm_route_principal.into(), -// load_cw_route_canister_wasm(), -// Encode!(&arg).unwrap(), -// None, -// ); -// fast_forward(&pic, 5); - -// dbg!("Cosmoswasm route canister installed"); - -// Self { -// cosmoswasm_route: cosmoswasm_route_principal, -// schnorr_canister: schnorr_canister_id.into(), -// pic, -// caller: Principal::anonymous(), -// } -// } - -// fn schnorr_public_key(&self) { -// let derivation_path: Vec = [vec![1u8; 4]] // Example derivation path for signing -// .iter() -// .map(|v| ByteBuf::from(v.clone())) -// .collect(); - -// let public_arg = SchnorrPublicKeyArgs { -// canister_id: None, -// derivation_path: derivation_path.clone(), -// key_id: SchnorrKeyIds::TestKey1.to_key_id(), -// }; - -// let res: Result = update( -// &self.pic, -// self.caller, -// self.schnorr_canister, -// "schnorr_public_key", -// encode_one(public_arg).unwrap(), -// ); - -// dbg!(&res); -// } - -// fn add_token(&self) { -// let res: Result, String> = update( -// &self.pic, -// self.caller, -// self.cosmoswasm_route, -// "test_add_token", -// encode_one(()).unwrap(), -// ); - -// dbg!(&res); -// } - -// fn cosmos_address(&self) { -// let res: Result, String> = update( -// &self.pic, -// self.caller, -// self.cosmoswasm_route, -// "cosmos_address", -// encode_one(()).unwrap(), -// ); - -// dbg!(&res); -// } -// } - -// #[test] -// fn test_schnorr_by_pocket_ic() { -// let setup = Setup::new(); -// setup.schnorr_public_key(); -// } - -// #[test] -// fn test_add_token() { -// let setup = Setup::new(); -// setup.add_token(); -// } - -// #[test] -// pub fn test_show_address() { -// let setup = Setup::new(); -// let address = setup.cosmos_address(); -// dbg!(&address); -// } diff --git a/route/cosmwasm/tests/tests.rs b/route/cosmwasm/tests/tests.rs deleted file mode 100644 index 532c4885..00000000 --- a/route/cosmwasm/tests/tests.rs +++ /dev/null @@ -1,134 +0,0 @@ -// use candid::{Decode, Encode, Principal}; -// use cosmoswasm_route::{ -// lifecycle::init::InitArgs, -// schnorr::{SchnorrKeyIds, SchnorrPublicKeyArgs, SchnorrPublicKeyResult}, -// }; -// use cosmrs::tendermint::serializers::bytes; -// use ic_base_types::{CanisterId, PrincipalId}; -// use ic_state_machine_tests::{StateMachine, WasmResult}; -// use ic_test_utilities_load_wasm::load_wasm; -// use omnity_types::Token; -// use pocket_ic::PocketIc; -// use serde_bytes::ByteBuf; - -// const SCHNORR_WASM: &[u8] = include_bytes!("../schnorr_canister.wasm"); - -// // fn install -// fn cw_wasm() -> Vec { -// load_wasm( -// std::env::var("CARGO_MANIFEST_DIR").unwrap(), -// "cosmoswasm_route", -// &[], -// ) -// } - -// fn install_cw_route_canister(env: &StateMachine, schnorr: Principal) -> CanisterId { -// let payload = InitArgs { -// schnorr_canister_principal: schnorr, -// cosmoswasm_port_contract_address: "osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks".to_string(), -// chain_id: "localosmosis".to_string(), -// }; -// env.install_canister(cw_wasm(), Encode!(&payload).unwrap(), None) -// .unwrap() -// } - -// fn install_schnorr_canister(env: &StateMachine) -> CanisterId { -// env.install_canister(SCHNORR_WASM.to_vec(), vec![], None) -// .unwrap() -// } - -// struct Setup { -// pub env: StateMachine, -// pub schnorr: CanisterId, -// pub cw_route: CanisterId, -// pub caller: PrincipalId, -// // pub hub -// } - -// fn canister_id_to_principal(canister_id: &CanisterId) -> Principal { -// Principal::from_slice(&canister_id.get().into_vec()) -// } - -// fn set_up() -> Setup { -// let env = StateMachine::new(); -// let schnorr = install_schnorr_canister(&env); -// let cw_route = install_cw_route_canister(&env, canister_id_to_principal(&schnorr)); -// let caller = PrincipalId::new_user_test_id(2); -// Setup { -// env, -// schnorr, -// cw_route, -// caller, -// } -// } - -// fn assert_reply(result: WasmResult) -> Vec { -// match result { -// WasmResult::Reply(bytes) => { -// dbg!(&bytes); -// bytes -// } -// WasmResult::Reject(reject) => { -// panic!("Expected a successful reply, got a reject: {}", reject) -// } -// } -// } - -// impl Setup { -// pub fn add_token(&self) { -// let _ = Decode!( -// &assert_reply( -// self.env -// .execute_ingress_as( -// self.caller, -// self.cw_route, -// "test_add_token", -// Encode!().unwrap() -// ) -// .unwrap() -// ), -// () -// ); -// } -// } - -// #[test] -// pub fn test_add_token() { -// let setup = set_up(); -// // let token = Token -// } - -// #[test] -// pub fn test_schnorr() { -// let setup = set_up(); - -// let derivation_path: Vec = [vec![1u8; 4]] // Example derivation path for signing -// .iter() -// .map(|v| ByteBuf::from(v.clone())) -// .collect(); - -// let key_id = SchnorrKeyIds::TestKey1.to_key_id(); - -// let payload = SchnorrPublicKeyArgs { -// // canister_id: Some(canister_id_to_principal(&setup.cw_route)), -// canister_id: None, -// derivation_path: derivation_path.clone(), -// key_id: key_id.clone(), -// }; -// let r = Decode!( -// &assert_reply( -// setup.env -// .execute_ingress_as( -// setup.caller, -// setup.schnorr, -// "schnorr_public_key", -// Encode!(&payload).unwrap() -// ) -// .unwrap() -// ), -// Result -// ) -// .unwrap(); - -// dbg!(&r); -// }