hychen / submoloch

The Polkadot version of MolochDAO
Apache License 2.0
0 stars 0 forks source link

Implement error handling helper crate #41

Open hychen opened 3 years ago

hychen commented 3 years ago

The following is the quick note of my roughly idea, gonna be changed later.

+begin_src rust

[ink_error::ink_error_definition]

pub enum SubmitProposalError { /// too many tribute tokens TooManyTributeTokensError }

+end_src

will derive to

+begin_src rust

[derive(displaydoc::Display, Debug, scale::Encode, scale::Decode)]

pub enum Error { /// too many tribute tokens ProposalNotFound, TransferFail(erc20::Erc20::error) }

+end_src

+begin_src rust

fn sponsor_proposal(&mut self, args: bool) -> Result<(), Error> { // exit early if input args are not good, ink_error::ensure!(true, Error::ProposalNotFound);

// panic to revert the state on chain.
ink_error::assert!(true, Error::TransferFail(erc20::Erc20::error:InsuffienceBalances));

// real business logic

Ok(());

}

+end_src