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