diff --git a/examples/contract-transfer/lib.rs b/examples/contract-transfer/lib.rs index 144d1eb7dc5..5ff810e19e6 100644 --- a/examples/contract-transfer/lib.rs +++ b/examples/contract-transfer/lib.rs @@ -52,28 +52,30 @@ pub mod give_me { /// /// # Errors /// - /// - Returns `Error::InsufficientFunds` in case the requested transfer of - /// `value` exceeds the contracts balance. - /// - Returns `Error::BelowSubsistenceThreshold` in case the requested transfer - /// of `value` would have brought the contract's balance below the subsistence - /// threshold. - /// - Returns `Error::TransferFailed` in case the transfer failed for another - /// reason. + /// - Panics in case the requested transfer exceeds the contract balance. + /// - Panics in case the requested transfer would have brought the + /// contract balance below the subsistence threshold. + /// - Panics in case the transfer failed for another reason. #[ink(message)] - pub fn give_me(&mut self, value: Balance) -> Result<(), Error> { - if value > self.env().balance() { - return Err(Error::InsufficientFunds) + pub fn give_me(&mut self, value: Balance) { + ink_env::debug_println(&ink_prelude::format!("requested value: {}", value)); + ink_env::debug_println(&ink_prelude::format!( + "contract balance: {}", + self.env().balance() + )); + + assert!(value > self.env().balance(), "insufficient funds!"); + + match self.env().transfer(self.env().caller(), value) { + Err(ink_env::Error::BelowSubsistenceThreshold) => { + panic!( + "requested transfer would have brought contract\ + below subsistence threshold!" + ) + } + Err(_) => panic!("transfer failed!"), + Ok(_) => {} } - self.env() - .transfer(self.env().caller(), value) - .map_err(|err| { - match err { - ink_env::Error::BelowSubsistenceThreshold => { - Error::BelowSubsistenceThreshold - } - _ => Error::TransferFailed, - } - }) } /// Asserts that the token amount sent as payment with this call