Documentation
¶
Index ¶
- Constants
- Variables
- func AddCurrency(code string, grapheme string, template string, decimal string, thousand string, ...) *money.Currency
- func AddCurrencyUnit(curCode string, unit CurrencyUnit) error
- func ApplyFileConfig(cfg *Config, filePath string) error
- func BoolRef(arg bool) *bool
- func Decimal(arg *Money) decimal.Decimal
- func DisplayCurrencyInUnit(unitCode string) error
- func DurationRef(dur time.Duration) *time.Duration
- func GetDurationRef(arg *time.Duration, name string) (time.Duration, error)
- func GetStringRef(arg *string, name string) (string, error)
- func IntRef(arg int) *int
- func IsAnonymousAccount(account string) bool
- func IsMaintainerAccount(account string) bool
- func IsObjectiveAccount(account string) bool
- func MustDecimal(amount string) *decimal.Decimal
- func NewAnonymousAccount(paymentID string, curCode string) string
- func NewMaintainerAccount(curCode string) string
- func NewObjectiveAccount(obj *Objective) string
- func PanicOnErr(err error)
- func PaymentIDFromAccount(acc string) (string, error)
- func RequireStringRef(s *string, name string) error
- func SetBitcoinTestConfig(cfg *Config)
- func StringRef(arg string) *string
- func TimeRef(arg time.Time) *time.Time
- type AgreedToTermsEvent
- type AgreementStore
- type Callback
- type Config
- type Contribute
- type Contribution
- type ContributionDetails
- type CurrencyUnit
- type DiskTransactionStore
- func (d *DiskTransactionStore) FindTransactions(fn TransactionPredicate) ([]Transaction, error)
- func (d *DiskTransactionStore) GetAccountBalance(acc string) (*Money, error)
- func (d *DiskTransactionStore) GetTransaction(txID TransactionID) (Transaction, error)
- func (d *DiskTransactionStore) SaveTransaction(tx Transaction) error
- type Event
- type EventHeader
- type EventLog
- type FileSystemStore
- func (o *FileSystemStore) DeleteObjective(projName string, objName string) error
- func (o *FileSystemStore) FindObjectivesByProject(name string) ([]*Objective, error)
- func (o *FileSystemStore) GetInitializedObjective(projName string, objName string) (*Objective, error)
- func (o *FileSystemStore) GetInitializedProject(name string) (*Project, error)
- func (o *FileSystemStore) GetObjective(projName string, objName string) (*Objective, error)
- func (o *FileSystemStore) GetObjectiveByVersion(version Version) (*Objective, error)
- func (o *FileSystemStore) GetProject(name string) (*Project, error)
- func (o *FileSystemStore) ListProjects() ([]string, error)
- func (o *FileSystemStore) SaveObjective(obj *Objective) error
- func (o *FileSystemStore) SaveProject(project *Project) error
- type FileSystemUserInterface
- type Logger
- type LookupTable
- type MarkdownString
- type Money
- func AddTransactions(account string, trs ...Transaction) (*Money, error)
- func CalcMatchedContributionAmount(amount, offered, limit *Money) (*Money, error)
- func MaxAllowedContribution(cfg *Config, obj *Objective, cur string) (*Money, error)
- func MinAllowedContribution(cfg *Config, cur string) (*Money, error)
- func MustMoney(amount, unitOrCurCode string) *Money
- func Negative(arg *Money) *Money
- func NewMoney(arg int64, code string) *Money
- func NewMoneyFromDecimal(amount decimal.Decimal, unitOrCurCode string) (*Money, error)
- func NewMoneyFromString(amount string, unitOrCurCode string) (*Money, error)
- func (m *Money) Absolute() (*Money, error)
- func (m *Money) Add(arg *Money) (*Money, error)
- func (m *Money) Amount() int64
- func (m *Money) AmountString() string
- func (m *Money) Cmp(arg *Money) (int, error)
- func (m *Money) Currency() *money.Currency
- func (m *Money) Display() string
- func (m *Money) DisplayAmount() string
- func (m *Money) Equal(arg *Money) (bool, error)
- func (m Money) GoString() string
- func (m *Money) IsNegative() bool
- func (m *Money) IsZero() bool
- func (m *Money) LessThanOrEqual(arg *Money) (bool, error)
- func (m *Money) MarshalJSON() ([]byte, error)
- func (m *Money) MarshalYAML() (interface{}, error)
- func (m *Money) String() string
- func (m *Money) Subtract(arg *Money) (*Money, error)
- func (m *Money) UnmarshalJSON(buf []byte) error
- func (m *Money) UnmarshalYAML(fn func(interface{}) error) error
- type Monies
- type MultiError
- type Objective
- func (o *Objective) Cancel()
- func (o *Objective) Claim()
- func (o *Objective) Copy() *Objective
- func (o *Objective) Currency() *money.Currency
- func (o Objective) GetVersion() Version
- func (o *Objective) HasProject(project string) bool
- func (s *Objective) ImpactPerc(maxCtr *Money) (Percentage, error)
- func (o Objective) IsCrowdMatched() bool
- func (o Objective) MinimumPercentMatched() (Percentage, error)
- func (o *Objective) SetVersion(version Version)
- func (o Objective) TotalMatched() (*Money, error)
- func (o Objective) TotalMatchedPerc() (Percentage, error)
- func (o Objective) TotalRefunded() (*Money, error)
- func (o Objective) TotalRefundedPerc() (Percentage, error)
- func (o *Objective) UnmarshalYAML(value *yaml.Node) error
- type ObjectiveManager
- type Percentage
- type Project
- type ServiceLogger
- type SetVersioner
- type StdLogger
- type Transaction
- type TransactionEvent
- type TransactionID
- type TransactionPredicate
- type TransactionStorer
- type Update
- type Version
- type Versioner
- type YAMLVersionStore
- func (o YAMLVersionStore) Each(fn func(*Objective) bool) error
- func (o YAMLVersionStore) GetVersion(version Version, obj SetVersioner) error
- func (o YAMLVersionStore) HasVersion(version Version) (bool, error)
- func (o YAMLVersionStore) ListVersions() ([]Version, error)
- func (o YAMLVersionStore) SaveVersion(obj Versioner) error
Constants ¶
const AccountNameSeparator = "/"
const AgreedToTermsEventType = "terms agreed"
const AnonymousAccount = "anonymous"
const CancelDir = "cancel"
CancelDir is the path whose contents should be cancelled.
const ClaimDir = "claim"
ClaimDir is the path whose contents should be claimed.
const ListenCGI = "CGI"
const ListenFastCGI = "FastCGI"
const ListenHTTP = "HTTP"
const MaintainerAccount = "maintainer"
const ObjectiveAccount = "objective"
Variables ¶
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"), }
var HTMLServiceAgreement string
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 ¶
ApplyFileConfig loads the configuration described by the given yaml file.
func DisplayCurrencyInUnit ¶
DisplayCurrencyInUnit uses the given currency unit when shown to the user.
Using an empty unitCode resets the default unit.
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 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.
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 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 ¶
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 EventLog ¶
type EventLog struct {
// contains filtered or unexported fields
}
func (*EventLog) RegisterCallback ¶
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 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 MaxAllowedContribution ¶
MaxAllowedContribution gives the highest allowed contribution amount.
func MinAllowedContribution ¶
MinAllowedContribution gives the lowest allowed contribution amount.
func NewMoneyFromDecimal ¶
func NewMoneyFromString ¶
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) ImpactPerc ¶
func (s *Objective) ImpactPerc(maxCtr *Money) (Percentage, error)
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) TotalMatchedPerc ¶
func (o Objective) TotalMatchedPerc() (Percentage, error)
func (Objective) TotalRefundedPerc ¶
func (o Objective) TotalRefundedPerc() (Percentage, error)
type ObjectiveManager ¶
type Percentage ¶
type Percentage float64
func (Percentage) String ¶
func (p Percentage) String() string
type Project ¶
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 StdLogger ¶
type StdLogger struct{}
StdLogger logs to the programs standard output.
func (*StdLogger) Printf ¶
Printf 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 Version ¶
Version is a cryptographic hash of its target.
func GetObjectiveAccountVersion ¶
func (Version) ShortString ¶
ShortString returns the uncommonly used Base64 encoding for a shorter result.
func (Version) String ¶
String returns the commonly used hex encoding of 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
Source Files
¶
- agreements.go
- config.go
- debug.go
- error.go
- event_log.go
- file_system.go
- funding.go
- logging.go
- money.go
- project.go
- project_transactions.go
- transaction.go
- transaction_store.go