Documentation
¶
Index ¶
- Constants
- Variables
- func UseLogger(logger btclog.Logger)
- type AddressManager
- type BaseDB
- type DepositManager
- type ID
- type Manager
- func (m *Manager) DeliverWithdrawalRequest(ctx context.Context, outpoints []wire.OutPoint, destAddr string, ...) (string, string, error)
- func (m *Manager) GetAllWithdrawals(ctx context.Context) ([]Withdrawal, error)
- func (m *Manager) Run(ctx context.Context, initChan chan struct{}) error
- func (m *Manager) WithdrawDeposits(ctx context.Context, outpoints []wire.OutPoint, destAddr string, ...) (string, string, error)
- type ManagerConfig
- type Querier
- type SqlStore
- type Store
- type Withdrawal
Constants ¶
const (
IdLength = 32
)
Variables ¶
var ( // ErrWithdrawingMixedDeposits is returned when a withdrawal is // requested for deposits in different states. ErrWithdrawingMixedDeposits = errors.New("need to withdraw deposits " + "having the same state, either all deposited or all " + "withdrawing") // ErrDiffPreviousWithdrawalTx signals that the user selected new // deposits that have different previous withdrawal transactions. ErrDiffPreviousWithdrawalTx = errors.New("can't bump fee for " + "deposits with different previous withdrawal tx hash") // ErrMissingPreviousWithdrawn is returned when the user tries to bump // the fee for a subset of previously selected deposits to withdraw. ErrMissingPreviousWithdrawn = errors.New("can't bump fee for subset " + "of clustered deposits") // MinConfs is the minimum number of confirmations we require for a // deposit to be considered withdrawn. MinConfs int32 = 3 )
Functions ¶
Types ¶
type AddressManager ¶
type AddressManager interface { // GetStaticAddressParameters returns the static address parameters. GetStaticAddressParameters(ctx context.Context) (*address.Parameters, error) // GetStaticAddress returns the deposit address for the given // client and server public keys. GetStaticAddress(ctx context.Context) (*script.StaticAddress, error) // ListUnspent returns a list of utxos at the static address. ListUnspent(ctx context.Context, minConfs, maxConfs int32) ([]*lnwallet.Utxo, error) }
AddressManager handles fetching of address parameters.
type BaseDB ¶
type BaseDB interface { Querier // ExecTx allows for executing a function in the context of a database // transaction. ExecTx(ctx context.Context, txOptions loopdb.TxOptions, txBody func(Querier) error) error }
BaseDB is the interface that contains all the queries generated by sqlc for the static_address_swaps table and transaction functionality.
type DepositManager ¶
type DepositManager interface { GetActiveDepositsInState(stateFilter fsm.StateType) ([]*deposit.Deposit, error) AllOutpointsActiveDeposits(outpoints []wire.OutPoint, stateFilter fsm.StateType) ([]*deposit.Deposit, bool) TransitionDeposits(ctx context.Context, deposits []*deposit.Deposit, event fsm.EventType, expectedFinalState fsm.StateType) error UpdateDeposit(ctx context.Context, d *deposit.Deposit) error }
type ID ¶
ID is a unique identifier for a deposit.
func GetRandomWithdrawalID ¶
GetRandomWithdrawalID generates a random withdrawal ID.
func (*ID) FromByteSlice ¶
FromByteSlice creates a deposit id from a byte slice.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the withdrawal state machines.
func NewManager ¶
func NewManager(cfg *ManagerConfig, currentHeight uint32) *Manager
NewManager creates a new deposit withdrawal manager.
func (*Manager) DeliverWithdrawalRequest ¶
func (m *Manager) DeliverWithdrawalRequest(ctx context.Context, outpoints []wire.OutPoint, destAddr string, satPerVbyte int64, amount int64) (string, string, error)
DeliverWithdrawalRequest forwards a withdrawal request to the manager main loop.
func (*Manager) GetAllWithdrawals ¶
func (m *Manager) GetAllWithdrawals(ctx context.Context) ([]Withdrawal, error)
GetAllWithdrawals returns all finalized withdrawals from the store.
func (*Manager) WithdrawDeposits ¶
func (m *Manager) WithdrawDeposits(ctx context.Context, outpoints []wire.OutPoint, destAddr string, satPerVbyte int64, amount int64) (string, string, error)
WithdrawDeposits starts a deposits withdrawal flow. If the amount is set to 0 the full amount of the selected deposits will be withdrawn.
type ManagerConfig ¶
type ManagerConfig struct { // StaticAddressServerClient is the client that calls the swap server // rpcs to negotiate static address withdrawals. StaticAddressServerClient staticaddressrpc.StaticAddressServerClient // AddressManager gives the withdrawal manager access to static address // parameters. AddressManager AddressManager // DepositManager gives the withdrawal manager access to the deposits // enabling it to create and manage withdrawals. DepositManager DepositManager // WalletKit is the wallet client that is used to derive new keys from // lnd's wallet. WalletKit lndclient.WalletKitClient // ChainParams is the chain configuration(mainnet, testnet...) this // manager uses. ChainParams *chaincfg.Params // ChainNotifier is the chain notifier that is used to listen for new // blocks. ChainNotifier lndclient.ChainNotifierClient // Signer is the signer client that is used to sign transactions. Signer lndclient.SignerClient // Store is the store that is used to persist the finalized withdrawal // transactions. Store *SqlStore }
ManagerConfig holds the configuration for the address manager.
type Querier ¶
type Querier interface { // CreateWithdrawal inserts a new withdrawal. CreateWithdrawal(ctx context.Context, arg sqlc.CreateWithdrawalParams) error // UpdateWithdrawal updates a withdrawal with confirmation parameters. UpdateWithdrawal(ctx context.Context, arg sqlc.UpdateWithdrawalParams) error // GetWithdrawalIDByDepositID retrieves the withdrawal ID associated // with a given deposit ID. GetWithdrawalIDByDepositID(ctx context.Context, depositID []byte) ( []byte, error) // CreateWithdrawalDeposit links withdrawal to deposits. CreateWithdrawalDeposit(ctx context.Context, arg sqlc.CreateWithdrawalDepositParams) error // GetWithdrawalDeposits retrieves the deposit IDs associated with a // withdrawal. GetWithdrawalDeposits(ctx context.Context, withdrawalID []byte) ( [][]byte, error) // GetAllWithdrawals retrieves all withdrawals from the database. GetAllWithdrawals(ctx context.Context) ([]sqlc.Withdrawal, error) }
type SqlStore ¶
type SqlStore struct {
// contains filtered or unexported fields
}
SqlStore is the backing store for static address withdrawals.
func NewSqlStore ¶
NewSqlStore constructs a new SQLStore from a BaseDB. The BaseDB is agnostic to the underlying driver which can be postgres or sqlite.
func (*SqlStore) CreateWithdrawal ¶
CreateWithdrawal creates a static address withdrawal record in the database.
func (*SqlStore) GetAllWithdrawals ¶
func (s *SqlStore) GetAllWithdrawals(ctx context.Context) ([]Withdrawal, error)
GetAllWithdrawals retrieves all static address withdrawals from the database. It returns a slice of Withdrawal structs, each containing a list of associated deposits.
func (*SqlStore) UpdateWithdrawal ¶
func (s *SqlStore) UpdateWithdrawal(ctx context.Context, deposits []*deposit.Deposit, tx *wire.MsgTx, confirmationHeight uint32, changePkScript []byte) error
UpdateWithdrawal updates a withdrawal record with the transaction information, including the withdrawn amount, change amount, and confirmation height. It is expected that the withdrawal has already been created with CreateWithdrawal, and that the deposits slice contains the deposits associated with the withdrawal.
type Store ¶
type Store interface { // CreateWithdrawal inserts a withdrawal into the store. CreateWithdrawal(ctx context.Context, tx *wire.MsgTx, confirmationHeight uint32, deposits []*deposit.Deposit, changePkScript []byte) error // GetAllWithdrawals retrieves all withdrawals. GetAllWithdrawals(ctx context.Context) ([]Withdrawal, error) }
Store is the database interface that is used to store and retrieve static address withdrawals.
type Withdrawal ¶
type Withdrawal struct { // ID is the unique identifier of the deposit. ID ID // TxID is the transaction ID of the withdrawal. TxID chainhash.Hash // Deposits is a list of deposits used to fund the withdrawal. Deposits []*deposit.Deposit // TotalDepositAmount is the total amount of all deposits used to fund // the withdrawal. TotalDepositAmount btcutil.Amount // WithdrawnAmount is the amount withdrawn. It represents the total // value of selected deposits minus fees and change. WithdrawnAmount btcutil.Amount // ChangeAmount is the optional change returned to the static address. ChangeAmount btcutil.Amount // InitiationTime is the time at which the withdrawal was initiated. InitiationTime time.Time // ConfirmationHeight is the block height at which the withdrawal was // confirmed. ConfirmationHeight int64 }
Withdrawal represents a finalized static address withdrawal record in the database.