plan

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: 8 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 ExtractPrice

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

ExtractPrice validates a price (pB/pQ).

Types

type TxAction

type TxAction struct {
	Owner  string
	Type   TxActionType
	Amount *big.Int

	CrossingOffer *string

	OperationAsset       *string
	OperationSource      *string
	OperationDestination *string
}

TxAction represents an action to be performed by a mint. Either an operation or crossing creation.

type TxActionType

type TxActionType string

TxActionType is the type of the action of a TxPlan

const (
	// TxActTpOperation is the action type for an operation creation.
	TxActTpOperation TxActionType = "operation"
	// TxActTpCrossing is the action type for a crossing creation.
	TxActTpCrossing TxActionType = "crossing"
)

type TxHop

type TxHop struct {
	Mint string

	OpAction *TxAction
	CrAction *TxAction
}

TxHop is a list of action to be performed by the mint at the associated hop. hop 0 is the mint creating the transaction, hop (i) is the mint on the offer path at index (i-1).

type TxPlan

type TxPlan struct {
	Hops        []*TxHop
	Transaction string
}

TxPlan is the plan associated with the transaction. It is constructed by each mint involved in the transaction. Each hop represents a mint along the offer path starting with the mint initiating the transaction.

func Compute

func Compute(
	ctx context.Context,
	client *mint.Client,
	tx *model.Transaction,
	shallow bool,
) (*TxPlan, error)

Compute retrieves the offers of the path and compute the transaction plan.

func (*TxPlan) Check

func (p *TxPlan) Check(
	ctx context.Context,
	transaction *mint.TransactionResource,
	hop int8,
) error

Check checks that the plan was properly executed at the specified hop by retrieving the transaction ont that mint and checking the actions against the advertised operations and crossings.

func (*TxPlan) CheckCanCancel

func (p *TxPlan) CheckCanCancel(
	ctx context.Context,
	client *mint.Client,
	hop int8,
) bool

CheckCanCancel checks that this node is authorized to cancel the transaction (this is the node with higher hop or the node above it has already canceled the transaction). Works on a shallow plan.

func (*TxPlan) CheckShouldCancel

func (p *TxPlan) CheckShouldCancel(
	ctx context.Context,
	client *mint.Client,
	hop int8,
) bool

CheckShouldCancel checks whether the next node on the offer path has canceled. If so, no need to settle, we can cancel instead. Works on a shallow plan.

func (*TxPlan) MinMaxHop

func (p *TxPlan) MinMaxHop(
	ctx context.Context,
) (*int8, *int8, error)

MinMaxHop returns the lowest and highest hops for the local mint in the transaction plan. Works on a shallow plan.

Jump to

Keyboard shortcuts

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