瀏覽代碼

refactor(target_chains/starknet): blanket impl for unwrap_with_felt252 (#1549)

Pavel Strakhov 1 年之前
父節點
當前提交
bf2c8b5d43

+ 0 - 27
target_chains/starknet/contracts/src/pyth.cairo

@@ -19,15 +19,6 @@ pub enum GetPriceUnsafeError {
     PriceFeedNotFound,
 }
 
-pub impl GetPriceUnsafeErrorUnwrapWithFelt252<T> of UnwrapWithFelt252<T, GetPriceUnsafeError> {
-    fn unwrap_with_felt252(self: Result<T, GetPriceUnsafeError>) -> T {
-        match self {
-            Result::Ok(v) => v,
-            Result::Err(err) => core::panic_with_felt252(err.into()),
-        }
-    }
-}
-
 impl GetPriceUnsafeErrorIntoFelt252 of Into<GetPriceUnsafeError, felt252> {
     fn into(self: GetPriceUnsafeError) -> felt252 {
         match self {
@@ -41,15 +32,6 @@ pub enum GovernanceActionError {
     AccessDenied,
 }
 
-pub impl GovernanceActionErrorUnwrapWithFelt252<T> of UnwrapWithFelt252<T, GovernanceActionError> {
-    fn unwrap_with_felt252(self: Result<T, GovernanceActionError>) -> T {
-        match self {
-            Result::Ok(v) => v,
-            Result::Err(err) => core::panic_with_felt252(err.into()),
-        }
-    }
-}
-
 impl GovernanceActionErrorIntoFelt252 of Into<GovernanceActionError, felt252> {
     fn into(self: GovernanceActionError) -> felt252 {
         match self {
@@ -67,15 +49,6 @@ pub enum UpdatePriceFeedsError {
     InsufficientFeeAllowance,
 }
 
-pub impl UpdatePriceFeedsErrorUnwrapWithFelt252<T> of UnwrapWithFelt252<T, UpdatePriceFeedsError> {
-    fn unwrap_with_felt252(self: Result<T, UpdatePriceFeedsError>) -> T {
-        match self {
-            Result::Ok(v) => v,
-            Result::Err(err) => core::panic_with_felt252(err.into()),
-        }
-    }
-}
-
 impl UpdatePriceFeedsErrorIntoFelt252 of Into<UpdatePriceFeedsError, felt252> {
     fn into(self: UpdatePriceFeedsError) -> felt252 {
         match self {

+ 9 - 0
target_chains/starknet/contracts/src/util.cairo

@@ -105,6 +105,15 @@ pub trait UnwrapWithFelt252<T, E> {
     fn unwrap_with_felt252(self: Result<T, E>) -> T;
 }
 
+pub impl UnwrapWithFelt252Impl<T, E, +Into<E, felt252>> of UnwrapWithFelt252<T, E> {
+    fn unwrap_with_felt252(self: Result<T, E>) -> T {
+        match self {
+            Result::Ok(v) => v,
+            Result::Err(err) => core::panic_with_felt252(err.into()),
+        }
+    }
+}
+
 /// Reinterpret `u64` as `i64` as if it was a two's complement binary representation.
 pub fn u64_as_i64(value: u64) -> i64 {
     if value < 0x8000000000000000 {

+ 0 - 30
target_chains/starknet/contracts/src/wormhole.cairo

@@ -38,15 +38,6 @@ pub enum GovernanceError {
     ActionAlreadyConsumed,
 }
 
-pub impl GovernanceErrorUnwrapWithFelt252<T> of UnwrapWithFelt252<T, GovernanceError> {
-    fn unwrap_with_felt252(self: Result<T, GovernanceError>) -> T {
-        match self {
-            Result::Ok(v) => v,
-            Result::Err(err) => core::panic_with_felt252(err.into()),
-        }
-    }
-}
-
 impl GovernanceErrorIntoFelt252 of Into<GovernanceError, felt252> {
     fn into(self: GovernanceError) -> felt252 {
         match self {
@@ -68,17 +59,6 @@ pub enum SubmitNewGuardianSetError {
     AccessDenied,
 }
 
-pub impl SubmitNewGuardianSetErrorUnwrapWithFelt252<
-    T
-> of UnwrapWithFelt252<T, SubmitNewGuardianSetError> {
-    fn unwrap_with_felt252(self: Result<T, SubmitNewGuardianSetError>) -> T {
-        match self {
-            Result::Ok(v) => v,
-            Result::Err(err) => core::panic_with_felt252(err.into()),
-        }
-    }
-}
-
 impl SubmitNewGuardianSetErrorIntoFelt252 of Into<SubmitNewGuardianSetError, felt252> {
     fn into(self: SubmitNewGuardianSetError) -> felt252 {
         match self {
@@ -104,16 +84,6 @@ pub enum ParseAndVerifyVmError {
     InvalidGuardianIndex,
 }
 
-pub impl ParseAndVerifyVmErrorUnwrapWithFelt252<T> of UnwrapWithFelt252<T, ParseAndVerifyVmError> {
-    fn unwrap_with_felt252(self: Result<T, ParseAndVerifyVmError>) -> T {
-        match self {
-            Result::Ok(v) => v,
-            Result::Err(err) => core::panic_with_felt252(err.into()),
-        }
-    }
-}
-
-
 impl ErrorIntoFelt252 of Into<ParseAndVerifyVmError, felt252> {
     fn into(self: ParseAndVerifyVmError) -> felt252 {
         match self {