bet

package
v0.0.0-...-0653a19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package bet provides an example of a core business API. Right now these calls are just wrapping the data/store layer. But at some point you will want to audit or something that isn't specific to the data/store layer.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.New("account not found")
	ErrInvalidAddress = errors.New("address is not in its proper form")
	ErrInvalidNonce   = errors.New("nonce must be 1 greater than previous nonce")
	ErrInvalidID      = errors.New("ID is not in its proper form")
)

Set of error variables for CRUD operations.

Functions

This section is empty.

Types

type Account

type Account struct {
	Address string `json:"address"`
	Nonce   int    `json:"nonce"`
}

Account represents an individual account

type Bet

type Bet struct {
	ID               string    `json:"id"`
	Status           string    `json:"status"`
	Description      string    `json:"description"`
	Terms            string    `json:"terms"`
	Amount           int       `json:"amount"`
	ModeratorAddress string    `json:"moderatorAddress"`
	Players          []Player  `json:"players"`
	DateExpired      time.Time `json:"dateExpired"`
	DateCreated      time.Time `json:"dateCreated"`
	DateUpdated      time.Time `json:"dateUpdated"`
}

Bet represents an individual bet.

type Core

type Core struct {
	// contains filtered or unexported fields
}

Core manages the set of APIs for product access.

func NewCore

func NewCore(log *zap.SugaredLogger, sqlxDB *sqlx.DB) Core

NewCore constructs a core for product api access.

func (Core) CreateAccount

func (c Core) CreateAccount(ctx context.Context, na NewAccount) (Account, error)

CreateAccount adds an Account to the database. It returns the created Account with fields populated.

func (Core) CreateBet

func (c Core) CreateBet(ctx context.Context, nb NewBet, now time.Time) (Bet, error)

CreateBet adds a Bet to the database.

func (Core) QueryBet

func (c Core) QueryBet(ctx context.Context, pageNumber int, rowsPerPage int) ([]Bet, error)

QueryBet gets all Bets from the database.

func (Core) QueryBetByID

func (c Core) QueryBetByID(ctx context.Context, betID string) (Bet, error)

QueryBetByID finds the bet identified by a given ID.

func (Core) UpdateAccount

func (c Core) UpdateAccount(ctx context.Context, address string, ua UpdateAccount) error

UpdateAccount modifies data about an Account. It will error if the specified address is invalid or does not reference an existing Account.

func (Core) UpdateBet

func (c Core) UpdateBet(ctx context.Context, betID string, uBet UpdateBet, now time.Time) error

UpdateBet modifies data about a Bet. It will error if the specified ID is invalid or does not reference an existing Bet.

type NewAccount

type NewAccount struct {
	Address string `json:"address"`
}

NewAccount contains information needed to create a new Account.

type NewBet

type NewBet struct {
	Description      string      `json:"description"`
	Terms            string      `json:"terms"`
	Amount           int         `json:"amount"`
	ModeratorAddress string      `json:"moderatorAddress"`
	Players          []NewPlayer `json:"players" validate:"required"`
	DateExpired      time.Time   `json:"dateExpired"`
}

NewBet is what we require from clients when adding a Bet.

type NewPlayer

type NewPlayer struct {
	Address string `db:"address"`
	InFavor bool   `db:"inFavor"`
}

NewPlayer represents the connection between a new Bet and an Account that is in a player role.

type Player

type Player struct {
	BetID   string `db:"betId"`
	Address string `db:"address"`
	InFavor bool   `db:"inFavor"`
}

Player represents the connection between a Bet and an Account that is in a player role.

type UpdateAccount

type UpdateAccount struct {
	Address string `json:"address"`
	Nonce   int    `json:"nonce"`
}

UpdateAccount contains information needed to update an Account.

type UpdateBet

type UpdateBet struct {
	Description      *string   `json:"description"`
	Terms            *string   `json:"terms"`
	Amount           *int      `json:"amount"`
	ModeratorAddress *string   `json:"moderatorAddress"`
	DateExpired      time.Time `json:"dateExpired"`
}

UpdateBet is what we require from clients when updating a Bet.

Directories

Path Synopsis
Package db contains bet/account/player/signature related CRUD functionality.
Package db contains bet/account/player/signature related CRUD functionality.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL