services

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: MIT Imports: 36 Imported by: 0

Documentation

Overview

services package is au json-rpc service for session management. client can perform three operations on session: - Open to initiate a session with valid credentials - Renew to extends the validty period from a valid session - Close to invalidate a session

Index

Constants

View Source
const (
	IconSize = uint(128)
)
View Source
const (
	SessionDuration = 3 * time.Minute
)
View Source
const (
	VerifySessionSubject = subjectPrefix + "VerifySession"
)
View Source
const Version string = "0.1"

Version

Variables

View Source
var (
	ErrInvalidCrendential    = errors.New("InvalidCredentials")
	ErrMissingCookie         = errors.New("MissingCookie")
	ErrInvalidCookie         = errors.New("ErrInvalidCookie")
	ErrSessionCreationFailed = errors.New("SessionCreationFailed")
	ErrTooManyOpenSession    = errors.New("TooManyOpenSession")
	ErrSessionExpired        = sessions.ErrSessionExpired
	ErrSessionClose          = errors.New("SessionCloseFailed")
)
View Source
var (
	ErrInvalidAccountID = errors.New("Invalid AccountID")
	ErrInvalidSwapID    = errors.New("Invalid SwapID")
	ErrInvalidPayload   = errors.New("Invalid Payload")

	ErrInvalidProposal       = errors.New("Invalid Proposal")
	ErrInsufficientFunds     = errors.New("Insufficient funds")
	ErrInvalidProposerAsset  = errors.New("Invalid Proposer Asset")
	ErrInvalidProposerAmount = errors.New("Invalid Proposer Amount")
	ErrInvalidReceiverAsset  = errors.New("Invalid Receiver Asset")
	ErrInvalidReceiverAmount = errors.New("Invalid Receiver Amount")
)
View Source
var (
	ErrWalletChainNotFoundError = errors.New("Chain Not Found")
	ErrInvalidPublicAddress     = errors.New("Invalid Public Address")
	ErrInvalidWithdraw          = errors.New("Invalid Withdraw")
)
View Source
var (
	ErrServiceInternalError = errors.New("Service Internal Error")
)
View Source
var (
	StatsMiddleware = stats.New()
)

Functions

func AppendRequestLog

func AppendRequestLog(log *logrus.Entry, r *http.Request) *logrus.Entry

func ContextValues

func ContextValues(ctx context.Context) (bank.Database, *sessions.Session, error)

func CreateCorsOptions

func CreateCorsOptions(corsAllowedOrigins []string) *cors.Cors

func CreateSessionWithCookie added in v0.0.2

func CreateSessionWithCookie(ctx context.Context, r *http.Request, w http.ResponseWriter, userID uint64) error

func GetRequestLog

func GetRequestLog(ctx context.Context, r *http.Request) *logrus.Entry

func GetServiceRequestLog

func GetServiceRequestLog(log *logrus.Entry, r *http.Request, service, operation string) *logrus.Entry

func NewAccountingHandler added in v0.0.2

func NewAccountingHandler(ctx context.Context) http.Handler

func NewSessionHandler

func NewSessionHandler(ctx context.Context) http.Handler

func NewSwapHandler added in v0.0.4

func NewSwapHandler(ctx context.Context) http.Handler

func NewUserHandler

func NewUserHandler(ctx context.Context) http.Handler

func NewWalletHandler added in v0.0.3

func NewWalletHandler(ctx context.Context) http.Handler

func OpenSessionAllowed

func OpenSessionAllowed(ctx context.Context, userID uint64) bool

func RegisterMessageHandlers added in v0.0.2

func RegisterMessageHandlers(ctx context.Context)

func RegisterServices

func RegisterServices(ctx context.Context, mux *mux.Router, corsAllowedOrigins []string)

func RequesterIP

func RequesterIP(r *http.Request) string

Types

type AccountHistoryRequest added in v0.0.2

type AccountHistoryRequest struct {
	SessionArgs
	AccountID string `json:"accountId"`
	WithEmpty bool   `json:"withEmpty"`
	From      int64  `json:"from"`
	To        int64  `json:"to"`
}

AccountHistoryRequest holds args for accounting history requests

type AccountHistoryResponse added in v0.0.2

type AccountHistoryResponse struct {
	AccountID   string             `json:"accountId"`
	DisplayName string             `json:"displayName"`
	Ticker      string             `json:"ticker"`
	From        int64              `json:"from"`
	To          int64              `json:"to"`
	Operations  []AccountOperation `json:"operations"`
}

AccountHistoryResponse holds args for accounting requests

type AccountInfo added in v0.0.2

type AccountInfo struct {
	Timestamp   int64        `json:"timestamp"`
	AccountID   string       `json:"accountId"`
	Currency    CurrencyInfo `json:"curency"`
	Name        string       `json:"name"`
	Status      string       `json:"status"`
	Balance     float64      `json:"balance"`
	TotalLocked float64      `json:"totalLocked"`
	Notional    Notional     `json:"notional"`
}

AccountInfo holds account information

type AccountOperation added in v0.0.2

type AccountOperation struct {
	Timestamp   int64   `json:"timestamp"`
	OperationID string  `json:"operationId"`
	Amount      float64 `json:"amount"`
	Balance     float64 `json:"balance"`
	LockAmount  float64 `json:"lockAmount"`
	TotalLocked float64 `json:"totalLocked"`
}

AccountOperation holds account operation

type AccountRequest added in v0.0.2

type AccountRequest struct {
	SessionArgs
	RateBase        string `json:"rateBase"`
	WithEmptyCrypto bool   `json:"withEmptyCrypto"`
}

AccountRequest holds args for accounting requests

type AccountResponse added in v0.0.2

type AccountResponse struct {
	Accounts []AccountInfo `json:"accounts"`
}

AccountResponse holds args for accounting requests

type AccountingService added in v0.0.2

type AccountingService int

func (*AccountingService) History added in v0.0.2

AccountingService operation return user's accounts

func (*AccountingService) List added in v0.0.2

func (p *AccountingService) List(r *http.Request, request *AccountRequest, reply *AccountResponse) error

AccountingService operation return user's accounts

type CookieCodec

type CookieCodec struct {
	// contains filtered or unexported fields
}

func NewCookieCodec

func NewCookieCodec(ctx context.Context) *CookieCodec

func (*CookieCodec) NewRequest

func (p *CookieCodec) NewRequest(r *http.Request) rpc.CodecRequest

type CookieCodecRequest

type CookieCodecRequest struct {
	// contains filtered or unexported fields
}

func (*CookieCodecRequest) Method

func (p *CookieCodecRequest) Method() (string, error)

func (*CookieCodecRequest) ReadRequest

func (p *CookieCodecRequest) ReadRequest(args interface{}) error

func (*CookieCodecRequest) WriteError

func (p *CookieCodecRequest) WriteError(w http.ResponseWriter, status int, err error)

func (*CookieCodecRequest) WriteResponse

func (p *CookieCodecRequest) WriteResponse(w http.ResponseWriter, args interface{})

type CurrencyInfo added in v0.0.2

type CurrencyInfo struct {
	DisplayName      string `json:"displayName"`
	Ticker           string `json:"ticker"`
	IsCrypto         bool   `json:"isCrypto"`
	IsAsset          bool   `json:"isAsset"`
	AssetHash        string `json:"assetHash"`
	DisplayPrecision uint   `json:"displayPrecision"`
	Icon             []byte `json:"icon,omitempty"`
}

type Notional added in v0.0.2

type Notional struct {
	RateBase         string  `json:"rateBase"`
	DisplayPrecision uint    `json:"displayPrecision"`
	Rate             float64 `json:"rate"`
	Balance          float64 `json:"balance"`
	TotalLocked      float64 `json:"totalLocked"`
}

type ProposalInfo added in v0.0.4

type ProposalInfo struct {
	ProposerAssetID string  `json:"proposerAssetId,omitempty"`
	ProposerAmount  float64 `json:"proposerAmount,omitempty"`
	ReceiverAssetID string  `json:"receiverAssetId,omitempty"`
	ReceiverAmount  float64 `json:"receiverAmount,omitempty"`
}

type SessionArgs

type SessionArgs struct {
	SessionID string `json:"-"` // SessionID is transmit to client via cookie
}

SessionArgs holds SessionID for operation requests and repls

type SessionOpenRequest

type SessionOpenRequest struct {
	Login    string `json:"login"`
	Password string `json:"password"`
	OTP      string `json:"otp,omitempty"`
}

SessionOpenRequest holds args for open requests

type SessionReply

type SessionReply struct {
	SessionArgs
	Status     string `json:"status"`
	ValidUntil int64  `json:"valid_until"`
}

SessionReply holds session informations for operation replies

type SessionService

type SessionService int

SessionService receiver

func (*SessionService) Close

func (p *SessionService) Close(r *http.Request, request *SessionArgs, reply *SessionReply) error

Close operation close the session and set status to closed

func (*SessionService) Open

func (p *SessionService) Open(r *http.Request, request *SessionOpenRequest, reply *SessionReply) error

Open operation perform check regarding credentials and return a sessionID session has a status [open, close] and a validation period

func (*SessionService) Renew

func (p *SessionService) Renew(r *http.Request, request *SessionArgs, reply *SessionReply) error

Open operation perform check the session validity and extends the validation period

type StatsArgs

type StatsArgs struct {
}

type StatsReply

type StatsReply struct {
	Application string      `json:"application"`
	Version     string      `json:"version"`
	Host        string      `json:"host"`
	Statistics  *stats.Data `json:"statistics"`
}

type StatsService

type StatsService int

func (*StatsService) Status

func (t *StatsService) Status(r *http.Request, args *StatsArgs, result *StatsReply) error

type SwapData added in v0.0.4

type SwapData struct {
	ProposerUnconfidentialAddress string `json:"u_address_p"`
}

type SwapInfo added in v0.0.4

type SwapInfo struct {
	Status string    `json:"status"`
	Legs   []SwapLeg `json:"legs"`
}

func (*SwapInfo) CreditLeg added in v0.0.4

func (p *SwapInfo) CreditLeg() SwapLeg

func (*SwapInfo) DebitLeg added in v0.0.4

func (p *SwapInfo) DebitLeg() SwapLeg

type SwapLeg added in v0.0.4

type SwapLeg struct {
	Incoming bool    `json:"incoming"`
	Funded   bool    `json:"funded"`
	Asset    string  `json:"asset"`
	Amount   float64 `json:"amount"`
	Fee      float64 `json:"fee"`
}

type SwapProposeRequest added in v0.0.4

type SwapProposeRequest struct {
	SwapRequest
	Proposal ProposalInfo `json:"proposal,omitempty"`
}

SwapProposeRequest holds args for swap requests

type SwapRequest added in v0.0.4

type SwapRequest struct {
	SessionArgs
	AccountID string `json:"accountId"`
	SwapID    string `json:"swapId"`
	Payload   string `json:"payload,omitempty"`
}

SwapProposeRequest holds args for swap requests

type SwapResponse added in v0.0.4

type SwapResponse struct {
	SwapID  string `json:"swapId"`
	Payload string `json:"payload,omitempty"`
}

SwapProposeResponse holds args for swap reqponses

type SwapService added in v0.0.4

type SwapService int

func (*SwapService) Accept added in v0.0.4

func (p *SwapService) Accept(r *http.Request, request *SwapRequest, reply *SwapResponse) error

Accept operation return proposal payload for swap

func (*SwapService) Finalize added in v0.0.4

func (p *SwapService) Finalize(r *http.Request, request *SwapRequest, reply *SwapResponse) error

Finalize operation return proposal payload for swap

func (*SwapService) Info added in v0.0.4

func (p *SwapService) Info(r *http.Request, request *SwapRequest, reply *SwapResponse) error

Info operation return proposal payload for swap

func (*SwapService) Propose added in v0.0.4

func (p *SwapService) Propose(r *http.Request, request *SwapProposeRequest, reply *SwapResponse) error

Propose operation return proposal payload for swap

type UserInfoRequest

type UserInfoRequest struct {
	SessionArgs
}

UserInfoRequest holds args for start requests

type UserInfoResponse

type UserInfoResponse struct {
	Email string `json:"email"`
}

UserInfoResponse holds args for start requests

type UserService

type UserService int

KYCService receiver

func (*UserService) Info

func (p *UserService) Info(r *http.Request, request *UserInfoRequest, reply *UserInfoResponse) error

Info operation return user's email

type WalletCancelWithdrawRequest added in v0.0.5

type WalletCancelWithdrawRequest struct {
	SessionArgs
	WithdrawID string `json:"withdrawId"`
}

WalletCancelWithdrawRequest holds args for wallet requests

type WalletCancelWithdrawResponse added in v0.0.5

type WalletCancelWithdrawResponse struct {
	WithdrawID string `json:"withdrawId"`
	Status     string `json:"status"`
}

WalletCancelWithdrawResponse holds args for wallet requests

type WalletNextDepositRequest added in v0.0.3

type WalletNextDepositRequest struct {
	SessionArgs
	AccountID string `json:"accountId"`
}

WalletNextDepositRequest holds args for accounting requests

type WalletNextDepositResponse added in v0.0.3

type WalletNextDepositResponse struct {
	Currency        string `json:"currency"`
	DisplayCurrency string `json:"displayCurrency"`
	PublicAddress   string `json:"publicAddress"`
	URL             string `json:"url"`
}

WalletNextDepositResponse holds args for accounting requests

type WalletSendFundsRequest added in v0.0.5

type WalletSendFundsRequest struct {
	SessionArgs
	AccountID     string  `json:"accountId"`
	PublicAddress string  `json:"publicAddress"`
	Amount        float64 `json:"amount"`
}

WalletSendFundsRequest holds args for wallet requests

type WalletSendFundsResponse added in v0.0.5

type WalletSendFundsResponse struct {
	WithdrawID string `json:"withdrawId"`
}

WalletSendFundsResponse holds args for wallet requests

type WalletSendHistoryRequest added in v0.0.5

type WalletSendHistoryRequest struct {
	SessionArgs
}

WalletSendHistoryRequest holds args for wallet requests

type WalletSendHistoryResponse added in v0.0.5

type WalletSendHistoryResponse struct {
	Withdraws []WithdrawInfo `json:"withdraws"`
}

WalletSendFundsResponse holds args for wallet requests

type WalletService added in v0.0.3

type WalletService int

func (*WalletService) CancelWithdraw added in v0.0.5

func (*WalletService) NextDeposit added in v0.0.3

WalletService operation return deposit address for account

func (*WalletService) SendFunds added in v0.0.5

func (*WalletService) SendHistory added in v0.0.5

type WithdrawInfo added in v0.0.5

type WithdrawInfo struct {
	WithdrawID string  `json:"withdrawId"`
	Timestamp  int64   `json:"timestamp"`
	AccountID  string  `json:"accountId"`
	Amount     float64 `json:"amount"`
	Chain      string  `json:"chain"`
	PublicKey  string  `json:"publicKey"`
	Status     string  `json:"status"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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