book

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: 13 Imported by: 0

Documentation

Overview

Package book represents all the transactions necessary for the game.

Index

Constants

View Source
const (
	StateNotExists  = 0
	StateLive       = 1
	StateReconciled = 2
	StateCancelled  = 3
)

These constants define the different bet states.

Variables

This section is empty.

Functions

This section is empty.

Types

type BetInfo

type BetInfo struct {
	State         int
	Participants  []common.Address
	Moderator     common.Address
	AmountBetGWei *big.Float
	Expiration    time.Time
}

BetInfo represents information about a bet inside the contract.

type Book

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

Book represents a bank that allows for the reconciling of a game and information about account balances.

func New

func New(ctx context.Context, backend ethereum.Backend, privateKey *ecdsa.PrivateKey, contractID string) (*Book, error)

New returns a new bank with the ability to manage the game money.

func (*Book) AccountBalance

func (b *Book) AccountBalance(ctx context.Context, accountID string) (BalanceGWei *big.Float, err error)

AccountBalance will return the balance for the specified account. Only the owner of the smart contract can make this call.

func (*Book) Balance

func (b *Book) Balance(ctx context.Context) (GWei *big.Float, err error)

Balance will return the balance for the connected account.

func (*Book) BetDetails

func (b *Book) BetDetails(ctx context.Context, betID string) (BetInfo, error)

BetDetails will the details for the specied betID.

func (*Book) CancelBetExpired

func (b *Book) CancelBetExpired(ctx context.Context, betID string) (*types.Transaction, *types.Receipt, error)

CancelBetExpired allows any participant to cancel the bet after the bet as expired for 30 days and it isn't reconciled.

func (*Book) CancelBetModerator

func (b *Book) CancelBetModerator(ctx context.Context, betID string, cbm CancelBetModerator) (*types.Transaction, *types.Receipt, error)

CancelBetModerator allows the moderator to sign off on cancelling the bet.

func (*Book) CancelBetOwner

func (b *Book) CancelBetOwner(ctx context.Context, betID string, cbo CancelBetOwner) (*types.Transaction, *types.Receipt, error)

CancelBetOwner allows the owner to sign off on cancelling the bet.

func (*Book) CancelBetParticipants

func (b *Book) CancelBetParticipants(ctx context.Context, betID string, cbp CancelBetParticipants) (*types.Transaction, *types.Receipt, error)

CancelBetParticipants allows the participants to sign off on cancelling the bet.

func (*Book) CheckBalance

func (b *Book) CheckBalance(ctx context.Context, expBal *big.Float) error

CheckBalance pulls and compares the specified balance for a player.

func (*Book) Client

func (b *Book) Client() *ethereum.Client

Client returns the underlying contract client.

func (*Book) ContractID

func (b *Book) ContractID() string

ContractID returns contract id in use.

func (*Book) Deposit

func (b *Book) Deposit(ctx context.Context, amountGWei *big.Float) (*types.Transaction, *types.Receipt, error)

Deposit will add the given amount to the account's contract balance.

func (*Book) Drain

func (b *Book) Drain(ctx context.Context) (*types.Transaction, *types.Receipt, error)

Drain will drain the full value of the smart contract and transfer it to the owner address.

func (*Book) EthereumBalance

func (b *Book) EthereumBalance(ctx context.Context) (wei *big.Int, err error)

EthereumBalance returns the current balance for the account connecting this book.

func (*Book) Nonce

func (b *Book) Nonce(ctx context.Context, accountID string) (*big.Int, error)

Nonce will return the current nonce for the specified account.

func (*Book) PlaceBet

func (b *Book) PlaceBet(ctx context.Context, betID string, pb PlaceBet) (*types.Transaction, *types.Receipt, error)

PlaceBet adds a new bet to the smart contract. This bet will be live if accepted by the smart contract and all participants will be bound to the bet.

func (*Book) ReconcileBet

func (b *Book) ReconcileBet(ctx context.Context, betID string, rb ReconcileBet) (*types.Transaction, *types.Receipt, error)

ReconcileBet allows the moderator to sign off on the live bet and provide the winning accounts.

func (*Book) Sign

func (b *Book) Sign(betID string, nonce int) ([]byte, error)

Sign produces a signature for use with the smart contract call.

func (*Book) Withdraw

func (b *Book) Withdraw(ctx context.Context) (*types.Transaction, *types.Receipt, error)

Withdraw will move all the account's balance in the contract, to the account's wallet.

type CancelBetModerator

type CancelBetModerator struct {
	AmountFeeGWei *big.Float
	Nonce         *big.Int
	Moderator     common.Address
	Signature     []byte
}

CancelBetModerator represents the input required to cancel a bet by the moderator.

func (CancelBetModerator) Validate

func (cbm CancelBetModerator) Validate() error

Validate verifies the reconcile bet value is properly initialized.

type CancelBetOwner

type CancelBetOwner struct {
	AmountFeeGWei *big.Float
}

CancelBetOwner represents the input required to cancel a bet by the contract owner.

func (CancelBetOwner) Validate

func (cbo CancelBetOwner) Validate() error

Validate verifies the reconcile bet value is properly initialized.

type CancelBetParticipants

type CancelBetParticipants struct {
	AmountFeeGWei *big.Float
	Nonces        []*big.Int
	Signatures    [][]byte
}

CancelBetParticipants represents the input required to cancel a bet by the participants.

func (CancelBetParticipants) Validate

func (cbp CancelBetParticipants) Validate() error

Validate verifies the reconcile bet value is properly initialized.

type PlaceBet

type PlaceBet struct {
	AmountBetGWei *big.Float
	AmountFeeGWei *big.Float
	Expiration    time.Time
	Moderator     common.Address
	Participants  []common.Address
	Nonces        []*big.Int
	Signatures    [][]byte
}

PlaceBet represents the input required to place a bet.

func (PlaceBet) Validate

func (pb PlaceBet) Validate() error

Validate verifies the new bet value is properly initialized.

type ReconcileBet

type ReconcileBet struct {
	Nonce     *big.Int
	Moderator common.Address
	Signature []byte
	Winners   []common.Address
}

ReconcileBet represents the input required to reconcile a bet.

func (ReconcileBet) Validate

func (rb ReconcileBet) Validate() error

Validate verifies the reconcile bet value is properly initialized.

Jump to

Keyboard shortcuts

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