slashing

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2019 License: Apache-2.0 Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultCodespace sdk.CodespaceType = ModuleName

	ErrorCodeSlashNotFound        sdk.CodeType = 501
	ErrorCodeInvalidStake         sdk.CodeType = 502
	ErrorCodeInvalidArgument      sdk.CodeType = 503
	ErrorCodeMaxSlashCountReached sdk.CodeType = 504
	ErrorCodeInvalidCreator       sdk.CodeType = 505
	ErrorCodeNotEnoughEarnedStake sdk.CodeType = 506
	ErrorCodeAlreadySlashed       sdk.CodeType = 507
	ErrorCodeInvalidSlashReason   sdk.CodeType = 508
	ErrorCodeAddressNotAuthorised sdk.CodeType = 509
	ErrorCodeAlreadyUnhelpful     sdk.CodeType = 510
)

Slashing errors reserve 500 ~ 599.

View Source
const (
	// TypeMsgSlashArgument represents the type of the message for creating new community
	TypeMsgSlashArgument = "slash_argument"
	// TypeMsgAddAdmin represents the type of message for adding a new admin
	TypeMsgAddAdmin = "add_admin"
	// TypeMsgRemoveAdmin represents the type of message for removeing an admin
	TypeMsgRemoveAdmin = "remove_admin"
	// TypeMsgUpdateParams represents the type of
	TypeMsgUpdateParams = "update_params"
)
View Source
const (
	QuerySlash                  = "slash"
	QuerySlashes                = "slashes"
	QueryArgumentSlashes        = "argument_slashes"
	QueryArgumentSlasherSlashes = "argument_slasher_slashes"
	QueryParams                 = "params"
)

query endpoints supported by the truchain Querier

View Source
const (
	StoreKey          = ModuleName
	RouterKey         = ModuleName
	QuerierRoute      = ModuleName
	DefaultParamspace = ModuleName

	AttributeKeyMinSlashCountKey = "min-slash-count"
	AttributeKeySlashResults     = "slash-results"
)

Defines slashing module constants

View Source
const ModuleName = "truslashing"

ModuleName is the name of this module

Variables

View Source
var (
	WithCommunityID   = exported.WithCommunityID
	ToModuleAccount   = exported.ToModuleAccount
	FromModuleAccount = exported.FromModuleAccount
)

nolint

View Source
var (
	SlashesKeyPrefix = []byte{0x00}
	SlashIDKey       = []byte{0x01}
	SlashCountPrefix = []byte{0x02}

	CreatorSlashesPrefix  = []byte{0x10}
	ArgumentSlashesPrefix = []byte{0x11}
	ArgumentCreatorPrefix = []byte{0x12}
)

Keys for slashing store Items are stored with the following key: values

- 0x00<slashID>: Slash{} - 0x01: nextSlashID - 0x02<argumentID>: slashCount

- 0x10<creator><slashID>: slashID - 0x11<argumentID><slashID>: slashID - 0x12<argumentID><slashCreator><slashID>: slashID

View Source
var (
	KeyMinSlashCount           = []byte("minStakeSlashCount")
	KeySlashMagnitude          = []byte("slashMagnitude")
	KeySlashMinStake           = []byte("slashMinStake")
	KeySlashAdmins             = []byte("slashAdmins")
	KeyCuratorShare            = []byte("curatorShare")
	KeyMaxDetailedReasonLength = []byte("maxDetailedReasonLength")
)

Keys for params

View Source
var ModuleCodec *codec.Codec

ModuleCodec encodes module codec

View Source
var SlashReasonName = []string{
	SlashReasonLogicOrEvidenceAbsent: "No clear logic or evidence",
	SlashReasonIssueNotAddressed:     "Doesn't address the issue",
	SlashReasonFocusedOnPerson:       "Focuses on the person",
	SlashNoOriginalThought:           "No original thought",
	SlashReasonPlagiarism:            "Plagiarism",
	SlashReasonOther:                 "Other",
	SlashReasonHarassment:            "Harassment",
	SlashReasonSpam:                  "Spam",
	SlashReasonOffensiveContent:      "Offensive Content",
}

