xmrmaker

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

Documentation

Overview

Package xmrmaker manages the swap state of individual swaps where the local swapd instance is offering Monero and accepting Ethereum assets 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
	Database                   offers.Database
	DataDir                    string
	WalletFile, WalletPassword string
	ExternalSender             bool
	Network                    Host
}

Config contains the configuration values for a new XMRMaker instance.

type Event

type Event interface {
	Type() EventType
}

Event represents a swap state event.

type EventContractReady

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

EventContractReady is the second expected event. It represents the contract being ready for us to claim the ETH.

func (*EventContractReady) Type

func (*EventContractReady) Type() EventType

Type ...

type EventETHLocked

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

EventETHLocked is the first expected event. It represents ETH being locked on-chain.

func (*EventETHLocked) Type

func (*EventETHLocked) Type() EventType

Type ...

type EventETHRefunded

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

EventETHRefunded is an optional event. It represents the ETH being refunded back to the counterparty, and thus we also must refund.

func (*EventETHRefunded) Type

func (*EventETHRefunded) 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 EventType

type EventType byte

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

const (
	// EventETHLockedType is triggered when the taker notifies us that the ETH
	// is locked in the smart contract. Upon verification, it causes us to lock
	// our XMR. After this event, the other possible events are
	// EventContractReadyType (success), EventETHRefundedType (abort), or
	// EventExitType (abort).
	EventETHLockedType EventType = iota

	// EventContractReadyType is triggered when the taker sets the contract to
	// "ready" or timeout1 is reached. When this event occurs, we can claim ETH
	// from the contract. After this event, the other possible events are
	// EventETHRefundedType (which would only happen if we go offline until
	// timeout2, causing us to refund), or EventExitType (refund).
	EventContractReadyType

	// EventETHRefundedType is triggered when the taker refunds the
	// contract-locked ETH back to themselves. It causes use to try to refund
	// our XMR. After this event, the only possible event is EventExitType.
	EventETHRefundedType

	// 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 leads to 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 Host

type Host interface {
	Advertise()
}

Host contains required network functionality.

type Instance

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

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

func NewInstance

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

NewInstance returns a new *xmrmaker.Instance. It accepts an endpoint to a monero-wallet-rpc instance where account 0 contains XMRMaker's XMR.

func (*Instance) ClearOffers

func (inst *Instance) ClearOffers(offerIDs []types.Hash) error

ClearOffers clears all offers.

func (*Instance) GetMoneroBalance

func (inst *Instance) GetMoneroBalance() (*mcrypto.Address, *wallet.GetBalanceResponse, error)

GetMoneroBalance returns the primary wallet address, and current balance of the user's monero wallet.

func (*Instance) GetOffers

func (inst *Instance) GetOffers() []*types.Offer

GetOffers returns all current offers.

func (*Instance) GetOngoingSwapState

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

GetOngoingSwapState ...

func (*Instance) HandleInitiateMessage

func (inst *Instance) HandleInitiateMessage(
	takerPeerID peer.ID,
	msg *message.SendKeysMessage,
) (net.SwapState, error)

HandleInitiateMessage is called when we receive a network message from a peer that they wish to initiate a swap.

func (*Instance) MakeOffer

func (inst *Instance) MakeOffer(
	o *types.Offer,
	useRelayer bool,
) (*types.OfferExtra, error)

MakeOffer makes a new swap offer.

func (*Instance) Provides

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

Provides returns types.ProvidesXMR

Directories

Path Synopsis
Package offers is a generated GoMock package.
Package offers is a generated GoMock package.

Jump to

Keyboard shortcuts

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