newop

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FeeStateFinalFee      string = "FinalFee"
	FeeStateNeedsChange   string = "NeedsChange"
	FeeStateNoPossibleFee string = "NoPossibleFee"
)
View Source
const (
	UpdateAll     = ""
	UpdateEmpty   = "UpdateEmpty"
	UpdateInPlace = "UpdateInPlace"
)

States are emitted in Transitions and contain a certain Update type. UpdateAll is the default. Means the state is meant to update the UI entirely. This is currently handled differently by clients. Falcon takes it as a built UI from scratch, while Apollo only builds from scratch if it has to, otherwise it just updates values. UpdateEmpty means the State machine is coming back to a previous State and UI needs no further updating. UpdateInPlace is a special update type for Falcon, it's used to just update values in place, no building UI from scratch.

View Source
const (
	OperationErrorUnpayable                = "Unpayable"
	OperationErrorAmountGreaterThanBalance = "AmountGreaterThanBalance"
	OperationErrorAmountTooSmall           = "AmountTooSmall"
	OperationErrorInvalidAddress           = "InvalidAddress"
	OperationErrorInvoiceExpired           = "InvoiceExpired"
)
View Source
const (
	DebtTypeNone    = string(fees.DebtTypeNone)
	DebtTypeCollect = string(fees.DebtTypeCollect)
	DebtTypeLend    = string(fees.DebtTypeLend)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AbortState

type AbortState struct {
	BaseState
	PreviousState interface {
		// contains filtered or unexported methods
	}
}

func (*AbortState) Cancel

func (s *AbortState) Cancel()

type AmountInfo

type AmountInfo struct {
	Amount                *BitcoinAmount
	TotalBalance          *BitcoinAmount
	TakeFeeFromAmount     bool
	FeeRateInSatsPerVByte float64
}

type BalanceErrorState

type BalanceErrorState struct {
	BaseState
	PaymentIntent *PaymentIntent
	TotalAmount   *MonetaryAmount
	Balance       *MonetaryAmount
	Error         string
}

type BaseState

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

BaseState contains the shared structure among all states

func (*BaseState) GetUpdate

func (s *BaseState) GetUpdate() string

type BestRouteFees

type BestRouteFees struct {
	MaxCapacity              int64
	FeeProportionalMillionth int64
	FeeBase                  int64
}

type BitcoinAmount

type BitcoinAmount struct {
	InSat             int64
	InPrimaryCurrency *MonetaryAmount
	InInputCurrency   *MonetaryAmount
}

type ConfirmLightningState

type ConfirmLightningState struct {
	*Resolved
	*AmountInfo
	*Validated
	Note string
}

func (*ConfirmLightningState) Back

func (s *ConfirmLightningState) Back() error

type ConfirmState

type ConfirmState struct {
	*Resolved
	*AmountInfo
	*Validated
	Note string
}

func (*ConfirmState) Back

func (s *ConfirmState) Back() error

func (*ConfirmState) OpenFeeEditor

func (s *ConfirmState) OpenFeeEditor() error

type EditFeeState

type EditFeeState struct {
	*Resolved
	*AmountInfo
	*Validated
	Note                     string
	MaxFeeRateInSatsPerVByte float64
}

func (*EditFeeState) CalculateFee

func (s *EditFeeState) CalculateFee(rateInSatsPerVByte float64) (*FeeState, error)

TODO this currently ignores and forgets input currency, which is important for amount display logic in Edit Fee screens

func (*EditFeeState) CloseEditor

func (s *EditFeeState) CloseEditor() error

func (*EditFeeState) MinFeeRateForTarget

func (s *EditFeeState) MinFeeRateForTarget(target int) (float64, error)

func (*EditFeeState) SetFeeRate

func (s *EditFeeState) SetFeeRate(rateInSatsPerVByte float64) error

type EnterAmountState

type EnterAmountState struct {
	*Resolved
	Amount       *BitcoinAmount
	TotalBalance *BitcoinAmount
}

func (*EnterAmountState) Back

func (s *EnterAmountState) Back() error

func (*EnterAmountState) ChangeCurrency

func (s *EnterAmountState) ChangeCurrency(currency string) error

ChangeCurrency is deprecated. Prefer the newer, ChangeCurrencyWithAmount(currency, inputAmount)

func (*EnterAmountState) ChangeCurrencyWithAmount added in v0.11.0

func (s *EnterAmountState) ChangeCurrencyWithAmount(currency string, inputAmount *MonetaryAmount) error

ChangeCurrencyWithAmount respond to the user action of changing the current input currency to a new one, while also updating the input amount, needed for performing the necessary conversion. Note: this state machine doesn't receive partial updates for the input amount each time the user types or deletes a digit, so ChangeCurrencyWithAmount needs to receive the updates input amount.

func (*EnterAmountState) EnterAmount

func (s *EnterAmountState) EnterAmount(amount *MonetaryAmount, takeFeeFromAmount bool) error

func (*EnterAmountState) PartialValidate

func (s *EnterAmountState) PartialValidate(inputAmount *MonetaryAmount) (bool, error)

type EnterDescriptionState

type EnterDescriptionState struct {
	*Resolved
	*AmountInfo
	*Validated
	Note string
}

func (*EnterDescriptionState) Back

func (s *EnterDescriptionState) Back() error

func (*EnterDescriptionState) EnterDescription

func (s *EnterDescriptionState) EnterDescription(description string) error

type ErrorState

type ErrorState struct {
	BaseState
	PaymentIntent *PaymentIntent
	Error         string
}

type ExchangeRateWindow

type ExchangeRateWindow struct {
	WindowId int
	// contains filtered or unexported fields
}

ExchangeRateWindow holds a map of exchange rates from BTC to every currency we handle

func (*ExchangeRateWindow) AddRate

func (w *ExchangeRateWindow) AddRate(currency string, rate float64)

func (*ExchangeRateWindow) Currencies

func (s *ExchangeRateWindow) Currencies() *libwallet.StringList

func (*ExchangeRateWindow) Rate

func (w *ExchangeRateWindow) Rate(currency string) float64

type FeeState

type FeeState struct {
	State              string
	Amount             *BitcoinAmount
	RateInSatsPerVByte float64
	TargetBlocks       int64 // 0 if target not found
}

func (*FeeState) IsFinal

func (f *FeeState) IsFinal() bool

func (*FeeState) IsNoPossibleFee

func (f *FeeState) IsNoPossibleFee() bool

func (*FeeState) NeedsChange

func (f *FeeState) NeedsChange() bool

type FeeWindow

type FeeWindow struct {
	FastConfTarget   int64
	MediumConfTarget int64
	SlowConfTarget   int64
	TargetedFees     map[uint]float64
}

FeeWindow holds a map of target block to fee rate for a given time

func (*FeeWindow) GetTargetedFees

func (w *FeeWindow) GetTargetedFees(target int64) float64

func (*FeeWindow) PutTargetedFees

func (w *FeeWindow) PutTargetedFees(target int64, feeRateInSatsPerVByte float64)

type FundingOutputPolicies

type FundingOutputPolicies struct {
	MaximumDebtInSat       int64
	PotentialCollectInSat  int64
	MaxAmountInSatFor0Conf int64
}

type MonetaryAmount

type MonetaryAmount struct {
	Value    decimal.Decimal
	Currency string
}

MonetaryAmount holds an amount of money in a certain currency

func NewMonetaryAmountFromFiat

func NewMonetaryAmountFromFiat(value string, currency string) *MonetaryAmount

func NewMonetaryAmountFromSatoshis

func NewMonetaryAmountFromSatoshis(value int64) *MonetaryAmount

func (*MonetaryAmount) String

func (m *MonetaryAmount) String() string

func (*MonetaryAmount) ValueAsString

func (m *MonetaryAmount) ValueAsString() string

type NextTransactionSize

type NextTransactionSize struct {
	SizeProgression     []SizeForAmount
	ValidAtOperationHid int64 // Just for debugging reasons
	ExpectedDebtInSat   int64
}

NextTransactionSize is a struct used for calculating fees in terms of the unspent outputs required to perform a transaction

func (*NextTransactionSize) AddSizeForAmount

func (w *NextTransactionSize) AddSizeForAmount(item *SizeForAmount)

func (*NextTransactionSize) GetOutpoints

func (w *NextTransactionSize) GetOutpoints() string

type PaymentContext

type PaymentContext struct {
	FeeWindow                *FeeWindow
	NextTransactionSize      *NextTransactionSize
	ExchangeRateWindow       *ExchangeRateWindow
	PrimaryCurrency          string
	MinFeeRateInSatsPerVByte float64
	SubmarineSwap            *SubmarineSwap
}

PaymentContext stores data required to analyze and validate an operation

type PaymentIntent

type PaymentIntent struct {
	URI *libwallet.MuunPaymentURI
}

PaymentIntent contains the resolved payment intent and does not change during the flow

func (*PaymentIntent) Amount

func (p *PaymentIntent) Amount() *MonetaryAmount

type ResolveState

type ResolveState struct {
	BaseState
	PaymentIntent *PaymentIntent
}

func (*ResolveState) SetContext

func (s *ResolveState) SetContext(context *PaymentContext) error

type Resolved

type Resolved struct {
	BaseState
	PaymentIntent  *PaymentIntent
	PaymentContext *PaymentContext
	PresetAmount   *BitcoinAmount
	PresetNote     string
}

type SizeForAmount

type SizeForAmount struct {
	SizeInVByte int64
	AmountInSat int64
	Outpoint    string
}

type StartState

type StartState struct {
	BaseState
}

func NewOperationFlow

func NewOperationFlow(listener TransitionListener) *StartState

NewOperationFlow sets up the StartState, so transitions will be reported to `listener`

func (*StartState) Resolve

func (s *StartState) Resolve(address string, network *libwallet.Network) error

func (*StartState) ResolveInvoice

func (s *StartState) ResolveInvoice(invoice *libwallet.Invoice, network *libwallet.Network) error

type State

type State interface {
	GetUpdate() string
}

State is an interface implemented by every state type, containing flow-level properties.

type SubmarineSwap

type SubmarineSwap struct {
	Receiver              *SubmarineSwapReceiver
	Fees                  *SwapFees
	FundingOutputPolicies *FundingOutputPolicies
	BestRouteFees         []*BestRouteFees
}

func (*SubmarineSwap) AddBestRouteFees

func (s *SubmarineSwap) AddBestRouteFees(bestRouteFees *BestRouteFees)

type SubmarineSwapReceiver

type SubmarineSwapReceiver struct {
	Alias            string
	NetworkAddresses string
	PublicKey        string
}

type SwapFees

type SwapFees struct {
	RoutingFeeInSat     int64
	DebtType            string
	DebtAmountInSat     int64
	OutputAmountInSat   int64
	OutputPaddingInSat  int64
	ConfirmationsNeeded int64
}

type SwapInfo

type SwapInfo struct {
	IsOneConf  bool
	OnchainFee *BitcoinAmount
	SwapFees   *SwapFees
}

type TransitionListener

type TransitionListener interface {
	OnStart(nextState *StartState)
	OnResolve(nextState *ResolveState)
	OnEnterAmount(nextState *EnterAmountState)
	OnEnterDescription(nextState *EnterDescriptionState)
	OnValidate(nextState *ValidateState)
	OnValidateLightning(nextState *ValidateLightningState)
	OnConfirm(nextState *ConfirmState)
	OnConfirmLightning(nextState *ConfirmLightningState)
	OnEditFee(nextState *EditFeeState)
	OnError(nextState *ErrorState)
	OnBalanceError(nextState *BalanceErrorState)
	OnAbort(nextState *AbortState)
}

TransitionListener allows app-level code to receive state updates asynchronously, preserving concrete types across the bridge and enforcing type safety.

type ValidateLightningState

type ValidateLightningState struct {
	*Resolved
	*AmountInfo
	Note string
}

func (*ValidateLightningState) Continue

func (s *ValidateLightningState) Continue() error

type ValidateState

type ValidateState struct {
	*Resolved
	*AmountInfo
	Note string
}

func (*ValidateState) Continue

func (s *ValidateState) Continue() error

type Validated

type Validated struct {
	Fee            *BitcoinAmount
	FeeNeedsChange bool
	Total          *BitcoinAmount
	SwapInfo       *SwapInfo
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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