librefund

package module
v0.0.0-...-8f31e64 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: MIT Imports: 21 Imported by: 0

README

LibreFund

WARNING: Project is still in alpha, backwards incompatible changes will be made. Not ready for release. USE AT YOUR OWN RISK.

To paraphrase Dominic Tarr

"We need another way to fund software. All the other ways are broken or unscalable. We need to align the interests of the users with developers. We need to feed developers, and the software needs to be freely distributable."

This project is another attempt at this.

If you believe the software unstable, pay for stability.

If you believe the software badly documented, pay for it to be to be documented.

Users align with the project's maintainer by funding aspects of the project they want worked on. The choice is conveyed by the maintainer offering a set of objectives (think OKRs). By offering the right choices for funding, the maintainer better understands what needs work.

But why be the only one paying? Free software is for everyone, you can wait for others to pay.

We need to align between paying users too. Its worth more if others give -with- you. Through a form of crowd matching, you pay for others to pay. The more you give, the more others give.

Hopefully with this approach, we can have better sustainable software for all.

Here you will find instructions on how to build, test, and run the service. For using the system and other information, please refer to the documentation section.

Project Goals

  1. Accountability: Facilitate accountability among all parties. Without trust, whats the point? Transparency will promote it amongst those concerned. It will help users gauge their contributions value. For the project maintainer, they must show themselves responsible while being protected against mischives or bad luck.

  2. Modifiable: Lead by following. Embody free software by emphasising its benefits. Make the source code clear and easy to modify. It means test coverage to avoid regressions, and other tests to document features. The project must be easy to fork.

  3. Simplicity: Simple to self-host, simple to give contributions, simple to operate. Lowering the cognitive load is a long term benefit for everyone. It means avoiding feature creep. It means making the project intuitive.

Documentation

Similar Projects

Building

Requirements:

go build ./cmd/librefund

Testing

To run all unit tests in the project, use Go's standard method.

go test ./...

Try it out

You can can give librefund a quick spin by using the project's test service data.

cd ./service/testdata/isolated
go run ../../../cmd/librefund

Documentation

Index

Constants

View Source
const AccountNameSeparator = "/"
View Source
const AgreedToTermsEventType = "terms agreed"
View Source
const AnonymousAccount = "anonymous"
View Source
const CancelDir = "cancel"

CancelDir is the path whose contents should be cancelled.

View Source
const ClaimDir = "claim"

ClaimDir is the path whose contents should be claimed.

View Source
const ListenCGI = "CGI"
View Source
const ListenFastCGI = "FastCGI"
View Source
const ListenHTTP = "HTTP"
View Source
const MaintainerAccount = "maintainer"
View Source
const ObjectiveAccount = "objective"

Variables

View Source
var AssetDir embed.FS
View Source
var DefaultConfig = Config{
	AgreementsFile: StringRef("var/agreements.json"),

	BitcoinConfirmTarget:            IntRef(500),
	BitcoinDisplayUnit:              StringRef(""),
	BitcoinEnable:                   BoolRef(false),
	BitcoinTransactionConfirmations: IntRef(5),
	BitcoinRPCConnect:               StringRef(""),
	BitcoinRPCPass:                  StringRef(""),
	BitcoinRPCUser:                  StringRef(""),
	BitcoinWallet:                   StringRef("funding"),
	HTTPBaseURL:                     StringRef("http://localhost:80"),
	GNUTalerAutoRefund:              DurationRef(time.Hour),
	GNUTalerEnable:                  BoolRef(false),
	GNUTalerInstance:                StringRef("default"),
	ListenAddr:                      StringRef(":80"),
	ListenProtocol:                  StringRef(ListenHTTP),
	LogCommands:                     BoolRef(false),
	ProjectDirectory:                StringRef("var/project"),
	ServiceAgreementEnable:          BoolRef(false),
	ServiceAgreementFile:            StringRef("var/service-agreement.html"),
	TestPaymentGatewayEnable:        BoolRef(false),
	TransactionFile:                 StringRef("var/transactions.json"),
}
View Source
var HTMLServiceAgreement string
View Source
var TrZero = &Transaction{}

Functions

func AddCurrency

func AddCurrency(
	code string,
	grapheme string,
	template string,
	decimal string,
	thousand string,
	fraction int,
	showFraction bool,
) *money.Currency

AddCurrency registers a new currency. The method is identical to Rhymod's go-money with the exception of the additional 'showFraction', indicating whether the trailing fraction amount (cents) should be displayed.

func AddCurrencyUnit

func AddCurrencyUnit(
	curCode string,
	unit CurrencyUnit,
) error

AddCurrencyUnit adds a new unit the currency can be displayed in.

func ApplyFileConfig

func ApplyFileConfig(cfg *Config, filePath string) error

ApplyFileConfig loads the configuration described by the given yaml file.

func BoolRef

func BoolRef(arg bool) *bool

func Decimal

func Decimal(arg *Money) decimal.Decimal

func DisplayCurrencyInUnit

func DisplayCurrencyInUnit(
	unitCode string,
) error

DisplayCurrencyInUnit uses the given currency unit when shown to the user.

Using an empty unitCode resets the default unit.

func DurationRef

func DurationRef(dur time.Duration) *time.Duration

func GetDurationRef

func GetDurationRef(arg *time.Duration, name string) (time.Duration, error)

func GetStringRef

func GetStringRef(arg *string, name string) (string, error)

func IntRef

func IntRef(arg int) *int

func IsAnonymousAccount

func IsAnonymousAccount(account string) bool

func IsMaintainerAccount

func IsMaintainerAccount(account string) bool

func IsObjectiveAccount

func IsObjectiveAccount(account string) bool

func MustDecimal

func MustDecimal(amount string) *decimal.Decimal

func NewAnonymousAccount

func NewAnonymousAccount(paymentID string, curCode string) string

func NewMaintainerAccount

func NewMaintainerAccount(curCode string) string

func NewObjectiveAccount

func NewObjectiveAccount(obj *Objective) string

func PanicOnErr

func PanicOnErr(err error)

func PaymentIDFromAccount

func PaymentIDFromAccount(acc string) (string, error)

func RequireStringRef

func RequireStringRef(s *string, name string) error

func SetBitcoinTestConfig

func SetBitcoinTestConfig(cfg *Config)

func StringRef

func StringRef(arg string) *string

func TimeRef

func TimeRef(arg time.Time) *time.Time

Types

type AgreedToTermsEvent

type AgreedToTermsEvent struct {
	CreatedAt     time.Time
	Event         string
	Terms         string
	TransactionID TransactionID
}

type AgreementStore

type AgreementStore struct {
	FilePath string
	// contains filtered or unexported fields
}

func OpenAgreementStore

func OpenAgreementStore(
	filePath string,
	terms string,
) (*AgreementStore, error)

func (*AgreementStore) AgreeToTerms

func (o *AgreementStore) AgreeToTerms(
	trID TransactionID,
	terms string,
) error

func (*AgreementStore) Close

func (o *AgreementStore) Close() error

func (*AgreementStore) GetServiceAgreement

func (o *AgreementStore) GetServiceAgreement() (string, error)

type Callback

type Callback func(ev Event)

type Config

type Config struct {
	// AgreementsFile is where user agreements, such as Terms of Service, is stored.
	AgreementsFile *string `yaml:"agreements-file,omitempty"`
	BitcoinEnable  *bool   `yaml:"bitcoin-enable,omitempty"`
	// BitcoinConfirmTarget is the the average number of blocks expected
	// for confirmations.
	BitcoinConfirmTarget *int `yaml:"bitcoin-confirm-target,omitempty"`
	// BitcoinUnit is the unit to display bitcoin (BTC, mBTC, nBTC, etc)
	BitcoinDisplayUnit *string `yaml:"bitcoin-display-unit,omitempty"`
	//BitcoinTransactionConfirmations are the number of blocks expected
	//confirmed before considering a transaction successful.
	BitcoinTransactionConfirmations *int           `yaml:"bitcoin-transaction-confirmations"`
	BitcoinNetwork                  *string        `yaml:"bitcoin-network"`
	BitcoinRPCConnect               *string        `yaml:"bitcoin-rpc-connect,omitempty"`
	BitcoinRPCPass                  *string        `yaml:"bitcoin-rpc-pass,omitempty"`
	BitcoinRPCUser                  *string        `yaml:"bitcoin-rpc-user,omitempty"`
	BitcoinWallet                   *string        `yaml:"bitcoin-wallet,omitempty"`
	GNUTalerAutoRefund              *time.Duration `yaml:"gnu-taler-auto-refund"`
	GNUTalerEnable                  *bool          `yaml:"gnu-taler-enable"`
	GNUTalerEndpoint                *string        `yaml:"gnu-taler-endpoint"`
	GNUTalerInstance                *string        `yaml:"gnu-taler-instance"`
	GNUTalerPassword                *string        `yaml:"gnu-taler-password"`
	GNUTalerUser                    *string        `yaml:"gnu-taler-user"`
	// HTTPBaseURL is used for redirects back from payment services.  There
	// may be a better way to handle this.
	HTTPBaseURL    *string `yaml:"http-base-url,omitempty"`
	ListenAddr     *string `yaml:"listen-addr,omitempty"`
	ListenProtocol *string `yaml:"listen-protocol,omitempty"`
	LogCommands    *bool   `yaml:"log-commands,omitempty"`
	// MinContribution is the lowest amount, by currency, allowed to be contributed.
	MinContribution map[string]decimal.Decimal `yaml:"min-contribution"`
	// MaxContribution is the highest amount, by currency, allowed to be contributed.
	MaxContribution map[string]decimal.Decimal `yaml:"max-contribution"`
	// ProjectDirectory is where projects are defined.
	ProjectDirectory       *string `yaml:"project-directory,omitempty"`
	ServiceAgreementEnable *bool   `yaml:"service-agreement-enable,omitempty"`
	ServiceAgreementFile   *string `yaml:"service-agreement-file,omitempty"`
	// ShowAlternativeCurrency will show money in an additional currency to
	// aid users when dealing with crypto tokens.
	ShowAlternativeCurrency *string `yaml:"show-alternative-currency"`
	SMTPAddress             *string `yaml:"smtp-address,omitempty"`
	SMTPNotifyContribution  *bool   `yaml:"smtp-notify-contribution,omitempty"`
	SMTPPassword            *string `yaml:"smtp-password,omitempty"`
	SMTPRecipients          *string `yaml:"smtp-recipients,omitempty"`
	SMTPUser                *string `yaml:"smtp-user,omitempty"`
	// SuggestedContributions is a list of recommended amounts when contributing.
	SuggestedContributions map[string][]decimal.Decimal `yaml:"suggested-contributions,omitempty"`
	// TestPaymentGatewayEnable enables an always successful payment
	// gateway which accepts all currencies.
	//
	// Other payment methods must be disabled.
	TestPaymentGatewayEnable *bool `yaml:"test-payment-gateway-enable,omitempty"`
	// TransactionFile records all monetary transactions.
	TransactionFile *string `yaml:"transaction-file,omitempty"`
}

Config is a set of global parameters for running the service.

func LoadConfigFromEnv

func LoadConfigFromEnv() Config

LoadConfigFromEnv load configuration from the file defined by 'FUNDING_CONFIG'.

func LoadConfigFromFile

func LoadConfigFromFile(filePath string) Config

func LoadTestConfig

func LoadTestConfig() Config

func (*Config) Apply

func (c *Config) Apply(arg Config)

type Contribute

type Contribute struct {
	Project       *Project      `json:"project"`
	Objective     *Objective    `json:"objective"`
	TransactionID TransactionID `json:"transactionID"`
	RedirectURL   string        `json:"redirectUrl,omitempty"`
}

type Contribution

type Contribution struct {
	CreatedAt time.Time `json:"createdAt"`
	Total     *Money    `json:"total"`

	Project   string
	Objective string
}

Contribution describes the effect of a transfer on the given objective.

func NewContribution

func NewContribution(
	projectName string,
	objectiveName string,
	tx Transaction,
) (*Contribution, error)

type ContributionDetails

