mint

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: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvCfgHost is the env config key for the mint host.
	EnvCfgHost env.ConfigKey = "host"
	// EnvCfgPort is the port on which to run the mint.
	EnvCfgPort env.ConfigKey = "port"
	// EnvCfgKeyFile is the production certificate key file.
	EnvCfgKeyFile env.ConfigKey = "key_file"
	// EnvCfgCrtFile is the production certificate file.
	EnvCfgCrtFile env.ConfigKey = "crt_file"
)
View Source
const (
	// ProtocolVersion is the current protocol version.
	ProtocolVersion string = "0"
	// TimeResolutionNs is the resolution of our time variables in nanoseconds
	// (aka resolution in milliseconds).
	TimeResolutionNs int64 = 1000 * 1000
	// TransactionExpiryMs is the time it takes to attempt to cancel a
	// transaction for this mint. Expressed in ms.
	TransactionExpiryMs int64 = 1000 * 60 * 60
)

Variables

View Source
var AddressRegexp = regexp.MustCompile(
	"^" + addressRegexpStr + "$",
)

AddressRegexp is used to validate and parse issuer names.

View Source
var AssetNameRegexp = regexp.MustCompile(
	"^" + addressRegexpStr + "\\[([A-Z0-9-]{1,64})\\.([0-9]{1,2})\\]" + "$",
)

AssetNameRegexp is used to validate and parse asset names.

View Source
var DefaultPort = map[env.Environment]int64{
	env.Production: 2406,
	env.QA:         2407,
}

DefaultPort is the mint default port by environment.

View Source
var DefaultScheme = map[env.Environment]string{
	env.Production: "https",
	env.QA:         "http",
}

DefaultScheme is the mint default scheme by environment.

View Source
var IDRegexp = regexp.MustCompile(
	"^(.+)\\[([a-z]+_[a-zA-Z0-9]+)\\]$",
)

IDRegexp is used to validate a full id including issuer and token.

Functions

func FullMintURL

func FullMintURL(
	ctx context.Context,
	host string,
	path string,
	query url.Values,
) *url.URL

FullMintURL constructs a fully qualified URL to contact a mint defaulting to the correct scheme and port based on the current environment.

func GetHost

func GetHost(
	ctx context.Context,
) string

GetHost retrieves the current mint host from the given contest.

func GetPort

func GetPort(
	ctx context.Context,
) string

GetPort retrieves the current mint port from the given contest.

func Logf

func Logf(
	ctx context.Context,
	format string,
	v ...interface{},
)

Logf shells out to logging.Logf adding the mint host as prefix.

func NormalizedAddress

func NormalizedAddress(
	ctx context.Context,
	address string,
) (string, error)

NormalizedAddress returns the address trimmed from the `+...@` part.

func NormalizedOwnerAndTokenFromID

func NormalizedOwnerAndTokenFromID(
	ctx context.Context,
	id string,
) (string, string, error)

NormalizedOwnerAndTokenFromID returns a normalized address and token from an id.

func UsernameAndMintHostFromAddress

func UsernameAndMintHostFromAddress(
	ctx context.Context,
	address string,
) (string, string, error)

UsernameAndMintHostFromAddress extracts the username and mint host from a fully qualified address.

Types

type AssetResource

type AssetResource struct {
	ID          string `json:"id"`
	Created     int64  `json:"created"`
	Owner       string `json:"owner"`
	Propagation PgType `json:"propagation"`

	Name  string `json:"name"`
	Code  string `json:"code"`
	Scale int8   `json:"scale"`
}

AssetResource is the representation of an asset in the mint API.

func AssetResourceFromName

func AssetResourceFromName(
	ctx context.Context,
	name string,
) (*AssetResource, error)

AssetResourceFromName parses an asset fully qualified name into an AssetResource object (without id or created date, owner is normalized).

func AssetResourcesFromPair

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

AssetResourcesFromPair parses a pair into an array of AssetResources (without id or created date).

type BalanceResource

type BalanceResource struct {
	ID          string `json:"id"`
	Created     int64  `json:"created"`
	Owner       string `json:"owner"`
	Propagation PgType `json:"propagation"`

	Asset  string   `json:"asset"`
	Holder string   `json:"holder"`
	Value  *big.Int `json:"value"`
}

BalanceResource is the representation of an asset balance in the mint API.

type Client

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

Client expose an interface to perform queries on remote mints.

func (*Client) CancelTransaction

func (c *Client) CancelTransaction(
	ctx context.Context,
	id string,
	hop int8,
	mint string,
) (*TransactionResource, error)

CancelTransaction propagates the cancelation of a transaction on the specified mint for the specified hop.

func (*Client) Init

func (c *Client) Init(
	ctx context.Context,
) error

Init initializes the mint client.

func (*Client) PropagateBalance

func (c *Client) PropagateBalance(
	ctx context.Context,
	id string,
	mint string,
) (*BalanceResource, error)

PropagateBalance propagates an balance to the specified mint.

func (*Client) PropagateOffer

func (c *Client) PropagateOffer(
	ctx context.Context,
	id string,
	mint string,
) (*OfferResource, error)

PropagateOffer propagates an offer to the specified mint.

func (*Client) PropagateOperation

func (c *Client) PropagateOperation(
	ctx context.Context,
	id string,
	mint string,
) (*OperationResource, error)

PropagateOperation propagates an operation to the specified mint.

func (*Client) PropagateTransaction

func (c *Client) PropagateTransaction(
	ctx context.Context,
	id string,
	hop int8,
	mint string,
) (*TransactionResource, error)

PropagateTransaction propagates a transaction to the specified mint.

func (*Client) RetrieveBalance

func (c *Client) RetrieveBalance(
	ctx context.Context,
	id string,
) (*BalanceResource, error)

RetrieveBalance retrieves an balance given its ID by extracting the mint and retrieving it from there.

func (*Client) RetrieveOffer

func (c *Client) RetrieveOffer(
	ctx context.Context,
	id string,
) (*OfferResource, error)

RetrieveOffer retrieves an offer given its ID by extracting the mint and retrieving it from there.

func (*Client) RetrieveOperation

func (c *Client) RetrieveOperation(
	ctx context.Context,
	id string,
) (*OperationResource, error)

RetrieveOperation retrieves an operation given its ID by extracting the mint and retrieving it from there.

func (*Client) RetrieveTransaction

func (c *Client) RetrieveTransaction(
	ctx context.Context,
	id string,
	mint *string,
) (*TransactionResource, error)

RetrieveTransaction retrieves a transaction given its ID by extracting the mint and retrieving it from there. If host is specified, it attempts to retrrieve the transaction from this host instead of the canonical host.

func (*Client) SettleTransaction

func (c *Client) SettleTransaction(
	ctx context.Context,
	id string,
	hop *int8,
	secret *string,
	mint *string,
) (*TransactionResource, error)

SettleTransaction settles a transaction. If hop, secret, mint are specified it settles on the specified mint using the specified hop and secret, otherwise it attempts to settle on the canonical mint.

type CrossingResource

type CrossingResource struct {
	ID          string `json:"id"`
	Created     int64  `json:"created"`
	Owner       string `json:"owner"`
	Propagation PgType `json:"propagation"`

	Offer  string   `json:"offer"`
	Amount *big.Int `json:"amount"`

	Status         TxStatus `json:"status"`
	Transaction    string   `json:"transaction"`
	TransactionHop int8     `json:"transaction_hop"`
}

CrossingResource is the representation of a crossing in the mint API.

type ErrMintClient

type ErrMintClient struct {
	StatusCode int
	ErrCode    string
	ErrMessage string
}

ErrMintClient is returned by the client when an proper error is returned by the mint it interacted with.

func (ErrMintClient) Error

func (e ErrMintClient) Error() string

type OfStatus

type OfStatus string

OfStatus is the status of an offer.

const (
	// OfStActive is used to mark an offer as active.
	OfStActive OfStatus = "active"
	// OfStClosed is used to mark an offer as closed.
	OfStClosed OfStatus = "closed"
	// OfStConsumed is used to mark an offer as consumed.
	OfStConsumed OfStatus = "consumed"
)

func (*OfStatus) Scan

func (s *OfStatus) Scan(src interface{}) error

Scan implements sql.Scanner.

func (OfStatus) Value

func (s OfStatus) Value() (value driver.Value, err error)

Value implements driver.Valuer.

type OfferResource

type OfferResource struct {
	ID          string `json:"id"`
	Created     int64  `json:"created"`
	Owner       string `json:"owner"`
	Propagation PgType `json:"propagation"`

	Pair   string   `json:"pair"`
	Price  string   `json:"price"`
	Amount *big.Int `json:"amount"`

	Status    OfStatus `json:"status"`
	Remainder *big.Int `json:"remainder"`
}

OfferResource is the representation of an offer in the mint API.

type OperationResource

type OperationResource struct {
	ID          string `json:"id"`
	Created     int64  `json:"created"`
	Owner       string `json:"owner"`
	Propagation PgType `json:"propagation"`

	Asset       string   `json:"asset"`
	Source      string   `json:"source"`
	Destination string   `json:"destination"`
	Amount      *big.Int `json:"amount"`

	Status         TxStatus `json:"status"`
	Transaction    *string  `json:"transaction"`
	TransactionHop *int8    `json:"transaction_hop"`
}

OperationResource is the representation of an operation in the mint API.

type PgType

type PgType string

PgType is the propagation type of an object.

const (
	// PgTpCanonical is an offer owned by this mint.
	PgTpCanonical PgType = "canonical"
	// PgTpPropagated is an offer propagated to this mint.
	PgTpPropagated PgType = "propagated"
)

func (*PgType) Scan

func (t *PgType) Scan(src interface{}) error

Scan implements sql.Scanner.

func (PgType) Value

func (t PgType) Value() (value driver.Value, err error)

Value implements driver.Valuer

type TkName

type TkName string

TkName represents a task name.

func (*TkName) Scan

func (s *TkName) Scan(src interface{}) error

Scan implements sql.Scanner.

func (TkName) Value

func (s TkName) Value() (value driver.Value, err error)

Value implements driver.Valuer.

type TkStatus

type TkStatus string

TkStatus represents a task status.

const (
	// TkStPending new or have been retried less than the task max retries.
	TkStPending TkStatus = "pending"
	// TkStSucceeded successfully executed once.
	TkStSucceeded TkStatus = "succeeded"
	// TkStFailed retried more than max retries with no success.
	TkStFailed TkStatus = "failed"
)

func (*TkStatus) Scan

func (s *TkStatus) Scan(src interface{}) error

Scan implements sql.Scanner.

func (TkStatus) Value

func (s TkStatus) Value() (value driver.Value, err error)

Value implements driver.Valuer.

type TransactionResource

type TransactionResource struct {
	ID          string `json:"id"`
	Created     int64  `json:"created"`
	Owner       string `json:"owner"`
	Propagation PgType `json:"propagation"`

	Pair        string   `json:"pair"`
	Amount      *big.Int `json:"amount"`
	Destination string   `json:"destination"`
	Path        []string `json:"path"`

	Status TxStatus `json:"status"`
	Lock   string   `json:"lock"`
	Secret *string  `json:"secret"`

	Operations []OperationResource `json:"operations"`
	Crossings  []CrossingResource  `json:"crossings"`
}

TransactionResource is the representation of a transaction in the mint API.

type TxStatus

type TxStatus string

TxStatus is the status of a transaction, operation or crossing.

const (
	// TxStPending is used to mark a transaction as pending (created but not
	// yet finalized)
	TxStPending TxStatus = "pending"
	// TxStReserved is used to mark a transaction or action (operation or
	// crossing) as reserved.
	TxStReserved TxStatus = "reserved"
	// TxStSettled is used to mark a transaction or action (operation or
	// crossing) as settled.
	TxStSettled TxStatus = "settled"
	// TxStCanceled is used to mark a transaction or action (operation or
	// crossing) as canceled.
	TxStCanceled TxStatus = "canceled"
)

func (*TxStatus) Scan

func (s *TxStatus) Scan(src interface{}) error

Scan implements sql.Scanner.

func (TxStatus) Value

func (s TxStatus) Value() (value driver.Value, err error)

Value implements driver.Valuer.

Directories

Path Synopsis
cmd
lib

Jump to

Keyboard shortcuts

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