[英]type annotations needed in substrate frotier rpc pallet
我正在使用 susbtrate 2.0.1 並嘗試將前沿實現集成到運行時中,這個實現在基板 2.0.0 上運行良好,但現在有一些語法錯誤。
Frontier Dependencies
frontier-consensus = { default-features = false,git = 'https://github.com/PureStake/frontier.git', branch = 'substrate-v2' }
frontier-rpc = { default-features = false, git = 'https://github.com/PureStake/frontier.git', branch = 'substrate-v2' }
frontier-rpc-primitives = { default-features = false, git = 'https://github.com/PureStake/frontier.git', branch = 'substrate-v2' }
以下是錯誤:
error[E0283]: type annotations needed
--> /Users/dev/Applications/.cargo/git/checkouts/frontier-6f1ff17f29a883b0/c5fe2a6/rpc/src/eth.rs:299:56
|
299 | Ok(U256::from(self.client.info().best_number.clone().unique_saturated_into()))
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: multiple `impl`s satisfying `U256: From<_>` found in the following crates: `core`, `primitive_types`:
- impl From<&'static str> for U256;
- impl From<U128> for U256;
- impl From<[u8; _]> for U256;
- impl From<i128> for U256;
and 15 more
help: try using a fully qualified path to specify the expected types
|
299 | Ok(U256::from(<<<B as BlockT>::Header as HeaderT>::Number as UniqueSaturatedInto<T>>::unique_saturated_into(self.client.info().best_number.clone())))
type annotations needed
--> /Users/dev/Applications/.cargo/git/checkouts/frontier-6f1ff17f29a883b0/c5fe2a6/rpc/src/eth_pubsub.rs:88:46
|
88 | self.client.info().best_number.clone().unique_saturated_into() as u32
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: type must be known at this point
help: try using a fully qualified path to specify the expected types
|
88 | <<<B as BlockT>::Header as HeaderT>::Number as UniqueSaturatedInto<T>>::unique_saturated_into(self.client.info().best_number.clone()) as u32
在這行代碼中出現此錯誤:
fn block_number(&self) -> Result<U256> {
Ok(U256::from(self.client.info().best_number.clone().unique_saturated_into()))
}
native_number = Some(
self.client.info().best_number.clone().unique_saturated_into() as u32
);
在這種情況下,編譯器無法從哪個類型( u64
u32
...?)中推斷出U256
。
您需要明確地編寫它。
順便說一句,您可以使用saturated_into
代替unique_saturated_into
,它支持渦輪魚風格。
例子:
U256::from(self.client.info().best_number.clone().saturated_into::<u32>());
如果您仍然想要unique_saturated_into
:
let bn: u32 = self.client.info().best_number.clone().unique_saturated_into();
U256::from(bn);
您能否將此問題遷移到https://substrate.stackexchange.com/questions ? 那是正確的地方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.