type ContributionDetails struct {
	AgreeToTerms   bool
	Amount         string
	Bitcoin        interface{}
	TransferMethod string
}

type CurrencyUnit

type CurrencyUnit struct {
	// UnitCode is a globally unique code representing the unit.
	UnitCode string
	Grapheme string
	Template string
	Fraction int
}

CurrencyUnit is unit in which a currency can be represented. For example 'BTC' and 'sats'.

func GetCurrencyUnit

func GetCurrencyUnit(
	unitCode string,
) (*CurrencyUnit, *money.Currency)

GetCurrencyUnit returns information on a type of unit of currency and its currency code.

func GetDisplayCurrencyUnit

func GetDisplayCurrencyUnit(
	curCode string,
) *CurrencyUnit

Get the unit to use when displaying a currency.

type DiskTransactionStore

type DiskTransactionStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDiskTransactionStore

func NewDiskTransactionStore(logger *EventLog) (*DiskTransactionStore, error)

func (*DiskTransactionStore) FindTransactions

func (d *DiskTransactionStore) FindTransactions(
	fn TransactionPredicate,
) ([]Transaction, error)

func (*DiskTransactionStore) GetAccountBalance

func (d *DiskTransactionStore) GetAccountBalance(acc string) (*Money, error)

func (*DiskTransactionStore) GetTransaction

func (d *DiskTransactionStore) GetTransaction(
	txID TransactionID,
) (Transaction, error)

func (*DiskTransactionStore) SaveTransaction

func (d *DiskTransactionStore) SaveTransaction(tx Transaction) error

type Event

type Event interface {
	Name() string
	New() interface{}
}

type EventHeader

type EventHeader struct {
	Event string `json:"event"`
}

type EventLog

type EventLog struct {
	// contains filtered or unexported fields
}

func NewEventLog

func NewEventLog(fp string) *EventLog

func (*EventLog) RegisterCallback

func (s *EventLog) RegisterCallback(event string, callback Callback)

func (*EventLog) RegisterEvent

func (s *EventLog) RegisterEvent(event Event)

func (*EventLog) Start

func (s *EventLog) Start() error

func (*EventLog) Stop

func (s *EventLog) Stop()

func (*EventLog) WriteEvent

func (s *EventLog) WriteEvent(event Event) error

type FileSystemStore

type FileSystemStore struct {
	RootDir      string
	VersionStore YAMLVersionStore
}

FileSystemStore manages the persistance of Projects and Objectives using the filesystem.

func NewFileSystemStore

func NewFileSystemStore(config Config, rootDir string) (*FileSystemStore, error)

func (*FileSystemStore) DeleteObjective

func (o *FileSystemStore) DeleteObjective(
	projName string,
	objName string,
) error

func (*FileSystemStore) FindObjectivesByProject

func (o *FileSystemStore) FindObjectivesByProject(
	name string,
) ([]*Objective, error)

func (*FileSystemStore) GetInitializedObjective

func (o *FileSystemStore) GetInitializedObjective(
	projName string,
	objName string,
) (*Objective, error)

LoadObjective retreives the given objective from the filesystem.

func (*FileSystemStore) GetInitializedProject

func (o *FileSystemStore) GetInitializedProject(name string) (*Project, error)

func (*FileSystemStore) GetObjective

func (o *FileSystemStore) GetObjective(
	projName string,
	objName string,
) (*Objective, error)

GetObjective retreives the given objective from the filesystem.

func (*FileSystemStore) GetObjectiveByVersion

func (o *FileSystemStore) GetObjectiveByVersion(
	version Version,
) (*Objective, error)

func (*FileSystemStore) GetProject

func (o *FileSystemStore) GetProject(
	name string,
) (*Project, error)

GetProject retrieves the given project from the file system.

func (*FileSystemStore) ListProjects

func (o *FileSystemStore) ListProjects() ([]string, error)

ListProjects returns all projects in the filesystem.

func (*FileSystemStore) SaveObjective

func (o *FileSystemStore) SaveObjective(obj *Objective) error

SaveObjective sets default values and stores it in the given File Path in YAML format.

func (*FileSystemStore) SaveProject

func (o *FileSystemStore) SaveProject(
	project *Project,
) error

