Documentation ¶
Index ¶
- Variables
- func GetAccounts(tx *sql.Tx) (accounts []string, err error)
- func GetConfig(tx *sql.Tx, key string) (value string, err error)
- func GetConfigs(tx *sql.Tx) (config map[string]string, err error)
- func GetUsers(tx *sql.Tx) (users []string, err error)
- func OpenDatabase(driver, source string) (db *sql.DB, err error)
- func PutConfig(tx *sql.Tx, key, value string) (err error)
- func SetPassword(password string) (stored string, err error)
- func Transact(database *sql.DB, body func(tx *sql.Tx) (err error)) (err error)
- func VerifyPassword(stored, password string) (err error)
- type Account
- type Bank
- func (b *Bank) CheckPassword(user, password string) (err error)
- func (b *Bank) Close() (err error)
- func (b *Bank) DeleteAccount(account string) (err error)
- func (b *Bank) DeleteUser(user string) (err error)
- func (b *Bank) Distribute(user string, origin string, destinations []string, description string) (err error)
- func (b *Bank) GetAccounts() (accounts []string, err error)
- func (b *Bank) GetConfig(key string) (value string, err error)
- func (b *Bank) GetConfigs() (configs map[string]string, err error)
- func (b *Bank) GetTransactions(limit, offset int, after int) (transactions []Transaction, err error)
- func (b *Bank) GetUsers() (users []string, err error)
- func (b *Bank) NewAccount(account string) (err error)
- func (b *Bank) NewBank() (err error)
- func (b *Bank) NewTransaction(user, origin, destination, description string, amount int) (err error)
- func (b *Bank) NewUser(user, password string) (err error)
- func (b *Bank) PutConfig(key, value string) (err error)
- func (b *Bank) SetPassword(user, password string) (err error)
- type Transaction
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrAccountExists = bcommon.HTTPError{"account exists", http.StatusBadRequest}
ErrAccountExists is returned when creating an account that already exists.
var ErrAccountHasBalance = bcommon.HTTPError{"account has a nonzero balance", http.StatusBadRequest}
ErrAccountHasBalance is returned when deleting a nonempty account.
var ErrInsufficientFunds = bcommon.HTTPError{"insufficient funds", http.StatusBadRequest}
ErrInsufficientFunds is returned when there are insufficient funds for some action.
var ErrNoSuchAccount = bcommon.HTTPError{"account does not exist", http.StatusNotFound}
ErrNoSuchAccount is returned when accessing an account which does not exist.
var ErrNoSuchConfig = bcommon.HTTPError{"no such configuration item", http.StatusNotFound}
ErrNoSuchConfig is return when a nonexistent configuration item is accessed.
var ErrNoSuchUser = bcommon.HTTPError{"user does not exist", http.StatusNotFound}
ErrNoSuchUser is returned when accessing a user who does not exist.
var ErrPasswordMismatch = errors.New("password mismatch")
ErrPasswordMismatch is returned by VerifyPassword for incorrect passwords.
var ErrUnsuitableParties = bcommon.HTTPError{"invalid or inconsistent parties to transaction", http.StatusBadRequest}
ErrUnsuitableParties is returned when there is something wrong with the proposed parties to a transaction.
var ErrUserExists = bcommon.HTTPError{"user exists", http.StatusBadRequest}
ErrUserExists is returned when creating a user that already exists.
var Version = "0.6.0-dirty"
Version is the version string of the program
Functions ¶
func GetAccounts ¶
GetAccounts returns the list of account names.
func GetConfigs ¶
GetConfigs returns the full configuration table.
func OpenDatabase ¶
OpenDatabase opens a database handle.
func SetPassword ¶
SetPassword computes a new stored string for a password.
func Transact ¶
Transact runs a function inside a database transaction. On success the transaction is committed. On error the transaction is rolled back.
func VerifyPassword ¶
VerifyPassword verifies a password against a stored version.
Types ¶
type Account ¶
Account defines a single account.
func (*Account) Delete ¶
Delete deletes an account.
Accounts with nonzero balances cannot be deleted.
type Bank ¶
Bank wraps access to a bank database.
func (*Bank) CheckPassword ¶
CheckPassword checks a user password.
func (*Bank) DeleteAccount ¶
DeleteAccount deletes a user
func (*Bank) DeleteUser ¶
DeleteUser deletes a user
func (*Bank) Distribute ¶
func (b *Bank) Distribute(user string, origin string, destinations []string, description string) (err error)
Distribute makes a distribution transaction.
func (*Bank) GetAccounts ¶
GetAccounts list accounts.
func (*Bank) GetConfigs ¶
GetConfigs retrieves all configuration items.
func (*Bank) GetTransactions ¶
func (b *Bank) GetTransactions(limit, offset int, after int) (transactions []Transaction, err error)
GetTransactions gets some transactions.
Starting with the most recent transaction, it skips `offset` transactions and then gets the next `limit` transactions.
func (*Bank) NewAccount ¶
NewAccount creates a new account.
func (*Bank) NewTransaction ¶
func (b *Bank) NewTransaction(user, origin, destination, description string, amount int) (err error)
NewTransaction makes a transaction.
func (*Bank) SetPassword ¶
SetPassword changes a user password.
type Transaction ¶
type Transaction struct { // Transaction ID ID int // Unix time of the transaction Time int64 // User who make the transaction User string // Description of the transaction Description string // Origin account Origin string // Destination account Destination string // Amount in pence Amount int OriginBalanceAfter int DestinationBalanceAfter int }
Transaction defines a single transaction.
func GetTransactions ¶
func GetTransactions(tx *sql.Tx, limit, offset int, after int) (transactions []Transaction, err error)
GetTransactions returns all transactions in a range.