atomicswap

package
v0.0.0-...-0269a1e Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCurrencyNotAllowed = errors.New("currency not allowed")
	ErrNoSalesFound       = errors.New("no sales found for the current currency and price")
)

Functions

This section is empty.

Types

type Client

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

Client for atomic swaps

func NewClient

func NewClient(ctx context.Context, nostr *nostr.Client, eth *goethclient.Client, stellar *stellargoclient.Client) (*Client, error)

NewClient for atomic swaps

func (*Client) AttemptBuy

func (c *Client) AttemptBuy(ctx context.Context, amount uint, currency string, maxPrice uint) (*Driver, error)

Attempt to buy from an already existing swap TODO: in the future this should be changed to keep listening for new sell orders

func (*Client) PlaceSellOrder

func (c *Client) PlaceSellOrder(ctx context.Context, amount uint, currency string, price uint) (*Driver, error)

PlaceSellOrder on nostr relays. A sell order is always for stellar based TFT. The buying currency, as well as the price to buy 1 TFT in that currency is specified. Amount is expressed in whole TFT (= 10_000_000 stropes of TFT). Price is expressed as the smallest possible unit of the target currency.

type Driver

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

Driver for atomic swaps

func (*Driver) Buy

func (d *Driver) Buy(ctx context.Context, seller string, sale nostr.Product, amount uint) error

Buy flow for the driver

func (*Driver) OpenSale

func (d *Driver) OpenSale(sale nostr.Product) error

OpenSale on the driver

type DriverStage

type DriverStage = int
const (
	// Initial conditions
	DriverStageOpenSale DriverStage = iota
	DriverStageStartBuy
	// In progress
	DriverStageAcceptedBuy
	DriverStageSetupSwap
	DriverStageParticipateSwap
	// Terminal conditions
	DriverStageClaimSwap
	DriverStageDone
)

type MsgAccept

type MsgAccept struct {
	Id             string         `json:"id"`
	EthAddress     common.Address `json:"ethAddress"`
	StellarAddress string         `json:"stellarAddress"`

	// Amount of TFT to swap
	Amount uint `json:"amount"`
	// SwapPrice of 1 TFT
	SwapPrice uint `json:"swapPrice"`
}

type MsgBuy

type MsgBuy struct {
	Id     string `json:"id"`
	Amount uint   `json:"amount"`
}

type MsgInitiateEth

type MsgInitiateEth struct {
	Id                  string             `json:"id"`
	SharedSecret        [sha256.Size]byte  `json:"sharedSecret"`
	EthAddress          common.Address     `json:"ethAddress"`
	StellarAddress      string             `json:"stellarAddress"`
	InitiateTransaction *types.Transaction `json:"initiateTransaction"`
}

type MsgParticipateStellar

type MsgParticipateStellar struct {
	Id             string `json:"id"`
	HoldingAccount string `json:"holdingAccount"`
	RefundTx       string `json:"refundTx"`
}

type MsgRedeemed

type MsgRedeemed struct {
	Id     string   `json:"id"`
	Secret [32]byte `json:"secret"`
}

Jump to

Keyboard shortcuts

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