type FileSystemUserInterface

type FileSystemUserInterface struct {
	// contains filtered or unexported fields
}

FileSystemUserInterface provides access for Maintainers to manage a project's objectives via the filesystem.

Objectives copied to the CancelDir are cancelled. Objectives copied to the ClaimDir are claimed.

func NewFileSystemUserInterface

func NewFileSystemUserInterface(
	srv ObjectiveManager,
	rootDir string,
) (*FileSystemUserInterface, error)

func (*FileSystemUserInterface) SetLogger

func (o *FileSystemUserInterface) SetLogger(log Logger)

func (*FileSystemUserInterface) Start

func (o *FileSystemUserInterface) Start() error

Start begins monitoring the filesystem for events.

func (*FileSystemUserInterface) Stop

func (o *FileSystemUserInterface) Stop()

Stops the file system interface.

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
	Println(a ...interface{})
}

Logger outputs information for the operator of the service.

type LookupTable

type LookupTable map[string]map[Version]struct{}

type MarkdownString

type MarkdownString string

MarkdownString is markdown formatted text.

func (MarkdownString) String

func (s MarkdownString) String() string

type Money

type Money money.Money

func AddTransactions

func AddTransactions(account string, trs ...Transaction) (*Money, error)

func CalcMatchedContributionAmount

func CalcMatchedContributionAmount(amount, offered, limit *Money) (*Money, error)

func MaxAllowedContribution

func MaxAllowedContribution(
	cfg *Config,
	obj *Objective,
	cur string,
) (*Money, error)

MaxAllowedContribution gives the highest allowed contribution amount.

func MinAllowedContribution

func MinAllowedContribution(
	cfg *Config,
	cur string,
) (*Money, error)

MinAllowedContribution gives the lowest allowed contribution amount.

func MustMoney

func MustMoney(amount, unitOrCurCode string) *Money

func Negative

func Negative(arg *Money) *Money

func NewMoney

func NewMoney(arg int64, code string) *Money

func NewMoneyFromDecimal

func NewMoneyFromDecimal(
	amount decimal.Decimal,
	unitOrCurCode string,
) (*Money, error)

func NewMoneyFromString

func NewMoneyFromString(
	amount string,
	unitOrCurCode string,
) (*Money, error)

func (*Money) Absolute

func (m *Money) Absolute() (*Money, error)

func (*Money) Add

func (m *Money) Add(arg *Money) (*Money, error)

func (*Money) Amount

func (m *Money) Amount() int64

func (*Money) AmountString

func (m *Money) AmountString() string

func (*Money) Cmp

func (m *Money) Cmp(arg *Money) (int, error)

func (*Money) Currency

func (m *Money) Currency() *money.Currency

func (*Money) Display

func (m *Money) Display() string

func (*Money) DisplayAmount

func (m *Money) DisplayAmount() string

func (*Money) Equal

func (m *Money) Equal(arg *Money) (bool, error)

func (Money) GoString

func (m Money) GoString() string

func (*Money) IsNegative

func (m *Money) IsNegative() bool

func (*Money) IsZero

func (m *Money) IsZero() bool

func (*Money) LessThanOrEqual

func (m *Money) LessThanOrEqual(arg *Money) (bool, error)

func (*Money) MarshalJSON

func (m *Money) MarshalJSON() ([]byte, error)

func (*Money) MarshalYAML

func (m *Money) MarshalYAML() (interface{}, error)

func (*Money) String

func (m *Money) String() string

func (*Money) Subtract

func (m *Money) Subtract(arg *Money) (*Money, error)

func (*Money) UnmarshalJSON

func (m *Money) UnmarshalJSON(buf []byte) error

func (*Money) UnmarshalYAML

func (m *Money) UnmarshalYAML(fn func(interface{}) error) error

type Monies

type Monies []*Money

func (Monies) Sum

func (s Monies) Sum() (*Money, error)

Sum returns the total amount of money in the collection.

type MultiError

type MultiError []error

func (*MultiError) AppendIfErr

func (o *MultiError) AppendIfErr(err error)

func (*MultiError) Error

func (o *MultiError) Error() string