SlashReasonName is the reason for the slash

Functions

func ErrAddressNotAuthorised

func ErrAddressNotAuthorised() sdk.Error

ErrAddressNotAuthorised throws an error when the address is not admin

func ErrAlreadySlashed

func ErrAlreadySlashed() sdk.Error

ErrAlreadySlashed throws an error when the creator has already slashed the stake previously

func ErrAlreadyUnhelpful added in v0.3.1

func ErrAlreadyUnhelpful() sdk.Error

ErrAlreadyUnhelpful throws an error when the creator has already slashed the stake previously

func ErrInvalidArgument

func ErrInvalidArgument(id uint64) sdk.Error

ErrInvalidArgument throws an error when the argument is invalid

func ErrInvalidCreator

func ErrInvalidCreator(address sdk.AccAddress) sdk.Error

ErrInvalidCreator throws an error when the creator is not an admin

func ErrInvalidSlashReason

func ErrInvalidSlashReason(because string) sdk.Error

ErrInvalidSlashReason throws an error when the slash reason is not valid

func ErrInvalidStake

func ErrInvalidStake(id uint64) sdk.Error

ErrInvalidStake throws an error when the stake is invalid

func ErrMaxSlashCountReached

func ErrMaxSlashCountReached(id uint64) sdk.Error

ErrMaxSlashCountReached throws an error when the max slash count on a stake is reached

func ErrNotEnoughEarnedStake

func ErrNotEnoughEarnedStake(address sdk.AccAddress) sdk.Error

ErrNotEnoughEarnedStake throws an error when the creator is not an admin

func ErrSlashNotFound

func ErrSlashNotFound(id uint64) sdk.Error

ErrSlashNotFound throws an error when the searched slash is not found

func InitGenesis

func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState)

InitGenesis initializes slashing state from genesis file

func NewHandler

func NewHandler(keeper Keeper) sdk.Handler

NewHandler creates a new handler for slashing module

func NewQuerier

func NewQuerier(keeper Keeper) sdk.Querier

NewQuerier creates a new querier

func ParamKeyTable

func ParamKeyTable() params.KeyTable

ParamKeyTable for slashing module

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers all the necessary types and interfaces for the module

func ValidateGenesis

func ValidateGenesis(data GenesisState) error

ValidateGenesis validates the genesis state data

Types

type AppModule

type AppModule struct {
	AppModuleBasic
	// contains filtered or unexported fields
}

AppModule defines external data for the module ----------------------------------------------------------------------------

func NewAppModule

func NewAppModule(keeper Keeper) AppModule

NewAppModule creates a NewAppModule object

func (AppModule) BeginBlock

func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock)

BeginBlock returns the begin blocker for the supply module.

func (AppModule) EndBlock

EndBlock returns the end blocker for the supply module. It returns no validator updates.

func (AppModule) ExportGenesis

func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage

ExportGenesis enforces exporting this module's data to a genesis file

func (AppModule) InitGenesis

func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate

InitGenesis enforces the creation of the genesis state for the slashing module

func (AppModule) NewHandler

func (am AppModule) NewHandler() sdk.Handler

NewHandler creates the handler for the slashing module

func (AppModule) NewQuerierHandler

func (am AppModule) NewQuerierHandler() sdk.Querier

NewQuerierHandler creates a new querier handler

func (AppModule) QuerierRoute

func (AppModule) QuerierRoute() string

QuerierRoute defines the querier route

func (AppModule) RegisterInvariants

func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry)

RegisterInvariants enforces registering of invariants

func (AppModule) Route

func (AppModule) Route() string

Route defines the key for the route

type AppModuleBasic

type AppModuleBasic struct{}

AppModuleBasic defines the internal data for the module ----------------------------------------------------------------------------

func (AppModuleBasic) DefaultGenesis

func (AppModuleBasic) DefaultGenesis() json.RawMessage

DefaultGenesis creates the default genesis state for testing

func (AppModuleBasic) GetQueryCmd

