xmrtaker

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: LGPL-3.0 Imports: 33 Imported by: 0

Documentation

Overview

Package xmrtaker manages the swap state of individual swaps where the local swapd instance is offering Ethereum assets and accepting Monero in return.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Backend        backend.Backend
	DataDir        string
	NoTransferBack bool
	ExternalSender bool
}

Config contains the configuration values for a new XMRTaker instance.

type Event

type Event interface {
	Type() EventType
}

Event represents a swap state event.

type EventETHClaimed

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

EventETHClaimed is the third expected event. It represents the ETH being claimed by the counterparty, and thus we can also claim the XMR.

func (*EventETHClaimed) Type

func (*EventETHClaimed) Type() EventType

Type ...

type EventExit

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

EventExit is an optional event. It is sent when the protocol should be stopped, for example if the remote peer closes their connection with us before sending all required messages, or we decide to cancel the swap.

func (*EventExit) Type

func (*EventExit) Type() EventType

Type ...

type EventKeysReceived

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

EventKeysReceived is the first expected event.

func (*EventKeysReceived) Type

func (*EventKeysReceived) Type() EventType

Type ...

type EventShouldRefund

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

EventShouldRefund is an optional event. It occurs when the XMR-maker doesn't lock before t1, so we should refund the ETH.

func (*EventShouldRefund) Type

func (*EventShouldRefund) Type() EventType

Type ...

type EventType

type EventType byte

EventType represents an event that occurs which moves the swap "state machine" to its next state.

const (
	// EventKeysReceivedType is triggered when we receive the XMR maker's
	// swap keys, allowing us to initiate the swap on-chain. It causes us to
	// lock our ETH and store keys in the smart contract. After this event,
	// the other possible events are EventXMRLockedType (success path) or
	// EventExitType (abort path).
	EventKeysReceivedType EventType = iota

	// EventXMRLockedType is triggered after we verify that the maker locked the
	// XMR for the swap. It causes us to set the contract to "ready", so that
	// the maker can claim his ETH. After this event, the other possible events
	// are EventETHClaimedType (success path), EventShouldRefundType (refund
	// path), or EventExitType (refund path).
	EventXMRLockedType

	// EventETHClaimedType is triggered when the maker claims their ETH from the
	// contract. It causes us to claim the XMR. After this event, the other
	// possible event is EventExitType (success path).
	EventETHClaimedType

	// EventShouldRefundType is triggered when we should refund, either because
	// we are nearing the timeout1 threshold and the maker hasn't locked XMR, or
	// because we've reached the timeout2 threshold and the maker hasn't claimed
	// the ETH. It causes us to refund the contract locked ETH locked to
	// ourselves. After this event, the only possible event is EventExitType
	// (refund path).
	//
	// Note: this constant is a placeholder for clarity. While the event it
	// represents is used, we never actually use the constant for its type.
	EventShouldRefundType

	// EventExitType is triggered by the protocol "exiting", which may happen
	// via a swap cancellation via the RPC endpoint, or from the counterparty
	// disconnecting from us on the p2p network. It causes us to attempt to
	// gracefully exit from the swap, which causes either an abort, refund, or
	// claim, depending on the state we're currently in. No other events can
	// occur after this.
	EventExitType

	// EventNoneType is set as the "nextExpectedEvent" once the swap has exited.
	// It does not trigger any action. No other events can occur after this.
	EventNoneType
)

func (EventType) String

func (t EventType) String() string

type EventXMRLocked

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

EventXMRLocked is the second expected event. It represents XMR being locked on-chain.

func (*EventXMRLocked) Type

func (*EventXMRLocked) Type() EventType

Type ...

type Instance

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

Instance implements the functionality that will be used by a user who owns ETH and wishes to swap for XMR.

func NewInstance

func NewInstance(cfg *Config) (*Instance, error)

NewInstance returns a new instance of XMRTaker. It accepts an endpoint to a monero-wallet-rpc instance where XMRTaker will generate the account in which the XMR will be deposited.

func (*Instance) ExternalSender

func (inst *Instance) ExternalSender(offerID types.Hash) (*txsender.ExternalSender, error)

ExternalSender returns the *txsender.ExternalSender for a swap, if the swap exists and is using and external tx sender

func (*Instance) GetOngoingSwapState

func (inst *Instance) GetOngoingSwapState(offerID types.Hash) common.SwapState

GetOngoingSwapState ...

func (*Instance) InitiateProtocol

func (inst *Instance) InitiateProtocol(
	makerPeerID peer.ID,
	providesAmount *apd.Decimal,
	offer *types.Offer,
) (common.SwapState, error)

InitiateProtocol is called when an RPC call is made from the user to take a swap. The input units are ether that we will provide.

func (*Instance) Provides

func (inst *Instance) Provides() coins.ProvidesCoin

Provides returns types.ProvidesETH

Jump to

Keyboard shortcuts

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