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
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 (Account) GetAddress
func (a Account) GetAddress() string
type AccountMetadata
type AccountMetadata map[string]metadata.Metadata
type AccountsVolumes
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
type AggregatedVolumes struct {
Aggregated VolumesByAssets `bun:"aggregated,type:jsonb"`
}
type BalancesByAssets
type BalancesByAssets map[string]*big.Int
type BalancesByAssetsByAccounts map[string]BalancesByAssets
type Configuration
type Configuration struct {
Bucket string `json:"bucket" bun:"bucket,type:varchar(255)"`
Metadata metadata.Metadata `json:"metadata" bun:"metadata,type:jsonb,nullzero"`
Features features.FeatureSet `json:"features" bun:"features,type:jsonb"`
}
func NewDefaultConfiguration() Configuration
func (*Configuration) SetDefaults
func (c *Configuration) SetDefaults()
func (*Configuration) Validate
func (c *Configuration) Validate() error
type CreatedTransaction
type CreatedTransaction struct {
Transaction Transaction `json:"transaction"`
AccountMetadata AccountMetadata `json:"accountMetadata"`
}
func (CreatedTransaction) GetMemento
func (p CreatedTransaction) GetMemento() any
func (CreatedTransaction) Type
func (p CreatedTransaction) Type() LogType
type DeletedMetadata
type DeletedMetadata struct {
TargetType string `json:"targetType"`
TargetID any `json:"targetId"`
Key string `json:"key"`
}
func (DeletedMetadata) Type
func (s DeletedMetadata) Type() LogType
func (*DeletedMetadata) UnmarshalJSON
func (s *DeletedMetadata) UnmarshalJSON(data []byte) error
type ErrInvalidBucketName
type ErrInvalidBucketName struct {
// contains filtered or unexported fields
}
func (ErrInvalidBucketName) Error
func (e ErrInvalidBucketName) Error() string
func (ErrInvalidBucketName) Is
func (e ErrInvalidBucketName) Is(err error) bool
type ErrInvalidLedgerName
type ErrInvalidLedgerName struct {
// contains filtered or unexported fields
}
func (ErrInvalidLedgerName) Error
func (e ErrInvalidLedgerName) Error() string
func (ErrInvalidLedgerName) Is
func (e ErrInvalidLedgerName) Is(err error) bool
type Ledger
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
func MustNewWithDefault(name string) Ledger
func New
func New(name string, configuration Configuration) (*Ledger, error)
func NewWithDefaults
func NewWithDefaults(name string) (*Ledger, error)
func (Ledger) HasFeature
func (l Ledger) HasFeature(feature, value string) bool
func (Ledger) WithMetadata
func (l Ledger) WithMetadata(m metadata.Metadata) Ledger
type Log
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
func NewLog(payload LogPayload) Log
func (Log) ChainLog
func (l Log) ChainLog(previous *Log) Log
func (*Log) ComputeHash
func (l *Log) ComputeHash(previous *Log)
func (*Log) UnmarshalJSON
func (l *Log) UnmarshalJSON(data []byte) error
func (Log) WithIdempotencyKey
func (l Log) WithIdempotencyKey(key string) Log
type LogPayload
type LogPayload interface {
Type() LogType
}
func HydrateLog
func HydrateLog(_type LogType, data []byte) (LogPayload, error)
type LogType
type LogType int16
const (
SetMetadataLogType LogType = iota // "SET_METADATA"
NewLogType // "NEW_TRANSACTION"
RevertedTransactionLogType // "REVERTED_TRANSACTION"
DeleteMetadataLogType
)
func LogTypeFromString
func LogTypeFromString(logType string) LogType
func (LogType) MarshalJSON
func (lt LogType) MarshalJSON() ([]byte, error)
func (*LogType) Scan
func (lt *LogType) Scan(src interface{}) error
func (LogType) String
func (lt LogType) String() string
func (*LogType) UnmarshalJSON
func (lt *LogType) UnmarshalJSON(data []byte) error
func (LogType) Value
func (lt LogType) Value() (driver.Value, error)
type Memento
type Memento interface {
GetMemento() any
}
type Move
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
type Moves []*Move
func (Moves) ComputePostCommitEffectiveVolumes
func (m Moves) ComputePostCommitEffectiveVolumes() PostCommitVolumes
type PostCommitVolumes
type PostCommitVolumes map[string]VolumesByAssets
func (PostCommitVolumes) AddInput
func (a PostCommitVolumes) AddInput(account, asset string, input *big.Int)
func (PostCommitVolumes) AddOutput
func (a PostCommitVolumes) AddOutput(account, asset string, output *big.Int)
func (PostCommitVolumes) Copy
func (a PostCommitVolumes) Copy() PostCommitVolumes
func (PostCommitVolumes) Merge
func (a PostCommitVolumes) Merge(volumes PostCommitVolumes) PostCommitVolumes
type Posting
type Posting struct {
Source string `json:"source"`
Destination string `json:"destination"`
Amount *big.Int `json:"amount"`
Asset string `json:"asset"`
}
func NewPosting
func NewPosting(source string, destination string, asset string, amount *big.Int) Posting
type Postings
type Postings []Posting
func (Postings) Reverse
func (p Postings) Reverse() Postings
func (Postings) Validate
func (p Postings) Validate() (int, error)
type RevertedTransaction
type RevertedTransaction struct {
RevertedTransaction Transaction `json:"revertedTransaction"`
RevertTransaction Transaction `json:"transaction"`
}
func (RevertedTransaction) GetMemento
func (r RevertedTransaction) GetMemento() any
func (RevertedTransaction) Type
func (r RevertedTransaction) Type() LogType
type SavedMetadata
type SavedMetadata struct {
TargetType string `json:"targetType"`
TargetID any `json:"targetId"`
Metadata metadata.Metadata `json:"metadata"`
}
func (SavedMetadata) Type
func (s SavedMetadata) Type() LogType
func (*SavedMetadata) UnmarshalJSON
func (s *SavedMetadata) UnmarshalJSON(data []byte) error
type Transaction
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
func NewTransaction() Transaction
func (Transaction) InvolvedAccounts
func (tx Transaction) InvolvedAccounts() []string
func (Transaction) InvolvedDestinations
func (tx Transaction) InvolvedDestinations() map[string][]string
func (Transaction) IsReverted
func (tx Transaction) IsReverted() bool
func (Transaction) JSONSchemaExtend
func (Transaction) JSONSchemaExtend(schema *jsonschema.Schema)
func (Transaction) MarshalJSON
func (tx Transaction) MarshalJSON() ([]byte, error)
func (Transaction) Reverse
func (tx Transaction) Reverse() Transaction
func (Transaction) VolumeUpdates
func (tx Transaction) VolumeUpdates() []AccountsVolumes
func (Transaction) WithInsertedAt
func (tx Transaction) WithInsertedAt(date time.Time) Transaction
func (Transaction) WithMetadata
func (tx Transaction) WithMetadata(m metadata.Metadata) Transaction
func (Transaction) WithPostCommitEffectiveVolumes
func (tx Transaction) WithPostCommitEffectiveVolumes(volumes PostCommitVolumes) Transaction
func (Transaction) WithPostings
func (tx Transaction) WithPostings(postings ...Posting) Transaction
func (Transaction) WithReference
func (tx Transaction) WithReference(ref string) Transaction
func (Transaction) WithRevertedAt
func (tx Transaction) WithRevertedAt(timestamp time.Time) Transaction
func (Transaction) WithTimestamp
func (tx Transaction) WithTimestamp(ts time.Time) Transaction
type TransactionData
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
func NewTransactionData() TransactionData
func (TransactionData) WithPostings
func (data TransactionData) WithPostings(postings ...Posting) TransactionData
type Transactions
type Transactions struct {
Transactions []TransactionData `json:"transactions"`
}
type Volumes
type Volumes struct {
Input *big.Int `json:"input"`
Output *big.Int `json:"output"`
}
func NewEmptyVolumes
func NewEmptyVolumes() Volumes
func NewVolumesInt64
func NewVolumesInt64(input, output int64) Volumes
func (Volumes) Balance
func (v Volumes) Balance() *big.Int
func (Volumes) Copy
func (v Volumes) Copy() Volumes
func (Volumes) JSONSchemaExtend
func (Volumes) JSONSchemaExtend(schema *jsonschema.Schema)
func (Volumes) MarshalJSON
func (v Volumes) MarshalJSON() ([]byte, error)
func (*Volumes) Scan
func (v *Volumes) Scan(src interface{}) error
func (Volumes) Value
func (v Volumes) Value() (driver.Value, error)
type VolumesByAssets
type VolumesByAssets map[string]Volumes
func (VolumesByAssets) Balances
func (v VolumesByAssets) Balances() BalancesByAssets
type VolumesWithBalance
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