-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from tellor-io/jailReporter
Jail
- Loading branch information
Showing
12 changed files
with
1,824 additions
and
179 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/tellor-io/layer/x/reporter/types" | ||
) | ||
|
||
// send a reporter to jail | ||
func (k Keeper) JailReporter(ctx context.Context, reporter types.OracleReporter, jailDuration int64) error { | ||
if reporter.Jailed { | ||
return types.ErrReporterJailed.Wrapf("cannot jail already jailed reporter, %v", reporter) | ||
} | ||
sdkctx := sdk.UnwrapSDKContext(ctx) | ||
reporter.JailedUntil = sdkctx.BlockTime().Add(time.Second * time.Duration(jailDuration)) | ||
reporter.Jailed = true | ||
reporterAddr := sdk.MustAccAddressFromBech32(reporter.GetReporter()) | ||
err := k.Reporters.Set(ctx, reporterAddr, reporter) | ||
if err != nil { | ||
return err | ||
} | ||
sdkctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
"jailed_reporter", | ||
sdk.NewAttribute("reporter", reporterAddr.String()), | ||
sdk.NewAttribute("duration", strconv.FormatInt(jailDuration, 10)), | ||
), | ||
}) | ||
return nil | ||
} | ||
|
||
// remove a reporter from jail | ||
func (k Keeper) unjailReporter(ctx context.Context, reporterAddr sdk.AccAddress, reporter types.OracleReporter) error { | ||
if !reporter.Jailed { | ||
return types.ErrReporterNotJailed.Wrapf("cannot unjail already unjailed reporter, %v", reporter) | ||
} | ||
|
||
sdkctx := sdk.UnwrapSDKContext(ctx) | ||
if sdkctx.BlockTime().Before(reporter.JailedUntil) { | ||
return types.ErrReporterJailed.Wrapf("cannot unjail reporter before jail time is up, %v", reporter) | ||
} | ||
|
||
reporter.Jailed = false | ||
|
||
return k.Reporters.Set(ctx, reporterAddr, reporter) | ||
} |
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
Oops, something went wrong.