3

I have an ink smart contract message that takes an enum as argument. The code is shown below;

#[derive(Encode, Decode)]
#[cfg_attr(
    feature = "std",
    derive(Debug, PartialEq, Eq, scale_info::TypeInfo, StorageLayout,)
)]
pub enum EncodableFunctions {
    SetAssets(Vec<ContentIdentifier>),
    ActivateVoting(u128),
}

 #[ink(message)]
    pub fn encode_function_name_and_input(
        &self,
        args: EncodableFunctions,
    ) -> ([u8; 4], Vec<u8>) {
        match args {
            EncodableFunctions::SetAssets => {
                let encoded_name = ink::selector_bytes!("set_default_assets");
                let inputs = ArgumentList::empty().push_arg(&args);
                let encoded_inputs = inputs.encode();
                (encoded_name, encoded_inputs)
            }
            EncodableFunctions::ActivateVoting => {
                let encoded_name = ink::selector_bytes!("activate_voting");
                let inputs = ArgumentList::empty().push_arg(&args);
                let encoded_inputs = inputs.encode();
                (encoded_name, encoded_inputs)
            }
        }
    }

The contract builds successfully and I'm able to deploy to Substrate COntracts UI but when I try to interact with the function, I get a blank screen like the image below

screenshot

There's no such error if I replace the enum with no associated values, like enum below. Any way I can make the function work?

 #[derive(Encode, Decode)]
#[cfg_attr(
    feature = "std",
    derive(Debug, PartialEq, Eq, scale_info::TypeInfo, StorageLayout,)
)]
pub enum EncodableFunctions {
    SetAssets,
    ActivateVoting,
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.