endpoint

package
v0.0.0-...-08046e1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PriceRegexp = regexp.MustCompile(
	"^([0-9]+)\\/([0-9]+)$")

PriceRegexp is used to validate and parse a transaction price.

Functions

func HandlerFor

func HandlerFor(
	name EndPtName,
) func(
	http.ResponseWriter,
	*http.Request,
)

HandlerFor returns an handler for the given endpoint name.

func ValidateAmount

func ValidateAmount(
	ctx context.Context,
	amount string,
) (*big.Int, error)

ValidateAmount validates the amount of an asset.

func ValidateAsset

func ValidateAsset(
	ctx context.Context,
	asset string,
) (*mint.AssetResource, error)

ValidateAsset vlaidates an asset name.

func ValidateAssetPair

func ValidateAssetPair(
	ctx context.Context,
	pair string,
) ([]mint.AssetResource, error)

ValidateAssetPair validates an asset pair.

func ValidateCreatedBefore

func ValidateCreatedBefore(
	ctx context.Context,
	createdBefore string,
) (*time.Time, error)

ValidateCreatedBefore validates a paging created_before.

func ValidateHop

func ValidateHop(
	ctx context.Context,
	hop string,
) (*int8, error)

ValidateHop validates a hop.

func ValidateID

func ValidateID(
	ctx context.Context,
	id string,
) (*string, *string, *string, error)

ValidateID validates the ID of an object

func ValidateLimit

func ValidateLimit(
	ctx context.Context,
	limit string,
) (*uint, error)

ValidateLimit validates a paging limit.

func ValidatePath

func ValidatePath(
	ctx context.Context,
	path []string,
) ([]string, error)

ValidatePath validates a path of offers.

func ValidatePrice

func ValidatePrice(
	ctx context.Context,
	price string,
) (*big.Int, *big.Int, error)

ValidatePrice validates a price (pB/pQ).

func ValidatePropagation

func ValidatePropagation(
	ctx context.Context,
	propagation string,
) (*mint.PgType, error)

ValidatePropagation validates a propagation type.

func ValidateSecret

func ValidateSecret(
	ctx context.Context,
	secret string,
) (*string, error)

ValidateSecret validates a secret.

Types

type CancelTransaction

type CancelTransaction struct {
	Client *mint.Client

	// Parameters
	Hop   int8
	ID    string
	Token string
	Owner string

	// State
	Tx   *model.Transaction
	Plan *plan.TxPlan
}

CancelTransaction creates a new transaction.

func (*CancelTransaction) Cancel

func (e *CancelTransaction) Cancel(
	ctx context.Context,
) error

Cancel cancels idempotently the underlying operations and crossings at the current hop.

func (*CancelTransaction) Execute

func (e *CancelTransaction) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*CancelTransaction) ExecuteAuthenticated

func (e *CancelTransaction) ExecuteAuthenticated(
	ctx context.Context,
) (*int, *svc.Resp, error)

ExecuteAuthenticated executes the authenticated cancellation of a transaction.

func (*CancelTransaction) ExecutePropagated

func (e *CancelTransaction) ExecutePropagated(
	ctx context.Context,
) (*int, *svc.Resp, error)

ExecutePropagated executes the settlement of a propagated transaction (involved mint).

func (*CancelTransaction) Propagate

func (e *CancelTransaction) Propagate(
	ctx context.Context,
) error

Propagate the transaction cancellation. Current hop cancellation is already performed.

func (*CancelTransaction) Validate

func (e *CancelTransaction) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type CloseOffer

type CloseOffer struct {
	ID    string
	Owner string
	Token string
}

CloseOffer closes an offer, making it unusable by transactions

func (*CloseOffer) Execute

func (e *CloseOffer) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*CloseOffer) Validate

func (e *CloseOffer) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type CreateAsset

type CreateAsset struct {
	Owner string
	Code  string
	Scale int8
}

CreateAsset controls the creation of new assets.

func (*CreateAsset) Execute

func (e *CreateAsset) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*CreateAsset) Validate

func (e *CreateAsset) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type CreateOffer

type CreateOffer struct {
	Client *mint.Client

	ID         string // propagation
	Token      string // propagation
	Owner      string
	Pair       []mint.AssetResource
	BasePrice  big.Int
	QuotePrice big.Int
	Amount     big.Int
}

CreateOffer creates a new canonical offer and triggers its propagation to all the mints involved. Offer are represented as asks: base asset (left) is offered in exchange for quote asset (right) for specified amount (of quote asset) at specified price.

func (*CreateOffer) Execute

func (e *CreateOffer) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*CreateOffer) Validate

func (e *CreateOffer) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type CreateTransaction

type CreateTransaction struct {
	Client *mint.Client

	// Parameters
	Hop         int8
	ID          string
	Owner       string
	BaseAsset   string
	QuoteAsset  string
	Amount      big.Int
	Destination string
	Path        []string

	// State
	Tx   *model.Transaction
	Plan *plan.TxPlan
}

CreateTransaction creates a new transaction.

func (*CreateTransaction) Execute

func (e *CreateTransaction) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*CreateTransaction) ExecuteCanonical

func (e *CreateTransaction) ExecuteCanonical(
	ctx context.Context,
) (*int, *svc.Resp, error)

ExecuteCanonical executes the creation of a canonical transaction (owner mint).

func (*CreateTransaction) ExecutePlan

func (e *CreateTransaction) ExecutePlan(
	ctx context.Context,
) error

ExecutePlan executes the Hop locally, performing the operation and the crossing action if applicable. ExecutePlan is executed in the context of a DB transaction and is idempotent (attempts to retrieve operations for that hop and transaction before executing them).

func (*CreateTransaction) ExecutePropagated

func (e *CreateTransaction) ExecutePropagated(
	ctx context.Context,
) (*int, *svc.Resp, error)

ExecutePropagated executes the creation of a propagated transaction (involved mint).

func (*CreateTransaction) Propagate

Propagate recursively propagates to the next mint in the chain of mint involved in a transaction.

func (*CreateTransaction) Validate

func (e *CreateTransaction) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type EndPtName

type EndPtName string

EndPtName reprensents an endpoint name.

const (
	// EndPtCancelTransaction cancels a reserved transaction.
	EndPtCancelTransaction EndPtName = "CancelTransaction"
)
const (
	// EndPtCloseOffer creates a new offer.
	EndPtCloseOffer EndPtName = "CloseOffer"
)
const (
	// EndPtCreateAsset creates a new assset.
	EndPtCreateAsset EndPtName = "CreateAsset"
)
const (
	// EndPtCreateOffer creates a new offer.
	EndPtCreateOffer EndPtName = "CreateOffer"
)
const (
	// EndPtCreateTransaction creates a new transaction.
	EndPtCreateTransaction EndPtName = "CreateTransaction"
)
const (
	// EndPtListAssetBalances creates a new assset.
	EndPtListAssetBalances EndPtName = "ListAssetBalances"
)
const (
	// EndPtListAssetOffers creates a new assset.
	EndPtListAssetOffers EndPtName = "ListAssetOffers"
)
const (
	// EndPtListAssets creates a new assset.
	EndPtListAssets EndPtName = "ListAssets"
)
const (
	// EndPtListBalances creates a new assset.
	EndPtListBalances EndPtName = "ListBalances"
)
const (
	// EndPtPropagateBalance creates a new balance.
	EndPtPropagateBalance EndPtName = "PropagateBalance"
)
const (
	// EndPtPropagateOffer creates a new offer.
	EndPtPropagateOffer EndPtName = "PropagateOffer"
)
const (
	// EndPtPropagateOperation creates a new operation.
	EndPtPropagateOperation EndPtName = "PropagateOperation"
)
const (
	// EndPtRetrieveAsset creates a new assset.
	EndPtRetrieveAsset EndPtName = "RetrieveAsset"
)
const (
	// EndPtRetrieveBalance creates a new assset.
	EndPtRetrieveBalance EndPtName = "RetrieveBalance"
)
const (
	// EndPtRetrieveOffer creates a new assset.
	EndPtRetrieveOffer EndPtName = "RetrieveOffer"
)
const (
	// EndPtRetrieveOperation creates a new assset.
	EndPtRetrieveOperation EndPtName = "RetrieveOperation"
)
const (
	// EndPtRetrieveTransaction creates a new assset.
	EndPtRetrieveTransaction EndPtName = "RetrieveTransaction"
)
const (
	// EndPtSettleTransaction settles a reserved transaction.
	EndPtSettleTransaction EndPtName = "SettleTransaction"
)

type Endpoint

type Endpoint interface {
	Validate(
		r *http.Request,
	) error

	Execute(
		ctx context.Context,
	) (*int, *svc.Resp, error)
}

Endpoint is the interface that endpoints need to implement.

func NewCancelTransaction

func NewCancelTransaction(
	r *http.Request,
) (Endpoint, error)