func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command

GetQueryCmd returns no root query command for the slashing module.

func (AppModuleBasic) GetTxCmd

func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command

GetTxCmd returns the root tx command for the slashing module.

func (AppModuleBasic) Name

func (AppModuleBasic) Name() string

Name define the name of the module

func (AppModuleBasic) RegisterCodec

func (AppModuleBasic) RegisterCodec(cdc *codec.Codec)

RegisterCodec registers the types needed for amino encoding/decoding

func (AppModuleBasic) RegisterRESTRoutes

func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router)

RegisterRESTRoutes registers the REST routes for the slashing module.

func (AppModuleBasic) ValidateGenesis

func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error

ValidateGenesis validates the genesis state

type GenesisState

type GenesisState struct {
	Slashes []Slash `json:"slashes"`
	Params  Params  `json:"params"`
}

GenesisState defines genesis data for the module

func DefaultGenesisState

func DefaultGenesisState() GenesisState

DefaultGenesisState returns a default genesis state

func ExportGenesis

func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState

ExportGenesis exports the genesis state

func NewGenesisState

func NewGenesisState() GenesisState

NewGenesisState creates a new genesis state.

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

Keeper is the model object for the package slashing module

func NewKeeper

func NewKeeper(
	storeKey sdk.StoreKey, paramStore params.Subspace, codec *codec.Codec,
	bankKeeper bank.Keeper, stakingKeeper staking.Keeper, accountKeeper account.Keeper, claimKeeper claim.Keeper,
) Keeper

NewKeeper creates a new keeper of the slashing Keeper

func (Keeper) AddAdmin

func (k Keeper) AddAdmin(ctx sdk.Context, admin, creator sdk.AccAddress) (err sdk.Error)

AddAdmin adds a new admin

func (Keeper) ArgumentSlasherSlashes

func (k Keeper) ArgumentSlasherSlashes(ctx sdk.Context, slasher sdk.AccAddress, argumentID uint64) []Slash

func (Keeper) ArgumentSlashes

func (k Keeper) ArgumentSlashes(ctx sdk.Context, argumentID uint64) []Slash

func (Keeper) CreateSlash

func (k Keeper) CreateSlash(ctx sdk.Context,
	argumentID uint64,
	slashType SlashType,
	slashReason SlashReason,
	slashDetailedReason string,
	creator sdk.AccAddress) (slash Slash, results []PunishmentResult, err sdk.Error)

CreateSlash creates a new slash on an argument (mark as "Unhelpful" in app)

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) Params

GetParams gets the genesis params for the slashing

func (Keeper) IterateArgumentSlasherSlashes

func (k Keeper) IterateArgumentSlasherSlashes(ctx sdk.Context, argumentID uint64, address sdk.AccAddress, cb slashCallback)

func (Keeper) IterateArgumentSlashes

func (k Keeper) IterateArgumentSlashes(ctx sdk.Context, argumentID uint64, cb slashCallback)

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

func (Keeper) RemoveAdmin

func (k Keeper) RemoveAdmin(ctx sdk.Context, admin, remover sdk.AccAddress) (err sdk.Error)

RemoveAdmin removes an admin

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params Params)

SetParams sets the params for the slashing

func (Keeper) Slash

func (k Keeper) Slash(ctx sdk.Context, id uint64) (slash Slash, err sdk.Error)

Slash returns a slash by its ID

func (Keeper) Slashes

func (k Keeper) Slashes(ctx sdk.Context) (slashes []Slash)

Slashes gets all slashes from the KVStore

func (Keeper) UpdateParams

func (k Keeper) UpdateParams(ctx sdk.Context, updater sdk.AccAddress, updates Params, updatedFields []string) sdk.Error

UpdateParams updates the required params

type MsgAddAdmin

type MsgAddAdmin struct {
	Admin   sdk.AccAddress `json:"admin"`
	Creator sdk.AccAddress `json:"creator"`
}

MsgAddAdmin defines the message to add a new admin

func NewMsgAddAdmin

