bank

package
v0.0.0-...-162b478 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0, MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxKeyAddress ctxKey = iota
)

Variables

View Source
var (
	ErrInsufficientFunds   = errors.New("insufficient funds")
	ErrOperationNotAllowed = errors.New("operation not allowed")
	ErrNothingToRefund     = errors.New("nothing to refund")
	ErrAuthNotFound        = errors.New("authorization not found")
	ErrAuthLocked          = errors.New("authorization is locked")
)

Functions

func AuthenticationCtx

func AuthenticationCtx() func(http.Handler) http.Handler

func ParseHeader

func ParseHeader(r *http.Request) (*types.Signature, types.Address, []byte, error)

func SetHeaders

func SetHeaders(w http.ResponseWriter, status int)

Types

type AuthModel

type AuthModel struct {
	UUID      uuid.UUID
	Available types.FIL
	Escrow    types.FIL
}

type AuthorizeParams

type AuthorizeParams struct {
	Proxy string `validate:"required,is-filecoin-address" json:"proxy"`
}

type Config

type Config struct {
	Env    string      `toml:"env"`
	Logger http.Logger `toml:"logger"`
	Db     Db          `toml:"database"`
	HTTP   http.HTTP   `toml:"http"`
	Wallet Wallet      `toml:"wallet"`
	Escrow Escrow      `toml:"escrow"`
}

func LoadConfiguration

func LoadConfiguration(cfgFilePath string) Config

type Db

type Db struct {
	Dsn          string `toml:"dsn"`
	MaxOpenConns int    `toml:"max-open-connections"`
	MaxIdleConns int    `toml:"max-idle-connections"`
	MaxIdleTime  string `toml:"max-idle-time"`
}

type DepositParams

type DepositParams struct {
	Amount types.FIL `validate:"required,is-valid-fil" json:"amount"`
}

type Escrow

type Escrow struct {
	Address  types.Address `toml:"address"`
	Deadline string        `toml:"deadline"`
}

type RedeemModel

type RedeemModel struct {
	Excess types.FIL
	SP     types.FIL
	CLI    types.FIL
}

type RedeemParams

type RedeemParams struct {
	UUID   uuid.UUID `validate:"required" json:"id"`
	Amount types.FIL `validate:"required,is-valid-fil" json:"amount"`
}

type RefundModel

type RefundModel struct {
	Available types.FIL
	Escrow    types.FIL
	Expired   types.FIL
}

type RegisterParams

type RegisterParams struct {
	ID    string    `validate:"required" json:"id"`
	Price types.FIL `validate:"required,is-valid-fil" json:"price"`
}

type Server

type Server struct {
	*http.Server

	BankService Service
}

func (*Server) JSON

func (s *Server) JSON(w http.ResponseWriter, r *http.Request, code int, value any)

func (*Server) RegisterValidators

func (s *Server) RegisterValidators()

func (*Server) Routes

func (s *Server) Routes(r chi.Router)

type Service

type Service interface {
	RegisterProxy(spid string, source string, price types.FIL) error
	Deposit(address string, price types.FIL) (types.FIL, error)
	Withdraw(address string, destination string, price types.FIL) (types.FIL, error)
	Balance(address string) (types.FIL, types.FIL, error)
	Authorize(address string, proxy string) (AuthModel, error)
	Refund(address string) (RefundModel, error)
	Verify(address string, uuid uuid.UUID, amount types.FIL) error
	Redeem(address string, uuid uuid.UUID, amount types.FIL) (RedeemModel, error)
}

type VerifyParams

type VerifyParams struct {
	UUID   uuid.UUID `validate:"required" json:"id"`
	Amount types.FIL `validate:"required,is-valid-fil" json:"amount"`
}

type Wallet

type Wallet struct {
	Address types.Address `toml:"address"`
}

type WithdrawParams

type WithdrawParams struct {
	Amount      types.FIL `validate:"required,is-valid-fil" json:"amount"`
	Destination string    `validate:"required,is-filecoin-address" json:"dst"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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