Skip to content

Commit

Permalink
feat(logic): add context extraction util
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Jan 6, 2023
1 parent be944fe commit 64a5523
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions x/logic/predicate/utils.go
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")
}

0 comments on commit 64a5523

Please sign in to comment.