func NewMsgAddAdmin(admin, creator sdk.AccAddress) MsgAddAdmin

NewMsgAddAdmin returns the messages to add a new admin

func (MsgAddAdmin) GetSignBytes

func (msg MsgAddAdmin) GetSignBytes() []byte

GetSignBytes implements Msg

func (MsgAddAdmin) GetSigners

func (msg MsgAddAdmin) GetSigners() []sdk.AccAddress

GetSigners implements Msg. Returns the creator as the signer.

func (MsgAddAdmin) Route

func (msg MsgAddAdmin) Route() string

Route implements Msg

func (MsgAddAdmin) Type

func (msg MsgAddAdmin) Type() string

Type implements Msg

func (MsgAddAdmin) ValidateBasic

func (msg MsgAddAdmin) ValidateBasic() sdk.Error

ValidateBasic implements Msg

type MsgRemoveAdmin

type MsgRemoveAdmin struct {
	Admin   sdk.AccAddress `json:"admin"`
	Remover sdk.AccAddress `json:"remover"`
}

MsgRemoveAdmin defines the message to remove an admin

func NewMsgRemoveAdmin

func NewMsgRemoveAdmin(admin, remover sdk.AccAddress) MsgRemoveAdmin

NewMsgRemoveAdmin returns the messages to remove an admin

func (MsgRemoveAdmin) GetSignBytes

func (msg MsgRemoveAdmin) GetSignBytes() []byte

GetSignBytes implements Msg

func (MsgRemoveAdmin) GetSigners

func (msg MsgRemoveAdmin) GetSigners() []sdk.AccAddress

GetSigners implements Msg. Returns the remover as the signer.

func (MsgRemoveAdmin) Route

func (msg MsgRemoveAdmin) Route() string

Route implements Msg

func (MsgRemoveAdmin) Type

func (msg MsgRemoveAdmin) Type() string

Type implements Msg

func (MsgRemoveAdmin) ValidateBasic

func (msg MsgRemoveAdmin) ValidateBasic() sdk.Error

ValidateBasic implements Msg

type MsgSlashArgument

type MsgSlashArgument struct {
	ArgumentID          uint64         `json:"argument_id"`
	SlashType           SlashType      `json:"slash_type"`
	SlashReason         SlashReason    `json:"slash_reason"`
	SlashDetailedReason string         `json:"slash_detailed_reason,omitempty"`
	Creator             sdk.AccAddress `json:"creator"`
}

MsgSlashArgument defines the message to slash an argument

func NewMsgSlashArgument

func NewMsgSlashArgument(argumentID uint64, slashType SlashType, slashReason SlashReason, slashDetailedReason string, creator sdk.AccAddress) MsgSlashArgument

NewMsgSlashArgument returns the messages to slash an argument

func (MsgSlashArgument) GetSignBytes

func (msg MsgSlashArgument) GetSignBytes() []byte

GetSignBytes implements Msg

func (MsgSlashArgument) GetSigners

func (msg MsgSlashArgument) GetSigners() []sdk.AccAddress

GetSigners implements Msg. Returns the creator as the signer.

func (MsgSlashArgument) Route

func (msg MsgSlashArgument) Route() string

Route implements Msg

func (MsgSlashArgument) Type

func (msg MsgSlashArgument) Type() string

Type implements Msg

func (MsgSlashArgument) ValidateBasic

func (msg MsgSlashArgument) ValidateBasic() sdk.Error

ValidateBasic implements Msg

type MsgUpdateParams

type MsgUpdateParams struct {
	Updates       Params         `json:"updates"`
	UpdatedFields []string       `json:"updated_fields"`
	Updater       sdk.AccAddress `json:"updater"`
}

MsgUpdateParams defines the message to remove an admin

func NewMsgUpdateParams

func NewMsgUpdateParams(updates Params, updatedFields []string, updater sdk.AccAddress) MsgUpdateParams

NewMsgUpdateParams returns the message to update the params

func (MsgUpdateParams) GetSignBytes

func (msg MsgUpdateParams) GetSignBytes() []byte

