Documentation ¶
Index ¶
Constants ¶
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 )
const DefaultConsensusNeeded float64 = 0.7
DefaultConsensusNeeded defines the default consensus value required for a prophecy to be finalized
Variables ¶
var ( ErrProphecyNotFound = sdkerrors.Register(ModuleName, 1, "prophecy with given id not found") ErrMinimumConsensusNeededInvalid = sdkerrors.Register(ModuleName, 2, "minimum consensus proportion of validator staking power must be > 0 and <= 1") ErrNoClaims = sdkerrors.Register(ModuleName, 3, "cannot create prophecy without initial claim") ErrInvalidIdentifier = sdkerrors.Register(ModuleName, 4, "invalid identifier provided, must be a nonempty string") ErrProphecyFinalized = sdkerrors.Register(ModuleName, 5, "prophecy already finalized") ErrDuplicateMessage = sdkerrors.Register(ModuleName, 6, "already processed message from validator for this id") ErrInvalidClaim = sdkerrors.Register(ModuleName, 7, "claim cannot be empty string") ErrInvalidValidator = sdkerrors.Register(ModuleName, 8, "claim must be made by actively bonded validator") ErrInternalDB = sdkerrors.Register(ModuleName, 9, " failed prophecy serialization/deserialization") )
Exported code type numbers
var StatusTextToString = [...]string{"pending", "success", "failed"}
var StringToStatusText = map[string]StatusText{ "pending": PendingStatusText, "success": SuccessStatusText, "failed": FailedStatusText, }
Functions ¶
This section is empty.
Types ¶
type Claim ¶
type Claim struct { ID string `json:"id"` ValidatorAddress sdk.ValAddress `json:"validator_address"` Content string `json:"content"` }
Claim contrains an arbitrary claim with arbitrary content made by a given validator
type DBProphecy ¶
type DBProphecy struct { ID string `json:"id"` Status Status `json:"status"` ClaimValidators []byte `json:"claim_validators"` ValidatorClaims []byte `json:"validator_claims"` }
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"` //This is a mapping from a claim to the list of validators that made that claim. ClaimValidators map[string][]sdk.ValAddress `json:"claim_validators"` //This is a mapping from a validator bech32 address to their claim ValidatorClaims map[string]string `json:"validator_claims"` }
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 NewProphecy ¶
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 StakingKeeper) (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 StakingKeeper ¶
type StakingKeeper interface { GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator staking.Validator, found bool) GetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress) (power int64) GetLastTotalPower(ctx sdk.Context) (power sdk.Int) GetBondedValidatorsByPower(ctx sdk.Context) []staking.Validator }
StakingKeeper defines the expected staking keeper
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
StatusText is an enum used to represent the status of the prophecy
const ( PendingStatusText StatusText = iota SuccessStatusText FailedStatusText )
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