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.

v0 source pure

Package rep keeps a public work record for each address: how many tasks it completed and was paid for, and how many t...

Overview

Package rep keeps a public work record for each address: how many tasks it completed and was paid for, and how many tasks it posted and paid out.

A Book holds no coins and makes no calls. A realm owns a Book and writes one Record each time it pays for finished work. Any realm can import this package to keep its own records, or read another realm's records through that realm's public functions.

Constants 1

const DefaultRecent

1const DefaultRecent = 20
source

DefaultRecent is the number of recent records kept per address when NewBook is given a value below 1.

Functions 1

func NewBook

1func NewBook(maxRecent int) *Book
source

NewBook returns an empty Book that keeps up to maxRecent records per address.

Types 3

type Book

struct
1type Book struct {
2	profiles  avl.Tree // address string -> *Profile
3	total     int
4	volume    int64
5	maxRecent int
6}
source

Book is a set of profiles, keyed by address.

Methods on Book

func Add

method on Book
1func (b *Book) Add(r Record)
source

Add stores a paid record for both the doer and the poster. It panics if the record is not valid, so a realm cannot store a bad record by mistake.

func Completed

method on Book
1func (b *Book) Completed(addr address) int
source

Completed returns how many tasks addr finished and was paid for.

func Earned

method on Book
1func (b *Book) Earned(addr address) int64
source

Earned returns the total paid to addr.

func HasCompleted

method on Book
1func (b *Book) HasCompleted(addr address, n int) bool
source

HasCompleted reports whether addr finished at least n tasks. Realms can use it to gate features by proven work.

func Profile

method on Book
1func (b *Book) Profile(addr address) Profile
source

Profile returns a copy of the profile for addr. Unknown addresses return an empty profile.

func Size

method on Book
1func (b *Book) Size() int
source

Size returns the number of addresses with a profile.

func Total

method on Book
1func (b *Book) Total() int
source

Total returns the number of paid records in the Book.

func Volume

method on Book
1func (b *Book) Volume() int64
source

Volume returns the total amount recorded, capped at the int64 maximum.

type Profile

struct
1type Profile struct {
2	Completed int   // tasks this address finished and was paid for
3	Earned    int64 // total paid to this address
4	Posted    int   // tasks this address paid out to someone else
5	Spent     int64 // total this address paid out
6	recent    []Record
7}
source

Profile is the record of one address. It is returned by value, so callers cannot change the Book through it.

Methods on Profile

func Recent

method on Profile
1func (p Profile) Recent() []Record
source

Recent returns the newest records first. The slice is a copy.

type Record

struct
1type Record struct {
2	TaskID string
3	Title  string
4	Poster address
5	Doer   address
6	Amount int64
7	Denom  string
8	At     time.Time
9}
source

Record is one paid piece of work.

Dependencies

Imports 2

/p/g1jw2yrfqnd4fp90qadw88pnjgpden4vgagjvpe6/rep/v0

Imported by indexer

Source Files 2