pow

package
v0.30.0-dev1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrInvalidCount

func ErrInvalidCount(codespace sdk.CodespaceType, msg string) sdk.Error

func ErrInvalidDifficulty

func ErrInvalidDifficulty(codespace sdk.CodespaceType, msg string) sdk.Error

nolint

func ErrInvalidProof

func ErrInvalidProof(codespace sdk.CodespaceType, msg string) sdk.Error

func ErrNonexistentCount

func ErrNonexistentCount(codespace sdk.CodespaceType) sdk.Error

func ErrNonexistentDifficulty

func ErrNonexistentDifficulty(codespace sdk.CodespaceType) sdk.Error

func ErrNonexistentReward

func ErrNonexistentReward(codespace sdk.CodespaceType) sdk.Error

func ErrNotBelowTarget

func ErrNotBelowTarget(codespace sdk.CodespaceType, msg string) sdk.Error

func InitGenesis

func InitGenesis(ctx sdk.Context, k Keeper, genesis Genesis) error

InitGenesis for the POW module

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

Register concrete types on codec codec

Types

type CodeType

type CodeType = sdk.CodeType

TODO remove, seems hacky

const (
	DefaultCodespace          sdk.CodespaceType = "pow"
	CodeInvalidDifficulty     CodeType          = 201
	CodeNonexistentDifficulty CodeType          = 202
	CodeNonexistentReward     CodeType          = 203
	CodeNonexistentCount      CodeType          = 204
	CodeInvalidProof          CodeType          = 205
	CodeNotBelowTarget        CodeType          = 206
	CodeInvalidCount          CodeType          = 207
	CodeUnknownRequest        CodeType          = sdk.CodeUnknownRequest
)

POW errors reserve 200 ~ 299

type Config

type Config struct {
	Denomination string
	Reward       int64
}

module users must specify coin denomination and reward (constant) per PoW solution

func NewConfig

func NewConfig(denomination string, reward int64) Config

type Genesis

type Genesis struct {
	Difficulty uint64 `json:"difficulty"`
	Count      uint64 `json:"count"`
}

genesis info must specify starting difficulty and starting count

func ExportGenesis

func ExportGenesis(ctx sdk.Context, k Keeper) Genesis

ExportGenesis for the PoW module

type Keeper

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

POW Keeper

func NewKeeper

func NewKeeper(key sdk.StoreKey, config Config, ck bank.Keeper, codespace sdk.CodespaceType) Keeper

func (Keeper) ApplyValid

func (k Keeper) ApplyValid(ctx sdk.Context, sender sdk.AccAddress, newDifficulty uint64, newCount uint64) sdk.Error

Add some coins for a POW well done

func (Keeper) CheckValid

func (k Keeper) CheckValid(ctx sdk.Context, difficulty uint64, count uint64) (uint64, uint64, sdk.Error)

Is the keeper state valid?

func (Keeper) GetLastCount

func (k Keeper) GetLastCount(ctx sdk.Context) (uint64, error)

get the last count

func (Keeper) GetLastDifficulty

func (k Keeper) GetLastDifficulty(ctx sdk.Context) (uint64, error)

get the last mining difficulty

func (Keeper) Handler

func (pk Keeper) Handler(ctx sdk.Context, msg sdk.Msg) sdk.Result

POW handler

func (Keeper) SetLastCount

func (k Keeper) SetLastCount(ctx sdk.Context, count uint64)

set the last count

func (Keeper) SetLastDifficulty

func (k Keeper) SetLastDifficulty(ctx sdk.Context, diff uint64)

set the last mining difficulty

type MsgMine

type MsgMine struct {
	Sender     sdk.AccAddress `json:"sender"`
	Difficulty uint64         `json:"difficulty"`
	Count      uint64         `json:"count"`
	Nonce      uint64         `json:"nonce"`
	Proof      []byte         `json:"proof"`
}

MsgMine - mine some coins with PoW

func GenerateMsgMine

func GenerateMsgMine(sender sdk.AccAddress, count uint64, difficulty uint64) MsgMine

generate the mine message

func NewMsgMine

func NewMsgMine(sender sdk.AccAddress, difficulty uint64, count uint64, nonce uint64, proof []byte) MsgMine

NewMsgMine - construct mine message

func (MsgMine) GetSignBytes

func (msg MsgMine) GetSignBytes() []byte

get the mine message sign bytes

func (MsgMine) GetSigners

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

func (MsgMine) Route

func (msg MsgMine) Route() string

nolint

func (MsgMine) String

func (msg MsgMine) String() string

func (MsgMine) Type

func (msg MsgMine) Type() string

func (MsgMine) ValidateBasic

func (msg MsgMine) ValidateBasic() sdk.Error

validate the mine message

Directories

Path Synopsis
client
cli

Jump to

Keyboard shortcuts

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