Skip to content Search Apps Documentation Source Content 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 campaign is the state machine behind Guildhall campaigns: bounties with a fixed reward per claim and a fixed ...

Overview

Package campaign is the state machine behind Guildhall campaigns: bounties with a fixed reward per claim and a fixed number of slots, for small tasks many people can do (write a post, translate a page, file a bug report).

Like gno.land/p/g1lnkytfqcjwllws63gvf0mv9yt04aswy4y9amhm/guildhall/bounty, it holds no funds and moves no coins. Transitions validate who is acting, mutate the campaign, and return the transfers the escrow realm must make.

The poster escrows Reward × Slots. Anyone except the poster and the reviewers can claim with a link to proof of the work; a pending claim reserves a slot. Any one reviewer approves (pays the reward) or rejects (frees the slot). Each address holds at most one pending or approved claim.

Example
1Open ──Close (poster, or anyone after the deadline)──▶ Closed (free slots refunded)
2Open ──(every slot paid)──▶ Closed
3
4Claim ──Approve──▶ Approved (reward paid)
5  └────Reject───▶ Rejected (slot freed; refunded if the campaign is closed)

Pending claims can still be reviewed after a campaign closes.

Constants 4

Variables 1

Functions 3

func New

1func New(p Params) (*Campaign, error)
source

New validates p and returns a funded, open campaign. When no reviewers are given, the poster reviews alone.

func ParseClaimStatus

1func ParseClaimStatus(s string) (ClaimStatus, bool)
source

ParseClaimStatus is the inverse of ClaimStatus.String.

func ParseStatus

1func ParseStatus(s string) (Status, bool)
source

ParseStatus is the inverse of Status.String.

Types 7

type Campaign

struct
 1type Campaign struct {
 2	ID          uint64
 3	Poster      address
 4	Title       string
 5	Description string
 6	Link        string
 7	Tags        []string
 8	Denom       string
 9	IsGRC20     bool
10	Reward      int64
11	Slots       int
12	Reviewers   []address
13	Deadline    time.Time // zero: no deadline
14	Status      Status
15	CreatedAt   time.Time
16	ClosedAt    time.Time
17
18	Paid     int // approved claims
19	Pending  int // claims awaiting review
20	Rejected int
21	Refunded int // slots returned to the poster
22
23	claims     avl.Tree // padded claim number -> *Claim
24	byClaimant avl.Tree // address -> latest claim number (int)
25}
source

Campaign is a pool of identical, individually paid tasks.

Methods on Campaign

func Approve

method on Campaign
1func (c *Campaign) Approve(caller address, number int, now time.Time) ([]Payout, error)
source

Approve pays a pending claim. Any one reviewer may approve. When the last slot is paid, the campaign closes.

func Claim

method on Campaign
1func (c *Campaign) Claim(claimant address, proof string, now time.Time) (int, error)
source

Claim records that claimant did the task, with a link to proof, and reserves a slot. It returns the claim number.

func ClaimCount

method on Campaign
1func (c *Campaign) ClaimCount() int
source

ClaimCount is the number of claims ever submitted.

func ClaimOf

method on Campaign
1func (c *Campaign) ClaimOf(addr address) *Claim
source

ClaimOf returns addr's most recent claim, or nil.

func Claims

method on Campaign
1func (c *Campaign) Claims(status *ClaimStatus, offset, limit int) (out []*Claim, more bool)
source

Claims returns up to limit claims, newest first, after skipping offset claims. With a status filter, only matching claims are counted.

func Close

method on Campaign
1func (c *Campaign) Close(caller address, now time.Time) ([]Payout, error)
source

Close stops new claims and refunds every slot that is neither paid nor awaiting review. The poster can close at any time; anyone can close once the deadline has passed.

func Escrowed

method on Campaign
1func (c *Campaign) Escrowed() int64
source

Escrowed is the amount still held for this campaign.

func Expired

method on Campaign
1func (c *Campaign) Expired(now time.Time) bool
source

Expired reports whether the campaign has a deadline that has passed.

func FreeSlots

method on Campaign
1func (c *Campaign) FreeSlots() int
source

FreeSlots is how many more claims an open campaign can take.

func GetClaim

method on Campaign
1func (c *Campaign) GetClaim(number int) *Claim
source

GetClaim returns claim number (1-based), or nil.

func IsReviewer

method on Campaign
1func (c *Campaign) IsReviewer(addr address) bool
source

IsReviewer reports whether addr may approve and reject claims.

func PaidOut

method on Campaign
1func (c *Campaign) PaidOut() int64
source

PaidOut is the amount paid to claimants so far.

func Reject

method on Campaign
1func (c *Campaign) Reject(caller address, number int, reason string, now time.Time) ([]Payout, error)
source

Reject turns down a pending claim and frees its slot. If the campaign has closed, the slot's reward goes back to the poster. The claimant may claim again while the campaign is open.

func Total

method on Campaign
1func (c *Campaign) Total() int64
source

Total is the amount escrowed when the campaign was posted.

type Claim

struct
 1type Claim struct {
 2	Number     int // 1-based, in order of submission
 3	Claimant   address
 4	Proof      string
 5	Status     ClaimStatus
 6	At         time.Time
 7	ReviewedBy address
 8	ReviewedAt time.Time
 9	Reason     string // why it was rejected
10}
source

Claim is one person's request to be paid for doing the task once.

type ClaimStatus

ident
1type ClaimStatus int
source

ClaimStatus is the state of a single claim.

Methods on ClaimStatus

func String

method on ClaimStatus
1func (s ClaimStatus) String() string
source

type Params

struct
 1type Params struct {
 2	ID          uint64
 3	Poster      address
 4	Title       string
 5	Description string
 6	Link        string
 7	Tags        []string
 8	Denom       string
 9	IsGRC20     bool
10	Reward      int64
11	Slots       int
12	Reviewers   []address
13	Deadline    time.Time
14	Now         time.Time
15}
source

Params are the inputs to New.

type Payout

struct
1type Payout struct {
2	Kind   PayoutKind
3	To     address
4	Amount int64
5	Claim  int
6}
source

Payout is a transfer the escrow realm must execute. Claim is the claim number for work payouts and 0 for refunds.

type PayoutKind

ident
1type PayoutKind string
source

PayoutKind says why escrowed funds move.

type Status

ident
1type Status int
source

Status is the lifecycle state of a campaign.

Methods on Status

func String

method on Status
1func (s Status) String() string
source

Dependencies

Source Files 2