model

package
v1.41.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Scale

func Scale(v, s0, s1 int) float64

Scale func scale: (V * 10^ (S0-S1))

func UndoScale

func UndoScale(v float64, s int) int

UndoScale Function to undo the scale calculation

func UpdateAccounts

func UpdateAccounts(operation string, fromTo map[string]Amount, accounts []*a.Account, result chan []*a.Account, e chan error)

UpdateAccounts function with some updates values in accounts and

func ValidateAccounts

func ValidateAccounts(validate Responses, accounts []*a.Account) error

ValidateAccounts function with some validates in accounts and DSL operations

func ValidateFromToOperation

func ValidateFromToOperation(ft FromTo, validate Responses, acc *a.Account) (Amount, Balance, error)

ValidateFromToOperation func that validate operate balance amount

Types

type Amount

type Amount struct {
	Asset string `json:"asset,omitempty" validate:"required" example:"BRL"`
	Value int    `json:"value,omitempty" validate:"required" example:"1000"`
	Scale int    `json:"scale,omitempty" validate:"gte=0" example:"2"`

} // @name Amount

Amount structure for marshaling/unmarshalling JSON.

swagger:model Amount @Description Amount is the struct designed to represent the amount of an operation.

func FindScale

func FindScale(asset string, v float64, s int) Amount

FindScale Function to find the scale for any value of a value

type Balance

type Balance struct {
	Available int `json:"available" example:"1500"`
	OnHold    int `json:"onHold" example:"500"`
	Scale     int `json:"scale" example:"2"`

} // @name Balance

Balance structure for marshaling/unmarshalling JSON.

swagger:model Balance @Description Balance is the struct designed to represent the account balance.

func OperateAmounts

func OperateAmounts(amount Amount, balance *a.Balance, operation string) Balance

OperateAmounts Function to sum or sub two amounts and normalize the scale

type Distribute

type Distribute struct {
	Remaining string   `json:"remaining,omitempty"`
	To        []FromTo `json:"to,omitempty" validate:"singletransactiontype,required,dive"`

} // @name Distribute

Distribute structure for marshaling/unmarshalling JSON.

swagger:model Distribute @Description Distribute is the struct designed to represent the distribution fields of an operation.

type FromTo

type FromTo struct {
	Account         string         `json:"account,omitempty" example:"@person1"`
	Amount          *Amount        `json:"amount,omitempty"`
	Share           *Share         `json:"share,omitempty"`
	Remaining       string         `json:"remaining,omitempty" example:"remaining"`
	Rate            *Rate          `json:"rate,omitempty"`
	Description     string         `json:"description,omitempty" example:"description"`
	ChartOfAccounts string         `json:"chartOfAccounts" example:"1000"`
	Metadata        map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,nonested,valuemax=2000"`
	IsFrom          bool           `json:"isFrom,omitempty" example:"true"`

} // @name FromTo

FromTo structure for marshaling/unmarshalling JSON.

swagger:model FromTo @Description FromTo is the struct designed to represent the from/to fields of an operation.

type Metadata

type Metadata struct {
	Key   string `json:"key,omitempty"`
	Value any    `json:"value,omitempty"`

} // @name Metadata

Metadata structure for marshaling/unmarshalling JSON.

swagger:model Metadata @Description Metadata is the struct designed to store metadata.

type Rate added in v1.31.0

type Rate struct {
	From       string `json:"from" validate:"required" example:"BRL"`
	To         string `json:"to" validate:"required" example:"USDe"`
	Value      int    `json:"value" validate:"required" example:"1000"`
	Scale      int    `json:"scale" validate:"gte=0" example:"2"`
	ExternalID string `json:"externalId" validate:"uuid,required" example:"00000000-0000-0000-0000-000000000000"`

} // @name Rate

Rate structure for marshaling/unmarshalling JSON.

swagger:model Rate @Description Rate is the struct designed to represent the rate fields of an operation.

func (Rate) IsEmpty added in v1.31.0

func (r Rate) IsEmpty() bool

IsEmpty method that set empty or nil in fields

type Responses

type Responses struct {
	Total        int
	Asset        string
	From         map[string]Amount
	To           map[string]Amount
	Sources      []string
	Destinations []string
	Aliases      []string
}

func ValidateSendSourceAndDistribute

func ValidateSendSourceAndDistribute(transaction Transaction) (*Responses, error)

ValidateSendSourceAndDistribute Validate send and distribute totals

type Send

type Send struct {
	Asset      string     `json:"asset,omitempty" validate:"required" example:"BRL"`
	Value      int        `json:"value,omitempty" validate:"required" example:"1000"`
	Scale      int        `json:"scale,omitempty" validate:"gte=0" example:"2"`
	Source     Source     `json:"source,omitempty" validate:"required"`
	Distribute Distribute `json:"distribute,omitempty" validate:"required"`

} // @name Send

Send structure for marshaling/unmarshalling JSON.

swagger:model Send @Description Send is the struct designed to represent the sending fields of an operation.

type Share

type Share struct {
	Percentage             int `json:"percentage,omitempty" validate:"required"`
	PercentageOfPercentage int `json:"percentageOfPercentage,omitempty"`

} // @name Share

Share structure for marshaling/unmarshalling JSON.

swagger:model Share @Description Share is the struct designed to represent the sharing fields of an operation.

type Source

type Source struct {
	Remaining string   `json:"remaining,omitempty" example:"remaining"`
	From      []FromTo `json:"from,omitempty" validate:"singletransactiontype,required,dive"`

} // @name Source

Source structure for marshaling/unmarshalling JSON.

swagger:model Source @Description Source is the struct designed to represent the source fields of an operation.

type Transaction

type Transaction struct {
	ChartOfAccountsGroupName string         `json:"chartOfAccountsGroupName,omitempty" example:"1000"`
	Description              string         `json:"description,omitempty" example:"Description"`
	Code                     string         `json:"code,omitempty" example:"00000000-0000-0000-0000-000000000000"`
	Pending                  bool           `json:"pending,omitempty" example:"false"`
	Metadata                 map[string]any `json:"metadata,omitempty" validate:"dive,keys,keymax=100,endkeys,nonested,valuemax=2000"`
	Send                     Send           `json:"send" validate:"required"`

} // @name Transaction

Transaction structure for marshaling/unmarshalling JSON.

swagger:model Transaction @Description Transaction is a struct designed to store transaction data.

Jump to

Keyboard shortcuts

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