GetSignBytes implements Msg

func (MsgUpdateParams) GetSigners

func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress

GetSigners implements Msg. Returns the remover as the signer.

func (MsgUpdateParams) Route

func (msg MsgUpdateParams) Route() string

Route implements Msg

func (MsgUpdateParams) Type

func (msg MsgUpdateParams) Type() string

Type implements Msg

func (MsgUpdateParams) ValidateBasic

func (msg MsgUpdateParams) ValidateBasic() sdk.Error

ValidateBasic implements Msg

type Params

type Params struct {
	MinSlashCount           int              `json:"min_slash_count"`
	SlashMagnitude          int              `json:"slash_magnitude"`
	SlashMinStake           sdk.Coin         `json:"slash_min_stake"`
	SlashAdmins             []sdk.AccAddress `json:"slash_admins"`
	CuratorShare            sdk.Dec          `json:"curator_share"`
	MaxDetailedReasonLength int              `json:"max_detailed_reason_length"`
}

Params holds parameters for Slashing

func DefaultParams

func DefaultParams() Params

DefaultParams is the Slashing params for testing

func (*Params) ParamSetPairs

func (p *Params) ParamSetPairs() params.ParamSetPairs

ParamSetPairs implements params.ParamSet

type PunishmentResult

type PunishmentResult struct {
	Type          PunishmentResultType `json:"type"`
	AppAccAddress sdk.AccAddress       `json:"address"`
	Coin          sdk.Coin             `json:"coin"`
}

type PunishmentResultType

type PunishmentResultType int
const (
	PunishmentInterestSlashed PunishmentResultType = iota
	PunishmentStakeSlashed
	PunishmentCuratorRewarded
	PunishmentJailed
)

type QueryArgumentSlasherSlashesParams

type QueryArgumentSlasherSlashesParams struct {
	ArgumentID uint64         `json:"argument_id"`
	Slasher    sdk.AccAddress `json:"slasher"`
}

QueryArgumentSlashesParams are params for querying slashes by argument id and slasher

type QueryArgumentSlashesParams

type QueryArgumentSlashesParams struct {
	ArgumentID uint64 `json:"argument_id"`
}

QueryArgumentSlashesParams are params for querying slashes by argument id

type QuerySlashParams

type QuerySlashParams struct {
	ID uint64 `json:"id"`
}

QuerySlashParams are params for querying slashes by id queries

type Slash

type Slash struct {
	ID             uint64
	ArgumentID     uint64
	Type           SlashType
	Reason         SlashReason
	DetailedReason string
	Creator        sdk.AccAddress
	CreatedTime    time.Time
}

Slash stores data about a slashing

func (Slash) String

func (s Slash) String() string

type SlashReason

type SlashReason int

SlashReason enum

const (
	// SlashReasonLogicOrEvidenceAbsent represents the reason when no clear logic or evidence is present
	SlashReasonLogicOrEvidenceAbsent SlashReason = iota
	// SlashReasonIssueNotAddressed represents the reason when the issue at hand is not addressed
	SlashReasonIssueNotAddressed
	// SlashReasonFocusedOnPerson represents the reason when the argument is focused on the person, not the idea
	SlashReasonFocusedOnPerson
	// SlashNoOriginalThought represents the reasons when a thought isn't original;
	SlashNoOriginalThought
	// SlashReasonPlagiarism represents the reason when the argument is plagiarised
	SlashReasonPlagiarism
	// SlashReasonOther represents the reason that is any other than the above
	SlashReasonOther
	// SlashReasonHarassment ...
	SlashReasonHarassment
	// SlashReasonSpam ...
	SlashReasonSpam
	// SlashReasonOffensiveContent ...
	SlashReasonOffensiveContent
)

func (SlashReason) String

func (r SlashReason) String() string

type SlashType

type SlashType int

SlashType enum

const (
	// SlashTypeUnhelpful represents the unhelpful slashing type
	SlashTypeUnhelpful SlashType = iota // 0
)

type Slashes

type Slashes []Slash

Slashes is an array of slashes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL