transactions

package
v0.0.3-alpha1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrTransactionBootstrap error when bootstrap fails.
	ErrTransactionBootstrap = errors.Error("failed to bootstrap transactions")

	// BootstrappedRepo is the key mapped to transactions.Repository.
	BootstrappedRepo = "BootstrappedRepo"

	// BootstrappedService is the key to mapped transactions.Service
	BootstrappedService = "BootstrappedService"
)
View Source
const (
	// ErrTransactionMissing error when transaction doesn't exist in Repository.
	ErrTransactionMissing = errors.Error("transaction doesn't exist")

	// ErrKeyConstructionFailed error when the key construction failed.
	ErrKeyConstructionFailed = errors.Error("failed to construct transaction key")
)
View Source
const ErrInvalidAccountID = errors.Error("Invalid Tenant ID")

ErrInvalidAccountID error for Invalid account ID.

View Source
const ErrInvalidTransactionID = errors.Error("Invalid Transaction ID")

ErrInvalidTransactionID error for Invalid transaction ID.

View Source
const (
	// TxIDParam maps transaction ID in the kwargs.
	TxIDParam = "transactionID"
)

Variables

This section is empty.

Functions

func GRPCHandler

func GRPCHandler(srv Service, configService config.Service) transactionspb.TransactionServiceServer

GRPCHandler returns an implementation of the TransactionServiceServer

Types

type BaseTask

type BaseTask struct {
	TxID      uuid.UUID
	TxService Service
}

BaseTask holds the required details and helper functions for tasks to update transactions. should be embedded into the task

func (*BaseTask) ParseTransactionID

func (b *BaseTask) ParseTransactionID(kwargs map[string]interface{}) error

ParseTransactionID parses txID.

func (*BaseTask) UpdateTransaction

func (b *BaseTask) UpdateTransaction(accountID identity.CentID, name string, err error) error

UpdateTransaction add a new log and updates the status of the transaction based on the error.

type Bootstrapper

type Bootstrapper struct{}

Bootstrapper implements bootstrap.Bootstrapper.

func (Bootstrapper) Bootstrap

func (b Bootstrapper) Bootstrap(ctx map[string]interface{}) error

Bootstrap adds transaction.Repository into context.

type Log

type Log struct {
	Action    string
	Message   string
	CreatedAt time.Time
}

Log represents a single task in a transaction.

func NewLog

func NewLog(action, message string) Log

NewLog constructs a new log with action and message

type Repository

type Repository interface {
	Get(cid identity.CentID, id uuid.UUID) (*Transaction, error)
	Save(transaction *Transaction) error
}

Repository can be implemented by a type that handles storage for transactions.

func NewRepository

func NewRepository(repo storage.Repository) Repository

NewRepository registers the the transaction model and returns the an implementation of the Repository.

type Service

type Service interface {
	CreateTransaction(accountID identity.CentID, desc string) (*Transaction, error)
	GetTransaction(accountID identity.CentID, id uuid.UUID) (*Transaction, error)
	SaveTransaction(tx *Transaction) error
	GetTransactionStatus(identity identity.CentID, id uuid.UUID) (*transactionspb.TransactionStatusResponse, error)
	WaitForTransaction(accountID identity.CentID, txID uuid.UUID) error
}

Service wraps the repository and exposes specific functions.

func NewService

func NewService(repo Repository) Service

NewService returns a Service implementation.

type Status

type Status string

Status represents the status of the transaction

const (
	Success Status = "success"
	Failed  Status = "failed"
	Pending Status = "pending"
)

Status constants

type Transaction

type Transaction struct {
	ID          uuid.UUID
	CID         identity.CentID
	Description string
	Status      Status
	Logs        []Log
	Metadata    map[string]string
	CreatedAt   time.Time
}

Transaction contains details of transaction.

func NewTransaction

func NewTransaction(identity identity.CentID, description string) *Transaction

NewTransaction returns a new transaction with a pending state

func (*Transaction) FromJSON

func (t *Transaction) FromJSON(data []byte) error

FromJSON loads the data into transaction.

func (*Transaction) JSON

func (t *Transaction) JSON() ([]byte, error)

JSON returns json marshaled transaction.

func (*Transaction) Type

func (t *Transaction) Type() reflect.Type

Type returns the reflect.Type of the transaction.

Jump to

Keyboard shortcuts

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