ledger

package module
v0.0.0-...-5ed654f Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2019 License: MIT Imports: 9 Imported by: 0

README

qledger-sdk-go

Note: This is a fork of the QLedger Go SDK for moov.io. There are no guarentees of API compatibility as we intend this for our internal use. We do intend to push useful changes upstream for the larger ecosystem around QLedger.

Configuration

The following environmental variables can be set to configure a Ledger instance:

  • LEDGER_AUTH_TOKEN: Token used to authenticate with a QLedger instance. (Example: long-complex-secret-token)
  • LEDGER_ENDPOINT: HTTP address for QLedger instance (Example: http://127.0.0.1:7000/qledger/)

Getting Help

Below is a table of ways to contact the moov.io team and community.

channel info
Project Documentation Our project documentation available online.
Google Group moov-users The Moov users Google group is for contributors other people contributing to the Moov project. You can join them without a google account by sending an email to moov-users+subscribe@googlegroups.com. After receiving the join-request message, you can simply reply to that to confirm the subscription.
Twitter @moov_io You can follow Moov.IO's Twitter feed to get updates on our project(s). You can also tweet us questions or just share blogs or stories.
GitHub Issue If you are able to reproduce an problem please open a GitHub Issue under the specific project that caused the error.
moov-io slack Join our slack channel to have an interactive discussion about the development of the project. Request an invite to the slack channel

Contributing

Yes please! Please review our Code of Conduct to get started!

License

MIT License See LICENSE for details.

Documentation

Index

Constants

View Source
const (
	// AccountsAPI is the endpoint for creating and updating accounts
	AccountsAPI = "/v1/accounts"
	// AccountsSearchAPI is the endpoint for searching accounts
	AccountsSearchAPI = "/v1/accounts/_search"
)
View Source
const (
	// TransactionsAPI is the endpoint for creating and updating transactions
	TransactionsAPI = "/v1/transactions"
	// TransactionsSearchAPI is the endpoint for searching transactions
	TransactionsSearchAPI = "/v1/transactions/_search"
)

Variables

View Source
var (
	ErrTransactionDuplicate = errors.New("Transaction is duplicate")
	ErrTransactionConflict  = errors.New("Transaction ID conflict")
	ErrTransactionInvalid   = errors.New("Transaction invalid")
	ErrTransactionNotfound  = errors.New("Transaction not found")

	ErrAccountConflict = errors.New("Account ID conflict")
	ErrAccountInvalid  = errors.New("Account invalid")
	ErrAccountNotfound = errors.New("Account not found")

	ErrInternalServer = errors.New("Ledger internal server error")
)

Functions

func NewUUID

func NewUUID() string

Types

type Account

type Account struct {
	ID      string                 `json:"id"`
	Balance int                    `json:"balance"`
	Data    map[string]interface{} `json:"data"`
}

Account holds information such as account ID, balance and search data

type Ledger

type Ledger struct {
	HTTP *http.Client
	// contains filtered or unexported fields
}

Ledger is the interface to all ledger API calls

func NewLedger

func NewLedger(endpoint string, authToken string) *Ledger

NewLedger returns instance of a Ledger

api := ledger.NewLedger("https://example.com/qledger", "secret-auth-token")

func (*Ledger) CreateAccount

func (ledger *Ledger) CreateAccount(account *Account) error

CreateAccount creates a new account to QLedger

func (*Ledger) CreateTransaction

func (ledger *Ledger) CreateTransaction(transaction *Transaction) error

CreateTransaction makes a new transaction to QLedger

func (*Ledger) DoRequest

func (l *Ledger) DoRequest(method, url string, body io.Reader) (*http.Response, error)

DoRequest creates a new request to Ledger with necessary headers set

func (*Ledger) GetAccount

func (ledger *Ledger) GetAccount(accountID string) (*Account, error)

GetAccount returns an account in the Ledger which matches the given ID

func (*Ledger) GetEndpoint

func (l *Ledger) GetEndpoint() string

GetEndpoint returns the enpoint of the ledger

func (*Ledger) GetTransaction

func (ledger *Ledger) GetTransaction(txnID string) (*Transaction, error)

GetTransaction returns a transaction in the Ledger which matches the given ID

func (*Ledger) Ping

func (l *Ledger) Ping() error

func (*Ledger) SearchAccounts

func (ledger *Ledger) SearchAccounts(searchQuery map[string]interface{}) ([]*Account, error)

SearchAccounts returns all account in the Ledger which satisfies the given search query

func (*Ledger) SearchTransactions

func (ledger *Ledger) SearchTransactions(searchQuery map[string]interface{}) ([]*Transaction, error)

SearchTransactions returns all transactions in the Ledger which satisfies the given search query

func (*Ledger) UpdateAccount

func (ledger *Ledger) UpdateAccount(account *Account) error

UpdateAccount creates a new account to QLedger

func (*Ledger) UpdateTransaction

func (ledger *Ledger) UpdateTransaction(txn *Transaction) error

UpdateTransaction updates `data` of existing transaction in QLedger

type Transaction

type Transaction struct {
	ID        string                 `json:"id"`
	Data      map[string]interface{} `json:"data"`
	Timestamp string                 `json:"timestamp"`
	Lines     []*TransactionLine     `json:"lines"`
}

Transaction holds information such as transaction ID, timestamp, movement of money between accounts and search data

type TransactionLine

type TransactionLine struct {
	AccountID string `json:"account"`
	Delta     int    `json:"delta"`
}

TransactionLine holds information about the account and amount transferred

Jump to

Keyboard shortcuts

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