-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a method to osmoutils for having a function write to state if no …
…err (#872) @antstalepresh made a neat method for doing this in a few places in the superfluid epoch logic. This just refactors it to a standalone method in osmoutils. Furthermore, this PR also renames osmotestutils -> osmoutils, which is a change I've wanted to make for a while.
- Loading branch information
1 parent
7343206
commit e7ab669
Showing
7 changed files
with
50 additions
and
37 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
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,21 @@ | ||
package osmoutils | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// This function lets you run the function f, but if theres an error | ||
// drop the state machine change and log the error. | ||
// If there is no error, proceeds as normal (but with some slowdown due to SDK store weirdness) | ||
// Try to avoid usage of iterators in f. | ||
func ApplyFuncIfNoError(ctx sdk.Context, f func(ctx sdk.Context) error) { | ||
// makes a new cache context, which all state changes get wrapped inside of. | ||
cacheCtx, write := ctx.CacheContext() | ||
err := f(cacheCtx) | ||
if err != nil { | ||
ctx.Logger().Error(err.Error()) | ||
} else { | ||
// no error, write the output of f | ||
write() | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package osmotestutils | ||
package osmoutils | ||
|
||
import ( | ||
"fmt" | ||
|
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
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
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
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