func (MultiError) ToError

func (o MultiError) ToError() error

ToError returns the type as an error value.

This method helps to avoid confusion in nil comparisons. A function could return a nil valued MultiError as an error which is a non-nil valued error interface value.

type Objective

type Objective struct {
	CreatedAt   time.Time
	Description MarkdownString
	ExpiresAt   time.Time
	// Funding is the total contributed amount.
	Funding *Money `yaml:",omitempty"`
	// FundingLimit is the maximum total contributed amount.
	FundingLimit     *Money `yaml:",omitempty"`
	MinimumLimit     *Money `yaml:",omitempty"`
	Name             string
	Projects         []string
	ShortDescription MarkdownString
	Updates          []Update `yaml:",omitempty"`
	Version          Version  `yaml:"-"`
}

TODO: Describe objective fields

func (*Objective) Cancel

func (o *Objective) Cancel()

Cancel removes the objective and returns all funds.

func (*Objective) Claim

func (o *Objective) Claim()

Claim closes the entity, and transfers funds to the maintainers account.

func (*Objective) Copy

func (o *Objective) Copy() *Objective

Copy returns a deep copy.

func (*Objective) Currency

func (o *Objective) Currency() *money.Currency

func (Objective) GetVersion

func (o Objective) GetVersion() Version

func (*Objective) HasProject

func (o *Objective) HasProject(project string) bool

func (*Objective) ImpactPerc

func (s *Objective) ImpactPerc(maxCtr *Money) (Percentage, error)

func (Objective) IsCrowdMatched

func (o Objective) IsCrowdMatched() bool

func (Objective) MinimumPercentMatched

func (o Objective) MinimumPercentMatched() (Percentage, error)

MinimumPercentMatched is the percentage of next contributions amount which will be matched by others, as a lower bound.

func (*Objective) SetVersion

func (o *Objective) SetVersion(version Version)

func (Objective) TotalMatched

func (o Objective) TotalMatched() (*Money, error)

func (Objective) TotalMatchedPerc

func (o Objective) TotalMatchedPerc() (Percentage, error)

func (Objective) TotalRefunded

func (o Objective) TotalRefunded() (*Money, error)

func (Objective) TotalRefundedPerc

func (o Objective) TotalRefundedPerc() (Percentage, error)

func (*Objective) UnmarshalYAML

func (o *Objective) UnmarshalYAML(value *yaml.Node) error

type ObjectiveManager

type ObjectiveManager interface {
	CancelObjective(projName, objName string) error
	ClaimObjective(projName, objName string) error
}

type Percentage

type Percentage float64

func (Percentage) String

func (p Percentage) String() string

type Project

type Project struct {
	ID          uuid.UUID
	Name        string
	Home        string                `yaml:",omitempty"`
	Description string                `yaml:",omitempty"`
	Objectives  map[string]*Objective `yaml:"-"`
	Updates     []Update              `yaml:",omitempty"`
}

func NewProject

func NewProject(
	name string,
) (*Project, error)

func (*Project) AddObjective

func (p *Project) AddObjective(arg *Objective) error

func (*Project) Copy

func (p *Project) Copy() *Project

func (*Project) GenerateID

func (p *Project) GenerateID()

type ServiceLogger

type ServiceLogger struct {
	// contains filtered or unexported fields
}

ServiceLogger logs each line with the current time and optional stack of namespaces associated with it.

func NewServiceLogger

func NewServiceLogger(
	w io.Writer,
) *ServiceLogger

NewServiceLogger creates a new ServiceLogger which writes to the given io.Writer.

func (*ServiceLogger) Printf

func (s *ServiceLogger) Printf(format string, v ...interface{})

Printf implements the Logger interface.

func (*ServiceLogger) Println

func (s *ServiceLogger) Println(a ...interface{})

Printf implements the Logger interface.

func (*ServiceLogger) With

func (s *ServiceLogger) With(namespace string) *ServiceLogger

With returns a new copy of the logger with the namespace attached to it.

type SetVersioner

type SetVersioner interface {
	SetVersion(version Version)
}

type StdLogger

type StdLogger struct{}

StdLogger logs to the programs standard output.

