types

package
v0.0.0-...-c0747e2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModuleName is the name of the oracle module
	ModuleName = "oracle"

	// StoreKey is the string store representation
	StoreKey = ModuleName

	// QuerierRoute is the querier route for the oracle module
	QuerierRoute = ModuleName

	// RouterKey is the msg router key for the oracle module
	RouterKey = ModuleName
)
View Source
const (
	PendingStatusText = StatusText(iota)
	SuccessStatusText
	FailedStatusText
)

Variables

View Source
var StatusTextToString = [...]string{"pending", "success", "failed"}
View Source
var StringToStatusText = map[string]StatusText{
	"pending": PendingStatusText,
	"success": SuccessStatusText,
	"failed":  FailedStatusText,
}

Functions

func ErrDuplicateMessage

func ErrDuplicateMessage(codespace sdk.CodespaceType) sdk.Error

func ErrInternalDB

func ErrInternalDB(codespace sdk.CodespaceType, err error) sdk.Error

func ErrInvalidClaim

func ErrInvalidClaim(codespace sdk.CodespaceType) sdk.Error

func ErrInvalidIdentifier

func ErrInvalidIdentifier(codespace sdk.CodespaceType) sdk.Error

func ErrInvalidValidator

func ErrInvalidValidator(codespace sdk.CodespaceType) sdk.Error

func ErrMinimumConsensusNeededInvalid

func ErrMinimumConsensusNeededInvalid(codespace sdk.CodespaceType) sdk.Error

func ErrNoClaims

func ErrNoClaims(codespace sdk.CodespaceType) sdk.Error

func ErrProphecyFinalized

func ErrProphecyFinalized(codespace sdk.CodespaceType) sdk.Error

func ErrProphecyNotFound

func ErrProphecyNotFound(codespace sdk.CodespaceType) sdk.Error

Types

type Claim

type Claim struct {
	ID               string         `json:"id"`
	ValidatorAddress sdk.ValAddress `json:"validator_address"`
	Content          string         `json:"content"`
}

func NewClaim

func NewClaim(id string, validatorAddress sdk.ValAddress, content string) Claim

NewClaim returns a new Claim

type CodeType

type CodeType = sdk.CodeType

Local code type

const (
	DefaultCodespace sdk.CodespaceType = ModuleName

	CodeProphecyNotFound              CodeType = 1
	CodeMinimumConsensusNeededInvalid CodeType = 2
	CodeNoClaims                      CodeType = 3
	CodeInvalidIdentifier             CodeType = 4
	CodeProphecyFinalized             CodeType = 5
	CodeDuplicateMessage              CodeType = 6
	CodeInvalidClaim                  CodeType = 7
	CodeInvalidValidator              CodeType = 8
	CodeInternalDB                    CodeType = 9
)

Exported code type numbers

type DBProphecy

type DBProphecy struct {
	ID              string `json:"id"`
	Status          Status `json:"status"`
	ClaimValidators []byte `json:"claim_validators"` //This is a mapping from a claim to the list of validators that made that claim
	ValidatorClaims []byte `json:"validator_claims"` //This is a mapping from a validator bech32 address to their claim
}

DBProphecy is what the prophecy becomes when being saved to the database. Tendermint/Amino does not support maps so we must serialize those variables into bytes.

func (DBProphecy) DeserializeFromDB

func (dbProphecy DBProphecy) DeserializeFromDB() (Prophecy, error)

DeserializeFromDB deserializes a DBProphecy into a prophecy

type Prophecy

type Prophecy struct {
	ID     string `json:"id"`
	Status Status `json:"status"`
	//WARNING: Mappings are nondeterministic in Amino, an so iterating over them could result in consensus failure. New code should not iterate over the below 2 mappings.
	ClaimValidators map[string][]sdk.ValAddress `json:"claim_validators"` //This is a mapping from a claim to the list of validators that made that claim.
	ValidatorClaims map[string]string           `json:"validator_claims"` //This is a mapping from a validator bech32 address to their claim
}

Prophecy is a struct that contains all the metadata of an oracle ritual. Claims are indexed by the claim's validator bech32 address and by the claim's json value to allow for constant lookup times for any validation/verifiation checks of duplicate claims Each transaction, pending potential results are also calculated, stored and indexed by their byte result to allow discovery of consensus on any the result in constant time without having to sort or run through the list of claims to find the one with highest consensus

func NewEmptyProphecy

func NewEmptyProphecy() Prophecy

NewEmptyProphecy returns a blank prophecy, used with errors

func NewProphecy

func NewProphecy(id string) Prophecy

NewProphecy returns a new Prophecy, initialized in pending status with an initial claim

func (Prophecy) AddClaim

func (prophecy Prophecy) AddClaim(validator sdk.ValAddress, claim string)

AddClaim adds a given claim to this prophecy

func (Prophecy) FindHighestClaim

func (prophecy Prophecy) FindHighestClaim(ctx sdk.Context, stakeKeeper staking.Keeper) (string, int64, int64)

FindHighestClaim looks through all the existing claims on a given prophecy. It adds up the total power across all claims and returns the highest claim, power for that claim, and total power claimed on the prophecy overall.

func (Prophecy) SerializeForDB

func (prophecy Prophecy) SerializeForDB() (DBProphecy, error)

SerializeForDB serializes a prophecy into a DBProphecy TODO: Using gob here may mean that different tendermint clients in different languages may serialize/store prophecies in their db in different ways - check with @codereviewer if this is ok or if it introduces a risk of creating forks. Or maybe using a slower json serializer or Amino:JSON would be ok

type Status

type Status struct {
	Text       StatusText `json:"text"`
	FinalClaim string     `json:"final_claim"`
}

Status is a struct that contains the status of a given prophecy

func NewStatus

func NewStatus(text StatusText, finalClaim string) Status

NewStatus returns a new Status with the given data contained

type StatusText

type StatusText int

func (StatusText) MarshalJSON

func (text StatusText) MarshalJSON() ([]byte, error)

func (StatusText) String

func (text StatusText) String() string

func (*StatusText) UnmarshalJSON

func (text *StatusText) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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