From 627045fa128f901b5bfc49f9db048ef09f22be42 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Mon, 31 Jan 2022 14:15:24 +0300 Subject: [PATCH 1/2] use raw balance value if tokenDecimals property is missing --- .../lib-substrate-relay/src/messages_metrics.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/relays/lib-substrate-relay/src/messages_metrics.rs b/relays/lib-substrate-relay/src/messages_metrics.rs index d2206094fe..1acba46221 100644 --- a/relays/lib-substrate-relay/src/messages_metrics.rs +++ b/relays/lib-substrate-relay/src/messages_metrics.rs @@ -202,9 +202,20 @@ where return Ok(metrics) } - let token_decimals = client.token_decimals().await?.ok_or_else(|| { - SubstrateError::Custom(format!("Missing token decimals from {} system properties", C::NAME)) - })?; + // if `tokenDecimals` is missing from system properties, we'll be using + let token_decimals = client + .token_decimals() + .await? + .map(|token_decimals| { + log::info!(target: "bridge", "Read `tokenDecimals` for {}: {}", C::NAME, token_decimals); + token_decimals + }) + .unwrap_or_else(|| { + // turns out it is normal not to have this property - e.g. when polkadot binary is started + // using `polkadot-local` chain. Let's use minimal nominal here + log::info!(target: "bridge", "Using default (zero) `tokenDecimals` value for {}", C::NAME); + 0 + }); let token_decimals = u32::try_from(token_decimals).map_err(|e| { anyhow::format_err!( "Token decimals value ({}) of {} doesn't fit into u32: {:?}", From 52fba2cbd982281d3c506fdc4b5dc195ca68a7aa Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Mon, 31 Jan 2022 14:20:43 +0300 Subject: [PATCH 2/2] fmt --- relays/lib-substrate-relay/src/messages_metrics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/relays/lib-substrate-relay/src/messages_metrics.rs b/relays/lib-substrate-relay/src/messages_metrics.rs index 1acba46221..00686ac4fd 100644 --- a/relays/lib-substrate-relay/src/messages_metrics.rs +++ b/relays/lib-substrate-relay/src/messages_metrics.rs @@ -211,8 +211,8 @@ where token_decimals }) .unwrap_or_else(|| { - // turns out it is normal not to have this property - e.g. when polkadot binary is started - // using `polkadot-local` chain. Let's use minimal nominal here + // turns out it is normal not to have this property - e.g. when polkadot binary is + // started using `polkadot-local` chain. Let's use minimal nominal here log::info!(target: "bridge", "Using default (zero) `tokenDecimals` value for {}", C::NAME); 0 });