types

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package types is for types that are shared by multiple packages

Index

Constants

This section is empty.

Variables

View Source
var (
	// CurOfferVersion is the latest supported version of a serialised Offer struct
	CurOfferVersion, _ = semver.NewVersion("1.0.0")
)
View Source
var EmptyHash = Hash{}

EmptyHash is an empty Hash

View Source
var EthAssetETH = EthAsset(ethcommon.Address{})

EthAssetETH describes regular ETH (rather than an ERC-20 token)

Functions

func IsHashZero

func IsHashZero(h Hash) bool

IsHashZero returns true if the hash is all zeros, otherwise false

Types

type EthAsset

type EthAsset ethcommon.Address

EthAsset represents an Ethereum asset (ETH or a token address)

func (EthAsset) Address

func (asset EthAsset) Address() ethcommon.Address

Address ...

func (EthAsset) IsETH

func (asset EthAsset) IsETH() bool

IsETH returns true of the asset is ETH, otherwise false

func (EthAsset) IsToken

func (asset EthAsset) IsToken() bool

IsToken returns true if the asset is an ERC20 token, otherwise false

func (EthAsset) MarshalText

func (asset EthAsset) MarshalText() ([]byte, error)

MarshalText returns the hex representation of the EthAsset or, in some cases, a short string.

func (EthAsset) String

func (asset EthAsset) String() string

String implements fmt.Stringer, returning the asset's address in hex prefixed by `ERC20@` if it's an ERC20 token, or ETH for ether.

func (*EthAsset) UnmarshalText

func (asset *EthAsset) UnmarshalText(input []byte) error

UnmarshalText assigns the EthAsset from the input text

type Hash

type Hash = ethcommon.Hash

Hash represents a 32-byte hash used as transaction IDs both by Ethereum and Monero.

func HexToHash

func HexToHash(s string) (Hash, error)

HexToHash decodes a hex-encoded string into a hash

type Offer

type Offer struct {
	Version      semver.Version      `json:"version"`
	ID           Hash                `json:"offerID" validate:"required"`
	Provides     coins.ProvidesCoin  `json:"provides" validate:"required"`
	MinAmount    *apd.Decimal        `json:"minAmount" validate:"required"` // Min XMR amount
	MaxAmount    *apd.Decimal        `json:"maxAmount" validate:"required"` // Max XMR amount
	ExchangeRate *coins.ExchangeRate `json:"exchangeRate" validate:"required"`
	EthAsset     EthAsset            `json:"ethAsset"`
	Nonce        uint64              `json:"nonce" validate:"required"`
}

Offer represents a swap offer

func NewOffer

func NewOffer(
	coin coins.ProvidesCoin,
	minAmount *apd.Decimal,
	maxAmount *apd.Decimal,
	exRate *coins.ExchangeRate,
	ethAsset EthAsset,
) *Offer

NewOffer creates and returns an Offer with an initialised ID and Version fields

func UnmarshalOffer

func UnmarshalOffer(jsonData []byte) (*Offer, error)

UnmarshalOffer deserializes a JSON offer, checking the version for compatibility before attempting to deserialize the whole blob.

func (*Offer) IsSet

func (o *Offer) IsSet() bool

IsSet returns true if the offer's fields are all set.

func (*Offer) MarshalJSON

func (o *Offer) MarshalJSON() ([]byte, error)

MarshalJSON provides JSON marshalling for the Offer type

func (*Offer) String

func (o *Offer) String() string

String ...

func (*Offer) UnmarshalJSON

func (o *Offer) UnmarshalJSON(data []byte) error

UnmarshalJSON provides JSON unmarshalling the Offer type

type OfferExtra

type OfferExtra struct {
	StatusCh   chan Status `json:"-"`
	UseRelayer bool        `json:"useRelayer,omitempty"`
}

OfferExtra represents extra data that is passed when an offer is made.

type Status

type Status byte

Status represents the stage that a swap is at.

const (
	// UnknownStatus is a placeholder for unmatched status strings and
	// uninitialized variables
	UnknownStatus Status = iota
	// ExpectingKeys is the status of the taker between taking an offer and
	// receiving a response with swap keys from the maker. It is also the
	// maker's status after creating an offer up until receiving keys from a
	// taker accepting the offer.
	ExpectingKeys
	// KeysExchanged is the status of the maker after a taker accepts his offer.
	KeysExchanged
	// ETHLocked is the taker status after locking her ETH up until confirming
	// that the maker locked his XMR.
	ETHLocked
	// XMRLocked is the maker's state after locking the XMR up until he confirms
	// that the the taker has set the contract to ready.
	XMRLocked
	// ContractReady is the taker's state after verifying the locked XMR and
	// setting the contract to ready.
	ContractReady
	// SweepingXMR is the taker's state after claiming the XMR and sweeping it
	// back into their primary wallet.
	// It can also be the maker's state if the maker refunds and is sweeping
	// the XMR back into his primary wallet.
	// Note: if sweeping is disabled, this stage does not occur.
	// Also note that the swap protocol is technically "done" at this stage;
	// however, this stage is required so that the node is aware that a sweep
	// is occurring in case of a daemon restart.
	SweepingXMR
	// CompletedSuccess represents a successful swap.
	CompletedSuccess
	// CompletedRefund represents a swap that was refunded.
	CompletedRefund
	// CompletedAbort represents the case where the swap aborts before any funds
	// are locked.
	CompletedAbort
)

Status values

func NewStatus

func NewStatus(str string) Status

NewStatus returns a Status from the given string. If there is no match, it returns UnknownStatus

func (Status) Description

func (s Status) Description() string

Description returns a description of the swap stage.

func (Status) IsOngoing

func (s Status) IsOngoing() bool

IsOngoing returns true if the status means the swap has not completed

func (Status) MarshalText

func (s Status) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Status) String

func (s Status) String() string

String returns the status as a text string.

func (*Status) UnmarshalText

func (s *Status) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

Jump to

Keyboard shortcuts

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