Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v1 source pure

Package rulecalc holds the evaluation rule schema for a grant round and the deterministic computation of its outcome....

Overview

Package rulecalc holds the evaluation rule schema for a grant round and the deterministic computation of its outcome. It has no state and moves no coins.

Constants 3

const WeightedSum, MajorityFirst

1const (
2	// WeightedSum: the winner has the highest sum of weight*score over all sheets.
3	WeightedSum Method = iota + 1
4	// MajorityFirst: each sheet's first place is its highest weighted app;
5	// the winner has the most first places.
6	MajorityFirst
7)
source

const LowestID, Refund

1const (
2	// LowestID: the tied app with the lowest ID wins.
3	LowestID TieBreak = iota + 1
4	// Refund: no winner; the grant returns to the customer.
5	Refund
6)
source

Functions 4

func AppsDigest

1func AppsDigest(apps []App, salt string) string
source

AppsDigest is the commitment to an application list, published before the rule phase and checked at reveal: hex(sha256) of one "Title|PkgPath|Payout\n" line per app, in order, followed by salt. It panics if a field contains "|" or a newline, or the salt contains a newline, since the same digest could then open to a different list.

Off-chain equivalent:

Example
1printf 'Title|PkgPath|Payout\n...salt' | sha256sum

func Compute

1func Compute(r Rule, nApps int, sheets []Sheet) (winner int, paid bool)
source

Compute returns the winning app ID. paid == false means the grant is refunded: no apps, fewer sheets than the quorum, or a top-level tie under the Refund tie-break. Sheets must already pass ValidateSheet.

func Totals

1func Totals(r Rule, nApps int, sheets []Sheet) []int
source

Totals returns the per-app figure the rule's method ranks by: weighted score sums for WeightedSum, first-place counts for MajorityFirst. Sheets must already pass ValidateSheet.

func ValidateSheet

1func ValidateSheet(r Rule, nApps int, s Sheet) error
source

ValidateSheet checks that s scores every app on every criterion within 0-10.

Types 6

type App

struct
1type App struct {
2	Title   string
3	PkgPath string
4	Payout  address
5}
source

App is one grant application. Its ID is its index in the revealed list.

type Criterion

struct
1type Criterion struct {
2	Name   string
3	Weight int
4}
source

Criterion is one named, weighted evaluation axis.

type Method

ident
1type Method int
source

Method is how evaluator score sheets are aggregated into a winner.

type Rule

struct
1type Rule struct {
2	Method    Method
3	Criteria  []Criterion
4	Quorum    int
5	Tie       TieBreak
6	Rationale string
7}
source

Rule is the procedure the evaluators agree on before applications are revealed. Rationale is shown to readers and never affects computation.

Methods on Rule

func Validate

method on Rule
1func (r Rule) Validate(nEvaluators int) error
source

Validate checks the rule against the schema for a round with nEvaluators joined evaluators.

type Sheet

struct
1type Sheet struct {
2	Evaluator address
3	Scores    [][]int
4}
source

Sheet is one evaluator's scores: Scores[app][criterion], apps ordered by ID 0..n-1, criteria in the order of Rule.Criteria.

type TieBreak

ident
1type TieBreak int
source

TieBreak decides a top-level tie.

Dependencies

Imports 5

/p/g1dxg6leh2vsde83qxcpprvj2xljqz6fg2jp2t08/rulecalc/v1

Imported by indexer

Source Files 7