Files
pezkuwi-subxt/substrate/primitives/wasm-interface/src/wasmi_impl.rs
T
Falco Hirschenberger b581604aa7 Apply some clippy lints (#11154)
* Apply some clippy hints

* Revert clippy ci changes

* Update client/cli/src/commands/generate.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/cli/src/commands/inspect_key.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/service/src/client/block_rules.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/service/src/client/block_rules.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/network/src/transactions.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/network/src/protocol.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Revert due to missing `or_default` function.

* Fix compilation and simplify code

* Undo change that corrupts benchmark.

* fix clippy

* Update client/service/test/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/state-db/src/noncanonical.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/state-db/src/noncanonical.rs

remove leftovers!

* Update client/tracing/src/logging/directives.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/fork-tree/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* added needed ref

* Update frame/referenda/src/benchmarking.rs

* Simplify byte-vec creation

* let's just not overlap the ranges

* Correction

* cargo fmt

* Update utils/frame/benchmarking-cli/src/shared/stats.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/frame/benchmarking-cli/src/pallet/command.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/frame/benchmarking-cli/src/pallet/command.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Giles Cope <gilescope@gmail.com>
2022-04-30 21:28:27 +00:00

81 lines
2.3 KiB
Rust

// This file is part of Substrate.
// Copyright (C) 2019-2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Implementation of conversions between Substrate and wasmi types.
use crate::{Signature, Value, ValueType};
use sp_std::vec::Vec;
impl From<Value> for wasmi::RuntimeValue {
fn from(value: Value) -> Self {
match value {
Value::I32(val) => Self::I32(val),
Value::I64(val) => Self::I64(val),
Value::F32(val) => Self::F32(val.into()),
Value::F64(val) => Self::F64(val.into()),
}
}
}
impl From<wasmi::RuntimeValue> for Value {
fn from(value: wasmi::RuntimeValue) -> Self {
match value {
wasmi::RuntimeValue::I32(val) => Self::I32(val),
wasmi::RuntimeValue::I64(val) => Self::I64(val),
wasmi::RuntimeValue::F32(val) => Self::F32(val.into()),
wasmi::RuntimeValue::F64(val) => Self::F64(val.into()),
}
}
}
impl From<ValueType> for wasmi::ValueType {
fn from(value: ValueType) -> Self {
match value {
ValueType::I32 => Self::I32,
ValueType::I64 => Self::I64,
ValueType::F32 => Self::F32,
ValueType::F64 => Self::F64,
}
}
}
impl From<wasmi::ValueType> for ValueType {
fn from(value: wasmi::ValueType) -> Self {
match value {
wasmi::ValueType::I32 => Self::I32,
wasmi::ValueType::I64 => Self::I64,
wasmi::ValueType::F32 => Self::F32,
wasmi::ValueType::F64 => Self::F64,
}
}
}
impl From<Signature> for wasmi::Signature {
fn from(sig: Signature) -> Self {
let args = sig.args.iter().map(|a| (*a).into()).collect::<Vec<_>>();
wasmi::Signature::new(args, sig.return_value.map(Into::into))
}
}
impl From<&wasmi::Signature> for Signature {
fn from(sig: &wasmi::Signature) -> Self {
Signature::new(
sig.params().iter().copied().map(Into::into).collect::<Vec<_>>(),
sig.return_type().map(Into::into),
)
}
}