generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logic): add context extraction util
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package predicate | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// UnwrapSDKContext retrieves a Context from a context.Context instance | ||
// attached with WrapSDKContext. It panics if a Context was not properly | ||
// attached. | ||
func UnwrapSDKContext(ctx context.Context) (sdk.Context, error) { | ||
if sdkCtx, ok := ctx.(sdk.Context); ok { | ||
return sdkCtx, nil | ||
} | ||
if sdkCtx, ok := ctx.Value(sdk.SdkContextKey).(sdk.Context); ok { | ||
return sdkCtx, nil | ||
} | ||
|
||
return sdk.Context{}, fmt.Errorf("no sdk.Context found in context") | ||
} |