func (*StdLogger) Printf

func (s *StdLogger) Printf(format string, v ...interface{})

Printf implements the Logger interface.

func (*StdLogger) Println

func (s *StdLogger) Println(a ...interface{})

Println implements the Logger interface.

type Transaction

type Transaction struct {
	CreatedAt  time.Time     `json:"createdAt,omitempty"`
	ExternalID string        `json:"externalID,omitempty"`
	ID         TransactionID `json:"id,omitempty"`

	Amount *Money `json:"amount,omitempty"`
	From   string `json:"from,omitempty"`
	To     string `json:"to,omitempty"`
}

Transaction is an event for to value transfers.

TODO: Introduce Memo into transactions

It is necessary to describe what these transfers are about.

func (*Transaction) Add

func (o *Transaction) Add(txs ...Transaction) (*Transaction, error)

func (*Transaction) Empty

func (o *Transaction) Empty() bool

func (*Transaction) Reverse

func (o *Transaction) Reverse() *Transaction

func (*Transaction) Subtract

func (o *Transaction) Subtract(txs ...Transaction) (*Transaction, error)

type TransactionEvent

type TransactionEvent struct {
	Event     string    `json:"event,omitempty"`
	CreatedAt time.Time `json:"createdAt,omitempty"`

	ExternalID    string        `json:"externalId,omitempty"`
	TransactionID TransactionID `json:"transactionId,omitempty"`

	From string `json:"from,omitempty"`
	To   string `json:"to,omitempty"`

	Amount   string `json:"amount,omitempty"`
	Currency string `json:"currency,omitempty"`
}

func NewTransactionEvent

func NewTransactionEvent(tx Transaction) TransactionEvent

func (*TransactionEvent) Name

func (s *TransactionEvent) Name() string

func (*TransactionEvent) New

func (s *TransactionEvent) New() interface{}

func (*TransactionEvent) UpdateTransaction

func (e *TransactionEvent) UpdateTransaction(arg *Transaction) error

type TransactionID

type TransactionID string

func NewTransactionID

func NewTransactionID() TransactionID

func (*TransactionID) String

func (t *TransactionID) String() string

type TransactionPredicate

type TransactionPredicate func(Transaction) bool

type TransactionStorer

type TransactionStorer interface {
	FindTransactions(fn TransactionPredicate) ([]Transaction, error)
	GetTransaction(id TransactionID) (Transaction, error)
	SaveTransaction(tx Transaction) error
}

type Update

type Update struct {
	CreatedAt time.Time
	Author    string
	Title     string
	Body      string
}

type Version

type Version [sha256.Size]byte

Version is a cryptographic hash of its target.

func GetObjectiveAccountVersion

func GetObjectiveAccountVersion(objAccount string) (Version, error)

func ParseVersion

func ParseVersion(arg string) (Version, error)

func (*Version) MarshalJSON

func (s *Version) MarshalJSON() ([]byte, error)

func (Version) ShortString

func (v Version) ShortString() string

ShortString returns the uncommonly used Base64 encoding for a shorter result.

func (Version) String

func (v Version) String() string

String returns the commonly used hex encoding of version.

func (*Version) UnmarshalJSON

func (s *Version) UnmarshalJSON(arg []byte) error

type Versioner

type Versioner interface {
	GetVersion() Version
}

type YAMLVersionStore

type YAMLVersionStore string

func NewVersionStore

func NewVersionStore(path string) YAMLVersionStore

func (YAMLVersionStore) Each

func (o YAMLVersionStore) Each(
	fn func(*Objective) bool,
) error

Each applies the argument to all items, or until true is returned by the argument.

func (YAMLVersionStore) GetVersion

func (o YAMLVersionStore) GetVersion(
	version Version,
	obj SetVersioner,
) error

func (YAMLVersionStore) HasVersion

func (o YAMLVersionStore) HasVersion(version Version) (bool, error)

func (YAMLVersionStore) ListVersions

func (o YAMLVersionStore) ListVersions() ([]Version, error)

func (YAMLVersionStore) SaveVersion

func (o YAMLVersionStore) SaveVersion(obj Versioner) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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