Documentation
¶
Index ¶
- func CalculateTotal(fromTos []FromTo, send Send, t chan int64, ft chan map[string]Amount, ...)
- func Normalize(total, amount, remaining *Amount)
- func Scale(v, s0, s1 int64) int64
- func UndoScale(v float64, s int64) int64
- func UpdateBalances(operation string, fromTo map[string]Amount, balances []*Balance, ...)
- func ValidateBalancesRules(ctx context.Context, transaction Transaction, validate Responses, ...) error
- func ValidateFromToOperation(ft FromTo, validate Responses, balance *Balance) (Amount, Balance, error)
- type Amount
- type Balance
- type Distribute
- type FromTo
- type Metadata
- type Rate
- type Responses
- type Send
- type Share
- type Source
- type Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateTotal ¶
func CalculateTotal(fromTos []FromTo, send Send, t chan int64, ft chan map[string]Amount, sd chan []string)
CalculateTotal Calculate total for sources/destinations based on shares, amounts and remains
func Normalize ¶
func Normalize(total, amount, remaining *Amount)
Normalize func that Normalize scale from all values
func UpdateBalances ¶
func UpdateBalances(operation string, fromTo map[string]Amount, balances []*Balance, result chan []*Balance)
UpdateBalances function with some updates values in balances.
func ValidateBalancesRules ¶
func ValidateBalancesRules(ctx context.Context, transaction Transaction, validate Responses, balances []*Balance) error
ValidateBalancesRules function with some validates in accounts and DSL operations
Types ¶
type Amount ¶
type Amount struct {
Asset string `json:"asset,omitempty" validate:"required" example:"BRL"`
Value int64 `json:"value,omitempty" validate:"required" example:"1000"`
Scale int64 `json:"scale,omitempty" validate:"gte=0" example:"2"`
Operation string `json:"operation,omitempty"`
} // @name Amount
Amount structure for marshaling/unmarshalling JSON.
swagger:model Amount @Description Amount is the struct designed to represent the amount of an operation.
type Balance ¶
type Balance struct {
ID string `json:"id" example:"00000000-0000-0000-0000-000000000000"`
OrganizationID string `json:"organizationId" example:"00000000-0000-0000-0000-000000000000"`
LedgerID string `json:"ledgerId" example:"00000000-0000-0000-0000-000000000000"`
AccountID string `json:"accountId" example:"00000000-0000-0000-0000-000000000000"`
Alias string `json:"alias" example:"@person1"`
AssetCode string `json:"assetCode" example:"BRL"`
Available int64 `json:"available" example:"1500"`
OnHold int64 `json:"onHold" example:"500"`
Scale int64 `json:"scale" example:"2"`
Version int64 `json:"version" example:"1"`
AccountType string `json:"accountType" example:"creditCard"`
AllowSending bool `json:"allowSending" example:"true"`
AllowReceiving bool `json:"allowReceiving" example:"true"`
CreatedAt time.Time `json:"createdAt" example:"2021-01-01T00:00:00Z"`
UpdatedAt time.Time `json:"updatedAt" example:"2021-01-01T00:00:00Z"`
DeletedAt *time.Time `json:"deletedAt" example:"2021-01-01T00:00:00Z"`
Metadata map[string]any `json:"metadata,omitempty"`
} // @name Balance
Balance structure for marshaling/unmarshalling JSON.
swagger:model Balance @Description Balance is the struct designed to represent the account balance.
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"`
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 ¶
type Rate struct {
From string `json:"from" validate:"required" example:"BRL"`
To string `json:"to" validate:"required" example:"USDe"`
Value int64 `json:"value" validate:"required" example:"1000"`
Scale int64 `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.
type Responses ¶
type Responses struct {
Total int64
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 int64 `json:"value,omitempty" validate:"required" example:"1000"`
Scale int64 `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 {
} // @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.
func (Transaction) IsEmpty ¶
func (t Transaction) IsEmpty() bool
IsEmpty is a func that validate if transaction is Empty.