transaction

package
v0.0.0-...-877dc42 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeHandler

func MakeHandler(ts Service, logger kitlog.Logger) http.Handler

MakeHandler returns a handler for the transaction service.

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 New

func New(from string, to string, currency account.Currency, amount float64) *Transaction

New creates 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"
)

Jump to

Keyboard shortcuts

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