Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
errors
  • Loading branch information
pmikolajczyk41 committed Sep 12, 2022
commit eb7dbca4129ce78c3e6a7be126fcbcd0b720e43c
3 changes: 2 additions & 1 deletion aleph-client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion benches/payout-stakers/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion bin/cliain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions contracts/button/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion contracts/button/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ std = [
"ink_primitives/std",
"ink_storage/std",
"scale-info/std",
"scale/std"
"scale/std",
"access_control/std",
"game_token/std",
"ticket_token/std",
"openbrush/std",
]
ink-as-dependency = []
73 changes: 8 additions & 65 deletions contracts/button/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use access_control::Role;
use ink_env::Error as InkEnvError;
use ink_prelude::{format, string::String};
use openbrush::contracts::psp22::PSP22Error;
Expand All @@ -6,82 +7,24 @@ use openbrush::contracts::psp22::PSP22Error;
#[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum GameError {
/// Returned if reset is called before the deadline
/// Reset has been called before the deadline
BeforeDeadline,
/// Returned if button is pressed after the deadline
/// Button has been pressed after the deadline
AfterDeadline,
/// Returned if a call is made from an account with missing access control privileges
MissingRole(String),
/// Call has been made from an account with missing access control privileges
MissingRole(Role),
/// Returned if a call to another contract has failed
ContractCall(String),
CrossContractCallFailed(String),
}

impl From<PSP22Error> for GameError {
fn from(e: PSP22Error) -> Self {
match e {
PSP22Error::Custom(message) => GameError::ContractCall(message),
PSP22Error::InsufficientBalance => {
GameError::ContractCall(String::from("PSP22::InsufficientBalance"))
}
PSP22Error::InsufficientAllowance => {
GameError::ContractCall(String::from("PSP22::InsufficientAllowance"))
}
PSP22Error::ZeroRecipientAddress => {
GameError::ContractCall(String::from("PSP22::ZeroRecipientAddress"))
}
PSP22Error::ZeroSenderAddress => {
GameError::ContractCall(String::from("PSP22::ZeroSenderAddress"))
}
PSP22Error::SafeTransferCheckFailed(message) => {
GameError::ContractCall(format!("PSP22::SafeTransferCheckFailed({})", message))
}
}
GameError::CrossContractCallFailed(format!("{:?}", e))
}
}

impl From<InkEnvError> for GameError {
fn from(e: InkEnvError) -> Self {
match e {
InkEnvError::Decode(_e) => {
GameError::ContractCall(String::from("Contract call failed due to Decode error"))
}
InkEnvError::CalleeTrapped => GameError::ContractCall(String::from(
"Contract call failed due to CalleeTrapped error",
)),
InkEnvError::CalleeReverted => GameError::ContractCall(String::from(
"Contract call failed due to CalleeReverted error",
)),
InkEnvError::KeyNotFound => GameError::ContractCall(String::from(
"Contract call failed due to KeyNotFound error",
)),
InkEnvError::_BelowSubsistenceThreshold => GameError::ContractCall(String::from(
"Contract call failed due to _BelowSubsistenceThreshold error",
)),
InkEnvError::TransferFailed => GameError::ContractCall(String::from(
"Contract call failed due to TransferFailed error",
)),
InkEnvError::_EndowmentTooLow => GameError::ContractCall(String::from(
"Contract call failed due to _EndowmentTooLow error",
)),
InkEnvError::CodeNotFound => GameError::ContractCall(String::from(
"Contract call failed due to CodeNotFound error",
)),
InkEnvError::NotCallable => GameError::ContractCall(String::from(
"Contract call failed due to NotCallable error",
)),
InkEnvError::Unknown => {
GameError::ContractCall(String::from("Contract call failed due to Unknown error"))
}
InkEnvError::LoggingDisabled => GameError::ContractCall(String::from(
"Contract call failed due to LoggingDisabled error",
)),
InkEnvError::EcdsaRecoveryFailed => GameError::ContractCall(String::from(
"Contract call failed due to EcdsaRecoveryFailed error",
)),
#[cfg(any(feature = "std", test, doc))]
InkEnvError::OffChain(_e) => {
GameError::ContractCall(String::from("Contract call failed due to OffChain error"))
}
}
GameError::CrossContractCallFailed(format!("Contract call failed due to {:?}", e))
}
}
19 changes: 14 additions & 5 deletions contracts/button/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ mod button_game {
caller,
required_role,
|why: InkEnvError| {
GameError::ContractCall(format!("Calling access control has failed: {:?}", why))
GameError::CrossContractCallFailed(format!(
"Calling access control has failed: {:?}",
why
))
},
|role: Role| GameError::MissingRole(format!("{:?}", role)),
|role: Role| GameError::MissingRole(role),
);

match role_check {
Expand Down Expand Up @@ -171,7 +174,10 @@ mod button_game {
#[ink(message)]
pub fn code_hash(&self) -> ButtonResult<Hash> {
self.env().own_code_hash().map_err(|why| {
GameError::ContractCall(format!("Can't retrieve own code hash: {:?}", why))
GameError::CrossContractCallFailed(format!(
"Can't retrieve own code hash: {:?}",
why
))
})
}

Expand Down Expand Up @@ -314,9 +320,12 @@ mod button_game {
account,
role,
|why: InkEnvError| {
GameError::ContractCall(format!("Calling access control has failed: {:?}", why))
GameError::CrossContractCallFailed(format!(
"Calling access control has failed: {:?}",
why
))
},
|role: Role| GameError::MissingRole(format!("{:?}", role)),
|role: Role| GameError::MissingRole(role),
)
}

Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion flooder/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.