diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f156f340ecd..8e68b230953 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -44,6 +44,7 @@ go_deps.bzl @dfinity/idx /publish/ @dfinity/idx # [Packages] +/packages/icrc-cbor/ @dfinity/finint @dfinity/cross-chain-team /packages/icrc-ledger-agent/ @dfinity/finint /packages/icrc-ledger-types/ @dfinity/finint /packages/ic-ledger-hash-of/ @dfinity/finint diff --git a/Cargo.lock b/Cargo.lock index a5bd872d210..6d17b5bfcb9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6657,6 +6657,7 @@ dependencies = [ "ic-stable-structures", "ic-state-machine-tests", "ic-utils-ensure", + "icrc-cbor", "icrc-ledger-client-cdk", "icrc-ledger-types", "maplit", @@ -13980,6 +13981,18 @@ dependencies = [ "url", ] +[[package]] +name = "icrc-cbor" +version = "0.1.0" +dependencies = [ + "candid", + "ethnum", + "minicbor", + "num-bigint 0.4.6", + "num-traits", + "proptest", +] + [[package]] name = "icrc-ledger-agent" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index b5ee088939f..d1fc36cac12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ + "packages/icrc-cbor", "packages/icrc-ledger-agent", "packages/icrc-ledger-client", "packages/icrc-ledger-client-cdk", diff --git a/packages/icrc-cbor/BUILD.bazel b/packages/icrc-cbor/BUILD.bazel new file mode 100644 index 00000000000..172a3b4050b --- /dev/null +++ b/packages/icrc-cbor/BUILD.bazel @@ -0,0 +1,40 @@ +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") + +package(default_visibility = ["//visibility:public"]) + +[rust_library( + name = "icrc-cbor" + target_suffix, + srcs = glob(["src/*.rs"]), + crate_features = features, + crate_name = "icrc_cbor", + deps = [ + # Keep sorted. + "@crate_index//:candid", + "@crate_index//:minicbor", + "@crate_index//:num-bigint", + "@crate_index//:num-traits", + ] + extra_deps, +) for (target_suffix, features, extra_deps) in [ + ("", [], []), + ( + "_u256", + ["u256"], + ["@crate_index//:ethnum"], + ), +]] + +[rust_test( + name = "unit_tests" + target_suffix, + crate = ":icrc-cbor", + crate_features = features, + deps = [ + "@crate_index//:proptest", + ] + extra_deps, +) for (target_suffix, features, extra_deps) in [ + ("", [], []), + ( + "_u256", + ["u256"], + ["@crate_index//:ethnum"], + ), +]] diff --git a/packages/icrc-cbor/CHANGELOG.md b/packages/icrc-cbor/CHANGELOG.md new file mode 100644 index 00000000000..0d523739a83 --- /dev/null +++ b/packages/icrc-cbor/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +- Initial version of the library diff --git a/packages/icrc-cbor/Cargo.toml b/packages/icrc-cbor/Cargo.toml new file mode 100644 index 00000000000..7ef286a9a9c --- /dev/null +++ b/packages/icrc-cbor/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "icrc-cbor" +version = "0.1.0" +description = "Cbor encoders and decoders commonly used by the ICRC ledger types." +license = "Apache-2.0" +readme = "README.md" +include = ["src", "Cargo.toml", "CHANGELOG.md", "LICENSE", "README.md"] +repository = "https://github.com/dfinity/ic" +authors.workspace = true +edition.workspace = true +documentation.workspace = true + +[dependencies] +candid = { workspace = true } +ethnum = { workspace = true, optional = true } +minicbor = { workspace = true } +num-bigint = { workspace = true } +num-traits = { workspace = true } + +[dev-dependencies] +proptest = { workspace = true } + +[features] +default = [] +u256 = ["dep:ethnum"] diff --git a/packages/icrc-cbor/LICENSE b/packages/icrc-cbor/LICENSE new file mode 100644 index 00000000000..c970c263c3a --- /dev/null +++ b/packages/icrc-cbor/LICENSE @@ -0,0 +1,193 @@ +Copyright © 2024 DFINITY Foundation + +Each file in this repository is licensed under the license as +described in the LICENSE file in the same directory that contains the +file or, if that doesn't exist, the first LICENSE file in any +higher-level directory. + +Unless stated otherwise as described above, all files in this +directory are licensed under the Apache License, Version 2.0 (the +"License"); you may not use these files except in compliance with the +License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +The license is also copied below: + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/packages/icrc-cbor/README.md b/packages/icrc-cbor/README.md new file mode 100644 index 00000000000..d88f4124f97 --- /dev/null +++ b/packages/icrc-cbor/README.md @@ -0,0 +1,3 @@ +# ICRC Cbor + +This package defines cbor encoders and decoders commonly used by the ICRC ledger types. diff --git a/packages/icrc-cbor/src/lib.rs b/packages/icrc-cbor/src/lib.rs new file mode 100644 index 00000000000..21890f1e711 --- /dev/null +++ b/packages/icrc-cbor/src/lib.rs @@ -0,0 +1,7 @@ +pub mod nat; +pub mod principal; +#[cfg(feature = "u256")] +pub mod u256; + +#[cfg(test)] +pub mod tests; diff --git a/rs/ethereum/cketh/minter/src/cbor/nat.rs b/packages/icrc-cbor/src/nat.rs similarity index 95% rename from rs/ethereum/cketh/minter/src/cbor/nat.rs rename to packages/icrc-cbor/src/nat.rs index d981cc3c940..b901e56ceae 100644 --- a/rs/ethereum/cketh/minter/src/cbor/nat.rs +++ b/packages/icrc-cbor/src/nat.rs @@ -44,7 +44,7 @@ pub mod option { #[derive(Decode, Encode)] #[cbor(transparent)] - struct CborNat(#[cbor(n(0), with = "crate::cbor::nat")] pub Nat); + struct CborNat(#[cbor(n(0), with = "crate::nat")] pub Nat); pub fn decode(d: &mut Decoder<'_>, ctx: &mut Ctx) -> Result, Error> { Ok(Option::::decode(d, ctx)?.map(|n| n.0)) diff --git a/rs/ethereum/cketh/minter/src/cbor/principal.rs b/packages/icrc-cbor/src/principal.rs similarity index 92% rename from rs/ethereum/cketh/minter/src/cbor/principal.rs rename to packages/icrc-cbor/src/principal.rs index 731f7c3b851..10fe4627ddb 100644 --- a/rs/ethereum/cketh/minter/src/cbor/principal.rs +++ b/packages/icrc-cbor/src/principal.rs @@ -22,7 +22,7 @@ pub mod option { #[derive(Decode, Encode)] #[cbor(transparent)] - struct CborPrincipal(#[cbor(n(0), with = "crate::cbor::principal")] pub Principal); + struct CborPrincipal(#[cbor(n(0), with = "crate::principal")] pub Principal); pub fn decode(d: &mut Decoder<'_>, ctx: &mut Ctx) -> Result, Error> { Ok(Option::::decode(d, ctx)?.map(|n| n.0)) diff --git a/packages/icrc-cbor/src/tests.rs b/packages/icrc-cbor/src/tests.rs new file mode 100644 index 00000000000..ba0e45b37d2 --- /dev/null +++ b/packages/icrc-cbor/src/tests.rs @@ -0,0 +1,94 @@ +use candid::{Nat, Principal}; +#[cfg(feature = "u256")] +use ethnum::{u256, U256}; +use minicbor::{Decode, Encode}; +use proptest::collection::vec as pvec; +use proptest::prelude::*; + +pub fn check_roundtrip(v: &T) -> Result<(), TestCaseError> +where + for<'a> T: PartialEq + std::fmt::Debug + Encode<()> + Decode<'a, ()>, +{ + let mut buf = vec![]; + minicbor::encode(v, &mut buf).expect("encoding should succeed"); + let decoded = minicbor::decode(&buf).expect("decoding should succeed"); + prop_assert_eq!(v, &decoded); + Ok(()) +} + +#[cfg(feature = "u256")] +#[derive(Eq, PartialEq, Debug, Decode, Encode)] +struct U256Container { + #[cbor(n(0), with = "crate::u256")] + pub value: u256, +} + +#[derive(Eq, PartialEq, Debug, Decode, Encode)] +struct NatContainer { + #[cbor(n(0), with = "crate::nat")] + pub value: Nat, +} + +#[derive(Eq, PartialEq, Debug, Decode, Encode)] +struct OptNatContainer { + #[cbor(n(0), with = "crate::nat::option")] + pub value: Option, +} + +#[derive(Eq, PartialEq, Debug, Decode, Encode)] +struct PrincipalContainer { + #[cbor(n(0), with = "crate::principal")] + pub value: Principal, +} + +#[derive(Eq, PartialEq, Debug, Decode, Encode)] +struct OptPrincipalContainer { + #[cbor(n(0), with = "crate::principal::option")] + pub value: Option, +} + +proptest! { + #[cfg(feature = "u256")] + #[test] + fn u256_encoding_roundtrip((hi, lo) in (any::(), any::())) { + check_roundtrip(&U256Container { + value: U256([hi, lo]), + })?; + } + + #[cfg(feature = "u256")] + #[test] + fn u256_small_value_encoding_roundtrip(n in any::()) { + check_roundtrip(&U256Container { + value: u256::from(n), + })?; + } + + #[test] + fn nat_encoding_roundtrip(n in any::()) { + check_roundtrip(&NatContainer { + value: Nat::from(n), + })?; + } + + #[test] + fn opt_nat_encoding_roundtrip(n in proptest::option::of(any::())) { + check_roundtrip(&OptNatContainer { + value: n.map(Nat::from), + })?; + } + + #[test] + fn principal_encoding_roundtrip(p in pvec(any::(), 0..30)) { + check_roundtrip(&PrincipalContainer { + value: Principal::from_slice(&p), + })?; + } + + #[test] + fn opt_principal_encoding_roundtrip(p in proptest::option::of(pvec(any::(), 0..30))) { + check_roundtrip(&OptPrincipalContainer { + value: p.map(|principal| Principal::from_slice(&principal)), + })?; + } +} diff --git a/rs/ethereum/cketh/minter/src/cbor/u256.rs b/packages/icrc-cbor/src/u256.rs similarity index 100% rename from rs/ethereum/cketh/minter/src/cbor/u256.rs rename to packages/icrc-cbor/src/u256.rs diff --git a/rs/ethereum/cketh/minter/BUILD.bazel b/rs/ethereum/cketh/minter/BUILD.bazel index 428e8eafd14..a1ff214df31 100644 --- a/rs/ethereum/cketh/minter/BUILD.bazel +++ b/rs/ethereum/cketh/minter/BUILD.bazel @@ -42,6 +42,7 @@ rust_library( deps = [ # Keep sorted. "//packages/ic-ethereum-types", + "//packages/icrc-cbor:icrc-cbor_u256", "//packages/icrc-ledger-client-cdk:icrc_ledger_client_cdk", "//packages/icrc-ledger-types:icrc_ledger_types", "//rs/crypto/secp256k1", diff --git a/rs/ethereum/cketh/minter/Cargo.toml b/rs/ethereum/cketh/minter/Cargo.toml index 3f4bc89ad09..db2749603a0 100644 --- a/rs/ethereum/cketh/minter/Cargo.toml +++ b/rs/ethereum/cketh/minter/Cargo.toml @@ -31,6 +31,7 @@ ic-metrics-encoder = "1" ic-sha3 = { workspace = true } ic-stable-structures = { workspace = true } ic-utils-ensure = { path = "../../../utils/ensure" } +icrc-cbor = { path = "../../../../packages/icrc-cbor", features = ["u256"]} icrc-ledger-client-cdk = { path = "../../../../packages/icrc-ledger-client-cdk" } icrc-ledger-types = { path = "../../../../packages/icrc-ledger-types" } minicbor = { workspace = true } diff --git a/rs/ethereum/cketh/minter/src/cbor/mod.rs b/rs/ethereum/cketh/minter/src/cbor/mod.rs index 45ec72208fd..e5c5c9726b5 100644 --- a/rs/ethereum/cketh/minter/src/cbor/mod.rs +++ b/rs/ethereum/cketh/minter/src/cbor/mod.rs @@ -1,7 +1,4 @@ pub mod id; -pub mod nat; -pub mod principal; -pub mod u256; #[cfg(test)] pub mod tests; diff --git a/rs/ethereum/cketh/minter/src/cbor/tests.rs b/rs/ethereum/cketh/minter/src/cbor/tests.rs index 2c0b28382aa..a748b38955b 100644 --- a/rs/ethereum/cketh/minter/src/cbor/tests.rs +++ b/rs/ethereum/cketh/minter/src/cbor/tests.rs @@ -1,9 +1,6 @@ use crate::checked_amount::CheckedAmountOf; -use candid::{Nat, Principal}; -use ethnum::{u256, U256}; use minicbor::{Decode, Encode}; use phantom_newtype::Id; -use proptest::collection::vec as pvec; use proptest::prelude::*; pub fn check_roundtrip(v: &T) -> Result<(), TestCaseError> @@ -21,36 +18,6 @@ enum IdTag {} type U256Newtype = CheckedAmountOf; type U64Newtype = Id; -#[derive(Eq, PartialEq, Debug, Decode, Encode)] -struct U256Container { - #[cbor(n(0), with = "crate::cbor::u256")] - pub value: u256, -} - -#[derive(Eq, PartialEq, Debug, Decode, Encode)] -struct NatContainer { - #[cbor(n(0), with = "crate::cbor::nat")] - pub value: Nat, -} - -#[derive(Eq, PartialEq, Debug, Decode, Encode)] -struct OptNatContainer { - #[cbor(n(0), with = "crate::cbor::nat::option")] - pub value: Option, -} - -#[derive(Eq, PartialEq, Debug, Decode, Encode)] -struct PrincipalContainer { - #[cbor(n(0), with = "crate::cbor::principal")] - pub value: Principal, -} - -#[derive(Eq, PartialEq, Debug, Decode, Encode)] -struct OptPrincipalContainer { - #[cbor(n(0), with = "crate::cbor::principal::option")] - pub value: Option, -} - #[derive(Eq, PartialEq, Debug, Decode, Encode)] struct U256NewtypeContainer { #[cbor(n(0))] @@ -64,20 +31,6 @@ struct U64NewtypeContainer { } proptest! { - #[test] - fn u256_encoding_roundtrip((hi, lo) in (any::(), any::())) { - check_roundtrip(&U256Container { - value: U256([hi, lo]), - })?; - } - - #[test] - fn u256_small_value_encoding_roundtrip(n in any::()) { - check_roundtrip(&U256Container { - value: u256::from(n), - })?; - } - #[test] fn checked_amount_of_encoding_roundtrip((hi, lo) in (any::(), any::())) { check_roundtrip(&U256NewtypeContainer { @@ -91,32 +44,4 @@ proptest! { value: U64Newtype::new(n), })?; } - - #[test] - fn nat_encoding_roundtrip(n in any::()) { - check_roundtrip(&NatContainer { - value: Nat::from(n), - })?; - } - - #[test] - fn opt_nat_encoding_roundtrip(n in proptest::option::of(any::())) { - check_roundtrip(&OptNatContainer { - value: n.map(Nat::from), - })?; - } - - #[test] - fn principal_encoding_roundtrip(p in pvec(any::(), 0..30)) { - check_roundtrip(&PrincipalContainer { - value: Principal::from_slice(&p), - })?; - } - - #[test] - fn opt_principal_encoding_roundtrip(p in proptest::option::of(pvec(any::(), 0..30))) { - check_roundtrip(&OptPrincipalContainer { - value: p.map(|principal| Principal::from_slice(&principal)), - })?; - } } diff --git a/rs/ethereum/cketh/minter/src/checked_amount.rs b/rs/ethereum/cketh/minter/src/checked_amount.rs index 5e06f0b74ec..652bb4c33aa 100644 --- a/rs/ethereum/cketh/minter/src/checked_amount.rs +++ b/rs/ethereum/cketh/minter/src/checked_amount.rs @@ -292,13 +292,13 @@ impl minicbor::Encode for CheckedAmountOf { e: &mut minicbor::Encoder, ctx: &mut C, ) -> Result<(), minicbor::encode::Error> { - crate::cbor::u256::encode(&self.0, e, ctx) + icrc_cbor::u256::encode(&self.0, e, ctx) } } impl<'b, C, Unit> minicbor::Decode<'b, C> for CheckedAmountOf { fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result { - crate::cbor::u256::decode(d, ctx).map(Self::from_inner) + icrc_cbor::u256::decode(d, ctx).map(Self::from_inner) } } diff --git a/rs/ethereum/cketh/minter/src/erc20.rs b/rs/ethereum/cketh/minter/src/erc20.rs index 0963b894227..8256430068d 100644 --- a/rs/ethereum/cketh/minter/src/erc20.rs +++ b/rs/ethereum/cketh/minter/src/erc20.rs @@ -23,7 +23,7 @@ pub struct CkErc20Token { pub erc20_contract_address: Address, #[n(2)] pub ckerc20_token_symbol: CkTokenSymbol, - #[cbor(n(3), with = "crate::cbor::principal")] + #[cbor(n(3), with = "icrc_cbor::principal")] pub ckerc20_ledger_id: Principal, } diff --git a/rs/ethereum/cketh/minter/src/eth_logs/mod.rs b/rs/ethereum/cketh/minter/src/eth_logs/mod.rs index 22cf3910894..0bb8207dcff 100644 --- a/rs/ethereum/cketh/minter/src/eth_logs/mod.rs +++ b/rs/ethereum/cketh/minter/src/eth_logs/mod.rs @@ -47,7 +47,7 @@ pub struct ReceivedEthEvent { pub from_address: Address, #[n(4)] pub value: Wei, - #[cbor(n(5), with = "crate::cbor::principal")] + #[cbor(n(5), with = "icrc_cbor::principal")] pub principal: Principal, #[n(6)] pub subaccount: Option, @@ -65,7 +65,7 @@ pub struct ReceivedErc20Event { pub from_address: Address, #[n(4)] pub value: Erc20Value, - #[cbor(n(5), with = "crate::cbor::principal")] + #[cbor(n(5), with = "icrc_cbor::principal")] pub principal: Principal, #[n(6)] pub erc20_contract_address: Address, diff --git a/rs/ethereum/cketh/minter/src/lifecycle/init.rs b/rs/ethereum/cketh/minter/src/lifecycle/init.rs index e982da95f58..749e03d663d 100644 --- a/rs/ethereum/cketh/minter/src/lifecycle/init.rs +++ b/rs/ethereum/cketh/minter/src/lifecycle/init.rs @@ -19,15 +19,15 @@ pub struct InitArg { pub ecdsa_key_name: String, #[n(2)] pub ethereum_contract_address: Option, - #[cbor(n(3), with = "crate::cbor::principal")] + #[cbor(n(3), with = "icrc_cbor::principal")] pub ledger_id: Principal, #[n(4)] pub ethereum_block_height: CandidBlockTag, - #[cbor(n(6), with = "crate::cbor::nat")] + #[cbor(n(6), with = "icrc_cbor::nat")] pub minimum_withdrawal_amount: Nat, - #[cbor(n(7), with = "crate::cbor::nat")] + #[cbor(n(7), with = "icrc_cbor::nat")] pub next_transaction_nonce: Nat, - #[cbor(n(8), with = "crate::cbor::nat")] + #[cbor(n(8), with = "icrc_cbor::nat")] pub last_scraped_block_number: Nat, } diff --git a/rs/ethereum/cketh/minter/src/lifecycle/upgrade.rs b/rs/ethereum/cketh/minter/src/lifecycle/upgrade.rs index 841ac280e88..d00fae4f1a2 100644 --- a/rs/ethereum/cketh/minter/src/lifecycle/upgrade.rs +++ b/rs/ethereum/cketh/minter/src/lifecycle/upgrade.rs @@ -10,25 +10,25 @@ use minicbor::{Decode, Encode}; #[derive(Clone, Eq, PartialEq, Debug, Default, CandidType, Decode, Deserialize, Encode)] pub struct UpgradeArg { - #[cbor(n(0), with = "crate::cbor::nat::option")] + #[cbor(n(0), with = "icrc_cbor::nat::option")] pub next_transaction_nonce: Option, - #[cbor(n(1), with = "crate::cbor::nat::option")] + #[cbor(n(1), with = "icrc_cbor::nat::option")] pub minimum_withdrawal_amount: Option, #[n(2)] pub ethereum_contract_address: Option, #[n(3)] pub ethereum_block_height: Option, - #[cbor(n(4), with = "crate::cbor::principal::option")] + #[cbor(n(4), with = "icrc_cbor::principal::option")] pub ledger_suite_orchestrator_id: Option, #[n(5)] pub erc20_helper_contract_address: Option, - #[cbor(n(6), with = "crate::cbor::nat::option")] + #[cbor(n(6), with = "icrc_cbor::nat::option")] pub last_erc20_scraped_block_number: Option, - #[cbor(n(7), with = "crate::cbor::principal::option")] + #[cbor(n(7), with = "icrc_cbor::principal::option")] pub evm_rpc_id: Option, #[n(8)] pub deposit_with_subaccount_helper_contract_address: Option, - #[cbor(n(9), with = "crate::cbor::nat::option")] + #[cbor(n(9), with = "icrc_cbor::nat::option")] pub last_deposit_with_subaccount_scraped_block_number: Option, } diff --git a/rs/ethereum/cketh/minter/src/state/event.rs b/rs/ethereum/cketh/minter/src/state/event.rs index 5989d697eaa..3cf607955e6 100644 --- a/rs/ethereum/cketh/minter/src/state/event.rs +++ b/rs/ethereum/cketh/minter/src/state/event.rs @@ -130,7 +130,7 @@ pub enum EventType { ReimbursedErc20Withdrawal { #[cbor(n(0), with = "crate::cbor::id")] cketh_ledger_burn_index: LedgerBurnIndex, - #[cbor(n(1), with = "crate::cbor::principal")] + #[cbor(n(1), with = "icrc_cbor::principal")] ckerc20_ledger_id: Principal, #[n(2)] reimbursed: Reimbursed, diff --git a/rs/ethereum/cketh/minter/src/state/transactions/mod.rs b/rs/ethereum/cketh/minter/src/state/transactions/mod.rs index 12b8cc00046..2dd7c974c3a 100644 --- a/rs/ethereum/cketh/minter/src/state/transactions/mod.rs +++ b/rs/ethereum/cketh/minter/src/state/transactions/mod.rs @@ -131,7 +131,7 @@ pub struct EthWithdrawalRequest { #[cbor(n(2), with = "crate::cbor::id")] pub ledger_burn_index: LedgerBurnIndex, /// The owner of the account from which the minter burned ckETH. - #[cbor(n(3), with = "crate::cbor::principal")] + #[cbor(n(3), with = "icrc_cbor::principal")] pub from: Principal, /// The subaccount from which the minter burned ckETH. #[n(4)] @@ -160,13 +160,13 @@ pub struct Erc20WithdrawalRequest { #[n(4)] pub erc20_contract_address: Address, /// The ckERC20 ledger on which the minter burned the ckERC20 tokens. - #[cbor(n(5), with = "crate::cbor::principal")] + #[cbor(n(5), with = "icrc_cbor::principal")] pub ckerc20_ledger_id: Principal, /// The transaction ID of the ckERC20 burn operation on the ckERC20 ledger. #[cbor(n(6), with = "crate::cbor::id")] pub ckerc20_ledger_burn_index: LedgerBurnIndex, /// The owner of the account from which the minter burned ckETH. - #[cbor(n(7), with = "crate::cbor::principal")] + #[cbor(n(7), with = "icrc_cbor::principal")] pub from: Principal, /// The subaccount from which the minter burned ckETH. #[n(8)] @@ -189,7 +189,7 @@ pub enum ReimbursementIndex { #[cbor(n(0), with = "crate::cbor::id")] cketh_ledger_burn_index: LedgerBurnIndex, /// The ckERC20 ledger canister ID identifying the ledger on which the burn to be reimbursed was made. - #[cbor(n(1), with = "crate::cbor::principal")] + #[cbor(n(1), with = "icrc_cbor::principal")] ledger_id: Principal, /// Burn index on the ckERC20 ledger #[cbor(n(2), with = "crate::cbor::id")] @@ -241,7 +241,7 @@ pub struct ReimbursementRequest { /// The amount that should be reimbursed in the smallest denomination. #[n(1)] pub reimbursed_amount: CkTokenAmount, - #[cbor(n(2), with = "crate::cbor::principal")] + #[cbor(n(2), with = "icrc_cbor::principal")] pub to: Principal, #[n(3)] pub to_subaccount: Option, diff --git a/rs/ethereum/cketh/minter/src/tx.rs b/rs/ethereum/cketh/minter/src/tx.rs index c256562864f..2ec583113dd 100644 --- a/rs/ethereum/cketh/minter/src/tx.rs +++ b/rs/ethereum/cketh/minter/src/tx.rs @@ -194,9 +194,9 @@ impl rlp::Encodable for Eip1559TransactionRequest { pub struct Eip1559Signature { #[n(0)] pub signature_y_parity: bool, - #[cbor(n(1), with = "crate::cbor::u256")] + #[cbor(n(1), with = "icrc_cbor::u256")] pub r: u256, - #[cbor(n(2), with = "crate::cbor::u256")] + #[cbor(n(2), with = "icrc_cbor::u256")] pub s: u256, }