transaction

package
v3.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AliasKey

func AliasKey(alias, balanceKey string) string

AliasKey function to concatenate alias with balance key

func AppendIfNotExist

func AppendIfNotExist(slice []string, s []string) []string

AppendIfNotExist Append if not exist

func CalculateTotal

func CalculateTotal(fromTos []FromTo, transaction Transaction, transactionType string, t chan decimal.Decimal, ft chan map[string]Amount, sd chan []string, or chan map[string]string)

CalculateTotal Calculate total for sources/destinations based on shares, amounts and remains

func ConcatAlias

func ConcatAlias(i int, alias string) string

ConcatAlias function to concat alias with index

func DetermineOperation

func DetermineOperation(isPending bool, isFrom bool, transactionType string) string

DetermineOperation Function to determine the operation

func SplitAlias

func SplitAlias(alias string) string

SplitAlias function to split alias with index

func SplitAliasWithKey

func SplitAliasWithKey(alias string) string

SplitAliasWithKey extracts the substring after the '#' character from the provided alias or returns the alias if '#' is not present.

func ValidateBalancesRules

func ValidateBalancesRules(ctx context.Context, transaction Transaction, validate Responses, balances []*Balance) error

ValidateBalancesRules function with some validates in accounts and DSL operations

func ValidateFromToOperation

func ValidateFromToOperation(ft FromTo, validate Responses, balance *Balance) (Amount, Balance, error)

ValidateFromToOperation func that validate operate balance

Types

type Amount

type Amount struct {
	Asset           string          `json:"asset,omitempty" validate:"required" example:"BRL"`
	Value           decimal.Decimal `json:"value,omitempty" validate:"required" example:"1000"`
	Operation       string          `json:"operation,omitempty"`
	TransactionType string          `json:"transactionType,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"`
	Key            string          `json:"key" example:"asset-freeze"`
	AssetCode      string          `json:"assetCode" example:"BRL"`
	Available      decimal.Decimal `json:"available" example:"1500"`
	OnHold         decimal.Decimal `json:"onHold" example:"500"`
	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.

func OperateBalances

func OperateBalances(amount Amount, balance Balance) (Balance, error)

OperateBalances Function to sum or sub two balances 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 {
	AccountAlias    string         `json:"accountAlias,omitempty" example:"@person1"`
	BalanceKey      string         `json:"balanceKey,omitempty" example:"asset-freeze"`
	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"`
	Route           string         `json:"route,omitempty" validate:"omitempty,max=250" example:"00000000-0000-0000-0000-000000000000"`

} // @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.

func (FromTo) ConcatAlias

func (ft FromTo) ConcatAlias(i int) string

ConcatAlias function to concat alias with index.

func (FromTo) SplitAlias

func (ft FromTo) SplitAlias() string

SplitAlias function to split alias with index.

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      decimal.Decimal `json:"value" validate:"required" example:"1000"`
	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

func (r Rate) IsEmpty() bool

IsEmpty method that set empty or nil in fields

type Responses

type Responses struct {
	Total               decimal.Decimal
	Asset               string
	From                map[string]Amount
	To                  map[string]Amount
	Sources             []string
	Destinations        []string
	Aliases             []string
	Pending             bool
	TransactionRoute    string
	OperationRoutesFrom map[string]string
	OperationRoutesTo   map[string]string
}

func ValidateSendSourceAndDistribute

func ValidateSendSourceAndDistribute(ctx context.Context, transaction Transaction, transactionType string) (*Responses, error)

ValidateSendSourceAndDistribute Validate send and distribute totals

type Send

type Send struct {
	Asset      string          `json:"asset,omitempty" validate:"required" example:"BRL"`
	Value      decimal.Decimal `json:"value,omitempty" validate:"required" example:"1000"`
	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             int64 `json:"percentage,omitempty" validate:"required"`
	PercentageOfPercentage int64 `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"`
	Route                    string           `json:"route,omitempty" validate:"omitempty,max=250" example:"00000000-0000-0000-0000-000000000000"`
	TransactionDate          *TransactionDate `json:"transactionDate,omitempty" example:"2021-01-01T00:00:00Z"`
	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.

type TransactionDate

type TransactionDate time.Time

TransactionDate is a custom time type that supports multiple ISO 8601 formats including milliseconds

func (TransactionDate) After

func (td TransactionDate) After(t time.Time) bool

func (TransactionDate) IsZero

func (td TransactionDate) IsZero() bool

func (TransactionDate) MarshalJSON

func (td TransactionDate) MarshalJSON() ([]byte, error)

func (TransactionDate) Time

func (td TransactionDate) Time() time.Time

func (*TransactionDate) UnmarshalJSON

func (td *TransactionDate) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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