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
Next Next commit
One contract to rule them all
  • Loading branch information
Michal Handzlik committed Aug 17, 2022
commit 01cd5fd766a3d563ad3d62602a36cc39f953ee31
68 changes: 0 additions & 68 deletions contracts/button/Cargo.lock

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

4 changes: 2 additions & 2 deletions contracts/button/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ access_control = { path = "../access_control", default-features = false, feature
game_token = { path = "../game_token", default-features = false, features = ["ink-as-dependency"] }
ticket_token = { path = "../ticket_token", default-features = false, features = ["ink-as-dependency"] }
openbrush = { git = "https://github.com/Supercolony-net/openbrush-contracts.git", rev = "8a20f95", default-features = false, features = ["psp22"] }
num = {version = "0.4.0", default-features = false }

[lib]
name = "button"
path = "lib.rs"
crate-type = [
"cdylib",
"rlib",
]

Expand All @@ -34,7 +34,7 @@ std = [
"ink_env/std",
"ink_lang/std",
"ink_metadata/std",
"ink_prelude/std",
"ink_prelude/std",
"ink_primitives/std",
"ink_storage/std",
"scale-info/std",
Expand Down
87 changes: 87 additions & 0 deletions contracts/button/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use ink_env::Error as InkEnvError;
use ink_prelude::{format, string::String};
use openbrush::contracts::psp22::PSP22Error;

/// GameError types
#[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
BeforeDeadline,
/// Returned if button is pressed after the deadline
AfterDeadline,
/// Returned if a call is made from an account with missing access control privileges
MissingRole(String),
/// Returned if a call to another contract has failed
ContractCall(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))
}
}
}
}

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"))
}
}
}
}
Loading