NewCancelTransaction constructs and initialiezes the endpoint.

func NewCloseOffer

func NewCloseOffer(
	r *http.Request,
) (Endpoint, error)

NewCloseOffer constructs and initialiezes the endpoint.

func NewCreateAsset

func NewCreateAsset(
	r *http.Request,
) (Endpoint, error)

NewCreateAsset constructs and initialiezes the endpoint.

func NewCreateOffer

func NewCreateOffer(
	r *http.Request,
) (Endpoint, error)

NewCreateOffer constructs and initialiezes the endpoint.

func NewCreateTransaction

func NewCreateTransaction(
	r *http.Request,
) (Endpoint, error)

NewCreateTransaction constructs and initialiezes the endpoint.

func NewListAssetBalances

func NewListAssetBalances(
	r *http.Request,
) (Endpoint, error)

NewListAssetBalances constructs and initialiezes the endpoint.

func NewListAssetOffers

func NewListAssetOffers(
	r *http.Request,
) (Endpoint, error)

NewListAssetOffers constructs and initialiezes the endpoint.

func NewListAssets

func NewListAssets(
	r *http.Request,
) (Endpoint, error)

NewListAssets constructs and initialiezes the endpoint.

func NewListBalances

func NewListBalances(
	r *http.Request,
) (Endpoint, error)

NewListBalances constructs and initialiezes the endpoint.

func NewPropagateBalance

func NewPropagateBalance(
	r *http.Request,
) (Endpoint, error)

NewPropagateBalance constructs and initialiezes the endpoint.

func NewPropagateOffer

func NewPropagateOffer(
	r *http.Request,
) (Endpoint, error)

NewPropagateOffer constructs and initialiezes the endpoint.

func NewPropagateOperation

func NewPropagateOperation(
	r *http.Request,
) (Endpoint, error)

NewPropagateOperation constructs and initialiezes the endpoint.

func NewRetrieveAsset

func NewRetrieveAsset(
	r *http.Request,
) (Endpoint, error)

NewRetrieveAsset constructs and initialiezes the endpoint.

func NewRetrieveBalance

func NewRetrieveBalance(
	r *http.Request,
) (Endpoint, error)

NewRetrieveBalance constructs and initialiezes the endpoint.

func NewRetrieveOffer

func NewRetrieveOffer(
	r *http.Request,
) (Endpoint, error)

NewRetrieveOffer constructs and initialiezes the endpoint.

func NewRetrieveOperation

func NewRetrieveOperation(
	r *http.Request,
) (Endpoint, error)

NewRetrieveOperation constructs and initialiezes the endpoint.

func NewRetrieveTransaction

func NewRetrieveTransaction(
	r *http.Request,
) (Endpoint, error)

NewRetrieveTransaction constructs and initialiezes the endpoint.

func NewSettleTransaction

func NewSettleTransaction(
	r *http.Request,
) (Endpoint, error)

NewSettleTransaction constructs and initialiezes the endpoint.

type ListAssetBalances

type ListAssetBalances struct {
	ListEndpoint
	Owner string
	Asset mint.AssetResource
}

ListAssetBalances returns a list of balances.

func (*ListAssetBalances) Execute

func (e *ListAssetBalances) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*ListAssetBalances) Validate

func (e *ListAssetBalances) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type ListAssetOffers

type ListAssetOffers struct {
	ListEndpoint
	Asset       mint.AssetResource
	Propagation mint.PgType
}

ListAssetOffers returns a list of offers.

func (*ListAssetOffers) Execute

func (e *ListAssetOffers) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*ListAssetOffers) Validate

func (e *ListAssetOffers) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type ListAssets

type ListAssets struct {
	ListEndpoint
	Owner string
}

ListAssets returns a list of assets.

func (*ListAssets) Execute

func (e *ListAssets) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*ListAssets) Validate

func (e *ListAssets) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type ListBalances

type ListBalances struct {
	ListEndpoint
	Holder string
}

ListBalances returns a list of balances.

func (*ListBalances) Execute

func (e *ListBalances) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*ListBalances) Validate

func (e *ListBalances) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type ListEndpoint

type ListEndpoint struct {
	CreatedBefore time.Time
	Limit         uint
}

ListEndpoint is an helper object to implement list endpoints.

func (*ListEndpoint) Validate

func (e *ListEndpoint) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type PropagateBalance

type PropagateBalance struct {
	Client *mint.Client

	ID    string
	Token string
	Owner string
}

PropagateBalance fetches the balance propagated and creates a local propagated copy of it.

func (*PropagateBalance) Execute

func (e *PropagateBalance) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*PropagateBalance) Validate

func (e *PropagateBalance) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type PropagateOffer

type PropagateOffer struct {
	Client *mint.Client

	ID    string // propagation
	Token string // propagation
	Owner string
}

PropagateOffer retrieves a canonical offer and creates a local propagated copy of it.

func (*PropagateOffer) Execute

func (e *PropagateOffer) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*PropagateOffer) Validate

func (e *PropagateOffer) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type PropagateOperation

type PropagateOperation struct {
	Client *mint.Client

	ID    string
	Owner string
	Token string
}

PropagateOperation retrieves a canonical operation and creates a local propagated copy of it.

func (*PropagateOperation) Execute

func (e *PropagateOperation) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*PropagateOperation) ExecutePropagated

func (e *PropagateOperation) ExecutePropagated(
	ctx context.Context,
) (*int, *svc.Resp, error)

ExecutePropagated executes the propagation of an operation (involved mint).

func (*PropagateOperation) Validate

func (e *PropagateOperation) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type RetrieveAsset

type RetrieveAsset struct {
	Asset mint.AssetResource
}

RetrieveAsset retrieves an asset based on its name. It is not authenticated and is used to verify the existence of an asset.

func (*RetrieveAsset) Execute

func (e *RetrieveAsset) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*RetrieveAsset) Validate

func (e *RetrieveAsset) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type RetrieveBalance

type RetrieveBalance struct {
	ID    string
	Token string
	Owner string
}

RetrieveBalance retrieves an balance based on its id. It is not authenticated and is used to verify balances when they get propagated.

func (*RetrieveBalance) Execute

func (e *RetrieveBalance) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*RetrieveBalance) Validate

func (e *RetrieveBalance) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type RetrieveOffer

type RetrieveOffer struct {
	ID    string
	Token string
	Owner string
}

RetrieveOffer retrieves an offer based on its id. It is not authenticated and is used to verify offers when they get propagated.

func (*RetrieveOffer) Execute

func (e *RetrieveOffer) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*RetrieveOffer) Validate

func (e *RetrieveOffer) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type RetrieveOperation

type RetrieveOperation struct {
	ID    string
	Token string
	Owner string
}

RetrieveOperation retrieves an operation based on its id. It is not authenticated and is used to verify operations when they get propagated.

func (*RetrieveOperation) Execute

func (e *RetrieveOperation) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*RetrieveOperation) Validate

func (e *RetrieveOperation) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type RetrieveTransaction

type RetrieveTransaction struct {
	ID    string
	Token string
	Owner string
}

RetrieveTransaction retrieves a transaction based on its id. It is not authenticated and is used to propagate transactions.

func (*RetrieveTransaction) Execute

func (e *RetrieveTransaction) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*RetrieveTransaction) Validate

func (e *RetrieveTransaction) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

type SettleTransaction

type SettleTransaction struct {
	Client *mint.Client

	// Parameters
	Hop    int8
	ID     string
	Token  string
	Owner  string
	Secret string

	// State
	Tx   *model.Transaction
	Plan *plan.TxPlan
}

SettleTransaction creates a new transaction.

func (*SettleTransaction) Execute

func (e *SettleTransaction) Execute(
	ctx context.Context,
) (*int, *svc.Resp, error)

Execute executes the endpoint.

func (*SettleTransaction) ExecuteCanonical

func (e *SettleTransaction) ExecuteCanonical(
	ctx context.Context,
) (*int, *svc.Resp, error)

ExecuteCanonical executes the canonical settlement of a transaction (owner mint).

func (*SettleTransaction) ExecutePropagated

func (e *SettleTransaction) ExecutePropagated(
	ctx context.Context,
) (*int, *svc.Resp, error)

ExecutePropagated executes the settlement of a propagated transaction (involved mint).

func (*SettleTransaction) Propagate

func (e *SettleTransaction) Propagate(
	ctx context.Context,
) error

Propagate the lock for settlement. Current hop settlement is already performed.

func (*SettleTransaction) Settle

func (e *SettleTransaction) Settle(
	ctx context.Context,
) error

Settle settles idempotently the underlying operations and crossings at the current hop.

func (*SettleTransaction) Validate

func (e *SettleTransaction) Validate(
	r *http.Request,
) error

Validate validates the input parameters.

Jump to

Keyboard shortcuts

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