From 684a003bbed4afded9890ce3bbbe38470d25eeec Mon Sep 17 00:00:00 2001 From: Marc Nijdam Date: Fri, 12 Apr 2024 12:49:47 -0500 Subject: [PATCH] bump proto to pin tonic to 0.10 (#788) * bump proto to pin tonic to 0.10 * proto back to master --- Cargo.lock | 204 +++++++++--------- Cargo.toml | 4 +- file_store/src/coverage.rs | 2 +- file_store/src/iot_beacon_report.rs | 2 +- file_store/src/iot_invalid_poc.rs | 18 +- file_store/src/iot_packet.rs | 6 +- file_store/src/iot_valid_poc.rs | 6 +- file_store/src/iot_witness_report.rs | 4 +- .../src/mobile_radio_invalidated_threshold.rs | 6 +- file_store/src/mobile_radio_threshold.rs | 13 +- file_store/src/mobile_session.rs | 2 +- file_store/src/mobile_subscriber.rs | 2 +- iot_config/src/admin.rs | 4 +- iot_config/src/admin_service.rs | 2 +- iot_config/src/gateway_service.rs | 2 +- iot_config/src/route.rs | 6 +- mobile_config/src/lib.rs | 4 +- mobile_verifier/tests/rewarder_sp_rewards.rs | 2 +- price/src/price_generator.rs | 4 +- reward_index/src/indexer.rs | 22 +- 20 files changed, 151 insertions(+), 164 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67c4cf0f0..b8444348a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,9 +96,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -785,7 +785,7 @@ dependencies = [ "bytes", "hex", "http 0.2.11", - "hyper 0.14.23", + "hyper 0.14.28", "ring 0.16.20", "time", "tokio", @@ -1037,7 +1037,7 @@ dependencies = [ "fastrand", "http 0.2.11", "http-body 0.4.5", - "hyper 0.14.23", + "hyper 0.14.28", "hyper-rustls 0.23.1", "lazy_static", "pin-project-lite", @@ -1090,7 +1090,7 @@ dependencies = [ "futures-core", "http 0.2.11", "http-body 0.4.5", - "hyper 0.14.23", + "hyper 0.14.28", "once_cell", "percent-encoding", "pin-project-lite", @@ -1112,7 +1112,7 @@ dependencies = [ "futures-core", "http 0.2.11", "http-body 0.4.5", - "hyper 0.14.23", + "hyper 0.14.28", "once_cell", "percent-encoding", "pin-project-lite", @@ -1238,18 +1238,18 @@ dependencies = [ [[package]] name = "axum" -version = "0.6.3" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678c5130a507ae3a7c797f9a17393c14849300b8440eac47cdb90a5bdcb3a543" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", - "axum-core 0.3.2", + "axum-core 0.3.4", "bitflags", "bytes", "futures-util", "http 0.2.11", "http-body 0.4.5", - "hyper 0.14.23", + "hyper 0.14.28", "itoa 1.0.9", "matchit", "memchr", @@ -1260,7 +1260,6 @@ dependencies = [ "serde", "sync_wrapper", "tower", - "tower-http", "tower-layer", "tower-service", ] @@ -1301,9 +1300,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cae3e661676ffbacb30f1a824089a8c9150e71017f7e1e38f2aa32009188d34" +checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" dependencies = [ "async-trait", "bytes", @@ -1422,7 +1421,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "beacon" version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=master#659cd817e882090de83e4debb3df63f99b06a70a" +source = "git+https://github.com/helium/proto?branch=master#e8d84a8a4a05f069a3ce4f90d67a525aa92b52f9" dependencies = [ "base64 0.21.7", "byteorder", @@ -1432,7 +1431,7 @@ dependencies = [ "rand_chacha 0.3.0", "rust_decimal", "serde", - "sha2 0.10.6", + "sha2 0.9.9", "thiserror", ] @@ -1605,7 +1604,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" dependencies = [ "borsh-derive 0.10.3", - "hashbrown 0.12.3", + "hashbrown 0.13.1", ] [[package]] @@ -1732,7 +1731,7 @@ checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ "lazy_static", "memchr", - "regex-automata", + "regex-automata 0.1.10", "serde", ] @@ -3351,15 +3350,15 @@ dependencies = [ [[package]] name = "helium-crypto" -version = "0.8.1" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5cff2c83e56f92211d867fbb233d700039deddf293beea7fecf99561f3bebb3" +checksum = "e3ea5347e981a2d16f06b51d04361a2562cd89b806d765293522f61c5de0ec49" dependencies = [ "base64 0.21.7", "bs58 0.5.0", "byteorder", "ed25519-compact", - "getrandom 0.2.10", + "getrandom 0.1.16", "k256", "lazy_static", "multihash", @@ -3386,7 +3385,7 @@ dependencies = [ [[package]] name = "helium-proto" version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=master#659cd817e882090de83e4debb3df63f99b06a70a" +source = "git+https://github.com/helium/proto?branch=master#e8d84a8a4a05f069a3ce4f90d67a525aa92b52f9" dependencies = [ "bytes", "prost", @@ -3602,9 +3601,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.23" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", @@ -3617,7 +3616,7 @@ dependencies = [ "httpdate", "itoa 1.0.9", "pin-project-lite", - "socket2 0.4.9", + "socket2 0.5.5", "tokio", "tower-service", "tracing", @@ -3650,13 +3649,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59df7c4e19c950e6e0e868dcc0a300b09a9b88e9ec55bd879ca819087a77355d" dependencies = [ "http 0.2.11", - "hyper 0.14.23", + "hyper 0.14.28", "log", "rustls 0.20.9", "rustls-native-certs", "tokio", "tokio-rustls 0.23.4", - "webpki-roots 0.22.5", ] [[package]] @@ -3667,8 +3665,10 @@ checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", "http 0.2.11", - "hyper 0.14.23", + "hyper 0.14.28", + "log", "rustls 0.21.9", + "rustls-native-certs", "tokio", "tokio-rustls 0.24.1", ] @@ -3679,7 +3679,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ - "hyper 0.14.23", + "hyper 0.14.28", "pin-project-lite", "tokio", "tokio-io-timeout", @@ -4038,9 +4038,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.16.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5af9646e616e37c61093ef85e25bd883ae0c22e2fa1e6eedfe590048247116e3" +checksum = "e5f3783308bddc49d0218307f66a09330c106fbd792c58bac5c8dc294fdd0f98" dependencies = [ "jsonrpsee-core", "jsonrpsee-http-client", @@ -4049,51 +4049,51 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.16.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673d68136e2f0f67323bab95b3a7177df26ac21ddbf395fc32d60f30fe5a1364" +checksum = "5aaa4c4d5fb801dcc316d81f76422db259809037a86b3194ae538dd026b05ed7" dependencies = [ "anyhow", "async-lock", "async-trait", "beef", - "futures-channel", "futures-timer", "futures-util", - "hyper 0.14.23", + "hyper 0.14.28", "jsonrpsee-types", "rustc-hash", "serde", "serde_json", "thiserror", "tokio", + "tokio-stream", "tracing", ] [[package]] name = "jsonrpsee-http-client" -version = "0.16.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42007820863ab29f3adeacf43886ef54abaedb35bc33dada25771db4e1f94de4" +checksum = "aa7165efcbfbc951d180162ff28fe91b657ed81925e37a35e4a396ce12109f96" dependencies = [ "async-trait", - "hyper 0.14.23", - "hyper-rustls 0.23.1", + "hyper 0.14.28", + "hyper-rustls 0.24.2", "jsonrpsee-core", "jsonrpsee-types", - "rustc-hash", "serde", "serde_json", "thiserror", "tokio", + "tower", "tracing", ] [[package]] name = "jsonrpsee-types" -version = "0.16.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7985a27ee315c7c8c5c5033ac133e9472aec881edfd947780f5a9970efb7cbbf" +checksum = "00aa7cc87bc42e04e26c8ac3e7186142f7fd2949c763d9b6a7e64a69672d8fb2" dependencies = [ "anyhow", "beef", @@ -4292,7 +4292,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" dependencies = [ - "regex-automata", + "regex-automata 0.1.10", ] [[package]] @@ -4389,7 +4389,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a4964177ddfdab1e3a2b37aec7cf320e14169abb0ed73999f558136409178d5" dependencies = [ "base64 0.21.7", - "hyper 0.14.23", + "hyper 0.14.28", "indexmap 1.9.3", "ipnet", "metrics", @@ -5138,7 +5138,7 @@ dependencies = [ "helium-crypto", "helium-proto", "http 0.2.11", - "hyper 0.14.23", + "hyper 0.14.28", "jsonrpsee", "metrics", "metrics-exporter-prometheus", @@ -5193,12 +5193,12 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "prettyplease" -version = "0.1.21" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c142c0e46b57171fe0c528bee8c5b7569e80f0c17e377cd0e30ea57dbc11bb51" +checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2 1.0.69", - "syn 1.0.109", + "syn 2.0.38", ] [[package]] @@ -5317,9 +5317,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.11.2" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0841812012b2d4a6145fae9a6af1534873c32aa67fff26bd09f8fa42c83f95a" +checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" dependencies = [ "bytes", "prost-derive", @@ -5327,46 +5327,44 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.11.2" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d8b442418ea0822409d9e7d047cbf1e7e9e1760b172bf9982cf29d517c93511" +checksum = "80b776a1b2dc779f5ee0641f8ade0125bc1298dd41a9a0c16d8bd57b42d222b1" dependencies = [ "bytes", "heck 0.4.0", - "itertools 0.10.5", - "lazy_static", + "itertools 0.12.0", "log", "multimap", + "once_cell", "petgraph", "prettyplease", "prost", "prost-types", "regex", - "syn 1.0.109", + "syn 2.0.38", "tempfile", - "which", ] [[package]] name = "prost-derive" -version = "0.11.2" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "164ae68b6587001ca506d3bf7f1000bfa248d0e1217b618108fba4ec1d0cc306" +checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.12.0", "proc-macro2 1.0.69", "quote 1.0.33", - "syn 1.0.109", + "syn 2.0.38", ] [[package]] name = "prost-types" -version = "0.11.2" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "747761bc3dc48f9a34553bf65605cf6cb6288ba219f3450b4275dbd81539551a" +checksum = "3235c33eb02c1f1e212abdbe34c78b264b038fb58ca612664343271e36e55ffe" dependencies = [ - "bytes", "prost", ] @@ -5648,13 +5646,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.0" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-automata 0.4.6", + "regex-syntax 0.8.3", ] [[package]] @@ -5663,7 +5662,18 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" dependencies = [ - "regex-syntax", + "regex-syntax 0.6.28", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.3", ] [[package]] @@ -5672,6 +5682,12 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + [[package]] name = "remove_dir_all" version = "0.5.3" @@ -5696,7 +5712,7 @@ dependencies = [ "h2 0.3.21", "http 0.2.11", "http-body 0.4.5", - "hyper 0.14.23", + "hyper 0.14.28", "hyper-rustls 0.24.2", "ipnet", "js-sys", @@ -6001,9 +6017,9 @@ dependencies = [ [[package]] name = "rustls-native-certs" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" dependencies = [ "openssl-probe", "rustls-pemfile", @@ -7806,50 +7822,46 @@ dependencies = [ [[package]] name = "tonic" -version = "0.8.3" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f219fad3b929bef19b1f86fbc0358d35daed8f2cac972037ac0dc10bbb8d5fb" +checksum = "d560933a0de61cf715926b9cac824d4c883c2c43142f787595e48280c40a1d0e" dependencies = [ "async-stream", "async-trait", - "axum 0.6.3", - "base64 0.13.1", + "axum 0.6.20", + "base64 0.21.7", "bytes", - "futures-core", - "futures-util", "h2 0.3.21", "http 0.2.11", "http-body 0.4.5", - "hyper 0.14.23", + "hyper 0.14.28", "hyper-timeout", "percent-encoding", "pin-project", "prost", - "prost-derive", + "rustls 0.21.9", "rustls-native-certs", "rustls-pemfile", "tokio", - "tokio-rustls 0.23.4", + "tokio-rustls 0.24.1", "tokio-stream", - "tokio-util", "tower", "tower-layer", "tower-service", "tracing", - "tracing-futures", ] [[package]] name = "tonic-build" -version = "0.8.4" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf5e9b9c0f7e0a7c027dcfaba7b2c60816c7049171f679d99ee2ff65d0de8c4" +checksum = "9d021fc044c18582b9a2408cd0dd05b1596e3ecdb5c4df822bb0183545683889" dependencies = [ "prettyplease", "proc-macro2 1.0.69", "prost-build", "quote 1.0.33", - "syn 1.0.109", + "syn 2.0.38", ] [[package]] @@ -7886,7 +7898,6 @@ dependencies = [ "http-body 0.4.5", "http-range-header", "pin-project-lite", - "tower", "tower-layer", "tower-service", "tracing", @@ -7937,16 +7948,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - [[package]] name = "tracing-subscriber" version = "0.3.18" @@ -8012,7 +8013,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if", - "rand 0.8.5", + "rand 0.7.3", "static_assertions", ] @@ -8342,17 +8343,6 @@ version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" -[[package]] -name = "which" -version = "4.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" -dependencies = [ - "either", - "libc", - "once_cell", -] - [[package]] name = "whoami" version = "1.2.3" @@ -8691,7 +8681,7 @@ dependencies = [ "rand 0.8.5", "serde", "serde_json", - "sha2 0.10.6", + "sha2 0.9.9", "thiserror", "twox-hash", "xorf", diff --git a/Cargo.toml b/Cargo.toml index 2f9d2a411..126cf1897 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ sqlx = {version = "0", features = [ "runtime-tokio-rustls" ]} helium-anchor-gen = {git = "https://github.com/helium/helium-anchor-gen.git"} -helium-crypto = {version = "0.8.1", features=["sqlx-postgres", "multisig"]} +helium-crypto = {version = "0.8.4", features=["sqlx-postgres", "multisig"]} hextree = {git = "https://github.com/jaykickliter/HexTree", branch = "main", features = ["disktree"]} helium-proto = {git = "https://github.com/helium/proto", branch = "master", features = ["services"]} solana-client = "1.16" @@ -78,7 +78,7 @@ rust_decimal = "1" rust_decimal_macros = "1" base64 = ">=0.21" sha2 = "0.10" -tonic = {version = "0", features = ["tls", "tls-roots"]} +tonic = {version = "0.10", features = ["tls", "tls-roots"]} http = "<=0.2" triggered = "0" futures = "*" diff --git a/file_store/src/coverage.rs b/file_store/src/coverage.rs index 083fdb048..0e1fad252 100644 --- a/file_store/src/coverage.rs +++ b/file_store/src/coverage.rs @@ -107,7 +107,7 @@ impl TryFrom for RadioHexSignalLevel { fn try_from(v: RadioHexSignalLevelProto) -> Result { Ok(Self { - signal_level: SignalLevel::from_i32(v.signal_level).ok_or_else(|| { + signal_level: SignalLevel::try_from(v.signal_level).map_err(|_| { DecodeError::unsupported_signal_level("coverage_object_req_v1", v.signal_level) })?, signal_power: v.signal_power, diff --git a/file_store/src/iot_beacon_report.rs b/file_store/src/iot_beacon_report.rs index 6a511e591..d6e29e91e 100644 --- a/file_store/src/iot_beacon_report.rs +++ b/file_store/src/iot_beacon_report.rs @@ -106,7 +106,7 @@ impl From for LoraBeaconReportReqV1 { impl TryFrom for IotBeaconReport { type Error = Error; fn try_from(v: LoraBeaconReportReqV1) -> Result { - let data_rate: DataRate = DataRate::from_i32(v.datarate).ok_or_else(|| { + let data_rate: DataRate = DataRate::try_from(v.datarate).map_err(|_| { DecodeError::unsupported_datarate("iot_beacon_report_req_v1", v.datarate) })?; let timestamp = v.timestamp()?; diff --git a/file_store/src/iot_invalid_poc.rs b/file_store/src/iot_invalid_poc.rs index d633b9345..f92f74127 100644 --- a/file_store/src/iot_invalid_poc.rs +++ b/file_store/src/iot_invalid_poc.rs @@ -68,10 +68,9 @@ impl TryFrom for IotInvalidBeaconReport { type Error = Error; fn try_from(v: LoraInvalidBeaconReportV1) -> Result { let inv_reason = v.reason; - let invalid_reason: InvalidReason = - InvalidReason::from_i32(inv_reason).ok_or_else(|| { - DecodeError::unsupported_invalid_reason("iot_invalid_beacon_report_v1", inv_reason) - })?; + let invalid_reason: InvalidReason = InvalidReason::try_from(inv_reason).map_err(|_| { + DecodeError::unsupported_invalid_reason("iot_invalid_beacon_report_v1", inv_reason) + })?; Ok(Self { received_timestamp: v.timestamp()?, reason: invalid_reason, @@ -107,13 +106,12 @@ impl TryFrom for IotInvalidWitnessReport { type Error = Error; fn try_from(v: LoraInvalidWitnessReportV1) -> Result { let inv_reason = v.reason; - let invalid_reason: InvalidReason = - InvalidReason::from_i32(inv_reason).ok_or_else(|| { - DecodeError::unsupported_invalid_reason("iot_invalid_witness_report_v1", inv_reason) - })?; + let invalid_reason: InvalidReason = InvalidReason::try_from(inv_reason).map_err(|_| { + DecodeError::unsupported_invalid_reason("iot_invalid_witness_report_v1", inv_reason) + })?; let participant_side = v.participant_side; - let side: InvalidParticipantSide = InvalidParticipantSide::from_i32(participant_side) - .ok_or_else(|| { + let side: InvalidParticipantSide = InvalidParticipantSide::try_from(participant_side) + .map_err(|_| { DecodeError::unsupported_participant_side( "iot_invalid_witness_report_v1", participant_side, diff --git a/file_store/src/iot_packet.rs b/file_store/src/iot_packet.rs index e337c4a19..582b50393 100644 --- a/file_store/src/iot_packet.rs +++ b/file_store/src/iot_packet.rs @@ -76,13 +76,13 @@ impl TryFrom for PacketRouterPacketReport { type Error = Error; fn try_from(v: PacketRouterPacketReportV1) -> Result { - let data_rate = DataRate::from_i32(v.datarate).ok_or_else(|| { + let data_rate = DataRate::try_from(v.datarate).map_err(|_| { DecodeError::unsupported_datarate("iot_packet_router_packet_report_v1", v.datarate) })?; - let region = Region::from_i32(v.region).ok_or_else(|| { + let region = Region::try_from(v.region).map_err(|_| { DecodeError::unsupported_region("iot_packet_router_packet_report_v1", v.region) })?; - let packet_type = PacketType::from_i32(v.r#type).ok_or_else(|| { + let packet_type = PacketType::try_from(v.r#type).map_err(|_| { DecodeError::unsupported_packet_type("iot_packet_router_packet_report_v1", v.r#type) })?; let received_timestamp = v.timestamp()?; diff --git a/file_store/src/iot_valid_poc.rs b/file_store/src/iot_valid_poc.rs index e8bccb6fd..90267f1c5 100644 --- a/file_store/src/iot_valid_poc.rs +++ b/file_store/src/iot_valid_poc.rs @@ -168,17 +168,17 @@ impl TryFrom for IotVerifiedWitnessReport { type Error = Error; fn try_from(v: LoraVerifiedWitnessReportV1) -> Result { let received_timestamp = v.timestamp()?; - let status = VerificationStatus::from_i32(v.status).ok_or_else(|| { + let status = VerificationStatus::try_from(v.status).map_err(|_| { DecodeError::unsupported_status_reason("iot_verified_witness_report_v1", v.status) })?; - let invalid_reason = InvalidReason::from_i32(v.invalid_reason).ok_or_else(|| { + let invalid_reason = InvalidReason::try_from(v.invalid_reason).map_err(|_| { DecodeError::unsupported_invalid_reason( "iot_verified_witness_report_v1", v.invalid_reason, ) })?; let participant_side = - InvalidParticipantSide::from_i32(v.participant_side).ok_or_else(|| { + InvalidParticipantSide::try_from(v.participant_side).map_err(|_| { DecodeError::unsupported_participant_side( "iot_verified_witness_report_v1", v.participant_side, diff --git a/file_store/src/iot_witness_report.rs b/file_store/src/iot_witness_report.rs index de60c83cf..1b79a1aef 100644 --- a/file_store/src/iot_witness_report.rs +++ b/file_store/src/iot_witness_report.rs @@ -78,8 +78,8 @@ impl TryFrom for IotWitnessReport { type Error = Error; fn try_from(v: LoraWitnessReportReqV1) -> Result { let dr = v.datarate; - let data_rate: DataRate = DataRate::from_i32(dr) - .ok_or_else(|| DecodeError::unsupported_datarate("iot_witness_report_req_v1", dr))?; + let data_rate: DataRate = DataRate::try_from(dr) + .map_err(|_| DecodeError::unsupported_datarate("iot_witness_report_req_v1", dr))?; let timestamp = v.timestamp()?; Ok(Self { diff --git a/file_store/src/mobile_radio_invalidated_threshold.rs b/file_store/src/mobile_radio_invalidated_threshold.rs index 82bb3b4be..3a73e0710 100644 --- a/file_store/src/mobile_radio_invalidated_threshold.rs +++ b/file_store/src/mobile_radio_invalidated_threshold.rs @@ -49,7 +49,7 @@ impl MsgDecode for VerifiedInvalidatedRadioThresholdIngestReport { impl TryFrom for InvalidatedRadioThresholdReportReq { type Error = Error; fn try_from(v: InvalidatedRadioThresholdReportReqV1) -> Result { - let reason = InvalidatedThresholdReason::from_i32(v.reason).ok_or_else(|| { + let reason = InvalidatedThresholdReason::try_from(v.reason).map_err(|_| { DecodeError::unsupported_invalidated_reason( "invalidated_radio_threshold_report_req_v1", v.reason, @@ -146,8 +146,8 @@ impl TryFrom { type Error = Error; fn try_from(v: VerifiedInvalidatedRadioThresholdIngestReportV1) -> Result { - let status = InvalidatedRadioThresholdReportVerificationStatus::from_i32(v.status) - .ok_or_else(|| { + let status = InvalidatedRadioThresholdReportVerificationStatus::try_from(v.status) + .map_err(|_| { DecodeError::unsupported_status_reason( "verified_invalidated_radio_threshold_ingest_report_v1", v.status, diff --git a/file_store/src/mobile_radio_threshold.rs b/file_store/src/mobile_radio_threshold.rs index b385c331b..060470fc0 100644 --- a/file_store/src/mobile_radio_threshold.rs +++ b/file_store/src/mobile_radio_threshold.rs @@ -138,13 +138,12 @@ impl From for RadioThresholdIngestReportV1 { impl TryFrom for VerifiedRadioThresholdIngestReport { type Error = Error; fn try_from(v: VerifiedRadioThresholdIngestReportV1) -> Result { - let status = - RadioThresholdReportVerificationStatus::from_i32(v.status).ok_or_else(|| { - DecodeError::unsupported_status_reason( - "verified_radio_threshold_ingest_report_v1", - v.status, - ) - })?; + let status = RadioThresholdReportVerificationStatus::try_from(v.status).map_err(|_| { + DecodeError::unsupported_status_reason( + "verified_radio_threshold_ingest_report_v1", + v.status, + ) + })?; Ok(Self { report: v .report diff --git a/file_store/src/mobile_session.rs b/file_store/src/mobile_session.rs index 0589b93e0..d5f1eda6c 100644 --- a/file_store/src/mobile_session.rs +++ b/file_store/src/mobile_session.rs @@ -86,7 +86,7 @@ impl MsgTimestamp for InvalidDataTransferIngestReport { impl TryFrom for InvalidDataTransferIngestReport { type Error = Error; fn try_from(v: InvalidDataTransferIngestReportV1) -> Result { - let reason = DataTransferIngestReportStatus::from_i32(v.reason).ok_or_else(|| { + let reason = DataTransferIngestReportStatus::try_from(v.reason).map_err(|_| { DecodeError::unsupported_status_reason("invalid_data_transfer_session_reason", v.reason) })?; Ok(Self { diff --git a/file_store/src/mobile_subscriber.rs b/file_store/src/mobile_subscriber.rs index ad7ed0fdd..85c8f6be1 100644 --- a/file_store/src/mobile_subscriber.rs +++ b/file_store/src/mobile_subscriber.rs @@ -129,7 +129,7 @@ impl From for SubscriberLocationIngestReportV1 { impl TryFrom for VerifiedSubscriberLocationIngestReport { type Error = Error; fn try_from(v: VerifiedSubscriberLocationIngestReportV1) -> Result { - let status = SubscriberReportVerificationStatus::from_i32(v.status).ok_or_else(|| { + let status = SubscriberReportVerificationStatus::try_from(v.status).map_err(|_| { DecodeError::unsupported_status_reason( "verified_subscriber_location_ingest_report_v1", v.status, diff --git a/iot_config/src/admin.rs b/iot_config/src/admin.rs index fd3c23f58..79fa7aaea 100644 --- a/iot_config/src/admin.rs +++ b/iot_config/src/admin.rs @@ -94,9 +94,9 @@ pub enum KeyType { impl KeyType { pub fn from_i32(v: i32) -> anyhow::Result { - ProtoKeyType::from_i32(v) + ProtoKeyType::try_from(v) .map(|kt| kt.into()) - .ok_or_else(|| anyhow!("unsupported key type {}", v)) + .map_err(|_| anyhow!("unsupported key type {}", v)) } } diff --git a/iot_config/src/admin_service.rs b/iot_config/src/admin_service.rs index 4e4647c3d..6260d3058 100644 --- a/iot_config/src/admin_service.rs +++ b/iot_config/src/admin_service.rs @@ -177,7 +177,7 @@ impl iot_config::Admin for AdminService { let signer = verify_public_key(&request.signer)?; self.verify_admin_request_signature(&signer, &request)?; - let region = Region::from_i32(request.region).ok_or_else(|| { + let region = Region::try_from(request.region).map_err(|_| { Status::invalid_argument(format!("invalid lora region {}", request.region)) })?; diff --git a/iot_config/src/gateway_service.rs b/iot_config/src/gateway_service.rs index 98059ecbd..454ab5cdd 100644 --- a/iot_config/src/gateway_service.rs +++ b/iot_config/src/gateway_service.rs @@ -188,7 +188,7 @@ impl iot_config::Gateway for GatewayService { let address: &PublicKeyBinary = &pubkey.into(); tracing::debug!(pubkey = %address, "fetching region params"); - let default_region = Region::from_i32(request.region).ok_or_else(|| { + let default_region = Region::try_from(request.region).map_err(|_| { Status::invalid_argument(format!("invalid lora region {}", request.region)) })?; diff --git a/iot_config/src/route.rs b/iot_config/src/route.rs index 6996dc785..fc5424208 100644 --- a/iot_config/src/route.rs +++ b/iot_config/src/route.rs @@ -1073,9 +1073,9 @@ pub struct UnsupportedFlowTypeError(i32); impl FlowType { fn from_i32(v: i32) -> Result { - proto::FlowTypeV1::from_i32(v) + proto::FlowTypeV1::try_from(v) .map(|ft| ft.into()) - .ok_or(UnsupportedFlowTypeError(v)) + .map_err(|_| UnsupportedFlowTypeError(v)) } } @@ -1151,7 +1151,7 @@ impl From for Protocol { let mut mapping = BTreeMap::new(); for entry in gwmp.mapping { let region = - proto::Region::from_i32(entry.region).unwrap_or(proto::Region::Us915); + proto::Region::try_from(entry.region).unwrap_or(proto::Region::Us915); mapping.insert(region, entry.port); } Protocol::Gwmp(Gwmp { mapping }) diff --git a/mobile_config/src/lib.rs b/mobile_config/src/lib.rs index 203c126d1..cac265fd5 100644 --- a/mobile_config/src/lib.rs +++ b/mobile_config/src/lib.rs @@ -39,9 +39,9 @@ pub enum KeyRole { impl KeyRole { pub fn from_i32(v: i32) -> anyhow::Result { - ProtoKeyRole::from_i32(v) + ProtoKeyRole::try_from(v) .map(|kr| kr.into()) - .ok_or_else(|| anyhow::anyhow!("unsupported key role {}", v)) + .map_err(|_| anyhow::anyhow!("unsupported key role {}", v)) } } diff --git a/mobile_verifier/tests/rewarder_sp_rewards.rs b/mobile_verifier/tests/rewarder_sp_rewards.rs index e542b8095..5f3c5e2e0 100644 --- a/mobile_verifier/tests/rewarder_sp_rewards.rs +++ b/mobile_verifier/tests/rewarder_sp_rewards.rs @@ -76,7 +76,7 @@ async fn test_service_provider_rewards(pool: PgPool) -> anyhow::Result<()> { if let Ok((sp_reward, unallocated_reward)) = rewards { assert_eq!( SP_1.to_string(), - ServiceProvider::from_i32(sp_reward.service_provider_id) + ServiceProvider::try_from(sp_reward.service_provider_id) .unwrap() .to_string() ); diff --git a/price/src/price_generator.rs b/price/src/price_generator.rs index faa058f60..2459c00af 100644 --- a/price/src/price_generator.rs +++ b/price/src/price_generator.rs @@ -64,8 +64,8 @@ impl TryFrom for Price { type Error = Error; fn try_from(value: PriceReportV1) -> Result { - let tt: BlockchainTokenTypeV1 = BlockchainTokenTypeV1::from_i32(value.token_type) - .ok_or_else(|| anyhow!("unsupported token type: {:?}", value.token_type))?; + let tt: BlockchainTokenTypeV1 = BlockchainTokenTypeV1::try_from(value.token_type) + .map_err(|_| anyhow!("unsupported token type: {:?}", value.token_type))?; Ok(Self { timestamp: Utc .timestamp_opt(value.timestamp as i64, 0) diff --git a/reward_index/src/indexer.rs b/reward_index/src/indexer.rs index 64afd4a5d..c30e1438b 100644 --- a/reward_index/src/indexer.rs +++ b/reward_index/src/indexer.rs @@ -158,17 +158,17 @@ impl Indexer { r.discovery_location_amount, )), Some(MobileReward::ServiceProviderReward(r)) => { - if let Some(sp) = ServiceProvider::from_i32(r.service_provider_id) { - Ok(( - RewardKey { - key: sp.to_string(), - reward_type: RewardType::MobileServiceProvider, - }, - r.amount, - )) - } else { - bail!("failed to decode service provider") - } + ServiceProvider::try_from(r.service_provider_id) + .map(|sp| { + Ok(( + RewardKey { + key: sp.to_string(), + reward_type: RewardType::MobileServiceProvider, + }, + r.amount, + )) + }) + .map_err(|_| anyhow!("failed to decode service provider"))? } Some(MobileReward::UnallocatedReward(r)) => Ok(( RewardKey {