Commit a3bfd946 authored by Hero Bird's avatar Hero Bird

[pdsl] Fix another bunch of clippy and (new) compiler warnings

parent ff2723d7
......@@ -328,7 +328,7 @@ impl TestEnv {
}
}
const TEST_ENV_LOG_TARGET: &'static str = "test-env";
const TEST_ENV_LOG_TARGET: &str = "test-env";
impl EnvTypes for TestEnv {
type Address = srml::Address;
......
......@@ -165,8 +165,7 @@ pub extern "C" fn deploy() {
fn decode_params() -> Action {
let input = ContractEnv::input();
let action = Action::decode(&mut &input[..]).unwrap();
action
Action::decode(&mut &input[..]).unwrap()
}
#[no_mangle]
......
......@@ -36,7 +36,7 @@ messages! {
}
fn instantiate() -> impl Contract {
ContractDecl::new::<Erc20Token>()
ContractDecl::using::<Erc20Token>()
.on_deploy(|env, init_supply| {
let caller = env.caller();
env.state.balances[&caller] = init_supply;
......
use crate::{
state::{
ContractState,
EmptyContractState,
},
exec_env::{
ExecutionEnv,
......@@ -46,7 +45,7 @@ impl<State> DeployHandler<State, NoDeployArgs> {
const fn init() -> Self {
Self {
args: PhantomData,
deploy_fn: move |env, _| {},
deploy_fn: move |_env, _| {},
}
}
}
......@@ -130,9 +129,13 @@ where
HandlerChain: Copy,
{}
/// An empty contract state.
#[derive(Copy, Clone)]
pub struct EmptyContractState;
impl ContractDecl<EmptyContractState, NoDeployArgs, UnreachableMessageHandler> {
/// Creates a new contract declaration with the given name.
pub const fn new<State>() -> ContractDecl<State, NoDeployArgs, UnreachableMessageHandler> {
pub const fn using<State>() -> ContractDecl<State, NoDeployArgs, UnreachableMessageHandler> {
ContractDecl {
state: PhantomData,
deployer: DeployHandler::init(),
......@@ -226,7 +229,6 @@ where
use pdsl_core::{
storage::{
Key,
Allocator,
alloc::{
BumpAlloc,
AllocateUsing,
......@@ -331,19 +333,19 @@ where
{
/// Calls the message encoded by the given call data.
///
/// # Note
/// # Panics
///
/// - If the contract has no message handler setup for the
/// message that is encoded by the given call data.
/// - If the encoded input arguments for the message do not
/// match the expected format.
fn call_with(&mut self, call_data: CallData) {
let mut this = self;
this
let call_result = self
.handlers
.handle_call(&mut this.env, call_data)
.ok()
.expect("trapped during message dispatch");
.handle_call(&mut self.env, call_data);
if let Err(err) = call_result {
panic!(err.description())
}
}
/// Calls the given message with its expected input arguments.
......
......@@ -23,6 +23,7 @@ pub use crate::{
ContractState,
},
contract::{
EmptyContractState,
NoDeployArgs,
DeployHandler,
ContractDecl,
......
......@@ -43,7 +43,7 @@ pub struct CallData {
raw_params: Vec<u8>,
}
impl parity_codec::Decode for CallData {
impl Decode for CallData {
fn decode<I: parity_codec::Input>(input: &mut I) -> Option<Self> {
let selector = MessageHandlerSelector::decode(input)?;
let mut param_buf = Vec::new();
......@@ -230,6 +230,16 @@ pub enum Error {
InvalidArguments,
}
impl Error {
/// Returns a short description of the error.
pub fn description(&self) -> &'static str {
match self {
Error::InvalidFunctionSelector => "encountered invalid message selector",
Error::InvalidArguments => "encountered invalid arguments for selected message"
}
}
}
/// Results of message handling operations.
pub type Result<T> = CoreResult<T, Error>;
......@@ -255,7 +265,7 @@ pub struct UnreachableMessageHandler;
impl<State> HandleCall<State> for UnreachableMessageHandler {
type Output = ();
fn handle_call(&self, _env: &mut ExecutionEnv<State>, data: CallData) -> Result<Self::Output> {
fn handle_call(&self, _env: &mut ExecutionEnv<State>, _data: CallData) -> Result<Self::Output> {
Err(Error::InvalidFunctionSelector)
}
}
......
use pdsl_core::{
storage::{
Flush,
alloc::{
AllocateUsing,
Initialize,
},
alloc::AllocateUsing,
},
};
......@@ -69,10 +66,3 @@ macro_rules! state {
}
};
}
use crate as pdsl_model; // TODO: Fix this to being not required!
state! {
/// An empty contract state.
pub struct EmptyContractState {}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment