Documentation ¶
Index ¶
- Constants
- Variables
- func IntGTE(a, b Int) bool
- func IntGreater(a, b Int) bool
- func IntLess(a, b Int) bool
- func PrefixEndBytes(prefix []byte) []byte
- type Donation
- type IF
- type Int
- func IntAdd(a, b Int) Int
- func IntDiv(a, b Int) Int
- func IntDivFrac(v Int, num, denom int64) Int
- func IntEMA(prev, new Int, windowSize int64) Int
- func IntMax(a, b Int) Int
- func IntMin(a, b Int) Int
- func IntMul(a, b Int) Int
- func IntMulFrac(v Int, num, denom int64) Int
- func IntSub(a, b Int) Int
- func NewInt(v int64) Int
- func NewIntFromBig(v *big.Int) Int
- func (i Int) Add(b Int)
- func (i Int) Clone() Int
- func (i Int) Cmp(b Int) int
- func (i Int) Div(b Int)
- func (i Int) MarshalAmino() (string, error)
- func (i Int) MarshalJSON() ([]byte, error)
- func (i Int) Mul(b Int)
- func (i Int) Sub(b Int)
- func (i *Int) UnmarshalAmino(text string) error
- func (i *Int) UnmarshalJSON(bz []byte) error
- type LinoCoin
- type Pid
- type PostIFPair
- type Rep
- type Reputation
- type ReputationImpl
- func (rep ReputationImpl) DonateAt(u Uid, p Pid, amount LinoCoin) IF
- func (rep ReputationImpl) ExportToFile(file string) error
- func (rep ReputationImpl) GetCurrentRound() (RoundId, Time)
- func (rep ReputationImpl) GetReputation(u Uid) Rep
- func (rep ReputationImpl) ImportFromFile(file string) error
- func (rep ReputationImpl) IncFreeScore(u Uid, score Rep)
- func (rep ReputationImpl) StartNewRound(t Time)
- func (rep ReputationImpl) Update(t Time)
- type ReputationStore
- type RoundId
- type Store
- type Time
- type Uid
- type UserIterator
- type UserReputation
- type UserReputationTable
Constants ¶
const ( // Inherited from testnet, the unit of 1 reputation is one coin // of testnet, which is 10^(-5) * 0.012 USD. // Caller need to convert the amount of donation to the number of test coins. DefaultRoundDurationSeconds = 25 * 3600 // how many seconds does a round last, default: 25 hours DefaultSampleWindowSize = 10 // how many rounds are used to sample out user's customer score. DefaultDecayFactor = 10 // reputation decay factor %. // Initial and minimum score is 10^(-5), one coin. DefaultInitialReputation = 1 )
Variables ¶
var (
KeySeparator = byte('/')
)
Functions ¶
func IntGreater ¶
func PrefixEndBytes ¶
PrefixEndBytes returns the []byte that would end a range query for all []byte with a certain prefix Deals with last byte of prefix being FF without overflowing
Types ¶
type Int ¶
func IntEMA ¶
return the exponential moving average of @p prev on having a new sample @p new with sample size of @p windowSize.
func IntMax ¶
a bunch of helper functions that takes two bitInt and returns a newly allocated bigInt.
func NewIntFromBig ¶
func (Int) MarshalAmino ¶
MarshalAmino defines custom encoding scheme
func (Int) MarshalJSON ¶
MarshalJSON defines custom encoding scheme
func (*Int) UnmarshalAmino ¶
UnmarshalAmino defines custom decoding scheme
func (*Int) UnmarshalJSON ¶
UnmarshalJSON defines custom decoding scheme
type PostIFPair ¶
used in topN.
type Reputation ¶
type Reputation interface { // Donate to post @p p wit @p s coins. // Note that if migrate is required, it must be done before donate. DonateAt(u Uid, p Pid, s LinoCoin) IF // user's freescore += @p r, NOTE: unit is COIN. IncFreeScore(u Uid, r Rep) // needs to be called every endblocker. Update(t Time) // current reputation of the user. GetReputation(u Uid) Rep // Round 0 is an invalidated round // Round 1 is a short round that will last for only one block, because round-1's // start time is set to 0. GetCurrentRound() (RoundId, Time) // current round and its start time. // ExportImporter ExportToFile(file string) error ImportFromFile(file string) error }
func NewReputation ¶
func NewReputation(s ReputationStore, bestN int, userMaxN int, roundDurationSeconds, sampleWindowSize, decayFactor int64) Reputation
type ReputationImpl ¶
type ReputationImpl struct { BestN int UserMaxN int RoundDurationSeconds int64 SampleWindowSize int64 DecayFactor int64 // contains filtered or unexported fields }
func (ReputationImpl) DonateAt ¶
func (rep ReputationImpl) DonateAt(u Uid, p Pid, amount LinoCoin) IF
Record @p u has donated to @p p with @p amount LinoCoin. Only the first UserMaxN posts will be counted and have impact. The invarience is that user will have only *one* round of donations unsettled, either because that round is current round(not ended yet), or the user has never donated after that round. So when a user donates, we first update user's reputation, then we add this donation to records.
func (ReputationImpl) ExportToFile ¶
func (rep ReputationImpl) ExportToFile(file string) error
ExportToFile - implementing ExporteImporter
func (ReputationImpl) GetCurrentRound ¶
func (rep ReputationImpl) GetCurrentRound() (RoundId, Time)
return the current round id the the start time of the round.
func (ReputationImpl) GetReputation ¶
func (rep ReputationImpl) GetReputation(u Uid) Rep
return the reputation of @p u.
func (ReputationImpl) ImportFromFile ¶
func (rep ReputationImpl) ImportFromFile(file string) error
ImportFromFile - implementing ExporteImporter
func (ReputationImpl) IncFreeScore ¶
func (rep ReputationImpl) IncFreeScore(u Uid, score Rep)
increase @p u user's reputation by @p score. To make added score permanent, add it on consumption, as reputation is only a temporory result, same in reputation migration.
func (ReputationImpl) StartNewRound ¶
func (rep ReputationImpl) StartNewRound(t Time)
write (RoundId + 1, t) into db and update current round
func (ReputationImpl) Update ¶
func (rep ReputationImpl) Update(t Time)
On BlockEnd(@p t), select out the seed set of the current round and start a new round.
type ReputationStore ¶
type ReputationStore interface { // Export all state to deterministic bytes Export() *UserReputationTable // Import state from bytes Import(tb *UserReputationTable) // Iterator over usernames IterateUsers(UserIterator) GetUserMeta(u Uid) *userMeta SetUserMeta(u Uid, data *userMeta) SetRoundMeta(r RoundId, dt *roundMeta) GetRoundMeta(r RoundId) *roundMeta // total donation power received of a @p post in @p r round. GetRoundPostMeta(r RoundId, p Pid) *roundPostMeta SetRoundPostMeta(r RoundId, p Pid, dt *roundPostMeta) DelRoundPostMeta(r RoundId, p Pid) /// ----------- In this round ------------- // RoundId is the current round, starts from 1. GetCurrentRound() RoundId // Global data. GetGameMeta() *gameMeta SetGameMeta(dt *gameMeta) }
ReputationStore - store reputation values. a simple wrapper around kv-store. It does not handle any reputation computation logic, except for init value for some field, like customer score. This interface should only be used by the reputation system implementation.
func NewReputationStore ¶
func NewReputationStore(s Store, initRep int64) ReputationStore
type Store ¶
type Store interface { Set(key []byte, val []byte) Get(key []byte) []byte Has(key []byte) bool Delete(key []byte) // Iterator over a domain of keys in ascending order. End is exclusive. // Start must be less than end, or the Iterator is invalid. // Iterator must be closed by caller. // To iterate over entire domain, use store.Iterator(nil, nil) // CONTRACT: No writes may happen within a domain while an iterator exists over it. Iterator(start, end []byte) db.Iterator }
Store - store.
type UserIterator ¶
type UserReputation ¶
type UserReputation struct { Username Uid `json:"username"` CustomerScore Rep `json:"customer_score"` FreeScore Rep `json:"free_score"` IsMiniDollar bool `json:"is_mini_dollar,omitempty"` }
UserReputation - pk: Username
type UserReputationTable ¶
type UserReputationTable struct {
Reputations []UserReputation `json:"reputations"`
}
UserReputationTable - pk by Username