swap

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Inactive = iota
	Initiated
	Audited
	AuditPending
	AuditFailed
	Redeemed
	AuditedSecret
	Refunded
	RefundFailed
	Cancelled
	Expired
)
View Source
const ExpiryUnit = int64(2 * 60 * 60)

Variables

This section is empty.

Functions

This section is empty.

Types

type ReceiptUpdate

type ReceiptUpdate struct {
	ID     SwapID
	Update func(receipt *SwapReceipt)
}

func NewReceiptUpdate

func NewReceiptUpdate(id SwapID, update func(receipt *SwapReceipt)) ReceiptUpdate

type Swap

type Swap struct {
	ID              SwapID
	Token           blockchain.Token
	Value           *big.Int
	Fee             *big.Int
	BrokerFee       *big.Int
	SecretHash      [32]byte
	TimeLock        int64
	SpendingAddress string
	WithdrawAddress string
	FundingAddress  string
	BrokerAddress   string
}

A Swap stores all of the information required to execute an atomic swap.

type SwapBlob

type SwapBlob struct {
	ID           SwapID               `json:"id,omitempty"`
	SendToken    blockchain.TokenName `json:"sendToken"`
	ReceiveToken blockchain.TokenName `json:"receiveToken"`

	// SendAmount and ReceiveAmount are decimal strings.
	SendFee              string `json:"sendFee,omitempty"`
	SendAmount           string `json:"sendAmount"`
	ReceiveFee           string `json:"receiveFee,omitempty"`
	ReceiveAmount        string `json:"receiveAmount"`
	MinimumReceiveAmount string `json:"minimumReceiveAmount,omitempty"`

	SendTo              string `json:"sendTo"`
	ReceiveFrom         string `json:"receiveFrom"`
	TimeLock            int64  `json:"timeLock"`
	SecretHash          string `json:"secretHash"`
	ShouldInitiateFirst bool   `json:"shouldInitiateFirst"`

	Delay            bool            `json:"delay,omitempty"`
	DelayInfo        json.RawMessage `json:"delayInfo,omitempty"`
	DelayCallbackURL string          `json:"delayCallbackUrl,omitempty"`

	BrokerFee              int64  `json:"brokerFee,omitempty"` // in BIPs or (1/10000)
	BrokerSendTokenAddr    string `json:"brokerSendTokenAddr,omitempty"`
	BrokerReceiveTokenAddr string `json:"brokerReceiveTokenAddr,omitempty"`

	WithdrawAddress string `json:"withdrawAddress,omitempty"`
	ResponseURL     string `json:"responseURL,omitempty"`
	Password        string `json:"password,omitempty"`
	PasswordHash    string `json:"passwordHash,omitempty"`
}

A SwapBlob is used to encode a Swap for storage and transmission.

type SwapID

type SwapID string

TODO: Rename to ID A SwapID uniquely identifies a Swap that is being executed.

func (SwapID) Generate

func (SwapID) Generate(rand *rand.Rand, size int) reflect.Value

Generate is used to create random values for testing

type SwapReceipt

type SwapReceipt struct {
	ID            SwapID               `json:"id"`
	SendToken     blockchain.TokenName `json:"sendToken"`
	ReceiveToken  blockchain.TokenName `json:"receiveToken"`
	SendAmount    string               `json:"sendAmount"`
	ReceiveAmount string               `json:"receiveAmount"`
	SendCost      blockchain.CostBlob  `json:"sendCost"`
	ReceiveCost   blockchain.CostBlob  `json:"receiveCost"`
	Timestamp     int64                `json:"timestamp"`
	TimeLock      int64                `json:"timeLock"`
	Status        int                  `json:"status"`
	Delay         bool                 `json:"delay"`
	DelayInfo     json.RawMessage      `json:"delayInfo,omitempty"`
	Active        bool                 `json:"active"`
	PasswordHash  string               `json:"passwordHash,omitempty"`
}

The SwapReceipt contains the swap details and the status.

func NewSwapReceipt

func NewSwapReceipt(blob SwapBlob) SwapReceipt

NewSwapReceipt returns a SwapReceipt from a swapBlob.

Jump to

Keyboard shortcuts

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