Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Repository ¶
type Repository interface { Store(*Transaction) error Find(id string) (*Transaction, error) FindAll() []*Transaction Delete(string) error }
Repository provides access a transaction store.
type Service ¶
type Service interface { // CreateTransaction creates a raw transaction CreateTransaction(string, string, account.Currency, float64) (*Transaction, error) // CommitTransaction commits the transaction by ID CommitTransaction(string) (*Transaction, error) // Transactions lists all transactions Transactions() []*Transaction // GetTransaction returns transaction by IDD GetTransaction(string) (*Transaction, error) // Watch is a event for transaction update Watch() }
Service is the interface that provides transaction methods.
func NewService ¶
func NewService(transactions Repository, accounts account.Repository, log log.Logger) Service
NewService creates transaction service
type Transaction ¶
type Transaction struct { ID string `json:"id"` From string `json:"from"` To string `json:"to"` Status TransactionStatus `json:"status"` Amount float64 `json:"amount"` Currency account.Currency `json:"currency"` }
Transaction represents transaction between 2 accounts
func (Transaction) CalculateHash ¶
func (t Transaction) CalculateHash() ([]byte, error)
CalculateHash hashes the values of a transaction ID
func (*Transaction) Commit ¶
func (t *Transaction) Commit() error
Commit commits the transaction, ready to be processed
func (*Transaction) Create ¶
func (t *Transaction) Create()
Create creates new transaction with generated ID
func (Transaction) Equals ¶
func (t Transaction) Equals(other merkletree.Content) (bool, error)
Equals checks if the content of transaction is equal to another content transaction
func (*Transaction) Hash ¶
func (t *Transaction) Hash() (string, error)
Hash is string representation of calculated hash
type TransactionStatus ¶
type TransactionStatus string
TransactionStatus is our status handler
const ( // StatusOK if the transaction passes verifications StatusOK TransactionStatus = "ok" // StatusInsufficientFunds if the account owner does not have enough balance StatusInsufficientFunds TransactionStatus = "insufficient_funds" // StatusErr for unknown errors that can happen StatusErr TransactionStatus = "unknown_error" // StatusPending is when transaction is ready to be processed StatusPending TransactionStatus = "pending" // StatusCreated is when transaction is created and ready for commit StatusCreated TransactionStatus = "created" )
Click to show internal directories.
Click to hide internal directories.