import "github.com/formancehq/ledger/internal"
- Constants
- Variables
- func ComputeIdempotencyHash(inputs any) string
- type Account
- type AccountMetadata
- type AccountsVolumes
- type AggregatedVolumes
- type BalancesByAssets
- type BalancesByAssetsByAccounts
- type Configuration
- type CreatedTransaction
- type DeletedMetadata
- type ErrInvalidBucketName
- type ErrInvalidLedgerName
- type Ledger
- type Log
- type LogPayload
- type LogType
- type Memento
- type Move
- type Moves
- type PostCommitVolumes
- type Posting
- type Postings
- type RevertedTransaction
- type SavedMetadata
- type Transaction
- func NewTransaction() Transaction
- func (tx Transaction) InvolvedAccounts() []string
- func (tx Transaction) InvolvedDestinations() map[string][]string
- func (tx Transaction) IsReverted() bool
- func (Transaction) JSONSchemaExtend(schema *jsonschema.Schema)
- func (tx Transaction) MarshalJSON() ([]byte, error)
- func (tx Transaction) Reverse() Transaction
- func (tx Transaction) VolumeUpdates() []AccountsVolumes
- func (tx Transaction) WithInsertedAt(date time.Time) Transaction
- func (tx Transaction) WithMetadata(m metadata.Metadata) Transaction
- func (tx Transaction) WithPostCommitEffectiveVolumes(volumes PostCommitVolumes) Transaction
- func (tx Transaction) WithPostings(postings ...Posting) Transaction
- func (tx Transaction) WithReference(ref string) Transaction
- func (tx Transaction) WithRevertedAt(timestamp time.Time) Transaction
- func (tx Transaction) WithTimestamp(ts time.Time) Transaction
- type TransactionData
- type Transactions
- type Volumes
- func NewEmptyVolumes() Volumes
- func NewVolumesInt64(input, output int64) Volumes
- func (v Volumes) Balance() *big.Int
- func (v Volumes) Copy() Volumes
- func (Volumes) JSONSchemaExtend(schema *jsonschema.Schema)
- func (v Volumes) MarshalJSON() ([]byte, error)
- func (v *Volumes) Scan(src interface{}) error
- func (v Volumes) Value() (driver.Value, error)
- type VolumesByAssets
- type VolumesWithBalance
- type VolumesWithBalanceByAssetByAccount
- type VolumesWithBalanceByAssets
const (
MetaTargetTypeAccount = "ACCOUNT"
MetaTargetTypeTransaction = "TRANSACTION"
)
const (
DefaultBucket = "_default"
)
const (
WORLD = "world"
)
var Zero = big.NewInt(0)
func ComputeIdempotencyHash(inputs any) string
type Account struct {
bun.BaseModel `bun:"table:accounts"`
Address string `json:"address" bun:"address"`
Metadata metadata.Metadata `json:"metadata" bun:"metadata,type:jsonb,default:'{}'"`
FirstUsage time.Time `json:"-" bun:"first_usage,nullzero"`
InsertionDate time.Time `json:"-" bun:"insertion_date,nullzero"`
UpdatedAt time.Time `json:"-" bun:"updated_at,nullzero"`
Volumes VolumesByAssets `json:"volumes,omitempty" bun:"volumes,scanonly"`
EffectiveVolumes VolumesByAssets `json:"effectiveVolumes,omitempty" bun:"effective_volumes,scanonly"`
}
func (a Account) GetAddress() string
type AccountMetadata map[string]metadata.Metadata
type AccountsVolumes struct {
bun.BaseModel `bun:"accounts_volumes"`
Account string `bun:"accounts_address,type:varchar"`
Asset string `bun:"asset,type:varchar"`
Input *big.Int `bun:"input,type:numeric"`
Output *big.Int `bun:"output,type:numeric"`
}
type AggregatedVolumes struct {
Aggregated VolumesByAssets `bun:"aggregated,type:jsonb"`
}
type BalancesByAssets map[string]*big.Int
type BalancesByAssetsByAccounts map[string]BalancesByAssets
type Configuration struct {
Bucket string `json:"bucket" bun:"bucket,type:varchar(255)"`
Metadata metadata.Metadata `json:"metadata" bun:"metadata,type:jsonb"`
Features features.FeatureSet `json:"features" bun:"features,type:jsonb"`
}
func NewDefaultConfiguration() Configuration
func (c *Configuration) SetDefaults()
func (c *Configuration) Validate() error
type CreatedTransaction struct {
Transaction Transaction `json:"transaction"`
AccountMetadata AccountMetadata `json:"accountMetadata"`
}
func (p CreatedTransaction) GetMemento() any
func (p CreatedTransaction) Type() LogType
type DeletedMetadata struct {
TargetType string `json:"targetType"`
TargetID any `json:"targetId"`
Key string `json:"key"`
}
func (s DeletedMetadata) Type() LogType
func (s *DeletedMetadata) UnmarshalJSON(data []byte) error
type ErrInvalidBucketName struct {
// contains filtered or unexported fields
}
func (e ErrInvalidBucketName) Error() string
func (e ErrInvalidBucketName) Is(err error) bool
type ErrInvalidLedgerName struct {
// contains filtered or unexported fields
}
func (e ErrInvalidLedgerName) Error() string
func (e ErrInvalidLedgerName) Is(err error) bool
type Ledger struct {
bun.BaseModel `bun:"_system.ledgers,alias:ledgers"`
Configuration
ID int `json:"id" bun:"id,type:int,scanonly"`
Name string `json:"name" bun:"name,type:varchar(255),pk"`
AddedAt time.Time `json:"addedAt" bun:"added_at,type:timestamp,nullzero"`
}
func MustNewWithDefault(name string) Ledger
func New(name string, configuration Configuration) (*Ledger, error)
func NewWithDefaults(name string) (*Ledger, error)
func (l Ledger) HasFeature(feature, value string) bool
func (l Ledger) WithMetadata(m metadata.Metadata) Ledger
Log represents atomic actions made on the ledger.
type Log struct {
bun.BaseModel `bun:"table:logs,alias:logs"`
Type LogType `json:"type" bun:"type,type:log_type"`
Data LogPayload `json:"data" bun:"data,type:jsonb"`
Date time.Time `json:"date" bun:"date,type:timestamptz,nullzero"`
IdempotencyKey string `json:"idempotencyKey" bun:"idempotency_key,type:varchar(256),unique,nullzero"`
// IdempotencyHash is a signature used when using IdempotencyKey.
// It allows to check if the usage of IdempotencyKey match inputs given on the first idempotency key usage.
IdempotencyHash string `json:"idempotencyHash" bun:"idempotency_hash,unique,nullzero"`
ID int `json:"id" bun:"id,unique,type:numeric"`
Hash []byte `json:"hash" bun:"hash,type:bytea"`
}
func NewLog(payload LogPayload) Log
func (l Log) ChainLog(previous *Log) Log
func (l *Log) ComputeHash(previous *Log)
func (l *Log) UnmarshalJSON(data []byte) error
func (l Log) WithIdempotencyKey(key string) Log
type LogPayload interface {
Type() LogType
}
func HydrateLog(_type LogType, data []byte) (LogPayload, error)
type LogType int16
const (
SetMetadataLogType LogType = iota // "SET_METADATA"
NewLogType // "NEW_TRANSACTION"
RevertedTransactionLogType // "REVERTED_TRANSACTION"
DeleteMetadataLogType
)
func LogTypeFromString(logType string) LogType
func (lt LogType) MarshalJSON() ([]byte, error)
func (lt *LogType) Scan(src interface{}) error
func (lt LogType) String() string
func (lt *LogType) UnmarshalJSON(data []byte) error
func (lt LogType) Value() (driver.Value, error)
type Memento interface {
GetMemento() any
}
type Move struct {
bun.BaseModel `bun:"table:moves"`
TransactionID int `bun:"transactions_id,type:bigint"`
IsSource bool `bun:"is_source,type:bool"`
Account string `bun:"accounts_address,type:varchar"`
Amount *bunpaginate.BigInt `bun:"amount,type:numeric"`
Asset string `bun:"asset,type:varchar"`
InsertionDate time.Time `bun:"insertion_date,type:timestamp,nullzero"`
EffectiveDate time.Time `bun:"effective_date,type:timestamp,nullzero"`
PostCommitVolumes *Volumes `bun:"post_commit_volumes,type:jsonb"`
PostCommitEffectiveVolumes *Volumes `bun:"post_commit_effective_volumes,type:jsonb,scanonly"`
}
type Moves []*Move
func (m Moves) ComputePostCommitEffectiveVolumes() PostCommitVolumes
type PostCommitVolumes map[string]VolumesByAssets
func (a PostCommitVolumes) AddInput(account, asset string, input *big.Int)
func (a PostCommitVolumes) AddOutput(account, asset string, output *big.Int)
func (a PostCommitVolumes) Copy() PostCommitVolumes
func (a PostCommitVolumes) Merge(volumes PostCommitVolumes) PostCommitVolumes
type Posting struct {
Source string `json:"source"`
Destination string `json:"destination"`
Amount *big.Int `json:"amount"`
Asset string `json:"asset"`
}
func NewPosting(source string, destination string, asset string, amount *big.Int) Posting
type Postings []Posting
func (p Postings) Reverse() Postings
func (p Postings) Validate() (int, error)
type RevertedTransaction struct {
RevertedTransaction Transaction `json:"revertedTransaction"`
RevertTransaction Transaction `json:"transaction"`
}
func (r RevertedTransaction) GetMemento() any
func (r RevertedTransaction) Type() LogType
type SavedMetadata struct {
TargetType string `json:"targetType"`
TargetID any `json:"targetId"`
Metadata metadata.Metadata `json:"metadata"`
}
func (s SavedMetadata) Type() LogType
func (s *SavedMetadata) UnmarshalJSON(data []byte) error
type Transaction struct {
bun.BaseModel `bun:"table:transactions,alias:transactions"`
TransactionData
ID int `json:"id" bun:"id,type:numeric"`
RevertedAt *time.Time `json:"revertedAt,omitempty" bun:"reverted_at,type:timestamp without time zone"`
// PostCommitVolumes are the volumes of each account/asset after a transaction has been committed.
// Those volumes will never change as those are computed in flight.
PostCommitVolumes PostCommitVolumes `json:"postCommitVolumes,omitempty" bun:"post_commit_volumes,type:jsonb"`
// PostCommitEffectiveVolumes are the volumes of each account/asset after the transaction TransactionData.Timestamp.
// Those volumes are also computed in flight, but can be updated if a transaction is inserted in the past.
PostCommitEffectiveVolumes PostCommitVolumes `json:"postCommitEffectiveVolumes,omitempty" bun:"post_commit_effective_volumes,type:jsonb,scanonly"`
}
func NewTransaction() Transaction
func (tx Transaction) InvolvedAccounts() []string
func (tx Transaction) InvolvedDestinations() map[string][]string
func (tx Transaction) IsReverted() bool
func (Transaction) JSONSchemaExtend(schema *jsonschema.Schema)
func (tx Transaction) MarshalJSON() ([]byte, error)
func (tx Transaction) Reverse() Transaction
func (tx Transaction) VolumeUpdates() []AccountsVolumes
func (tx Transaction) WithInsertedAt(date time.Time) Transaction
func (tx Transaction) WithMetadata(m metadata.Metadata) Transaction
func (tx Transaction) WithPostCommitEffectiveVolumes(volumes PostCommitVolumes) Transaction
func (tx Transaction) WithPostings(postings ...Posting) Transaction
func (tx Transaction) WithReference(ref string) Transaction
func (tx Transaction) WithRevertedAt(timestamp time.Time) Transaction
func (tx Transaction) WithTimestamp(ts time.Time) Transaction
type TransactionData struct {
Postings Postings `json:"postings" bun:"postings,type:jsonb"`
Metadata metadata.Metadata `json:"metadata" bun:"metadata,type:jsonb,default:'{}'"`
Timestamp time.Time `json:"timestamp" bun:"timestamp,type:timestamp without time zone,nullzero"`
Reference string `json:"reference,omitempty" bun:"reference,type:varchar,unique,nullzero"`
InsertedAt time.Time `json:"insertedAt,omitempty" bun:"inserted_at,type:timestamp without time zone,nullzero"`
}
func NewTransactionData() TransactionData
func (data TransactionData) WithPostings(postings ...Posting) TransactionData
type Transactions struct {
Transactions []TransactionData `json:"transactions"`
}
type Volumes struct {
Input *big.Int `json:"input"`
Output *big.Int `json:"output"`
}
func NewEmptyVolumes() Volumes
func NewVolumesInt64(input, output int64) Volumes
func (v Volumes) Balance() *big.Int
func (v Volumes) Copy() Volumes
func (Volumes) JSONSchemaExtend(schema *jsonschema.Schema)
func (v Volumes) MarshalJSON() ([]byte, error)
func (v *Volumes) Scan(src interface{}) error
func (v Volumes) Value() (driver.Value, error)
type VolumesByAssets map[string]Volumes
func (v VolumesByAssets) Balances() BalancesByAssets
type VolumesWithBalance struct {
Input *big.Int `json:"input" bun:"input"`
Output *big.Int `json:"output" bun:"output"`
Balance *big.Int `json:"balance" bun:"balance"`
}
type VolumesWithBalanceByAssetByAccount struct {
Account string `json:"account" bun:"account"`
Asset string `json:"asset" bun:"asset"`
VolumesWithBalance
}
type VolumesWithBalanceByAssets map[string]*VolumesWithBalance
Generated by gomarkdoc